@blade-hq/agent-client 2612.0.0-beta.98 → 2612.0.0-beta.99

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.
package/README.md CHANGED
@@ -360,29 +360,35 @@ const saved = await client.sessions.callFileOpener(sessionId, {
360
360
  **它不是把现有会话切成回放模式,而是派生一个新会话**,源会话原样不动:
361
361
 
362
362
  ```ts
363
- // 1. 能不能拿它当素材(有并行子智能体、运行快照不完整的不行)
363
+ // 1. 检查这个会话能否作为回放素材
364
364
  const { supported, reason } = await client.sessions.getReplayPreview(sourceId)
365
365
  if (!supported) return show(reason) // reason 可直接展示给用户
366
366
 
367
367
  // 2. 派生回放会话——这一步才是"进入回放",返回的是一个全新的 session_id
368
- const { session_id: replayId } = await client.sessions.startReplaySession(sourceId)
369
- const fast = await client.sessions.startReplaySession(sourceId, 2) // 或显式 1 | 2 | 5
368
+ const { session_id: replayId } = await client.sessions.startReplaySession(sourceId, 2, {
369
+ mode: "sandbox_files_only",
370
+ preset: "technical",
371
+ })
370
372
 
371
373
  // 3. 连上它,一出生就带着 replay 状态
372
374
  const session = await client.sessions.connect(replayId)
373
375
  session.getState().replay
374
- // → { isReplay: true, speed: 5, sourceSessionId: sourceId }
376
+ // 回放状态包含倍速、来源、模式和演示设置
375
377
  ```
376
378
 
377
379
  不传倍速时用 `DEFAULT_REPLAY_SPEED`;所有创建入口都该用它,免得同一个源对话
378
380
  从不同入口开出来速度不一样。倍速类型是 `ReplaySpeed`,会话详情里的 `replay_state` 是 `ReplayState`。
379
381
 
382
+ `ReplayMode` 决定实际执行什么:`sandbox_files_only` 只还原沙盒文件,`live_tools` 在目标环境真实运行工具。
383
+ `ReplayPreset` 只填默认设置;`ReplaySettings` 可以覆盖失败卡片、未命中处理、台词提示和「下一步」按钮。
384
+ `ReplayToolAction` 用于处理现场工具暂停。读取回放状态中的 `tool_failure.id`,调用 `session.resolveReplayToolFailure({ id, choice: "skip" })` 可用录制结果播完这一轮。
385
+
380
386
  **连上之后不会自动播——它跟用户对台词**(下面的 `session` 都是第 3 步连上的**回放会话**):
381
387
 
382
388
  ```ts
383
389
  // 源会话当初第一句问的是"帮我查下当前目录"
384
390
  await session.send("帮我查下当前目录") // 对得上:按倍速重现当时的回复和工具调用
385
- await session.send("今天天气怎么样") // 对不上:抛 replayMismatch 等你决定(见下)
391
+ await session.send("今天天气怎么样") // 未命中:按 on_mismatch 的设置处理
386
392
  ```
387
393
 
388
394
  **回放中的状态和动作**都挂在会话上,和 `send()` 同级:
@@ -391,6 +397,7 @@ await session.send("今天天气怎么样") // 对不上:抛 replayMismatc
391
397
  session.getState().replay // { isReplay, speed, sourceSessionId } | null(不是回放会话)
392
398
  session.getState().viewerRole // "viewer" 表示只读,改不动回放
393
399
  await session.setReplaySpeed(2)
400
+ await session.setReplaySettings({ hide_failed_tools: true })
394
401
  await session.exitReplay() // 退出回放,之后的对话真的运行
395
402
  ```
396
403
 
@@ -407,7 +414,7 @@ session.subscribe(() => (state.value = session.getState()))
407
414
 
408
415
  连接会话时会一并拉好初始回放状态,所以第一帧就知道自己在不在回放。
409
416
 
410
- **输入冲突**:用户说的话和录制内容对不上时,服务端会推 `replayMismatch`,必须在事件里给出决定:
417
+ **输入冲突**:`on_mismatch: "silent"` 在未命中时直接转为真实执行;`"ask"` 在还有录制轮次时发出 `replayMismatch`:
411
418
 
412
419
  ```ts
413
420
  session.on("replayMismatch", ({ expectedMessage, actualMessage, respond }) => {
@@ -539,6 +546,10 @@ await client.phones.revokeKey() // 作废,之后手机重连一律被拒
539
546
 
540
547
  ## AgentSession
541
548
 
549
+ `getState().activePlan` 提供当前分支的计划快照。界面展示草稿后,用户可调用 `session.approvePlan(draft)` 确认该版本。返回 `accepted` 表示请求已进入持久队列,执行开始后会收到 `phase: "executing"` 的计划快照。
550
+
551
+ 计划类型包括 `PlanDocument`、`PlanPhase`、`PlanNode`、`PlanLeafStatus` 和 `PlanAgentRef`。需要自行保存和重试批准请求的宿主,可将 `ApprovePlanInput` 和原始 `requestId` 一起传给 `send()`。
552
+
542
553
  一个会话的实时状态机。**状态归属实例**:同一页面建多个会话互不干扰。
543
554
 
544
555
  ### 状态
@@ -775,7 +786,7 @@ session.send("@org/data-analysis 这是什么?", {
775
786
 
776
787
  ## 运行错误说明:userFacingErrorText
777
788
 
778
- 运行失败时,服务端通过 `system:error` 推送错误说明,同一段说明也会随失败回合写进历史(回合上的 `error_message`)。自己渲染消息时,实时与历史两条路径都应经过 `userFacingErrorText(message)`:沙盒内存超限(退出码 137)的原始报错会换成统一的友好说明,其余原样返回。`AgentSession` 自带的状态已经做了这一转换,只用 `getState()` 时不需要再调用。
789
+ 运行失败时,服务端通过 `system:error` 推送错误说明,同一段说明也会随失败回合写进历史(回合上的 `error_message`)。自己渲染消息时,实时与历史两条路径都应经过 `userFacingErrorText(message)`:平台确认沙盒内存超限的原始报错会换成统一的友好说明,普通进程退出码 137 及其他错误原样返回。`AgentSession` 自带的状态已经做了这一转换,只用 `getState()` 时不需要再调用。
779
790
 
780
791
  ```ts
781
792
  import { userFacingErrorText } from "@blade-hq/agent-client"
@@ -865,7 +876,7 @@ chat.renderers = {
865
876
 
866
877
  - **客户端与登录**:`BladeClient`、`BladeClientOptions`、`UploadProgress`、`BladeApiError`、`LoginOptions`、`LoginResult`、`TokenStorageMode`、`AuthResource`、`ExchangeCodeParams`、`ExchangeCodeResult`、`ProvidersResponse`、`UserInfo`
867
878
  - **SDK 身份**:`SDK_NAME`、`SDK_VERSION`
868
- - **百变包与共享数据**:`ProfileResource`、`PacksResource`、`PackRecordsResource`、`PackProfile`、`ProfileComponent`、`PackManifest`、`PackLayoutOperation`、`InstalledPack`、`PackRecord`、`PackRecordQuery`;隔离页面宿主使用 `attachPackPageBridge`,协议与生命周期见 [Pack pages](docs/pack-pages.md)。
879
+ - **百变包与共享数据**:`ProfileResource`、`PacksResource`、`PackRecordsResource`、`PackProfile`、`ProfileAdjustment`、`PersonalLayoutOperation`、`StyleSummary`、`StyleAppearance`、`ProfileComponent`、`PackManifest`、`PackLayoutOperation`、`InstalledPack`、`PackEvent`、`PackRecord`、`PackRecordQuery`;隔离页面宿主使用 `attachPackPageBridge`,协议与生命周期见 [Pack pages](docs/pack-pages.md)。
869
880
  - **实时会话**:`AgentSession`、`AgentSessionError`、`AgentSessionEvents`、`AgentSessionEventName`、`SessionState`、`WorkflowRunState`、`WorkflowRunEntry`(`SessionState.workflowRuns` 的形态)、`ConnectionStatus`、`InputKind`、`SendOptions`、`AttachAppOptions`、`AskUserAnswerData`、`AgentLoopInfo`、`ActiveCompactionState`、`ReplaySnapshot`
870
881
  - **声明式会话**:`SessionDefinition`、`SolutionDefinition`、`SkillDefinition`、`SkillFile`、`SessionConfig`、`TextFile`、`SessionSetupError`、`SessionSetupStage`
871
882
  - **会话消息队列**:`SessionQueueSnapshot`、`QueuedMessage`、`QueuedMessageStatus`、`QueueMessageOptions`、`QueueOperationResult`
@@ -1130,7 +1141,12 @@ BA 默认提供内置定时任务。应用自行管理定时安排时,可在
1130
1141
 
1131
1142
  ### 百变包与界面清单
1132
1143
 
1133
- `client.profile.get()` 读取服务端合成的账号清单;宿主按 `regions` 选择自己支持的组件,不在浏览器里重新叠加布局。`client.profile.onChanged(refresh)` 返回取消订阅函数,并在重连后通知宿主刷新。`client.packs.list()`、`enable(name)`、`disable(name)` 和 `reset()` 管理当前账号的百变包,`file(name, path)` 使用同一鉴权身份读取已启用包的页面。包页面由宿主使用隔离 iframe 承载。内置 Web 提供页面与设置入口,扩展和嵌入 SDK 暂不显示包页面。
1144
+ `client.profile.get()` 读取服务端合成的账号清单;宿主按 `regions` 选择自己支持的组件,不在浏览器里重新叠加布局。`client.profile.onChanged(refresh)` 返回取消订阅函数,并在重连后通知宿主刷新。`client.packs.list()`、`enable(name)`、`disable(name)` 管理当前账号的百变包,`file(name, path)` 使用同一鉴权身份读取已启用包的页面。包页面由宿主使用隔离 iframe 承载。内置 Web 提供页面与设置入口,扩展和嵌入 SDK 暂不显示包页面。
1145
+
1146
+
1147
+ `client.styles.list()` 列出内置风格(`StyleSummary`),`select(name)` 保存当前账号的选择并返回新清单,`reset()` 回到清爽版、停用 fixture/user 扩展并清空 clean 的个人小改动;保留其它风格的个人小改动与旧 my-layout。`client.packs.reset()` 只清空当前风格的个人小改动,保留当前风格、其它风格的小改动与已安装内容;两种重置都保留对话与业务数据。`client.packs.applyLayout(ops)` 只接受 hide/show 和 profile.adjustments 中的 ID;adjustments 包含标题和 visible 状态,被个人隐藏的项目仍会保留在其中以便恢复,风格本身收起的项目不在可调整范围内。`StyleSummary.has_triggers` 用于更换前说明原风格的自动处理是否会暂停。清单的 `style`、`appearance`(`StyleAppearance`)、`landing` 分别描述当前风格、外观与打开页面。风格变更同样通过 `profile:changed` 通知。 `StyleSummary.unavailable_reason` 非空表示单位导航配置未开放此风格入口,宿主应展示原因并禁用选择。未配置的协同默认隐藏,仅管理员启用或风格显式显示后才进入 Go 输出的有效导航;前端不能用原版组件目录代替有效导航。管理员明确隐藏优先于风格与个人小改动;已选中该风格时保留选择及数据,根路径暂回首页,直接协同页面地址仍沿用原有访问规则。内置风格可用 `move`/`add` 的 `first: true` 将入口置顶(与 `after` 互斥);个人小改动仍只允许 hide/show,不接受排列参数。
1148
+
1149
+ `client.packs.emitEvent(name, {type, payload, dedupe_key})` submits an event for the authenticated account; `event(name, id)` reads its durable status (`PackEvent`). A `delivered` status means consumed by the reliable input queue, not execution completed. `hookKey(name)` returns the public URL and whether a key exists; `hookKey(name, true)` rotates it and returns the new key once. `clearSimulated(name, collection)` only deletes records explicitly marked `simulated: true`, keeping conversations and formal records. See [Pack pages](docs/pack-pages.md) for iframe actions.
1134
1150
 
1135
1151
 
1136
1152
  `ProfileResource` 与 `PacksResource` 分别提供上述清单和包操作;`PackProfile`、`ProfileComponent` 描述最终界面,`PackManifest`、`PackLayoutOperation` 和 `InstalledPack` 描述保存/安装的数据形状。完整字段见同目录生成的 `public-api.md` 与 `src/resources/profile.ts`。
@@ -4,7 +4,7 @@ import { SandboxResource } from "./resources/sandbox";
4
4
  import { ToolProvider, type ToolProviderOptions } from "./tool-provider";
5
5
  import { type LoginOptions, type LoginResult, type TokenStorageMode } from "./auth-login";
6
6
  import { type BladeFetchInit, type HttpMethod } from "./rest";
7
- import { ProfileResource, PacksResource } from "./resources/profile";
7
+ import { ProfileResource, PacksResource, StylesResource } from "./resources/profile";
8
8
  import { AuthResource } from "./resources/auth";
9
9
  import { HeadlessResource } from "./resources/headless";
10
10
  import { ComputersResource } from "./resources/computers";
@@ -55,6 +55,7 @@ export declare class BladeClient {
55
55
  private readonly socketReplacementListeners;
56
56
  private runtimeToken;
57
57
  readonly options: BladeClientOptions;
58
+ readonly styles: StylesResource;
58
59
  readonly profile: ProfileResource;
59
60
  readonly packs: PacksResource;
60
61
  readonly sandbox: SandboxResource;