111 lines
4.5 KiB
Python
111 lines
4.5 KiB
Python
"""运行时 API schema。"""
|
|
|
|
from typing import Any, Literal
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
|
|
class EventResponse(BaseModel):
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"examples": [
|
|
{
|
|
"event_id": "event_70d5ef8a4c5b44a893b4f83f933b78e9",
|
|
"run_id": "run_a2c8ecc73c0e4cc7bc2fafbaeada74e0",
|
|
"character_id": "character_ec83d55746c54e47ab6f98d683032626",
|
|
"type": "message.delta",
|
|
"sequence": 2,
|
|
"visibility": "public",
|
|
"payload": {
|
|
"message_id": "message_2f9b7bf7d3b84231b67b28bb39fbfa7a",
|
|
"delta": "你好,我是魂镜中的默认人物,",
|
|
"index": 0,
|
|
},
|
|
"created_at": "2026-06-19T09:10:52.676462Z",
|
|
}
|
|
]
|
|
}
|
|
)
|
|
|
|
event_id: str = Field(description="事件 ID,前缀为 event_。")
|
|
run_id: str = Field(description="所属运行 ID。")
|
|
character_id: str = Field(description="所属人物 ID。")
|
|
type: str = Field(description="事件类型,例如 run.started、message.delta、run.completed。")
|
|
sequence: int = Field(description="Run 内递增序号,用于 SSE 断点续传。")
|
|
visibility: str = Field(description="事件可见性:public / internal / audit。")
|
|
payload: dict[str, Any] = Field(
|
|
description="事件负载。message.delta 中包含 delta、index、message_id。"
|
|
)
|
|
created_at: str = Field(description="创建时间,UTC ISO 8601 字符串。")
|
|
trace_id: str | None = Field(
|
|
default=None, description="链路追踪 ID,可在司命台链路追踪页据此追溯。"
|
|
)
|
|
|
|
|
|
class RunResponse(BaseModel):
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"examples": [
|
|
{
|
|
"id": "run_a2c8ecc73c0e4cc7bc2fafbaeada74e0",
|
|
"character_id": "character_ec83d55746c54e47ab6f98d683032626",
|
|
"session_id": "session_2e7c3cbd4ef8472bab59718b7d012f80",
|
|
"status": "completed",
|
|
"goal": "回复用户消息",
|
|
"origin": "chat",
|
|
"model_hint": "deepseek-v4-flash",
|
|
"started_at": "2026-06-19T09:10:52.660153Z",
|
|
"completed_at": "2026-06-19T09:10:52.690000Z",
|
|
"error_code": None,
|
|
"error_message": None,
|
|
"created_at": "2026-06-19T09:10:52.660153Z",
|
|
"updated_at": "2026-06-19T09:10:52.690000Z",
|
|
}
|
|
]
|
|
}
|
|
)
|
|
|
|
id: str = Field(description="运行 ID,前缀为 run_。")
|
|
character_id: str = Field(description="所属人物 ID。")
|
|
session_id: str | None = Field(description="关联会话 ID。")
|
|
status: str = Field(
|
|
description="运行状态:queued / running / completed / failed / cancelled / interrupted。"
|
|
)
|
|
goal: str | None = Field(description="运行目标。")
|
|
origin: str = Field(description="运行来源,例如 chat。")
|
|
model_hint: str | None = Field(description="本次运行使用的逻辑模型名或能力槽位。")
|
|
started_at: str | None = Field(description="开始时间。")
|
|
completed_at: str | None = Field(description="完成时间。")
|
|
error_code: str | None = Field(description="失败错误码;成功时为空。")
|
|
error_message: str | None = Field(description="失败错误信息;成功时为空。")
|
|
created_at: str = Field(description="创建时间,UTC ISO 8601 字符串。")
|
|
updated_at: str = Field(description="更新时间,UTC ISO 8601 字符串。")
|
|
|
|
|
|
class AgentControlRequest(BaseModel):
|
|
"""运行中 steer / follow-up 消息。"""
|
|
|
|
content: str = Field(min_length=1, max_length=20_000)
|
|
|
|
|
|
class AgentControlResponse(BaseModel):
|
|
accepted: bool = True
|
|
|
|
|
|
class ConfirmationResolutionResponse(BaseModel):
|
|
"""工具确认 resolve 结果(approve/deny 端点成功响应)。"""
|
|
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"examples": [
|
|
{"status": "resolved", "approved": True},
|
|
{"status": "resolved", "approved": False},
|
|
]
|
|
}
|
|
)
|
|
|
|
status: Literal["resolved"] = Field(
|
|
default="resolved", description="恒为 resolved;失败路径由错误响应覆盖。"
|
|
)
|
|
approved: bool = Field(description="裁决结果:True=批准,False=拒绝。")
|