@providerprotocol/ai 0.0.34 → 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.
Files changed (136) hide show
  1. package/README.md +546 -3
  2. package/dist/anthropic/index.d.ts +2 -1
  3. package/dist/anthropic/index.js +151 -145
  4. package/dist/anthropic/index.js.map +1 -1
  5. package/dist/cerebras/index.d.ts +392 -0
  6. package/dist/cerebras/index.js +648 -0
  7. package/dist/cerebras/index.js.map +1 -0
  8. package/dist/chunk-2YXFLRQ6.js +49 -0
  9. package/dist/chunk-2YXFLRQ6.js.map +1 -0
  10. package/dist/chunk-4OGB7JZA.js +157 -0
  11. package/dist/chunk-4OGB7JZA.js.map +1 -0
  12. package/dist/chunk-4RX4VQCB.js +31 -0
  13. package/dist/chunk-4RX4VQCB.js.map +1 -0
  14. package/dist/chunk-5IWHCXKN.js +30 -0
  15. package/dist/chunk-5IWHCXKN.js.map +1 -0
  16. package/dist/{chunk-3C7O2RNO.js → chunk-A2IM7PGT.js} +6 -4
  17. package/dist/{chunk-3C7O2RNO.js.map → chunk-A2IM7PGT.js.map} +1 -1
  18. package/dist/{chunk-3D6XGGVG.js → chunk-ARVM24K2.js} +2 -2
  19. package/dist/{chunk-4J6OFUKX.js → chunk-AY55T37A.js} +70 -162
  20. package/dist/chunk-AY55T37A.js.map +1 -0
  21. package/dist/{chunk-ILR2D5PN.js → chunk-BRP5XJ6Q.js} +2 -86
  22. package/dist/chunk-BRP5XJ6Q.js.map +1 -0
  23. package/dist/chunk-C4JP64VW.js +298 -0
  24. package/dist/chunk-C4JP64VW.js.map +1 -0
  25. package/dist/chunk-COS4ON4G.js +111 -0
  26. package/dist/chunk-COS4ON4G.js.map +1 -0
  27. package/dist/chunk-CRP6Y7NF.js +31 -0
  28. package/dist/chunk-CRP6Y7NF.js.map +1 -0
  29. package/dist/chunk-EPB3GQNL.js +118 -0
  30. package/dist/chunk-EPB3GQNL.js.map +1 -0
  31. package/dist/chunk-ETBFOLQN.js +34 -0
  32. package/dist/chunk-ETBFOLQN.js.map +1 -0
  33. package/dist/chunk-I53CI6ZZ.js +142 -0
  34. package/dist/chunk-I53CI6ZZ.js.map +1 -0
  35. package/dist/chunk-IDZOVWP3.js +29 -0
  36. package/dist/chunk-IDZOVWP3.js.map +1 -0
  37. package/dist/chunk-JA3UZALR.js +88 -0
  38. package/dist/chunk-JA3UZALR.js.map +1 -0
  39. package/dist/{chunk-WAKD3OO5.js → chunk-N5DX5JW3.js} +31 -31
  40. package/dist/chunk-N5DX5JW3.js.map +1 -0
  41. package/dist/chunk-OIEWDFQU.js +97 -0
  42. package/dist/chunk-OIEWDFQU.js.map +1 -0
  43. package/dist/{chunk-TOJCZMVU.js → chunk-PMK5LZ5Z.js} +40 -40
  44. package/dist/chunk-PMK5LZ5Z.js.map +1 -0
  45. package/dist/{chunk-6S222DHN.js → chunk-RJGTRQ47.js} +20 -1
  46. package/dist/chunk-RJGTRQ47.js.map +1 -0
  47. package/dist/chunk-UFFJDYCE.js +94 -0
  48. package/dist/chunk-UFFJDYCE.js.map +1 -0
  49. package/dist/chunk-VGKZIGVI.js +222 -0
  50. package/dist/chunk-VGKZIGVI.js.map +1 -0
  51. package/dist/{chunk-KUPF5KHT.js → chunk-Y5H7C5J4.js} +2 -2
  52. package/dist/{embedding-D2BYIehX.d.ts → embedding-BXA72PlJ.d.ts} +1 -1
  53. package/dist/google/index.d.ts +2 -1
  54. package/dist/google/index.js +202 -199
  55. package/dist/google/index.js.map +1 -1
  56. package/dist/groq/index.d.ts +410 -0
  57. package/dist/groq/index.js +649 -0
  58. package/dist/groq/index.js.map +1 -0
  59. package/dist/http/index.d.ts +3 -2
  60. package/dist/http/index.js +5 -4
  61. package/dist/image-stream-CCgwB7ve.d.ts +11 -0
  62. package/dist/index.d.ts +8 -118
  63. package/dist/index.js +520 -769
  64. package/dist/index.js.map +1 -1
  65. package/dist/{llm-BQJZj3cD.d.ts → llm-ByUFPcFH.d.ts} +12 -1632
  66. package/dist/middleware/logging/index.d.ts +76 -0
  67. package/dist/middleware/logging/index.js +74 -0
  68. package/dist/middleware/logging/index.js.map +1 -0
  69. package/dist/middleware/parsed-object/index.d.ts +45 -0
  70. package/dist/middleware/parsed-object/index.js +73 -0
  71. package/dist/middleware/parsed-object/index.js.map +1 -0
  72. package/dist/middleware/pubsub/index.d.ts +97 -0
  73. package/dist/middleware/pubsub/index.js +160 -0
  74. package/dist/middleware/pubsub/index.js.map +1 -0
  75. package/dist/middleware/pubsub/server/express/index.d.ts +66 -0
  76. package/dist/middleware/pubsub/server/express/index.js +11 -0
  77. package/dist/middleware/pubsub/server/express/index.js.map +1 -0
  78. package/dist/middleware/pubsub/server/fastify/index.d.ts +67 -0
  79. package/dist/middleware/pubsub/server/fastify/index.js +11 -0
  80. package/dist/middleware/pubsub/server/fastify/index.js.map +1 -0
  81. package/dist/middleware/pubsub/server/h3/index.d.ts +70 -0
  82. package/dist/middleware/pubsub/server/h3/index.js +11 -0
  83. package/dist/middleware/pubsub/server/h3/index.js.map +1 -0
  84. package/dist/middleware/pubsub/server/index.d.ts +78 -0
  85. package/dist/middleware/pubsub/server/index.js +34 -0
  86. package/dist/middleware/pubsub/server/index.js.map +1 -0
  87. package/dist/middleware/pubsub/server/webapi/index.d.ts +63 -0
  88. package/dist/middleware/pubsub/server/webapi/index.js +11 -0
  89. package/dist/middleware/pubsub/server/webapi/index.js.map +1 -0
  90. package/dist/ollama/index.d.ts +2 -1
  91. package/dist/ollama/index.js +48 -45
  92. package/dist/ollama/index.js.map +1 -1
  93. package/dist/openai/index.d.ts +2 -1
  94. package/dist/openai/index.js +319 -313
  95. package/dist/openai/index.js.map +1 -1
  96. package/dist/openrouter/index.d.ts +2 -1
  97. package/dist/openrouter/index.js +381 -385
  98. package/dist/openrouter/index.js.map +1 -1
  99. package/dist/proxy/index.d.ts +10 -914
  100. package/dist/proxy/index.js +275 -1007
  101. package/dist/proxy/index.js.map +1 -1
  102. package/dist/proxy/server/express/index.d.ts +161 -0
  103. package/dist/proxy/server/express/index.js +24 -0
  104. package/dist/proxy/server/express/index.js.map +1 -0
  105. package/dist/proxy/server/fastify/index.d.ts +162 -0
  106. package/dist/proxy/server/fastify/index.js +24 -0
  107. package/dist/proxy/server/fastify/index.js.map +1 -0
  108. package/dist/proxy/server/h3/index.d.ts +189 -0
  109. package/dist/proxy/server/h3/index.js +28 -0
  110. package/dist/proxy/server/h3/index.js.map +1 -0
  111. package/dist/proxy/server/index.d.ts +151 -0
  112. package/dist/proxy/server/index.js +48 -0
  113. package/dist/proxy/server/index.js.map +1 -0
  114. package/dist/proxy/server/webapi/index.d.ts +278 -0
  115. package/dist/proxy/server/webapi/index.js +32 -0
  116. package/dist/proxy/server/webapi/index.js.map +1 -0
  117. package/dist/responses/index.d.ts +650 -0
  118. package/dist/responses/index.js +930 -0
  119. package/dist/responses/index.js.map +1 -0
  120. package/dist/{retry-8Ch-WWgX.d.ts → retry-BDMo4AVu.d.ts} +1 -1
  121. package/dist/stream-S7nwQRqM.d.ts +1643 -0
  122. package/dist/types-CE4B7pno.d.ts +96 -0
  123. package/dist/utils/index.d.ts +53 -0
  124. package/dist/utils/index.js +7 -0
  125. package/dist/utils/index.js.map +1 -0
  126. package/dist/xai/index.d.ts +2 -1
  127. package/dist/xai/index.js +310 -310
  128. package/dist/xai/index.js.map +1 -1
  129. package/package.json +82 -4
  130. package/dist/chunk-4J6OFUKX.js.map +0 -1
  131. package/dist/chunk-6S222DHN.js.map +0 -1
  132. package/dist/chunk-ILR2D5PN.js.map +0 -1
  133. package/dist/chunk-TOJCZMVU.js.map +0 -1
  134. package/dist/chunk-WAKD3OO5.js.map +0 -1
  135. /package/dist/{chunk-3D6XGGVG.js.map → chunk-ARVM24K2.js.map} +0 -0
  136. /package/dist/{chunk-KUPF5KHT.js.map → chunk-Y5H7C5J4.js.map} +0 -0
@@ -0,0 +1,67 @@
1
+ import { P as PubSubAdapter } from '../../../../types-CE4B7pno.js';
2
+ import '../../../../stream-S7nwQRqM.js';
3
+
4
+ /**
5
+ * @fileoverview Fastify adapter for pub-sub stream resumption.
6
+ *
7
+ * Provides utilities for Fastify servers to handle stream reconnections.
8
+ *
9
+ * @module middleware/pubsub/server/fastify
10
+ */
11
+
12
+ /**
13
+ * Fastify Reply interface (minimal type to avoid dependency).
14
+ */
15
+ interface FastifyReply {
16
+ raw: {
17
+ setHeader(name: string, value: string): void;
18
+ write(chunk: string): boolean;
19
+ end(): void;
20
+ on(event: 'close', listener: () => void): void;
21
+ };
22
+ }
23
+ /**
24
+ * Stream buffered and live events to a Fastify reply.
25
+ *
26
+ * Handles reconnection for Fastify routes:
27
+ * 1. Replays buffered events from the adapter
28
+ * 2. Subscribes to live events until completion signal
29
+ * 3. Ends when stream completes or client disconnects
30
+ *
31
+ * @param streamId - The stream ID to subscribe to
32
+ * @param adapter - The pub-sub adapter instance
33
+ * @param reply - Fastify reply object
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { llm } from '@providerprotocol/ai';
38
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
39
+ * import { pubsubMiddleware, memoryAdapter } from '@providerprotocol/ai/middleware/pubsub';
40
+ * import { fastify as pubsubFastify } from '@providerprotocol/ai/middleware/pubsub/server';
41
+ *
42
+ * const adapter = memoryAdapter();
43
+ *
44
+ * app.post('/api/chat', async (request, reply) => {
45
+ * const { input, conversationId } = request.body as { input: string; conversationId: string };
46
+ *
47
+ * if (!await adapter.exists(conversationId)) {
48
+ * const model = llm({
49
+ * model: anthropic('claude-sonnet-4-20250514'),
50
+ * middleware: [pubsubMiddleware({ adapter, streamId: conversationId })],
51
+ * });
52
+ * model.stream(input).then(turn => saveToDatabase(conversationId, turn));
53
+ * }
54
+ *
55
+ * return pubsubFastify.streamSubscriber(conversationId, adapter, reply);
56
+ * });
57
+ * ```
58
+ */
59
+ declare function streamSubscriber(streamId: string, adapter: PubSubAdapter, reply: FastifyReply): Promise<void>;
60
+ /**
61
+ * Fastify adapter namespace for pub-sub server utilities.
62
+ */
63
+ declare const fastify: {
64
+ streamSubscriber: typeof streamSubscriber;
65
+ };
66
+
67
+ export { fastify, streamSubscriber };
@@ -0,0 +1,11 @@
1
+ import {
2
+ fastify,
3
+ streamSubscriber
4
+ } from "../../../../chunk-CRP6Y7NF.js";
5
+ import "../../../../chunk-EPB3GQNL.js";
6
+ import "../../../../chunk-ETBFOLQN.js";
7
+ export {
8
+ fastify,
9
+ streamSubscriber
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,70 @@
1
+ import { P as PubSubAdapter } from '../../../../types-CE4B7pno.js';
2
+ import '../../../../stream-S7nwQRqM.js';
3
+
4
+ /**
5
+ * @fileoverview H3/Nitro/Nuxt adapter for pub-sub stream resumption.
6
+ *
7
+ * Provides utilities for H3-based servers (Nuxt, Nitro, or standalone H3)
8
+ * to handle stream reconnections.
9
+ *
10
+ * @module middleware/pubsub/server/h3
11
+ */
12
+
13
+ /**
14
+ * H3 Event interface (minimal type to avoid dependency).
15
+ */
16
+ interface H3Event {
17
+ node: {
18
+ res: {
19
+ setHeader(name: string, value: string): void;
20
+ write(chunk: string): boolean;
21
+ end(): void;
22
+ on(event: 'close', listener: () => void): void;
23
+ };
24
+ };
25
+ }
26
+ /**
27
+ * Stream buffered and live events to an H3 event response.
28
+ *
29
+ * Handles reconnection for H3/Nuxt routes:
30
+ * 1. Replays buffered events from the adapter
31
+ * 2. Subscribes to live events until completion signal
32
+ * 3. Ends when stream completes or client disconnects
33
+ *
34
+ * @param streamId - The stream ID to subscribe to
35
+ * @param adapter - The pub-sub adapter instance
36
+ * @param event - H3 event object
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { llm } from '@providerprotocol/ai';
41
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
42
+ * import { pubsubMiddleware, memoryAdapter } from '@providerprotocol/ai/middleware/pubsub';
43
+ * import { h3 } from '@providerprotocol/ai/middleware/pubsub/server';
44
+ *
45
+ * const adapter = memoryAdapter();
46
+ *
47
+ * export default defineEventHandler(async (event) => {
48
+ * const { input, conversationId } = await readBody(event);
49
+ *
50
+ * if (!await adapter.exists(conversationId)) {
51
+ * const model = llm({
52
+ * model: anthropic('claude-sonnet-4-20250514'),
53
+ * middleware: [pubsubMiddleware({ adapter, streamId: conversationId })],
54
+ * });
55
+ * model.stream(input).then(turn => saveToDatabase(conversationId, turn));
56
+ * }
57
+ *
58
+ * return h3.streamSubscriber(conversationId, adapter, event);
59
+ * });
60
+ * ```
61
+ */
62
+ declare function streamSubscriber(streamId: string, adapter: PubSubAdapter, event: H3Event): Promise<void>;
63
+ /**
64
+ * H3 adapter namespace for pub-sub server utilities.
65
+ */
66
+ declare const h3: {
67
+ streamSubscriber: typeof streamSubscriber;
68
+ };
69
+
70
+ export { h3, streamSubscriber };
@@ -0,0 +1,11 @@
1
+ import {
2
+ h3,
3
+ streamSubscriber
4
+ } from "../../../../chunk-4RX4VQCB.js";
5
+ import "../../../../chunk-EPB3GQNL.js";
6
+ import "../../../../chunk-ETBFOLQN.js";
7
+ export {
8
+ h3,
9
+ streamSubscriber
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,78 @@
1
+ import { streamSubscriber as streamSubscriber$2 } from './h3/index.js';
2
+ export { h3 } from './h3/index.js';
3
+ import { streamSubscriber as streamSubscriber$1 } from './fastify/index.js';
4
+ export { fastify } from './fastify/index.js';
5
+ import { streamSubscriber } from './express/index.js';
6
+ export { express } from './express/index.js';
7
+ import { createSubscriberStream } from './webapi/index.js';
8
+ export { webapi } from './webapi/index.js';
9
+ export { P as PubSubAdapter } from '../../../types-CE4B7pno.js';
10
+ import '../../../stream-S7nwQRqM.js';
11
+
12
+ /**
13
+ * Server adapters namespace for pub-sub stream resumption.
14
+ *
15
+ * Contains framework-specific adapters for Web API, Express, Fastify, and H3.
16
+ *
17
+ * @example Web API (Next.js App Router, Bun, Deno)
18
+ * ```typescript
19
+ * import { webapi } from '@providerprotocol/ai/middleware/pubsub/server';
20
+ *
21
+ * export async function POST(req: Request) {
22
+ * const { streamId } = await req.json();
23
+ * return new Response(webapi.createSubscriberStream(streamId, adapter), {
24
+ * headers: { 'Content-Type': 'text/event-stream' },
25
+ * });
26
+ * }
27
+ * ```
28
+ *
29
+ * @example Express
30
+ * ```typescript
31
+ * import { express } from '@providerprotocol/ai/middleware/pubsub/server';
32
+ *
33
+ * app.post('/api/ai/reconnect', (req, res) => {
34
+ * const { streamId } = req.body;
35
+ * express.streamSubscriber(streamId, adapter, res);
36
+ * });
37
+ * ```
38
+ *
39
+ * @example Fastify
40
+ * ```typescript
41
+ * import { fastify } from '@providerprotocol/ai/middleware/pubsub/server';
42
+ *
43
+ * app.post('/api/ai/reconnect', (request, reply) => {
44
+ * const { streamId } = request.body;
45
+ * return fastify.streamSubscriber(streamId, adapter, reply);
46
+ * });
47
+ * ```
48
+ *
49
+ * @example H3/Nuxt
50
+ * ```typescript
51
+ * import { h3 } from '@providerprotocol/ai/middleware/pubsub/server';
52
+ *
53
+ * export default defineEventHandler(async (event) => {
54
+ * const { streamId } = await readBody(event);
55
+ * return h3.streamSubscriber(streamId, adapter, event);
56
+ * });
57
+ * ```
58
+ */
59
+ declare const server: {
60
+ /** Web API adapter (Bun, Deno, Next.js, Workers) */
61
+ webapi: {
62
+ createSubscriberStream: typeof createSubscriberStream;
63
+ };
64
+ /** Express/Connect adapter */
65
+ express: {
66
+ streamSubscriber: typeof streamSubscriber;
67
+ };
68
+ /** Fastify adapter */
69
+ fastify: {
70
+ streamSubscriber: typeof streamSubscriber$1;
71
+ };
72
+ /** H3/Nitro/Nuxt adapter */
73
+ h3: {
74
+ streamSubscriber: typeof streamSubscriber$2;
75
+ };
76
+ };
77
+
78
+ export { server };
@@ -0,0 +1,34 @@
1
+ import {
2
+ webapi
3
+ } from "../../../chunk-2YXFLRQ6.js";
4
+ import {
5
+ express
6
+ } from "../../../chunk-5IWHCXKN.js";
7
+ import {
8
+ h3
9
+ } from "../../../chunk-4RX4VQCB.js";
10
+ import {
11
+ fastify
12
+ } from "../../../chunk-CRP6Y7NF.js";
13
+ import "../../../chunk-EPB3GQNL.js";
14
+ import "../../../chunk-ETBFOLQN.js";
15
+
16
+ // src/middleware/pubsub/server/index.ts
17
+ var server = {
18
+ /** Web API adapter (Bun, Deno, Next.js, Workers) */
19
+ webapi,
20
+ /** Express/Connect adapter */
21
+ express,
22
+ /** Fastify adapter */
23
+ fastify,
24
+ /** H3/Nitro/Nuxt adapter */
25
+ h3
26
+ };
27
+ export {
28
+ express,
29
+ fastify,
30
+ h3,
31
+ server,
32
+ webapi
33
+ };
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/middleware/pubsub/server/index.ts"],"sourcesContent":["/**\n * @fileoverview Framework adapters for pub-sub stream resumption.\n *\n * Provides framework-specific adapters for handling stream reconnections\n * with various server frameworks. The Web API adapter works with modern\n * frameworks like Bun, Deno, Next.js App Router, and Cloudflare Workers.\n * Additional adapters provide native integration for Express, Fastify, and H3/Nuxt.\n *\n * @module middleware/pubsub/server\n */\n\nimport { express } from './express.ts';\nimport { fastify } from './fastify.ts';\nimport { h3 } from './h3.ts';\nimport { webapi } from './webapi.ts';\n\nexport { express, fastify, h3, webapi };\nexport type { PubSubAdapter } from '../types.ts';\n\n/**\n * Server adapters namespace for pub-sub stream resumption.\n *\n * Contains framework-specific adapters for Web API, Express, Fastify, and H3.\n *\n * @example Web API (Next.js App Router, Bun, Deno)\n * ```typescript\n * import { webapi } from '@providerprotocol/ai/middleware/pubsub/server';\n *\n * export async function POST(req: Request) {\n * const { streamId } = await req.json();\n * return new Response(webapi.createSubscriberStream(streamId, adapter), {\n * headers: { 'Content-Type': 'text/event-stream' },\n * });\n * }\n * ```\n *\n * @example Express\n * ```typescript\n * import { express } from '@providerprotocol/ai/middleware/pubsub/server';\n *\n * app.post('/api/ai/reconnect', (req, res) => {\n * const { streamId } = req.body;\n * express.streamSubscriber(streamId, adapter, res);\n * });\n * ```\n *\n * @example Fastify\n * ```typescript\n * import { fastify } from '@providerprotocol/ai/middleware/pubsub/server';\n *\n * app.post('/api/ai/reconnect', (request, reply) => {\n * const { streamId } = request.body;\n * return fastify.streamSubscriber(streamId, adapter, reply);\n * });\n * ```\n *\n * @example H3/Nuxt\n * ```typescript\n * import { h3 } from '@providerprotocol/ai/middleware/pubsub/server';\n *\n * export default defineEventHandler(async (event) => {\n * const { streamId } = await readBody(event);\n * return h3.streamSubscriber(streamId, adapter, event);\n * });\n * ```\n */\nexport const server = {\n /** Web API adapter (Bun, Deno, Next.js, Workers) */\n webapi,\n /** Express/Connect adapter */\n express,\n /** Fastify adapter */\n fastify,\n /** H3/Nitro/Nuxt adapter */\n h3,\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAkEO,IAAM,SAAS;AAAA;AAAA,EAEpB;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AACF;","names":[]}
@@ -0,0 +1,63 @@
1
+ import { P as PubSubAdapter } from '../../../../types-CE4B7pno.js';
2
+ import '../../../../stream-S7nwQRqM.js';
3
+
4
+ /**
5
+ * @fileoverview Web API adapter for pub-sub stream resumption.
6
+ *
7
+ * Provides utilities for Web API native frameworks (Bun, Deno, Next.js App Router,
8
+ * Cloudflare Workers) to handle stream reconnections.
9
+ *
10
+ * @module middleware/pubsub/server/webapi
11
+ */
12
+
13
+ /**
14
+ * Creates a ReadableStream that replays buffered events and subscribes to live events.
15
+ *
16
+ * Handles reconnection for Web API frameworks (Bun, Deno, Next.js, Cloudflare Workers):
17
+ * 1. Replays buffered events from the adapter
18
+ * 2. Subscribes to live events until completion signal
19
+ * 3. Closes when stream completes or client disconnects
20
+ *
21
+ * @param streamId - The stream ID to subscribe to
22
+ * @param adapter - The pub-sub adapter instance
23
+ * @returns A ReadableStream of SSE-formatted data
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { llm } from '@providerprotocol/ai';
28
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
29
+ * import { pubsubMiddleware, memoryAdapter } from '@providerprotocol/ai/middleware/pubsub';
30
+ * import { webapi } from '@providerprotocol/ai/middleware/pubsub/server';
31
+ *
32
+ * const adapter = memoryAdapter();
33
+ *
34
+ * // Next.js App Router / Bun.serve / Deno.serve
35
+ * export async function POST(req: Request) {
36
+ * const { input, conversationId } = await req.json();
37
+ *
38
+ * if (!await adapter.exists(conversationId)) {
39
+ * const model = llm({
40
+ * model: anthropic('claude-sonnet-4-20250514'),
41
+ * middleware: [pubsubMiddleware({ adapter, streamId: conversationId })],
42
+ * });
43
+ * model.stream(input).then(turn => saveToDatabase(conversationId, turn));
44
+ * }
45
+ *
46
+ * return new Response(webapi.createSubscriberStream(conversationId, adapter), {
47
+ * headers: {
48
+ * 'Content-Type': 'text/event-stream',
49
+ * 'Cache-Control': 'no-cache',
50
+ * },
51
+ * });
52
+ * }
53
+ * ```
54
+ */
55
+ declare function createSubscriberStream(streamId: string, adapter: PubSubAdapter): ReadableStream<Uint8Array>;
56
+ /**
57
+ * Web API adapter namespace for pub-sub server utilities.
58
+ */
59
+ declare const webapi: {
60
+ createSubscriberStream: typeof createSubscriberStream;
61
+ };
62
+
63
+ export { createSubscriberStream, webapi };
@@ -0,0 +1,11 @@
1
+ import {
2
+ createSubscriberStream,
3
+ webapi
4
+ } from "../../../../chunk-2YXFLRQ6.js";
5
+ import "../../../../chunk-EPB3GQNL.js";
6
+ import "../../../../chunk-ETBFOLQN.js";
7
+ export {
8
+ createSubscriberStream,
9
+ webapi
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,4 +1,5 @@
1
- import { P as Provider } from '../llm-BQJZj3cD.js';
1
+ import { d as Provider } from '../llm-ByUFPcFH.js';
2
+ import '../stream-S7nwQRqM.js';
2
3
 
3
4
  /**
4
5
  * @fileoverview Type definitions for the Ollama provider.
@@ -1,59 +1,35 @@
1
1
  import {
2
2
  parseJsonResponse
3
- } from "../chunk-3C7O2RNO.js";
3
+ } from "../chunk-A2IM7PGT.js";
4
4
  import {
5
- StreamEventType,
6
- objectDelta
7
- } from "../chunk-6S222DHN.js";
5
+ resolveApiKey
6
+ } from "../chunk-ARVM24K2.js";
7
+ import {
8
+ createProvider
9
+ } from "../chunk-JA3UZALR.js";
8
10
  import {
9
11
  AssistantMessage,
10
- createProvider,
11
12
  isAssistantMessage,
12
13
  isToolResultMessage,
13
14
  isUserMessage
14
- } from "../chunk-ILR2D5PN.js";
15
+ } from "../chunk-BRP5XJ6Q.js";
15
16
  import {
16
- resolveApiKey
17
- } from "../chunk-3D6XGGVG.js";
18
- import {
19
- ErrorCode,
20
- ModalityType,
21
- UPPError,
22
17
  doFetch,
23
18
  doStreamFetch,
24
19
  normalizeHttpError,
25
20
  toError
26
- } from "../chunk-4J6OFUKX.js";
21
+ } from "../chunk-AY55T37A.js";
22
+ import {
23
+ ErrorCode,
24
+ ModalityType,
25
+ UPPError
26
+ } from "../chunk-COS4ON4G.js";
27
+ import {
28
+ StreamEventType,
29
+ objectDelta
30
+ } from "../chunk-RJGTRQ47.js";
27
31
 
28
32
  // src/providers/ollama/transform.ts
29
- function transformRequest(request, modelId) {
30
- const params = request.params ?? {};
31
- const {
32
- keep_alive,
33
- think,
34
- logprobs,
35
- top_logprobs,
36
- ...optionsParams
37
- } = params;
38
- const ollamaRequest = {
39
- model: modelId,
40
- messages: transformMessages(request.messages, request.system)
41
- };
42
- if (keep_alive !== void 0) ollamaRequest.keep_alive = keep_alive;
43
- if (think !== void 0) ollamaRequest.think = think;
44
- if (logprobs !== void 0) ollamaRequest.logprobs = logprobs;
45
- if (top_logprobs !== void 0) ollamaRequest.top_logprobs = top_logprobs;
46
- if (Object.keys(optionsParams).length > 0) {
47
- ollamaRequest.options = optionsParams;
48
- }
49
- if (request.tools && request.tools.length > 0) {
50
- ollamaRequest.tools = request.tools.map(transformTool);
51
- }
52
- if (request.structure) {
53
- ollamaRequest.format = request.structure;
54
- }
55
- return ollamaRequest;
56
- }
57
33
  function normalizeSystem(system) {
58
34
  if (system === void 0 || system === null) return void 0;
59
35
  if (typeof system === "string") return system;
@@ -170,6 +146,34 @@ function transformTool(tool) {
170
146
  }
171
147
  };
172
148
  }
149
+ function transformRequest(request, modelId) {
150
+ const params = request.params ?? {};
151
+ const {
152
+ keep_alive,
153
+ think,
154
+ logprobs,
155
+ top_logprobs,
156
+ ...optionsParams
157
+ } = params;
158
+ const ollamaRequest = {
159
+ model: modelId,
160
+ messages: transformMessages(request.messages, request.system)
161
+ };
162
+ if (keep_alive !== void 0) ollamaRequest.keep_alive = keep_alive;
163
+ if (think !== void 0) ollamaRequest.think = think;
164
+ if (logprobs !== void 0) ollamaRequest.logprobs = logprobs;
165
+ if (top_logprobs !== void 0) ollamaRequest.top_logprobs = top_logprobs;
166
+ if (Object.keys(optionsParams).length > 0) {
167
+ ollamaRequest.options = optionsParams;
168
+ }
169
+ if (request.tools && request.tools.length > 0) {
170
+ ollamaRequest.tools = request.tools.map(transformTool);
171
+ }
172
+ if (request.structure) {
173
+ ollamaRequest.format = request.structure;
174
+ }
175
+ return ollamaRequest;
176
+ }
173
177
  function transformResponse(data) {
174
178
  const content = [];
175
179
  const toolCalls = [];
@@ -462,7 +466,7 @@ function createLLMHandler() {
462
466
  "Content-Type": "application/json"
463
467
  };
464
468
  if (apiKey) {
465
- headers["Authorization"] = `Bearer ${apiKey}`;
469
+ headers.Authorization = `Bearer ${apiKey}`;
466
470
  }
467
471
  if (request.config.headers) {
468
472
  for (const [key, value] of Object.entries(request.config.headers)) {
@@ -514,7 +518,7 @@ function createLLMHandler() {
514
518
  "Content-Type": "application/json"
515
519
  };
516
520
  if (apiKey) {
517
- headers["Authorization"] = `Bearer ${apiKey}`;
521
+ headers.Authorization = `Bearer ${apiKey}`;
518
522
  }
519
523
  if (request.config.headers) {
520
524
  for (const [key, value] of Object.entries(request.config.headers)) {
@@ -563,10 +567,9 @@ function createLLMHandler() {
563
567
  }
564
568
  const events = transformStreamChunk(chunk, state);
565
569
  for (const event of events) {
570
+ yield event;
566
571
  if (request.structure && event.type === StreamEventType.TextDelta) {
567
572
  yield objectDelta(event.delta.text ?? "", event.index);
568
- } else {
569
- yield event;
570
573
  }
571
574
  }
572
575
  }