@blade-hq/agent-react 2608.0.5-beta.0 → 2608.0.5-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,40 +0,0 @@
1
- /** 纯 LLM 模式的高级设置:让用户自己改模型服务地址。 */
2
- export interface LlmAdvancedSettings {
3
- /** 允许改模型服务地址,默认允许。 */
4
- baseURL?: boolean;
5
- /** 允许改模型名,默认允许。 */
6
- model?: boolean;
7
- /**
8
- * 允许在界面上填密钥,默认**不允许**。
9
- * 打开意味着密钥存在浏览器里,只适合受控内网、演示,或密钥本身就属于当前用户的场景。
10
- */
11
- apiKey?: boolean;
12
- /** 覆盖值存哪:`local` 记住用户的选择(默认),`memory` 只在本次会话有效。 */
13
- storage?: "local" | "memory";
14
- /** localStorage 的键,默认按组件拿到的 baseURL 生成。 */
15
- storageKey?: string;
16
- }
17
- export interface LlmOverride {
18
- baseURL?: string;
19
- model?: string;
20
- apiKey?: string;
21
- }
22
- export declare function normalizeAdvanced(value: boolean | LlmAdvancedSettings | undefined): Required<Pick<LlmAdvancedSettings, "baseURL" | "model" | "apiKey" | "storage">> | null;
23
- export declare function readOverride(settings: boolean | LlmAdvancedSettings | undefined, baseURL: string): LlmOverride;
24
- declare function writeOverride(settings: boolean | LlmAdvancedSettings | undefined, baseURL: string, override: LlmOverride): void;
25
- interface Props {
26
- settings: boolean | LlmAdvancedSettings;
27
- /** 组件拿到的默认值,用来做占位提示与"恢复默认" */
28
- defaults: {
29
- baseURL: string;
30
- model: string;
31
- };
32
- override: LlmOverride;
33
- onChange: (next: LlmOverride) => void;
34
- }
35
- /**
36
- * 输入框上方的一行「高级设置」:默认收起,展开后可以改模型服务地址与模型。
37
- * 只有调用方显式打开才渲染——不传 advanced 时这里一个节点都不会出现。
38
- */
39
- export declare function LlmAdvancedSettingsBar({ settings, defaults, override, onChange }: Props): import("react/jsx-runtime").JSX.Element | null;
40
- export { writeOverride };
@@ -1,29 +0,0 @@
1
- import { type LlmChatOptions } from "../hooks/use-llm-chat";
2
- import { type ChatPresentationProps } from "./ChatSurface";
3
- import { type LlmAdvancedSettings, type LlmOverride } from "./LlmAdvancedSettings";
4
- /** 纯 LLM 模式的操作句柄,对应智能体模式的 session.insertText() / send()。 */
5
- export interface LlmChatHandle {
6
- /** 把文本放进输入框交给用户确认,不直接发出去。 */
7
- insertText: (text: string) => void;
8
- send: (text: string) => Promise<boolean>;
9
- /** 清空这段对话。 */
10
- reset: () => void;
11
- }
12
- export interface LlmChatProps extends LlmChatOptions, ChatPresentationProps {
13
- /** 拿到操作句柄:业务界面把选中的数据塞进输入框,或直接发一句。 */
14
- onReady?: (handle: LlmChatHandle) => void;
15
- /**
16
- * 打开输入框上方的「高级设置」,让用户自己改模型服务地址(默认还能改模型名)。
17
- * 不传就一个节点都不渲染。传 `true` 用默认配置,或用对象细调。
18
- */
19
- advanced?: boolean | LlmAdvancedSettings;
20
- /** 用户改了覆盖值时回调,方便宿主自己也记一份。 */
21
- onOverrideChange?: (override: LlmOverride) => void;
22
- }
23
- /**
24
- * 纯 LLM 模式的聊天界面:不建会话、不连实时通道、也不要求登录 Blade,
25
- * 只按 **OpenAI Chat Completions** 标准协议跟模型服务一问一答。
26
- *
27
- * 默认形态是把 `baseURL` 指向自己后端的透传路径,由后端补密钥再转发,浏览器不持有密钥。
28
- */
29
- export declare function LlmChat({ classNames, renderers, slots, placeholder, theme, onReady, advanced, onOverrideChange, ...options }: LlmChatProps): import("react/jsx-runtime").JSX.Element;
@@ -1,59 +0,0 @@
1
- import type { FinalArtifact, PostChatFollowup, ResultFeedback as SavedResultFeedback, ResultFeedbackReason } from "@blade-hq/agent-client";
2
- export type FollowupInteractionEvent = {
3
- type: "suggestions_shown";
4
- sessionId?: string;
5
- assistantEntryId: string;
6
- count: number;
7
- } | {
8
- type: "suggestion_adopted";
9
- sessionId?: string;
10
- assistantEntryId: string;
11
- suggestionIndex: number;
12
- } | {
13
- type: "artifact_shown";
14
- sessionId?: string;
15
- assistantEntryId: string;
16
- artifactIndex: number;
17
- artifactKind: FinalArtifact["kind"];
18
- } | {
19
- type: "artifact_opened";
20
- sessionId?: string;
21
- assistantEntryId: string;
22
- artifactIndex: number;
23
- artifactKind: FinalArtifact["kind"];
24
- } | {
25
- type: "artifact_download_started";
26
- sessionId?: string;
27
- assistantEntryId: string;
28
- artifactIndex: number;
29
- artifactKind: "file";
30
- } | {
31
- type: "artifact_download_succeeded";
32
- sessionId?: string;
33
- assistantEntryId: string;
34
- artifactIndex: number;
35
- artifactKind: "file";
36
- } | {
37
- type: "result_feedback_shown";
38
- sessionId?: string;
39
- assistantEntryId: string;
40
- } | {
41
- type: "result_feedback_submitted";
42
- sessionId?: string;
43
- assistantEntryId: string;
44
- helpful: boolean;
45
- reason: ResultFeedbackReason | null;
46
- updatedAt: string;
47
- };
48
- export declare function HistoricalResultFeedback({ feedback }: {
49
- feedback: SavedResultFeedback;
50
- }): import("react/jsx-runtime").JSX.Element;
51
- export declare function PostChatFollowupBlock({ followup, sessionId, onSuggestion, isViewer, onInteraction, savedFeedback, onFeedbackSaved, }: {
52
- followup: PostChatFollowup;
53
- sessionId?: string;
54
- onSuggestion?: (value: string) => void;
55
- isViewer?: boolean;
56
- onInteraction?: (event: FollowupInteractionEvent) => void;
57
- savedFeedback?: SavedResultFeedback;
58
- onFeedbackSaved?: (feedback: SavedResultFeedback) => void;
59
- }): import("react/jsx-runtime").JSX.Element | null;
@@ -1,13 +0,0 @@
1
- import type { ReplaySpeed } from "@blade-hq/agent-client";
2
- export interface ReplayBarProps {
3
- /** 非回放会话传 false 时整条不渲染。 */
4
- isReplay: boolean;
5
- speed: ReplaySpeed;
6
- onSpeedChange: (speed: ReplaySpeed) => void;
7
- onExit: () => void;
8
- /** 传 useReplay().canControl。只读身份下仍然显示"在回放",但操作按钮禁用。 */
9
- canControl?: boolean;
10
- className?: string;
11
- }
12
- /** 回放会话的顶部状态条:说明当前在回放、切换倍速、随时退出回放。 */
13
- export declare function ReplayBar({ isReplay, speed, onSpeedChange, onExit, canControl, className, }: ReplayBarProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,8 +0,0 @@
1
- import type { ReplayMismatch } from "../hooks/use-replay";
2
- export interface ReplayMismatchPromptProps {
3
- /** 来自 useReplay().mismatch;为 null 时不渲染。 */
4
- mismatch: ReplayMismatch | null;
5
- className?: string;
6
- }
7
- /** 回放中输入和录制内容对不上时的选择卡:按录制继续,还是从这里真跑。 */
8
- export declare function ReplayMismatchPrompt({ mismatch, className }: ReplayMismatchPromptProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,57 +0,0 @@
1
- import type { ChatMessage } from "@blade-hq/agent-client";
2
- /** OpenAI 标准的工具声明,原样发给模型服务。 */
3
- export interface ChatCompletionTool {
4
- type: "function";
5
- function: {
6
- name: string;
7
- description?: string;
8
- parameters?: Record<string, unknown>;
9
- };
10
- }
11
- export interface LlmToolCall {
12
- id: string;
13
- name: string;
14
- /** 模型生成的 JSON 字符串,是不可信输入,用之前自己校验。 */
15
- arguments: string;
16
- }
17
- export interface LlmChatOptions {
18
- /** OpenAI 兼容根地址,如 `/api/llm`(自己后端的透传路径)或 `http://host:30000/v1`。 */
19
- baseURL: string;
20
- model: string;
21
- /**
22
- * 直连模型服务时才需要。默认形态是让 `baseURL` 指向自己的后端,由后端补密钥转发,
23
- * 浏览器不持有密钥。
24
- */
25
- apiKey?: string;
26
- headers?: Record<string, string>;
27
- /** 系统提示词,合成到消息最前面。 */
28
- system?: string;
29
- /** 每次带上最近多少轮,默认 12。越长越贵,也越容易超上下文。 */
30
- historyTurns?: number;
31
- temperature?: number;
32
- /** 透传给模型服务的额外字段。 */
33
- extraBody?: Record<string, unknown>;
34
- tools?: ChatCompletionTool[];
35
- /** 执行模型请求的工具,返回值会被序列化后回喂给模型。 */
36
- onToolCall?: (call: LlmToolCall) => Promise<unknown>;
37
- /** 工具最多来回几轮,默认 4,防止模型绕圈烧 token。 */
38
- maxToolRounds?: number;
39
- fetchImpl?: typeof fetch;
40
- }
41
- export interface UseLlmChatResult {
42
- messages: ChatMessage[];
43
- isStreaming: boolean;
44
- /** 出错原因;下一次发送会清掉。 */
45
- error: string | null;
46
- send: (text: string) => Promise<boolean>;
47
- stop: () => void;
48
- reset: () => void;
49
- }
50
- /**
51
- * 纯 LLM 对话的状态机,协议就是 **OpenAI Chat Completions**——任何兼容实现都能直接接,
52
- * 不需要为这个组件专门写后端。
53
- *
54
- * 工具调用走 OpenAI 标准的多轮流程:模型返回 tool_calls → 调 onToolCall 执行 →
55
- * 结果作为 role:"tool" 消息回喂 → 再请求一次。
56
- */
57
- export declare function useLlmChat(options: LlmChatOptions): UseLlmChatResult;
@@ -1,50 +0,0 @@
1
- import type { AgentSession, ReplaySpeed } from "@blade-hq/agent-client";
2
- /** 回放中用户说的话和录制内容对不上,需要当场决定往哪走。 */
3
- export interface ReplayMismatch {
4
- /** 用户这次实际发出的内容。 */
5
- actualMessage: string;
6
- /** 源会话里录制的下一句。 */
7
- expectedMessage: string;
8
- /** keep_replay:按录制内容继续;continue_replay:从这里转为真实运行。 */
9
- resolve: (decision: "keep_replay" | "continue_replay") => void;
10
- }
11
- export interface UseReplayResult {
12
- /** 当前会话是不是正在回放(转自主运行后为 false)。 */
13
- isReplay: boolean;
14
- /** 当前播放倍速,非回放会话固定为 1。 */
15
- speed: ReplaySpeed;
16
- setSpeed: (speed: ReplaySpeed) => Promise<void>;
17
- /** 退出回放,之后的对话交给真实模型运行。 */
18
- exitToAutonomous: () => Promise<void>;
19
- /** 待决策的输入冲突;处理完自动清空。 */
20
- mismatch: ReplayMismatch | null;
21
- /** 能不能改回放(改回放是 owner 专属)。只读身份下仍然显示"在回放",但不能操作。 */
22
- canControl: boolean;
23
- /** 当前会话能否作为回放来源(并行子智能体等场景不支持)。 */
24
- canReplay: boolean;
25
- /** canReplay 为 false 时的原因,可直接展示。 */
26
- unsupportedReason: string | null;
27
- /** 从当前会话派生一个回放会话,返回新会话 id。 */
28
- startReplay: (speed?: ReplaySpeed) => Promise<string>;
29
- isStarting: boolean;
30
- /** 最近一次回放操作失败的原因。 */
31
- error: Error | null;
32
- }
33
- /**
34
- * 会话回放(演示 / 彩排模式)。
35
- *
36
- * 回放会话不会自动播放:用户照常发消息,只要这句和源会话录制的下一句意图一致,
37
- * 服务端就按倍速重放当时的回复和工具调用,完全不调用模型;对不上就抛出
38
- * `mismatch` 交给界面决定。
39
- *
40
- * 同一个 hook 覆盖两种身份——传入的会话既可能是回放会话(isReplay / setSpeed /
41
- * exitToAutonomous / mismatch),也可能是准备被回放的源会话(canReplay /
42
- * startReplay)。
43
- *
44
- * 回放状态本身住在 `SessionState.replay` 里(非 React 宿主直接订阅它即可),
45
- * 这里只做 React 绑定:订阅快照 + 接管冲突 + 拉一次 preview。
46
- *
47
- * **注册即接管**:底层的 `replayMismatch` 只交给最先注册的处理器。调用本 hook
48
- * 就意味着由它接管冲突;不调用则维持 SDK 默认行为——直接转为真实运行。
49
- */
50
- export declare function useReplay(session: AgentSession | null): UseReplayResult;