@springbrand/chat-client 0.1.3-alpha.11 → 0.1.3-alpha.13
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 +8 -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.13",
|
|
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.22"
|
|
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
|
@@ -148,6 +148,8 @@ type SharedChatConnectionOptions = {
|
|
|
148
148
|
protocols?: string | string[];
|
|
149
149
|
inboxAgent?: string;
|
|
150
150
|
sessionAgent?: string;
|
|
151
|
+
/** Host projection used only until the selected Session sends its first state. */
|
|
152
|
+
initialTurnActive?: boolean;
|
|
151
153
|
};
|
|
152
154
|
|
|
153
155
|
export type ChatConnectionOptions = SharedChatConnectionOptions & (
|
|
@@ -384,9 +386,12 @@ export function useUniversalAgentChat(
|
|
|
384
386
|
? "streaming"
|
|
385
387
|
: "submitted"
|
|
386
388
|
: normalizedSdkStatus;
|
|
389
|
+
const hydratingTurnActive = facetState === undefined &&
|
|
390
|
+
connection.initialTurnActive === true;
|
|
387
391
|
const status = dispatchError
|
|
388
392
|
? "error"
|
|
389
|
-
: optimisticMessages.length > 0
|
|
393
|
+
: (optimisticMessages.length > 0 || hydratingTurnActive) &&
|
|
394
|
+
authoritativeStatus === "ready"
|
|
390
395
|
? "submitted"
|
|
391
396
|
: authoritativeStatus;
|
|
392
397
|
const messagesRef = useRef(messages);
|
|
@@ -478,7 +483,8 @@ export function useUniversalAgentChat(
|
|
|
478
483
|
isToolContinuation;
|
|
479
484
|
const pendingLocalTurn = optimisticMessages.length > 0 &&
|
|
480
485
|
(status === "submitted" || status === "streaming");
|
|
481
|
-
const turnActive =
|
|
486
|
+
const turnActive = hydratingTurnActive ||
|
|
487
|
+
Boolean(turn?.activeSubmissionId) ||
|
|
482
488
|
pendingLocalTurn ||
|
|
483
489
|
(authoritativeTurn === undefined && sdkTurnActive);
|
|
484
490
|
const canSteer = turnActive &&
|
|
@@ -700,7 +706,6 @@ export function useUniversalAgentChat(
|
|
|
700
706
|
type: MessageType.CF_AGENT_CHAT_REQUEST_CANCEL,
|
|
701
707
|
id: requestId,
|
|
702
708
|
}));
|
|
703
|
-
return;
|
|
704
709
|
}
|
|
705
710
|
const result = submissionId
|
|
706
711
|
? await agentRef.current.call<{ ok: boolean }>(
|