@blade-hq/agent-client 2612.0.0-beta.7 → 2612.0.0-beta.71
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/README.md +352 -34
- package/dist/application-client.d.ts +19 -0
- package/dist/blade-client.d.ts +25 -9
- package/dist/{chunk-E7J2JBML.js → chunk-DMVWOTJB.js} +1588 -391
- package/dist/chunk-DMVWOTJB.js.map +1 -0
- package/dist/index.d.ts +18 -5
- package/dist/index.js +15 -1
- package/dist/internal.d.ts +12 -4
- package/dist/internal.js +29 -3
- package/dist/internal.js.map +1 -1
- package/dist/resources/auth.d.ts +9 -1
- package/dist/resources/computers.d.ts +2 -7
- package/dist/resources/connectors.d.ts +323 -0
- package/dist/resources/headless.d.ts +1 -1
- package/dist/resources/llm.d.ts +64 -0
- package/dist/resources/models.d.ts +6 -1
- package/dist/resources/phones.d.ts +109 -0
- package/dist/resources/plugins.d.ts +22 -0
- package/dist/resources/sandbox.d.ts +22 -0
- package/dist/resources/sessions.d.ts +105 -10
- package/dist/schemas/ask-user-question.d.ts +21 -0
- package/dist/schemas/context-attachments.d.ts +18 -0
- package/dist/schemas/message-utils.d.ts +3 -9
- package/dist/schemas/message.d.ts +16 -2
- package/dist/schemas/plugin-refs.d.ts +7 -0
- package/dist/schemas/projection.d.ts +14 -1
- package/dist/schemas/session.d.ts +2 -48
- package/dist/server-clock.d.ts +2 -0
- package/dist/session/agent-session.d.ts +44 -95
- package/dist/session/definition.d.ts +3 -0
- package/dist/session/events.d.ts +0 -1
- package/dist/session/hub.d.ts +0 -24
- package/dist/session/state.d.ts +8 -1
- package/dist/session/workflow.d.ts +10 -3
- package/dist/shared/projection/builder.d.ts +0 -2
- package/dist/shared/projection/index.d.ts +1 -0
- package/dist/shared/projection/workflow.d.ts +24 -0
- package/dist/tool-provider.d.ts +60 -0
- package/dist/types/socket-events.d.ts +167 -11
- package/dist/version.d.ts +0 -1
- package/node_modules/engine.io-client/build/cjs/globals.node.d.ts +2 -3
- package/node_modules/engine.io-client/build/cjs/index.d.ts +3 -3
- package/node_modules/engine.io-client/build/cjs/index.js +1 -4
- package/node_modules/engine.io-client/build/cjs/socket.d.ts +39 -82
- package/node_modules/engine.io-client/build/cjs/socket.js +151 -218
- package/node_modules/engine.io-client/build/cjs/transport.d.ts +1 -1
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.d.ts +4 -4
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js +2 -2
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.js +17 -7
- package/node_modules/engine.io-client/build/cjs/transports/websocket.node.js +17 -7
- package/node_modules/engine.io-client/build/esm/globals.node.d.ts +2 -3
- package/node_modules/engine.io-client/build/esm/index.d.ts +3 -3
- package/node_modules/engine.io-client/build/esm/index.js +1 -2
- package/node_modules/engine.io-client/build/esm/socket.d.ts +39 -82
- package/node_modules/engine.io-client/build/esm/socket.js +141 -206
- package/node_modules/engine.io-client/build/esm/transport.d.ts +1 -1
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.d.ts +4 -4
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.js +2 -2
- package/node_modules/engine.io-client/build/esm-debug/globals.node.d.ts +2 -3
- package/node_modules/engine.io-client/build/esm-debug/index.d.ts +3 -3
- package/node_modules/engine.io-client/build/esm-debug/index.js +1 -2
- package/node_modules/engine.io-client/build/esm-debug/socket.d.ts +39 -82
- package/node_modules/engine.io-client/build/esm-debug/socket.js +150 -215
- package/node_modules/engine.io-client/build/esm-debug/transport.d.ts +1 -1
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.d.ts +4 -4
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.js +2 -2
- package/node_modules/engine.io-client/dist/engine.io.esm.min.js +3 -3
- package/node_modules/engine.io-client/dist/engine.io.esm.min.js.map +1 -1
- package/node_modules/engine.io-client/dist/engine.io.js +164 -239
- package/node_modules/engine.io-client/dist/engine.io.js.map +1 -1
- package/node_modules/engine.io-client/dist/engine.io.min.js +3 -3
- package/node_modules/engine.io-client/dist/engine.io.min.js.map +1 -1
- package/node_modules/engine.io-client/package.json +2 -2
- package/node_modules/socket.io-parser/build/cjs/binary.js +4 -1
- package/node_modules/socket.io-parser/build/cjs/index.d.ts +14 -4
- package/node_modules/socket.io-parser/build/cjs/index.js +18 -11
- package/node_modules/socket.io-parser/build/esm/binary.js +4 -1
- package/node_modules/socket.io-parser/build/esm/index.d.ts +14 -4
- package/node_modules/socket.io-parser/build/esm/index.js +14 -10
- package/node_modules/socket.io-parser/build/esm-debug/binary.js +4 -1
- package/node_modules/socket.io-parser/build/esm-debug/index.d.ts +14 -4
- package/node_modules/socket.io-parser/build/esm-debug/index.js +14 -10
- package/node_modules/socket.io-parser/package.json +1 -1
- package/node_modules/ws/index.js +15 -6
- package/node_modules/ws/lib/constants.js +1 -0
- package/node_modules/ws/lib/permessage-deflate.js +9 -7
- package/node_modules/ws/lib/receiver.js +37 -0
- package/node_modules/ws/lib/sender.js +6 -1
- package/node_modules/ws/lib/websocket-server.js +18 -6
- package/node_modules/ws/lib/websocket.js +50 -17
- package/node_modules/ws/package.json +8 -3
- package/node_modules/ws/wrapper.mjs +14 -1
- package/package.json +4 -4
- package/public-api.md +662 -36
- package/dist/chunk-E7J2JBML.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ContextAttachment } from "../schemas/context-attachments";
|
|
1
2
|
import type { TopicAssetRef } from "../schemas/topic-assets";
|
|
2
3
|
import { type RawEvent } from "../shared/projection";
|
|
3
4
|
import type { MessageContent } from "../schemas/message";
|
|
@@ -41,10 +42,11 @@ export interface SessionDetailSnapshot {
|
|
|
41
42
|
status?: SessionStatus;
|
|
42
43
|
replay_state?: ReplayState | null;
|
|
43
44
|
viewer_role?: "owner" | "viewer";
|
|
44
|
-
runtime_type?: string | null;
|
|
45
45
|
}
|
|
46
46
|
/** 服务端 chat:end 载荷里 AgentSession 关心的字段。 */
|
|
47
47
|
export interface ChatEndPayload {
|
|
48
|
+
chat_run_id?: string;
|
|
49
|
+
result?: unknown;
|
|
48
50
|
status?: string;
|
|
49
51
|
/** 排队中断:服务端取消了排队中的发送,`cancelled_client_request_ids` 是被取消的请求。 */
|
|
50
52
|
queued?: boolean;
|
|
@@ -58,6 +60,7 @@ export interface AttachAppOptions {
|
|
|
58
60
|
getContext: () => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
59
61
|
}
|
|
60
62
|
export interface SendOptions {
|
|
63
|
+
contextAttachments?: ContextAttachment[];
|
|
61
64
|
/** planning / executing 模式。 */
|
|
62
65
|
mode?: string;
|
|
63
66
|
/** AskUserQuestion 的作答(tool_call_id + 选项)。 */
|
|
@@ -76,14 +79,39 @@ export interface SendOptions {
|
|
|
76
79
|
replayDecision?: "keep_replay" | "continue_replay";
|
|
77
80
|
/** 用户显式选择的知识库 id;后端将元信息作为 once Context 提供给模型。 */
|
|
78
81
|
/** Explicit topic assets for this message only. */
|
|
79
|
-
refs?: import("../schemas/plugin-refs").
|
|
82
|
+
refs?: import("../schemas/plugin-refs").MessageRef[];
|
|
80
83
|
topicAssetRefs?: TopicAssetRef[];
|
|
81
84
|
/**
|
|
82
|
-
*
|
|
83
|
-
* 是否真的入队由服务端按运行状态判定(等待回答时发送即作答,不会被误排队)。
|
|
85
|
+
* 默认发送引导消息;显式为 true 时等待当前运行结束(等待回答时发送仍作答)。
|
|
84
86
|
*/
|
|
85
87
|
queueWhenRunning?: boolean;
|
|
86
88
|
}
|
|
89
|
+
/** Durable text input with message-scoped application data. Persist this JSON value before calling sendPrepared. */
|
|
90
|
+
export interface PreparedSend {
|
|
91
|
+
sessionId: string;
|
|
92
|
+
requestId: string;
|
|
93
|
+
content: string;
|
|
94
|
+
options: PreparedSendOptions;
|
|
95
|
+
}
|
|
96
|
+
export interface PreparedSendOptions {
|
|
97
|
+
/** Require BA submit_result for this execution. */
|
|
98
|
+
headless?: boolean;
|
|
99
|
+
/** false 时补充当前运行;省略或 true 时等待下一轮。 */
|
|
100
|
+
queueWhenRunning?: boolean;
|
|
101
|
+
contextAttachments?: ContextAttachment[];
|
|
102
|
+
mode?: "planning" | "executing";
|
|
103
|
+
model?: string;
|
|
104
|
+
thinkingOverride?: boolean;
|
|
105
|
+
reasoningLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
106
|
+
}
|
|
107
|
+
export interface DeliveryReceipt {
|
|
108
|
+
requestId: string;
|
|
109
|
+
status: "accepted" | "not_found" | "rejected" | "unknown";
|
|
110
|
+
itemId?: string;
|
|
111
|
+
queueStatus?: string;
|
|
112
|
+
executionId?: string | null;
|
|
113
|
+
message?: string;
|
|
114
|
+
}
|
|
87
115
|
export declare function sessionStatusFromChatEnd(status: string | undefined): SessionStatus;
|
|
88
116
|
/**
|
|
89
117
|
* 一个会话的实时状态机:封装 Socket.IO 订阅、历史 + 流式合流、断线补数,
|
|
@@ -96,9 +124,7 @@ export declare class AgentSession {
|
|
|
96
124
|
private readonly logCursor;
|
|
97
125
|
readonly sessionId: string;
|
|
98
126
|
private state;
|
|
99
|
-
/** status 每变化一次加一(单调递增)。异步读取会话详情时据此判断请求期间状态是否变过,避免 running→终态→running 这类来回被误认为「没变」。 */
|
|
100
127
|
private statusRevision;
|
|
101
|
-
/** 实时事件写入 status 时调用:值不变也要记一次,才能识别请求期间收到过更新的状态。 */
|
|
102
128
|
private noteLiveStatus;
|
|
103
129
|
private readonly listeners;
|
|
104
130
|
private readonly emitter;
|
|
@@ -114,9 +140,7 @@ export declare class AgentSession {
|
|
|
114
140
|
private subscriptionQueue;
|
|
115
141
|
private replaceQueue;
|
|
116
142
|
private timelineEpoch;
|
|
117
|
-
/** 定位请求的流水号:被后一次选择取代的那次定位不再提交窗口(见 locateEntry)。 */
|
|
118
143
|
private locateToken;
|
|
119
|
-
/** 在途那次定位的请求句柄。**只**服务定位:权威刷新不共用它(见 cancelPendingLocate)。 */
|
|
120
144
|
private locateAbort;
|
|
121
145
|
private pagingGeneration;
|
|
122
146
|
private liveRevision;
|
|
@@ -133,45 +157,25 @@ export declare class AgentSession {
|
|
|
133
157
|
private bufferedCommandDeliveries;
|
|
134
158
|
private pendingReplayMessage;
|
|
135
159
|
private pendingReplayMode;
|
|
160
|
+
private pendingReplayRequestId;
|
|
161
|
+
private pendingReplayAttachments;
|
|
136
162
|
private pendingReplayRefs;
|
|
137
163
|
private pendingReplayTopicAssetRefs;
|
|
138
164
|
private recentChatEndAt;
|
|
139
|
-
/**
|
|
140
|
-
* 最近一次已经通过 `error` 事件投递过的服务端失败(`message` + `code`)。
|
|
141
|
-
*
|
|
142
|
-
* `chat:send` 被代理时服务端会先发 `system:error`、再用同一条失败回 ack,两条
|
|
143
|
-
* 通道都会到达这里:前者走 `_handleSystemError`,后者走发送失败的回滚。不去重
|
|
144
|
-
* 的话调用方会收到两次同一个 `error`(重复提示、重试逻辑跑两遍)。
|
|
145
|
-
*
|
|
146
|
-
* 带代际边界,只认「本次 `emitWithAck` 等待期间」投递的那一条:否则队列/停止
|
|
147
|
-
* 失败留下的标记会一直挂着,之后一次无关的订阅失败只是文案码相同就被当成
|
|
148
|
-
* 重复而静音。用单调递增的代际号而不是时间戳,同一毫秒内的两条也不会混淆。
|
|
149
|
-
*/
|
|
150
165
|
private lastDeliveredSystemError;
|
|
151
|
-
/** 每次投递 `system:error` 递增,用于判定某条失败是否属于本次等待。 */
|
|
152
166
|
private systemErrorGeneration;
|
|
153
167
|
private subscriptionReplaySource;
|
|
154
168
|
private disposed;
|
|
155
169
|
private getAppContext;
|
|
156
170
|
private sendPending;
|
|
157
171
|
private manualCompactionRequest;
|
|
158
|
-
/** Reload requests from retracts/epoch changes; done only when a reload started after the latest one succeeds. */
|
|
159
172
|
private epochReloadRequested;
|
|
160
173
|
private epochReloadDone;
|
|
161
174
|
private epochReloadRunning;
|
|
162
|
-
/** 手动整理的在途标记,同时写进状态(界面据此保持「正在整理」,见 SessionState.compactionPending)。 */
|
|
163
175
|
private setManualCompactionRequest;
|
|
164
176
|
private handleManualCompactionFinished;
|
|
165
|
-
/** 最近一次还在等服务端结果的发送请求 id;排队中断的 chat:end 据此判断回滚是否过期。 */
|
|
166
177
|
private pendingChatRequestId;
|
|
167
|
-
/** 会话详情给出的运行时类型;"native" 时启用原生智能体的投影规则(见 _handleTurnEvents / _handleChatEnd)。 */
|
|
168
|
-
private runtimeType;
|
|
169
|
-
/** workflow_run_id → 触发它的 workflow:run 工具调用 id(只有 run:start 事件带工具调用 id)。 */
|
|
170
178
|
private readonly workflowRunToolCalls;
|
|
171
|
-
/**
|
|
172
|
-
* 第一方 Web 的精简模式传输优化:订阅时是否要 token 级事件。null 表示宿主没设置,订阅时不带这个字段。
|
|
173
|
-
* `desiredStreamTokens` 是宿主最新的选择;运行中不切换,等这一轮结束再重订阅。
|
|
174
|
-
*/
|
|
175
179
|
private desiredStreamTokens;
|
|
176
180
|
private joinedStreamTokens;
|
|
177
181
|
private readonly deliveredCommandKeys;
|
|
@@ -232,11 +236,6 @@ export declare class AgentSession {
|
|
|
232
236
|
* 生效;不带 resume,服务端不会重发上一轮的终态事件(否则会被当成一次新的结束)。
|
|
233
237
|
*/
|
|
234
238
|
refreshRunningState(): Promise<void>;
|
|
235
|
-
/**
|
|
236
|
-
* timeline 被整体改写(rewind / checkout / 释放):推进纪元,并把在途定位请求一并中止
|
|
237
|
-
* ——它已经属于旧 timeline,却还占着替换队列,会让改写后的权威窗口排在后面等它跑完。
|
|
238
|
-
* 作废号仍然保留:中止只是让它更早结束。
|
|
239
|
-
*/
|
|
240
239
|
private invalidateTimeline;
|
|
241
240
|
/**
|
|
242
241
|
* 拉取当前分支的用户发言目录(消息导航侧栏用)。
|
|
@@ -265,6 +264,14 @@ export declare class AgentSession {
|
|
|
265
264
|
* CLI 安装成功后才保存 getContext;之后每次 send 前恰好读取一次。
|
|
266
265
|
*/
|
|
267
266
|
attachApp(options: AttachAppOptions): Promise<AppCliAttachment | null>;
|
|
267
|
+
/** 立即为整个会话切换模型,并接续因模型故障停下的任务。 */
|
|
268
|
+
selectModel(model: string): Promise<boolean>;
|
|
269
|
+
/** Prepare a durable text input without sending any network request. */
|
|
270
|
+
prepareSend(content: string, options?: PreparedSendOptions): PreparedSend;
|
|
271
|
+
/** Durably send a text input with its saved delivery intent. Retries must reuse the saved request. */
|
|
272
|
+
sendPrepared(request: PreparedSend): Promise<DeliveryReceipt>;
|
|
273
|
+
/** Owner-authorized lookup; receipts remain until the session is deleted. */
|
|
274
|
+
getDelivery(requestId: string): Promise<DeliveryReceipt>;
|
|
268
275
|
/** 发送一条消息。字符串或多模态内容均可。 */
|
|
269
276
|
send(content: MessageContent, options?: SendOptions): Promise<boolean>;
|
|
270
277
|
/**
|
|
@@ -294,19 +301,13 @@ export declare class AgentSession {
|
|
|
294
301
|
resumeQueue(): Promise<QueueOperationResult>;
|
|
295
302
|
/** 拉取一份权威队列快照。首次连接与每次重连后由实例自动调用,也可以手动刷新。 */
|
|
296
303
|
refreshQueue(): Promise<QueueOperationResult>;
|
|
297
|
-
/**
|
|
298
|
-
* 发出一条队列命令并安装 ack 里的快照。
|
|
299
|
-
* 传输层失败(超时 / 断线)会 reject,由调用方决定是否重试。
|
|
300
|
-
*/
|
|
301
304
|
private requestQueueAck;
|
|
302
|
-
/** 队列命令的对外入口:传输失败只体现为失败结果,不向调用方抛异常。 */
|
|
303
305
|
private runQueueCommand;
|
|
304
306
|
private sendUnlocked;
|
|
305
307
|
private rollbackOptimisticSend;
|
|
306
|
-
/** 撤回一次乐观提交:移除乐观消息、恢复提问作答、清掉回放草稿。 */
|
|
307
308
|
private discardOptimisticSend;
|
|
308
309
|
/** 停止当前回复。 */
|
|
309
|
-
stop(): Promise<Record<string, unknown>>;
|
|
310
|
+
stop(executionId?: string): Promise<Record<string, unknown>>;
|
|
310
311
|
/** 手动触发上下文压缩。 */
|
|
311
312
|
compact(): Promise<Record<string, unknown>>;
|
|
312
313
|
/**
|
|
@@ -329,92 +330,50 @@ export declare class AgentSession {
|
|
|
329
330
|
*/
|
|
330
331
|
dispose(): void;
|
|
331
332
|
get isDisposed(): boolean;
|
|
332
|
-
/** @internal 连接状态变化(同 client 下所有会话共享一条连接)。 */
|
|
333
333
|
_setConnection(connection: ConnectionStatus): void;
|
|
334
|
-
/**
|
|
335
|
-
* @internal 服务端广播的权威队列快照。
|
|
336
|
-
* 结构不合法或 revision 不新的一律丢弃,绝不用旧快照覆盖新状态。
|
|
337
|
-
*/
|
|
338
334
|
_handleQueueUpdated(payload: unknown): void;
|
|
339
|
-
/** @internal socket 重连后由 Hub 调用:重新加入房间并补数。 */
|
|
340
335
|
_rejoinAfterReconnect(): Promise<void>;
|
|
341
|
-
/** @internal 首次连接:加载历史 + 加入房间。 */
|
|
342
336
|
_bootstrap(): Promise<void>;
|
|
343
|
-
/** 订阅生命周期串行执行;一次失败只由自己的调用方观察,不截断后续重连。 */
|
|
344
337
|
private enqueueSubscription;
|
|
345
|
-
/** 改回放是 owner 专属(服务端 PATCH 走 _get_owned_session)。 */
|
|
346
338
|
private get canControlReplay();
|
|
347
|
-
/** 拉一次会话详情,填会话状态、回放状态、只读身份和运行时类型;失败不挡启动。 */
|
|
348
339
|
private syncSessionFromDetail;
|
|
349
|
-
/** 安装一份会话详情;`statusRevisionAtRequest` 是发出请求时的状态修订号。 */
|
|
350
340
|
private applySessionDetail;
|
|
351
341
|
/** 调整回放倍速;不是回放会话、或只读身份时什么都不做。 */
|
|
352
342
|
setReplaySpeed(speed: ReplaySpeed): Promise<void>;
|
|
353
343
|
/** 退出回放,之后的对话交给真实模型运行;不是回放会话、或只读身份时什么都不做。 */
|
|
354
344
|
exitReplay(): Promise<void>;
|
|
355
|
-
/** 把一次回放控制请求排进队列;前一个完成后才发出,响应直接安装。 */
|
|
356
345
|
private applyReplayControl;
|
|
357
|
-
/** @internal */
|
|
358
346
|
_handleTurnStart(turn: TurnProjection): void;
|
|
359
|
-
/** @internal */
|
|
360
347
|
_handleTurnPatch(patch: PatchEnvelope): void;
|
|
361
|
-
/** @internal */
|
|
362
348
|
_handleTurnEnd(turn: TurnProjection): void;
|
|
363
349
|
private runEpochReload;
|
|
364
|
-
/** @internal 历史回放通道(event_format: raw)。 */
|
|
365
350
|
_handleTurnEvents(incoming: RawEvent[], replayed?: boolean): void;
|
|
366
|
-
/** @internal */
|
|
367
351
|
_handleChatStart(): void;
|
|
368
|
-
|
|
369
|
-
* @internal 返回 false 表示这是一条过期的排队回滚(被取消的是更早的请求,当前运行不受影响),
|
|
370
|
-
* Hub 据此不把它当成一次运行结束广播出去。
|
|
371
|
-
*/
|
|
352
|
+
private recordRunResult;
|
|
372
353
|
_handleChatEnd(payload?: ChatEndPayload): boolean;
|
|
373
|
-
/** @internal */
|
|
374
354
|
_handleSystemError(message: string, code?: string): void;
|
|
375
|
-
/** @internal */
|
|
376
355
|
_handleTaskUpdated(tasks: unknown[]): void;
|
|
377
|
-
/** @internal */
|
|
378
356
|
_handleWorkspaceFilesChanged(filePath?: string, paths?: string[] | null): void;
|
|
379
|
-
/** @internal */
|
|
380
357
|
_handleSessionUpdated(data: {
|
|
381
358
|
workspace_path?: string;
|
|
382
359
|
chat_group_id?: string | null;
|
|
383
360
|
intent?: string;
|
|
384
361
|
status?: SessionStatus;
|
|
385
362
|
model?: string | null;
|
|
386
|
-
bound_skill_id?: string | null;
|
|
387
363
|
replay_state?: Record<string, unknown> | null;
|
|
388
364
|
}): void;
|
|
389
|
-
/** @internal */
|
|
390
365
|
_handleRewind(checkpointId: string): void;
|
|
391
|
-
/** @internal */
|
|
392
366
|
_handleReplayMismatch(data: {
|
|
393
367
|
actual_message?: string;
|
|
394
368
|
expected_message?: string;
|
|
395
369
|
}): void;
|
|
396
|
-
/** @internal */
|
|
397
370
|
_handleSystemNotification(loopId: string, notification: Record<string, unknown>): void;
|
|
398
|
-
/** @internal */
|
|
399
371
|
_handleBackgroundTask(task: AgentSessionEvents["backgroundTask"]): void;
|
|
400
|
-
/** @internal */
|
|
401
372
|
_handleArtifact(data: Record<string, unknown>, kind: "created" | "updated", replayed?: boolean): void;
|
|
402
|
-
/** @internal 加入房间的应答里带 is_running,据此校准流式状态。 */
|
|
403
373
|
_applyRunningState(isRunning: boolean, liveRevisionAtJoin?: number): void;
|
|
404
374
|
private markRunningIfIdle;
|
|
405
375
|
private finishStreaming;
|
|
406
|
-
/**
|
|
407
|
-
* 原生智能体常在用户发言之前就宣告一个空的 assistant 回合(投影的起点),它的真实内容会随第一条
|
|
408
|
-
* 输出再发一次。消息列表在启动期间本来就显示一个「正在生成」占位,两者并存会出现两个占位,
|
|
409
|
-
* 所以只丢掉原生会话里这种空的流式回合。
|
|
410
|
-
*/
|
|
411
|
-
private isNativeBootstrapTurn;
|
|
412
|
-
/** 实时 workflow:* 事件叠加到对应工具调用的时间线上(见 workflow.ts 的来源规则)。 */
|
|
413
376
|
private applyWorkflowEvents;
|
|
414
|
-
/**
|
|
415
|
-
* @internal 宿主改了 token 订阅偏好(精简模式)。空闲时立即重订阅;运行中等这一轮结束再换,
|
|
416
|
-
* 避免在输出中途丢掉 token 流。
|
|
417
|
-
*/
|
|
418
377
|
_setStreamTokens(enabled: boolean): void;
|
|
419
378
|
private applyDesiredStreamTokens;
|
|
420
379
|
private completeChat;
|
|
@@ -425,28 +384,18 @@ export declare class AgentSession {
|
|
|
425
384
|
private schedulePatchFlush;
|
|
426
385
|
private cancelPatchFlush;
|
|
427
386
|
private flushPatches;
|
|
428
|
-
/** turn 数据落地后统一派生语义事件(指令 / 工具调用 / 消息 / 模式 / 预览 / OOM)。 */
|
|
429
387
|
private emitTurnDerivedEvents;
|
|
430
388
|
private dispatchCommand;
|
|
431
389
|
private dispatchRawCommands;
|
|
432
390
|
private deliverCommand;
|
|
433
391
|
private deliverCommandNow;
|
|
434
392
|
private notifySandboxOom;
|
|
435
|
-
/**
|
|
436
|
-
* 权威刷新(运行结束 / 重连补数):**按当前窗口第一条发言取窗口**,不再另记"用户想看哪段"。
|
|
437
|
-
*
|
|
438
|
-
* 窗口本身就是"用户在看哪段":首屏就是最新一页,向上翻页 / 定位之后首条就是用户滚到的位置。
|
|
439
|
-
* 直接拿 `from_entry_id = 当前窗口第一条 turn_id` 去取,运行结束、重连补数、翻页之后的对账
|
|
440
|
-
* 是同一条规则,不需要意图、锚点、已落地锚点这些状态;窗口首条已经不在分支上(404 / 409)时
|
|
441
|
-
* 回落到最新一页。
|
|
442
|
-
*/
|
|
443
393
|
private refreshAuthoritativeHistory;
|
|
444
394
|
private replaceFromHistory;
|
|
445
395
|
private invalidateOlderPaging;
|
|
446
396
|
private beginCommandRecovery;
|
|
447
397
|
private scheduleHistoricalCommandRestore;
|
|
448
398
|
private flushBufferedCommands;
|
|
449
|
-
/** 首次订阅前的 REST 历史建立语义事件基线,随后同一工具的订阅回放不再投递。 */
|
|
450
399
|
private seedToolCallDeliveryBaseline;
|
|
451
400
|
private ensureJoined;
|
|
452
401
|
private ensureIdleBeforeSend;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { McpSourceConfig } from "../resources/sessions";
|
|
1
2
|
export type TextFile = {
|
|
2
3
|
path: string;
|
|
3
4
|
content: string;
|
|
@@ -23,6 +24,8 @@ export interface SkillDefinition {
|
|
|
23
24
|
files: SkillFile[];
|
|
24
25
|
}
|
|
25
26
|
export interface SessionConfig {
|
|
27
|
+
/** Application tools bound at session creation, before any execution. */
|
|
28
|
+
mcpSources?: McpSourceConfig[];
|
|
26
29
|
/** Server 模型目录中的 model ID。 */
|
|
27
30
|
model?: string;
|
|
28
31
|
enableThinking?: boolean;
|
package/dist/session/events.d.ts
CHANGED
package/dist/session/hub.d.ts
CHANGED
|
@@ -58,7 +58,6 @@ export declare class SessionHub {
|
|
|
58
58
|
private readonly client;
|
|
59
59
|
private readonly sessions;
|
|
60
60
|
private readonly bootstrapPending;
|
|
61
|
-
/** 每个会话当前有多少方持有(connect 一次 +1,dispose 一次 -1)。 */
|
|
62
61
|
private readonly holdCounts;
|
|
63
62
|
private connection;
|
|
64
63
|
private readonly connectionListeners;
|
|
@@ -67,29 +66,18 @@ export declare class SessionHub {
|
|
|
67
66
|
private readonly authBusyReconnect;
|
|
68
67
|
private readonly hubEmitter;
|
|
69
68
|
private options;
|
|
70
|
-
/** token 订阅偏好(第一方 Web 精简模式);null 表示不设置,订阅时不带字段。 */
|
|
71
69
|
private streamTokens;
|
|
72
|
-
/** 状态订阅(mode: "status")的持有计数。 */
|
|
73
70
|
private readonly statusWatchCounts;
|
|
74
71
|
private readonly statusLogCursors;
|
|
75
72
|
private readonly replayPlaybackIds;
|
|
76
|
-
/** 启动连接门控:扣住期间只登记「需要连接」,放开后连一次。 */
|
|
77
73
|
private connectionHeld;
|
|
78
74
|
private connectDeferred;
|
|
79
|
-
/**
|
|
80
|
-
* 宿主显式要过连接(ensureConnected / reconnect,例如只收产品事件的页面)。有会话、状态订阅或这个需求时,
|
|
81
|
-
* 鉴权忙碌的临时拒绝都要按服务端建议重试,否则连接会一直停在断开,直到别的动作碰巧重连。
|
|
82
|
-
*/
|
|
83
75
|
private connectionDemanded;
|
|
84
76
|
constructor(client: BladeClient);
|
|
85
77
|
/** 调整 Hub 行为(见 SessionHubOptions)。只影响之后创建的会话实例。 */
|
|
86
78
|
configure(options: Partial<SessionHubOptions>): void;
|
|
87
79
|
/** 监听 Hub 级事件(见 SessionHubEvents)。返回取消函数。 */
|
|
88
80
|
on<K extends keyof SessionHubEvents>(name: K, handler: (event: SessionHubEvents[K]) => void): () => void;
|
|
89
|
-
/**
|
|
90
|
-
* @internal 第一方 Web 的精简模式传输优化:订阅时是否要 token 级事件。
|
|
91
|
-
* 空闲会话立即重订阅,运行中的会话等这一轮结束。
|
|
92
|
-
*/
|
|
93
81
|
setStreamTokens(enabled: boolean): void;
|
|
94
82
|
/**
|
|
95
83
|
* 只订阅一个会话的运行状态(chat:start / chat:end / session:updated / system:error),
|
|
@@ -131,27 +119,15 @@ export declare class SessionHub {
|
|
|
131
119
|
disconnect(): void;
|
|
132
120
|
/** 清理当前身份下缓存的全部会话,避免切换登录身份后复用旧快照。 */
|
|
133
121
|
disposeAll(): void;
|
|
134
|
-
/**
|
|
135
|
-
* @internal 底层 socket 被换掉时由 BladeClient 调用(如 setBaseUrl)。
|
|
136
|
-
* 事件监听器绑在旧 socket 实例上,换新实例后必须重绑,否则所有
|
|
137
|
-
* turn:* / chat:* 事件都会静默丢弃。
|
|
138
|
-
*/
|
|
139
122
|
_handleSocketReplaced(): void;
|
|
140
123
|
private runtimeFor;
|
|
141
|
-
/** 记一份持有。 */
|
|
142
124
|
private hold;
|
|
143
|
-
/**
|
|
144
|
-
* 归还一份持有;还剩别的持有者时返回 false,让 AgentSession 保持可用。
|
|
145
|
-
* 归零才退订房间并从路由表移除。
|
|
146
|
-
*/
|
|
147
125
|
private release;
|
|
148
126
|
private statusCursor;
|
|
149
127
|
private emitStatusSubscribe;
|
|
150
|
-
/** 不管还有几方持有都立即释放(启动失败、切换身份)。 */
|
|
151
128
|
private forceRelease;
|
|
152
129
|
private needsConnection;
|
|
153
130
|
private setConnection;
|
|
154
|
-
/** 事件带 session_id 时精确路由;缺省时按当前唯一活跃会话兜底。 */
|
|
155
131
|
private route;
|
|
156
132
|
private ensureBound;
|
|
157
133
|
private routeArtifact;
|
package/dist/session/state.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ export interface SessionState {
|
|
|
40
40
|
isStreaming: boolean;
|
|
41
41
|
/** 会话状态(running / completed / failed / waiting_for_input / interrupted …)。 */
|
|
42
42
|
status: SessionStatus | null;
|
|
43
|
+
/** Latest BA execution terminal, restored from durable lifecycle events independently of message paging. */
|
|
44
|
+
lastRun: {
|
|
45
|
+
runId: string;
|
|
46
|
+
status: string;
|
|
47
|
+
result: unknown;
|
|
48
|
+
} | null;
|
|
43
49
|
/** 当前模式(planning / executing),来自 mode_change 事件。 */
|
|
44
50
|
mode: "planning" | "executing" | null;
|
|
45
51
|
/** Socket.IO 连接状态(同一 client 下所有会话共享)。 */
|
|
@@ -84,6 +90,7 @@ export interface ReplaySnapshot {
|
|
|
84
90
|
export declare function toReplaySnapshot(raw: ReplayState | null | undefined): ReplaySnapshot | null;
|
|
85
91
|
export declare function createInitialSessionState(sessionId: string): SessionState;
|
|
86
92
|
export declare function parentForkToolCallIdFromTurn(turn: TurnProjection): string | null;
|
|
93
|
+
export declare function messageContentFromTurn(turn: Pick<TurnProjection, "blocks">): MessageContent;
|
|
87
94
|
export declare function extractModeFromBlocks(blocks: ContentBlock[]): "planning" | "executing" | null;
|
|
88
95
|
export declare function reconcileOptimisticUserTurns(currentTurns: TurnProjection[], incomingTurns: TurnProjection[]): TurnProjection[];
|
|
89
96
|
/** Reconcile a bulk authoritative window only by an echoed request identity.
|
|
@@ -107,7 +114,7 @@ export declare function withTurns(state: SessionState, turns: TurnProjection[]):
|
|
|
107
114
|
* 直接返回原 state——引用不变,订阅者不会收到多余通知。
|
|
108
115
|
*/
|
|
109
116
|
export declare function withQueue(state: SessionState, snapshot: SessionQueueSnapshot): SessionState;
|
|
110
|
-
export declare function addUserMessage(state: SessionState, content: MessageContent, clientRequestId?: string, topicAssetRefs?: TopicAssetRef[], refs?: import("../schemas/plugin-refs").
|
|
117
|
+
export declare function addUserMessage(state: SessionState, content: MessageContent, clientRequestId?: string, topicAssetRefs?: TopicAssetRef[], refs?: import("../schemas/plugin-refs").MessageRef[], contextAttachments?: import("../schemas/context-attachments").ContextAttachment[]): SessionState;
|
|
111
118
|
export declare function upsertTurn(state: SessionState, turn: TurnProjection): SessionState;
|
|
112
119
|
export declare function applyTurnPatch(state: SessionState, patch: PatchEnvelope): SessionState;
|
|
113
120
|
export declare function addErrorMessage(state: SessionState, content: string): SessionState;
|
|
@@ -8,14 +8,20 @@ import type { TurnProjection } from "../schemas/projection";
|
|
|
8
8
|
* - 工具调用结束后:一律用工具结果里留存的 `[workflow] …` 行重建(落盘,历史也只有这一份)。
|
|
9
9
|
* 这样实时、历史、重连、回放在运行结束后得到同一份时间线。
|
|
10
10
|
*/
|
|
11
|
-
export type WorkflowRunEntry =
|
|
11
|
+
export type WorkflowRunEntry =
|
|
12
|
+
/** status:步骤终态(done / error / cancelled);落史与直播的终态更新都会带上。 */
|
|
13
|
+
{
|
|
12
14
|
kind: "step";
|
|
13
15
|
stepId: string;
|
|
14
16
|
desc: string;
|
|
15
17
|
stepKind: string;
|
|
16
|
-
|
|
18
|
+
status?: string;
|
|
19
|
+
}
|
|
20
|
+
/** stepId:这行属于哪一步。并行分支的输出不按宣告顺序到达,不能按位置归到上一步。 */
|
|
21
|
+
| {
|
|
17
22
|
kind: "log";
|
|
18
23
|
text: string;
|
|
24
|
+
stepId?: string;
|
|
19
25
|
};
|
|
20
26
|
export interface WorkflowRunState {
|
|
21
27
|
/** 触发它的 workflow:run 工具调用 id。 */
|
|
@@ -35,7 +41,8 @@ export declare function isWorkflowRunToolName(name: string): boolean;
|
|
|
35
41
|
* 非前缀行(最终输出 / traceback)不参与,由界面在外层展示。
|
|
36
42
|
*/
|
|
37
43
|
export declare function workflowEntriesFromOutput(output: string): WorkflowRunEntry[];
|
|
38
|
-
/**
|
|
44
|
+
/** 运行的标题只从工具参数取:历史没有实时事件,两条路径都用这一个来源。
|
|
45
|
+
* 与 host 起跑时发的 label 同款:「技能「org/x」」,非 main 流程再带「 · 流程 x」。 */
|
|
39
46
|
export declare function workflowNameFromArguments(argumentsJson: string): string;
|
|
40
47
|
export declare function isWorkflowEvent(type: string): boolean;
|
|
41
48
|
/**
|
|
@@ -33,10 +33,8 @@ export declare class ClientProjectionBuilder {
|
|
|
33
33
|
private latestTurns;
|
|
34
34
|
private turnsById;
|
|
35
35
|
private loopDescriptions;
|
|
36
|
-
/** loop_name → 正在运行的子智能体起点,agent:end 结算并挂到父工具调用上。 */
|
|
37
36
|
private activeSubagentRuns;
|
|
38
37
|
private pendingChildPauses;
|
|
39
|
-
/** 作答后子回路续跑,最终回复就是随后落盘的父 Agent 工具结果。 */
|
|
40
38
|
private answeredChildParents;
|
|
41
39
|
private pendingMemoryRefs;
|
|
42
40
|
private activeCompactions;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { acceptedPostChatFollowupCompletesLatestRun, acknowledgeTurnEvents, ClientProjectionBuilder, hasChatRunEvent, type RawEvent, type ProjectionUpdate, } from "./builder";
|
|
2
2
|
export { type TurnState, createTurnState, snapshot, PAUSE_TOOL_NAMES } from "./state";
|
|
3
3
|
export { projectHistory, type RawHistoryEntry } from "./history";
|
|
4
|
+
export { workflowEntriesFromSteps, workflowRunCancelled, type WorkflowTimelineEntry, } from "./workflow";
|
|
4
5
|
export { buildContextTurn } from "./context";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WorkflowStepProjection } from "../../schemas/projection";
|
|
2
|
+
/** 固定流程时间线的一条事件:step 开一张步骤卡,log 归并进上一张卡。
|
|
3
|
+
* 形状与 session/workflow.ts 的 WorkflowRunEntry 一致(结构化兼容,直接互喂)。 */
|
|
4
|
+
export type WorkflowTimelineEntry = {
|
|
5
|
+
kind: "step";
|
|
6
|
+
stepId: string;
|
|
7
|
+
desc: string;
|
|
8
|
+
stepKind: string;
|
|
9
|
+
status?: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "log";
|
|
12
|
+
text: string;
|
|
13
|
+
stepId?: string;
|
|
14
|
+
};
|
|
15
|
+
/** 解释执行落史的结构化步骤 → 时间线事件流:与 host live 事件逐行同文案、同顺序。
|
|
16
|
+
* 命令步骤的「└ 输出」行从同一 4KiB 截断串推导(含 …(共N字) 记号),叶子步骤的
|
|
17
|
+
* 「失败:」行还原 error 条目里存的失败说明(容器步骤的 error 条目不带说明)。
|
|
18
|
+
* 条目按终态落盘(容器晚于子步骤、并行分支按完成先后),带 seq / log_seq 时按它们
|
|
19
|
+
* 排回直播时的顺序;旧记录没有序号就按落盘顺序。流式与刷新重建必须渲染出相同结果。 */
|
|
20
|
+
export declare function workflowEntriesFromSteps(steps: readonly WorkflowStepProjection[]): WorkflowTimelineEntry[];
|
|
21
|
+
/** 取消的运行在工具层留档是通用错误串(status=error),真相在步骤条目里:有步骤标记
|
|
22
|
+
* cancelled 且没有步骤失败,整次运行按「已取消」呈现。并行分支失败时兄弟分支也会被
|
|
23
|
+
* 取消,那是失败不是取消。 */
|
|
24
|
+
export declare function workflowRunCancelled(steps: readonly WorkflowStepProjection[]): boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { BladeClient } from "./blade-client";
|
|
2
|
+
export interface ProviderTool {
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
inputSchema: Record<string, unknown>;
|
|
6
|
+
outputSchema?: Record<string, unknown>;
|
|
7
|
+
/** Allows transport retries with identical arguments after uncertain delivery. */
|
|
8
|
+
annotations?: {
|
|
9
|
+
idempotentHint?: boolean;
|
|
10
|
+
};
|
|
11
|
+
handler: (arguments_: Record<string, unknown>, context: {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
executionId?: string;
|
|
15
|
+
requestId?: string;
|
|
16
|
+
toolCallId?: string;
|
|
17
|
+
}) => Promise<ProviderToolResult>;
|
|
18
|
+
}
|
|
19
|
+
export interface ProviderToolResult {
|
|
20
|
+
content: Array<{
|
|
21
|
+
type: "text";
|
|
22
|
+
text: string;
|
|
23
|
+
}>;
|
|
24
|
+
structuredContent?: Record<string, unknown>;
|
|
25
|
+
isError?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface ToolProviderOptions {
|
|
28
|
+
/** Stable application-owned ID, preserved across reconnects. */
|
|
29
|
+
providerId: string;
|
|
30
|
+
/** Secret bound to the session's mcp_sources bearer_token. */
|
|
31
|
+
capability: string;
|
|
32
|
+
tools: ProviderTool[];
|
|
33
|
+
onError?: (error: Error) => void;
|
|
34
|
+
}
|
|
35
|
+
/** Backend-only outbound connection. Reconnects registrations, never tool calls. */
|
|
36
|
+
export declare class ToolProvider {
|
|
37
|
+
private client;
|
|
38
|
+
private options;
|
|
39
|
+
private onDispose;
|
|
40
|
+
readonly url: string;
|
|
41
|
+
private socket?;
|
|
42
|
+
private timer?;
|
|
43
|
+
private registrationTimer?;
|
|
44
|
+
private disposed;
|
|
45
|
+
private registered;
|
|
46
|
+
private attempts;
|
|
47
|
+
private calls;
|
|
48
|
+
private waiters;
|
|
49
|
+
constructor(client: BladeClient, options: ToolProviderOptions, onDispose: () => void);
|
|
50
|
+
/** Resolves only after BA has authenticated and registered this connection. */
|
|
51
|
+
ready(): Promise<void>;
|
|
52
|
+
reconnect(): void;
|
|
53
|
+
private reset;
|
|
54
|
+
private fail;
|
|
55
|
+
private open;
|
|
56
|
+
private schedule;
|
|
57
|
+
private definitions;
|
|
58
|
+
private receive;
|
|
59
|
+
dispose(): void;
|
|
60
|
+
}
|