@providerprotocol/ai 0.0.34 → 0.0.35
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 +542 -3
- package/dist/anthropic/index.d.ts +2 -1
- package/dist/anthropic/index.js +151 -145
- package/dist/anthropic/index.js.map +1 -1
- package/dist/cerebras/index.d.ts +392 -0
- package/dist/cerebras/index.js +648 -0
- package/dist/cerebras/index.js.map +1 -0
- package/dist/chunk-3GWM5GR3.js +153 -0
- package/dist/chunk-3GWM5GR3.js.map +1 -0
- package/dist/chunk-4OGB7JZA.js +157 -0
- package/dist/chunk-4OGB7JZA.js.map +1 -0
- package/dist/chunk-7DXVRILR.js +49 -0
- package/dist/chunk-7DXVRILR.js.map +1 -0
- package/dist/{chunk-3C7O2RNO.js → chunk-A2IM7PGT.js} +6 -4
- package/dist/{chunk-3C7O2RNO.js.map → chunk-A2IM7PGT.js.map} +1 -1
- package/dist/{chunk-3D6XGGVG.js → chunk-ARVM24K2.js} +2 -2
- package/dist/{chunk-4J6OFUKX.js → chunk-AY55T37A.js} +70 -162
- package/dist/chunk-AY55T37A.js.map +1 -0
- package/dist/{chunk-ILR2D5PN.js → chunk-BRP5XJ6Q.js} +2 -86
- package/dist/chunk-BRP5XJ6Q.js.map +1 -0
- package/dist/chunk-C4JP64VW.js +298 -0
- package/dist/chunk-C4JP64VW.js.map +1 -0
- package/dist/chunk-COS4ON4G.js +111 -0
- package/dist/chunk-COS4ON4G.js.map +1 -0
- package/dist/chunk-ETBFOLQN.js +34 -0
- package/dist/chunk-ETBFOLQN.js.map +1 -0
- package/dist/chunk-HB4ZIH3T.js +31 -0
- package/dist/chunk-HB4ZIH3T.js.map +1 -0
- package/dist/chunk-I53CI6ZZ.js +142 -0
- package/dist/chunk-I53CI6ZZ.js.map +1 -0
- package/dist/chunk-IDZOVWP3.js +29 -0
- package/dist/chunk-IDZOVWP3.js.map +1 -0
- package/dist/chunk-JA3UZALR.js +88 -0
- package/dist/chunk-JA3UZALR.js.map +1 -0
- package/dist/{chunk-WAKD3OO5.js → chunk-N5DX5JW3.js} +31 -31
- package/dist/chunk-N5DX5JW3.js.map +1 -0
- package/dist/chunk-OIEWDFQU.js +97 -0
- package/dist/chunk-OIEWDFQU.js.map +1 -0
- package/dist/{chunk-TOJCZMVU.js → chunk-PMK5LZ5Z.js} +40 -40
- package/dist/chunk-PMK5LZ5Z.js.map +1 -0
- package/dist/chunk-UFFJDYCE.js +94 -0
- package/dist/chunk-UFFJDYCE.js.map +1 -0
- package/dist/chunk-VGKZIGVI.js +222 -0
- package/dist/chunk-VGKZIGVI.js.map +1 -0
- package/dist/chunk-VOEWHQUB.js +31 -0
- package/dist/chunk-VOEWHQUB.js.map +1 -0
- package/dist/{chunk-KUPF5KHT.js → chunk-Y5H7C5J4.js} +2 -2
- package/dist/chunk-ZI67WIQS.js +30 -0
- package/dist/chunk-ZI67WIQS.js.map +1 -0
- package/dist/{embedding-D2BYIehX.d.ts → embedding-CW6SaOOz.d.ts} +1 -1
- package/dist/google/index.d.ts +2 -1
- package/dist/google/index.js +202 -199
- package/dist/google/index.js.map +1 -1
- package/dist/groq/index.d.ts +410 -0
- package/dist/groq/index.js +649 -0
- package/dist/groq/index.js.map +1 -0
- package/dist/http/index.d.ts +3 -2
- package/dist/http/index.js +5 -4
- package/dist/image-stream-C0ciACM2.d.ts +11 -0
- package/dist/index.d.ts +8 -118
- package/dist/index.js +518 -767
- package/dist/index.js.map +1 -1
- package/dist/{llm-BQJZj3cD.d.ts → llm-DwbUK7un.d.ts} +12 -1632
- package/dist/middleware/logging/index.d.ts +76 -0
- package/dist/middleware/logging/index.js +74 -0
- package/dist/middleware/logging/index.js.map +1 -0
- package/dist/middleware/parsed-object/index.d.ts +45 -0
- package/dist/middleware/parsed-object/index.js +73 -0
- package/dist/middleware/parsed-object/index.js.map +1 -0
- package/dist/middleware/pubsub/index.d.ts +104 -0
- package/dist/middleware/pubsub/index.js +230 -0
- package/dist/middleware/pubsub/index.js.map +1 -0
- package/dist/middleware/pubsub/server/express/index.d.ts +52 -0
- package/dist/middleware/pubsub/server/express/index.js +11 -0
- package/dist/middleware/pubsub/server/express/index.js.map +1 -0
- package/dist/middleware/pubsub/server/fastify/index.d.ts +53 -0
- package/dist/middleware/pubsub/server/fastify/index.js +11 -0
- package/dist/middleware/pubsub/server/fastify/index.js.map +1 -0
- package/dist/middleware/pubsub/server/h3/index.d.ts +56 -0
- package/dist/middleware/pubsub/server/h3/index.js +11 -0
- package/dist/middleware/pubsub/server/h3/index.js.map +1 -0
- package/dist/middleware/pubsub/server/index.d.ts +78 -0
- package/dist/middleware/pubsub/server/index.js +34 -0
- package/dist/middleware/pubsub/server/index.js.map +1 -0
- package/dist/middleware/pubsub/server/webapi/index.d.ts +53 -0
- package/dist/middleware/pubsub/server/webapi/index.js +11 -0
- package/dist/middleware/pubsub/server/webapi/index.js.map +1 -0
- package/dist/ollama/index.d.ts +2 -1
- package/dist/ollama/index.js +48 -45
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +2 -1
- package/dist/openai/index.js +319 -313
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +2 -1
- package/dist/openrouter/index.js +379 -383
- package/dist/openrouter/index.js.map +1 -1
- package/dist/proxy/index.d.ts +10 -914
- package/dist/proxy/index.js +275 -1007
- package/dist/proxy/index.js.map +1 -1
- package/dist/proxy/server/express/index.d.ts +161 -0
- package/dist/proxy/server/express/index.js +24 -0
- package/dist/proxy/server/express/index.js.map +1 -0
- package/dist/proxy/server/fastify/index.d.ts +162 -0
- package/dist/proxy/server/fastify/index.js +24 -0
- package/dist/proxy/server/fastify/index.js.map +1 -0
- package/dist/proxy/server/h3/index.d.ts +189 -0
- package/dist/proxy/server/h3/index.js +28 -0
- package/dist/proxy/server/h3/index.js.map +1 -0
- package/dist/proxy/server/index.d.ts +151 -0
- package/dist/proxy/server/index.js +48 -0
- package/dist/proxy/server/index.js.map +1 -0
- package/dist/proxy/server/webapi/index.d.ts +278 -0
- package/dist/proxy/server/webapi/index.js +32 -0
- package/dist/proxy/server/webapi/index.js.map +1 -0
- package/dist/responses/index.d.ts +650 -0
- package/dist/responses/index.js +930 -0
- package/dist/responses/index.js.map +1 -0
- package/dist/{retry-8Ch-WWgX.d.ts → retry-YayV42GV.d.ts} +1 -1
- package/dist/stream-CecfVCPO.d.ts +1632 -0
- package/dist/types-C8Gciizr.d.ts +168 -0
- package/dist/utils/index.d.ts +53 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/xai/index.d.ts +2 -1
- package/dist/xai/index.js +310 -310
- package/dist/xai/index.js.map +1 -1
- package/package.json +82 -4
- package/dist/chunk-4J6OFUKX.js.map +0 -1
- package/dist/chunk-ILR2D5PN.js.map +0 -1
- package/dist/chunk-TOJCZMVU.js.map +0 -1
- package/dist/chunk-WAKD3OO5.js.map +0 -1
- /package/dist/{chunk-3D6XGGVG.js.map → chunk-ARVM24K2.js.map} +0 -0
- /package/dist/{chunk-KUPF5KHT.js.map → chunk-Y5H7C5J4.js.map} +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { P as PubSubAdapter } from '../../../../types-C8Gciizr.js';
|
|
2
|
+
import '../../../../stream-CecfVCPO.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Express/Connect adapter for pub-sub stream resumption.
|
|
6
|
+
*
|
|
7
|
+
* Provides utilities for Express.js or Connect-based servers
|
|
8
|
+
* to handle stream reconnections.
|
|
9
|
+
*
|
|
10
|
+
* @module middleware/pubsub/server/express
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Express Response interface (minimal type to avoid dependency).
|
|
15
|
+
*/
|
|
16
|
+
interface ExpressResponse {
|
|
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
|
+
* Stream buffered and live events to an Express response.
|
|
24
|
+
*
|
|
25
|
+
* This utility handles the reconnection pattern for Express routes:
|
|
26
|
+
* 1. Replays all buffered events from the adapter
|
|
27
|
+
* 2. If stream is already completed, ends immediately
|
|
28
|
+
* 3. Otherwise, subscribes to live events until completion
|
|
29
|
+
*
|
|
30
|
+
* @param streamId - The stream ID to subscribe to
|
|
31
|
+
* @param adapter - The pub-sub adapter instance
|
|
32
|
+
* @param res - Express response object
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { streamSubscriber } from '@providerprotocol/ai/middleware/pubsub/server/express';
|
|
37
|
+
*
|
|
38
|
+
* app.post('/api/ai/reconnect', async (req, res) => {
|
|
39
|
+
* const { streamId } = req.body;
|
|
40
|
+
* streamSubscriber(streamId, adapter, res);
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function streamSubscriber(streamId: string, adapter: PubSubAdapter, res: ExpressResponse): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Express adapter namespace for pub-sub server utilities.
|
|
47
|
+
*/
|
|
48
|
+
declare const express: {
|
|
49
|
+
streamSubscriber: typeof streamSubscriber;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { express, streamSubscriber };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { P as PubSubAdapter } from '../../../../types-C8Gciizr.js';
|
|
2
|
+
import '../../../../stream-CecfVCPO.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
|
+
* This utility handles the reconnection pattern for Fastify routes:
|
|
27
|
+
* 1. Replays all buffered events from the adapter
|
|
28
|
+
* 2. If stream is already completed, ends immediately
|
|
29
|
+
* 3. Otherwise, subscribes to live events until completion
|
|
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 { streamSubscriber } from '@providerprotocol/ai/middleware/pubsub/server/fastify';
|
|
38
|
+
*
|
|
39
|
+
* app.post('/api/ai/reconnect', async (request, reply) => {
|
|
40
|
+
* const { streamId } = request.body;
|
|
41
|
+
* return streamSubscriber(streamId, adapter, reply);
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function streamSubscriber(streamId: string, adapter: PubSubAdapter, reply: FastifyReply): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Fastify adapter namespace for pub-sub server utilities.
|
|
48
|
+
*/
|
|
49
|
+
declare const fastify: {
|
|
50
|
+
streamSubscriber: typeof streamSubscriber;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { fastify, streamSubscriber };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { P as PubSubAdapter } from '../../../../types-C8Gciizr.js';
|
|
2
|
+
import '../../../../stream-CecfVCPO.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
|
+
* This utility handles the reconnection pattern for H3/Nuxt routes:
|
|
30
|
+
* 1. Replays all buffered events from the adapter
|
|
31
|
+
* 2. If stream is already completed, ends immediately
|
|
32
|
+
* 3. Otherwise, subscribes to live events until completion
|
|
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 { streamSubscriber } from '@providerprotocol/ai/middleware/pubsub/server/h3';
|
|
41
|
+
*
|
|
42
|
+
* export default defineEventHandler(async (event) => {
|
|
43
|
+
* const { streamId } = await readBody(event);
|
|
44
|
+
* return streamSubscriber(streamId, adapter, event);
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function streamSubscriber(streamId: string, adapter: PubSubAdapter, event: H3Event): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* H3 adapter namespace for pub-sub server utilities.
|
|
51
|
+
*/
|
|
52
|
+
declare const h3: {
|
|
53
|
+
streamSubscriber: typeof streamSubscriber;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { h3, streamSubscriber };
|
|
@@ -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-C8Gciizr.js';
|
|
10
|
+
import '../../../stream-CecfVCPO.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-7DXVRILR.js";
|
|
4
|
+
import {
|
|
5
|
+
express
|
|
6
|
+
} from "../../../chunk-ZI67WIQS.js";
|
|
7
|
+
import {
|
|
8
|
+
h3
|
|
9
|
+
} from "../../../chunk-HB4ZIH3T.js";
|
|
10
|
+
import {
|
|
11
|
+
fastify
|
|
12
|
+
} from "../../../chunk-VOEWHQUB.js";
|
|
13
|
+
import "../../../chunk-3GWM5GR3.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,53 @@
|
|
|
1
|
+
import { P as PubSubAdapter } from '../../../../types-C8Gciizr.js';
|
|
2
|
+
import '../../../../stream-CecfVCPO.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
|
+
* This utility handles the reconnection pattern for server routes:
|
|
17
|
+
* 1. Replays all buffered events from the adapter
|
|
18
|
+
* 2. If stream is already completed, closes immediately
|
|
19
|
+
* 3. Otherwise, subscribes to live events until completion
|
|
20
|
+
*
|
|
21
|
+
* Works with any framework that supports web standard ReadableStream.
|
|
22
|
+
*
|
|
23
|
+
* @param streamId - The stream ID to subscribe to
|
|
24
|
+
* @param adapter - The pub-sub adapter instance
|
|
25
|
+
* @returns A ReadableStream of SSE-formatted data
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { createSubscriberStream } from '@providerprotocol/ai/middleware/pubsub/server/webapi';
|
|
30
|
+
*
|
|
31
|
+
* // Next.js App Router
|
|
32
|
+
* export async function POST(req: Request) {
|
|
33
|
+
* const { streamId } = await req.json();
|
|
34
|
+
*
|
|
35
|
+
* return new Response(createSubscriberStream(streamId, adapter), {
|
|
36
|
+
* headers: {
|
|
37
|
+
* 'Content-Type': 'text/event-stream',
|
|
38
|
+
* 'Cache-Control': 'no-cache',
|
|
39
|
+
* 'Connection': 'keep-alive',
|
|
40
|
+
* },
|
|
41
|
+
* });
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function createSubscriberStream(streamId: string, adapter: PubSubAdapter): ReadableStream<Uint8Array>;
|
|
46
|
+
/**
|
|
47
|
+
* Web API adapter namespace for pub-sub server utilities.
|
|
48
|
+
*/
|
|
49
|
+
declare const webapi: {
|
|
50
|
+
createSubscriberStream: typeof createSubscriberStream;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { createSubscriberStream, webapi };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/ollama/index.d.ts
CHANGED
package/dist/ollama/index.js
CHANGED
|
@@ -1,59 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseJsonResponse
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-A2IM7PGT.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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-
|
|
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-
|
|
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-6S222DHN.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
|
|
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
|
|
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
|
}
|