@springbrand/chat-client 0.1.3-alpha.10 → 0.1.3-alpha.12
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 +7 -3
- package/src/index.ts +1 -0
- package/src/use-universal-agent-chat.ts +10 -3
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.12",
|
|
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.2.0-alpha.
|
|
28
|
+
"@springbrand/agent-runtime": "0.2.0-alpha.21"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"typecheck": "tsc --noEmit"
|
package/src/chat-sessions.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { useAgent } from "agents/react";
|
|
3
3
|
|
|
4
|
-
interface InboxState<Session> {
|
|
4
|
+
export interface InboxState<Session> {
|
|
5
5
|
chats: Session[];
|
|
6
6
|
workspaceRev?: number;
|
|
7
7
|
}
|
|
@@ -33,8 +33,11 @@ export async function loadChatSessions<Session>(
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/** Browser client for the user Inbox. Routing and presentation stay with the host UI. */
|
|
36
|
-
export function useChatSessions<
|
|
37
|
-
|
|
36
|
+
export function useChatSessions<
|
|
37
|
+
Session,
|
|
38
|
+
State extends InboxState<Session> = InboxState<Session>,
|
|
39
|
+
>(options: ChatSessionsOptions = {}) {
|
|
40
|
+
const inbox = useAgent<State>({
|
|
38
41
|
agent: "Inbox",
|
|
39
42
|
basePath: CURRENT_INBOX_AGENT_PATH,
|
|
40
43
|
...(options.protocols === undefined ? {} : { protocols: options.protocols }),
|
|
@@ -93,6 +96,7 @@ export function useChatSessions<Session>(options: ChatSessionsOptions = {}) {
|
|
|
93
96
|
synced: inbox.state !== undefined || snapshot !== undefined,
|
|
94
97
|
connected: inbox.identified,
|
|
95
98
|
workspaceRev: inbox.state?.workspaceRev ?? 0,
|
|
99
|
+
inboxState: inbox.state,
|
|
96
100
|
createChat,
|
|
97
101
|
forkChat,
|
|
98
102
|
renameChat,
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { createSafeUIMessageAgentConnection } from "./ui-message-stream-guard";
|
|
|
18
18
|
import { CURRENT_INBOX_AGENT_PATH } from "./chat-sessions";
|
|
19
19
|
|
|
20
20
|
type ChatMessageMetadata = Record<string, unknown> & {
|
|
21
|
+
error?: string;
|
|
21
22
|
requestedCapabilities?: readonly RequestedCapability[];
|
|
22
23
|
turnStatus?: string;
|
|
23
24
|
};
|
|
@@ -364,6 +365,14 @@ export function useUniversalAgentChat(
|
|
|
364
365
|
? "ready"
|
|
365
366
|
: sdkStatus;
|
|
366
367
|
const sdkError = stoppedByUser || hasTerminalMessage ? undefined : error;
|
|
368
|
+
const runtimeError = dispatchError ?? sdkError ?? connectionError ?? undefined;
|
|
369
|
+
const runtimeErrorMessage = runtimeError instanceof Error
|
|
370
|
+
? runtimeError.message
|
|
371
|
+
: runtimeError;
|
|
372
|
+
const presentationError = latestTurnStatus === "error" &&
|
|
373
|
+
latestMessage?.metadata?.error === runtimeErrorMessage
|
|
374
|
+
? undefined
|
|
375
|
+
: runtimeError;
|
|
367
376
|
// RPC admissions bypass useChat's request lifecycle. Project the durable
|
|
368
377
|
// Turn here so presentation stays correct without a second send path.
|
|
369
378
|
const authoritativeStatus =
|
|
@@ -691,7 +700,6 @@ export function useUniversalAgentChat(
|
|
|
691
700
|
type: MessageType.CF_AGENT_CHAT_REQUEST_CANCEL,
|
|
692
701
|
id: requestId,
|
|
693
702
|
}));
|
|
694
|
-
return;
|
|
695
703
|
}
|
|
696
704
|
const result = submissionId
|
|
697
705
|
? await agentRef.current.call<{ ok: boolean }>(
|
|
@@ -771,8 +779,7 @@ export function useUniversalAgentChat(
|
|
|
771
779
|
status,
|
|
772
780
|
runtimeLoad: facetState?.runtimeLoad,
|
|
773
781
|
isStreaming,
|
|
774
|
-
error:
|
|
775
|
-
connectionError ?? undefined,
|
|
782
|
+
error: presentationError,
|
|
776
783
|
sendText,
|
|
777
784
|
steerText,
|
|
778
785
|
enqueueText,
|