@springbrand/chat-client 0.1.3-alpha.2 → 0.1.3-alpha.3
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/package.json +2 -2
- package/src/chat-sessions.ts +0 -13
- package/src/use-universal-agent-chat.ts +70 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@springbrand/chat-client",
|
|
3
|
-
"version": "0.1.3-alpha.
|
|
3
|
+
"version": "0.1.3-alpha.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@types/react-dom": "^19.2.3",
|
|
26
26
|
"react-dom": "^19.2.7",
|
|
27
27
|
"typescript": "^7.0.2",
|
|
28
|
-
"@springbrand/agent-runtime": "0.1.3-alpha.
|
|
28
|
+
"@springbrand/agent-runtime": "0.1.3-alpha.4"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"typecheck": "tsc --noEmit"
|
package/src/chat-sessions.ts
CHANGED
|
@@ -88,18 +88,6 @@ export function useChatSessions<Session>(options: ChatSessionsOptions = {}) {
|
|
|
88
88
|
await inbox.call("archiveChat", [id, archived]);
|
|
89
89
|
}, [inbox]);
|
|
90
90
|
|
|
91
|
-
const reloadChatRuntime = useCallback(
|
|
92
|
-
async (chatId: string, userAgentId: string) => {
|
|
93
|
-
const result = await inbox.call<{ userAgentId: string } | null>(
|
|
94
|
-
"chatReloadRuntime",
|
|
95
|
-
[chatId, userAgentId],
|
|
96
|
-
);
|
|
97
|
-
if (!result) throw new Error("Session is unavailable");
|
|
98
|
-
return result;
|
|
99
|
-
},
|
|
100
|
-
[inbox],
|
|
101
|
-
);
|
|
102
|
-
|
|
103
91
|
return {
|
|
104
92
|
chats: inbox.state?.chats ?? snapshot ?? [],
|
|
105
93
|
synced: inbox.state !== undefined || snapshot !== undefined,
|
|
@@ -111,7 +99,6 @@ export function useChatSessions<Session>(options: ChatSessionsOptions = {}) {
|
|
|
111
99
|
deleteChat,
|
|
112
100
|
pinChat,
|
|
113
101
|
archiveChat,
|
|
114
|
-
reloadChatRuntime,
|
|
115
102
|
};
|
|
116
103
|
}
|
|
117
104
|
|
|
@@ -8,6 +8,8 @@ import { useAgent, useAgentToolEvents } from "agents/react";
|
|
|
8
8
|
import {
|
|
9
9
|
type MessageDelivery,
|
|
10
10
|
type MessageDispatchReceipt,
|
|
11
|
+
type RuntimeAssemblyView,
|
|
12
|
+
type RuntimeConfigUpdateResult,
|
|
11
13
|
type RuntimeQueuedSubmission,
|
|
12
14
|
type RuntimeState,
|
|
13
15
|
} from "@springbrand/agent-runtime/contracts";
|
|
@@ -28,7 +30,7 @@ type ChatRuntimeLoadState =
|
|
|
28
30
|
| { status: "idle"; available: false }
|
|
29
31
|
| {
|
|
30
32
|
status: "loading";
|
|
31
|
-
phase: "config" | "
|
|
33
|
+
phase: "config" | "assembly" | "mcp" | "pi";
|
|
32
34
|
available: boolean;
|
|
33
35
|
startedAt: number;
|
|
34
36
|
updatedAt: number;
|
|
@@ -41,7 +43,7 @@ type ChatRuntimeLoadState =
|
|
|
41
43
|
}
|
|
42
44
|
| {
|
|
43
45
|
status: "error";
|
|
44
|
-
phase: "config" | "
|
|
46
|
+
phase: "config" | "assembly" | "mcp" | "pi";
|
|
45
47
|
available: boolean;
|
|
46
48
|
startedAt: number;
|
|
47
49
|
failedAt: number;
|
|
@@ -89,6 +91,29 @@ export interface ChatRuntime {
|
|
|
89
91
|
steerQueued: (submissionId: string) => Promise<boolean>;
|
|
90
92
|
cancelQueued: (submissionId: string) => Promise<boolean>;
|
|
91
93
|
stop: () => Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* 把用户对某张交互卡片的操作回写成那次工具调用的结果。
|
|
96
|
+
*
|
|
97
|
+
* 走的是这条已开的 WS 连接(`agent.call`),不是 HTTP —— ack 与随后流下来的
|
|
98
|
+
* `tool-output-available` chunk 同序到达,UI 状态不会倒挂。
|
|
99
|
+
*/
|
|
100
|
+
respondToolInteraction: (
|
|
101
|
+
toolCallId: string,
|
|
102
|
+
response: unknown,
|
|
103
|
+
) => Promise<boolean>;
|
|
104
|
+
/**
|
|
105
|
+
* 读取该 Session facet 当前真正装配出来的 Runtime。
|
|
106
|
+
*
|
|
107
|
+
* 复用这条已开的 WS 连接,调用方不必为一个只读控制面方法另建 `useAgent`。
|
|
108
|
+
*
|
|
109
|
+
* 与其它动作不同,失败会原样抛出:这是读取而不是提交,调用方需要知道是
|
|
110
|
+
* 装配未就绪还是连接断了,收敛成 `undefined` 会让调试面板无从显示原因。
|
|
111
|
+
*/
|
|
112
|
+
getRuntimeAssembly: () => Promise<RuntimeAssemblyView>;
|
|
113
|
+
updateConfig: <Change = unknown>(
|
|
114
|
+
command: unknown,
|
|
115
|
+
) => Promise<RuntimeConfigUpdateResult<Change>>;
|
|
116
|
+
reloadRuntime: () => Promise<void>;
|
|
92
117
|
regenerate: () => void;
|
|
93
118
|
canRetry: boolean;
|
|
94
119
|
agentToolRuns: AgentToolRunState<ChatMessage["parts"][number]>[];
|
|
@@ -664,7 +689,50 @@ export function useUniversalAgentChat(
|
|
|
664
689
|
);
|
|
665
690
|
}, [submitMessage]);
|
|
666
691
|
|
|
692
|
+
// 交互卡片的写回口。失败只返回 false —— 调用方(块组件)自己决定怎么提示;
|
|
693
|
+
// 权威状态永远来自 part 的 state,不来自这里的返回值。
|
|
694
|
+
const respondToolInteraction = useCallback(async (
|
|
695
|
+
toolCallId: string,
|
|
696
|
+
response: unknown,
|
|
697
|
+
): Promise<boolean> => {
|
|
698
|
+
try {
|
|
699
|
+
const receipt = await agentRef.current.call<{ ok: boolean }>(
|
|
700
|
+
"respondToolInteraction",
|
|
701
|
+
[toolCallId, response],
|
|
702
|
+
);
|
|
703
|
+
return receipt.ok;
|
|
704
|
+
} catch {
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
}, []);
|
|
708
|
+
|
|
709
|
+
// 只读控制面:Runtime 尚未装配时由 Agent 侧 `ensureRuntimeReady` 负责等待,
|
|
710
|
+
// 这里不缓存结果 —— 换模型、加技能或 reload 之后调用方要拿到的是新装配。
|
|
711
|
+
const getRuntimeAssembly = useCallback(
|
|
712
|
+
() => agentRef.current.call<RuntimeAssemblyView>("getRuntimeAssembly", []),
|
|
713
|
+
[],
|
|
714
|
+
);
|
|
715
|
+
const updateConfig = useCallback(
|
|
716
|
+
<Change,>(command: unknown) =>
|
|
717
|
+
agentRef.current.call<RuntimeConfigUpdateResult<Change>>(
|
|
718
|
+
"updateConfig",
|
|
719
|
+
[command],
|
|
720
|
+
),
|
|
721
|
+
[],
|
|
722
|
+
);
|
|
723
|
+
const reloadRuntime = useCallback(
|
|
724
|
+
() => agentRef.current.call<void>(
|
|
725
|
+
"reloadRuntime",
|
|
726
|
+
[undefined, { force: true }],
|
|
727
|
+
),
|
|
728
|
+
[],
|
|
729
|
+
);
|
|
730
|
+
|
|
667
731
|
return {
|
|
732
|
+
respondToolInteraction,
|
|
733
|
+
getRuntimeAssembly,
|
|
734
|
+
updateConfig,
|
|
735
|
+
reloadRuntime,
|
|
668
736
|
messages: visibleMessages,
|
|
669
737
|
status,
|
|
670
738
|
runtimeLoad: facetState?.runtimeLoad,
|