@providerprotocol/ai 0.0.35 → 0.0.36
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 +17 -13
- package/dist/anthropic/index.d.ts +2 -2
- package/dist/anthropic/index.js +1 -1
- package/dist/cerebras/index.d.ts +2 -2
- package/dist/cerebras/index.js +1 -1
- package/dist/{chunk-7DXVRILR.js → chunk-2YXFLRQ6.js} +2 -2
- package/dist/chunk-2YXFLRQ6.js.map +1 -0
- package/dist/{chunk-HB4ZIH3T.js → chunk-4RX4VQCB.js} +2 -2
- package/dist/chunk-4RX4VQCB.js.map +1 -0
- package/dist/{chunk-ZI67WIQS.js → chunk-5IWHCXKN.js} +2 -2
- package/dist/chunk-5IWHCXKN.js.map +1 -0
- package/dist/{chunk-VOEWHQUB.js → chunk-CRP6Y7NF.js} +2 -2
- package/dist/chunk-CRP6Y7NF.js.map +1 -0
- package/dist/{chunk-3GWM5GR3.js → chunk-EPB3GQNL.js} +30 -65
- package/dist/chunk-EPB3GQNL.js.map +1 -0
- package/dist/{chunk-6S222DHN.js → chunk-RJGTRQ47.js} +20 -1
- package/dist/chunk-RJGTRQ47.js.map +1 -0
- package/dist/{embedding-CW6SaOOz.d.ts → embedding-BXA72PlJ.d.ts} +1 -1
- package/dist/google/index.d.ts +2 -2
- package/dist/google/index.js +1 -1
- package/dist/groq/index.d.ts +2 -2
- package/dist/groq/index.js +1 -1
- package/dist/http/index.d.ts +3 -3
- package/dist/{image-stream-C0ciACM2.d.ts → image-stream-CCgwB7ve.d.ts} +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -1
- package/dist/{llm-DwbUK7un.d.ts → llm-ByUFPcFH.d.ts} +1 -1
- package/dist/middleware/logging/index.d.ts +2 -2
- package/dist/middleware/parsed-object/index.d.ts +2 -2
- package/dist/middleware/parsed-object/index.js +1 -1
- package/dist/middleware/pubsub/index.d.ts +27 -34
- package/dist/middleware/pubsub/index.js +49 -119
- package/dist/middleware/pubsub/index.js.map +1 -1
- package/dist/middleware/pubsub/server/express/index.d.ts +24 -10
- package/dist/middleware/pubsub/server/express/index.js +2 -2
- package/dist/middleware/pubsub/server/fastify/index.d.ts +24 -10
- package/dist/middleware/pubsub/server/fastify/index.js +2 -2
- package/dist/middleware/pubsub/server/h3/index.d.ts +23 -9
- package/dist/middleware/pubsub/server/h3/index.js +2 -2
- package/dist/middleware/pubsub/server/index.d.ts +2 -2
- package/dist/middleware/pubsub/server/index.js +5 -5
- package/dist/middleware/pubsub/server/webapi/index.d.ts +23 -13
- package/dist/middleware/pubsub/server/webapi/index.js +2 -2
- package/dist/ollama/index.d.ts +2 -2
- package/dist/ollama/index.js +1 -1
- package/dist/openai/index.d.ts +2 -2
- package/dist/openai/index.js +1 -1
- package/dist/openrouter/index.d.ts +2 -2
- package/dist/openrouter/index.js +1 -1
- package/dist/proxy/index.d.ts +4 -4
- package/dist/proxy/index.js +1 -1
- package/dist/proxy/server/express/index.d.ts +4 -4
- package/dist/proxy/server/fastify/index.d.ts +4 -4
- package/dist/proxy/server/h3/index.d.ts +4 -4
- package/dist/proxy/server/index.d.ts +4 -4
- package/dist/proxy/server/webapi/index.d.ts +4 -4
- package/dist/responses/index.d.ts +2 -2
- package/dist/responses/index.js +1 -1
- package/dist/{retry-YayV42GV.d.ts → retry-BDMo4AVu.d.ts} +1 -1
- package/dist/{stream-CecfVCPO.d.ts → stream-S7nwQRqM.d.ts} +17 -6
- package/dist/types-CE4B7pno.d.ts +96 -0
- package/dist/xai/index.d.ts +2 -2
- package/dist/xai/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3GWM5GR3.js.map +0 -1
- package/dist/chunk-6S222DHN.js.map +0 -1
- package/dist/chunk-7DXVRILR.js.map +0 -1
- package/dist/chunk-HB4ZIH3T.js.map +0 -1
- package/dist/chunk-VOEWHQUB.js.map +0 -1
- package/dist/chunk-ZI67WIQS.js.map +0 -1
- package/dist/types-C8Gciizr.d.ts +0 -168
package/README.md
CHANGED
|
@@ -47,6 +47,12 @@ for await (const event of stream) {
|
|
|
47
47
|
const turn = await stream.turn;
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
Stream results are PromiseLike, so you can also await the stream directly to auto-drain:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const turn = await claude.stream('Count to 5');
|
|
54
|
+
```
|
|
55
|
+
|
|
50
56
|
**Stream Control:**
|
|
51
57
|
|
|
52
58
|
```typescript
|
|
@@ -642,7 +648,9 @@ const result = await model.generate('Hello');
|
|
|
642
648
|
|
|
643
649
|
### Pub-Sub Middleware (Stream Resumption)
|
|
644
650
|
|
|
645
|
-
Enable reconnecting clients to catch up on missed events during active generation. The middleware buffers events
|
|
651
|
+
Enable reconnecting clients to catch up on missed events during active generation. The middleware buffers events, publishes them to subscribers, and removes streams on completion/abort/error.
|
|
652
|
+
If a stream never reaches those hooks (for example, a process crash), the adapter may retain the entry. Custom adapters should invoke `onComplete` when `remove()` runs so subscriber streams can terminate.
|
|
653
|
+
Streams are created lazily on first `append()` or `subscribe()` call.
|
|
646
654
|
|
|
647
655
|
```typescript
|
|
648
656
|
import { llm } from '@providerprotocol/ai';
|
|
@@ -662,11 +670,12 @@ Bun.serve({
|
|
|
662
670
|
|
|
663
671
|
if (!exists) {
|
|
664
672
|
// Start background generation (fire and forget)
|
|
673
|
+
// Stream is created lazily on first append()
|
|
665
674
|
const model = llm({
|
|
666
675
|
model: anthropic('claude-sonnet-4-20250514'),
|
|
667
676
|
middleware: [pubsubMiddleware({ adapter, streamId })],
|
|
668
677
|
});
|
|
669
|
-
|
|
678
|
+
model.stream(messages).then(turn => { /* save to DB */ });
|
|
670
679
|
}
|
|
671
680
|
|
|
672
681
|
// Both new and reconnect: subscribe to events
|
|
@@ -710,17 +719,12 @@ Implement `PubSubAdapter` for custom backends (Redis, etc.):
|
|
|
710
719
|
import type { PubSubAdapter } from '@providerprotocol/ai/middleware/pubsub';
|
|
711
720
|
|
|
712
721
|
const redisAdapter: PubSubAdapter = {
|
|
713
|
-
async exists(streamId) { /*
|
|
714
|
-
async
|
|
715
|
-
async
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
async
|
|
719
|
-
async getStream(streamId) { /* ... */ },
|
|
720
|
-
subscribe(streamId, callback) { /* ... */ },
|
|
721
|
-
publish(streamId, event) { /* ... */ },
|
|
722
|
-
async remove(streamId) { /* ... */ },
|
|
723
|
-
async cleanup(maxAge) { /* ... */ },
|
|
722
|
+
async exists(streamId) { /* check if stream exists */ },
|
|
723
|
+
async append(streamId, event) { /* append event, create lazily */ },
|
|
724
|
+
async getEvents(streamId) { /* return events or [] */ },
|
|
725
|
+
subscribe(streamId, onEvent, onComplete) { /* subscribe to live events */ },
|
|
726
|
+
publish(streamId, event) { /* broadcast to subscribers */ },
|
|
727
|
+
async remove(streamId) { /* notify onComplete then delete */ },
|
|
724
728
|
};
|
|
725
729
|
```
|
|
726
730
|
|
package/dist/anthropic/index.js
CHANGED
package/dist/cerebras/index.d.ts
CHANGED
package/dist/cerebras/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runSubscriberStream
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EPB3GQNL.js";
|
|
4
4
|
|
|
5
5
|
// src/middleware/pubsub/server/webapi.ts
|
|
6
6
|
function createSubscriberStream(streamId, adapter) {
|
|
@@ -46,4 +46,4 @@ export {
|
|
|
46
46
|
createSubscriberStream,
|
|
47
47
|
webapi
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-2YXFLRQ6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware/pubsub/server/webapi.ts"],"sourcesContent":["/**\n * @fileoverview Web API adapter for pub-sub stream resumption.\n *\n * Provides utilities for Web API native frameworks (Bun, Deno, Next.js App Router,\n * Cloudflare Workers) to handle stream reconnections.\n *\n * @module middleware/pubsub/server/webapi\n */\n\nimport type { PubSubAdapter } from '../types.ts';\nimport { runSubscriberStream } from './shared.ts';\n\n/**\n * Creates a ReadableStream that replays buffered events and subscribes to live events.\n *\n * Handles reconnection for Web API frameworks (Bun, Deno, Next.js, Cloudflare Workers):\n * 1. Replays buffered events from the adapter\n * 2. Subscribes to live events until completion signal\n * 3. Closes when stream completes or client disconnects\n *\n * @param streamId - The stream ID to subscribe to\n * @param adapter - The pub-sub adapter instance\n * @returns A ReadableStream of SSE-formatted data\n *\n * @example\n * ```typescript\n * import { llm } from '@providerprotocol/ai';\n * import { anthropic } from '@providerprotocol/ai/anthropic';\n * import { pubsubMiddleware, memoryAdapter } from '@providerprotocol/ai/middleware/pubsub';\n * import { webapi } from '@providerprotocol/ai/middleware/pubsub/server';\n *\n * const adapter = memoryAdapter();\n *\n * // Next.js App Router / Bun.serve / Deno.serve\n * export async function POST(req: Request) {\n * const { input, conversationId } = await req.json();\n *\n * if (!await adapter.exists(conversationId)) {\n * const model = llm({\n * model: anthropic('claude-sonnet-4-20250514'),\n * middleware: [pubsubMiddleware({ adapter, streamId: conversationId })],\n * });\n * model.stream(input).then(turn => saveToDatabase(conversationId, turn));\n * }\n *\n * return new Response(webapi.createSubscriberStream(conversationId, adapter), {\n * headers: {\n * 'Content-Type': 'text/event-stream',\n * 'Cache-Control': 'no-cache',\n * },\n * });\n * }\n * ```\n */\nexport function createSubscriberStream(\n streamId: string,\n adapter: PubSubAdapter\n): ReadableStream<Uint8Array> {\n const encoder = new TextEncoder();\n const abortController = new AbortController();\n let closed = false;\n\n return new ReadableStream({\n async start(controller) {\n await runSubscriberStream(\n streamId,\n adapter,\n {\n write: (data: string) => {\n if (closed) {\n return;\n }\n controller.enqueue(encoder.encode(data));\n },\n end: () => {\n if (closed) {\n return;\n }\n closed = true;\n try {\n controller.close();\n } catch {\n // Ignore close errors after cancellation\n }\n },\n },\n { signal: abortController.signal }\n );\n },\n cancel() {\n abortController.abort();\n },\n });\n}\n\n/**\n * Web API adapter namespace for pub-sub server utilities.\n */\nexport const webapi = {\n createSubscriberStream,\n};\n"],"mappings":";;;;;AAsDO,SAAS,uBACd,UACA,SAC4B;AAC5B,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,kBAAkB,IAAI,gBAAgB;AAC5C,MAAI,SAAS;AAEb,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM,MAAM,YAAY;AACtB,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,UACE,OAAO,CAAC,SAAiB;AACvB,gBAAI,QAAQ;AACV;AAAA,YACF;AACA,uBAAW,QAAQ,QAAQ,OAAO,IAAI,CAAC;AAAA,UACzC;AAAA,UACA,KAAK,MAAM;AACT,gBAAI,QAAQ;AACV;AAAA,YACF;AACA,qBAAS;AACT,gBAAI;AACF,yBAAW,MAAM;AAAA,YACnB,QAAQ;AAAA,YAER;AAAA,UACF;AAAA,QACF;AAAA,QACA,EAAE,QAAQ,gBAAgB,OAAO;AAAA,MACnC;AAAA,IACF;AAAA,IACA,SAAS;AACP,sBAAgB,MAAM;AAAA,IACxB;AAAA,EACF,CAAC;AACH;AAKO,IAAM,SAAS;AAAA,EACpB;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runSubscriberStream
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EPB3GQNL.js";
|
|
4
4
|
|
|
5
5
|
// src/middleware/pubsub/server/h3.ts
|
|
6
6
|
async function streamSubscriber(streamId, adapter, event) {
|
|
@@ -28,4 +28,4 @@ export {
|
|
|
28
28
|
streamSubscriber,
|
|
29
29
|
h3
|
|
30
30
|
};
|
|
31
|
-
//# sourceMappingURL=chunk-
|
|
31
|
+
//# sourceMappingURL=chunk-4RX4VQCB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware/pubsub/server/h3.ts"],"sourcesContent":["/**\n * @fileoverview H3/Nitro/Nuxt adapter for pub-sub stream resumption.\n *\n * Provides utilities for H3-based servers (Nuxt, Nitro, or standalone H3)\n * to handle stream reconnections.\n *\n * @module middleware/pubsub/server/h3\n */\n\nimport type { PubSubAdapter } from '../types.ts';\nimport { runSubscriberStream } from './shared.ts';\n\n/**\n * H3 Event interface (minimal type to avoid dependency).\n */\ninterface H3Event {\n node: {\n res: {\n setHeader(name: string, value: string): void;\n write(chunk: string): boolean;\n end(): void;\n on(event: 'close', listener: () => void): void;\n };\n };\n}\n\n/**\n * Stream buffered and live events to an H3 event response.\n *\n * Handles reconnection for H3/Nuxt routes:\n * 1. Replays buffered events from the adapter\n * 2. Subscribes to live events until completion signal\n * 3. Ends when stream completes or client disconnects\n *\n * @param streamId - The stream ID to subscribe to\n * @param adapter - The pub-sub adapter instance\n * @param event - H3 event object\n *\n * @example\n * ```typescript\n * import { llm } from '@providerprotocol/ai';\n * import { anthropic } from '@providerprotocol/ai/anthropic';\n * import { pubsubMiddleware, memoryAdapter } from '@providerprotocol/ai/middleware/pubsub';\n * import { h3 } from '@providerprotocol/ai/middleware/pubsub/server';\n *\n * const adapter = memoryAdapter();\n *\n * export default defineEventHandler(async (event) => {\n * const { input, conversationId } = await readBody(event);\n *\n * if (!await adapter.exists(conversationId)) {\n * const model = llm({\n * model: anthropic('claude-sonnet-4-20250514'),\n * middleware: [pubsubMiddleware({ adapter, streamId: conversationId })],\n * });\n * model.stream(input).then(turn => saveToDatabase(conversationId, turn));\n * }\n *\n * return h3.streamSubscriber(conversationId, adapter, event);\n * });\n * ```\n */\nexport async function streamSubscriber(\n streamId: string,\n adapter: PubSubAdapter,\n event: H3Event\n): Promise<void> {\n const res = event.node.res;\n res.setHeader('Content-Type', 'text/event-stream');\n res.setHeader('Cache-Control', 'no-cache');\n res.setHeader('Connection', 'keep-alive');\n\n const abortController = new AbortController();\n res.on('close', () => abortController.abort());\n\n await runSubscriberStream(\n streamId,\n adapter,\n {\n write: (data: string) => res.write(data),\n end: () => res.end(),\n },\n { signal: abortController.signal }\n );\n}\n\n/**\n * H3 adapter namespace for pub-sub server utilities.\n */\nexport const h3 = {\n streamSubscriber,\n};\n"],"mappings":";;;;;AA8DA,eAAsB,iBACpB,UACA,SACA,OACe;AACf,QAAM,MAAM,MAAM,KAAK;AACvB,MAAI,UAAU,gBAAgB,mBAAmB;AACjD,MAAI,UAAU,iBAAiB,UAAU;AACzC,MAAI,UAAU,cAAc,YAAY;AAExC,QAAM,kBAAkB,IAAI,gBAAgB;AAC5C,MAAI,GAAG,SAAS,MAAM,gBAAgB,MAAM,CAAC;AAE7C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,MACE,OAAO,CAAC,SAAiB,IAAI,MAAM,IAAI;AAAA,MACvC,KAAK,MAAM,IAAI,IAAI;AAAA,IACrB;AAAA,IACA,EAAE,QAAQ,gBAAgB,OAAO;AAAA,EACnC;AACF;AAKO,IAAM,KAAK;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runSubscriberStream
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EPB3GQNL.js";
|
|
4
4
|
|
|
5
5
|
// src/middleware/pubsub/server/express.ts
|
|
6
6
|
async function streamSubscriber(streamId, adapter, res) {
|
|
@@ -27,4 +27,4 @@ export {
|
|
|
27
27
|
streamSubscriber,
|
|
28
28
|
express
|
|
29
29
|
};
|
|
30
|
-
//# sourceMappingURL=chunk-
|
|
30
|
+
//# sourceMappingURL=chunk-5IWHCXKN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware/pubsub/server/express.ts"],"sourcesContent":["/**\n * @fileoverview Express/Connect adapter for pub-sub stream resumption.\n *\n * Provides utilities for Express.js or Connect-based servers\n * to handle stream reconnections.\n *\n * @module middleware/pubsub/server/express\n */\n\nimport type { PubSubAdapter } from '../types.ts';\nimport { runSubscriberStream } from './shared.ts';\n\n/**\n * Express Response interface (minimal type to avoid dependency).\n */\ninterface ExpressResponse {\n setHeader(name: string, value: string): void;\n write(chunk: string): boolean;\n end(): void;\n on(event: 'close', listener: () => void): void;\n}\n\n/**\n * Stream buffered and live events to an Express response.\n *\n * Handles reconnection for Express routes:\n * 1. Replays buffered events from the adapter\n * 2. Subscribes to live events until completion signal\n * 3. Ends when stream completes or client disconnects\n *\n * @param streamId - The stream ID to subscribe to\n * @param adapter - The pub-sub adapter instance\n * @param res - Express response object\n *\n * @example\n * ```typescript\n * import { llm } from '@providerprotocol/ai';\n * import { anthropic } from '@providerprotocol/ai/anthropic';\n * import { pubsubMiddleware, memoryAdapter } from '@providerprotocol/ai/middleware/pubsub';\n * import { express } from '@providerprotocol/ai/middleware/pubsub/server';\n *\n * const adapter = memoryAdapter();\n *\n * app.post('/api/chat', async (req, res) => {\n * const { input, conversationId } = req.body;\n *\n * if (!await adapter.exists(conversationId)) {\n * const model = llm({\n * model: anthropic('claude-sonnet-4-20250514'),\n * middleware: [pubsubMiddleware({ adapter, streamId: conversationId })],\n * });\n * model.stream(input).then(turn => saveToDatabase(conversationId, turn));\n * }\n *\n * return express.streamSubscriber(conversationId, adapter, res);\n * });\n * ```\n */\nexport async function streamSubscriber(\n streamId: string,\n adapter: PubSubAdapter,\n res: ExpressResponse\n): Promise<void> {\n res.setHeader('Content-Type', 'text/event-stream');\n res.setHeader('Cache-Control', 'no-cache');\n res.setHeader('Connection', 'keep-alive');\n\n const abortController = new AbortController();\n res.on('close', () => abortController.abort());\n\n await runSubscriberStream(\n streamId,\n adapter,\n {\n write: (data: string) => res.write(data),\n end: () => res.end(),\n },\n { signal: abortController.signal }\n );\n}\n\n/**\n * Express adapter namespace for pub-sub server utilities.\n */\nexport const express = {\n streamSubscriber,\n};\n"],"mappings":";;;;;AA0DA,eAAsB,iBACpB,UACA,SACA,KACe;AACf,MAAI,UAAU,gBAAgB,mBAAmB;AACjD,MAAI,UAAU,iBAAiB,UAAU;AACzC,MAAI,UAAU,cAAc,YAAY;AAExC,QAAM,kBAAkB,IAAI,gBAAgB;AAC5C,MAAI,GAAG,SAAS,MAAM,gBAAgB,MAAM,CAAC;AAE7C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,MACE,OAAO,CAAC,SAAiB,IAAI,MAAM,IAAI;AAAA,MACvC,KAAK,MAAM,IAAI,IAAI;AAAA,IACrB;AAAA,IACA,EAAE,QAAQ,gBAAgB,OAAO;AAAA,EACnC;AACF;AAKO,IAAM,UAAU;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runSubscriberStream
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EPB3GQNL.js";
|
|
4
4
|
|
|
5
5
|
// src/middleware/pubsub/server/fastify.ts
|
|
6
6
|
async function streamSubscriber(streamId, adapter, reply) {
|
|
@@ -28,4 +28,4 @@ export {
|
|
|
28
28
|
streamSubscriber,
|
|
29
29
|
fastify
|
|
30
30
|
};
|
|
31
|
-
//# sourceMappingURL=chunk-
|
|
31
|
+
//# sourceMappingURL=chunk-CRP6Y7NF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware/pubsub/server/fastify.ts"],"sourcesContent":["/**\n * @fileoverview Fastify adapter for pub-sub stream resumption.\n *\n * Provides utilities for Fastify servers to handle stream reconnections.\n *\n * @module middleware/pubsub/server/fastify\n */\n\nimport type { PubSubAdapter } from '../types.ts';\nimport { runSubscriberStream } from './shared.ts';\n\n/**\n * Fastify Reply interface (minimal type to avoid dependency).\n */\ninterface FastifyReply {\n raw: {\n setHeader(name: string, value: string): void;\n write(chunk: string): boolean;\n end(): void;\n on(event: 'close', listener: () => void): void;\n };\n}\n\n/**\n * Stream buffered and live events to a Fastify reply.\n *\n * Handles reconnection for Fastify routes:\n * 1. Replays buffered events from the adapter\n * 2. Subscribes to live events until completion signal\n * 3. Ends when stream completes or client disconnects\n *\n * @param streamId - The stream ID to subscribe to\n * @param adapter - The pub-sub adapter instance\n * @param reply - Fastify reply object\n *\n * @example\n * ```typescript\n * import { llm } from '@providerprotocol/ai';\n * import { anthropic } from '@providerprotocol/ai/anthropic';\n * import { pubsubMiddleware, memoryAdapter } from '@providerprotocol/ai/middleware/pubsub';\n * import { fastify as pubsubFastify } from '@providerprotocol/ai/middleware/pubsub/server';\n *\n * const adapter = memoryAdapter();\n *\n * app.post('/api/chat', async (request, reply) => {\n * const { input, conversationId } = request.body as { input: string; conversationId: string };\n *\n * if (!await adapter.exists(conversationId)) {\n * const model = llm({\n * model: anthropic('claude-sonnet-4-20250514'),\n * middleware: [pubsubMiddleware({ adapter, streamId: conversationId })],\n * });\n * model.stream(input).then(turn => saveToDatabase(conversationId, turn));\n * }\n *\n * return pubsubFastify.streamSubscriber(conversationId, adapter, reply);\n * });\n * ```\n */\nexport async function streamSubscriber(\n streamId: string,\n adapter: PubSubAdapter,\n reply: FastifyReply\n): Promise<void> {\n const res = reply.raw;\n res.setHeader('Content-Type', 'text/event-stream');\n res.setHeader('Cache-Control', 'no-cache');\n res.setHeader('Connection', 'keep-alive');\n\n const abortController = new AbortController();\n res.on('close', () => abortController.abort());\n\n await runSubscriberStream(\n streamId,\n adapter,\n {\n write: (data: string) => res.write(data),\n end: () => res.end(),\n },\n { signal: abortController.signal }\n );\n}\n\n/**\n * Fastify adapter namespace for pub-sub server utilities.\n */\nexport const fastify = {\n streamSubscriber,\n};\n"],"mappings":";;;;;AA2DA,eAAsB,iBACpB,UACA,SACA,OACe;AACf,QAAM,MAAM,MAAM;AAClB,MAAI,UAAU,gBAAgB,mBAAmB;AACjD,MAAI,UAAU,iBAAiB,UAAU;AACzC,MAAI,UAAU,cAAc,YAAY;AAExC,QAAM,kBAAkB,IAAI,gBAAgB;AAC5C,MAAI,GAAG,SAAS,MAAM,gBAAgB,MAAM,CAAC;AAE7C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,MACE,OAAO,CAAC,SAAiB,IAAI,MAAM,IAAI;AAAA,MACvC,KAAK,MAAM,IAAI,IAAI;AAAA,IACrB;AAAA,IACA,EAAE,QAAQ,gBAAgB,OAAO;AAAA,EACnC;AACF;AAKO,IAAM,UAAU;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -3,66 +3,47 @@ import {
|
|
|
3
3
|
} from "./chunk-ETBFOLQN.js";
|
|
4
4
|
|
|
5
5
|
// src/middleware/pubsub/server/shared.ts
|
|
6
|
-
var DEFAULT_CREATION_TIMEOUT = 5e3;
|
|
7
|
-
var CREATION_POLL_INTERVAL = 50;
|
|
8
6
|
function formatSSE(event) {
|
|
9
7
|
const serialized = serializeStreamEvent(event);
|
|
10
8
|
return `data: ${JSON.stringify(serialized)}
|
|
11
9
|
|
|
12
10
|
`;
|
|
13
11
|
}
|
|
14
|
-
async function waitForStream(streamId, adapter, timeout, signal) {
|
|
15
|
-
const deadline = Date.now() + timeout;
|
|
16
|
-
while (Date.now() < deadline) {
|
|
17
|
-
if (signal?.aborted) return false;
|
|
18
|
-
const exists = await adapter.exists(streamId);
|
|
19
|
-
if (exists) return true;
|
|
20
|
-
await new Promise((resolve) => setTimeout(resolve, CREATION_POLL_INTERVAL));
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
12
|
async function runSubscriberStream(streamId, adapter, writer, options = {}) {
|
|
25
|
-
const { signal
|
|
13
|
+
const { signal } = options;
|
|
26
14
|
if (signal?.aborted) {
|
|
27
15
|
writer.end();
|
|
28
16
|
return;
|
|
29
17
|
}
|
|
30
18
|
try {
|
|
31
|
-
const streamExists = await waitForStream(streamId, adapter, creationTimeout, signal);
|
|
32
19
|
if (signal?.aborted) {
|
|
33
20
|
writer.end();
|
|
34
21
|
return;
|
|
35
22
|
}
|
|
36
|
-
if (!streamExists) {
|
|
37
|
-
writer.write(`data: ${JSON.stringify({ error: "Stream not found" })}
|
|
38
|
-
|
|
39
|
-
`);
|
|
40
|
-
writer.end();
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
23
|
const queue = [];
|
|
44
24
|
let resolveWait = null;
|
|
45
|
-
let
|
|
25
|
+
let completed = false;
|
|
46
26
|
let lastSentCursor = -1;
|
|
47
|
-
const
|
|
27
|
+
const onEvent = (event, cursor) => {
|
|
48
28
|
queue.push({ event, cursor: cursor ?? null });
|
|
49
29
|
resolveWait?.();
|
|
50
|
-
}
|
|
30
|
+
};
|
|
31
|
+
const onComplete = () => {
|
|
32
|
+
completed = true;
|
|
33
|
+
resolveWait?.();
|
|
34
|
+
};
|
|
35
|
+
const unsubscribe = adapter.subscribe(streamId, onEvent, onComplete);
|
|
51
36
|
const onAbort = () => {
|
|
52
|
-
|
|
37
|
+
completed = true;
|
|
53
38
|
resolveWait?.();
|
|
54
39
|
};
|
|
55
40
|
signal?.addEventListener("abort", onAbort);
|
|
56
41
|
const drainQueue = () => {
|
|
57
42
|
while (queue.length > 0 && !signal?.aborted) {
|
|
58
43
|
const item = queue.shift();
|
|
59
|
-
if (!item)
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
44
|
+
if (!item) break;
|
|
62
45
|
const { event, cursor } = item;
|
|
63
|
-
if (cursor !== null && cursor <= lastSentCursor)
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
46
|
+
if (cursor !== null && cursor <= lastSentCursor) continue;
|
|
66
47
|
writer.write(formatSSE(event));
|
|
67
48
|
if (cursor !== null && cursor > lastSentCursor) {
|
|
68
49
|
lastSentCursor = cursor;
|
|
@@ -70,32 +51,30 @@ async function runSubscriberStream(streamId, adapter, writer, options = {}) {
|
|
|
70
51
|
}
|
|
71
52
|
};
|
|
72
53
|
const dropReplayDuplicates = () => {
|
|
73
|
-
if (queue.length === 0)
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
54
|
+
if (queue.length === 0) return;
|
|
76
55
|
const filtered = [];
|
|
77
56
|
for (const item of queue) {
|
|
78
|
-
if (item.cursor !== null && item.cursor <= lastSentCursor)
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
57
|
+
if (item.cursor !== null && item.cursor <= lastSentCursor) continue;
|
|
81
58
|
filtered.push(item);
|
|
82
59
|
}
|
|
83
60
|
queue.length = 0;
|
|
84
61
|
queue.push(...filtered);
|
|
85
62
|
};
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
63
|
+
const waitForSignal = () => new Promise((resolve) => {
|
|
64
|
+
let settled = false;
|
|
65
|
+
const settle = () => {
|
|
66
|
+
if (settled) return;
|
|
67
|
+
settled = true;
|
|
68
|
+
resolveWait = null;
|
|
69
|
+
resolve();
|
|
70
|
+
};
|
|
71
|
+
resolveWait = settle;
|
|
72
|
+
if (completed || signal?.aborted || queue.length > 0) {
|
|
73
|
+
settle();
|
|
74
|
+
}
|
|
89
75
|
});
|
|
90
76
|
try {
|
|
91
77
|
const events = await adapter.getEvents(streamId);
|
|
92
|
-
if (!events) {
|
|
93
|
-
writer.write(`data: ${JSON.stringify({ error: "Stream not found" })}
|
|
94
|
-
|
|
95
|
-
`);
|
|
96
|
-
writer.end();
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
78
|
for (const event of events) {
|
|
100
79
|
if (signal?.aborted) break;
|
|
101
80
|
writer.write(formatSSE(event));
|
|
@@ -106,24 +85,10 @@ async function runSubscriberStream(streamId, adapter, writer, options = {}) {
|
|
|
106
85
|
writer.end();
|
|
107
86
|
return;
|
|
108
87
|
}
|
|
109
|
-
|
|
110
|
-
if (completed) {
|
|
88
|
+
while (!completed && !signal?.aborted) {
|
|
111
89
|
drainQueue();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
while (!done) {
|
|
117
|
-
if (signal?.aborted) break;
|
|
118
|
-
drainQueue();
|
|
119
|
-
if (signal?.aborted) break;
|
|
120
|
-
const isComplete = await adapter.isCompleted(streamId).catch(() => false);
|
|
121
|
-
if (isComplete) {
|
|
122
|
-
done = true;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
await waitForNewEvents();
|
|
126
|
-
resolveWait = null;
|
|
90
|
+
if (completed || signal?.aborted) break;
|
|
91
|
+
await waitForSignal();
|
|
127
92
|
}
|
|
128
93
|
if (!signal?.aborted) {
|
|
129
94
|
drainQueue();
|
|
@@ -150,4 +115,4 @@ async function runSubscriberStream(streamId, adapter, writer, options = {}) {
|
|
|
150
115
|
export {
|
|
151
116
|
runSubscriberStream
|
|
152
117
|
};
|
|
153
|
-
//# sourceMappingURL=chunk-
|
|
118
|
+
//# sourceMappingURL=chunk-EPB3GQNL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware/pubsub/server/shared.ts"],"sourcesContent":["/**\n * @fileoverview Shared utilities for pub-sub server adapters.\n *\n * @module middleware/pubsub/server/shared\n * @internal\n */\n\nimport type { StreamEvent } from '../../../types/stream.ts';\nimport type { PubSubAdapter } from '../types.ts';\nimport { serializeStreamEvent } from '../../../stream/serialization.ts';\n\n/**\n * Writer interface for abstracting how data is written to responses.\n * @internal\n */\nexport interface StreamWriter {\n write(data: string): void;\n end(): void;\n}\n\n/**\n * Options for runSubscriberStream.\n * @internal\n */\nexport interface StreamOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Formats a stream event as an SSE data line.\n */\nexport function formatSSE(event: StreamEvent): string {\n const serialized = serializeStreamEvent(event);\n return `data: ${JSON.stringify(serialized)}\\n\\n`;\n}\n\n/**\n * Core subscriber stream logic shared across all adapters.\n *\n * Handles:\n * 1. Subscribing to live events and completion signal\n * 2. Replaying buffered events (empty if stream just started)\n * 3. Processing live events until completion signal\n * 4. Final cleanup\n * 5. Client disconnect via AbortSignal\n *\n * @internal\n */\nexport async function runSubscriberStream(\n streamId: string,\n adapter: PubSubAdapter,\n writer: StreamWriter,\n options: StreamOptions = {}\n): Promise<void> {\n const { signal } = options;\n\n if (signal?.aborted) {\n writer.end();\n return;\n }\n\n try {\n if (signal?.aborted) {\n writer.end();\n return;\n }\n\n const queue: Array<{ event: StreamEvent; cursor: number | null }> = [];\n let resolveWait: (() => void) | null = null;\n let completed = false;\n let lastSentCursor = -1;\n\n const onEvent = (event: StreamEvent, cursor?: number): void => {\n queue.push({ event, cursor: cursor ?? null });\n resolveWait?.();\n };\n\n const onComplete = (): void => {\n completed = true;\n resolveWait?.();\n };\n\n const unsubscribe = adapter.subscribe(streamId, onEvent, onComplete);\n\n const onAbort = (): void => {\n completed = true;\n resolveWait?.();\n };\n signal?.addEventListener('abort', onAbort);\n\n const drainQueue = (): void => {\n while (queue.length > 0 && !signal?.aborted) {\n const item = queue.shift();\n if (!item) break;\n const { event, cursor } = item;\n if (cursor !== null && cursor <= lastSentCursor) continue;\n writer.write(formatSSE(event));\n if (cursor !== null && cursor > lastSentCursor) {\n lastSentCursor = cursor;\n }\n }\n };\n\n const dropReplayDuplicates = (): void => {\n if (queue.length === 0) return;\n const filtered: Array<{ event: StreamEvent; cursor: number | null }> = [];\n for (const item of queue) {\n if (item.cursor !== null && item.cursor <= lastSentCursor) continue;\n filtered.push(item);\n }\n queue.length = 0;\n queue.push(...filtered);\n };\n\n const waitForSignal = (): Promise<void> => new Promise((resolve) => {\n let settled = false;\n\n const settle = (): void => {\n if (settled) return;\n settled = true;\n resolveWait = null;\n resolve();\n };\n\n resolveWait = settle;\n\n if (completed || signal?.aborted || queue.length > 0) {\n settle();\n }\n });\n\n try {\n const events = await adapter.getEvents(streamId);\n\n for (const event of events) {\n if (signal?.aborted) break;\n writer.write(formatSSE(event));\n }\n\n lastSentCursor = events.length - 1;\n dropReplayDuplicates();\n\n if (signal?.aborted) {\n writer.end();\n return;\n }\n\n // Wait for events or completion signal\n while (!completed && !signal?.aborted) {\n drainQueue();\n if (completed || signal?.aborted) break;\n await waitForSignal();\n }\n\n if (!signal?.aborted) {\n drainQueue();\n }\n } finally {\n signal?.removeEventListener('abort', onAbort);\n unsubscribe();\n }\n\n if (!signal?.aborted) {\n writer.write('data: [DONE]\\n\\n');\n }\n writer.end();\n } catch (error) {\n if (!signal?.aborted) {\n const errorMsg = error instanceof Error ? error.message : String(error);\n writer.write(`data: ${JSON.stringify({ error: errorMsg })}\\n\\n`);\n }\n writer.end();\n }\n}\n"],"mappings":"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","names":[]}
|
|
@@ -29,6 +29,7 @@ var StreamEventType = {
|
|
|
29
29
|
};
|
|
30
30
|
function createStreamResult(generator, turnPromiseOrFactory, abortController) {
|
|
31
31
|
let cachedTurn = null;
|
|
32
|
+
let drainStarted = false;
|
|
32
33
|
const getTurn = () => {
|
|
33
34
|
if (typeof turnPromiseOrFactory === "function") {
|
|
34
35
|
if (!cachedTurn) {
|
|
@@ -38,6 +39,20 @@ function createStreamResult(generator, turnPromiseOrFactory, abortController) {
|
|
|
38
39
|
}
|
|
39
40
|
return turnPromiseOrFactory;
|
|
40
41
|
};
|
|
42
|
+
const drain = () => {
|
|
43
|
+
if (drainStarted) return;
|
|
44
|
+
drainStarted = true;
|
|
45
|
+
void (async () => {
|
|
46
|
+
try {
|
|
47
|
+
let done = false;
|
|
48
|
+
while (!done) {
|
|
49
|
+
const result = await generator.next();
|
|
50
|
+
done = result.done ?? false;
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
};
|
|
41
56
|
return {
|
|
42
57
|
[Symbol.asyncIterator]() {
|
|
43
58
|
return generator;
|
|
@@ -47,6 +62,10 @@ function createStreamResult(generator, turnPromiseOrFactory, abortController) {
|
|
|
47
62
|
},
|
|
48
63
|
abort() {
|
|
49
64
|
abortController.abort();
|
|
65
|
+
},
|
|
66
|
+
then(onfulfilled, onrejected) {
|
|
67
|
+
drain();
|
|
68
|
+
return getTurn().then(onfulfilled, onrejected);
|
|
50
69
|
}
|
|
51
70
|
};
|
|
52
71
|
}
|
|
@@ -127,4 +146,4 @@ export {
|
|
|
127
146
|
toolExecutionStart,
|
|
128
147
|
toolExecutionEnd
|
|
129
148
|
};
|
|
130
|
-
//# sourceMappingURL=chunk-
|
|
149
|
+
//# sourceMappingURL=chunk-RJGTRQ47.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/stream.ts"],"sourcesContent":["/**\n * @fileoverview Streaming types for real-time LLM responses.\n *\n * Defines the event types and interfaces for streaming LLM inference,\n * including text deltas, tool call deltas, and control events.\n *\n * @module types/stream\n */\n\nimport type { Turn } from './turn.ts';\n\n/**\n * Stream event type constants.\n *\n * Use these constants instead of raw strings for type-safe event handling:\n *\n * @example\n * ```typescript\n * import { StreamEventType } from 'upp';\n *\n * for await (const event of stream) {\n * if (event.type === StreamEventType.TextDelta) {\n * process.stdout.write(event.delta.text ?? '');\n * }\n * }\n * ```\n */\nexport const StreamEventType = {\n /** Incremental text output */\n TextDelta: 'text_delta',\n /** Incremental reasoning/thinking output */\n ReasoningDelta: 'reasoning_delta',\n /** Incremental image data */\n ImageDelta: 'image_delta',\n /** Incremental audio data */\n AudioDelta: 'audio_delta',\n /** Incremental video data */\n VideoDelta: 'video_delta',\n /** Incremental tool call data (arguments being streamed) */\n ToolCallDelta: 'tool_call_delta',\n /** Incremental structured object data (for structured output responses) */\n ObjectDelta: 'object_delta',\n /** Tool execution has started (may be emitted after completion in some implementations) */\n ToolExecutionStart: 'tool_execution_start',\n /** Tool execution has completed */\n ToolExecutionEnd: 'tool_execution_end',\n /** Beginning of a message */\n MessageStart: 'message_start',\n /** End of a message */\n MessageStop: 'message_stop',\n /** Beginning of a content block */\n ContentBlockStart: 'content_block_start',\n /** End of a content block */\n ContentBlockStop: 'content_block_stop',\n} as const;\n\n/**\n * Stream event type discriminator union.\n *\n * This type is derived from {@link StreamEventType} constants. Use `StreamEventType.TextDelta`\n * for constants or `type MyType = StreamEventType` for type annotations.\n */\nexport type StreamEventType = (typeof StreamEventType)[keyof typeof StreamEventType];\n\n/**\n * Event delta data payload.\n *\n * Contains the type-specific data for a streaming event.\n * Different fields are populated depending on the event type:\n *\n * | Event Type | Fields |\n * |------------|--------|\n * | `text_delta` | `text` |\n * | `reasoning_delta` | `text` |\n * | `object_delta` | `text` |\n * | `image_delta` | `data` |\n * | `audio_delta` | `data` |\n * | `video_delta` | `data` |\n * | `tool_call_delta` | `toolCallId`, `toolName`, `argumentsJson` |\n * | `tool_execution_start` | `toolCallId`, `toolName`, `timestamp` |\n * | `tool_execution_end` | `toolCallId`, `toolName`, `result`, `isError`, `timestamp` |\n * | `message_start` | (none) |\n * | `message_stop` | (none) |\n * | `content_block_start` | (none) |\n * | `content_block_stop` | (none) |\n */\nexport interface EventDelta {\n /** Incremental text content (text_delta, reasoning_delta, object_delta) */\n text?: string;\n\n /** Incremental binary data (image_delta, audio_delta, video_delta) */\n data?: Uint8Array;\n\n /** Tool call identifier (tool_call_delta, tool_execution_start/end) */\n toolCallId?: string;\n\n /** Tool name (tool_call_delta, tool_execution_start/end) */\n toolName?: string;\n\n /** Incremental JSON arguments string (tool_call_delta) */\n argumentsJson?: string;\n\n /** Tool execution result (tool_execution_end) */\n result?: unknown;\n\n /** Whether tool execution resulted in an error (tool_execution_end) */\n isError?: boolean;\n\n /** Timestamp in milliseconds (tool_execution_start/end) */\n timestamp?: number;\n}\n\n/**\n * A single streaming event from the LLM.\n *\n * Events are emitted in order as the model generates output,\n * allowing for real-time display of responses.\n *\n * @example\n * ```typescript\n * import { StreamEventType } from 'upp';\n *\n * for await (const event of stream) {\n * if (event.type === StreamEventType.TextDelta) {\n * process.stdout.write(event.delta.text ?? '');\n * } else if (event.type === StreamEventType.ToolCallDelta) {\n * console.log('Tool:', event.delta.toolName);\n * }\n * }\n * ```\n */\nexport interface StreamEvent {\n /** Event type discriminator */\n type: StreamEventType;\n\n /** Index of the content block this event belongs to */\n index: number;\n\n /** Event-specific data payload */\n delta: EventDelta;\n}\n\n/**\n * Stream result - an async iterable that also provides the final turn.\n *\n * Allows consuming streaming events while also awaiting the complete\n * Turn result after streaming finishes. Implements `PromiseLike<Turn>`\n * for direct awaiting with automatic stream consumption.\n *\n * @typeParam TData - Type of the structured output data\n *\n * @example\n * ```typescript\n * import { StreamEventType } from 'upp';\n *\n * const stream = instance.stream('Tell me a story');\n *\n * // Option 1: Consume streaming events manually\n * for await (const event of stream) {\n * if (event.type === StreamEventType.TextDelta) {\n * process.stdout.write(event.delta.text ?? '');\n * }\n * }\n * const turn = await stream.turn;\n *\n * // Option 2: Just await the turn (auto-drains the stream)\n * const turn = await instance.stream('Tell me a story');\n *\n * // Option 3: Fire-and-forget with callback\n * instance.stream('Tell me a story').then(turn => saveToDB(turn));\n * ```\n */\nexport interface StreamResult<TData = unknown>\n extends AsyncIterable<StreamEvent>, PromiseLike<Turn<TData>> {\n /**\n * Promise that resolves to the complete Turn after streaming finishes.\n * Rejects if the stream is aborted or terminated early.\n */\n readonly turn: Promise<Turn<TData>>;\n\n /**\n * Aborts the stream, stopping further events and cancelling the request.\n * This will cause {@link StreamResult.turn} to reject.\n */\n abort(): void;\n}\n\n/**\n * Creates a StreamResult from an async generator and completion promise.\n *\n * @typeParam TData - Type of the structured output data\n * @param generator - Async generator that yields stream events\n * @param turnPromiseOrFactory - Promise or factory that resolves to the complete Turn\n * @param abortController - Controller for aborting the stream\n * @returns A StreamResult that can be iterated and awaited\n *\n * @example\n * ```typescript\n * const abortController = new AbortController();\n * const stream = createStreamResult(\n * eventGenerator(),\n * turnPromise,\n * abortController\n * );\n *\n * // Can be awaited directly (auto-drains)\n * const turn = await stream;\n *\n * // Or iterated manually\n * for await (const event of stream) { ... }\n * const turn = await stream.turn;\n * ```\n */\nexport function createStreamResult<TData = unknown>(\n generator: AsyncGenerator<StreamEvent, void, unknown>,\n turnPromiseOrFactory: Promise<Turn<TData>> | (() => Promise<Turn<TData>>),\n abortController: AbortController\n): StreamResult<TData> {\n let cachedTurn: Promise<Turn<TData>> | null = null;\n let drainStarted = false;\n\n const getTurn = (): Promise<Turn<TData>> => {\n if (typeof turnPromiseOrFactory === 'function') {\n if (!cachedTurn) {\n cachedTurn = turnPromiseOrFactory();\n }\n return cachedTurn;\n }\n return turnPromiseOrFactory;\n };\n\n const drain = (): void => {\n if (drainStarted) return;\n drainStarted = true;\n void (async () => {\n try {\n let done = false;\n while (!done) {\n const result = await generator.next();\n done = result.done ?? false;\n }\n } catch {\n // Errors are surfaced via turn promise\n }\n })();\n };\n\n return {\n [Symbol.asyncIterator]() {\n return generator;\n },\n get turn() {\n return getTurn();\n },\n abort() {\n abortController.abort();\n },\n then<TResult1 = Turn<TData>, TResult2 = never>(\n onfulfilled?: ((value: Turn<TData>) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n drain();\n return getTurn().then(onfulfilled, onrejected);\n },\n };\n}\n\n/**\n * Creates a text delta stream event.\n *\n * @param text - The incremental text content\n * @param index - Content block index (default: 0)\n * @returns A text_delta StreamEvent\n */\nexport function textDelta(text: string, index = 0): StreamEvent {\n return {\n type: StreamEventType.TextDelta,\n index,\n delta: { text },\n };\n}\n\n/**\n * Creates a tool call delta stream event.\n *\n * @param toolCallId - Unique identifier for the tool call\n * @param toolName - Name of the tool being called\n * @param argumentsJson - Incremental JSON arguments string\n * @param index - Content block index (default: 0)\n * @returns A tool_call_delta StreamEvent\n */\nexport function toolCallDelta(\n toolCallId: string,\n toolName: string,\n argumentsJson: string,\n index = 0\n): StreamEvent {\n return {\n type: StreamEventType.ToolCallDelta,\n index,\n delta: { toolCallId, toolName, argumentsJson },\n };\n}\n\n/**\n * Creates an object delta stream event for structured output responses.\n *\n * @param text - The incremental text content\n * @param index - Content block index (default: 0)\n * @returns An object_delta StreamEvent\n */\nexport function objectDelta(text: string, index = 0): StreamEvent {\n return {\n type: StreamEventType.ObjectDelta,\n index,\n delta: { text },\n };\n}\n\n/**\n * Creates a message start stream event.\n *\n * @returns A message_start StreamEvent\n */\nexport function messageStart(): StreamEvent {\n return {\n type: StreamEventType.MessageStart,\n index: 0,\n delta: {},\n };\n}\n\n/**\n * Creates a message stop stream event.\n *\n * @returns A message_stop StreamEvent\n */\nexport function messageStop(): StreamEvent {\n return {\n type: StreamEventType.MessageStop,\n index: 0,\n delta: {},\n };\n}\n\n/**\n * Creates a content block start stream event.\n *\n * @param index - The content block index starting\n * @returns A content_block_start StreamEvent\n */\nexport function contentBlockStart(index: number): StreamEvent {\n return {\n type: StreamEventType.ContentBlockStart,\n index,\n delta: {},\n };\n}\n\n/**\n * Creates a content block stop stream event.\n *\n * @param index - The content block index stopping\n * @returns A content_block_stop StreamEvent\n */\nexport function contentBlockStop(index: number): StreamEvent {\n return {\n type: StreamEventType.ContentBlockStop,\n index,\n delta: {},\n };\n}\n\n/**\n * Creates a tool execution start stream event.\n *\n * @param toolCallId - Unique identifier for the tool call\n * @param toolName - Name of the tool being executed\n * @param timestamp - Start timestamp in milliseconds\n * @param index - Content block index (default: 0)\n * @returns A tool_execution_start StreamEvent\n */\nexport function toolExecutionStart(\n toolCallId: string,\n toolName: string,\n timestamp: number,\n index = 0\n): StreamEvent {\n return {\n type: StreamEventType.ToolExecutionStart,\n index,\n delta: { toolCallId, toolName, timestamp },\n };\n}\n\n/**\n * Creates a tool execution end stream event.\n *\n * @param toolCallId - Unique identifier for the tool call\n * @param toolName - Name of the tool that was executed\n * @param result - The result from the tool execution\n * @param isError - Whether the execution resulted in an error\n * @param timestamp - End timestamp in milliseconds\n * @param index - Content block index (default: 0)\n * @returns A tool_execution_end StreamEvent\n */\nexport function toolExecutionEnd(\n toolCallId: string,\n toolName: string,\n result: unknown,\n isError: boolean,\n timestamp: number,\n index = 0\n): StreamEvent {\n return {\n type: StreamEventType.ToolExecutionEnd,\n index,\n delta: { toolCallId, toolName, result, isError, timestamp },\n };\n}\n"],"mappings":"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","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProviderIdentity, b as ProviderConfig, M as Middleware, E as EmbeddingInput, c as EmbeddingUsage, B as BoundEmbeddingModel } from './llm-
|
|
1
|
+
import { P as ProviderIdentity, b as ProviderConfig, M as Middleware, E as EmbeddingInput, c as EmbeddingUsage, B as BoundEmbeddingModel } from './llm-ByUFPcFH.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Embedding types for vector embedding generation.
|
package/dist/google/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as ProviderConfig, d as Provider } from '../llm-
|
|
2
|
-
import '../stream-
|
|
1
|
+
import { b as ProviderConfig, d as Provider } from '../llm-ByUFPcFH.js';
|
|
2
|
+
import '../stream-S7nwQRqM.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Provider-specific parameters for Google Gemini API requests.
|
package/dist/google/index.js
CHANGED
package/dist/groq/index.d.ts
CHANGED
package/dist/groq/index.js
CHANGED
package/dist/http/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { D as DynamicKey, E as ExponentialBackoff, L as LinearBackoff, N as NoRetry, a as RetryAfterStrategy, R as RoundRobinKeys, T as TokenBucket, W as WeightedKeys, m as maskApiKey, r as resolveApiKey } from '../retry-
|
|
2
|
-
import { b as ProviderConfig, e as Modality, U as UPPError, f as ErrorCode } from '../llm-
|
|
3
|
-
import '../stream-
|
|
1
|
+
export { D as DynamicKey, E as ExponentialBackoff, L as LinearBackoff, N as NoRetry, a as RetryAfterStrategy, R as RoundRobinKeys, T as TokenBucket, W as WeightedKeys, m as maskApiKey, r as resolveApiKey } from '../retry-BDMo4AVu.js';
|
|
2
|
+
import { b as ProviderConfig, e as Modality, U as UPPError, f as ErrorCode } from '../llm-ByUFPcFH.js';
|
|
3
|
+
import '../stream-S7nwQRqM.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* HTTP fetch utilities with retry, timeout, and error normalization.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { L as LLMOptions, h as LLMInstance, i as ImageOptions, j as ImageInstance, k as LLMHandler, l as EmbeddingHandler, m as ImageHandler, d as Provider, g as ModelReference } from './llm-
|
|
2
|
-
export { a0 as AnyRequest, a1 as AnyResponse, B as BoundEmbeddingModel, X as BoundImageModel, A as BoundLLMModel, E as EmbeddingInput, r as EmbeddingProvider, t as EmbeddingRequest, u as EmbeddingResponse, c as EmbeddingUsage, v as EmbeddingVector, f as ErrorCode, H as GeneratedImage, n as Image, Q as ImageCapabilities, F as ImageEditInput, V as ImageEditRequest, G as ImageGenerateOptions, D as ImageInput, Y as ImageModelInput, s as ImageProvider, a as ImageProviderStreamResult, S as ImageRequest, W as ImageResponse, N as ImageResult, O as ImageStreamEvent, I as ImageStreamResult, J as ImageUsage, C as InferenceInput, K as KeyStrategy, w as LLMCapabilities, q as LLMProvider, x as LLMRequest, y as LLMResponse, z as LLMStreamResult, M as Middleware, Z as MiddlewareContext, $ as MiddlewareModality, e as Modality, o as ModalityType, b as ProviderConfig, P as ProviderIdentity, R as RetryStrategy, _ as StreamContext, T as Thread, p as ThreadJSON, U as UPPError } from './llm-
|
|
3
|
-
import { E as EmbeddingOptions, a as EmbeddingInstance } from './embedding-
|
|
4
|
-
export { b as EmbedOptions, c as Embedding, h as EmbeddingInputType, g as EmbeddingModelInput, e as EmbeddingProgress, d as EmbeddingResult, f as EmbeddingStream } from './embedding-
|
|
5
|
-
import { D as DocumentSource, j as DocumentBlock, k as AudioBlock, V as VideoBlock } from './stream-
|
|
6
|
-
export { L as AfterCallResult, A as AssistantContent, g as AssistantMessage, K as BeforeCallResult, B as BinaryBlock, C as ContentBlock, o as ContentBlockType, q as DocumentSourceType, E as EventDelta, c as ImageBlock, I as ImageSource, p as ImageSourceType, J as JSONSchema, l as JSONSchemaProperty, m as JSONSchemaPropertyType, M as Message, a as MessageJSON, Z as MessageMetadata, _ as MessageOptions, Q as MessageRole, e as MessageType, R as ReasoningBlock, S as StreamEvent, a2 as StreamEventType, i as StreamResult, n as TextBlock, h as TokenUsage, d as Tool, F as ToolCall, N as ToolExecution, H as ToolMetadata, G as ToolResult, P as ToolResultMessage, f as ToolUseStrategy, T as Turn, U as UserContent, O as UserMessage, a1 as aggregateUsage, a9 as contentBlockStart, aa as contentBlockStop, a3 as createStreamResult, $ as createTurn, a0 as emptyUsage, X as isAssistantMessage, x as isAudioBlock, z as isBinaryBlock, w as isDocumentBlock, v as isImageBlock, u as isReasoningBlock, s as isTextBlock, Y as isToolResultMessage, W as isUserMessage, y as isVideoBlock, a7 as messageStart, a8 as messageStop, a6 as objectDelta, r as reasoning, t as text, a4 as textDelta, a5 as toolCallDelta, ac as toolExecutionEnd, ab as toolExecutionStart } from './stream-
|
|
7
|
-
export { D as DynamicKey, E as ExponentialBackoff, L as LinearBackoff, N as NoRetry, a as RetryAfterStrategy, R as RoundRobinKeys, T as TokenBucket, W as WeightedKeys } from './retry-
|
|
1
|
+
import { L as LLMOptions, h as LLMInstance, i as ImageOptions, j as ImageInstance, k as LLMHandler, l as EmbeddingHandler, m as ImageHandler, d as Provider, g as ModelReference } from './llm-ByUFPcFH.js';
|
|
2
|
+
export { a0 as AnyRequest, a1 as AnyResponse, B as BoundEmbeddingModel, X as BoundImageModel, A as BoundLLMModel, E as EmbeddingInput, r as EmbeddingProvider, t as EmbeddingRequest, u as EmbeddingResponse, c as EmbeddingUsage, v as EmbeddingVector, f as ErrorCode, H as GeneratedImage, n as Image, Q as ImageCapabilities, F as ImageEditInput, V as ImageEditRequest, G as ImageGenerateOptions, D as ImageInput, Y as ImageModelInput, s as ImageProvider, a as ImageProviderStreamResult, S as ImageRequest, W as ImageResponse, N as ImageResult, O as ImageStreamEvent, I as ImageStreamResult, J as ImageUsage, C as InferenceInput, K as KeyStrategy, w as LLMCapabilities, q as LLMProvider, x as LLMRequest, y as LLMResponse, z as LLMStreamResult, M as Middleware, Z as MiddlewareContext, $ as MiddlewareModality, e as Modality, o as ModalityType, b as ProviderConfig, P as ProviderIdentity, R as RetryStrategy, _ as StreamContext, T as Thread, p as ThreadJSON, U as UPPError } from './llm-ByUFPcFH.js';
|
|
3
|
+
import { E as EmbeddingOptions, a as EmbeddingInstance } from './embedding-BXA72PlJ.js';
|
|
4
|
+
export { b as EmbedOptions, c as Embedding, h as EmbeddingInputType, g as EmbeddingModelInput, e as EmbeddingProgress, d as EmbeddingResult, f as EmbeddingStream } from './embedding-BXA72PlJ.js';
|
|
5
|
+
import { D as DocumentSource, j as DocumentBlock, k as AudioBlock, V as VideoBlock } from './stream-S7nwQRqM.js';
|
|
6
|
+
export { L as AfterCallResult, A as AssistantContent, g as AssistantMessage, K as BeforeCallResult, B as BinaryBlock, C as ContentBlock, o as ContentBlockType, q as DocumentSourceType, E as EventDelta, c as ImageBlock, I as ImageSource, p as ImageSourceType, J as JSONSchema, l as JSONSchemaProperty, m as JSONSchemaPropertyType, M as Message, a as MessageJSON, Z as MessageMetadata, _ as MessageOptions, Q as MessageRole, e as MessageType, R as ReasoningBlock, S as StreamEvent, a2 as StreamEventType, i as StreamResult, n as TextBlock, h as TokenUsage, d as Tool, F as ToolCall, N as ToolExecution, H as ToolMetadata, G as ToolResult, P as ToolResultMessage, f as ToolUseStrategy, T as Turn, U as UserContent, O as UserMessage, a1 as aggregateUsage, a9 as contentBlockStart, aa as contentBlockStop, a3 as createStreamResult, $ as createTurn, a0 as emptyUsage, X as isAssistantMessage, x as isAudioBlock, z as isBinaryBlock, w as isDocumentBlock, v as isImageBlock, u as isReasoningBlock, s as isTextBlock, Y as isToolResultMessage, W as isUserMessage, y as isVideoBlock, a7 as messageStart, a8 as messageStop, a6 as objectDelta, r as reasoning, t as text, a4 as textDelta, a5 as toolCallDelta, ac as toolExecutionEnd, ab as toolExecutionStart } from './stream-S7nwQRqM.js';
|
|
7
|
+
export { D as DynamicKey, E as ExponentialBackoff, L as LinearBackoff, N as NoRetry, a as RetryAfterStrategy, R as RoundRobinKeys, T as TokenBucket, W as WeightedKeys } from './retry-BDMo4AVu.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @fileoverview LLM instance factory and streaming logic for the Universal Provider Protocol.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as ImageSource, c as ImageBlock, S as StreamEvent, d as Tool, M as Message, T as Turn, U as UserContent, A as AssistantContent, e as MessageType, a as MessageJSON, f as ToolUseStrategy, J as JSONSchema, g as AssistantMessage, h as TokenUsage, C as ContentBlock, i as StreamResult } from './stream-
|
|
1
|
+
import { I as ImageSource, c as ImageBlock, S as StreamEvent, d as Tool, M as Message, T as Turn, U as UserContent, A as AssistantContent, e as MessageType, a as MessageJSON, f as ToolUseStrategy, J as JSONSchema, g as AssistantMessage, h as TokenUsage, C as ContentBlock, i as StreamResult } from './stream-S7nwQRqM.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Error types for the Unified Provider Protocol.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as Middleware } from '../../llm-
|
|
2
|
-
import { E as EventDelta, S as StreamEvent } from '../../stream-
|
|
1
|
+
import { M as Middleware } from '../../llm-ByUFPcFH.js';
|
|
2
|
+
import { E as EventDelta, S as StreamEvent } from '../../stream-S7nwQRqM.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @fileoverview Parsed object middleware for incremental JSON parsing.
|