@blade-hq/agent-react 2608.0.6 → 2608.0.7-beta.0
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 +155 -3
- package/dist/components/AgentChat.d.ts +21 -0
- package/dist/components/AssistantTurnBlock.d.ts +1 -1
- package/dist/components/ChatSurface.d.ts +68 -0
- package/dist/components/ChatView.d.ts +20 -39
- package/dist/components/LlmAdvancedSettings.d.ts +40 -0
- package/dist/components/LlmChat.d.ts +29 -0
- package/dist/components/MarkdownContent.d.ts +3 -6
- package/dist/components/MessageList.d.ts +10 -3
- package/dist/components/PostChatFollowupBlock.d.ts +59 -0
- package/dist/components/ReplayBar.d.ts +13 -0
- package/dist/components/ReplayMismatchPrompt.d.ts +8 -0
- package/dist/embed/entry.d.ts +5 -0
- package/dist/hooks/use-llm-chat.d.ts +57 -0
- package/dist/hooks/use-replay.d.ts +50 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +1673 -434
- package/dist/index.js.map +1 -1
- package/dist/style.css +52 -11
- package/dist/style.full.css +53 -12
- package/package.json +2 -2
- package/public-api.md +424 -4
- package/dist/components/FileCard.d.ts +0 -16
- package/dist/lib/media-tags.d.ts +0 -24
|
@@ -0,0 +1,57 @@
|
|
|
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;
|
|
@@ -0,0 +1,50 @@
|
|
|
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;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,22 @@ export { BladeProvider, useBladeClient } from "./context";
|
|
|
2
2
|
export type { BladeProviderProps } from "./context";
|
|
3
3
|
export { useAgentSession } from "./hooks/use-agent-session";
|
|
4
4
|
export type { UseAgentSessionOptions, UseAgentSessionResult } from "./hooks/use-agent-session";
|
|
5
|
+
export { useReplay } from "./hooks/use-replay";
|
|
6
|
+
export type { ReplayMismatch, UseReplayResult } from "./hooks/use-replay";
|
|
7
|
+
export { useLlmChat } from "./hooks/use-llm-chat";
|
|
8
|
+
export type { ChatCompletionTool, LlmChatOptions, LlmToolCall, UseLlmChatResult, } from "./hooks/use-llm-chat";
|
|
5
9
|
export { ChatView } from "./components/ChatView";
|
|
6
|
-
export type { ChatViewClassNames, ChatViewProps, ChatViewRenderers, ChatViewSlots, } from "./components/ChatView";
|
|
10
|
+
export type { ChatViewClassNames, ChatViewProps, ChatViewRenderers, ChatViewSlots, FollowupInteractionEvent, } from "./components/ChatView";
|
|
11
|
+
export { AgentChat } from "./components/AgentChat";
|
|
12
|
+
export type { AgentChatProps } from "./components/AgentChat";
|
|
13
|
+
export { LlmChat } from "./components/LlmChat";
|
|
14
|
+
export type { LlmChatHandle, LlmChatProps } from "./components/LlmChat";
|
|
15
|
+
export type { LlmAdvancedSettings, LlmOverride } from "./components/LlmAdvancedSettings";
|
|
7
16
|
export { MarkdownContent } from "./components/MarkdownContent";
|
|
8
17
|
export type { MarkdownContentProps } from "./components/MarkdownContent";
|
|
18
|
+
export { ReplayBar } from "./components/ReplayBar";
|
|
19
|
+
export type { ReplayBarProps } from "./components/ReplayBar";
|
|
20
|
+
export { ReplayMismatchPrompt } from "./components/ReplayMismatchPrompt";
|
|
21
|
+
export type { ReplayMismatchPromptProps } from "./components/ReplayMismatchPrompt";
|
|
9
22
|
export type { ToolCallRenderer } from "./components/ToolCallBlock";
|
|
10
23
|
export * from "@blade-hq/agent-client";
|