@blade-hq/agent-react 2610.0.0-beta.1 → 2610.0.1-alpha.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.
package/README.md CHANGED
@@ -28,7 +28,6 @@ export function App() {
28
28
 
29
29
  - 不传 `sessionId` 自动创建新会话;未登录时 `ChatView` 自己渲染登录按钮(弹窗授权,见 agent-client 的 `client.auth.login()`)。
30
30
  - 同一 `BladeProvider` 下可以放多个 `ChatView`,各自独立会话、互不干扰。
31
- - 宿主只需要完成态消息时,可在 `BladeClient` 构造参数中传 `streamTokens: false`,不订阅逐 token 增量。
32
31
 
33
32
  ## BladeProvider
34
33
 
@@ -140,7 +139,6 @@ await replay.exitToAutonomous() // 退出回放,之后真的运
140
139
  onSessionCreated={(id) => ...} // 自动创建的会话 id 交还调用方
141
140
  onSessionReady={(session) => ...} // 会话实例就绪(页面协作高级用法)
142
141
  commands={{ "map.highlight": (data) => map.highlight(data) }} // 智能体 → 页面指令
143
- onFollowupInteraction={(event) => analytics.capture(event.type, event)} // 厂商无关交互回调
144
142
  placeholder="输入消息..."
145
143
  classNames={{ root: "...", banner: "...", messages: "...", input: "..." }} // ChatViewClassNames
146
144
  renderers={{ toolCall: (info) => <MyToolCard info={info} /> }} // ChatViewRenderers
@@ -150,8 +148,6 @@ await replay.exitToAutonomous() // 退出回放,之后真的运
150
148
 
151
149
  全部 props 见 `ChatViewProps`。样式说明:
152
150
 
153
- `onFollowupInteraction` 使用 `FollowupInteractionEvent`,覆盖下一步建议展示/采纳、成果展示/打开/下载以及结果评分。SDK 不内置 PostHog 等分析厂商;宿主回调抛错也不会中断用户点击或下载。
154
-
155
151
  - 必须引入一份样式,按宿主有没有 Tailwind 二选一:
156
152
  - **`style.full.css`**(默认选它):布局兜底 + 编译好的 Tailwind 产物,自包含,宿主没装 Tailwind 也是完整视觉。
157
153
  - **`style.css`**:只有 `.blade-chat-*` 布局兜底。宿主自己装了 Tailwind、且 `content` 配了扫描 `node_modules/@blade-hq/agent-react` 时用它,可以少一份重复 CSS。选错不会报错,只是工具块、思考块内部会退化成没有布局的裸 HTML。
@@ -257,6 +253,8 @@ models.filter((m) => m.serviceModelId)
257
253
  <MarkdownContent content={markdownText} />
258
254
  ```
259
255
 
256
+ 传了 `sessionId` 才会把智能体产出文件的 `MEDIA:` 行折叠成下载卡片(下载要用它)。`ChatView` 内部已经传好,只有单独用 `MarkdownContent` 时需要自己给:
257
+
260
258
  ```tsx
261
259
  <MarkdownContent sessionId={sessionId}>{markdownText}</MarkdownContent>
262
260
  ```
@@ -304,4 +302,4 @@ blade-chat { --primary: 262 83% 58%; height: 640px; }
304
302
 
305
303
  为方便单包引入,本包 re-export 了 agent-client 的全部公开声明(`BladeClient`、`AgentSession`、`SessionState`、协议类型等),文档一律见 [agent-client 的 README](../agent-client/README.md)。完整签名见 [public-api.md](./public-api.md)。
306
304
 
307
- 本包自有声明:`BladeProvider`、`BladeProviderProps`、`useBladeClient`、`useAgentSession`、`UseAgentSessionOptions`、`UseAgentSessionResult`、`useReplay`、`UseReplayResult`、`ReplayMismatch`、`ReplayBar`、`ReplayBarProps`、`ReplayMismatchPrompt`、`ReplayMismatchPromptProps`、`ChatView`、`ChatViewProps`、`ChatViewClassNames`、`ChatViewRenderers`、`ChatViewSlots`、`FollowupInteractionEvent`、`ToolCallRenderer`、`MarkdownContent`、`MarkdownContentProps`。
305
+ 本包自有声明:`BladeProvider`、`BladeProviderProps`、`useBladeClient`、`useAgentSession`、`UseAgentSessionOptions`、`UseAgentSessionResult`、`useReplay`、`UseReplayResult`、`ReplayMismatch`、`ReplayBar`、`ReplayBarProps`、`ReplayMismatchPrompt`、`ReplayMismatchPromptProps`、`ChatView`、`ChatViewProps`、`ChatViewClassNames`、`ChatViewRenderers`、`ChatViewSlots`、`ToolCallRenderer`、`MarkdownContent`、`MarkdownContentProps`。
@@ -1,9 +1,6 @@
1
1
  import type { AgentSession, CreateSessionRequest } from "@blade-hq/agent-client";
2
2
  import { type ChatPresentationProps } from "./ChatSurface";
3
- import type { FollowupInteractionEvent } from "./PostChatFollowupBlock";
4
3
  export interface AgentChatProps extends ChatPresentationProps {
5
- /** follow-up、成果和评分交互;SDK 不绑定任何分析厂商。 */
6
- onFollowupInteraction?: (event: FollowupInteractionEvent) => void;
7
4
  /** 连接既有会话;不传则按 createOptions 自动新建。 */
8
5
  sessionId?: string;
9
6
  createOptions?: CreateSessionRequest;
@@ -7,7 +7,7 @@ interface Props {
7
7
  onAnswer?: (answer: string, toolCallId: string, answerData: AskUserAnswerData) => void;
8
8
  sessionStatus?: string;
9
9
  toolCallRenderer?: ToolCallRenderer;
10
- /** 会话 id;传给 Markdown 渲染的统一上下文。 */
10
+ /** 传给 Markdown 渲染,用于把 MEDIA 行折叠成文件下载卡片。 */
11
11
  sessionId?: string;
12
12
  }
13
13
  /**
@@ -1,8 +1,6 @@
1
- import type { AskUserAnswerData, ChatMessage, ConnectionStatus, PostChatFollowup } from "@blade-hq/agent-client";
1
+ import type { AskUserAnswerData, ChatMessage, ConnectionStatus } from "@blade-hq/agent-client";
2
2
  import type { ReactNode } from "react";
3
3
  import type { ToolCallRenderer } from "./ToolCallBlock";
4
- import type { FollowupInteractionEvent } from "./PostChatFollowupBlock";
5
- import type { ResultFeedback } from "@blade-hq/agent-client";
6
4
  export interface ChatViewClassNames {
7
5
  root?: string;
8
6
  banner?: string;
@@ -33,26 +31,19 @@ export interface ChatPresentationProps {
33
31
  /** 主题落到聊天根节点上:深色变量挂在 [data-theme="dark"] 上,由它继承给整棵子树。 */
34
32
  export declare function themeAttr(theme: ChatPresentationProps["theme"]): "dark" | undefined;
35
33
  interface ChatSurfaceProps extends ChatPresentationProps {
36
- /** follow-up、成果和评分交互;SDK 不绑定任何分析厂商。 */
37
- onFollowupInteraction?: (event: FollowupInteractionEvent) => void;
38
34
  connection: ConnectionStatus;
39
35
  errorMessage: string | null;
40
36
  messages: ChatMessage[];
41
- postChatFollowup?: PostChatFollowup | null;
42
37
  isStreaming: boolean;
43
38
  isStopping: boolean;
44
39
  inputText: string;
45
40
  onInputChange: (value: string) => void;
46
- onSuggestion?: (value: string) => void;
47
41
  onSend: (text: string) => Promise<boolean>;
48
42
  onStop: () => void;
49
43
  sessionStatus?: string;
50
44
  askAnswers?: Record<string, AskUserAnswerData>;
51
45
  onAnswer?: (answer: string, toolCallId: string, answerData: AskUserAnswerData) => void;
52
46
  sessionId?: string;
53
- isViewer?: boolean;
54
- resultFeedbackByEntry?: ReadonlyMap<string, ResultFeedback>;
55
- onResultFeedbackSaved?: (feedback: ResultFeedback) => void;
56
47
  /** 输入框上方的内部区域(纯 LLM 模式的高级设置用)。不传时不渲染任何节点。 */
57
48
  beforeInput?: ReactNode;
58
49
  /** 连接状态条下方的横幅(回放模式条用)。不传时不渲染任何节点。 */
@@ -64,5 +55,5 @@ interface ChatSurfaceProps extends ChatPresentationProps {
64
55
  * 这里的 DOM 结构受 tests/chat-view-compat.test.tsx 的快照保护——接入方拿
65
56
  * .blade-chat-* 类名写了自己的样式,结构一动他们的页面就歪。
66
57
  */
67
- export declare function ChatSurface({ theme, classNames, renderers, slots, placeholder, connection, errorMessage, messages, postChatFollowup, isStreaming, isStopping, inputText, onInputChange, onSuggestion, onSend, onStop, sessionStatus, askAnswers, onAnswer, sessionId, isViewer, resultFeedbackByEntry, onResultFeedbackSaved, onFollowupInteraction, beforeInput, banner, }: ChatSurfaceProps): import("react/jsx-runtime").JSX.Element;
58
+ export declare function ChatSurface({ theme, classNames, renderers, slots, placeholder, connection, errorMessage, messages, isStreaming, isStopping, inputText, onInputChange, onSend, onStop, sessionStatus, askAnswers, onAnswer, sessionId, beforeInput, banner, }: ChatSurfaceProps): import("react/jsx-runtime").JSX.Element;
68
59
  export {};
@@ -3,7 +3,6 @@ import { type LlmChatHandle } from "./LlmChat";
3
3
  import type { LlmAdvancedSettings, LlmOverride } from "./LlmAdvancedSettings";
4
4
  import type { LlmChatOptions } from "../hooks/use-llm-chat";
5
5
  export type { ChatViewClassNames, ChatViewRenderers, ChatViewSlots, } from "./ChatSurface";
6
- export type { FollowupInteractionEvent } from "./PostChatFollowupBlock";
7
6
  export interface ChatViewProps extends AgentChatProps {
8
7
  /** 挂哪个下层组件。默认 `agent`——不传就是接 Blade 智能体会话的原有行为。 */
9
8
  mode?: "agent" | "llm";
@@ -0,0 +1,16 @@
1
+ import { type ComponentPropsWithRef } from "react";
2
+ import type { ExtraProps } from "streamdown";
3
+ export type FileCardProps = ComponentPropsWithRef<"span"> & ExtraProps & {
4
+ "data-path"?: string;
5
+ "data-name"?: string;
6
+ dataPath?: string;
7
+ dataName?: string;
8
+ sessionId?: string;
9
+ };
10
+ /**
11
+ * 智能体产出文件的下载卡片(由 MEDIA 行折叠而来)。
12
+ *
13
+ * 整张卡片只有一个动作:下载。第一方界面点卡片是「在右侧预览」,那依赖 app 的 artifact
14
+ * 面板,SDK 里没有这块,所以不摆预览入口也不写预览文案——UI 不能承诺不存在的能力。
15
+ */
16
+ export declare function FileCard({ node, "data-path": pathAttribute, "data-name": nameAttribute, dataPath, dataName, sessionId, children, className, ...props }: FileCardProps): import("react/jsx-runtime").JSX.Element;
@@ -3,11 +3,14 @@ export interface MarkdownContentProps {
3
3
  className?: string;
4
4
  /** 流式渲染传 "streaming",历史静态内容默认 "static"。 */
5
5
  mode?: "streaming" | "static";
6
- /** 会话 id;保留给聊天组件统一透传上下文。 */
6
+ /**
7
+ * 会话 id。传了才会把 `MEDIA:` 行折叠成文件下载卡片——下载要用它。
8
+ * 不要给用户消息传:用户自己在输入框打一行 `MEDIA:` 不该被当成平台产物。
9
+ */
7
10
  sessionId?: string;
8
11
  }
9
12
  /**
10
- * SDK 版 Markdown 渲染:附带代码块复制按钮;相比第一方版本去掉了
11
- * mermaid、外链确认弹窗与文件预览。
13
+ * SDK 版 Markdown 渲染:附带代码块复制按钮、智能体产出文件的下载卡片;
14
+ * 相比第一方版本去掉了 mermaid、外链确认弹窗与文件预览。
12
15
  */
13
16
  export declare function MarkdownContent({ children, className, mode, sessionId }: MarkdownContentProps): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,8 @@
1
- import type { AskUserAnswerData, ChatMessage, PostChatFollowup, ResultFeedback } from "@blade-hq/agent-client";
1
+ import type { AskUserAnswerData, ChatMessage } from "@blade-hq/agent-client";
2
2
  import { type ReactNode } from "react";
3
- import { type FollowupInteractionEvent } from "./PostChatFollowupBlock";
4
3
  import type { ToolCallRenderer } from "./ToolCallBlock";
5
4
  interface Props {
6
5
  messages: ChatMessage[];
7
- postChatFollowup?: PostChatFollowup | null;
8
- onSuggestion?: (value: string) => void;
9
6
  isStreaming: boolean;
10
7
  sessionStatus?: string;
11
8
  askAnswers?: Record<string, AskUserAnswerData>;
@@ -13,16 +10,12 @@ interface Props {
13
10
  toolCallRenderer?: ToolCallRenderer;
14
11
  emptyState?: ReactNode;
15
12
  className?: string;
16
- /** 会话 id;传给助手消息的统一上下文。 */
13
+ /** 传给助手消息的 Markdown 渲染,用于把 MEDIA 行折叠成文件下载卡片。 */
17
14
  sessionId?: string;
18
- isViewer?: boolean;
19
- onFollowupInteraction?: (event: FollowupInteractionEvent) => void;
20
- resultFeedbackByEntry?: ReadonlyMap<string, ResultFeedback>;
21
- onResultFeedbackSaved?: (feedback: ResultFeedback) => void;
22
15
  }
23
16
  /**
24
17
  * 消息列表:use-stick-to-bottom 自动滚动 + 按轮次分组渲染。
25
18
  * 相比第一方版本去掉了轮次导航栏、吸顶状态条与规划摘要卡片。
26
19
  */
27
- export declare function MessageList({ messages, postChatFollowup, onSuggestion, isStreaming, sessionStatus, askAnswers, onAnswer, toolCallRenderer, emptyState, className, sessionId, isViewer, onFollowupInteraction, resultFeedbackByEntry, onResultFeedbackSaved, }: Props): import("react/jsx-runtime").JSX.Element;
20
+ export declare function MessageList({ messages, isStreaming, sessionStatus, askAnswers, onAnswer, toolCallRenderer, emptyState, className, sessionId, }: Props): import("react/jsx-runtime").JSX.Element;
28
21
  export {};
@@ -39,7 +39,6 @@ declare const BladeAgent: {
39
39
  isHiddenInternalMessage: typeof agentClient.isHiddenInternalMessage;
40
40
  normalizeMessageContent: typeof agentClient.normalizeMessageContent;
41
41
  transformSlashCommand: typeof agentClient.transformSlashCommand;
42
- latestPostChatFollowup: typeof agentClient.latestPostChatFollowup;
43
42
  DEFAULT_REPLAY_SPEED: agentClient.ReplaySpeed;
44
43
  SessionInfo: import("arktype/internal/variants/object.ts").ObjectType<{
45
44
  id: string;
@@ -85,7 +84,6 @@ declare const BladeAgent: {
85
84
  number: string;
86
85
  }, {}>;
87
86
  TaskStatus: import("arktype/internal/variants/string.ts").StringType<"done" | "failed" | "in_progress" | "pending" | "skipped", {}>;
88
- acceptedPostChatFollowupCompletesLatestRun: typeof agentClient.acceptedPostChatFollowupCompletesLatestRun;
89
87
  ClientProjectionBuilder: typeof agentClient.ClientProjectionBuilder;
90
88
  createSocket: typeof agentClient.createSocket;
91
89
  getChat: typeof getChat;
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export type { ReplayMismatch, UseReplayResult } from "./hooks/use-replay";
7
7
  export { useLlmChat } from "./hooks/use-llm-chat";
8
8
  export type { ChatCompletionTool, LlmChatOptions, LlmToolCall, UseLlmChatResult, } from "./hooks/use-llm-chat";
9
9
  export { ChatView } from "./components/ChatView";
10
- export type { ChatViewClassNames, ChatViewProps, ChatViewRenderers, ChatViewSlots, FollowupInteractionEvent, } from "./components/ChatView";
10
+ export type { ChatViewClassNames, ChatViewProps, ChatViewRenderers, ChatViewSlots, } from "./components/ChatView";
11
11
  export { AgentChat } from "./components/AgentChat";
12
12
  export type { AgentChatProps } from "./components/AgentChat";
13
13
  export { LlmChat } from "./components/LlmChat";