@blade-hq/agent-client 1.2.1-alpha.4 → 1.2.1-beta.1

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.
@@ -1,4 +1,4 @@
1
- import type { BackgroundTask } from "../schemas/background";
1
+ import type { BackgroundTask, BackgroundTaskStopResult } from "../schemas/background";
2
2
  import type { TurnProjection } from "../schemas/projection";
3
3
  import type { PublishedSolutionRef, SessionDetail, SessionInfo, TemplateId } from "../schemas/session";
4
4
  import type { Task } from "../schemas/task";
@@ -262,10 +262,7 @@ export declare class SessionsResource {
262
262
  }>;
263
263
  listBackgroundTasks(sessionId: string, init?: RequestInit): Promise<BackgroundTask[]>;
264
264
  getBackgroundTask(sessionId: string, taskId: string, tail?: number, init?: RequestInit): Promise<BackgroundTask>;
265
- stopBackgroundTask(sessionId: string, taskId: string): Promise<{
266
- message: string;
267
- task?: BackgroundTask | null;
268
- }>;
265
+ stopBackgroundTask(sessionId: string, taskId: string): Promise<BackgroundTaskStopResult>;
269
266
  probeSessionUrl(sessionId: string, url: string): Promise<{
270
267
  reachable: boolean;
271
268
  requires_proxy: boolean;
@@ -2,8 +2,16 @@ export interface BackgroundTask {
2
2
  id: string;
3
3
  command: string;
4
4
  description?: string;
5
- status: "queued" | "starting" | "running" | "succeeded" | "done" | "failed" | "timeout" | "cancelled" | "lost";
6
- legacy_status?: "running" | "done" | "failed";
5
+ /**
6
+ * The server's real status. Never collapse these client-side: telling a user
7
+ * that a cancelled or lost task is "done" is exactly the lie this replaced.
8
+ *
9
+ * `lost` means the platform stopped being able to track the process, not
10
+ * that it failed — it may still be running.
11
+ */
12
+ status: "starting" | "running" | "cancelling" | "succeeded" | "failed" | "cancelled" | "lost";
13
+ /** Set on `failed` to say why, e.g. `start_failed`, `log_budget_exceeded`. */
14
+ failure_reason?: string | null;
7
15
  exit_code?: number | null;
8
16
  elapsed_seconds: number;
9
17
  output_lines_count?: number;
@@ -12,5 +20,12 @@ export interface BackgroundTask {
12
20
  log_path?: string | null;
13
21
  started_at?: number | null;
14
22
  finished_at?: number | null;
15
- heartbeat_at?: number | null;
23
+ }
24
+ /** Outcome of a stop request. `ok: false` is a real answer, not an error. */
25
+ export interface BackgroundTaskStopResult {
26
+ ok: boolean;
27
+ message: string;
28
+ /** Why the stop could not be confirmed, e.g. `still_running`, `probe_unknown`. */
29
+ reason?: string | null;
30
+ task?: BackgroundTask | null;
16
31
  }
@@ -67,6 +67,7 @@ export declare class AgentSession {
67
67
  private disposed;
68
68
  private getAppContext;
69
69
  private sendPending;
70
+ private manualCompactionPending;
70
71
  private readonly deliveredCommandKeys;
71
72
  private readonly deliveredToolPreviews;
72
73
  private readonly oomNotifiedKeys;
@@ -99,8 +100,9 @@ export declare class AgentSession {
99
100
  */
100
101
  attachApp(options: AttachAppOptions): Promise<AppCliAttachment | null>;
101
102
  /** 发送一条消息。字符串或多模态内容均可。 */
102
- send(content: MessageContent, options?: SendOptions): Promise<void>;
103
+ send(content: MessageContent, options?: SendOptions): Promise<boolean>;
103
104
  private sendUnlocked;
105
+ private rollbackOptimisticSend;
104
106
  /** 智能体运行期间追加补充说明(不打断当前回复)。 */
105
107
  append(text: string): void;
106
108
  /** 停止当前回复。 */
@@ -166,15 +168,7 @@ export declare class AgentSession {
166
168
  /** @internal */
167
169
  _handleSystemNotification(loopId: string, notification: Record<string, unknown>): void;
168
170
  /** @internal */
169
- _handleBackgroundTask(task: {
170
- id: string;
171
- command: string;
172
- description?: string;
173
- status: "running" | "done" | "failed";
174
- exitCode?: number | null;
175
- elapsedSeconds: number;
176
- output?: string;
177
- }): void;
171
+ _handleBackgroundTask(task: AgentSessionEvents["backgroundTask"]): void;
178
172
  /** @internal */
179
173
  _handleArtifact(event: AgentSessionEvents["artifact"]): void;
180
174
  /** @internal 加入房间的应答里带 is_running,据此校准流式状态。 */
@@ -88,7 +88,14 @@ export interface AgentSessionEvents {
88
88
  id: string;
89
89
  command: string;
90
90
  description?: string;
91
- status: "running" | "done" | "failed";
91
+ /**
92
+ * 与 REST 一致的真实状态。不要在客户端合并这些值:把 cancelled / lost
93
+ * 显示成"完成"会让订阅方拿到与 REST 相反的结论。
94
+ * lost 表示平台跟丢了这个进程,不代表它失败,也可能仍在运行。
95
+ */
96
+ status: "starting" | "running" | "cancelling" | "succeeded" | "failed" | "cancelled" | "lost";
97
+ /** failed 时说明原因,如 start_failed、log_budget_exceeded。 */
98
+ failureReason?: string | null;
92
99
  exitCode?: number | null;
93
100
  elapsedSeconds: number;
94
101
  output?: string;
@@ -344,6 +344,18 @@ export declare namespace AgentBoardFileOpPayloadSchema {
344
344
  }
345
345
  }
346
346
  export type AgentBoardFileOpPayload = AgentBoardFileOpPayloadSchema.AgentBoardFileOpPayload;
347
+ export declare namespace ChatSendAckSchema {
348
+ type Status = string;
349
+ type Message = (string | null);
350
+ type Code = (string | number | null);
351
+ interface ChatSendAck {
352
+ status: Status;
353
+ message?: Message;
354
+ code?: Code;
355
+ [k: string]: unknown;
356
+ }
357
+ }
358
+ export type ChatSendAck = ChatSendAckSchema.ChatSendAck;
347
359
  export declare namespace ChatStopAckSchema {
348
360
  type Status = string;
349
361
  type Message = (string | null);
@@ -369,7 +381,7 @@ export declare namespace ChatCompactAckSchema {
369
381
  }
370
382
  export type ChatCompactAck = ChatCompactAckSchema.ChatCompactAck;
371
383
  export interface ClientToServerEvents {
372
- "chat:send": (payload: ChatSendPayload) => void;
384
+ "chat:send": (payload: ChatSendPayload, ack: (response: ChatSendAck) => void) => void;
373
385
  "chat:stop": (payload: ChatStopPayload, ack: (response: ChatStopAck) => void) => void;
374
386
  "chat:append": (payload: ChatAppendPayload) => void;
375
387
  "chat:compact": (payload: ChatCompactPayload, ack: (response: ChatCompactAck) => void) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blade-hq/agent-client",
3
- "version": "1.2.1-alpha.4",
3
+ "version": "1.2.1-beta.1",
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
- 共 116 个公开声明。
6
+ 共 117 个公开声明。
7
7
 
8
8
  ## `ActiveCompactionState` (interface)
9
9
 
@@ -49,7 +49,7 @@ listDir: (dirPath?: string) => Promise<FileEntry[]>
49
49
  off: <K extends keyof AgentSessionEvents>(name: K, handler: (event: AgentSessionEvents[K]) => void) => void
50
50
  on: <K extends keyof AgentSessionEvents>(name: K, handler: (event: AgentSessionEvents[K]) => void) => () => void
51
51
  onCommand: (action: string, handler: CommandHandler) => () => void
52
- send: (content: MessageContent, options?: SendOptions) => Promise<void>
52
+ send: (content: MessageContent, options?: SendOptions) => Promise<boolean>
53
53
  sessionId: string
54
54
  stop: () => Promise<Record<string, unknown>>
55
55
  subscribe: (listener: () => void) => () => void
@@ -66,7 +66,7 @@ export type AgentSessionEventName = keyof AgentSessionEvents
66
66
  ```ts
67
67
  artifact: { filePath: string; contentType: string; title: string; content: string; oldString?: string; newString?: string; kind: "created" | "updated"; }
68
68
  attachRequested: { label: string; content: string; }
69
- backgroundTask: { id: string; command: string; description?: string; status: "running" | "done" | "failed"; exitCode?: number | null; elapsedSeconds: number; output?: string; }
69
+ 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; }
70
70
  chatEnd: { status: string; }
71
71
  command: { action: string; payload: unknown; toolCallId?: string; }
72
72
  error: { message: string; }
@@ -161,16 +161,24 @@ command: string
161
161
  description: string | undefined
162
162
  elapsed_seconds: number
163
163
  exit_code: number | null | undefined
164
+ failure_reason: string | null | undefined
164
165
  finished_at: number | null | undefined
165
- heartbeat_at: number | null | undefined
166
166
  id: string
167
- legacy_status: "failed" | "running" | "done" | undefined
168
167
  log_path: string | null | undefined
169
168
  output: string | undefined
170
169
  output_lines_count: number | undefined
171
170
  output_preview: string[] | undefined
172
171
  started_at: number | null | undefined
173
- status: "failed" | "running" | "done" | "cancelled" | "queued" | "starting" | "succeeded" | "timeout" | "lost"
172
+ status: "failed" | "running" | "cancelled" | "starting" | "cancelling" | "succeeded" | "lost"
173
+ ```
174
+
175
+ ## `BackgroundTaskStopResult` (interface)
176
+
177
+ ```ts
178
+ message: string
179
+ ok: boolean
180
+ reason: string | null | undefined
181
+ task: BackgroundTask | null | undefined
174
182
  ```
175
183
 
176
184
  ## `BizRole` (interface)
@@ -939,7 +947,7 @@ rewindSession: (sessionId: string, checkpointId: string) => Promise<{ id: string
939
947
  setSessionEnv: (sessionId: string, env: Record<string, string>) => Promise<SessionDetail>
940
948
  shareFile: (sessionId: string, sourcePath: string, linkName?: string, shareFolder?: string) => Promise<{ path: string; target: string; }>
941
949
  startReplaySession: (sourceSessionId: string, speed?: 1 | 2 | 5) => Promise<{ session_id: string; }>
942
- stopBackgroundTask: (sessionId: string, taskId: string) => Promise<{ message: string; task?: BackgroundTask | null; }>
950
+ stopBackgroundTask: (sessionId: string, taskId: string) => Promise<BackgroundTaskStopResult>
943
951
  switchBranch: (sessionId: string, checkpointId: string) => Promise<{ id: string; leaf_id: string; }>
944
952
  tokenizeMessages: (messages: Array<Record<string, unknown>>, options?: { model?: string; add_generation_prompt?: boolean; enable_thinking?: boolean | null; tools?: Array<Record<string, unknown>>; }) => Promise<TokenizeResult>
945
953
  tokenizePrompt: (prompt: string, model?: string) => Promise<TokenizeResult>