@springbrand/chat-client 0.3.0-alpha.1 → 0.3.0-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@springbrand/chat-client",
3
- "version": "0.3.0-alpha.1",
3
+ "version": "0.3.0-alpha.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -13,8 +13,8 @@
13
13
  ".": "./src/index.ts"
14
14
  },
15
15
  "peerDependencies": {
16
- "@cloudflare/ai-chat": "^0.11.0",
17
- "agents": "^0.22.0",
16
+ "@cloudflare/ai-chat": "^0.12.0",
17
+ "agents": "^0.23.0",
18
18
  "ai": "^7.0.0",
19
19
  "react": "^19.0.0"
20
20
  },
@@ -22,12 +22,12 @@
22
22
  "nanoid": "^5.1.16"
23
23
  },
24
24
  "devDependencies": {
25
- "@cloudflare/ai-chat": "0.11.0",
25
+ "@cloudflare/ai-chat": "0.12.0",
26
26
  "@types/react": "^19.2.18",
27
27
  "@types/react-dom": "^19.2.5",
28
28
  "react-dom": "^19.2.8",
29
29
  "typescript": "^7.0.2",
30
- "@springbrand/agent-runtime": "0.3.0-alpha.1"
30
+ "@springbrand/agent-runtime": "0.3.0-alpha.4"
31
31
  },
32
32
  "scripts": {
33
33
  "typecheck": "tsc --noEmit"
@@ -180,8 +180,9 @@ type SharedChatConnectionOptions = {
180
180
  };
181
181
 
182
182
  export type ChatConnectionOptions = SharedChatConnectionOptions & (
183
- | { inboxName: string; basePath?: never }
184
- | { inboxName?: never; basePath?: string }
183
+ | { inboxName: string; basePath?: never; sessionBasePath?: never }
184
+ | { inboxName?: never; basePath?: string; sessionBasePath?: never }
185
+ | { inboxName?: never; basePath?: never; sessionBasePath: string }
185
186
  );
186
187
 
187
188
  type SessionAgentConnection = ReturnType<typeof useAgent<RuntimeState>>;
@@ -206,19 +207,24 @@ export function UniversalAgentChatProvider({
206
207
  children: ReactNode;
207
208
  }) {
208
209
  const inboxAgent = connection.inboxAgent ?? "Inbox";
210
+ const routed = connection.sessionBasePath !== undefined;
209
211
  const agent = useAgent<RuntimeState>({
210
- agent: inboxAgent,
211
- ...(connection.inboxName === undefined
212
- ? { basePath: connection.basePath ?? CURRENT_INBOX_AGENT_PATH }
213
- : { name: connection.inboxName }),
212
+ agent: routed ? connection.sessionAgent ?? "UniversalAgent" : inboxAgent,
213
+ ...(routed
214
+ ? { basePath: connection.sessionBasePath, name: chatId }
215
+ : connection.inboxName === undefined
216
+ ? { basePath: connection.basePath ?? CURRENT_INBOX_AGENT_PATH }
217
+ : { name: connection.inboxName }),
214
218
  ...(connection.host === undefined ? {} : { host: connection.host }),
215
219
  ...(connection.protocols === undefined ? {} : { protocols: connection.protocols }),
216
220
  ...(connection.onMessage === undefined ? {} : { onMessage: connection.onMessage }),
217
221
  connectionTimeout: 6_000,
218
- sub: [{
219
- agent: connection.sessionAgent ?? "UniversalAgent",
220
- name: chatId,
221
- }],
222
+ ...(routed ? {} : {
223
+ sub: [{
224
+ agent: connection.sessionAgent ?? "UniversalAgent",
225
+ name: chatId,
226
+ }],
227
+ }),
222
228
  });
223
229
  const chatAgent = useMemo(
224
230
  () => createSafeUIMessageAgentConnection(agent),
@@ -597,6 +603,13 @@ export function useUniversalAgentChat(): ChatRuntime {
597
603
  throw new Error("useUniversalAgentChat must be used within UniversalAgentChatProvider");
598
604
  }
599
605
  const { chatId, connection, agent, chatAgent } = context;
606
+ const routedHistoryUrl = connection.sessionBasePath !== undefined &&
607
+ connection.host !== undefined
608
+ ? new URL(
609
+ `/${connection.sessionBasePath.replace(/^\/+/, "")}`,
610
+ connection.host,
611
+ ).toString()
612
+ : undefined;
600
613
  const [optimisticMessages, setOptimisticMessages] =
601
614
  useState<ChatMessage[]>([]);
602
615
  const [optimisticQueued, setOptimisticQueued] =
@@ -632,7 +645,10 @@ export function useUniversalAgentChat(): ChatRuntime {
632
645
  agent: chatAgent,
633
646
  getInitialMessages: connection.skipInitialMessages
634
647
  ? null
635
- : ({ url }) => loadInitialMessages(url, connection.credentials),
648
+ : ({ url }) => loadInitialMessages(
649
+ routedHistoryUrl ?? url,
650
+ connection.credentials,
651
+ ),
636
652
  ...(connection.credentials === undefined
637
653
  ? {}
638
654
  : { credentials: connection.credentials }),