@tanstack/ai-octane 0.3.1 → 0.4.0

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": "@tanstack/ai-octane",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Octane bindings for TanStack AI streaming chat, structured outputs, and media generation.",
5
5
  "author": "Dominic Gannaway",
6
6
  "license": "MIT",
@@ -47,11 +47,11 @@
47
47
  ],
48
48
  "//lint": "The .tsrx.d.ts companions are generated declaration emits of the .tsrx implementations, so they are not hand-formatted and are excluded from lint rather than edited in place (a regeneration would undo any fix).",
49
49
  "dependencies": {
50
- "@tanstack/ai-client": "0.31.1"
50
+ "@tanstack/ai-client": "0.32.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "octane": "^0.1.17",
54
- "@tanstack/ai": "^0.54.0"
54
+ "@tanstack/ai": "^0.55.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@octanejs/testing-library": "0.1.14",
@@ -62,7 +62,7 @@
62
62
  "octane": "0.1.17",
63
63
  "vite": "^8.2.1",
64
64
  "zod": "^4.2.0",
65
- "@tanstack/ai": "0.54.0"
65
+ "@tanstack/ai": "0.55.0"
66
66
  },
67
67
  "scripts": {
68
68
  "lint:fix": "oxlint src --type-aware --ignore-pattern '**/*.tsrx.d.ts' --fix",
package/src/types.ts CHANGED
@@ -263,6 +263,16 @@ interface BaseUseChatReturn<
263
263
  */
264
264
  isLoading: boolean
265
265
 
266
+ /**
267
+ * True when the last hydrate or older-page response said more messages exist.
268
+ */
269
+ hasOlderMessages: boolean
270
+
271
+ /**
272
+ * Fetch the next older window and put it in front of the painted messages.
273
+ */
274
+ loadOlderMessages: () => Promise<void>
275
+
266
276
  /**
267
277
  * Current error, if any
268
278
  */
package/src/use-chat.tsrx CHANGED
@@ -53,6 +53,7 @@ export function useChat<
53
53
  options.initialMessages || [],
54
54
  )
55
55
  const [isLoading, setIsLoading] = useState(false)
56
+ const [hasOlderMessages, setHasOlderMessages] = useState(false)
56
57
  const [error, setError] = useState<Error | undefined>(undefined)
57
58
  const [status, setStatus] = useState<ChatClientState>('ready')
58
59
  const [isSubscribed, setIsSubscribed] = useState(false)
@@ -141,16 +142,25 @@ export function useChat<
141
142
  ...transport,
142
143
  initialMessages: messagesToUse,
143
144
  ...(typeof initialOptions.threadId === 'string' &&
144
- initialOptions.persistence
145
+ initialOptions.persistence === true
145
146
  ? {
146
- persistence: initialOptions.persistence,
147
+ persistence: true,
147
148
  threadId: initialOptions.threadId,
149
+ ...(initialOptions.history !== undefined && {
150
+ history: initialOptions.history,
151
+ }),
148
152
  }
149
- : {
150
- ...(initialOptions.threadId !== undefined && {
153
+ : typeof initialOptions.threadId === 'string' &&
154
+ initialOptions.persistence
155
+ ? {
156
+ persistence: initialOptions.persistence,
151
157
  threadId: initialOptions.threadId,
158
+ }
159
+ : {
160
+ ...(initialOptions.threadId !== undefined && {
161
+ threadId: initialOptions.threadId,
162
+ }),
152
163
  }),
153
- }),
154
164
  ...(initialOptions.body !== undefined && { body: initialOptions.body }),
155
165
  ...(initialOptions.forwardedProps !== undefined && {
156
166
  forwardedProps: initialOptions.forwardedProps,
@@ -206,6 +216,9 @@ export function useChat<
206
216
  onMessagesChange: (newMessages: Array<UIMessage<TTools>>) => {
207
217
  runOrQueueForActiveInstance(() => {
208
218
  setMessages(newMessages)
219
+ const currentInstance = getActiveInstance()
220
+ if (!currentInstance) return
221
+ setHasOlderMessages(currentInstance.getHasOlderMessages())
209
222
  })
210
223
  },
211
224
  onLoadingChange: (newIsLoading: boolean) => {
@@ -300,6 +313,7 @@ export function useChat<
300
313
  if (clientMessages !== messagesRef.current) {
301
314
  setMessages(clientMessages)
302
315
  }
316
+ setHasOlderMessages(client.getHasOlderMessages())
303
317
  }, [client])
304
318
 
305
319
  // OCTANE DIVERGENCE: upstream captures the initial transport. ChatClient
@@ -424,6 +438,11 @@ export function useChat<
424
438
  }
425
439
  }, [client, syncResumeState])
426
440
 
441
+ const loadOlderMessages = useCallback(async () => {
442
+ await client.loadOlderMessages()
443
+ setHasOlderMessages(client.getHasOlderMessages())
444
+ }, [client])
445
+
427
446
  const stop = useCallback(() => {
428
447
  client.stop()
429
448
  }, [client])
@@ -560,6 +579,8 @@ export function useChat<
560
579
  reload,
561
580
  stop,
562
581
  isLoading,
582
+ hasOlderMessages,
583
+ loadOlderMessages,
563
584
  error,
564
585
  status,
565
586
  isSubscribed,