@downcity/agent 1.1.216 → 1.1.222
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 +2 -0
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +6 -0
- package/bin/agent/local/Agent.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 +8 -1
- package/bin/agent/local/services/AgentSessions.js.map +1 -1
- package/bin/agent/remote/RemoteSession.d.ts +11 -7
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +36 -11
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +9 -3
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +6 -2
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +38 -11
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +6 -2
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +8 -2
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +2 -0
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/executor/types/SessionRecords.d.ts +2 -0
- package/bin/executor/types/SessionRecords.d.ts.map +1 -1
- package/bin/executor/types/SessionRecords.js.map +1 -1
- package/bin/index.d.ts +5 -2
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -0
- package/bin/index.js.map +1 -1
- package/bin/rpc/Client.d.ts +18 -4
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +25 -3
- package/bin/rpc/Client.js.map +1 -1
- package/bin/session/Session.d.ts +13 -3
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +48 -18
- package/bin/session/Session.js.map +1 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +3 -0
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts +45 -0
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts.map +1 -0
- package/bin/session/recorder/JsonlSessionMessageStore.js +127 -0
- package/bin/session/recorder/JsonlSessionMessageStore.js.map +1 -0
- package/bin/session/recorder/SessionMessageCodec.d.ts +20 -0
- package/bin/session/recorder/SessionMessageCodec.d.ts.map +1 -0
- package/bin/session/recorder/SessionMessageCodec.js +252 -0
- package/bin/session/recorder/SessionMessageCodec.js.map +1 -0
- package/bin/session/recorder/SessionMessageReducer.d.ts +12 -0
- package/bin/session/recorder/SessionMessageReducer.d.ts.map +1 -0
- package/bin/session/recorder/SessionMessageReducer.js +109 -0
- package/bin/session/recorder/SessionMessageReducer.js.map +1 -0
- package/bin/session/recorder/SessionRecorder.d.ts +177 -0
- package/bin/session/recorder/SessionRecorder.d.ts.map +1 -0
- package/bin/session/recorder/SessionRecorder.js +610 -0
- package/bin/session/recorder/SessionRecorder.js.map +1 -0
- package/bin/session/recorder/SessionRecorderCompaction.d.ts +18 -0
- package/bin/session/recorder/SessionRecorderCompaction.d.ts.map +1 -0
- package/bin/session/recorder/SessionRecorderCompaction.js +141 -0
- package/bin/session/recorder/SessionRecorderCompaction.js.map +1 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts +66 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts.map +1 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.js +195 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.js.map +1 -0
- package/bin/session/runtime/SessionMessageEventHub.d.ts +15 -0
- package/bin/session/runtime/SessionMessageEventHub.d.ts.map +1 -0
- package/bin/session/runtime/SessionMessageEventHub.js +28 -0
- package/bin/session/runtime/SessionMessageEventHub.js.map +1 -0
- package/bin/session/runtime/SessionPromptRuntime.d.ts +7 -13
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.js +13 -13
- package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
- package/bin/session/services/SessionStateService.d.ts +15 -3
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +165 -76
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionTurnService.d.ts +4 -0
- package/bin/session/services/SessionTurnService.d.ts.map +1 -1
- package/bin/session/services/SessionTurnService.js +82 -52
- package/bin/session/services/SessionTurnService.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts +8 -3
- package/bin/session/services/SessionViewService.d.ts.map +1 -1
- package/bin/session/services/SessionViewService.js +13 -5
- package/bin/session/services/SessionViewService.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +2 -0
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +10 -0
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/Persistence.d.ts +6 -0
- package/bin/session/storage/Persistence.d.ts.map +1 -1
- package/bin/session/storage/Persistence.js +12 -0
- package/bin/session/storage/Persistence.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +3 -2
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +10 -0
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +12 -4
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +13 -1
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +32 -6
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +4 -3
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/bin/types/sdk/AgentSessionEvent.d.ts +2 -1
- package/bin/types/sdk/AgentSessionEvent.d.ts.map +1 -1
- package/bin/types/session/SessionMessage.d.ts +217 -0
- package/bin/types/session/SessionMessage.d.ts.map +1 -0
- package/bin/types/session/SessionMessage.js +8 -0
- package/bin/types/session/SessionMessage.js.map +1 -0
- package/bin/types/session/SessionMessageMutation.d.ts +92 -0
- package/bin/types/session/SessionMessageMutation.d.ts.map +1 -0
- package/bin/types/session/SessionMessageMutation.js +21 -0
- package/bin/types/session/SessionMessageMutation.js.map +1 -0
- package/bin/types/session/SessionOptions.d.ts +3 -0
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/package.json +3 -3
- package/scripts/agent-env.test.mjs +4 -4
- package/scripts/remote-session-reconnect.test.mjs +33 -0
- package/scripts/session-action-message.test.mjs +148 -27
- package/scripts/session-list-title.test.mjs +6 -19
- package/scripts/session-prompt-runtime.test.mjs +4 -16
- package/scripts/session-recorder.test.mjs +245 -0
- package/scripts/session-title-event.test.mjs +10 -18
- package/src/agent/local/Agent.ts +6 -0
- package/src/agent/local/services/AgentSessions.ts +14 -1
- package/src/agent/remote/RemoteSession.ts +52 -16
- package/src/agent/remote/RemoteTransport.ts +20 -6
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +67 -13
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +27 -6
- package/src/executor/types/SessionHistoryMeta.ts +2 -0
- package/src/executor/types/SessionRecords.ts +2 -0
- package/src/index.ts +23 -5
- package/src/rpc/Client.ts +47 -8
- package/src/session/Session.ts +66 -31
- package/src/session/browse/Browse.ts +3 -0
- package/src/session/recorder/JsonlSessionMessageStore.ts +162 -0
- package/src/session/recorder/SessionMessageCodec.ts +279 -0
- package/src/session/recorder/SessionMessageReducer.ts +155 -0
- package/src/session/recorder/SessionRecorder.ts +812 -0
- package/src/session/recorder/SessionRecorderCompaction.ts +187 -0
- package/src/session/recorder/SessionRecorderHistoryStore.ts +276 -0
- package/src/session/runtime/SessionMessageEventHub.ts +35 -0
- package/src/session/runtime/SessionPromptRuntime.ts +23 -24
- package/src/session/services/SessionStateService.ts +189 -84
- package/src/session/services/SessionTurnService.ts +88 -59
- package/src/session/services/SessionViewService.ts +28 -13
- package/src/session/storage/Metadata.ts +13 -0
- package/src/session/storage/Persistence.ts +18 -0
- package/src/session/storage/RuntimeSessionPort.ts +6 -4
- package/src/types/agent/AgentOptions.ts +12 -0
- package/src/types/agent/SessionActor.ts +28 -5
- package/src/types/agent/SessionTypes.ts +13 -1
- package/src/types/rpc/RpcProtocol.ts +34 -6
- package/src/types/runtime/agent/AgentContext.ts +8 -2
- package/src/types/sdk/AgentSessionEvent.ts +2 -0
- package/src/types/session/SessionMessage.ts +247 -0
- package/src/types/session/SessionMessageMutation.ts +121 -0
- package/src/types/session/SessionOptions.ts +4 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/session/SessionEventMapper.d.ts +0 -32
- package/bin/session/SessionEventMapper.d.ts.map +0 -1
- package/bin/session/SessionEventMapper.js +0 -131
- package/bin/session/SessionEventMapper.js.map +0 -1
- package/bin/types/sdk/InternalUiChunkEvent.d.ts +0 -100
- package/bin/types/sdk/InternalUiChunkEvent.d.ts.map +0 -1
- package/bin/types/sdk/InternalUiChunkEvent.js +0 -9
- package/bin/types/sdk/InternalUiChunkEvent.js.map +0 -1
- package/scripts/session-history-archive.test.mjs +0 -188
- package/src/session/SessionEventMapper.ts +0 -148
- package/src/types/sdk/InternalUiChunkEvent.ts +0 -108
|
@@ -17,7 +17,7 @@ import { getSdkAgentSessionArchiveFilePath } from "@/session/storage/Paths.js";
|
|
|
17
17
|
import { ensureSessionTitle } from "@/session/SessionTitle.js";
|
|
18
18
|
import { readSessionMetadata } from "@/session/storage/Metadata.js";
|
|
19
19
|
import { buildSessionSystemBlocks } from "@/session/SessionSystemBuilder.js";
|
|
20
|
-
import type {
|
|
20
|
+
import type { SessionHistoryStore } from "@/executor/store/history/SessionHistoryStore.js";
|
|
21
21
|
import type { SessionSystemComposer } from "@/executor/composer/system/SessionSystemComposer.js";
|
|
22
22
|
import type {
|
|
23
23
|
AgentSessionForkInput,
|
|
@@ -32,6 +32,8 @@ import type { SessionRecordV1 } from "@/executor/types/SessionRecords.js";
|
|
|
32
32
|
import { SessionStateService } from "@/session/services/SessionStateService.js";
|
|
33
33
|
import type { SessionRunContext } from "@/types/executor/SessionRunContext.js";
|
|
34
34
|
import type { Logger } from "@/utils/logger/Logger.js";
|
|
35
|
+
import { SessionRecorder } from "@/session/recorder/SessionRecorder.js";
|
|
36
|
+
import type { SessionMessage } from "@/types/session/SessionMessage.js";
|
|
35
37
|
|
|
36
38
|
type SessionViewServiceOptions<TSession extends Pick<AgentSession, "set">> = {
|
|
37
39
|
/**
|
|
@@ -52,7 +54,10 @@ type SessionViewServiceOptions<TSession extends Pick<AgentSession, "set">> = {
|
|
|
52
54
|
/**
|
|
53
55
|
* 当前 session 历史事实源。
|
|
54
56
|
*/
|
|
55
|
-
history_store:
|
|
57
|
+
history_store: SessionHistoryStore;
|
|
58
|
+
|
|
59
|
+
/** 当前 Session Message Recorder。 */
|
|
60
|
+
recorder: SessionRecorder;
|
|
56
61
|
|
|
57
62
|
/**
|
|
58
63
|
* 当前 session 状态服务。
|
|
@@ -98,7 +103,8 @@ type SessionViewServiceOptions<TSession extends Pick<AgentSession, "set">> = {
|
|
|
98
103
|
*/
|
|
99
104
|
create_fork_session: (session_id: string) => Promise<{
|
|
100
105
|
session: TSession;
|
|
101
|
-
history_store:
|
|
106
|
+
history_store: SessionHistoryStore;
|
|
107
|
+
recorder: SessionRecorder;
|
|
102
108
|
state_service: SessionStateService;
|
|
103
109
|
}>;
|
|
104
110
|
};
|
|
@@ -110,7 +116,8 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
110
116
|
private readonly agent_id: string;
|
|
111
117
|
private readonly project_root: string;
|
|
112
118
|
private readonly session_id: string;
|
|
113
|
-
private readonly history_store:
|
|
119
|
+
private readonly history_store: SessionHistoryStore;
|
|
120
|
+
private readonly recorder: SessionRecorder;
|
|
114
121
|
private readonly state_service: SessionStateService;
|
|
115
122
|
private readonly logger: Logger;
|
|
116
123
|
private readonly is_executing: SessionViewServiceOptions<TSession>["is_executing"];
|
|
@@ -125,6 +132,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
125
132
|
this.project_root = options.project_root;
|
|
126
133
|
this.session_id = options.session_id;
|
|
127
134
|
this.history_store = options.history_store;
|
|
135
|
+
this.recorder = options.recorder;
|
|
128
136
|
this.state_service = options.state_service;
|
|
129
137
|
this.logger = options.logger;
|
|
130
138
|
this.is_executing = options.is_executing;
|
|
@@ -282,11 +290,14 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
282
290
|
typeof input === "string"
|
|
283
291
|
? String(input || "").trim() || undefined
|
|
284
292
|
: String(input?.messageId || "").trim() || undefined;
|
|
285
|
-
const
|
|
293
|
+
const message_page = await this.recorder.list_messages({
|
|
294
|
+
limit: 500,
|
|
295
|
+
include_internal: true,
|
|
296
|
+
});
|
|
286
297
|
const fork_messages =
|
|
287
298
|
!message_id
|
|
288
|
-
?
|
|
289
|
-
: this.resolve_fork_messages(
|
|
299
|
+
? message_page.items
|
|
300
|
+
: this.resolve_fork_messages(message_page.items, message_id);
|
|
290
301
|
const action_id = `history-forking:${this.session_id}:${Date.now()}:${nanoid(8)}`;
|
|
291
302
|
|
|
292
303
|
await this.state_service.emit_action_event({
|
|
@@ -306,6 +317,9 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
306
317
|
await forked_bundle.state_service.set(
|
|
307
318
|
{
|
|
308
319
|
model: session_config.model,
|
|
320
|
+
...(session_config.modelId
|
|
321
|
+
? { modelId: session_config.modelId }
|
|
322
|
+
: {}),
|
|
309
323
|
},
|
|
310
324
|
{ emit_action: false },
|
|
311
325
|
);
|
|
@@ -330,11 +344,11 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
330
344
|
}
|
|
331
345
|
|
|
332
346
|
private resolve_fork_messages(
|
|
333
|
-
messages:
|
|
347
|
+
messages: SessionMessage[],
|
|
334
348
|
message_id: string,
|
|
335
|
-
):
|
|
349
|
+
): SessionMessage[] {
|
|
336
350
|
const target_index = messages.findIndex(
|
|
337
|
-
(message) =>
|
|
351
|
+
(message) => message.message_id === message_id,
|
|
338
352
|
);
|
|
339
353
|
if (target_index < 0) {
|
|
340
354
|
throw new Error(
|
|
@@ -346,12 +360,13 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
346
360
|
|
|
347
361
|
private async append_fork_messages(
|
|
348
362
|
forked_bundle: {
|
|
349
|
-
history_store:
|
|
363
|
+
history_store: SessionHistoryStore;
|
|
364
|
+
recorder: SessionRecorder;
|
|
350
365
|
state_service: SessionStateService;
|
|
351
366
|
},
|
|
352
|
-
messages:
|
|
367
|
+
messages: SessionMessage[],
|
|
353
368
|
): Promise<void> {
|
|
354
|
-
await forked_bundle.
|
|
369
|
+
await forked_bundle.recorder.import_messages(messages);
|
|
355
370
|
}
|
|
356
371
|
|
|
357
372
|
private stringify_system_content(content: unknown): string {
|
|
@@ -33,6 +33,11 @@ function normalizeModelLabel(input: unknown): string | undefined {
|
|
|
33
33
|
return label || undefined;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
function normalize_model_id(input: unknown): string | undefined {
|
|
37
|
+
const model_id = typeof input === "string" ? input.trim() : "";
|
|
38
|
+
return model_id || undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
36
41
|
/**
|
|
37
42
|
* 归一化 session 标题。
|
|
38
43
|
*/
|
|
@@ -153,6 +158,9 @@ export async function readSessionMetadataFromPath(input: {
|
|
|
153
158
|
...(normalizeModelLabel(raw.modelLabel)
|
|
154
159
|
? { modelLabel: normalizeModelLabel(raw.modelLabel) }
|
|
155
160
|
: {}),
|
|
161
|
+
...(normalize_model_id(raw.modelId)
|
|
162
|
+
? { modelId: normalize_model_id(raw.modelId) }
|
|
163
|
+
: {}),
|
|
156
164
|
...(normalize_message_count(raw.messageCount) !== undefined
|
|
157
165
|
? { messageCount: normalize_message_count(raw.messageCount) }
|
|
158
166
|
: {}),
|
|
@@ -204,6 +212,8 @@ export async function patchSessionModelLabel(
|
|
|
204
212
|
* 当前模型实例。
|
|
205
213
|
*/
|
|
206
214
|
model?: LanguageModel;
|
|
215
|
+
/** 当前模型稳定 ID。 */
|
|
216
|
+
modelId?: string;
|
|
207
217
|
},
|
|
208
218
|
): Promise<SessionHistoryMetaV1> {
|
|
209
219
|
const current = await readSessionMetadata(input);
|
|
@@ -220,6 +230,9 @@ export async function patchSessionModelLabel(
|
|
|
220
230
|
modelLabel,
|
|
221
231
|
}
|
|
222
232
|
: {}),
|
|
233
|
+
...(normalize_model_id(input.modelId)
|
|
234
|
+
? { modelId: normalize_model_id(input.modelId) }
|
|
235
|
+
: {}),
|
|
223
236
|
};
|
|
224
237
|
await writeSessionMetadata({
|
|
225
238
|
...input,
|
|
@@ -39,6 +39,12 @@ export interface TouchSessionMetadataParams {
|
|
|
39
39
|
* 当前 session 内存配置快照。
|
|
40
40
|
*/
|
|
41
41
|
sessionConfig: AgentSessionConfigSnapshot;
|
|
42
|
+
/** 当前 canonical Message 总数。 */
|
|
43
|
+
message_count?: number;
|
|
44
|
+
/** 当前 Message 日志文件字节数。 */
|
|
45
|
+
history_bytes?: number;
|
|
46
|
+
/** 最近一条用户可见 Message 的文本摘要。 */
|
|
47
|
+
preview_text?: string;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
/**
|
|
@@ -93,6 +99,18 @@ export async function touchSessionMetadata(
|
|
|
93
99
|
modelLabel: params.sessionConfig.modelLabel,
|
|
94
100
|
}
|
|
95
101
|
: {}),
|
|
102
|
+
...(params.sessionConfig.modelId
|
|
103
|
+
? {
|
|
104
|
+
modelId: params.sessionConfig.modelId,
|
|
105
|
+
}
|
|
106
|
+
: {}),
|
|
107
|
+
...(typeof params.message_count === "number"
|
|
108
|
+
? { messageCount: params.message_count }
|
|
109
|
+
: {}),
|
|
110
|
+
...(typeof params.history_bytes === "number"
|
|
111
|
+
? { historyBytes: params.history_bytes }
|
|
112
|
+
: {}),
|
|
113
|
+
...(params.preview_text ? { previewText: params.preview_text } : {}),
|
|
96
114
|
};
|
|
97
115
|
await writeSessionMetadata({
|
|
98
116
|
projectRoot: params.projectRoot,
|
|
@@ -12,9 +12,11 @@ import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js"
|
|
|
12
12
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
13
13
|
import type {
|
|
14
14
|
AgentSessionEvent,
|
|
15
|
-
AgentSessionSubscriber,
|
|
16
|
-
AgentSessionUnsubscribe,
|
|
17
15
|
} from "@/types/sdk/AgentSessionEvent.js";
|
|
16
|
+
import type {
|
|
17
|
+
SessionMessageMutationSubscriber,
|
|
18
|
+
SessionMessageMutationUnsubscribe,
|
|
19
|
+
} from "@/types/session/SessionMessageMutation.js";
|
|
18
20
|
import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -41,8 +43,8 @@ export interface CreateRuntimeSessionPortParams {
|
|
|
41
43
|
* 订阅当前 session 的 future 事件。
|
|
42
44
|
*/
|
|
43
45
|
subscribe: (
|
|
44
|
-
subscriber:
|
|
45
|
-
) =>
|
|
46
|
+
subscriber: SessionMessageMutationSubscriber,
|
|
47
|
+
) => SessionMessageMutationUnsubscribe;
|
|
46
48
|
/**
|
|
47
49
|
* 发布一条 session runtime 事件。
|
|
48
50
|
*/
|
|
@@ -82,6 +82,18 @@ export interface AgentOptions {
|
|
|
82
82
|
*/
|
|
83
83
|
model?: AgentModel;
|
|
84
84
|
|
|
85
|
+
/** 当前 Agent 默认模型对应的稳定 ID。 */
|
|
86
|
+
model_id?: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 按稳定 ID 解析 Session 运行时模型。
|
|
90
|
+
*
|
|
91
|
+
* 关键点(中文)
|
|
92
|
+
* - Session 热切换与进程重启后的恢复统一使用该 resolver。
|
|
93
|
+
* - SDK 不维护模型目录,具体目录与鉴权由宿主负责。
|
|
94
|
+
*/
|
|
95
|
+
resolve_model?: (model_id: string) => Promise<AgentModel>;
|
|
96
|
+
|
|
85
97
|
/**
|
|
86
98
|
* 当前 agent 显式持有的插件实例集合。
|
|
87
99
|
*
|
|
@@ -16,8 +16,6 @@ import type {
|
|
|
16
16
|
AgentListSessionsInput,
|
|
17
17
|
AgentSessionConfigSnapshot,
|
|
18
18
|
AgentSessionForkInput,
|
|
19
|
-
AgentSessionRecordsInput,
|
|
20
|
-
AgentSessionRecordsPage,
|
|
21
19
|
AgentSessionInfo,
|
|
22
20
|
AgentSessionSetInput,
|
|
23
21
|
AgentSessionSummaryPage,
|
|
@@ -27,6 +25,16 @@ import type {
|
|
|
27
25
|
AgentSessionSubscriber,
|
|
28
26
|
AgentSessionUnsubscribe,
|
|
29
27
|
} from "@/types/sdk/AgentSessionEvent.js";
|
|
28
|
+
import type {
|
|
29
|
+
ListSessionMessageChangesInput,
|
|
30
|
+
SessionMessageMutationPage,
|
|
31
|
+
SessionMessageMutationSubscriber,
|
|
32
|
+
SessionMessageMutationUnsubscribe,
|
|
33
|
+
} from "@/types/session/SessionMessageMutation.js";
|
|
34
|
+
import type {
|
|
35
|
+
ListSessionMessagesInput,
|
|
36
|
+
SessionMessagePage,
|
|
37
|
+
} from "@/types/session/SessionMessage.js";
|
|
30
38
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
31
39
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
32
40
|
import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
|
|
@@ -71,10 +79,22 @@ export interface AgentSessionActor {
|
|
|
71
79
|
stop(): Promise<AgentSessionStopResult>;
|
|
72
80
|
|
|
73
81
|
/** 订阅当前 session 的未来事件。 */
|
|
74
|
-
subscribe(
|
|
82
|
+
subscribe(
|
|
83
|
+
subscriber: SessionMessageMutationSubscriber,
|
|
84
|
+
): SessionMessageMutationUnsubscribe;
|
|
85
|
+
|
|
86
|
+
/** 订阅远程 transport 使用的 Message 与 turn lifecycle 事件。 */
|
|
87
|
+
subscribe_transport(
|
|
88
|
+
subscriber: AgentSessionSubscriber,
|
|
89
|
+
): AgentSessionUnsubscribe;
|
|
75
90
|
|
|
76
|
-
/** 读取当前 session
|
|
77
|
-
|
|
91
|
+
/** 读取当前 session messages 分页。 */
|
|
92
|
+
messages(input?: ListSessionMessagesInput): Promise<SessionMessagePage>;
|
|
93
|
+
|
|
94
|
+
/** 读取指定 cursor 后的 Message Mutation。 */
|
|
95
|
+
message_changes(
|
|
96
|
+
input: ListSessionMessageChangesInput,
|
|
97
|
+
): Promise<SessionMessageMutationPage>;
|
|
78
98
|
|
|
79
99
|
/** 读取当前 session 生效的 system 快照。 */
|
|
80
100
|
system(): Promise<AgentSessionSystemSnapshot>;
|
|
@@ -101,6 +121,9 @@ export interface AgentSession extends AgentSessionActor {
|
|
|
101
121
|
* 远程 Agent 返回的公开 session 接口。
|
|
102
122
|
*/
|
|
103
123
|
export interface RemoteAgentSession extends AgentSessionActor {
|
|
124
|
+
/** 按稳定模型 ID 更新远程 Session 模型。 */
|
|
125
|
+
set(input: AgentSessionSetInput): Promise<void>;
|
|
126
|
+
|
|
104
127
|
/** 从当前远程 session 创建一个分叉会话。 */
|
|
105
128
|
fork(input?: AgentSessionForkInput | string): Promise<RemoteAgentSession>;
|
|
106
129
|
}
|
|
@@ -67,9 +67,17 @@ export interface AgentSessionSetInput {
|
|
|
67
67
|
*
|
|
68
68
|
* 关键点(中文)
|
|
69
69
|
* - 这里接受运行中的模型实例,而不是模型 ID。
|
|
70
|
-
* -
|
|
70
|
+
* - 未同时提供 `modelId` 时,SDK 会从模型实例推导稳定 ID 并持久化。
|
|
71
71
|
*/
|
|
72
72
|
model?: AgentModel;
|
|
73
|
+
/**
|
|
74
|
+
* 当前 session 使用的稳定模型 ID。
|
|
75
|
+
*
|
|
76
|
+
* 关键点(中文)
|
|
77
|
+
* - 由 Agent 宿主提供的模型 resolver 解析为运行时模型实例。
|
|
78
|
+
* - 该值会持久化到 session metadata,进程重启后可以恢复。
|
|
79
|
+
*/
|
|
80
|
+
modelId?: string;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
/**
|
|
@@ -80,6 +88,8 @@ export interface AgentSessionConfigSnapshot {
|
|
|
80
88
|
model?: LanguageModel;
|
|
81
89
|
/** 当前模型的轻量可读标签。 */
|
|
82
90
|
modelLabel?: string;
|
|
91
|
+
/** 当前 session 绑定的稳定模型 ID。 */
|
|
92
|
+
modelId?: string;
|
|
83
93
|
}
|
|
84
94
|
|
|
85
95
|
/**
|
|
@@ -253,6 +263,8 @@ export interface AgentSessionSummary {
|
|
|
253
263
|
messageCount: number;
|
|
254
264
|
/** 当前 session 绑定模型的可读标签。 */
|
|
255
265
|
modelLabel?: string;
|
|
266
|
+
/** 当前 session 绑定的稳定模型 ID。 */
|
|
267
|
+
modelId?: string;
|
|
256
268
|
/** 当前 session 是否处于执行中。 */
|
|
257
269
|
executing?: boolean;
|
|
258
270
|
}
|
|
@@ -15,12 +15,14 @@ import type {
|
|
|
15
15
|
AgentArchiveSessionResult,
|
|
16
16
|
AgentArchiveSessionsResult,
|
|
17
17
|
AgentCleanArchiveResult,
|
|
18
|
-
AgentSessionRecordsInput,
|
|
19
18
|
AgentSessionSystemSnapshot,
|
|
19
|
+
AgentSessionSetInput,
|
|
20
20
|
} from "@/types/agent/SessionTypes.js";
|
|
21
21
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
22
22
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
23
23
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
24
|
+
import type { ListSessionMessagesInput } from "@/types/session/SessionMessage.js";
|
|
25
|
+
import type { ListSessionMessageChangesInput } from "@/types/session/SessionMessageMutation.js";
|
|
24
26
|
import type { JsonObject, JsonValue } from "@/types/common/Json.js";
|
|
25
27
|
import type { PluginControlAction } from "@/types/plugin/PluginState.js";
|
|
26
28
|
import type { ShellApprovalMode } from "@downcity/shell";
|
|
@@ -60,6 +62,19 @@ export type RpcRequest =
|
|
|
60
62
|
sessionId: string;
|
|
61
63
|
};
|
|
62
64
|
}
|
|
65
|
+
| {
|
|
66
|
+
/** 请求 id,用于匹配响应。 */
|
|
67
|
+
id: string;
|
|
68
|
+
/** 更新 session 模型。 */
|
|
69
|
+
method: "sdk.sessions.set";
|
|
70
|
+
/** Session 配置更新参数。 */
|
|
71
|
+
params: {
|
|
72
|
+
/** 目标 session id。 */
|
|
73
|
+
sessionId: string;
|
|
74
|
+
/** 仅包含稳定 modelId 的配置输入。 */
|
|
75
|
+
input: AgentSessionSetInput;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
63
78
|
| {
|
|
64
79
|
/** 请求 id,用于匹配响应。 */
|
|
65
80
|
id: string;
|
|
@@ -112,14 +127,27 @@ export type RpcRequest =
|
|
|
112
127
|
| {
|
|
113
128
|
/** 请求 id,用于匹配响应。 */
|
|
114
129
|
id: string;
|
|
115
|
-
/** 读取 session
|
|
116
|
-
method: "sdk.sessions.
|
|
117
|
-
/**
|
|
130
|
+
/** 读取 session messages。 */
|
|
131
|
+
method: "sdk.sessions.messages";
|
|
132
|
+
/** messages 查询参数。 */
|
|
133
|
+
params: {
|
|
134
|
+
/** 目标 session id。 */
|
|
135
|
+
sessionId: string;
|
|
136
|
+
/** messages 分页参数。 */
|
|
137
|
+
input?: ListSessionMessagesInput;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
| {
|
|
141
|
+
/** 请求 id,用于匹配响应。 */
|
|
142
|
+
id: string;
|
|
143
|
+
/** 读取 session message mutations。 */
|
|
144
|
+
method: "sdk.sessions.message_changes";
|
|
145
|
+
/** changes 查询参数。 */
|
|
118
146
|
params: {
|
|
119
147
|
/** 目标 session id。 */
|
|
120
148
|
sessionId: string;
|
|
121
|
-
/**
|
|
122
|
-
input
|
|
149
|
+
/** Mutation 增量参数。 */
|
|
150
|
+
input: ListSessionMessageChangesInput;
|
|
123
151
|
};
|
|
124
152
|
}
|
|
125
153
|
| {
|
|
@@ -33,6 +33,10 @@ import type {
|
|
|
33
33
|
AgentSessionSubscriber,
|
|
34
34
|
AgentSessionUnsubscribe,
|
|
35
35
|
} from "@/types/sdk/AgentSessionEvent.js";
|
|
36
|
+
import type {
|
|
37
|
+
SessionMessageMutationSubscriber,
|
|
38
|
+
SessionMessageMutationUnsubscribe,
|
|
39
|
+
} from "@/types/session/SessionMessageMutation.js";
|
|
36
40
|
import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
|
|
37
41
|
|
|
38
42
|
/**
|
|
@@ -133,9 +137,11 @@ export interface SessionPort {
|
|
|
133
137
|
*
|
|
134
138
|
* 关键点(中文)
|
|
135
139
|
* - 只广播订阅之后产生的事件。
|
|
136
|
-
* -
|
|
140
|
+
* - 当前 Message snapshot 通过公开 SDK `session.messages()` 读取。
|
|
137
141
|
*/
|
|
138
|
-
subscribe(
|
|
142
|
+
subscribe(
|
|
143
|
+
subscriber: SessionMessageMutationSubscriber,
|
|
144
|
+
): SessionMessageMutationUnsubscribe;
|
|
139
145
|
/**
|
|
140
146
|
* 发布一条 session runtime 事件。
|
|
141
147
|
*
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type { JsonValue } from "@/types/common/Json.js";
|
|
10
10
|
import type { SessionAssistantStepVisibility } from "@/executor/types/SessionRun.js";
|
|
11
11
|
import type { AgentSessionActionEvent } from "@/types/sdk/AgentSessionAction.js";
|
|
12
|
+
import type { SessionMessageMutation } from "@/types/session/SessionMessageMutation.js";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* 单个 turn 开始事件。
|
|
@@ -346,6 +347,7 @@ export interface AgentSessionErrorEvent {
|
|
|
346
347
|
* Session 订阅可见事件联合类型。
|
|
347
348
|
*/
|
|
348
349
|
export type AgentSessionEvent =
|
|
350
|
+
| SessionMessageMutation
|
|
349
351
|
| AgentSessionTurnStartEvent
|
|
350
352
|
| AgentSessionTextDeltaEvent
|
|
351
353
|
| AgentSessionReasoningDeltaEvent
|