@blade-hq/agent-client 2610.0.0-rc.0 → 2610.0.0

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.
Files changed (37) hide show
  1. package/README.md +202 -12
  2. package/dist/auth.d.ts +0 -1
  3. package/dist/blade-client.d.ts +22 -1
  4. package/dist/index.d.ts +31 -9
  5. package/dist/index.js +1851 -263
  6. package/dist/index.js.map +1 -1
  7. package/dist/polling-backoff.d.ts +11 -0
  8. package/dist/resources/chat-groups.d.ts +31 -0
  9. package/dist/resources/computers.d.ts +54 -2
  10. package/dist/resources/plugins.d.ts +43 -0
  11. package/dist/resources/sessions.d.ts +190 -1
  12. package/dist/resources/site-visits.d.ts +32 -0
  13. package/dist/rest.d.ts +8 -0
  14. package/dist/schemas/mcp-app.d.ts +30 -0
  15. package/dist/schemas/message-utils.d.ts +10 -0
  16. package/dist/schemas/message.d.ts +3 -0
  17. package/dist/schemas/projection.d.ts +25 -1
  18. package/dist/schemas/session.d.ts +7 -0
  19. package/dist/session/agent-session.d.ts +152 -18
  20. package/dist/session/definition.d.ts +6 -1
  21. package/dist/session/errors.d.ts +11 -0
  22. package/dist/session/events.d.ts +14 -2
  23. package/dist/session/history-page.d.ts +9 -0
  24. package/dist/session/hub.d.ts +1 -0
  25. package/dist/session/queue.d.ts +104 -0
  26. package/dist/session/state.d.ts +15 -1
  27. package/dist/shared/auth-busy.d.ts +9 -0
  28. package/dist/shared/projection/builder.d.ts +10 -0
  29. package/dist/shared/projection/helpers.d.ts +2 -2
  30. package/dist/shared/projection/index.d.ts +1 -1
  31. package/dist/shared/projection/state.d.ts +7 -0
  32. package/dist/shared/tool-ui-card.d.ts +60 -0
  33. package/dist/shared/type-guards.d.ts +2 -0
  34. package/dist/socket.d.ts +2 -0
  35. package/dist/types/socket-events.d.ts +186 -2
  36. package/package.json +1 -1
  37. package/public-api.md +747 -11
@@ -0,0 +1,60 @@
1
+ import type { ChatMessage, ToolCallInfo } from "../schemas/message";
2
+ import type { ContentBlock } from "../schemas/projection";
3
+ import { type McpAppData } from "../schemas/mcp-app";
4
+ /**
5
+ * MCP App 卡片(`_meta.ui` → `tool_ui` block)的共享判定层。
6
+ *
7
+ * 判定逻辑不许各写一份(仓库 CLAUDE.md):agent-react 与 apps/web 都从这里消费卡片的
8
+ * 实例、可见性、身份和终态规则;样式与状态容器(侧栏页签栈等)两侧各自实现。
9
+ */
10
+ export interface ToolUiCard {
11
+ resourceUri?: string;
12
+ resourceURI?: string;
13
+ resourceHTML?: string;
14
+ /** Local HTML source file; hosts can normalize it against the session workspace. */
15
+ sourcePath?: string;
16
+ /** 历史投影标记:绝不重新解析 resourceUri(刷新不重放 MCP/资源读取)。 */
17
+ archived?: boolean;
18
+ target: "inline" | "preview";
19
+ height: number;
20
+ title?: string;
21
+ /** 留档的 MCP App 来源身份与调用数据(来源 server、ui:// 资源、CSP 元数据)。 */
22
+ mcpApp?: McpAppData;
23
+ }
24
+ /** 严格守卫:target/height 缺失、archived 无留档 HTML、或 mcpApp 来源身份残缺的
25
+ * 卡片一律判无效,消息流、侧栏、toolPreview 事件三处一致降级(不渲染、不发事件、
26
+ * 不推送)。后端 `_tool_ui_meta.py` 总会补齐 target/height 默认值,判无效即数据畸形。 */
27
+ export declare function isToolUiCard(value: unknown): value is ToolUiCard;
28
+ export type ToolUiCardContentType = "resource-html" | "resource-uri" | "resource-file";
29
+ /** 解析卡片实际要渲染的内容。archived 卡片只认留档 HTML,绝不回退到
30
+ * resourceUri——历史恢复/浏览器刷新不得因此重新发起 MCP 资源读取。 */
31
+ export declare function resolveToolUiCardContent(card: ToolUiCard): {
32
+ type: ToolUiCardContentType;
33
+ content: string;
34
+ } | null;
35
+ /** 卡片实例身份/去重键:uri 卡片按内容去重(同一 URI 多次产出只留一份),
36
+ * 文件 HTML 按来源路径,无来源的 HTML 按 toolCallId 去重。 */
37
+ export declare function buildToolUiCardKey(toolCallId: string, type: ToolUiCardContentType, content: string, sourcePath?: string): string;
38
+ /** 内部「阶段进度」卡片不对用户展示入口。 */
39
+ export declare function isInternalStatusToolUiCard(card: {
40
+ title?: string | null;
41
+ } | null): boolean;
42
+ /** app-dev 会话里的应用预览卡片:走专门的预览页签,不开普通侧栏 artifact。 */
43
+ export declare function isAppDevToolUiCard(card: ToolUiCard, isAppDev: boolean): boolean;
44
+ export interface InlineToolUiCardEntry {
45
+ key: string;
46
+ toolCallId: string;
47
+ card: ToolUiCard;
48
+ }
49
+ /** 从一轮消息里收集 target=inline 的卡片(渲染进消息流)。 */
50
+ export declare function collectInlineToolUiCards(messages: ChatMessage[]): InlineToolUiCardEntry[];
51
+ export interface PreviewToolUiCardEntry {
52
+ key: string;
53
+ toolCall: ToolCallInfo;
54
+ card: ToolUiCard;
55
+ /** 所属消息的 blocks;调用方需要还原卡片所在 block 上下文时用。 */
56
+ blocks: ContentBlock[];
57
+ }
58
+ /** 从一轮消息里收集 target=preview 的卡片(进侧栏/面板,不进消息流),
59
+ * 并绑定回所属的 toolCall。 */
60
+ export declare function collectPreviewToolUiCards(messages: ChatMessage[]): PreviewToolUiCardEntry[];
@@ -0,0 +1,2 @@
1
+ /** Return true for non-null, non-array objects. */
2
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
package/dist/socket.d.ts CHANGED
@@ -4,6 +4,8 @@ import type { ClientToServerEvents, ServerToClientEvents } from "./types/socket-
4
4
  export type TypedSocket = Socket<ServerToClientEvents, ClientToServerEvents>;
5
5
  export interface CreateSocketOptions extends AuthOptions {
6
6
  baseUrl: string;
7
+ /** MV3 service workers have WebSocket but no XMLHttpRequest. */
8
+ transports?: ("polling" | "websocket")[];
7
9
  path?: string;
8
10
  }
9
11
  export declare function createSocket(options: CreateSocketOptions): TypedSocket;
@@ -34,6 +34,7 @@ export declare namespace ChatSendPayloadSchema {
34
34
  type CompactionRatio = (number | null);
35
35
  type NativeApprovalPolicy = (("unlessTrusted" | "never") | null);
36
36
  type KbIds = (number[] | null);
37
+ type QueueWhenRunning = boolean;
37
38
  interface ChatSendPayload {
38
39
  session_id: SessionId;
39
40
  message: Message;
@@ -52,6 +53,7 @@ export declare namespace ChatSendPayloadSchema {
52
53
  compaction_ratio?: CompactionRatio;
53
54
  native_approval_policy?: NativeApprovalPolicy;
54
55
  kb_ids?: KbIds;
56
+ queue_when_running?: QueueWhenRunning;
55
57
  [k: string]: unknown;
56
58
  }
57
59
  interface Message {
@@ -76,9 +78,11 @@ export type ChatStopPayload = ChatStopPayloadSchema.ChatStopPayload;
76
78
  export declare namespace ChatAppendPayloadSchema {
77
79
  type SessionId = string;
78
80
  type Message = string;
81
+ type ClientRequestId = (string | null);
79
82
  interface ChatAppendPayload {
80
83
  session_id: SessionId;
81
84
  message: Message;
85
+ client_request_id?: ClientRequestId;
82
86
  [k: string]: unknown;
83
87
  }
84
88
  }
@@ -91,6 +95,72 @@ export declare namespace ChatCompactPayloadSchema {
91
95
  }
92
96
  }
93
97
  export type ChatCompactPayload = ChatCompactPayloadSchema.ChatCompactPayload;
98
+ export declare namespace ChatQueueListPayloadSchema {
99
+ type SessionId = string;
100
+ interface ChatQueueListPayload {
101
+ session_id: SessionId;
102
+ [k: string]: unknown;
103
+ }
104
+ }
105
+ export type ChatQueueListPayload = ChatQueueListPayloadSchema.ChatQueueListPayload;
106
+ export declare namespace ChatQueueUpdatePayloadSchema {
107
+ type SessionId = string;
108
+ type ItemId = string;
109
+ type ExpectedVersion = number;
110
+ type Message = string;
111
+ interface ChatQueueUpdatePayload {
112
+ session_id: SessionId;
113
+ item_id: ItemId;
114
+ expected_version: ExpectedVersion;
115
+ message: Message;
116
+ [k: string]: unknown;
117
+ }
118
+ }
119
+ export type ChatQueueUpdatePayload = ChatQueueUpdatePayloadSchema.ChatQueueUpdatePayload;
120
+ export declare namespace ChatQueueReorderPayloadSchema {
121
+ type SessionId = string;
122
+ type ExpectedRevision = number;
123
+ type OrderedIds = string[];
124
+ interface ChatQueueReorderPayload {
125
+ session_id: SessionId;
126
+ expected_revision: ExpectedRevision;
127
+ ordered_ids: OrderedIds;
128
+ [k: string]: unknown;
129
+ }
130
+ }
131
+ export type ChatQueueReorderPayload = ChatQueueReorderPayloadSchema.ChatQueueReorderPayload;
132
+ export declare namespace ChatQueueCancelPayloadSchema {
133
+ type SessionId = string;
134
+ type ItemId = string;
135
+ type ExpectedVersion = (number | null);
136
+ interface ChatQueueCancelPayload {
137
+ session_id: SessionId;
138
+ item_id: ItemId;
139
+ expected_version?: ExpectedVersion;
140
+ [k: string]: unknown;
141
+ }
142
+ }
143
+ export type ChatQueueCancelPayload = ChatQueueCancelPayloadSchema.ChatQueueCancelPayload;
144
+ export declare namespace ChatQueueDeliverPayloadSchema {
145
+ type SessionId = string;
146
+ type ItemId = string;
147
+ type ExpectedVersion = number;
148
+ interface ChatQueueDeliverPayload {
149
+ session_id: SessionId;
150
+ item_id: ItemId;
151
+ expected_version: ExpectedVersion;
152
+ [k: string]: unknown;
153
+ }
154
+ }
155
+ export type ChatQueueDeliverPayload = ChatQueueDeliverPayloadSchema.ChatQueueDeliverPayload;
156
+ export declare namespace ChatQueueResumePayloadSchema {
157
+ type SessionId = string;
158
+ interface ChatQueueResumePayload {
159
+ session_id: SessionId;
160
+ [k: string]: unknown;
161
+ }
162
+ }
163
+ export type ChatQueueResumePayload = ChatQueueResumePayloadSchema.ChatQueueResumePayload;
94
164
  export declare namespace SessionSubscribePayloadSchema {
95
165
  type SessionId = string;
96
166
  type Mode = string;
@@ -183,6 +253,43 @@ export declare namespace ChatEndPayloadSchema {
183
253
  }
184
254
  }
185
255
  export type ChatEndPayload = ChatEndPayloadSchema.ChatEndPayload;
256
+ export declare namespace ChatQueueUpdatedPayloadSchema {
257
+ type SessionId = string;
258
+ type Revision = number;
259
+ type Paused = boolean;
260
+ type PauseReason = (string | null);
261
+ type Id = string;
262
+ type Content = string;
263
+ type Position = number;
264
+ type Version = number;
265
+ type Status = string;
266
+ type CreatedAt = string;
267
+ type UpdatedAt = string;
268
+ type TargetRunId = (string | null);
269
+ type Error = (string | null);
270
+ type Items = ChatQueueItem[];
271
+ interface ChatQueueUpdatedPayload {
272
+ session_id: SessionId;
273
+ revision: Revision;
274
+ paused?: Paused;
275
+ pause_reason?: PauseReason;
276
+ items?: Items;
277
+ [k: string]: unknown;
278
+ }
279
+ interface ChatQueueItem {
280
+ id: Id;
281
+ content: Content;
282
+ position: Position;
283
+ version: Version;
284
+ status: Status;
285
+ created_at: CreatedAt;
286
+ updated_at: UpdatedAt;
287
+ target_run_id?: TargetRunId;
288
+ error?: Error;
289
+ [k: string]: unknown;
290
+ }
291
+ }
292
+ export type ChatQueueUpdatedPayload = ChatQueueUpdatedPayloadSchema.ChatQueueUpdatedPayload;
186
293
  export declare namespace SessionCreatedPayloadSchema {
187
294
  type SessionId = string;
188
295
  interface SessionCreatedPayload {
@@ -192,6 +299,8 @@ export declare namespace SessionCreatedPayloadSchema {
192
299
  }
193
300
  export type SessionCreatedPayload = SessionCreatedPayloadSchema.SessionCreatedPayload;
194
301
  export declare namespace SessionUpdatedPayloadSchema {
302
+ type WorkspacePath = (string | null);
303
+ type ChatGroupId = (string | null);
195
304
  type SessionId = string;
196
305
  type Model = (string | null);
197
306
  type ReplayState = ({
@@ -201,6 +310,8 @@ export declare namespace SessionUpdatedPayloadSchema {
201
310
  type ProjectId = (number | null);
202
311
  type ProjectName = (string | null);
203
312
  interface SessionUpdatedPayload {
313
+ workspace_path?: WorkspacePath;
314
+ chat_group_id?: ChatGroupId;
204
315
  session_id: SessionId;
205
316
  model?: Model;
206
317
  replay_state?: ReplayState;
@@ -221,6 +332,16 @@ export declare namespace WorkspaceFilesChangedPayloadSchema {
221
332
  }
222
333
  }
223
334
  export type WorkspaceFilesChangedPayload = WorkspaceFilesChangedPayloadSchema.WorkspaceFilesChangedPayload;
335
+ export declare namespace MCPAppChangedPayloadSchema {
336
+ type SessionId = string;
337
+ type SourceId = string;
338
+ interface MCPAppChangedPayload {
339
+ session_id: SessionId;
340
+ source_id: SourceId;
341
+ [k: string]: unknown;
342
+ }
343
+ }
344
+ export type MCPAppChangedPayload = MCPAppChangedPayloadSchema.MCPAppChangedPayload;
224
345
  export declare namespace SystemErrorPayloadSchema {
225
346
  type Message = string;
226
347
  type SessionId = (string | null);
@@ -278,6 +399,20 @@ export declare namespace TurnEventsPayloadSchema {
278
399
  }
279
400
  }
280
401
  export type TurnEventsPayload = TurnEventsPayloadSchema.TurnEventsPayload;
402
+ export declare namespace TurnTimingPayloadSchema {
403
+ type SessionId = string;
404
+ type LoopName = string;
405
+ type TurnId = string;
406
+ type FirstTokenDeliveryMs = number;
407
+ interface TurnTimingPayload {
408
+ session_id: SessionId;
409
+ loop_name: LoopName;
410
+ turn_id: TurnId;
411
+ first_token_delivery_ms: FirstTokenDeliveryMs;
412
+ [k: string]: unknown;
413
+ }
414
+ }
415
+ export type TurnTimingPayload = TurnTimingPayloadSchema.TurnTimingPayload;
281
416
  export declare namespace AsrReadyPayloadSchema {
282
417
  type RequestId = string;
283
418
  type Provider = string;
@@ -394,11 +529,58 @@ export declare namespace ChatCompactAckSchema {
394
529
  }
395
530
  }
396
531
  export type ChatCompactAck = ChatCompactAckSchema.ChatCompactAck;
532
+ export declare namespace ChatQueueAckSchema {
533
+ type SessionId = string;
534
+ type Revision = number;
535
+ type Paused = boolean;
536
+ type PauseReason = (string | null);
537
+ type Id = string;
538
+ type Content = string;
539
+ type Position = number;
540
+ type Version = number;
541
+ type Status = string;
542
+ type CreatedAt = string;
543
+ type UpdatedAt = string;
544
+ type TargetRunId = (string | null);
545
+ type Error = (string | null);
546
+ type Items = ChatQueueItem[];
547
+ type Status1 = string;
548
+ type Message = (string | null);
549
+ interface ChatQueueAck {
550
+ session_id: SessionId;
551
+ revision: Revision;
552
+ paused?: Paused;
553
+ pause_reason?: PauseReason;
554
+ items?: Items;
555
+ status?: Status1;
556
+ message?: Message;
557
+ [k: string]: unknown;
558
+ }
559
+ interface ChatQueueItem {
560
+ id: Id;
561
+ content: Content;
562
+ position: Position;
563
+ version: Version;
564
+ status: Status;
565
+ created_at: CreatedAt;
566
+ updated_at: UpdatedAt;
567
+ target_run_id?: TargetRunId;
568
+ error?: Error;
569
+ [k: string]: unknown;
570
+ }
571
+ }
572
+ export type ChatQueueAck = ChatQueueAckSchema.ChatQueueAck;
397
573
  export interface ClientToServerEvents {
398
574
  "chat:send": (payload: ChatSendPayload, ack: (response: ChatSendAck) => void) => void;
399
575
  "chat:stop": (payload: ChatStopPayload, ack: (response: ChatStopAck) => void) => void;
400
- "chat:append": (payload: ChatAppendPayload) => void;
576
+ "chat:append": (payload: ChatAppendPayload, ack: (response: ChatQueueAck) => void) => void;
401
577
  "chat:compact": (payload: ChatCompactPayload, ack: (response: ChatCompactAck) => void) => void;
578
+ "chat:queue:list": (payload: ChatQueueListPayload, ack: (response: ChatQueueAck) => void) => void;
579
+ "chat:queue:update": (payload: ChatQueueUpdatePayload, ack: (response: ChatQueueAck) => void) => void;
580
+ "chat:queue:reorder": (payload: ChatQueueReorderPayload, ack: (response: ChatQueueAck) => void) => void;
581
+ "chat:queue:cancel": (payload: ChatQueueCancelPayload, ack: (response: ChatQueueAck) => void) => void;
582
+ "chat:queue:deliver": (payload: ChatQueueDeliverPayload, ack: (response: ChatQueueAck) => void) => void;
583
+ "chat:queue:resume": (payload: ChatQueueResumePayload, ack: (response: ChatQueueAck) => void) => void;
402
584
  "session:subscribe": (payload: SessionSubscribePayload) => void;
403
585
  "session:subscribe_batch": (payload: SessionSubscribeBatchPayload) => void;
404
586
  "session:unsubscribe": (payload: SessionUnsubscribePayload) => void;
@@ -412,13 +594,15 @@ export interface ClientToServerEvents {
412
594
  export interface ServerToClientEvents {
413
595
  "chat:start": (payload: ChatStartPayload) => void;
414
596
  "chat:end": (payload: ChatEndPayload) => void;
415
- "chat:append:ack": (payload: unknown) => void;
597
+ "chat:queue:updated": (payload: ChatQueueUpdatedPayload) => void;
416
598
  "session:created": (payload: SessionCreatedPayload) => void;
417
599
  "session:updated": (payload: SessionUpdatedPayload) => void;
418
600
  "workspace:files_changed": (payload: WorkspaceFilesChangedPayload) => void;
601
+ "mcp-app:changed": (payload: MCPAppChangedPayload) => void;
419
602
  "system:error": (payload: SystemErrorPayload) => void;
420
603
  "system:notification": (payload: SystemNotificationPayload) => void;
421
604
  "turn:events": (payload: TurnEventsPayload) => void;
605
+ "turn:timing": (payload: TurnTimingPayload) => void;
422
606
  "task:updated": (payload: unknown) => void;
423
607
  "task:synced": (payload: unknown) => void;
424
608
  "artifact:created": (payload: unknown) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blade-hq/agent-client",
3
- "version": "2610.0.0-rc.0",
3
+ "version": "2610.0.0",
4
4
  "description": "Blade Agent 框架无关客户端:会话实时状态机、REST 通道、弹窗登录、页面协作。浏览器与 Node.js 通用。",
5
5
  "repository": {
6
6
  "type": "git",