@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,278 @@
1
+ import { M as Message, J as JSONSchema, H as ToolMetadata, T as Turn, i as StreamResult, d as Tool } from '../../../stream-CecfVCPO.js';
2
+ import { n as Image, E as EmbeddingInput, N as ImageResult } from '../../../llm-DwbUK7un.js';
3
+ import { d as EmbeddingResult } from '../../../embedding-CW6SaOOz.js';
4
+ import { I as ImageStreamLike } from '../../../image-stream-C0ciACM2.js';
5
+
6
+ /**
7
+ * @fileoverview Media serialization utilities for proxy transport.
8
+ *
9
+ * Handles converting embedding inputs and image results/events to/from JSON
10
+ * for HTTP transport. These are pure functions with no side effects.
11
+ *
12
+ * @module providers/proxy/serialization.media
13
+ */
14
+
15
+ type SerializedImageSource = {
16
+ type: 'base64';
17
+ data: string;
18
+ } | {
19
+ type: 'url';
20
+ url: string;
21
+ } | {
22
+ type: 'bytes';
23
+ data: number[] | string;
24
+ };
25
+ interface SerializedImage {
26
+ source: SerializedImageSource;
27
+ mimeType: string;
28
+ width?: number;
29
+ height?: number;
30
+ }
31
+ /**
32
+ * Deserialize an Image from JSON transport.
33
+ */
34
+ declare function deserializeImage(image: SerializedImage): Image;
35
+
36
+ /**
37
+ * @fileoverview Web API adapter for proxy server.
38
+ *
39
+ * Provides utilities for using PP proxy with Web API native frameworks
40
+ * (Bun, Deno, Next.js App Router, Cloudflare Workers).
41
+ *
42
+ * These utilities return standard Web API Response objects that work
43
+ * directly with modern runtimes.
44
+ *
45
+ * @module providers/proxy/server/webapi
46
+ */
47
+
48
+ /**
49
+ * Parsed request body from a proxy HTTP request.
50
+ * This is just the deserialized PP data from the request body.
51
+ */
52
+ interface ParsedRequest {
53
+ messages: Message[];
54
+ system?: string | unknown[];
55
+ params?: Record<string, unknown>;
56
+ model?: string;
57
+ tools?: Array<{
58
+ name: string;
59
+ description: string;
60
+ parameters: JSONSchema;
61
+ metadata?: ToolMetadata;
62
+ }>;
63
+ structure?: JSONSchema;
64
+ }
65
+ /**
66
+ * Parsed request body for embedding endpoints.
67
+ */
68
+ interface ParsedEmbeddingRequest {
69
+ inputs: EmbeddingInput[];
70
+ params?: Record<string, unknown>;
71
+ model?: string;
72
+ }
73
+ /**
74
+ * Parsed request body for image endpoints.
75
+ */
76
+ interface ParsedImageRequest {
77
+ prompt: string;
78
+ params?: Record<string, unknown>;
79
+ model?: string;
80
+ image?: ReturnType<typeof deserializeImage>;
81
+ mask?: ReturnType<typeof deserializeImage>;
82
+ }
83
+ /**
84
+ * Parse an HTTP request body into PP types.
85
+ *
86
+ * @param body - The JSON-parsed request body
87
+ * @returns Deserialized PP data
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const body = await req.json();
92
+ * const { messages, system, params } = parseBody(body);
93
+ *
94
+ * const instance = llm({ model: anthropic('...'), system, params });
95
+ * const turn = await instance.generate(messages);
96
+ * ```
97
+ */
98
+ declare function parseBody(body: unknown): ParsedRequest;
99
+ /**
100
+ * Parse an HTTP request body into embedding inputs.
101
+ *
102
+ * @param body - The JSON-parsed request body
103
+ * @returns Parsed embedding request data
104
+ */
105
+ declare function parseEmbeddingBody(body: unknown): ParsedEmbeddingRequest;
106
+ /**
107
+ * Parse an HTTP request body into image request data.
108
+ *
109
+ * @param body - The JSON-parsed request body
110
+ * @returns Parsed image request data
111
+ */
112
+ declare function parseImageBody(body: unknown): ParsedImageRequest;
113
+ /**
114
+ * Create a JSON Response from a Turn.
115
+ *
116
+ * @param turn - The completed inference turn
117
+ * @returns HTTP Response with JSON body
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * const turn = await instance.generate(messages);
122
+ * return toJSON(turn);
123
+ * ```
124
+ */
125
+ declare function toJSON(turn: Turn): Response;
126
+ /**
127
+ * Create a JSON Response from an embedding result.
128
+ *
129
+ * @param result - The embedding result
130
+ * @returns HTTP Response with JSON body
131
+ */
132
+ declare function toEmbeddingJSON(result: EmbeddingResult): Response;
133
+ /**
134
+ * Create a JSON Response from an image result.
135
+ *
136
+ * @param result - The image result
137
+ * @returns HTTP Response with JSON body
138
+ */
139
+ declare function toImageJSON(result: ImageResult): Response;
140
+ /**
141
+ * Create an SSE Response from a StreamResult.
142
+ *
143
+ * Streams PP StreamEvents as SSE, then sends the final Turn data.
144
+ *
145
+ * @param stream - The StreamResult from instance.stream()
146
+ * @returns HTTP Response with SSE body
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * const stream = instance.stream(messages);
151
+ * return toSSE(stream);
152
+ * ```
153
+ */
154
+ declare function toSSE(stream: StreamResult): Response;
155
+ /**
156
+ * Create an SSE Response from an ImageStreamResult.
157
+ *
158
+ * Streams image events as SSE, then sends the final image result.
159
+ *
160
+ * @param stream - The ImageStreamResult or ImageProviderStreamResult from image().stream()
161
+ * @returns HTTP Response with SSE body
162
+ */
163
+ declare function toImageSSE(stream: ImageStreamLike): Response;
164
+ /**
165
+ * Create an error Response.
166
+ *
167
+ * @param message - Error message
168
+ * @param status - HTTP status code (default: 500)
169
+ * @returns HTTP Response with error body
170
+ */
171
+ declare function toError(message: string, status?: number): Response;
172
+ /**
173
+ * Bind tool schemas to implementation functions.
174
+ *
175
+ * Takes tool schemas from the request and binds them to your
176
+ * server-side implementations.
177
+ *
178
+ * @param schemas - Tool schemas from the request
179
+ * @param implementations - Map of tool name to implementation
180
+ * @returns Array of complete Tool objects
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const { tools: schemas } = parseBody(body);
185
+ *
186
+ * const tools = bindTools(schemas, {
187
+ * get_weather: async ({ location }) => fetchWeather(location),
188
+ * search: async ({ query }) => searchDB(query),
189
+ * });
190
+ *
191
+ * const instance = llm({ model, tools });
192
+ * ```
193
+ */
194
+ declare function bindTools(schemas: ParsedRequest['tools'], implementations: Record<string, (params: unknown) => unknown | Promise<unknown>>): Tool[];
195
+ /**
196
+ * Web API adapter utilities.
197
+ *
198
+ * For use with Bun, Deno, Next.js App Router, Cloudflare Workers,
199
+ * and other frameworks that support Web API Response.
200
+ *
201
+ * **Security Note:** The proxy works without configuration, meaning no
202
+ * authentication by default. Always add your own auth layer in production.
203
+ *
204
+ * @example Basic usage
205
+ * ```typescript
206
+ * import { llm } from '@providerprotocol/ai';
207
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
208
+ * import { parseBody, toJSON, toSSE } from '@providerprotocol/ai/proxy';
209
+ *
210
+ * // Bun.serve / Deno.serve / Next.js App Router
211
+ * export async function POST(req: Request) {
212
+ * const { messages, system } = parseBody(await req.json());
213
+ * const instance = llm({ model: anthropic('claude-sonnet-4-20250514'), system });
214
+ *
215
+ * if (req.headers.get('accept')?.includes('text/event-stream')) {
216
+ * return toSSE(instance.stream(messages));
217
+ * }
218
+ * return toJSON(await instance.generate(messages));
219
+ * }
220
+ * ```
221
+ *
222
+ * @example API Gateway with authentication
223
+ * ```typescript
224
+ * import { llm } from '@providerprotocol/ai';
225
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
226
+ * import { ExponentialBackoff, RoundRobinKeys } from '@providerprotocol/ai/http';
227
+ * import { parseBody, toJSON, toSSE, toError } from '@providerprotocol/ai/proxy';
228
+ *
229
+ * // Your platform's user validation
230
+ * async function validateToken(token: string): Promise<{ id: string } | null> {
231
+ * // Verify JWT, check database, etc.
232
+ * return token ? { id: 'user-123' } : null;
233
+ * }
234
+ *
235
+ * // Server manages AI provider keys - users never see them
236
+ * const claude = llm({
237
+ * model: anthropic('claude-sonnet-4-20250514'),
238
+ * config: {
239
+ * apiKey: new RoundRobinKeys([process.env.ANTHROPIC_KEY_1!, process.env.ANTHROPIC_KEY_2!]),
240
+ * retryStrategy: new ExponentialBackoff({ maxAttempts: 3 }),
241
+ * },
242
+ * });
243
+ *
244
+ * Bun.serve({
245
+ * port: 3000,
246
+ * async fetch(req) {
247
+ * // Authenticate with YOUR platform credentials
248
+ * const token = req.headers.get('Authorization')?.replace('Bearer ', '');
249
+ * const user = await validateToken(token ?? '');
250
+ * if (!user) return toError('Unauthorized', 401);
251
+ *
252
+ * // Rate limit, track usage, bill user, etc.
253
+ * // await trackUsage(user.id);
254
+ *
255
+ * const { messages, system, params } = parseBody(await req.json());
256
+ *
257
+ * if (params?.stream) {
258
+ * return toSSE(claude.stream(messages, { system }));
259
+ * }
260
+ * return toJSON(await claude.generate(messages, { system }));
261
+ * },
262
+ * });
263
+ * ```
264
+ */
265
+ declare const webapi: {
266
+ parseBody: typeof parseBody;
267
+ parseEmbeddingBody: typeof parseEmbeddingBody;
268
+ parseImageBody: typeof parseImageBody;
269
+ toJSON: typeof toJSON;
270
+ toEmbeddingJSON: typeof toEmbeddingJSON;
271
+ toImageJSON: typeof toImageJSON;
272
+ toSSE: typeof toSSE;
273
+ toImageSSE: typeof toImageSSE;
274
+ toError: typeof toError;
275
+ bindTools: typeof bindTools;
276
+ };
277
+
278
+ export { type ParsedEmbeddingRequest, type ParsedImageRequest, type ParsedRequest, bindTools, parseBody, parseEmbeddingBody, parseImageBody, toEmbeddingJSON, toError, toImageJSON, toImageSSE, toJSON, toSSE, webapi };
@@ -0,0 +1,32 @@
1
+ import {
2
+ bindTools,
3
+ parseBody,
4
+ parseEmbeddingBody,
5
+ parseImageBody,
6
+ toEmbeddingJSON,
7
+ toError,
8
+ toImageJSON,
9
+ toImageSSE,
10
+ toJSON,
11
+ toSSE,
12
+ webapi
13
+ } from "../../../chunk-VGKZIGVI.js";
14
+ import "../../../chunk-C4JP64VW.js";
15
+ import "../../../chunk-ETBFOLQN.js";
16
+ import "../../../chunk-N5DX5JW3.js";
17
+ import "../../../chunk-BRP5XJ6Q.js";
18
+ import "../../../chunk-COS4ON4G.js";
19
+ export {
20
+ bindTools,
21
+ parseBody,
22
+ parseEmbeddingBody,
23
+ parseImageBody,
24
+ toEmbeddingJSON,
25
+ toError,
26
+ toImageJSON,
27
+ toImageSSE,
28
+ toJSON,
29
+ toSSE,
30
+ webapi
31
+ };
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}