@blade-hq/agent-client 1.2.1-alpha.2 → 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,6 +1,6 @@
1
- import type { BackgroundTask } from "../schemas/background";
1
+ import type { BackgroundTask, BackgroundTaskStopResult } from "../schemas/background";
2
2
  import type { TurnProjection } from "../schemas/projection";
3
- import type { SessionDetail, SessionInfo, TemplateId } from "../schemas/session";
3
+ import type { PublishedSolutionRef, SessionDetail, SessionInfo, TemplateId } from "../schemas/session";
4
4
  import type { Task } from "../schemas/task";
5
5
  import type { BladeClient, UploadProgress } from "../blade-client";
6
6
  import type { AgentSession } from "../session/agent-session";
@@ -9,7 +9,12 @@ import type { SessionProfile } from "../types/sdk-profile";
9
9
  export interface CreateSessionRequest {
10
10
  intent?: string;
11
11
  template_id?: TemplateId;
12
+ /** 正式 Solution 来源。Hub 使用 { source: "hub", org, name }。 */
13
+ solution_ref?: PublishedSolutionRef;
14
+ /** @deprecated 请使用结构化的 solution_ref;继续支持以保证现有 SDK 调用无感升级。 */
12
15
  solution_id?: string;
16
+ /** 从已有会话复制其不可变 Solution 与 Skill 运行快照。 */
17
+ solution_snapshot_session_id?: string;
13
18
  biz_role_id?: string | null;
14
19
  primary_skill_id?: string | null;
15
20
  model?: string | null;
@@ -150,6 +155,12 @@ export interface ImportPreview {
150
155
  skills: ImportPreviewSkill[];
151
156
  scenario: ImportPreviewScenario | null;
152
157
  }
158
+ export interface ImportSessionOptions {
159
+ /** 导入后改用这个正式 Solution 的最新版。 */
160
+ solution_ref?: PublishedSolutionRef;
161
+ /** 导入后改用已有会话的完整运行快照。 */
162
+ solution_snapshot_session_id?: string;
163
+ }
153
164
  export declare class SessionsResource {
154
165
  private client;
155
166
  constructor(client: BladeClient);
@@ -170,6 +181,7 @@ export declare class SessionsResource {
170
181
  offset: number;
171
182
  template_id_prefix?: string;
172
183
  solution_id?: string;
184
+ solution_registry_id?: string;
173
185
  q?: string;
174
186
  }): Promise<PaginatedSessionsResult>;
175
187
  listSessionsWithSkillData(): Promise<SkillDevSession[]>;
@@ -250,10 +262,7 @@ export declare class SessionsResource {
250
262
  }>;
251
263
  listBackgroundTasks(sessionId: string, init?: RequestInit): Promise<BackgroundTask[]>;
252
264
  getBackgroundTask(sessionId: string, taskId: string, tail?: number, init?: RequestInit): Promise<BackgroundTask>;
253
- stopBackgroundTask(sessionId: string, taskId: string): Promise<{
254
- message: string;
255
- task?: BackgroundTask | null;
256
- }>;
265
+ stopBackgroundTask(sessionId: string, taskId: string): Promise<BackgroundTaskStopResult>;
257
266
  probeSessionUrl(sessionId: string, url: string): Promise<{
258
267
  reachable: boolean;
259
268
  requires_proxy: boolean;
@@ -285,7 +294,7 @@ export declare class SessionsResource {
285
294
  getDownloadDirUrl(sessionId: string, dirPath: string): string;
286
295
  exportSession(sessionId: string): Promise<void>;
287
296
  previewImport(file: File): Promise<ImportPreview>;
288
- importSession(file: File, name?: string, solutionId?: string | null): Promise<{
297
+ importSession(file: File, name?: string, solutionOverride?: string | null | ImportSessionOptions): Promise<{
289
298
  session_id: string;
290
299
  }>;
291
300
  }
@@ -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
  }
@@ -4,6 +4,14 @@ export type SessionStatus = typeof SessionStatus.infer;
4
4
  export type TemplateId = "default" | "skill_editor" | "ship_attack";
5
5
  export type SkillEditorTemplateId = "skill_editor";
6
6
  export type ModeId = "planning" | "executing";
7
+ export type PublishedSolutionRef = {
8
+ source: "builtin";
9
+ name: string;
10
+ } | {
11
+ source: "hub";
12
+ org: string;
13
+ name: string;
14
+ };
7
15
  export interface ReplayState {
8
16
  source_session_id?: string;
9
17
  status?: "replay" | "autonomous";
@@ -43,6 +51,7 @@ export declare const SessionInfo: import("arktype/internal/variants/object.ts").
43
51
  model?: string | null | undefined;
44
52
  enable_thinking?: boolean | null | undefined;
45
53
  solution_id?: string | null | undefined;
54
+ solution_ref?: unknown;
46
55
  biz_role_id?: string | null | undefined;
47
56
  solution?: unknown;
48
57
  plan_summary?: string | null | undefined;
@@ -69,6 +78,7 @@ export type SessionInfo = Omit<typeof SessionInfo.infer, "template_id" | "soluti
69
78
  model?: string | null;
70
79
  enable_thinking?: boolean | null;
71
80
  solution_id?: string | null;
81
+ solution_ref?: PublishedSolutionRef | null;
72
82
  biz_role_id?: string | null;
73
83
  solution?: Solution | null;
74
84
  primary_skill_id?: string | null;
@@ -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.2",
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
- 共 114 个公开声明。
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)
@@ -349,6 +357,8 @@ primary_skill_id: string | null | undefined
349
357
  runtime_type: "sandbox" | "daemon" | null | undefined
350
358
  session_solution_asset_id: string | null | undefined
351
359
  solution_id: string | undefined
360
+ solution_ref: PublishedSolutionRef | undefined
361
+ solution_snapshot_session_id: string | undefined
352
362
  template_id: TemplateId | undefined
353
363
  ```
354
364
 
@@ -454,6 +464,13 @@ image_url: { url: string; }
454
464
  type: "image_url"
455
465
  ```
456
466
 
467
+ ## `ImportSessionOptions` (interface)
468
+
469
+ ```ts
470
+ solution_ref: PublishedSolutionRef | undefined
471
+ solution_snapshot_session_id: string | undefined
472
+ ```
473
+
457
474
  ## `InboundAction` (type)
458
475
 
459
476
  ```ts
@@ -657,6 +674,14 @@ password_enabled: boolean
657
674
  providers: { name: string; authorize_url: string; }[]
658
675
  ```
659
676
 
677
+ ## `PublishedSolutionRef` (type)
678
+
679
+ ```ts
680
+ export type PublishedSolutionRef =
681
+ | { source: "builtin"; name: string }
682
+ | { source: "hub"; org: string; name: string }
683
+ ```
684
+
660
685
  ## `RawEvent` (interface)
661
686
 
662
687
  ```ts
@@ -775,6 +800,7 @@ runtime_type: string | null | undefined
775
800
  shared: boolean | undefined
776
801
  solution: Solution | null | undefined
777
802
  solution_id: string | null | undefined
803
+ solution_ref: PublishedSolutionRef | null | undefined
778
804
  status: "completed" | "failed" | "interrupted" | "running" | "created" | "waiting_for_input"
779
805
  template_id: TemplateId | null | undefined
780
806
  updated_at: string
@@ -823,6 +849,7 @@ SessionInfo = type({
823
849
  "model?": "string | null",
824
850
  "enable_thinking?": "boolean | null",
825
851
  "solution_id?": "string | null",
852
+ "solution_ref?": "unknown",
826
853
  "biz_role_id?": "string | null",
827
854
  "solution?": "unknown",
828
855
  "plan_summary?": "string | null",
@@ -905,11 +932,11 @@ getSessionHistory: (sessionId: string, init?: RequestInit) => Promise<SessionHis
905
932
  getSessionTasks: (sessionId: string) => Promise<Task[]>
906
933
  getSessionTurns: (sessionId: string) => Promise<TurnProjection[]>
907
934
  getSharedSession: (token: string) => Promise<TurnProjection[]>
908
- importSession: (file: File, name?: string, solutionId?: string | null) => Promise<{ session_id: string; }>
935
+ importSession: (file: File, name?: string, solutionOverride?: string | null | ImportSessionOptions) => Promise<{ session_id: string; }>
909
936
  listBackgroundTasks: (sessionId: string, init?: RequestInit) => Promise<BackgroundTask[]>
910
937
  listDir: (sessionId: string, dirPath: string) => Promise<FileEntry[]>
911
938
  listSessions: (template_id_prefix?: string, solution_id?: string) => Promise<SessionInfo[]>
912
- listSessionsPaginated: (params: { limit: number; offset: number; template_id_prefix?: string; solution_id?: string; q?: string; }) => Promise<PaginatedSessionsResult>
939
+ listSessionsPaginated: (params: { limit: number; offset: number; template_id_prefix?: string; solution_id?: string; solution_registry_id?: string; q?: string; }) => Promise<PaginatedSessionsResult>
913
940
  listSessionsWithSkillData: () => Promise<SkillDevSession[]>
914
941
  pinSession: (sessionId: string, pinned: boolean) => Promise<SessionInfo>
915
942
  previewImport: (file: File) => Promise<ImportPreview>
@@ -920,7 +947,7 @@ rewindSession: (sessionId: string, checkpointId: string) => Promise<{ id: string
920
947
  setSessionEnv: (sessionId: string, env: Record<string, string>) => Promise<SessionDetail>
921
948
  shareFile: (sessionId: string, sourcePath: string, linkName?: string, shareFolder?: string) => Promise<{ path: string; target: string; }>
922
949
  startReplaySession: (sourceSessionId: string, speed?: 1 | 2 | 5) => Promise<{ session_id: string; }>
923
- stopBackgroundTask: (sessionId: string, taskId: string) => Promise<{ message: string; task?: BackgroundTask | null; }>
950
+ stopBackgroundTask: (sessionId: string, taskId: string) => Promise<BackgroundTaskStopResult>
924
951
  switchBranch: (sessionId: string, checkpointId: string) => Promise<{ id: string; leaf_id: string; }>
925
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>
926
953
  tokenizePrompt: (prompt: string, model?: string) => Promise<TokenizeResult>