Details (original message): Define the core contracts: domain model, stream events, HITL, profiles, tools, plugins, UI vocabulary, ingest IR, retrieval and memory; golden-sample conformance tests; TS mirror.
123 lines
3.5 KiB
Go
123 lines
3.5 KiB
Go
package core
|
|
|
|
import "encoding/json"
|
|
|
|
// 事件信封:后端 → 前端的唯一增量通道(SSE),持久化后转发,Seq 在会话内单调。
|
|
// 消费方对未知 Type 静默忽略(原则 6 前向兼容)。
|
|
type StreamEvent struct {
|
|
Seq int64 `json:"seq"`
|
|
RunID ID `json:"runId,omitempty"`
|
|
ConversationID ID `json:"conversationId"`
|
|
TS string `json:"ts"` // RFC3339
|
|
V int `json:"v"`
|
|
Type StreamEventType `json:"type"`
|
|
Payload json.RawMessage `json:"payload,omitempty"`
|
|
}
|
|
|
|
type StreamEventType string
|
|
|
|
const (
|
|
EvMessageDelta StreamEventType = "message.delta"
|
|
EvThinkingDelta StreamEventType = "thinking.delta"
|
|
EvToolCall StreamEventType = "tool.call"
|
|
EvToolResult StreamEventType = "tool.result"
|
|
EvRunPhase StreamEventType = "run.phase"
|
|
EvHITLRequest StreamEventType = "hitl.request"
|
|
EvHITLResolved StreamEventType = "hitl.resolved"
|
|
EvPlanUpdate StreamEventType = "plan.update"
|
|
EvTodoUpdate StreamEventType = "todo.update"
|
|
EvAgentSpawn StreamEventType = "agent.spawn"
|
|
EvAgentProgress StreamEventType = "agent.progress"
|
|
EvAgentResult StreamEventType = "agent.result"
|
|
EvArtifactCreated StreamEventType = "artifact.created"
|
|
EvArtifactUpdated StreamEventType = "artifact.updated"
|
|
EvRunCompleted StreamEventType = "run.completed"
|
|
EvRunFailed StreamEventType = "run.failed"
|
|
EvError StreamEventType = "error"
|
|
)
|
|
|
|
// ProtocolVersion 是事件信封与 payload 词汇的当前版本。
|
|
const ProtocolVersion = 1
|
|
|
|
// ---- 各事件 payload(新增字段只增不删;消费方忽略未知字段)----
|
|
|
|
// MessageDeltaPayload:正文增量。Index 标识目标 Part 序号(流式聚合用)。
|
|
type MessageDeltaPayload struct {
|
|
Index int `json:"index"`
|
|
Text string `json:"text"`
|
|
}
|
|
|
|
type ThinkingDeltaPayload struct {
|
|
Index int `json:"index"`
|
|
Text string `json:"text"`
|
|
}
|
|
|
|
type ToolCallPayload struct {
|
|
CallID string `json:"callId"`
|
|
Name string `json:"name"`
|
|
Arguments string `json:"arguments,omitempty"`
|
|
}
|
|
|
|
type ToolResultPayload struct {
|
|
CallID string `json:"callId"`
|
|
Status string `json:"status"`
|
|
Summary string `json:"summary,omitempty"`
|
|
Truncated bool `json:"truncated,omitempty"`
|
|
}
|
|
|
|
type RunPhasePayload struct {
|
|
Phase RunPhase `json:"phase"`
|
|
}
|
|
|
|
type HITLResolvedPayload struct {
|
|
CardID ID `json:"cardId"`
|
|
Answer string `json:"answer,omitempty"`
|
|
Kind string `json:"kind"` // choice | free | timeout | cancelled
|
|
}
|
|
|
|
type PlanUpdatePayload struct {
|
|
Plan PlanSnapshot `json:"plan"`
|
|
}
|
|
|
|
type TodoUpdatePayload struct {
|
|
List TodoList `json:"list"`
|
|
}
|
|
|
|
// AgentSpawnPayload:子代理派生;AgentRun 即子 Run(父子关系即任务树)。
|
|
type AgentSpawnPayload struct {
|
|
AgentRun ID `json:"agentRun"`
|
|
Name string `json:"name"`
|
|
Task string `json:"task"`
|
|
}
|
|
|
|
type AgentProgressPayload struct {
|
|
AgentRun ID `json:"agentRun"`
|
|
Note string `json:"note,omitempty"`
|
|
Phase RunPhase `json:"phase,omitempty"`
|
|
}
|
|
|
|
type AgentResultPayload struct {
|
|
AgentRun ID `json:"agentRun"`
|
|
Status RunStatus `json:"status"`
|
|
Summary string `json:"summary,omitempty"`
|
|
}
|
|
|
|
type ArtifactPayload struct {
|
|
Artifact Artifact `json:"artifact"`
|
|
}
|
|
|
|
type RunCompletedPayload struct {
|
|
Usage Usage `json:"usage"`
|
|
}
|
|
|
|
type RunFailedPayload struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type ErrorPayload struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
RunID ID `json:"runId,omitempty"`
|
|
}
|