@blade-hq/agent-client 2610.0.0-beta.7 → 2610.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.
Files changed (40) hide show
  1. package/README.md +248 -9
  2. package/dist/auth.d.ts +0 -1
  3. package/dist/blade-client.d.ts +21 -3
  4. package/dist/index.d.ts +35 -6
  5. package/dist/index.js +2210 -268
  6. package/dist/index.js.map +1 -1
  7. package/dist/platform-endpoints.d.ts +14 -0
  8. package/dist/polling-backoff.d.ts +11 -0
  9. package/dist/resources/chat-groups.d.ts +26 -0
  10. package/dist/resources/computers.d.ts +115 -0
  11. package/dist/resources/models.d.ts +2 -0
  12. package/dist/resources/plugins.d.ts +43 -0
  13. package/dist/resources/sessions.d.ts +186 -1
  14. package/dist/resources/site-visits.d.ts +32 -0
  15. package/dist/rest.d.ts +8 -0
  16. package/dist/schemas/context.d.ts +49 -0
  17. package/dist/schemas/event.d.ts +9 -0
  18. package/dist/schemas/mcp-app.d.ts +30 -0
  19. package/dist/schemas/message-utils.d.ts +13 -1
  20. package/dist/schemas/message.d.ts +3 -0
  21. package/dist/schemas/projection.d.ts +37 -2
  22. package/dist/schemas/session.d.ts +9 -1
  23. package/dist/session/agent-session.d.ts +142 -16
  24. package/dist/session/events.d.ts +4 -0
  25. package/dist/session/history-page.d.ts +9 -0
  26. package/dist/session/hub.d.ts +9 -1
  27. package/dist/session/queue.d.ts +99 -0
  28. package/dist/session/state.d.ts +18 -2
  29. package/dist/shared/auth-busy.d.ts +9 -0
  30. package/dist/shared/projection/builder.d.ts +12 -0
  31. package/dist/shared/projection/context.d.ts +3 -0
  32. package/dist/shared/projection/helpers.d.ts +2 -2
  33. package/dist/shared/projection/history.d.ts +1 -0
  34. package/dist/shared/projection/index.d.ts +2 -1
  35. package/dist/shared/projection/state.d.ts +7 -0
  36. package/dist/shared/tool-ui-card.d.ts +58 -0
  37. package/dist/shared/type-guards.d.ts +2 -0
  38. package/dist/types/socket-events.d.ts +195 -6
  39. package/package.json +1 -1
  40. package/public-api.md +918 -12
@@ -4,6 +4,7 @@ export interface RawHistoryEntry {
4
4
  kind?: string;
5
5
  loop_name?: string;
6
6
  message?: Record<string, unknown>;
7
+ source?: Record<string, unknown>;
7
8
  data?: Record<string, unknown>;
8
9
  timestamp?: string;
9
10
  [key: string]: unknown;
@@ -1,3 +1,4 @@
1
- export { acceptedPostChatFollowupCompletesLatestRun, ClientProjectionBuilder, type RawEvent, type ProjectionUpdate, } from "./builder";
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 { buildContextTurn } from "./context";
@@ -10,6 +10,13 @@ export interface TurnState {
10
10
  toolCalls: ToolCallProjection[];
11
11
  usage: Record<string, unknown> | null;
12
12
  responseDone: boolean;
13
+ firstTokenMs: number | null;
14
+ streamDurationMs: number | null;
15
+ firstTokenDeliveryMs: number | null;
16
+ /** 生产者上报的模型请求时序;缺失时保持 null,不用浏览器时间补(#2581 A1/I1)。 */
17
+ modelStartedAt: string | null;
18
+ modelDurationMs: number | null;
19
+ modelStartedAtReported: boolean;
13
20
  memoryRefs: MemoryRef[] | null;
14
21
  parentForkToolCallId: string | null;
15
22
  }
@@ -0,0 +1,58 @@
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
+ /** 历史投影标记:绝不重新解析 resourceUri(刷新不重放 MCP/资源读取)。 */
15
+ archived?: boolean;
16
+ target: "inline" | "preview";
17
+ height: number;
18
+ title?: string;
19
+ /** 留档的 MCP App 来源身份与调用数据(来源 server、ui:// 资源、CSP 元数据)。 */
20
+ mcpApp?: McpAppData;
21
+ }
22
+ /** 严格守卫:target/height 缺失、archived 无留档 HTML、或 mcpApp 来源身份残缺的
23
+ * 卡片一律判无效,消息流、侧栏、toolPreview 事件三处一致降级(不渲染、不发事件、
24
+ * 不推送)。后端 `_tool_ui_meta.py` 总会补齐 target/height 默认值,判无效即数据畸形。 */
25
+ export declare function isToolUiCard(value: unknown): value is ToolUiCard;
26
+ export type ToolUiCardContentType = "resource-html" | "resource-uri";
27
+ /** 解析卡片实际要渲染的内容。archived 卡片只认留档 HTML,绝不回退到
28
+ * resourceUri——历史恢复/浏览器刷新不得因此重新发起 MCP 资源读取。 */
29
+ export declare function resolveToolUiCardContent(card: ToolUiCard): {
30
+ type: ToolUiCardContentType;
31
+ content: string;
32
+ } | null;
33
+ /** 卡片实例身份/去重键:uri 卡片按内容去重(同一 URI 多次产出只留一份),
34
+ * html 卡片按 toolCallId 去重(同一调用的新 HTML 覆盖旧内容)。 */
35
+ export declare function buildToolUiCardKey(toolCallId: string, type: ToolUiCardContentType, content: string): string;
36
+ /** 内部「阶段进度」卡片不对用户展示入口。 */
37
+ export declare function isInternalStatusToolUiCard(card: {
38
+ title?: string | null;
39
+ } | null): boolean;
40
+ /** app-dev 会话里的应用预览卡片:走专门的预览页签,不开普通侧栏 artifact。 */
41
+ export declare function isAppDevToolUiCard(card: ToolUiCard, isAppDev: boolean): boolean;
42
+ export interface InlineToolUiCardEntry {
43
+ key: string;
44
+ toolCallId: string;
45
+ card: ToolUiCard;
46
+ }
47
+ /** 从一轮消息里收集 target=inline 的卡片(渲染进消息流)。 */
48
+ export declare function collectInlineToolUiCards(messages: ChatMessage[]): InlineToolUiCardEntry[];
49
+ export interface PreviewToolUiCardEntry {
50
+ key: string;
51
+ toolCall: ToolCallInfo;
52
+ card: ToolUiCard;
53
+ /** 所属消息的 blocks;调用方需要还原卡片所在 block 上下文时用。 */
54
+ blocks: ContentBlock[];
55
+ }
56
+ /** 从一轮消息里收集 target=preview 的卡片(进侧栏/面板,不进消息流),
57
+ * 并绑定回所属的 toolCall。 */
58
+ 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>;
@@ -32,6 +32,9 @@ export declare namespace ChatSendPayloadSchema {
32
32
  [k: string]: unknown;
33
33
  } | null);
34
34
  type CompactionRatio = (number | null);
35
+ type NativeApprovalPolicy = (("unlessTrusted" | "never") | null);
36
+ type KbIds = (number[] | null);
37
+ type QueueWhenRunning = boolean;
35
38
  interface ChatSendPayload {
36
39
  session_id: SessionId;
37
40
  message: Message;
@@ -48,6 +51,9 @@ export declare namespace ChatSendPayloadSchema {
48
51
  runtime_env?: RuntimeEnv;
49
52
  app_context?: AppContext;
50
53
  compaction_ratio?: CompactionRatio;
54
+ native_approval_policy?: NativeApprovalPolicy;
55
+ kb_ids?: KbIds;
56
+ queue_when_running?: QueueWhenRunning;
51
57
  [k: string]: unknown;
52
58
  }
53
59
  interface Message {
@@ -72,9 +78,11 @@ export type ChatStopPayload = ChatStopPayloadSchema.ChatStopPayload;
72
78
  export declare namespace ChatAppendPayloadSchema {
73
79
  type SessionId = string;
74
80
  type Message = string;
81
+ type ClientRequestId = (string | null);
75
82
  interface ChatAppendPayload {
76
83
  session_id: SessionId;
77
84
  message: Message;
85
+ client_request_id?: ClientRequestId;
78
86
  [k: string]: unknown;
79
87
  }
80
88
  }
@@ -87,20 +95,84 @@ export declare namespace ChatCompactPayloadSchema {
87
95
  }
88
96
  }
89
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;
90
164
  export declare namespace SessionSubscribePayloadSchema {
91
165
  type SessionId = string;
92
166
  type Mode = string;
93
167
  type EventFormat = "raw";
94
168
  type AfterSequence = number;
95
169
  type Resume = boolean;
96
- type StreamTokens = boolean;
97
170
  interface SessionSubscribePayload {
98
171
  session_id: SessionId;
99
172
  mode?: Mode;
100
173
  event_format?: EventFormat;
101
174
  after_sequence?: AfterSequence;
102
175
  resume?: Resume;
103
- stream_tokens?: StreamTokens;
104
176
  [k: string]: unknown;
105
177
  }
106
178
  }
@@ -116,7 +188,6 @@ export declare namespace SessionSubscribeBatchPayloadSchema {
116
188
  type EventFormat = "raw";
117
189
  type AfterSequence = number;
118
190
  type Resume = boolean;
119
- type StreamTokens = boolean;
120
191
  interface SessionSubscribeBatchPayload {
121
192
  sessions: Sessions;
122
193
  [k: string]: unknown;
@@ -127,7 +198,6 @@ export declare namespace SessionSubscribeBatchPayloadSchema {
127
198
  event_format?: EventFormat;
128
199
  after_sequence?: AfterSequence;
129
200
  resume?: Resume;
130
- stream_tokens?: StreamTokens;
131
201
  [k: string]: unknown;
132
202
  }
133
203
  }
@@ -183,6 +253,51 @@ 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;
293
+ export declare namespace SessionCreatedPayloadSchema {
294
+ type SessionId = string;
295
+ interface SessionCreatedPayload {
296
+ session_id: SessionId;
297
+ [k: string]: unknown;
298
+ }
299
+ }
300
+ export type SessionCreatedPayload = SessionCreatedPayloadSchema.SessionCreatedPayload;
186
301
  export declare namespace SessionUpdatedPayloadSchema {
187
302
  type SessionId = string;
188
303
  type Model = (string | null);
@@ -213,6 +328,16 @@ export declare namespace WorkspaceFilesChangedPayloadSchema {
213
328
  }
214
329
  }
215
330
  export type WorkspaceFilesChangedPayload = WorkspaceFilesChangedPayloadSchema.WorkspaceFilesChangedPayload;
331
+ export declare namespace MCPAppChangedPayloadSchema {
332
+ type SessionId = string;
333
+ type SourceId = string;
334
+ interface MCPAppChangedPayload {
335
+ session_id: SessionId;
336
+ source_id: SourceId;
337
+ [k: string]: unknown;
338
+ }
339
+ }
340
+ export type MCPAppChangedPayload = MCPAppChangedPayloadSchema.MCPAppChangedPayload;
216
341
  export declare namespace SystemErrorPayloadSchema {
217
342
  type Message = string;
218
343
  type SessionId = (string | null);
@@ -270,6 +395,20 @@ export declare namespace TurnEventsPayloadSchema {
270
395
  }
271
396
  }
272
397
  export type TurnEventsPayload = TurnEventsPayloadSchema.TurnEventsPayload;
398
+ export declare namespace TurnTimingPayloadSchema {
399
+ type SessionId = string;
400
+ type LoopName = string;
401
+ type TurnId = string;
402
+ type FirstTokenDeliveryMs = number;
403
+ interface TurnTimingPayload {
404
+ session_id: SessionId;
405
+ loop_name: LoopName;
406
+ turn_id: TurnId;
407
+ first_token_delivery_ms: FirstTokenDeliveryMs;
408
+ [k: string]: unknown;
409
+ }
410
+ }
411
+ export type TurnTimingPayload = TurnTimingPayloadSchema.TurnTimingPayload;
273
412
  export declare namespace AsrReadyPayloadSchema {
274
413
  type RequestId = string;
275
414
  type Provider = string;
@@ -386,11 +525,58 @@ export declare namespace ChatCompactAckSchema {
386
525
  }
387
526
  }
388
527
  export type ChatCompactAck = ChatCompactAckSchema.ChatCompactAck;
528
+ export declare namespace ChatQueueAckSchema {
529
+ type SessionId = string;
530
+ type Revision = number;
531
+ type Paused = boolean;
532
+ type PauseReason = (string | null);
533
+ type Id = string;
534
+ type Content = string;
535
+ type Position = number;
536
+ type Version = number;
537
+ type Status = string;
538
+ type CreatedAt = string;
539
+ type UpdatedAt = string;
540
+ type TargetRunId = (string | null);
541
+ type Error = (string | null);
542
+ type Items = ChatQueueItem[];
543
+ type Status1 = string;
544
+ type Message = (string | null);
545
+ interface ChatQueueAck {
546
+ session_id: SessionId;
547
+ revision: Revision;
548
+ paused?: Paused;
549
+ pause_reason?: PauseReason;
550
+ items?: Items;
551
+ status?: Status1;
552
+ message?: Message;
553
+ [k: string]: unknown;
554
+ }
555
+ interface ChatQueueItem {
556
+ id: Id;
557
+ content: Content;
558
+ position: Position;
559
+ version: Version;
560
+ status: Status;
561
+ created_at: CreatedAt;
562
+ updated_at: UpdatedAt;
563
+ target_run_id?: TargetRunId;
564
+ error?: Error;
565
+ [k: string]: unknown;
566
+ }
567
+ }
568
+ export type ChatQueueAck = ChatQueueAckSchema.ChatQueueAck;
389
569
  export interface ClientToServerEvents {
390
570
  "chat:send": (payload: ChatSendPayload, ack: (response: ChatSendAck) => void) => void;
391
571
  "chat:stop": (payload: ChatStopPayload, ack: (response: ChatStopAck) => void) => void;
392
- "chat:append": (payload: ChatAppendPayload) => void;
572
+ "chat:append": (payload: ChatAppendPayload, ack: (response: ChatQueueAck) => void) => void;
393
573
  "chat:compact": (payload: ChatCompactPayload, ack: (response: ChatCompactAck) => void) => void;
574
+ "chat:queue:list": (payload: ChatQueueListPayload, ack: (response: ChatQueueAck) => void) => void;
575
+ "chat:queue:update": (payload: ChatQueueUpdatePayload, ack: (response: ChatQueueAck) => void) => void;
576
+ "chat:queue:reorder": (payload: ChatQueueReorderPayload, ack: (response: ChatQueueAck) => void) => void;
577
+ "chat:queue:cancel": (payload: ChatQueueCancelPayload, ack: (response: ChatQueueAck) => void) => void;
578
+ "chat:queue:deliver": (payload: ChatQueueDeliverPayload, ack: (response: ChatQueueAck) => void) => void;
579
+ "chat:queue:resume": (payload: ChatQueueResumePayload, ack: (response: ChatQueueAck) => void) => void;
394
580
  "session:subscribe": (payload: SessionSubscribePayload) => void;
395
581
  "session:subscribe_batch": (payload: SessionSubscribeBatchPayload) => void;
396
582
  "session:unsubscribe": (payload: SessionUnsubscribePayload) => void;
@@ -404,12 +590,15 @@ export interface ClientToServerEvents {
404
590
  export interface ServerToClientEvents {
405
591
  "chat:start": (payload: ChatStartPayload) => void;
406
592
  "chat:end": (payload: ChatEndPayload) => void;
407
- "chat:append:ack": (payload: unknown) => void;
593
+ "chat:queue:updated": (payload: ChatQueueUpdatedPayload) => void;
594
+ "session:created": (payload: SessionCreatedPayload) => void;
408
595
  "session:updated": (payload: SessionUpdatedPayload) => void;
409
596
  "workspace:files_changed": (payload: WorkspaceFilesChangedPayload) => void;
597
+ "mcp-app:changed": (payload: MCPAppChangedPayload) => void;
410
598
  "system:error": (payload: SystemErrorPayload) => void;
411
599
  "system:notification": (payload: SystemNotificationPayload) => void;
412
600
  "turn:events": (payload: TurnEventsPayload) => void;
601
+ "turn:timing": (payload: TurnTimingPayload) => void;
413
602
  "task:updated": (payload: unknown) => void;
414
603
  "task:synced": (payload: unknown) => void;
415
604
  "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-beta.7",
3
+ "version": "2610.0.0-beta.71",
4
4
  "description": "Blade Agent 框架无关客户端:会话实时状态机、REST 通道、弹窗登录、页面协作。浏览器与 Node.js 通用。",
5
5
  "repository": {
6
6
  "type": "git",