@downcity/agent 1.1.222 → 1.1.224
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/agent/local/Agent.d.ts +1 -34
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +1 -44
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +35 -2
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentSessions.d.ts +6 -0
- package/bin/agent/local/services/AgentSessions.d.ts.map +1 -1
- package/bin/agent/local/services/AgentSessions.js +42 -0
- package/bin/agent/local/services/AgentSessions.js.map +1 -1
- package/bin/agent/remote/RemoteAgent.d.ts +1 -35
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js +1 -37
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteSession.d.ts +24 -45
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +74 -121
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +11 -27
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +7 -21
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +11 -47
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +7 -20
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +8 -17
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +2 -2
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/types/SessionHistoryPaths.d.ts +1 -1
- package/bin/index.d.ts +3 -3
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -1
- package/bin/index.js.map +1 -1
- package/bin/rpc/Client.d.ts +7 -36
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +28 -78
- package/bin/rpc/Client.js.map +1 -1
- package/bin/session/Session.d.ts +16 -8
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +66 -21
- package/bin/session/Session.js.map +1 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +49 -18
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts +30 -24
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts.map +1 -1
- package/bin/session/recorder/JsonlSessionMessageStore.js +163 -59
- package/bin/session/recorder/JsonlSessionMessageStore.js.map +1 -1
- package/bin/session/recorder/SessionMessageCodec.d.ts.map +1 -1
- package/bin/session/recorder/SessionMessageCodec.js +6 -1
- package/bin/session/recorder/SessionMessageCodec.js.map +1 -1
- package/bin/session/recorder/SessionRecorder.d.ts +20 -11
- package/bin/session/recorder/SessionRecorder.d.ts.map +1 -1
- package/bin/session/recorder/SessionRecorder.js +148 -103
- package/bin/session/recorder/SessionRecorder.js.map +1 -1
- package/bin/session/recorder/SessionRecorderCompaction.d.ts.map +1 -1
- package/bin/session/recorder/SessionRecorderCompaction.js +1 -0
- package/bin/session/recorder/SessionRecorderCompaction.js.map +1 -1
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts +5 -5
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts.map +1 -1
- package/bin/session/recorder/SessionRecorderHistoryStore.js +5 -5
- package/bin/session/recorder/SessionRecorderHistoryStore.js.map +1 -1
- package/bin/session/runtime/SessionEventHub.d.ts +12 -5
- package/bin/session/runtime/SessionEventHub.d.ts.map +1 -1
- package/bin/session/runtime/SessionEventHub.js +11 -6
- package/bin/session/runtime/SessionEventHub.js.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts +2 -2
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.js +35 -17
- package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
- package/bin/session/services/SessionStateService.d.ts +2 -2
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +6 -2
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionTurnService.d.ts +2 -7
- package/bin/session/services/SessionTurnService.d.ts.map +1 -1
- package/bin/session/services/SessionTurnService.js +2 -8
- package/bin/session/services/SessionTurnService.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +1 -1
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +2 -2
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +3 -4
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +2 -2
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +11 -7
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +35 -62
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +4 -4
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/bin/types/session/SessionApproval.d.ts +97 -0
- package/bin/types/session/SessionApproval.d.ts.map +1 -0
- package/bin/types/session/SessionApproval.js +7 -0
- package/bin/types/session/SessionApproval.js.map +1 -0
- package/bin/types/session/SessionMessage.d.ts +10 -4
- package/bin/types/session/SessionMessage.d.ts.map +1 -1
- package/bin/types/session/SessionMutation.d.ts +116 -0
- package/bin/types/session/SessionMutation.d.ts.map +1 -0
- package/bin/types/session/SessionMutation.js +19 -0
- package/bin/types/session/SessionMutation.js.map +1 -0
- package/bin/types/session/SessionOptions.d.ts +9 -0
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/package.json +3 -3
- package/scripts/remote-session-reconnect.test.mjs +7 -3
- package/scripts/session-history-inflight.test.mjs +2 -2
- package/scripts/session-prompt-runtime.test.mjs +3 -3
- package/scripts/session-recorder.test.mjs +100 -146
- package/src/agent/local/Agent.ts +1 -55
- package/src/agent/local/services/AgentAssemblyService.ts +39 -3
- package/src/agent/local/services/AgentSessions.ts +47 -0
- package/src/agent/remote/RemoteAgent.ts +1 -54
- package/src/agent/remote/RemoteSession.ts +105 -163
- package/src/agent/remote/RemoteTransport.ts +23 -34
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +33 -90
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +22 -39
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +2 -2
- package/src/executor/types/SessionHistoryPaths.ts +1 -1
- package/src/index.ts +20 -12
- package/src/rpc/Client.ts +48 -106
- package/src/session/Session.ts +91 -34
- package/src/session/browse/Browse.ts +51 -22
- package/src/session/recorder/JsonlSessionMessageStore.ts +170 -86
- package/src/session/recorder/SessionMessageCodec.ts +6 -1
- package/src/session/recorder/SessionRecorder.ts +183 -124
- package/src/session/recorder/SessionRecorderCompaction.ts +1 -0
- package/src/session/recorder/SessionRecorderHistoryStore.ts +5 -5
- package/src/session/runtime/SessionEventHub.ts +25 -12
- package/src/session/runtime/SessionPromptRuntime.ts +37 -19
- package/src/session/services/SessionStateService.ts +8 -6
- package/src/session/services/SessionTurnService.ts +3 -14
- package/src/session/storage/Paths.ts +2 -2
- package/src/session/storage/RuntimeSessionPort.ts +8 -11
- package/src/types/agent/SessionActor.ts +23 -20
- package/src/types/rpc/RpcProtocol.ts +34 -71
- package/src/types/runtime/agent/AgentContext.ts +7 -11
- package/src/types/session/SessionApproval.ts +108 -0
- package/src/types/session/SessionMessage.ts +10 -4
- package/src/types/session/SessionMutation.ts +141 -0
- package/src/types/session/SessionOptions.ts +25 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/session/recorder/SessionMessageReducer.d.ts +0 -12
- package/bin/session/recorder/SessionMessageReducer.d.ts.map +0 -1
- package/bin/session/recorder/SessionMessageReducer.js +0 -109
- package/bin/session/recorder/SessionMessageReducer.js.map +0 -1
- package/bin/session/runtime/SessionMessageEventHub.d.ts +0 -15
- package/bin/session/runtime/SessionMessageEventHub.d.ts.map +0 -1
- package/bin/session/runtime/SessionMessageEventHub.js +0 -28
- package/bin/session/runtime/SessionMessageEventHub.js.map +0 -1
- package/bin/types/sdk/AgentSessionEvent.d.ts +0 -303
- package/bin/types/sdk/AgentSessionEvent.d.ts.map +0 -1
- package/bin/types/sdk/AgentSessionEvent.js +0 -9
- package/bin/types/sdk/AgentSessionEvent.js.map +0 -1
- package/bin/types/session/SessionMessageMutation.d.ts +0 -92
- package/bin/types/session/SessionMessageMutation.d.ts.map +0 -1
- package/bin/types/session/SessionMessageMutation.js +0 -21
- package/bin/types/session/SessionMessageMutation.js.map +0 -1
- package/src/session/recorder/SessionMessageReducer.ts +0 -155
- package/src/session/runtime/SessionMessageEventHub.ts +0 -35
- package/src/types/sdk/AgentSessionEvent.ts +0 -372
- package/src/types/session/SessionMessageMutation.ts +0 -121
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session Message Mutation reducer。
|
|
3
|
-
*
|
|
4
|
-
* 历史重放与实时消费者共享 message、part、delta 三种归并语义。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { SessionAssistantMessage, SessionMessage } from "@/types/session/SessionMessage.js";
|
|
8
|
-
import type { SessionMessageMutation } from "@/types/session/SessionMessageMutation.js";
|
|
9
|
-
|
|
10
|
-
/** 将单条 Mutation 应用到已有 Message。 */
|
|
11
|
-
export function reduce_session_message(
|
|
12
|
-
current_message: SessionMessage | undefined,
|
|
13
|
-
mutation: SessionMessageMutation,
|
|
14
|
-
): SessionMessage {
|
|
15
|
-
if (mutation.variant === "message") {
|
|
16
|
-
validate_message_snapshot(current_message, mutation);
|
|
17
|
-
return structuredClone(mutation.message);
|
|
18
|
-
}
|
|
19
|
-
if (!current_message) {
|
|
20
|
-
throw new Error(`Session Message does not exist: ${mutation.message_id}`);
|
|
21
|
-
}
|
|
22
|
-
validate_next_revision(current_message, mutation);
|
|
23
|
-
const assistant = require_streaming_assistant(current_message);
|
|
24
|
-
|
|
25
|
-
if (mutation.variant === "part") {
|
|
26
|
-
if (mutation.part.part_id !== mutation.part_id) {
|
|
27
|
-
throw new Error(`Part Mutation identity mismatch: ${mutation.part_id}`);
|
|
28
|
-
}
|
|
29
|
-
if (mutation.part.type !== mutation.type) {
|
|
30
|
-
throw new Error(`Part Mutation type mismatch: ${mutation.part_id}`);
|
|
31
|
-
}
|
|
32
|
-
const exists = assistant.parts.some(
|
|
33
|
-
(part) => part.part_id === mutation.part_id,
|
|
34
|
-
);
|
|
35
|
-
const parts = exists
|
|
36
|
-
? assistant.parts.map((part) =>
|
|
37
|
-
part.part_id === mutation.part_id
|
|
38
|
-
? structuredClone(mutation.part)
|
|
39
|
-
: part,
|
|
40
|
-
)
|
|
41
|
-
: [...assistant.parts, structuredClone(mutation.part)];
|
|
42
|
-
return with_revision(assistant, mutation, { parts });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const existing_part = assistant.parts.find(
|
|
46
|
-
(part) => part.part_id === mutation.part_id,
|
|
47
|
-
);
|
|
48
|
-
if (
|
|
49
|
-
!existing_part ||
|
|
50
|
-
(existing_part.type !== "text" && existing_part.type !== "reasoning")
|
|
51
|
-
) {
|
|
52
|
-
throw new Error(`Delta target Part does not exist: ${mutation.part_id}`);
|
|
53
|
-
}
|
|
54
|
-
if (existing_part.type !== mutation.type) {
|
|
55
|
-
throw new Error(`Delta type changed for Part: ${mutation.part_id}`);
|
|
56
|
-
}
|
|
57
|
-
const parts = assistant.parts.map((part) =>
|
|
58
|
-
part.part_id === mutation.part_id &&
|
|
59
|
-
(part.type === "text" || part.type === "reasoning")
|
|
60
|
-
? { ...part, text: part.text + mutation.delta }
|
|
61
|
-
: part,
|
|
62
|
-
);
|
|
63
|
-
return with_revision(assistant, mutation, { parts });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** 按 commit_sequence 重放 Mutation,恢复线性 Message snapshot。 */
|
|
67
|
-
export function reduce_session_messages(
|
|
68
|
-
mutations: SessionMessageMutation[],
|
|
69
|
-
): SessionMessage[] {
|
|
70
|
-
const messages = new Map<string, SessionMessage>();
|
|
71
|
-
const ordered = [...mutations].sort(
|
|
72
|
-
(left, right) => left.commit_sequence - right.commit_sequence,
|
|
73
|
-
);
|
|
74
|
-
let previous_commit_sequence = 0;
|
|
75
|
-
for (const mutation of ordered) {
|
|
76
|
-
if (mutation.commit_sequence <= previous_commit_sequence) {
|
|
77
|
-
throw new Error(`Duplicate commit_sequence: ${String(mutation.commit_sequence)}`);
|
|
78
|
-
}
|
|
79
|
-
messages.set(
|
|
80
|
-
mutation.message_id,
|
|
81
|
-
reduce_session_message(messages.get(mutation.message_id), mutation),
|
|
82
|
-
);
|
|
83
|
-
previous_commit_sequence = mutation.commit_sequence;
|
|
84
|
-
}
|
|
85
|
-
return [...messages.values()].sort(
|
|
86
|
-
(left, right) => left.sequence - right.sequence,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function validate_message_snapshot(
|
|
91
|
-
current_message: SessionMessage | undefined,
|
|
92
|
-
mutation: Extract<SessionMessageMutation, { variant: "message" }>,
|
|
93
|
-
): void {
|
|
94
|
-
if (mutation.message.message_id !== mutation.message_id) {
|
|
95
|
-
throw new Error(`Message Mutation identity mismatch: ${mutation.message_id}`);
|
|
96
|
-
}
|
|
97
|
-
if (mutation.message.type !== mutation.type) {
|
|
98
|
-
throw new Error(`Message Mutation type mismatch: ${mutation.message_id}`);
|
|
99
|
-
}
|
|
100
|
-
if (mutation.message.sequence !== mutation.sequence) {
|
|
101
|
-
throw new Error(`Message Mutation sequence mismatch: ${mutation.message_id}`);
|
|
102
|
-
}
|
|
103
|
-
if (mutation.message.revision !== mutation.revision) {
|
|
104
|
-
throw new Error(`Message Mutation revision mismatch: ${mutation.message_id}`);
|
|
105
|
-
}
|
|
106
|
-
if (!current_message) {
|
|
107
|
-
if (mutation.revision !== 1) {
|
|
108
|
-
throw new Error(`New Message revision must be 1: ${mutation.message_id}`);
|
|
109
|
-
}
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
validate_next_revision(current_message, mutation);
|
|
113
|
-
if (current_message.type !== mutation.type) {
|
|
114
|
-
throw new Error(`Message type changed: ${mutation.message_id}`);
|
|
115
|
-
}
|
|
116
|
-
if (current_message.sequence !== mutation.sequence) {
|
|
117
|
-
throw new Error(`Message sequence changed: ${mutation.message_id}`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function validate_next_revision(
|
|
122
|
-
current_message: SessionMessage,
|
|
123
|
-
mutation: SessionMessageMutation,
|
|
124
|
-
): void {
|
|
125
|
-
if (mutation.revision !== current_message.revision + 1) {
|
|
126
|
-
throw new Error(
|
|
127
|
-
`Invalid Message revision for ${mutation.message_id}: expected ${String(current_message.revision + 1)}, received ${String(mutation.revision)}`,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function require_streaming_assistant(
|
|
133
|
-
message: SessionMessage,
|
|
134
|
-
): SessionAssistantMessage {
|
|
135
|
-
if (message.type !== "assistant") {
|
|
136
|
-
throw new Error(`Session Message is not assistant: ${message.message_id}`);
|
|
137
|
-
}
|
|
138
|
-
if (message.status !== "streaming") {
|
|
139
|
-
throw new Error(`Assistant Message is already closed: ${message.message_id}`);
|
|
140
|
-
}
|
|
141
|
-
return message;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function with_revision<TMessage extends SessionMessage>(
|
|
145
|
-
message: TMessage,
|
|
146
|
-
mutation: SessionMessageMutation,
|
|
147
|
-
changes: object,
|
|
148
|
-
): TMessage {
|
|
149
|
-
return {
|
|
150
|
-
...message,
|
|
151
|
-
...changes,
|
|
152
|
-
revision: mutation.revision,
|
|
153
|
-
updated_at: mutation.created_at,
|
|
154
|
-
} as TMessage;
|
|
155
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SessionMessage mutation 事件总线。
|
|
3
|
-
*
|
|
4
|
-
* EventHub 只广播 Recorder 已成功提交的 mutation,不创建或转换事件。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
SessionMessageMutation,
|
|
9
|
-
SessionMessageMutationSubscriber,
|
|
10
|
-
SessionMessageMutationUnsubscribe,
|
|
11
|
-
} from "@/types/session/SessionMessageMutation.js";
|
|
12
|
-
|
|
13
|
-
/** SessionMessage mutation 的进程内广播器。 */
|
|
14
|
-
export class SessionMessageEventHub {
|
|
15
|
-
private readonly subscribers = new Set<SessionMessageMutationSubscriber>();
|
|
16
|
-
|
|
17
|
-
/** 订阅未来成功提交的 mutation。 */
|
|
18
|
-
subscribe(subscriber: SessionMessageMutationSubscriber): SessionMessageMutationUnsubscribe {
|
|
19
|
-
this.subscribers.add(subscriber);
|
|
20
|
-
return () => {
|
|
21
|
-
this.subscribers.delete(subscriber);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** 广播一条已持久化 mutation。 */
|
|
26
|
-
publish(mutation: SessionMessageMutation): void {
|
|
27
|
-
for (const subscriber of this.subscribers) {
|
|
28
|
-
try {
|
|
29
|
-
subscriber(mutation);
|
|
30
|
-
} catch {
|
|
31
|
-
// 单个订阅者失败不能影响提交结果和其他订阅者。
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Session 事件类型定义。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - `subscribe()` 暴露的是 session 级长期事件序列,而不是单次执行的局部结果。
|
|
6
|
-
* - 事件只表达“当前 turn 正在发生什么”,不负责历史回放。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { JsonValue } from "@/types/common/Json.js";
|
|
10
|
-
import type { SessionAssistantStepVisibility } from "@/executor/types/SessionRun.js";
|
|
11
|
-
import type { AgentSessionActionEvent } from "@/types/sdk/AgentSessionAction.js";
|
|
12
|
-
import type { SessionMessageMutation } from "@/types/session/SessionMessageMutation.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 单个 turn 开始事件。
|
|
16
|
-
*/
|
|
17
|
-
export interface AgentSessionTurnStartEvent {
|
|
18
|
-
/**
|
|
19
|
-
* 当前事件类型。
|
|
20
|
-
*/
|
|
21
|
-
type: "turn-start";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 当前 turn 的稳定标识。
|
|
25
|
-
*
|
|
26
|
-
* 说明(中文)
|
|
27
|
-
* - 同一个 turn 内的全部增量事件都会复用这个 turnId。
|
|
28
|
-
* - 当 Session 排队进入下一轮时,会生成新的 turnId。
|
|
29
|
-
*/
|
|
30
|
-
turnId: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 普通文本增量事件。
|
|
35
|
-
*/
|
|
36
|
-
export interface AgentSessionTextDeltaEvent {
|
|
37
|
-
/**
|
|
38
|
-
* 当前事件类型。
|
|
39
|
-
*/
|
|
40
|
-
type: "text-delta";
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 当前文本所属 turn。
|
|
44
|
-
*/
|
|
45
|
-
turnId: string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 当前这次新增的可见文本片段。
|
|
49
|
-
*/
|
|
50
|
-
text: string;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* reasoning 文本增量事件。
|
|
55
|
-
*/
|
|
56
|
-
export interface AgentSessionReasoningDeltaEvent {
|
|
57
|
-
/**
|
|
58
|
-
* 当前事件类型。
|
|
59
|
-
*/
|
|
60
|
-
type: "reasoning-delta";
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 当前 reasoning 所属 turn。
|
|
64
|
-
*/
|
|
65
|
-
turnId: string;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 当前这次新增的 reasoning 文本片段。
|
|
69
|
-
*/
|
|
70
|
-
text: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 工具调用事件。
|
|
75
|
-
*/
|
|
76
|
-
export interface AgentSessionToolCallEvent {
|
|
77
|
-
/**
|
|
78
|
-
* 当前事件类型。
|
|
79
|
-
*/
|
|
80
|
-
type: "tool-call";
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 当前工具调用所属 turn。
|
|
84
|
-
*/
|
|
85
|
-
turnId: string;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 当前工具调用唯一标识。
|
|
89
|
-
*/
|
|
90
|
-
toolCallId: string;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 当前工具名称。
|
|
94
|
-
*/
|
|
95
|
-
toolName: "shell_exec" | "shell_session" | "shell_write" | string;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 当前工具输入参数。
|
|
99
|
-
*/
|
|
100
|
-
args: JsonValue;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 工具结果事件。
|
|
105
|
-
*/
|
|
106
|
-
export interface AgentSessionToolResultEvent {
|
|
107
|
-
/**
|
|
108
|
-
* 当前事件类型。
|
|
109
|
-
*/
|
|
110
|
-
type: "tool-result";
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 当前工具结果所属 turn。
|
|
114
|
-
*/
|
|
115
|
-
turnId: string;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 当前工具调用唯一标识。
|
|
119
|
-
*/
|
|
120
|
-
toolCallId: string;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* 当前工具名称。
|
|
124
|
-
*/
|
|
125
|
-
toolName: "shell_exec" | "shell_session" | "shell_write" | string;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 当前工具输出结果。
|
|
129
|
-
*/
|
|
130
|
-
result: JsonValue;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 工具审批请求事件。
|
|
135
|
-
*/
|
|
136
|
-
export interface AgentSessionToolApprovalRequestEvent {
|
|
137
|
-
/**
|
|
138
|
-
* 当前事件类型。
|
|
139
|
-
*/
|
|
140
|
-
type: "tool-approval-request";
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 当前审批所属 turn。
|
|
144
|
-
*/
|
|
145
|
-
turnId: string;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 当前工具调用唯一标识。
|
|
149
|
-
*/
|
|
150
|
-
toolCallId: string;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* 当前工具名称。
|
|
154
|
-
*/
|
|
155
|
-
toolName: "shell_exec" | "shell_session" | "shell_write" | string;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 当前审批请求唯一标识。
|
|
159
|
-
*/
|
|
160
|
-
approvalId: string;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 请求执行的 sandbox 模式。
|
|
164
|
-
*/
|
|
165
|
-
sandbox: "unrestricted";
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* 请求执行的命令文本。
|
|
169
|
-
*
|
|
170
|
-
* 说明(中文)
|
|
171
|
-
* - `shell_exec` / `shell_session` start 中是命令文本。
|
|
172
|
-
* - `shell_write` 中是 stdin 写入内容,用于兼容内部审批展示。
|
|
173
|
-
*/
|
|
174
|
-
cmd: string;
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* 当前审批动作类型。
|
|
178
|
-
*/
|
|
179
|
-
operation?: "exec" | "start" | "write";
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 关联 shell_id;session 输入审批时用于标识目标会话。
|
|
183
|
-
*/
|
|
184
|
-
shellId?: string;
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* stdin 写入内容预览;仅 session 输入审批存在。
|
|
188
|
-
*/
|
|
189
|
-
inputPreview?: string;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* stdin 写入字符数;仅 session 输入审批存在。
|
|
193
|
-
*/
|
|
194
|
-
inputChars?: number;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* 命令执行目录。
|
|
198
|
-
*/
|
|
199
|
-
cwd: string;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Agent 给用户展示的申请原因。
|
|
203
|
-
*/
|
|
204
|
-
reason: string;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* 当前审批状态。
|
|
208
|
-
*/
|
|
209
|
-
status: "pending";
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* 工具审批结果事件。
|
|
214
|
-
*/
|
|
215
|
-
export interface AgentSessionToolApprovalResultEvent {
|
|
216
|
-
/**
|
|
217
|
-
* 当前事件类型。
|
|
218
|
-
*/
|
|
219
|
-
type: "tool-approval-result";
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* 当前审批所属 turn。
|
|
223
|
-
*/
|
|
224
|
-
turnId: string;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* 当前工具调用唯一标识。
|
|
228
|
-
*/
|
|
229
|
-
toolCallId: string;
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* 当前工具名称。
|
|
233
|
-
*/
|
|
234
|
-
toolName: "shell_exec" | "shell_session" | "shell_write" | string;
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* 当前审批请求唯一标识。
|
|
238
|
-
*/
|
|
239
|
-
approvalId: string;
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* 用户最终决策。
|
|
243
|
-
*/
|
|
244
|
-
decision: "approved" | "denied" | "expired";
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* assistant step 完成事件。
|
|
249
|
-
*/
|
|
250
|
-
export interface AgentSessionAssistantStepEvent {
|
|
251
|
-
/**
|
|
252
|
-
* 当前事件类型。
|
|
253
|
-
*/
|
|
254
|
-
type: "assistant-step";
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* 当前 assistant step 所属 turn。
|
|
258
|
-
*/
|
|
259
|
-
turnId: string;
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* 当前 step 文本。
|
|
263
|
-
*/
|
|
264
|
-
text: string;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* 当前 step 序号(从 1 开始)。
|
|
268
|
-
*/
|
|
269
|
-
stepIndex: number;
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* 当前 step 可见性。
|
|
273
|
-
*/
|
|
274
|
-
visibility?: SessionAssistantStepVisibility;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Session 标题更新事件。
|
|
279
|
-
*/
|
|
280
|
-
export interface AgentSessionTitleEvent {
|
|
281
|
-
/**
|
|
282
|
-
* 当前事件类型。
|
|
283
|
-
*/
|
|
284
|
-
type: "session-title";
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* 当前 session 唯一标识。
|
|
288
|
-
*/
|
|
289
|
-
sessionId: string;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* 当前 session 最新标题。
|
|
293
|
-
*
|
|
294
|
-
* 说明(中文)
|
|
295
|
-
* - 标题已持久化到 session meta。
|
|
296
|
-
* - 新 session 通常在首条 user message 落盘后生成标题。
|
|
297
|
-
*/
|
|
298
|
-
title: string;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* 单个 turn 完成事件。
|
|
303
|
-
*/
|
|
304
|
-
export interface AgentSessionTurnFinishEvent {
|
|
305
|
-
/**
|
|
306
|
-
* 当前事件类型。
|
|
307
|
-
*/
|
|
308
|
-
type: "turn-finish";
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* 当前已完成 turn 的稳定标识。
|
|
312
|
-
*/
|
|
313
|
-
turnId: string;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* 当前 turn 最终可见文本。
|
|
317
|
-
*/
|
|
318
|
-
text: string;
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* 当前 turn 是否成功结束。
|
|
322
|
-
*/
|
|
323
|
-
success: boolean;
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* 当前 turn 失败时的错误文本。
|
|
327
|
-
*/
|
|
328
|
-
error?: string;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Session 级错误事件。
|
|
333
|
-
*/
|
|
334
|
-
export interface AgentSessionErrorEvent {
|
|
335
|
-
/**
|
|
336
|
-
* 当前事件类型。
|
|
337
|
-
*/
|
|
338
|
-
type: "error";
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* 当前错误文本。
|
|
342
|
-
*/
|
|
343
|
-
message: string;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Session 订阅可见事件联合类型。
|
|
348
|
-
*/
|
|
349
|
-
export type AgentSessionEvent =
|
|
350
|
-
| SessionMessageMutation
|
|
351
|
-
| AgentSessionTurnStartEvent
|
|
352
|
-
| AgentSessionTextDeltaEvent
|
|
353
|
-
| AgentSessionReasoningDeltaEvent
|
|
354
|
-
| AgentSessionToolCallEvent
|
|
355
|
-
| AgentSessionToolResultEvent
|
|
356
|
-
| AgentSessionToolApprovalRequestEvent
|
|
357
|
-
| AgentSessionToolApprovalResultEvent
|
|
358
|
-
| AgentSessionAssistantStepEvent
|
|
359
|
-
| AgentSessionTitleEvent
|
|
360
|
-
| AgentSessionActionEvent
|
|
361
|
-
| AgentSessionTurnFinishEvent
|
|
362
|
-
| AgentSessionErrorEvent;
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Session 事件订阅回调。
|
|
366
|
-
*/
|
|
367
|
-
export type AgentSessionSubscriber = (event: AgentSessionEvent) => void;
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* 取消 Session 订阅的返回函数。
|
|
371
|
-
*/
|
|
372
|
-
export type AgentSessionUnsubscribe = () => void;
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session Message Mutation 与增量读取类型。
|
|
3
|
-
*
|
|
4
|
-
* Mutation 只按变化层级分成 message、part、delta 三种 variant;`type` 在各 variant
|
|
5
|
-
* 内直接表达对应的 Message 或 Part 类型。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { SessionAssistantMessagePart, SessionMessage } from "@/types/session/SessionMessage.js";
|
|
9
|
-
|
|
10
|
-
/** Mutation 公共字段。 */
|
|
11
|
-
export interface SessionMessageMutationBase {
|
|
12
|
-
/** Mutation 稳定唯一标识。 */
|
|
13
|
-
mutation_id: string;
|
|
14
|
-
/** Mutation 在 Session 内的单调提交序号。 */
|
|
15
|
-
commit_sequence: number;
|
|
16
|
-
/** Mutation 目标 Message。 */
|
|
17
|
-
message_id: string;
|
|
18
|
-
/** 应用 Mutation 后的 Message revision。 */
|
|
19
|
-
revision: number;
|
|
20
|
-
/** Mutation 所属 Session。 */
|
|
21
|
-
session_id: string;
|
|
22
|
-
/** Mutation 所属 turn。 */
|
|
23
|
-
turn_id?: string;
|
|
24
|
-
/** Mutation 创建时间戳(ms)。 */
|
|
25
|
-
created_at: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** 顶层 Message 创建或状态更新 Mutation。 */
|
|
29
|
-
export type SessionMessageSnapshotMutation = {
|
|
30
|
-
[TType in SessionMessage["type"]]: SessionMessageMutationBase & {
|
|
31
|
-
/** Mutation 层级固定为 message。 */
|
|
32
|
-
variant: "message";
|
|
33
|
-
/** 当前完整 Message 类型。 */
|
|
34
|
-
type: TType;
|
|
35
|
-
/** Message 在线性 Session 中的固定位置。 */
|
|
36
|
-
sequence: number;
|
|
37
|
-
/** 创建或更新后的完整 Message 快照。 */
|
|
38
|
-
message: Extract<SessionMessage, { type: TType }>;
|
|
39
|
-
};
|
|
40
|
-
}[SessionMessage["type"]];
|
|
41
|
-
|
|
42
|
-
/** Assistant Part 创建或状态更新 Mutation。 */
|
|
43
|
-
export type SessionPartSnapshotMutation = {
|
|
44
|
-
[TType in SessionAssistantMessagePart["type"]]: SessionMessageMutationBase & {
|
|
45
|
-
/** Mutation 层级固定为 part。 */
|
|
46
|
-
variant: "part";
|
|
47
|
-
/** 当前完整 Part 类型。 */
|
|
48
|
-
type: TType;
|
|
49
|
-
/** 被创建或更新的 Part 标识。 */
|
|
50
|
-
part_id: string;
|
|
51
|
-
/** 创建或更新后的完整 Part 快照。 */
|
|
52
|
-
part: SessionAssistantMessagePart & { type: TType };
|
|
53
|
-
};
|
|
54
|
-
}[SessionAssistantMessagePart["type"]];
|
|
55
|
-
|
|
56
|
-
/** Assistant 文本或推理原始增量 Mutation。 */
|
|
57
|
-
export interface SessionDeltaMutation extends SessionMessageMutationBase {
|
|
58
|
-
/** Mutation 层级固定为 delta。 */
|
|
59
|
-
variant: "delta";
|
|
60
|
-
/** Delta 类型只允许 text 或 reasoning。 */
|
|
61
|
-
type: "text" | "reasoning";
|
|
62
|
-
/** Delta 所属 Part 标识。 */
|
|
63
|
-
part_id: string;
|
|
64
|
-
/** 本次模型新增的原始文本,不是累计全文。 */
|
|
65
|
-
delta: string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** 全部合法 Session Message Mutation。 */
|
|
69
|
-
export type SessionMessageMutation =
|
|
70
|
-
| SessionMessageSnapshotMutation
|
|
71
|
-
| SessionPartSnapshotMutation
|
|
72
|
-
| SessionDeltaMutation;
|
|
73
|
-
|
|
74
|
-
/** 从 commit cursor 增量读取 Mutation 的输入。 */
|
|
75
|
-
export interface ListSessionMessageChangesInput {
|
|
76
|
-
/** 只返回 commit_sequence 严格大于该值的 Mutation。 */
|
|
77
|
-
after_commit_sequence: number;
|
|
78
|
-
/** 单页数量上限。 */
|
|
79
|
-
limit?: number;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Mutation 增量分页结果。 */
|
|
83
|
-
export interface SessionMessageMutationPage {
|
|
84
|
-
/** 当前页按 commit_sequence 升序排列的 Mutation。 */
|
|
85
|
-
items: SessionMessageMutation[];
|
|
86
|
-
/** 当前页之后是否仍有 Mutation。 */
|
|
87
|
-
has_more: boolean;
|
|
88
|
-
/** 下一次增量读取应使用的 commit_sequence。 */
|
|
89
|
-
next_commit_sequence: number;
|
|
90
|
-
/** 当前 Session 已提交的最大 commit_sequence。 */
|
|
91
|
-
latest_commit_sequence: number;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Session Mutation 订阅回调。 */
|
|
95
|
-
export type SessionMessageMutationSubscriber = (mutation: SessionMessageMutation) => void;
|
|
96
|
-
|
|
97
|
-
/** 取消 Session Mutation 订阅的函数。 */
|
|
98
|
-
export type SessionMessageMutationUnsubscribe = () => void;
|
|
99
|
-
|
|
100
|
-
/** 判断未知事件是否为 Session Message Mutation。 */
|
|
101
|
-
export function is_session_message_mutation(input: unknown): input is SessionMessageMutation {
|
|
102
|
-
if (!input || typeof input !== "object") return false;
|
|
103
|
-
const candidate = input as {
|
|
104
|
-
variant?: unknown;
|
|
105
|
-
type?: unknown;
|
|
106
|
-
mutation_id?: unknown;
|
|
107
|
-
commit_sequence?: unknown;
|
|
108
|
-
};
|
|
109
|
-
if (
|
|
110
|
-
typeof candidate.mutation_id !== "string" ||
|
|
111
|
-
typeof candidate.commit_sequence !== "number" ||
|
|
112
|
-
typeof candidate.type !== "string"
|
|
113
|
-
) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
return (
|
|
117
|
-
candidate.variant === "message" ||
|
|
118
|
-
candidate.variant === "part" ||
|
|
119
|
-
candidate.variant === "delta"
|
|
120
|
-
);
|
|
121
|
-
}
|