@stll/chat 0.1.39 → 0.1.40
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/README.md +9 -0
- package/dist/.bun/install/cache/links/@tanstack_ai-event-client@0.13.1-c12313b8e0f930fe/node_modules/@tanstack/ai-event-client/dist/esm/envelope.d.ts +5 -0
- package/dist/.bun/install/cache/links/@tanstack_ai-event-client@0.13.1-c12313b8e0f930fe/node_modules/@tanstack/ai-event-client/dist/esm/index.d.ts +141 -0
- package/dist/.bun/install/cache/links/@tanstack_devtools-event-client@0.4.4-93caf0d86e8c814b/node_modules/@tanstack/devtools-event-client/dist/esm/index.d.ts +1 -0
- package/dist/.bun/install/cache/links/@tanstack_devtools-event-client@0.4.4-93caf0d86e8c814b/node_modules/@tanstack/devtools-event-client/dist/esm/plugin.d.ts +5 -0
- package/dist/durable-transport.d.ts +68 -0
- package/dist/durable-transport.js +239 -0
- package/dist/resume-contract.d.ts +32 -0
- package/dist/resume-contract.js +30 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/activity-records.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/adapter.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/agent-loop-strategies.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/agents/define-agent.d.ts +4 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/agents/route.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/agents/spawn.d.ts +6 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/agents/turn.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/cancel.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/index.d.ts +9 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/mcp/manager.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/mcp/types.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/messages.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/middleware/builder.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/middleware/compose.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/middleware/define.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/middleware/generic-interrupts.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/middleware/index.d.ts +8 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/middleware/locks.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/middleware/run-store.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/middleware/types.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/middleware/validate.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/runtime-context-types.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/index.d.ts +4 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/processor.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/strategies.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/types.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/approval-schema.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/lazy-tool-manager.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/lazy-tools.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/schema-converter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/tool-calls.d.ts +5 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/tool-definition.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/unique-tool-names.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/embed/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/embed/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/evaluate/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/evaluate/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/files/index.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateAudio/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateAudio/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateImage/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateImage/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateLiveVideo/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateLiveVideo/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateSpeech/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateSpeech/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateTranscription/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateTranscription/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateVideo/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateVideo/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateVideo/snap.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateVoice/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateVoice/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateWorld/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/generateWorld/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/index.d.ts +32 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/middleware/index.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/middleware/run.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/middleware/types.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/rerank/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/rerank/index.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/summarize/adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/summarize/chat-stream-summarize.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/activities/summarize/index.d.ts +4 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/client.d.ts +23 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/custom-events.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/extend-adapter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/generic-interrupt-continuation.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/index.d.ts +66 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/interrupt-definition.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/interrupt-resume.d.ts +4 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/interrupts.d.ts +30 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/realtime/event-emitter.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/realtime/index.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/realtime/types.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/stream-durability.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/stream-to-response.d.ts +4 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/stream-to-websocket.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/tool-registry.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/tools/provider-tool.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/types.d.ts +539 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/adapter-yield-chunk.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/ag-ui-usage.d.ts +8 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/ag-ui-wire.d.ts +3 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/chat-params.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/chunk-ids.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/content-source.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/embedding-input.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/errors.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/media-prompt.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/merge-metadata.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/normalize-stream-chunk.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/provider-executed.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/restore-inbound-chunk.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/subagent-wire.d.ts +2 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/tool-result.d.ts +1 -0
- package/dist/work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/utilities/usage.d.ts +1 -0
- package/package.json +23 -8
package/README.md
CHANGED
|
@@ -26,3 +26,12 @@ const runtime = createChatRuntime({ transport });
|
|
|
26
26
|
Validate every explicit provider/model selection with
|
|
27
27
|
`resolveChatModelSelection`. It rejects unknown, empty, duplicate, and
|
|
28
28
|
unconfigured provider/model combinations with `ChatConfigurationError`.
|
|
29
|
+
|
|
30
|
+
For TanStack hosts, `@stll/chat/durable-transport` exports
|
|
31
|
+
`createDurableChatTransport`: pass its `connection` and `persistence` to
|
|
32
|
+
`ChatClient`, call `attach()` while a viewer is mounted and `detach()` when it
|
|
33
|
+
leaves. The host supplies authenticated probe/join URLs and transcript reload
|
|
34
|
+
callbacks. Resume state comes from the server; this adapter stores no transcript
|
|
35
|
+
on the device. Network retries rejoin the log with the last event cursor and
|
|
36
|
+
jittered backoff, bounded to three minutes. Detaching keeps an accepted server
|
|
37
|
+
turn running; the host must use the turn cancellation endpoint for Stop.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import "../../../../../../@tanstack_devtools-event-client@0.4.4-93caf0d86e8c814b/node_modules/@tanstack/devtools-event-client/dist/esm/index.js";
|
|
2
|
+
import "./envelope.js";
|
|
3
|
+
//#region ../../../../../.bun/install/cache/links/@tanstack+ai-event-client@0.13.1-c12313b8e0f930fe/node_modules/@tanstack/ai-event-client/dist/esm/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Detailed breakdown of prompt/input token usage.
|
|
6
|
+
* Fields are populated based on provider support.
|
|
7
|
+
*/
|
|
8
|
+
export interface PromptTokensDetails {
|
|
9
|
+
/** Tokens read from cache */
|
|
10
|
+
cachedTokens?: number;
|
|
11
|
+
/** Tokens written to cache */
|
|
12
|
+
cacheWriteTokens?: number;
|
|
13
|
+
/** Audio input tokens */
|
|
14
|
+
audioTokens?: number;
|
|
15
|
+
/** Video input tokens */
|
|
16
|
+
videoTokens?: number;
|
|
17
|
+
/** Image input tokens */
|
|
18
|
+
imageTokens?: number;
|
|
19
|
+
/** Text input tokens */
|
|
20
|
+
textTokens?: number;
|
|
21
|
+
/** Document input tokens (e.g. PDF inputs on Gemini) */
|
|
22
|
+
documentTokens?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Detailed breakdown of completion/output token usage.
|
|
26
|
+
* Fields are populated based on provider support.
|
|
27
|
+
*/
|
|
28
|
+
export interface CompletionTokensDetails {
|
|
29
|
+
/** Reasoning/thinking tokens */
|
|
30
|
+
reasoningTokens?: number;
|
|
31
|
+
/** Audio output tokens */
|
|
32
|
+
audioTokens?: number;
|
|
33
|
+
/** Video output tokens */
|
|
34
|
+
videoTokens?: number;
|
|
35
|
+
/** Image output tokens */
|
|
36
|
+
imageTokens?: number;
|
|
37
|
+
/** Text output tokens */
|
|
38
|
+
textTokens?: number;
|
|
39
|
+
/** Document output tokens */
|
|
40
|
+
documentTokens?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Provider-reported cost breakdown for a single request, normalized onto a
|
|
44
|
+
* canonical shape so consumer code is portable across gateways. Each adapter's
|
|
45
|
+
* extractor maps its provider-specific wire keys (e.g. OpenRouter's
|
|
46
|
+
* `upstream_inference_prompt_cost`, `upstream_inference_input_cost`) onto these
|
|
47
|
+
* fields at runtime.
|
|
48
|
+
*/
|
|
49
|
+
export interface UsageCostBreakdown {
|
|
50
|
+
/** Total cost the gateway paid the upstream provider. */
|
|
51
|
+
upstreamCost?: number;
|
|
52
|
+
/** Upstream cost for input (prompt) tokens. */
|
|
53
|
+
upstreamInputCost?: number;
|
|
54
|
+
/** Upstream cost for output (completion) tokens. */
|
|
55
|
+
upstreamOutputCost?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Unit a billed quantity is counted in. The named members cover the units
|
|
59
|
+
* TanStack AI adapters bill in today; the `(string & {})` member keeps the
|
|
60
|
+
* union open for genuinely provider-specific units while preserving
|
|
61
|
+
* autocompletion for the common ones.
|
|
62
|
+
*/
|
|
63
|
+
export type BillingUnit = 'tokens' | 'seconds' | 'characters' | 'images' | 'videos' | 'megapixels' | 'requests' | 'units' | (string & {});
|
|
64
|
+
/**
|
|
65
|
+
* A billed quantity paired with the unit it is counted in, so consumers can
|
|
66
|
+
* label and aggregate usage without out-of-band knowledge of the provider or
|
|
67
|
+
* activity. `unit: 'units'` marks an opaque provider-defined unit (e.g. fal's
|
|
68
|
+
* "fal units") whose price is only knowable from the provider's pricing page.
|
|
69
|
+
*/
|
|
70
|
+
export interface BilledUsage {
|
|
71
|
+
/** Number of units billed. */
|
|
72
|
+
quantity: number;
|
|
73
|
+
/** The unit `quantity` is counted in. */
|
|
74
|
+
unit: BillingUnit;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Default value type for {@link TokenUsage.providerUsageDetails} when an adapter
|
|
78
|
+
* does not supply a specific shape. Values are constrained to non-nullish
|
|
79
|
+
* (`NonNullable<unknown>`, i.e. `{}`) rather than `unknown` so that `TokenUsage`
|
|
80
|
+
* stays assignable across JSON-serialization boundaries — e.g. TanStack Start's
|
|
81
|
+
* server-fn return types model serializable values as `{}` and reject `unknown`,
|
|
82
|
+
* which permits `null`/`undefined`.
|
|
83
|
+
*/
|
|
84
|
+
export type ProviderUsageDetails = Record<string, NonNullable<unknown>>;
|
|
85
|
+
/**
|
|
86
|
+
* Canonical token usage for a run, with optional detailed breakdowns and
|
|
87
|
+
* provider-reported cost. This is the single source of truth re-exported by
|
|
88
|
+
* `@tanstack/ai`.
|
|
89
|
+
*
|
|
90
|
+
* Core fields (`promptTokens`, `completionTokens`, `totalTokens`) are always
|
|
91
|
+
* present. Detail fields are provider-dependent and absent when not reported,
|
|
92
|
+
* so consumers must treat them as optional.
|
|
93
|
+
*
|
|
94
|
+
* `providerUsageDetails` is parameterized via `TProviderDetails` so adapters can
|
|
95
|
+
* surface a strongly-typed bag (e.g. `TokenUsage<AnthropicProviderUsageDetails>`);
|
|
96
|
+
* it defaults to {@link ProviderUsageDetails} (an open, serializable record) for
|
|
97
|
+
* generic consumers.
|
|
98
|
+
*/
|
|
99
|
+
export interface TokenUsage<TProviderDetails = ProviderUsageDetails> {
|
|
100
|
+
/** Total input/prompt tokens */
|
|
101
|
+
promptTokens: number;
|
|
102
|
+
/** Total output/completion tokens */
|
|
103
|
+
completionTokens: number;
|
|
104
|
+
/** Total tokens as reported by the provider; may exceed promptTokens +
|
|
105
|
+
* completionTokens when reasoning/cache/tool tokens are billed separately. */
|
|
106
|
+
totalTokens: number;
|
|
107
|
+
/** Detailed breakdown of prompt tokens by category */
|
|
108
|
+
promptTokensDetails?: PromptTokensDetails;
|
|
109
|
+
/** Detailed breakdown of completion tokens by category */
|
|
110
|
+
completionTokensDetails?: CompletionTokensDetails;
|
|
111
|
+
/**
|
|
112
|
+
* The primary non-token billed quantity, self-describing via its unit —
|
|
113
|
+
* e.g. `{ quantity: 8, unit: 'seconds' }` for a video generation or
|
|
114
|
+
* `{ quantity: 3, unit: 'units' }` for fal's opaque endpoint units. Absent
|
|
115
|
+
* when the activity bills purely in tokens (the token fields above are
|
|
116
|
+
* already self-describing). When a provider bills tokens *on top of* a media
|
|
117
|
+
* unit, the tokens stay in the token fields and `billed` carries the media
|
|
118
|
+
* unit. A quantity, distinct from the monetary `cost` / `costDetails`.
|
|
119
|
+
*/
|
|
120
|
+
billed?: BilledUsage;
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated Read {@link TokenUsage.billed} instead, which pairs the same
|
|
123
|
+
* duration with an explicit `unit: 'seconds'`. Still populated alongside
|
|
124
|
+
* `billed` for backward compatibility; will be removed in a future release.
|
|
125
|
+
*/
|
|
126
|
+
durationSeconds?: number;
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated Read {@link TokenUsage.billed} instead, which pairs the same
|
|
129
|
+
* count with the unit it is denominated in (`seconds`, `units`, …) — this
|
|
130
|
+
* bare count is ambiguous across providers. Still populated alongside
|
|
131
|
+
* `billed` for backward compatibility; will be removed in a future release.
|
|
132
|
+
*/
|
|
133
|
+
unitsBilled?: number;
|
|
134
|
+
/** Provider-specific usage details not covered by standard fields */
|
|
135
|
+
providerUsageDetails?: TProviderDetails;
|
|
136
|
+
/** Provider-reported cost for the request, when available. */
|
|
137
|
+
cost?: number;
|
|
138
|
+
/** Provider-reported cost breakdown, when available. */
|
|
139
|
+
costDetails?: UsageCostBreakdown;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./plugin.js";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AGUIEvent, ActivityDeltaEvent as ActivityDeltaEvent$1, ActivitySnapshotEvent as ActivitySnapshotEvent$1, ContentPart, CustomEvent as CustomEvent$1, MessagesSnapshotEvent as MessagesSnapshotEvent$1, ModelMessage, RawEvent as RawEvent$1, ReasoningEncryptedValueEvent as ReasoningEncryptedValueEvent$1, ReasoningEndEvent as ReasoningEndEvent$1, ReasoningMessageChunkEvent as ReasoningMessageChunkEvent$1, ReasoningMessageContentEvent as ReasoningMessageContentEvent$1, ReasoningMessageEndEvent as ReasoningMessageEndEvent$1, ReasoningMessageStartEvent as ReasoningMessageStartEvent$1, ReasoningStartEvent as ReasoningStartEvent$1, RunErrorEvent as RunErrorEvent$1, RunFinishedEvent as RunFinishedEvent$1, RunStartedEvent as RunStartedEvent$1, StateDeltaEvent as StateDeltaEvent$1, StateSnapshotEvent as StateSnapshotEvent$1, StepFinishedEvent as StepFinishedEvent$1, StepStartedEvent as StepStartedEvent$1, SubagentErrorEvent as SubagentErrorEvent$1, SubagentFinishedEvent as SubagentFinishedEvent$1, SubagentStartedEvent as SubagentStartedEvent$1, TextMessageChunkEvent as TextMessageChunkEvent$1, TextMessageContentEvent as TextMessageContentEvent$1, TextMessageEndEvent as TextMessageEndEvent$1, TextMessageStartEvent as TextMessageStartEvent$1, ToolCallArgsEvent as ToolCallArgsEvent$1, ToolCallChunkEvent as ToolCallChunkEvent$1, ToolCallEndEvent as ToolCallEndEvent$1, ToolCallResultEvent as ToolCallResultEvent$1, ToolCallStartEvent as ToolCallStartEvent$1, UIMessage as UIMessage$1 } from "./work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/types.js";
|
|
2
|
+
import "./work/stella/stella/node_modules/.bun/@tanstack_ai@0.65.1_9c170ad6cb10badb/node_modules/@tanstack/ai/dist/esm/index.js";
|
|
3
|
+
import { ChatTurnResumeProbe } from "./resume-contract.js";
|
|
4
|
+
import { EventType } from "@ag-ui/core";
|
|
5
|
+
import { UIMessage } from "@tanstack/ai-client";
|
|
6
|
+
//#region src/durable-transport.d.ts
|
|
7
|
+
declare const ChatReconnectError_base: import("better-result").TaggedErrorClass<"ChatReconnectError">;
|
|
8
|
+
export declare class ChatReconnectError extends ChatReconnectError_base<{
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
code?: "invalid-response" | "refused";
|
|
11
|
+
message: string;
|
|
12
|
+
}> {}
|
|
13
|
+
export type ChatResumeProbe = ChatTurnResumeProbe;
|
|
14
|
+
declare const waitForReconnect: (delay: number, signal: AbortSignal | null | undefined) => Promise<void>;
|
|
15
|
+
type ChatLoadedTurn = {
|
|
16
|
+
type: "active";
|
|
17
|
+
} | {
|
|
18
|
+
type: "parked";
|
|
19
|
+
runId: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "settled";
|
|
22
|
+
};
|
|
23
|
+
type DurableChatTransportOptions<TMessages extends UIMessage[]> = {
|
|
24
|
+
initialMessages: TMessages;
|
|
25
|
+
initialTurn: ChatLoadedTurn;
|
|
26
|
+
threadId: string;
|
|
27
|
+
/** Server truth is checked on mount and before every read-only retry. */
|
|
28
|
+
probe: (signal?: AbortSignal | null) => Promise<ChatResumeProbe>;
|
|
29
|
+
joinUrl: () => string;
|
|
30
|
+
sendUrl: string;
|
|
31
|
+
fetchClient: typeof fetch;
|
|
32
|
+
onReconnectChange: (reconnecting: boolean) => void;
|
|
33
|
+
onTranscript: () => void;
|
|
34
|
+
onError: (error: ChatReconnectError) => void;
|
|
35
|
+
random?: () => number;
|
|
36
|
+
now?: () => number;
|
|
37
|
+
wait?: typeof waitForReconnect;
|
|
38
|
+
};
|
|
39
|
+
/** Shared by hosts: cache no legal text or run pointer on the device. The
|
|
40
|
+
* SDK's persistence contract restores its run from the authenticated server. */
|
|
41
|
+
export declare const createDurableChatTransport: <TMessages extends UIMessage[]>({ initialMessages, initialTurn, threadId, probe, joinUrl, sendUrl, fetchClient, onReconnectChange, onTranscript, onError, random, now, wait }: DurableChatTransportOptions<TMessages>) => {
|
|
42
|
+
connection: {
|
|
43
|
+
connect(messages: UIMessage$1<unknown>[] | ModelMessage<string | ContentPart<unknown, unknown, unknown, unknown, unknown>[] | null>[], data?: Record<string, any> | undefined, abortSignal?: AbortSignal | undefined, runContext?: import("@tanstack/ai-client").RunAgentInputContext | undefined): AsyncGenerator<AGUIEvent, void, unknown>;
|
|
44
|
+
joinRun(runId: string, signal?: AbortSignal): AsyncGenerator<ActivitySnapshotEvent$1 | ActivityDeltaEvent$1 | RawEvent$1 | TextMessageChunkEvent$1 | ToolCallChunkEvent$1 | ReasoningMessageChunkEvent$1 | RunStartedEvent$1 | RunFinishedEvent$1 | RunErrorEvent$1 | TextMessageStartEvent$1 | TextMessageContentEvent$1 | TextMessageEndEvent$1 | ToolCallStartEvent$1 | ToolCallArgsEvent$1 | ToolCallEndEvent$1 | ToolCallResultEvent$1 | StepStartedEvent$1 | StepFinishedEvent$1 | MessagesSnapshotEvent$1 | StateSnapshotEvent$1 | StateDeltaEvent$1 | CustomEvent$1 | ReasoningStartEvent$1 | ReasoningMessageStartEvent$1 | ReasoningMessageContentEvent$1 | ReasoningMessageEndEvent$1 | ReasoningEndEvent$1 | ReasoningEncryptedValueEvent$1 | SubagentStartedEvent$1 | SubagentFinishedEvent$1 | SubagentErrorEvent$1 | {
|
|
45
|
+
readonly type: EventType.CUSTOM;
|
|
46
|
+
readonly name: "stella.chat.rejoin-attached";
|
|
47
|
+
readonly value: {
|
|
48
|
+
readonly runId: string;
|
|
49
|
+
readonly threadId: string;
|
|
50
|
+
};
|
|
51
|
+
}, void, unknown>;
|
|
52
|
+
};
|
|
53
|
+
persistence: {
|
|
54
|
+
getItem: (resumedThreadId: string) => Promise<{
|
|
55
|
+
resume?: {
|
|
56
|
+
resumeState: {
|
|
57
|
+
threadId: string;
|
|
58
|
+
runId: string;
|
|
59
|
+
};
|
|
60
|
+
pendingInterrupts?: import("@ag-ui/core").Interrupt[];
|
|
61
|
+
};
|
|
62
|
+
messages: TMessages;
|
|
63
|
+
} | undefined>;
|
|
64
|
+
setItem: () => undefined;
|
|
65
|
+
removeItem: () => undefined;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { chatTurnResumeProbeSchema } from "./resume-contract.js";
|
|
2
|
+
import { Result, TaggedError, panic } from "better-result";
|
|
3
|
+
import { EventType } from "@ag-ui/core";
|
|
4
|
+
import { fetchServerSentEvents } from "@tanstack/ai-client";
|
|
5
|
+
import * as v from "valibot";
|
|
6
|
+
//#region src/durable-transport.ts
|
|
7
|
+
var ChatReconnectError = class extends TaggedError("ChatReconnectError") {};
|
|
8
|
+
const RECONNECT_WINDOW_MS = 18e4;
|
|
9
|
+
const MAX_RECONNECT_DELAY_MS = 15e3;
|
|
10
|
+
const REJOIN_ATTACHED_EVENT = "stella.chat.rejoin-attached";
|
|
11
|
+
const reconnectDelay = ({ attempt, jitter }) => Math.min(MAX_RECONNECT_DELAY_MS, 500 * 2 ** Math.min(attempt, 8)) * (.5 + jitter * .5);
|
|
12
|
+
const waitForReconnect = async (delay, signal) => await new Promise((resolve, reject) => {
|
|
13
|
+
if (signal?.aborted) {
|
|
14
|
+
reject(new ChatReconnectError({
|
|
15
|
+
message: "Chat reconnect aborted.",
|
|
16
|
+
cause: signal.reason
|
|
17
|
+
}));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const abort = () => {
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
reject(new ChatReconnectError({
|
|
23
|
+
message: "Chat reconnect aborted.",
|
|
24
|
+
cause: signal?.reason
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
const timer = setTimeout(() => {
|
|
28
|
+
signal?.removeEventListener("abort", abort);
|
|
29
|
+
resolve();
|
|
30
|
+
}, delay);
|
|
31
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
32
|
+
});
|
|
33
|
+
const loadedTurnNeedsRefresh = (loaded, transcript) => {
|
|
34
|
+
switch (loaded.type) {
|
|
35
|
+
case "active": return true;
|
|
36
|
+
case "parked": return transcript.resumeSnapshot?.resumeState.runId !== loaded.runId;
|
|
37
|
+
case "settled": return false;
|
|
38
|
+
default: return panic(loaded);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const terminalChatResponse = ({ runId, resume, onTranscript, onReconnectChange }) => {
|
|
42
|
+
onTranscript();
|
|
43
|
+
onReconnectChange(false);
|
|
44
|
+
return new Response(`data: ${JSON.stringify({
|
|
45
|
+
type: "RUN_FINISHED",
|
|
46
|
+
runId,
|
|
47
|
+
...resume?.pendingInterrupts === void 0 ? {} : { outcome: {
|
|
48
|
+
type: "interrupt",
|
|
49
|
+
interrupts: resume.pendingInterrupts
|
|
50
|
+
} }
|
|
51
|
+
})}\n\n`, { headers: { "Content-Type": "text/event-stream" } });
|
|
52
|
+
};
|
|
53
|
+
const createChatResumePersistence = ({ initialMessages, initialTurn, probe, onReconnectChange, onTranscript, onError, random, now, wait }) => {
|
|
54
|
+
let initialTurnState = initialTurn;
|
|
55
|
+
return {
|
|
56
|
+
getItem: async (resumedThreadId) => {
|
|
57
|
+
const began = now();
|
|
58
|
+
let retries = 0;
|
|
59
|
+
while (now() - began < RECONNECT_WINDOW_MS) {
|
|
60
|
+
const result = await Result.tryPromise(async () => await probe());
|
|
61
|
+
if (Result.isError(result) && result.error.cause instanceof ChatReconnectError && result.error.cause.code !== void 0) {
|
|
62
|
+
onReconnectChange(false);
|
|
63
|
+
onError(result.error.cause);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (Result.isOk(result)) switch (result.value.type) {
|
|
67
|
+
case "running": return {
|
|
68
|
+
messages: initialMessages,
|
|
69
|
+
resume: { resumeState: {
|
|
70
|
+
threadId: resumedThreadId,
|
|
71
|
+
runId: result.value.runId
|
|
72
|
+
} }
|
|
73
|
+
};
|
|
74
|
+
case "transcript":
|
|
75
|
+
if (loadedTurnNeedsRefresh(initialTurnState, result.value)) {
|
|
76
|
+
initialTurnState = { type: "settled" };
|
|
77
|
+
onTranscript();
|
|
78
|
+
}
|
|
79
|
+
onReconnectChange(false);
|
|
80
|
+
return {
|
|
81
|
+
messages: initialMessages,
|
|
82
|
+
...result.value.resumeSnapshot === void 0 ? {} : { resume: result.value.resumeSnapshot }
|
|
83
|
+
};
|
|
84
|
+
case "preparing": break;
|
|
85
|
+
default: return panic(result.value);
|
|
86
|
+
}
|
|
87
|
+
onReconnectChange(true);
|
|
88
|
+
await wait(reconnectDelay({
|
|
89
|
+
attempt: retries,
|
|
90
|
+
jitter: random()
|
|
91
|
+
}), void 0);
|
|
92
|
+
retries += 1;
|
|
93
|
+
}
|
|
94
|
+
onReconnectChange(false);
|
|
95
|
+
onError(new ChatReconnectError({ message: "Chat resume timed out." }));
|
|
96
|
+
},
|
|
97
|
+
setItem: () => void 0,
|
|
98
|
+
removeItem: () => void 0
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/** Shared by hosts: cache no legal text or run pointer on the device. The
|
|
102
|
+
* SDK's persistence contract restores its run from the authenticated server. */
|
|
103
|
+
const createDurableChatTransport = ({ initialMessages, initialTurn, threadId, probe, joinUrl, sendUrl, fetchClient, onReconnectChange, onTranscript, onError, random = Math.random, now = () => performance.now(), wait = waitForReconnect }) => {
|
|
104
|
+
let reconnectStartedAt;
|
|
105
|
+
let attempt = 0;
|
|
106
|
+
const resumableFetch = Object.assign(async (input, init) => {
|
|
107
|
+
const headers = new Headers(init?.headers);
|
|
108
|
+
if (!(init?.method === "GET" || headers.has("Last-Event-ID"))) {
|
|
109
|
+
reconnectStartedAt = void 0;
|
|
110
|
+
attempt = 0;
|
|
111
|
+
return await fetchClient(input, init);
|
|
112
|
+
}
|
|
113
|
+
const source = new URL(input instanceof Request ? input.url : String(input));
|
|
114
|
+
const runId = source.searchParams.get("runId") ?? headers.get("X-Run-Id") ?? "";
|
|
115
|
+
onReconnectChange(true);
|
|
116
|
+
reconnectStartedAt ??= now();
|
|
117
|
+
while (!init?.signal?.aborted) {
|
|
118
|
+
if (now() - reconnectStartedAt >= RECONNECT_WINDOW_MS) throw new ChatReconnectError({ message: "Chat reconnection timed out." });
|
|
119
|
+
if (attempt > 0) await wait(reconnectDelay({
|
|
120
|
+
attempt: attempt - 1,
|
|
121
|
+
jitter: random()
|
|
122
|
+
}), init?.signal);
|
|
123
|
+
attempt += 1;
|
|
124
|
+
const result = await Result.tryPromise(async () => {
|
|
125
|
+
const state = await probe(init?.signal);
|
|
126
|
+
switch (state.type) {
|
|
127
|
+
case "transcript": return terminalChatResponse({
|
|
128
|
+
runId,
|
|
129
|
+
resume: state.resumeSnapshot,
|
|
130
|
+
onTranscript,
|
|
131
|
+
onReconnectChange
|
|
132
|
+
});
|
|
133
|
+
case "preparing": return;
|
|
134
|
+
case "running":
|
|
135
|
+
if (state.runId !== runId) return terminalChatResponse({
|
|
136
|
+
runId,
|
|
137
|
+
onTranscript,
|
|
138
|
+
onReconnectChange
|
|
139
|
+
});
|
|
140
|
+
break;
|
|
141
|
+
default: return panic(state);
|
|
142
|
+
}
|
|
143
|
+
const target = new URL(joinUrl());
|
|
144
|
+
target.searchParams.set("runId", runId);
|
|
145
|
+
target.searchParams.set("lastEventId", source.searchParams.get("offset") ?? "-1");
|
|
146
|
+
const response = await fetchClient(target, {
|
|
147
|
+
...init,
|
|
148
|
+
method: "GET",
|
|
149
|
+
body: null
|
|
150
|
+
});
|
|
151
|
+
if (!response.ok) {
|
|
152
|
+
const message = `Chat rejoin failed (${response.status}).`;
|
|
153
|
+
throw response.status === 401 || response.status === 403 || response.status === 404 ? new ChatReconnectError({
|
|
154
|
+
code: "refused",
|
|
155
|
+
message
|
|
156
|
+
}) : new ChatReconnectError({ message });
|
|
157
|
+
}
|
|
158
|
+
if (response.headers.get("Content-Type")?.includes("application/json")) {
|
|
159
|
+
const body = await response.json();
|
|
160
|
+
const parsed = v.safeParse(chatTurnResumeProbeSchema, body);
|
|
161
|
+
if (!parsed.success || parsed.output.type === "running") throw new ChatReconnectError({
|
|
162
|
+
code: "invalid-response",
|
|
163
|
+
message: "Invalid chat rejoin response."
|
|
164
|
+
});
|
|
165
|
+
switch (parsed.output.type) {
|
|
166
|
+
case "preparing": return;
|
|
167
|
+
case "transcript": return terminalChatResponse({
|
|
168
|
+
runId,
|
|
169
|
+
resume: parsed.output.resumeSnapshot,
|
|
170
|
+
onTranscript,
|
|
171
|
+
onReconnectChange
|
|
172
|
+
});
|
|
173
|
+
default: return panic(parsed.output);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
onReconnectChange(false);
|
|
177
|
+
return response;
|
|
178
|
+
});
|
|
179
|
+
if (Result.isOk(result) && result.value !== void 0) return result.value;
|
|
180
|
+
if (Result.isError(result) && result.error.cause instanceof ChatReconnectError && result.error.cause.code !== void 0) {
|
|
181
|
+
onError(result.error.cause);
|
|
182
|
+
return new Response(null, { status: 502 });
|
|
183
|
+
}
|
|
184
|
+
if (init?.signal?.aborted) throw init.signal.reason;
|
|
185
|
+
}
|
|
186
|
+
throw init.signal.reason;
|
|
187
|
+
}, { preconnect: () => void 0 });
|
|
188
|
+
const persistence = createChatResumePersistence({
|
|
189
|
+
initialMessages,
|
|
190
|
+
initialTurn,
|
|
191
|
+
probe,
|
|
192
|
+
onReconnectChange,
|
|
193
|
+
onTranscript,
|
|
194
|
+
onError,
|
|
195
|
+
random,
|
|
196
|
+
now,
|
|
197
|
+
wait
|
|
198
|
+
});
|
|
199
|
+
const upstream = fetchServerSentEvents(sendUrl, {
|
|
200
|
+
credentials: "include",
|
|
201
|
+
headers: { "Content-Type": "application/json" },
|
|
202
|
+
fetchClient: resumableFetch,
|
|
203
|
+
reconnect: {
|
|
204
|
+
delayMs: 0,
|
|
205
|
+
maxAttempts: 100
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
const progress = () => {
|
|
209
|
+
reconnectStartedAt = void 0;
|
|
210
|
+
attempt = 0;
|
|
211
|
+
};
|
|
212
|
+
return {
|
|
213
|
+
connection: {
|
|
214
|
+
async *connect(...args) {
|
|
215
|
+
for await (const chunk of upstream.connect(...args)) {
|
|
216
|
+
progress();
|
|
217
|
+
yield chunk;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
async *joinRun(runId, signal) {
|
|
221
|
+
yield {
|
|
222
|
+
type: EventType.CUSTOM,
|
|
223
|
+
name: REJOIN_ATTACHED_EVENT,
|
|
224
|
+
value: {
|
|
225
|
+
runId,
|
|
226
|
+
threadId
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
for await (const chunk of upstream.joinRun(runId, signal)) {
|
|
230
|
+
progress();
|
|
231
|
+
yield chunk;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
persistence
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
//#endregion
|
|
239
|
+
export { ChatReconnectError, createDurableChatTransport };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Interrupt } from "@ag-ui/core";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
//#region src/resume-contract.d.ts
|
|
4
|
+
/** Keep native interrupt validation tied to the protocol's owning schema. */
|
|
5
|
+
export declare const chatResumeSnapshotSchema: v.ObjectSchema<{
|
|
6
|
+
readonly resumeState: v.ObjectSchema<{
|
|
7
|
+
readonly threadId: v.StringSchema<undefined>;
|
|
8
|
+
readonly runId: v.StringSchema<undefined>;
|
|
9
|
+
}, undefined>;
|
|
10
|
+
readonly pendingInterrupts: v.ExactOptionalSchema<v.ArraySchema<v.CustomSchema<Interrupt, undefined>, undefined>, undefined>;
|
|
11
|
+
}, undefined>;
|
|
12
|
+
/** Server truth for reconnecting readers; no local pointer establishes ownership. */
|
|
13
|
+
export declare const chatTurnResumeProbeSchema: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
14
|
+
readonly type: v.LiteralSchema<"preparing", undefined>;
|
|
15
|
+
readonly turnId: v.StringSchema<undefined>;
|
|
16
|
+
}, undefined>, v.ObjectSchema<{
|
|
17
|
+
readonly type: v.LiteralSchema<"running", undefined>;
|
|
18
|
+
readonly turnId: v.StringSchema<undefined>;
|
|
19
|
+
readonly runId: v.StringSchema<undefined>;
|
|
20
|
+
}, undefined>, v.ObjectSchema<{
|
|
21
|
+
readonly type: v.LiteralSchema<"transcript", undefined>;
|
|
22
|
+
readonly turnId: v.StringSchema<undefined>;
|
|
23
|
+
readonly resumeSnapshot: v.ExactOptionalSchema<v.ObjectSchema<{
|
|
24
|
+
readonly resumeState: v.ObjectSchema<{
|
|
25
|
+
readonly threadId: v.StringSchema<undefined>;
|
|
26
|
+
readonly runId: v.StringSchema<undefined>;
|
|
27
|
+
}, undefined>;
|
|
28
|
+
readonly pendingInterrupts: v.ExactOptionalSchema<v.ArraySchema<v.CustomSchema<Interrupt, undefined>, undefined>, undefined>;
|
|
29
|
+
}, undefined>, undefined>;
|
|
30
|
+
}, undefined>], undefined>;
|
|
31
|
+
export type ChatTurnResumeProbe = v.InferOutput<typeof chatTurnResumeProbeSchema>;
|
|
32
|
+
//#endregion
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { InterruptSchema } from "@ag-ui/core/schemas";
|
|
3
|
+
//#region src/resume-contract.ts
|
|
4
|
+
/** Keep native interrupt validation tied to the protocol's owning schema. */
|
|
5
|
+
const chatResumeSnapshotSchema = v.object({
|
|
6
|
+
resumeState: v.object({
|
|
7
|
+
threadId: v.string(),
|
|
8
|
+
runId: v.string()
|
|
9
|
+
}),
|
|
10
|
+
pendingInterrupts: v.exactOptional(v.array(v.custom((value) => InterruptSchema.safeParse(value).success)))
|
|
11
|
+
});
|
|
12
|
+
/** Server truth for reconnecting readers; no local pointer establishes ownership. */
|
|
13
|
+
const chatTurnResumeProbeSchema = v.variant("type", [
|
|
14
|
+
v.object({
|
|
15
|
+
type: v.literal("preparing"),
|
|
16
|
+
turnId: v.string()
|
|
17
|
+
}),
|
|
18
|
+
v.object({
|
|
19
|
+
type: v.literal("running"),
|
|
20
|
+
turnId: v.string(),
|
|
21
|
+
runId: v.string()
|
|
22
|
+
}),
|
|
23
|
+
v.object({
|
|
24
|
+
type: v.literal("transcript"),
|
|
25
|
+
turnId: v.string(),
|
|
26
|
+
resumeSnapshot: v.exactOptional(chatResumeSnapshotSchema)
|
|
27
|
+
})
|
|
28
|
+
]);
|
|
29
|
+
//#endregion
|
|
30
|
+
export { chatResumeSnapshotSchema, chatTurnResumeProbeSchema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../../types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./middleware/run-store.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "../../types.js";
|
|
2
|
+
import "./adapter.js";
|
|
3
|
+
import "../../interrupt-definition.js";
|
|
4
|
+
import "./agents/define-agent.js";
|
|
5
|
+
import "./middleware/types.js";
|
|
6
|
+
import "./agents/spawn.js";
|
|
7
|
+
import "./middleware/builder.js";
|
|
8
|
+
import "./runtime-context-types.js";
|
|
9
|
+
import "./mcp/types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../tools/tool-definition.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../../interrupt-definition.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../../types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./middleware/types.js";
|