@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.
Files changed (133) hide show
  1. package/README.md +542 -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-3GWM5GR3.js +153 -0
  9. package/dist/chunk-3GWM5GR3.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-7DXVRILR.js +49 -0
  13. package/dist/chunk-7DXVRILR.js.map +1 -0
  14. package/dist/{chunk-3C7O2RNO.js → chunk-A2IM7PGT.js} +6 -4
  15. package/dist/{chunk-3C7O2RNO.js.map → chunk-A2IM7PGT.js.map} +1 -1
  16. package/dist/{chunk-3D6XGGVG.js → chunk-ARVM24K2.js} +2 -2
  17. package/dist/{chunk-4J6OFUKX.js → chunk-AY55T37A.js} +70 -162
  18. package/dist/chunk-AY55T37A.js.map +1 -0
  19. package/dist/{chunk-ILR2D5PN.js → chunk-BRP5XJ6Q.js} +2 -86
  20. package/dist/chunk-BRP5XJ6Q.js.map +1 -0
  21. package/dist/chunk-C4JP64VW.js +298 -0
  22. package/dist/chunk-C4JP64VW.js.map +1 -0
  23. package/dist/chunk-COS4ON4G.js +111 -0
  24. package/dist/chunk-COS4ON4G.js.map +1 -0
  25. package/dist/chunk-ETBFOLQN.js +34 -0
  26. package/dist/chunk-ETBFOLQN.js.map +1 -0
  27. package/dist/chunk-HB4ZIH3T.js +31 -0
  28. package/dist/chunk-HB4ZIH3T.js.map +1 -0
  29. package/dist/chunk-I53CI6ZZ.js +142 -0
  30. package/dist/chunk-I53CI6ZZ.js.map +1 -0
  31. package/dist/chunk-IDZOVWP3.js +29 -0
  32. package/dist/chunk-IDZOVWP3.js.map +1 -0
  33. package/dist/chunk-JA3UZALR.js +88 -0
  34. package/dist/chunk-JA3UZALR.js.map +1 -0
  35. package/dist/{chunk-WAKD3OO5.js → chunk-N5DX5JW3.js} +31 -31
  36. package/dist/chunk-N5DX5JW3.js.map +1 -0
  37. package/dist/chunk-OIEWDFQU.js +97 -0
  38. package/dist/chunk-OIEWDFQU.js.map +1 -0
  39. package/dist/{chunk-TOJCZMVU.js → chunk-PMK5LZ5Z.js} +40 -40
  40. package/dist/chunk-PMK5LZ5Z.js.map +1 -0
  41. package/dist/chunk-UFFJDYCE.js +94 -0
  42. package/dist/chunk-UFFJDYCE.js.map +1 -0
  43. package/dist/chunk-VGKZIGVI.js +222 -0
  44. package/dist/chunk-VGKZIGVI.js.map +1 -0
  45. package/dist/chunk-VOEWHQUB.js +31 -0
  46. package/dist/chunk-VOEWHQUB.js.map +1 -0
  47. package/dist/{chunk-KUPF5KHT.js → chunk-Y5H7C5J4.js} +2 -2
  48. package/dist/chunk-ZI67WIQS.js +30 -0
  49. package/dist/chunk-ZI67WIQS.js.map +1 -0
  50. package/dist/{embedding-D2BYIehX.d.ts → embedding-CW6SaOOz.d.ts} +1 -1
  51. package/dist/google/index.d.ts +2 -1
  52. package/dist/google/index.js +202 -199
  53. package/dist/google/index.js.map +1 -1
  54. package/dist/groq/index.d.ts +410 -0
  55. package/dist/groq/index.js +649 -0
  56. package/dist/groq/index.js.map +1 -0
  57. package/dist/http/index.d.ts +3 -2
  58. package/dist/http/index.js +5 -4
  59. package/dist/image-stream-C0ciACM2.d.ts +11 -0
  60. package/dist/index.d.ts +8 -118
  61. package/dist/index.js +518 -767
  62. package/dist/index.js.map +1 -1
  63. package/dist/{llm-BQJZj3cD.d.ts → llm-DwbUK7un.d.ts} +12 -1632
  64. package/dist/middleware/logging/index.d.ts +76 -0
  65. package/dist/middleware/logging/index.js +74 -0
  66. package/dist/middleware/logging/index.js.map +1 -0
  67. package/dist/middleware/parsed-object/index.d.ts +45 -0
  68. package/dist/middleware/parsed-object/index.js +73 -0
  69. package/dist/middleware/parsed-object/index.js.map +1 -0
  70. package/dist/middleware/pubsub/index.d.ts +104 -0
  71. package/dist/middleware/pubsub/index.js +230 -0
  72. package/dist/middleware/pubsub/index.js.map +1 -0
  73. package/dist/middleware/pubsub/server/express/index.d.ts +52 -0
  74. package/dist/middleware/pubsub/server/express/index.js +11 -0
  75. package/dist/middleware/pubsub/server/express/index.js.map +1 -0
  76. package/dist/middleware/pubsub/server/fastify/index.d.ts +53 -0
  77. package/dist/middleware/pubsub/server/fastify/index.js +11 -0
  78. package/dist/middleware/pubsub/server/fastify/index.js.map +1 -0
  79. package/dist/middleware/pubsub/server/h3/index.d.ts +56 -0
  80. package/dist/middleware/pubsub/server/h3/index.js +11 -0
  81. package/dist/middleware/pubsub/server/h3/index.js.map +1 -0
  82. package/dist/middleware/pubsub/server/index.d.ts +78 -0
  83. package/dist/middleware/pubsub/server/index.js +34 -0
  84. package/dist/middleware/pubsub/server/index.js.map +1 -0
  85. package/dist/middleware/pubsub/server/webapi/index.d.ts +53 -0
  86. package/dist/middleware/pubsub/server/webapi/index.js +11 -0
  87. package/dist/middleware/pubsub/server/webapi/index.js.map +1 -0
  88. package/dist/ollama/index.d.ts +2 -1
  89. package/dist/ollama/index.js +48 -45
  90. package/dist/ollama/index.js.map +1 -1
  91. package/dist/openai/index.d.ts +2 -1
  92. package/dist/openai/index.js +319 -313
  93. package/dist/openai/index.js.map +1 -1
  94. package/dist/openrouter/index.d.ts +2 -1
  95. package/dist/openrouter/index.js +379 -383
  96. package/dist/openrouter/index.js.map +1 -1
  97. package/dist/proxy/index.d.ts +10 -914
  98. package/dist/proxy/index.js +275 -1007
  99. package/dist/proxy/index.js.map +1 -1
  100. package/dist/proxy/server/express/index.d.ts +161 -0
  101. package/dist/proxy/server/express/index.js +24 -0
  102. package/dist/proxy/server/express/index.js.map +1 -0
  103. package/dist/proxy/server/fastify/index.d.ts +162 -0
  104. package/dist/proxy/server/fastify/index.js +24 -0
  105. package/dist/proxy/server/fastify/index.js.map +1 -0
  106. package/dist/proxy/server/h3/index.d.ts +189 -0
  107. package/dist/proxy/server/h3/index.js +28 -0
  108. package/dist/proxy/server/h3/index.js.map +1 -0
  109. package/dist/proxy/server/index.d.ts +151 -0
  110. package/dist/proxy/server/index.js +48 -0
  111. package/dist/proxy/server/index.js.map +1 -0
  112. package/dist/proxy/server/webapi/index.d.ts +278 -0
  113. package/dist/proxy/server/webapi/index.js +32 -0
  114. package/dist/proxy/server/webapi/index.js.map +1 -0
  115. package/dist/responses/index.d.ts +650 -0
  116. package/dist/responses/index.js +930 -0
  117. package/dist/responses/index.js.map +1 -0
  118. package/dist/{retry-8Ch-WWgX.d.ts → retry-YayV42GV.d.ts} +1 -1
  119. package/dist/stream-CecfVCPO.d.ts +1632 -0
  120. package/dist/types-C8Gciizr.d.ts +168 -0
  121. package/dist/utils/index.d.ts +53 -0
  122. package/dist/utils/index.js +7 -0
  123. package/dist/utils/index.js.map +1 -0
  124. package/dist/xai/index.d.ts +2 -1
  125. package/dist/xai/index.js +310 -310
  126. package/dist/xai/index.js.map +1 -1
  127. package/package.json +82 -4
  128. package/dist/chunk-4J6OFUKX.js.map +0 -1
  129. package/dist/chunk-ILR2D5PN.js.map +0 -1
  130. package/dist/chunk-TOJCZMVU.js.map +0 -1
  131. package/dist/chunk-WAKD3OO5.js.map +0 -1
  132. /package/dist/{chunk-3D6XGGVG.js.map → chunk-ARVM24K2.js.map} +0 -0
  133. /package/dist/{chunk-KUPF5KHT.js.map → chunk-Y5H7C5J4.js.map} +0 -0
@@ -0,0 +1,162 @@
1
+ import { T as Turn, i as StreamResult } from '../../../stream-CecfVCPO.js';
2
+ import { d as EmbeddingResult } from '../../../embedding-CW6SaOOz.js';
3
+ import { N as ImageResult } from '../../../llm-DwbUK7un.js';
4
+ import { I as ImageStreamLike } from '../../../image-stream-C0ciACM2.js';
5
+
6
+ /**
7
+ * @fileoverview Fastify adapter for proxy server.
8
+ *
9
+ * Provides utilities for using PP proxy with Fastify servers.
10
+ * These adapters convert PP types to Fastify-compatible responses.
11
+ *
12
+ * @module providers/proxy/server/fastify
13
+ */
14
+
15
+ /**
16
+ * Fastify Reply interface (minimal type to avoid dependency).
17
+ */
18
+ interface FastifyReply {
19
+ header(name: string, value: string): FastifyReply;
20
+ status(code: number): FastifyReply;
21
+ send(payload: unknown): FastifyReply;
22
+ raw: {
23
+ write(chunk: string): boolean;
24
+ end(): void;
25
+ };
26
+ }
27
+ /**
28
+ * Send a Turn as JSON response.
29
+ *
30
+ * @param turn - The completed inference turn
31
+ * @param reply - Fastify reply object
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const turn = await instance.generate(messages);
36
+ * return fastifyAdapter.sendJSON(turn, reply);
37
+ * ```
38
+ */
39
+ declare function sendJSON(turn: Turn, reply: FastifyReply): FastifyReply;
40
+ /**
41
+ * Send an EmbeddingResult as JSON response.
42
+ *
43
+ * @param result - The embedding result
44
+ * @param reply - Fastify reply object
45
+ */
46
+ declare function sendEmbeddingJSON(result: EmbeddingResult, reply: FastifyReply): FastifyReply;
47
+ /**
48
+ * Send an ImageResult as JSON response.
49
+ *
50
+ * @param result - The image result
51
+ * @param reply - Fastify reply object
52
+ */
53
+ declare function sendImageJSON(result: ImageResult, reply: FastifyReply): FastifyReply;
54
+ /**
55
+ * Stream a StreamResult as Server-Sent Events.
56
+ *
57
+ * @param stream - The StreamResult from instance.stream()
58
+ * @param reply - Fastify reply object
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const stream = instance.stream(messages);
63
+ * return fastifyAdapter.streamSSE(stream, reply);
64
+ * ```
65
+ */
66
+ declare function streamSSE(stream: StreamResult, reply: FastifyReply): FastifyReply;
67
+ /**
68
+ * Stream an ImageStreamResult as Server-Sent Events.
69
+ *
70
+ * @param stream - The ImageStreamResult or ImageProviderStreamResult from image().stream()
71
+ * @param reply - Fastify reply object
72
+ */
73
+ declare function streamImageSSE(stream: ImageStreamLike, reply: FastifyReply): FastifyReply;
74
+ /**
75
+ * Send an error response.
76
+ *
77
+ * @param message - Error message
78
+ * @param status - HTTP status code
79
+ * @param reply - Fastify reply object
80
+ */
81
+ declare function sendError(message: string, status: number, reply: FastifyReply): FastifyReply;
82
+ /**
83
+ * Fastify adapter utilities.
84
+ *
85
+ * @example Basic usage
86
+ * ```typescript
87
+ * import Fastify from 'fastify';
88
+ * import { llm } from '@providerprotocol/ai';
89
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
90
+ * import { parseBody } from '@providerprotocol/ai/proxy';
91
+ * import { fastify as fastifyAdapter } from '@providerprotocol/ai/proxy/server';
92
+ *
93
+ * const app = Fastify();
94
+ *
95
+ * app.post('/api/ai', async (request, reply) => {
96
+ * const { messages, system, params } = parseBody(request.body);
97
+ * const instance = llm({ model: anthropic('claude-sonnet-4-20250514'), system });
98
+ *
99
+ * if (request.headers.accept?.includes('text/event-stream')) {
100
+ * return fastifyAdapter.streamSSE(instance.stream(messages), reply);
101
+ * } else {
102
+ * const turn = await instance.generate(messages);
103
+ * return fastifyAdapter.sendJSON(turn, reply);
104
+ * }
105
+ * });
106
+ * ```
107
+ *
108
+ * @example API Gateway with authentication
109
+ * ```typescript
110
+ * import Fastify from 'fastify';
111
+ * import { llm } from '@providerprotocol/ai';
112
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
113
+ * import { ExponentialBackoff, RoundRobinKeys } from '@providerprotocol/ai/http';
114
+ * import { parseBody } from '@providerprotocol/ai/proxy';
115
+ * import { fastify as fastifyAdapter } from '@providerprotocol/ai/proxy/server';
116
+ *
117
+ * const app = Fastify();
118
+ *
119
+ * // Server manages AI provider keys - users never see them
120
+ * const claude = llm({
121
+ * model: anthropic('claude-sonnet-4-20250514'),
122
+ * config: {
123
+ * apiKey: new RoundRobinKeys([process.env.ANTHROPIC_KEY_1!, process.env.ANTHROPIC_KEY_2!]),
124
+ * retryStrategy: new ExponentialBackoff({ maxAttempts: 3 }),
125
+ * },
126
+ * });
127
+ *
128
+ * // Auth hook for your platform
129
+ * app.addHook('preHandler', async (request, reply) => {
130
+ * const token = request.headers.authorization?.replace('Bearer ', '');
131
+ * const user = await validatePlatformToken(token);
132
+ * if (!user) {
133
+ * reply.status(401).send({ error: 'Unauthorized' });
134
+ * return;
135
+ * }
136
+ * request.user = user;
137
+ * });
138
+ *
139
+ * app.post('/api/ai', async (request, reply) => {
140
+ * // Track usage per user
141
+ * // await trackUsage(request.user.id);
142
+ *
143
+ * const { messages, system, params } = parseBody(request.body);
144
+ *
145
+ * if (params?.stream) {
146
+ * return fastifyAdapter.streamSSE(claude.stream(messages, { system }), reply);
147
+ * }
148
+ * const turn = await claude.generate(messages, { system });
149
+ * return fastifyAdapter.sendJSON(turn, reply);
150
+ * });
151
+ * ```
152
+ */
153
+ declare const fastify: {
154
+ sendJSON: typeof sendJSON;
155
+ sendEmbeddingJSON: typeof sendEmbeddingJSON;
156
+ sendImageJSON: typeof sendImageJSON;
157
+ streamSSE: typeof streamSSE;
158
+ streamImageSSE: typeof streamImageSSE;
159
+ sendError: typeof sendError;
160
+ };
161
+
162
+ export { fastify, sendEmbeddingJSON, sendError, sendImageJSON, sendJSON, streamImageSSE, streamSSE };
@@ -0,0 +1,24 @@
1
+ import {
2
+ fastify,
3
+ sendEmbeddingJSON,
4
+ sendError,
5
+ sendImageJSON,
6
+ sendJSON,
7
+ streamImageSSE,
8
+ streamSSE
9
+ } from "../../../chunk-UFFJDYCE.js";
10
+ import "../../../chunk-C4JP64VW.js";
11
+ import "../../../chunk-ETBFOLQN.js";
12
+ import "../../../chunk-N5DX5JW3.js";
13
+ import "../../../chunk-BRP5XJ6Q.js";
14
+ import "../../../chunk-COS4ON4G.js";
15
+ export {
16
+ fastify,
17
+ sendEmbeddingJSON,
18
+ sendError,
19
+ sendImageJSON,
20
+ sendJSON,
21
+ streamImageSSE,
22
+ streamSSE
23
+ };
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,189 @@
1
+ import { T as Turn, i as StreamResult } from '../../../stream-CecfVCPO.js';
2
+ import { d as EmbeddingResult } from '../../../embedding-CW6SaOOz.js';
3
+ import { N as ImageResult } from '../../../llm-DwbUK7un.js';
4
+ import { I as ImageStreamLike } from '../../../image-stream-C0ciACM2.js';
5
+
6
+ /**
7
+ * @fileoverview H3/Nitro/Nuxt adapter for proxy server.
8
+ *
9
+ * Provides utilities for using PP proxy with H3-based servers
10
+ * (Nuxt, Nitro, or standalone H3).
11
+ *
12
+ * @module providers/proxy/server/h3
13
+ */
14
+
15
+ /**
16
+ * H3 Event interface (minimal type to avoid dependency).
17
+ */
18
+ interface H3Event {
19
+ node: {
20
+ res: {
21
+ setHeader(name: string, value: string): void;
22
+ write(chunk: string): boolean;
23
+ end(): void;
24
+ };
25
+ };
26
+ }
27
+ /**
28
+ * Send a Turn as JSON response.
29
+ *
30
+ * @param turn - The completed inference turn
31
+ * @param event - H3 event object
32
+ * @returns Serialized turn data
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const turn = await instance.generate(messages);
37
+ * return h3Adapter.sendJSON(turn, event);
38
+ * ```
39
+ */
40
+ declare function sendJSON(turn: Turn, event: H3Event): unknown;
41
+ /**
42
+ * Send an EmbeddingResult as JSON response.
43
+ *
44
+ * @param result - The embedding result
45
+ * @param event - H3 event object
46
+ * @returns Serialized result data
47
+ */
48
+ declare function sendEmbeddingJSON(result: EmbeddingResult, event: H3Event): unknown;
49
+ /**
50
+ * Send an ImageResult as JSON response.
51
+ *
52
+ * @param result - The image result
53
+ * @param event - H3 event object
54
+ * @returns Serialized image result data
55
+ */
56
+ declare function sendImageJSON(result: ImageResult, event: H3Event): unknown;
57
+ /**
58
+ * Stream a StreamResult as Server-Sent Events.
59
+ *
60
+ * @param stream - The StreamResult from instance.stream()
61
+ * @param event - H3 event object
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const stream = instance.stream(messages);
66
+ * return h3Adapter.streamSSE(stream, event);
67
+ * ```
68
+ */
69
+ declare function streamSSE(stream: StreamResult, event: H3Event): void;
70
+ /**
71
+ * Stream an ImageStreamResult as Server-Sent Events.
72
+ *
73
+ * @param stream - The ImageStreamResult or ImageProviderStreamResult from image().stream()
74
+ * @param event - H3 event object
75
+ */
76
+ declare function streamImageSSE(stream: ImageStreamLike, event: H3Event): void;
77
+ /**
78
+ * Create a ReadableStream for H3's sendStream utility.
79
+ *
80
+ * Use this with H3's sendStream for better integration:
81
+ * ```typescript
82
+ * import { sendStream } from 'h3';
83
+ * return sendStream(event, h3Adapter.createSSEStream(stream));
84
+ * ```
85
+ *
86
+ * @param stream - The StreamResult from instance.stream()
87
+ * @returns A ReadableStream of SSE data
88
+ */
89
+ declare function createSSEStream(stream: StreamResult): ReadableStream<Uint8Array>;
90
+ /**
91
+ * Create a ReadableStream for image SSE data.
92
+ *
93
+ * @param stream - The ImageStreamResult or ImageProviderStreamResult from image().stream()
94
+ * @returns A ReadableStream of SSE data
95
+ */
96
+ declare function createImageSSEStream(stream: ImageStreamLike): ReadableStream<Uint8Array>;
97
+ /**
98
+ * Send an error response.
99
+ *
100
+ * @param message - Error message
101
+ * @param status - HTTP status code
102
+ * @param event - H3 event object
103
+ * @returns Error object for H3 to serialize
104
+ */
105
+ declare function sendError(message: string, status: number, event: H3Event): {
106
+ error: string;
107
+ statusCode: number;
108
+ };
109
+ /**
110
+ * H3/Nitro/Nuxt adapter utilities.
111
+ *
112
+ * @example Basic usage
113
+ * ```typescript
114
+ * // Nuxt server route: server/api/ai.post.ts
115
+ * import { llm } from '@providerprotocol/ai';
116
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
117
+ * import { parseBody } from '@providerprotocol/ai/proxy';
118
+ * import { h3 as h3Adapter } from '@providerprotocol/ai/proxy/server';
119
+ *
120
+ * export default defineEventHandler(async (event) => {
121
+ * const body = await readBody(event);
122
+ * const { messages, system, params } = parseBody(body);
123
+ * const instance = llm({ model: anthropic('claude-sonnet-4-20250514'), system });
124
+ *
125
+ * const wantsStream = getHeader(event, 'accept')?.includes('text/event-stream');
126
+ * if (wantsStream) {
127
+ * return h3Adapter.streamSSE(instance.stream(messages), event);
128
+ * } else {
129
+ * const turn = await instance.generate(messages);
130
+ * return h3Adapter.sendJSON(turn, event);
131
+ * }
132
+ * });
133
+ * ```
134
+ *
135
+ * @example API Gateway with authentication (Nuxt)
136
+ * ```typescript
137
+ * // server/api/ai.post.ts
138
+ * import { llm } from '@providerprotocol/ai';
139
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
140
+ * import { ExponentialBackoff, RoundRobinKeys } from '@providerprotocol/ai/http';
141
+ * import { parseBody } from '@providerprotocol/ai/proxy';
142
+ * import { h3 as h3Adapter } from '@providerprotocol/ai/proxy/server';
143
+ *
144
+ * // Server manages AI provider keys - users never see them
145
+ * const claude = llm({
146
+ * model: anthropic('claude-sonnet-4-20250514'),
147
+ * config: {
148
+ * apiKey: new RoundRobinKeys([
149
+ * process.env.ANTHROPIC_KEY_1!,
150
+ * process.env.ANTHROPIC_KEY_2!,
151
+ * ]),
152
+ * retryStrategy: new ExponentialBackoff({ maxAttempts: 3 }),
153
+ * },
154
+ * });
155
+ *
156
+ * export default defineEventHandler(async (event) => {
157
+ * // Authenticate with your platform credentials
158
+ * const token = getHeader(event, 'authorization')?.replace('Bearer ', '');
159
+ * const user = await validatePlatformToken(token);
160
+ * if (!user) {
161
+ * throw createError({ statusCode: 401, message: 'Unauthorized' });
162
+ * }
163
+ *
164
+ * // Track usage per user
165
+ * // await trackUsage(user.id);
166
+ *
167
+ * const body = await readBody(event);
168
+ * const { messages, system, params } = parseBody(body);
169
+ *
170
+ * if (params?.stream) {
171
+ * return h3Adapter.streamSSE(claude.stream(messages, { system }), event);
172
+ * }
173
+ * const turn = await claude.generate(messages, { system });
174
+ * return h3Adapter.sendJSON(turn, event);
175
+ * });
176
+ * ```
177
+ */
178
+ declare const h3: {
179
+ sendJSON: typeof sendJSON;
180
+ sendEmbeddingJSON: typeof sendEmbeddingJSON;
181
+ sendImageJSON: typeof sendImageJSON;
182
+ streamSSE: typeof streamSSE;
183
+ streamImageSSE: typeof streamImageSSE;
184
+ createSSEStream: typeof createSSEStream;
185
+ createImageSSEStream: typeof createImageSSEStream;
186
+ sendError: typeof sendError;
187
+ };
188
+
189
+ export { createImageSSEStream, createSSEStream, h3, sendEmbeddingJSON, sendError, sendImageJSON, sendJSON, streamImageSSE, streamSSE };
@@ -0,0 +1,28 @@
1
+ import {
2
+ createImageSSEStream,
3
+ createSSEStream,
4
+ h3,
5
+ sendEmbeddingJSON,
6
+ sendError,
7
+ sendImageJSON,
8
+ sendJSON,
9
+ streamImageSSE,
10
+ streamSSE
11
+ } from "../../../chunk-4OGB7JZA.js";
12
+ import "../../../chunk-C4JP64VW.js";
13
+ import "../../../chunk-ETBFOLQN.js";
14
+ import "../../../chunk-N5DX5JW3.js";
15
+ import "../../../chunk-BRP5XJ6Q.js";
16
+ import "../../../chunk-COS4ON4G.js";
17
+ export {
18
+ createImageSSEStream,
19
+ createSSEStream,
20
+ h3,
21
+ sendEmbeddingJSON,
22
+ sendError,
23
+ sendImageJSON,
24
+ sendJSON,
25
+ streamImageSSE,
26
+ streamSSE
27
+ };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,151 @@
1
+ import { sendJSON as sendJSON$2, sendEmbeddingJSON as sendEmbeddingJSON$2, sendImageJSON as sendImageJSON$2, streamSSE as streamSSE$2, streamImageSSE as streamImageSSE$2, createSSEStream, createImageSSEStream, sendError as sendError$2 } from './h3/index.js';
2
+ export { h3 } from './h3/index.js';
3
+ import { sendJSON as sendJSON$1, sendEmbeddingJSON as sendEmbeddingJSON$1, sendImageJSON as sendImageJSON$1, streamSSE as streamSSE$1, streamImageSSE as streamImageSSE$1, sendError as sendError$1 } from './fastify/index.js';
4
+ export { fastify } from './fastify/index.js';
5
+ import { sendJSON, sendEmbeddingJSON, sendImageJSON, streamSSE, streamImageSSE, sendError } from './express/index.js';
6
+ export { express } from './express/index.js';
7
+ import { parseBody, parseEmbeddingBody, parseImageBody, toJSON, toEmbeddingJSON, toImageJSON, toSSE, toImageSSE, toError, bindTools } from './webapi/index.js';
8
+ export { ParsedEmbeddingRequest, ParsedImageRequest, ParsedRequest, webapi } from './webapi/index.js';
9
+ import { M as Message, J as JSONSchema, H as ToolMetadata, T as Turn, i as StreamResult } from '../../stream-CecfVCPO.js';
10
+ import '../../embedding-CW6SaOOz.js';
11
+ import '../../llm-DwbUK7un.js';
12
+ import '../../image-stream-C0ciACM2.js';
13
+
14
+ /**
15
+ * @fileoverview Shared types for proxy server adapters.
16
+ *
17
+ * @module providers/proxy/server/types
18
+ */
19
+
20
+ /**
21
+ * Parsed request body from a proxy HTTP request.
22
+ */
23
+ interface ParsedBody {
24
+ messages: Message[];
25
+ system?: string | unknown[];
26
+ params?: Record<string, unknown>;
27
+ model?: string;
28
+ tools?: Array<{
29
+ name: string;
30
+ description: string;
31
+ parameters: JSONSchema;
32
+ metadata?: ToolMetadata;
33
+ }>;
34
+ structure?: JSONSchema;
35
+ }
36
+ /**
37
+ * Handler function signature for proxy endpoints.
38
+ * Takes parsed request data and returns either a Turn or StreamResult.
39
+ */
40
+ type ProxyHandler = (body: ParsedBody, meta: RequestMeta) => Promise<Turn> | StreamResult | Promise<StreamResult>;
41
+ /**
42
+ * Metadata about the incoming request.
43
+ */
44
+ interface RequestMeta {
45
+ /** Whether the client wants a streaming response */
46
+ wantsStream: boolean;
47
+ /** Raw headers from the request */
48
+ headers: Record<string, string | undefined>;
49
+ }
50
+ /**
51
+ * Options for adapter middleware.
52
+ */
53
+ interface AdapterOptions {
54
+ /** Custom error handler */
55
+ onError?: (error: Error) => {
56
+ message: string;
57
+ status: number;
58
+ };
59
+ }
60
+
61
+ /**
62
+ * Server adapters namespace.
63
+ *
64
+ * Contains framework-specific adapters for Web API, Express, Fastify, and H3.
65
+ *
66
+ * @example Express
67
+ * ```typescript
68
+ * import { express } from '@providerprotocol/ai/proxy/server';
69
+ *
70
+ * app.post('/api/ai', async (req, res) => {
71
+ * const { messages } = parseBody(req.body);
72
+ * if (req.headers.accept?.includes('text/event-stream')) {
73
+ * express.streamSSE(instance.stream(messages), res);
74
+ * } else {
75
+ * express.sendJSON(await instance.generate(messages), res);
76
+ * }
77
+ * });
78
+ * ```
79
+ *
80
+ * @example Fastify
81
+ * ```typescript
82
+ * import { fastify } from '@providerprotocol/ai/proxy/server';
83
+ *
84
+ * app.post('/api/ai', async (request, reply) => {
85
+ * const { messages } = parseBody(request.body);
86
+ * if (request.headers.accept?.includes('text/event-stream')) {
87
+ * return fastify.streamSSE(instance.stream(messages), reply);
88
+ * }
89
+ * return fastify.sendJSON(await instance.generate(messages), reply);
90
+ * });
91
+ * ```
92
+ *
93
+ * @example H3/Nuxt
94
+ * ```typescript
95
+ * import { h3 } from '@providerprotocol/ai/proxy/server';
96
+ *
97
+ * export default defineEventHandler(async (event) => {
98
+ * const { messages } = parseBody(await readBody(event));
99
+ * if (getHeader(event, 'accept')?.includes('text/event-stream')) {
100
+ * return h3.streamSSE(instance.stream(messages), event);
101
+ * }
102
+ * return h3.sendJSON(await instance.generate(messages), event);
103
+ * });
104
+ * ```
105
+ */
106
+ declare const server: {
107
+ /** Web API adapter (Bun, Deno, Next.js, Workers) */
108
+ webapi: {
109
+ parseBody: typeof parseBody;
110
+ parseEmbeddingBody: typeof parseEmbeddingBody;
111
+ parseImageBody: typeof parseImageBody;
112
+ toJSON: typeof toJSON;
113
+ toEmbeddingJSON: typeof toEmbeddingJSON;
114
+ toImageJSON: typeof toImageJSON;
115
+ toSSE: typeof toSSE;
116
+ toImageSSE: typeof toImageSSE;
117
+ toError: typeof toError;
118
+ bindTools: typeof bindTools;
119
+ };
120
+ /** Express/Connect adapter */
121
+ express: {
122
+ sendJSON: typeof sendJSON;
123
+ sendEmbeddingJSON: typeof sendEmbeddingJSON;
124
+ sendImageJSON: typeof sendImageJSON;
125
+ streamSSE: typeof streamSSE;
126
+ streamImageSSE: typeof streamImageSSE;
127
+ sendError: typeof sendError;
128
+ };
129
+ /** Fastify adapter */
130
+ fastify: {
131
+ sendJSON: typeof sendJSON$1;
132
+ sendEmbeddingJSON: typeof sendEmbeddingJSON$1;
133
+ sendImageJSON: typeof sendImageJSON$1;
134
+ streamSSE: typeof streamSSE$1;
135
+ streamImageSSE: typeof streamImageSSE$1;
136
+ sendError: typeof sendError$1;
137
+ };
138
+ /** H3/Nitro/Nuxt adapter */
139
+ h3: {
140
+ sendJSON: typeof sendJSON$2;
141
+ sendEmbeddingJSON: typeof sendEmbeddingJSON$2;
142
+ sendImageJSON: typeof sendImageJSON$2;
143
+ streamSSE: typeof streamSSE$2;
144
+ streamImageSSE: typeof streamImageSSE$2;
145
+ createSSEStream: typeof createSSEStream;
146
+ createImageSSEStream: typeof createImageSSEStream;
147
+ sendError: typeof sendError$2;
148
+ };
149
+ };
150
+
151
+ export { type AdapterOptions, type ParsedBody, type ProxyHandler, type RequestMeta, bindTools, parseBody, parseEmbeddingBody, parseImageBody, server, toEmbeddingJSON, toError, toImageJSON, toImageSSE, toJSON, toSSE };
@@ -0,0 +1,48 @@
1
+ import {
2
+ server
3
+ } from "../../chunk-IDZOVWP3.js";
4
+ import {
5
+ fastify
6
+ } from "../../chunk-UFFJDYCE.js";
7
+ import {
8
+ bindTools,
9
+ parseBody,
10
+ parseEmbeddingBody,
11
+ parseImageBody,
12
+ toEmbeddingJSON,
13
+ toError,
14
+ toImageJSON,
15
+ toImageSSE,
16
+ toJSON,
17
+ toSSE,
18
+ webapi
19
+ } from "../../chunk-VGKZIGVI.js";
20
+ import {
21
+ express
22
+ } from "../../chunk-OIEWDFQU.js";
23
+ import {
24
+ h3
25
+ } from "../../chunk-4OGB7JZA.js";
26
+ import "../../chunk-C4JP64VW.js";
27
+ import "../../chunk-ETBFOLQN.js";
28
+ import "../../chunk-N5DX5JW3.js";
29
+ import "../../chunk-BRP5XJ6Q.js";
30
+ import "../../chunk-COS4ON4G.js";
31
+ export {
32
+ bindTools,
33
+ express,
34
+ fastify,
35
+ h3,
36
+ parseBody,
37
+ parseEmbeddingBody,
38
+ parseImageBody,
39
+ server,
40
+ toEmbeddingJSON,
41
+ toError,
42
+ toImageJSON,
43
+ toImageSSE,
44
+ toJSON,
45
+ toSSE,
46
+ webapi
47
+ };
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}