@blade-hq/agent-react 2610.0.0-beta.26 → 2610.0.0-beta.28

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
@@ -32,7 +32,6 @@ export function App() {
32
32
 
33
33
  - 不传 `sessionId` 自动创建新会话;未登录时 `ChatView` 自己渲染登录按钮(弹窗授权,见 agent-client 的 `client.auth.login()`)。
34
34
  - 同一 `BladeProvider` 下可以放多个 `ChatView`,各自独立会话、互不干扰。
35
- - 宿主只需要完成态消息时,可在 `BladeClient` 构造参数中传 `streamTokens: false`,不订阅逐 token 增量。
36
35
 
37
36
  ## BladeProvider
38
37
 
@@ -137,6 +136,9 @@ await replay.exitToAutonomous() // 退出回放,之后真的运
137
136
 
138
137
  完整聊天界面:消息列表(Markdown、代码高亮、工具调用、提问卡片)+ 输入框 + 连接状态条 + 登录引导。
139
138
 
139
+ `ChatView` 固定使用普通展示模式。产品内置 Web 的精简/开发者模式不属于 SDK 公共能力,
140
+ 因此没有 `renderMode` 等切换属性。
141
+
140
142
  ```tsx
141
143
  <ChatView
142
144
  sessionId={id} // 可选;不传自动建会话
@@ -154,7 +156,7 @@ await replay.exitToAutonomous() // 退出回放,之后真的运
154
156
 
155
157
  全部 props 见 `ChatViewProps`。样式说明:
156
158
 
157
- `ChatView` 会把项目说明、可用能力和当前工作环境显示为默认折叠的业务卡片。自建消息列表可直接使用 `ContextCard`,属性见 `ContextCardProps`;状态到文案的映射来自 agent-client 的 `getContextDisplayState`,不需要接入方重复判断。底层数据类型为 `ContextProjectionData` / `ContextProjectionFields`,展示结果为 `ContextDisplayState`,并保留 `ContextAction`、`ContextSourceInfo` 和 `contextProjectionData` 给 headless 消费方。
159
+ `ChatView` 的普通展示模式不显示只供诊断的项目说明、可用能力和当前工作环境。需要自建诊断界面时,可直接使用独立的 `ContextCard`,属性见 `ContextCardProps`;状态到文案的映射来自 agent-client 的 `getContextDisplayState`,不需要接入方重复判断。底层数据类型为 `ContextProjectionData` / `ContextProjectionFields`,展示结果为 `ContextDisplayState`,并保留 `ContextAction`、`ContextSourceInfo` 和 `contextProjectionData` 给 headless 消费方。
158
160
 
159
161
  `onFollowupInteraction` 使用 `FollowupInteractionEvent`,覆盖下一步建议展示/采纳、成果展示/打开/下载以及结果评分。SDK 不内置 PostHog 等分析厂商;宿主回调抛错也不会中断用户点击或下载。
160
162
  文件成果以文件名为文本的标准下载链接展示;Vue / 纯 HTML 使用的 `<blade-chat>` 与 `ChatView` 行为一致。
@@ -268,6 +270,27 @@ models.filter((m) => m.serviceModelId)
268
270
  <MarkdownContent sessionId={sessionId}>{markdownText}</MarkdownContent>
269
271
  ```
270
272
 
273
+ ## isAgentComputerCommand / isAgentComputerToolCall / classifyAgentComputerLaunchOutcome
274
+
275
+ 判断智能体是否在沙盒里启动了通用 GUI 应用镜像(`computer launch`)——后端 blade-agent 通过 `computer` CLI 驱动一块虚拟屏幕运行任意 GUI 软件,这些函数用于自行接入方判断要不要展示对应的实时画面入口(比如自建一个类似「电脑镜像」的标签页)。当前 SDK 侧还没有内置这块 UI,只导出判定规则,避免各接入方重新猜一遍匹配逻辑。
276
+
277
+ `isAgentComputerCommand`/`isAgentComputerToolCall` 只回答"这条命令是不是一次 launch 尝试",不回答"这次 launch 最终成不成功"——待处理、已失败的 launch 也会命中。要判断真实结果(比如决定要不要展示画面入口),用 `classifyAgentComputerLaunchOutcome`:它会解析工具调用的 `status`/`result`,返回 `"pending" | "succeeded" | "failed" | "unknown"`。`"unknown"` 表示 `status` 已经是终态但 `result` 字段本身缺失(常见于会话整理/compaction 之后的历史投影,归档时不会重新序列化完整 result),跟"result 回来了、里面确实没有成功标记"的 `"failed"` 是两种不同性质的证据——接入方要按自己的场景决定怎么处理(展示类场景可以偏宽松,当作足够展示;自动跳转/替用户做决定的场景应该偏保守,当作跟 `"failed"` 一样处理)。
278
+
279
+ ```ts
280
+ import {
281
+ isAgentComputerCommand,
282
+ isAgentComputerToolCall,
283
+ classifyAgentComputerLaunchOutcome,
284
+ } from "@blade-hq/agent-react"
285
+
286
+ isAgentComputerCommand("computer launch --exec /opt/apps/foo/bar") // true
287
+ isAgentComputerCommand("computer status") // false(只认 launch,不认查询类子命令)
288
+
289
+ isAgentComputerToolCall(toolCall.arguments) // 工具调用的 JSON 参数版本
290
+
291
+ classifyAgentComputerLaunchOutcome(toolCall) // "pending" | "succeeded" | "failed" | "unknown"
292
+ ```
293
+
271
294
  ## 选择模型
272
295
 
273
296
  SDK 的 ChatView / `<blade-chat>` 不内置模型选择器(默认用后端配置的模型)。指定模型有两种方式:
@@ -28,4 +28,13 @@ interface Props {
28
28
  export declare function AskUserQuestionBlock({ data, answered, toolCallId, sessionStatus, answerData, onAnswer, }: Props): import("react/jsx-runtime").JSX.Element;
29
29
  /** 解析 AskUserQuestion 的工具结果/参数,容错 LLM 把 questions 输出为字符串的情况。 */
30
30
  export declare function parseAskUserQuestion(toolResult: string | null | undefined): AskUserQuestionData | null;
31
+ export interface AskUserQuestionError {
32
+ message: string;
33
+ detail: string | null;
34
+ }
35
+ /**
36
+ * Keep this parser synchronized with apps/web/AskUserQuestionBlock.tsx.
37
+ * The built-in Web cannot import agent-react, and this is not a public SDK protocol API.
38
+ */
39
+ export declare function parseAskUserQuestionError(toolResult: string | null | undefined): AskUserQuestionError | null;
31
40
  export {};
@@ -8,6 +8,7 @@ interface Props {
8
8
  answered?: boolean;
9
9
  answerData?: AskUserAnswerData;
10
10
  sessionStatus?: string;
11
+ isActiveQuestion?: boolean;
11
12
  renderer?: ToolCallRenderer;
12
13
  }
13
14
  /**
@@ -19,10 +20,11 @@ interface Props {
19
20
  * 会同时把已经回答过的旧提问重新变成可作答(历史加载不会带回 answerData),
20
21
  * 而且会盖住投影层的错误——这个 bug 就是这么藏住的。
21
22
  */
22
- export declare function resolveAskQuestionState({ toolStatus, hasAnswerData, fallbackAnswered, }: {
23
+ export declare function resolveAskQuestionState({ toolStatus, hasAnswerData, fallbackAnswered, fallbackAwaiting, }: {
23
24
  toolStatus: ToolCallInfo["status"];
24
25
  hasAnswerData: boolean;
25
26
  fallbackAnswered?: boolean;
27
+ fallbackAwaiting?: boolean;
26
28
  }): {
27
29
  awaitingAnswer: boolean;
28
30
  answered: boolean;
@@ -31,5 +33,5 @@ export declare function resolveAskQuestionState({ toolStatus, hasAnswerData, fal
31
33
  * 极简工具调用块:状态 + 展示名一行,点开后是参数/结果的 <pre> 折叠展示。
32
34
  * AskUserQuestion 特殊处理为提问选项卡片。
33
35
  */
34
- export declare function ToolCallBlock({ toolCall, onAnswer, answered, answerData, sessionStatus, renderer, }: Props): import("react/jsx-runtime").JSX.Element;
36
+ export declare function ToolCallBlock({ toolCall, onAnswer, answered, answerData, sessionStatus, isActiveQuestion, renderer, }: Props): import("react/jsx-runtime").JSX.Element;
35
37
  export {};
@@ -76,6 +76,7 @@ declare const BladeAgent: {
76
76
  disable_tools?: string[] | undefined;
77
77
  runtime_type?: string | null | undefined;
78
78
  daemon_id?: string | null | undefined;
79
+ agent_runtime_id?: string | null | undefined;
79
80
  workspace_path?: string | null | undefined;
80
81
  match?: unknown;
81
82
  }, {}>;
package/dist/index.d.ts CHANGED
@@ -24,4 +24,6 @@ export type { ReplayMismatchPromptProps } from "./components/ReplayMismatchPromp
24
24
  export type { ToolCallRenderer } from "./components/ToolCallBlock";
25
25
  export { ContextCard } from "./components/ContextCard";
26
26
  export type { ContextCardProps } from "./components/ContextCard";
27
+ export { isAgentComputerCommand, isAgentComputerToolCall, classifyAgentComputerLaunchOutcome, } from "./lib/agent-computer-command";
28
+ export type { AgentComputerLaunchOutcome } from "./lib/agent-computer-command";
27
29
  export * from "@blade-hq/agent-client";