@blade-hq/agent-client 2610.0.0-beta.80 → 2610.0.0-beta.82

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.
@@ -108,6 +108,20 @@ export declare class AgentSession {
108
108
  private pendingReplayMode;
109
109
  private pendingReplayKbIds;
110
110
  private recentChatEndAt;
111
+ /**
112
+ * 最近一次已经通过 `error` 事件投递过的服务端失败(`message` + `code`)。
113
+ *
114
+ * `chat:send` 被代理时服务端会先发 `system:error`、再用同一条失败回 ack,两条
115
+ * 通道都会到达这里:前者走 `_handleSystemError`,后者走发送失败的回滚。不去重
116
+ * 的话调用方会收到两次同一个 `error`(重复提示、重试逻辑跑两遍)。
117
+ *
118
+ * 带代际边界,只认「本次 `emitWithAck` 等待期间」投递的那一条:否则队列/停止
119
+ * 失败留下的标记会一直挂着,之后一次无关的订阅失败只是文案码相同就被当成
120
+ * 重复而静音。用单调递增的代际号而不是时间戳,同一毫秒内的两条也不会混淆。
121
+ */
122
+ private lastDeliveredSystemError;
123
+ /** 每次投递 `system:error` 递增,用于判定某条失败是否属于本次等待。 */
124
+ private systemErrorGeneration;
111
125
  private subscriptionReplaySource;
112
126
  private disposed;
113
127
  private getAppContext;
@@ -288,7 +302,7 @@ export declare class AgentSession {
288
302
  /** @internal */
289
303
  _handleChatEnd(status: string): void;
290
304
  /** @internal */
291
- _handleSystemError(message: string): void;
305
+ _handleSystemError(message: string, code?: string): void;
292
306
  /** @internal */
293
307
  _handleTaskUpdated(tasks: unknown[]): void;
294
308
  /** @internal */
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 一次会话操作的失败。
3
+ *
4
+ * `code` 是服务端给的机器可读原因(如 `owner_timeout` / `route_broken`),
5
+ * 调用方据此决定要不要重试;`message` 是可以直接展示的业务文案,不要当协议解析。
6
+ */
7
+ export declare class AgentSessionError extends Error {
8
+ readonly name = "AgentSessionError";
9
+ readonly code?: string;
10
+ constructor(message: string, code?: string);
11
+ }
@@ -31,9 +31,15 @@ export interface AgentSessionEvents {
31
31
  chatEnd: {
32
32
  status: string;
33
33
  };
34
- /** 运行错误(system:error、发送失败等)。 */
34
+ /**
35
+ * 运行错误(system:error、发送失败等)。
36
+ *
37
+ * `code` 是服务端给的机器可读原因(如 `owner_timeout` / `route_broken`),
38
+ * 供调用方决定要不要重试;`message` 是可以直接展示的业务文案。
39
+ */
35
40
  error: {
36
41
  message: string;
42
+ code?: string;
37
43
  };
38
44
  /** planning / executing 模式切换。 */
39
45
  modeChange: {
@@ -65,6 +65,11 @@ export interface QueueOperationResult {
65
65
  /** 服务端快照;缺失时为 null,调用方不得据此清空本地队列。 */
66
66
  snapshot: SessionQueueSnapshot | null;
67
67
  message: string | null;
68
+ /**
69
+ * 服务端给的机器可读失败原因(如 `owner_timeout` / `route_broken` / `owner_busy`),
70
+ * 供调用方决定要不要重试;`message` 是可以直接展示的业务文案。
71
+ */
72
+ code?: string;
68
73
  }
69
74
  /** 判定一份载荷是不是完整的权威队列快照(广播事件用)。 */
70
75
  export declare function isSessionQueueSnapshot(value: unknown): value is SessionQueueSnapshot;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blade-hq/agent-client",
3
- "version": "2610.0.0-beta.80",
3
+ "version": "2610.0.0-beta.82",
4
4
  "description": "Blade Agent 框架无关客户端:会话实时状态机、REST 通道、弹窗登录、页面协作。浏览器与 Node.js 通用。",
5
5
  "repository": {
6
6
  "type": "git",
package/public-api.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > 本文件由 `scripts/public-api-report.mjs` 生成,请勿手改。
4
4
  > 公共面变更时重新生成本报告,并同步更新 README 对应章节——CI 会校验两者。
5
5
 
6
- 共 244 个公开声明。
6
+ 共 245 个公开声明。
7
7
 
8
8
  ## `acceptedPostChatFollowupCompletesLatestRun` (function)
9
9
 
@@ -103,6 +103,16 @@ subscribe: (listener: () => void) => () => void
103
103
  updateQueuedMessage: (itemId: string, expectedVersion: number, content: string) => Promise<QueueOperationResult>
104
104
  ```
105
105
 
106
+ ## `AgentSessionError` (class)
107
+
108
+ ```ts
109
+ cause: unknown
110
+ code: string | undefined
111
+ message: string
112
+ name: "AgentSessionError"
113
+ stack: string | undefined
114
+ ```
115
+
106
116
  ## `AgentSessionEventName` (type)
107
117
 
108
118
  ```ts
@@ -117,7 +127,7 @@ attachRequested: { label: string; content: string; }
117
127
  backgroundTask: { id: string; command: string; description?: string; status: "starting" | "running" | "cancelling" | "succeeded" | "failed" | "cancelled" | "lost"; failureReason?: string | null; exitCode?: number | null; elapsedSeconds: number; output?: string; }
118
128
  chatEnd: { status: string; }
119
129
  command: { action: string; payload: unknown; toolCallId?: string; }
120
- error: { message: string; }
130
+ error: { message: string; code?: string; }
121
131
  insertTextRequested: { text: string; }
122
132
  message: { message: ChatMessage; turn: TurnProjection; }
123
133
  modeChange: { mode: "planning" | "executing"; }
@@ -1325,6 +1335,7 @@ queuedMessageStatusLabel: (status: QueuedMessageStatus) => string
1325
1335
  ## `QueueOperationResult` (interface)
1326
1336
 
1327
1337
  ```ts
1338
+ code: string | undefined
1328
1339
  conflict: boolean
1329
1340
  message: string | null
1330
1341
  ok: boolean