@springbrand/chat-client 0.1.3-alpha.21 → 0.1.3-alpha.23
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
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.23",
|
|
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.30"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"typecheck": "tsc --noEmit"
|
|
@@ -33,6 +33,7 @@ import { CURRENT_INBOX_AGENT_PATH } from "./chat-sessions";
|
|
|
33
33
|
type ChatMessageMetadata = Record<string, unknown> & {
|
|
34
34
|
error?: string;
|
|
35
35
|
requestedCapabilities?: readonly RequestedCapability[];
|
|
36
|
+
turnId?: string;
|
|
36
37
|
turnStatus?: string;
|
|
37
38
|
};
|
|
38
39
|
type ChatMessage = UIMessage<ChatMessageMetadata>;
|
|
@@ -174,6 +175,7 @@ type SharedChatConnectionOptions = {
|
|
|
174
175
|
host?: string;
|
|
175
176
|
credentials?: RequestCredentials;
|
|
176
177
|
protocols?: string | string[];
|
|
178
|
+
onMessage?: (message: MessageEvent) => void;
|
|
177
179
|
inboxAgent?: string;
|
|
178
180
|
sessionAgent?: string;
|
|
179
181
|
/** Host projection used only until the selected Session sends its first state. */
|
|
@@ -213,6 +215,7 @@ export function UniversalAgentChatProvider({
|
|
|
213
215
|
: { name: connection.inboxName }),
|
|
214
216
|
...(connection.host === undefined ? {} : { host: connection.host }),
|
|
215
217
|
...(connection.protocols === undefined ? {} : { protocols: connection.protocols }),
|
|
218
|
+
...(connection.onMessage === undefined ? {} : { onMessage: connection.onMessage }),
|
|
216
219
|
connectionTimeout: 6_000,
|
|
217
220
|
sub: [{
|
|
218
221
|
agent: connection.sessionAgent ?? "UniversalAgent",
|
|
@@ -569,11 +572,25 @@ export function useUniversalAgentChat(): ChatRuntime {
|
|
|
569
572
|
const dispatchMessage = useCallback(async (
|
|
570
573
|
message: ChatMessage,
|
|
571
574
|
delivery: MessageDelivery,
|
|
572
|
-
): Promise<MessageDispatchReceipt> =>
|
|
573
|
-
agentRef.current.call<MessageDispatchReceipt>(
|
|
575
|
+
): Promise<MessageDispatchReceipt> => {
|
|
576
|
+
const dispatch = () => agentRef.current.call<MessageDispatchReceipt>(
|
|
574
577
|
"dispatchMessage",
|
|
575
578
|
[message, delivery],
|
|
576
|
-
)
|
|
579
|
+
);
|
|
580
|
+
try {
|
|
581
|
+
return await dispatch();
|
|
582
|
+
} catch (error) {
|
|
583
|
+
// The server deduplicates dispatches by message.id, so replay only the
|
|
584
|
+
// transport failures that mean admission may already have succeeded.
|
|
585
|
+
const retryable = error instanceof Error && (
|
|
586
|
+
/^RPC call to dispatchMessage timed out after \d+ms$/u.test(error.message) ||
|
|
587
|
+
(error.message === "Connection closed" && agentRef.current.shouldReconnect)
|
|
588
|
+
);
|
|
589
|
+
if (!retryable) throw error;
|
|
590
|
+
await agentRef.current.ready;
|
|
591
|
+
return dispatch();
|
|
592
|
+
}
|
|
593
|
+
}, []);
|
|
577
594
|
|
|
578
595
|
const submitMessage = useCallback(async (
|
|
579
596
|
message: ChatMessage,
|