@llmops/gateway 0.1.0-beta.12 → 0.1.0-beta.13

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.
@@ -0,0 +1,434 @@
1
+ import * as hono_types0 from "hono/types";
2
+ import { Context, Hono } from "hono";
3
+
4
+ //#region src/globals.d.ts
5
+
6
+ declare enum BatchEndpoints {
7
+ CHAT_COMPLETIONS = "/v1/chat/completions",
8
+ COMPLETIONS = "/v1/completions",
9
+ EMBEDDINGS = "/v1/embeddings",
10
+ }
11
+ //#endregion
12
+ //#region src/middlewares/hooks/types.d.ts
13
+ interface Check {
14
+ id: string;
15
+ parameters: object;
16
+ is_enabled?: boolean;
17
+ }
18
+ interface HookOnFailObject {
19
+ feedback?: HookFeedback;
20
+ }
21
+ interface HookOnSuccessObject {
22
+ feedback?: HookFeedback;
23
+ }
24
+ interface HookObject {
25
+ type: HookType;
26
+ id: string;
27
+ checks?: Check[];
28
+ async?: boolean;
29
+ sequential?: boolean;
30
+ onFail?: HookOnFailObject;
31
+ onSuccess?: HookOnSuccessObject;
32
+ deny?: boolean;
33
+ eventType: 'beforeRequestHook' | 'afterRequestHook';
34
+ }
35
+ interface GuardrailFeedbackMetadata {
36
+ successfulChecks: string;
37
+ failedChecks: string;
38
+ erroredChecks: string;
39
+ }
40
+ interface GuardrailFeedback {
41
+ value?: number;
42
+ weight?: number;
43
+ metadata?: GuardrailFeedbackMetadata;
44
+ }
45
+ type HookFeedback = GuardrailFeedback;
46
+ declare enum HookType {
47
+ GUARDRAIL = "guardrail",
48
+ MUTATOR = "mutator",
49
+ }
50
+ //#endregion
51
+ //#region src/types/requestBody.d.ts
52
+ /**
53
+ * Settings for retrying requests.
54
+ * @interface
55
+ */
56
+ interface RetrySettings {
57
+ /** The maximum number of retry attempts. */
58
+ attempts: number;
59
+ /** The HTTP status codes on which to retry. */
60
+ onStatusCodes: number[];
61
+ /** Whether to use the provider's retry wait. */
62
+ useRetryAfterHeader?: boolean;
63
+ }
64
+ interface CacheSettings {
65
+ mode: string;
66
+ maxAge?: number;
67
+ }
68
+ /**
69
+ * Configuration for an AI provider.
70
+ * @interface
71
+ */
72
+ interface Options {
73
+ /** The name of the provider. */
74
+ provider: string;
75
+ /** The name of the API key for the provider. */
76
+ virtualKey?: string;
77
+ /** The API key for the provider. */
78
+ apiKey?: string;
79
+ /** The weight of the provider, used for load balancing. */
80
+ weight?: number;
81
+ /** The retry settings for the provider. */
82
+ retry?: RetrySettings;
83
+ /** The parameters to override in the request. */
84
+ overrideParams?: Params;
85
+ /** The actual url used to make llm calls */
86
+ urlToFetch?: string;
87
+ /** Azure specific */
88
+ resourceName?: string;
89
+ deploymentId?: string;
90
+ apiVersion?: string;
91
+ adAuth?: string;
92
+ azureAuthMode?: string;
93
+ azureManagedClientId?: string;
94
+ azureWorkloadClientId?: string;
95
+ azureEntraClientId?: string;
96
+ azureEntraClientSecret?: string;
97
+ azureEntraTenantId?: string;
98
+ azureAdToken?: string;
99
+ azureModelName?: string;
100
+ /** Workers AI specific */
101
+ workersAiAccountId?: string;
102
+ /** The parameter to set custom base url */
103
+ customHost?: string;
104
+ /** The parameter to set list of headers to be forwarded as-is to the provider */
105
+ forwardHeaders?: string[];
106
+ /** provider option index picked based on weight in loadbalance mode */
107
+ index?: number;
108
+ cache?: CacheSettings | string;
109
+ metadata?: Record<string, string>;
110
+ requestTimeout?: number;
111
+ /** This is used to determine if the request should be transformed to formData Example: Stability V2 */
112
+ transformToFormData?: boolean;
113
+ /** AWS specific (used for Bedrock and Sagemaker) */
114
+ awsSecretAccessKey?: string;
115
+ awsAccessKeyId?: string;
116
+ awsSessionToken?: string;
117
+ awsRegion?: string;
118
+ awsAuthType?: string;
119
+ awsRoleArn?: string;
120
+ awsExternalId?: string;
121
+ awsS3Bucket?: string;
122
+ awsS3ObjectKey?: string;
123
+ awsBedrockModel?: string;
124
+ awsServerSideEncryption?: string;
125
+ awsServerSideEncryptionKMSKeyId?: string;
126
+ awsService?: string;
127
+ foundationModel?: string;
128
+ /** Sagemaker specific */
129
+ amznSagemakerCustomAttributes?: string;
130
+ amznSagemakerTargetModel?: string;
131
+ amznSagemakerTargetVariant?: string;
132
+ amznSagemakerTargetContainerHostname?: string;
133
+ amznSagemakerInferenceId?: string;
134
+ amznSagemakerEnableExplanations?: string;
135
+ amznSagemakerInferenceComponent?: string;
136
+ amznSagemakerSessionId?: string;
137
+ amznSagemakerModelName?: string;
138
+ /** Stability AI specific */
139
+ stabilityClientId?: string;
140
+ stabilityClientUserId?: string;
141
+ stabilityClientVersion?: string;
142
+ /** Hugging Face specific */
143
+ huggingfaceBaseUrl?: string;
144
+ /** Google Vertex AI specific */
145
+ vertexRegion?: string;
146
+ vertexProjectId?: string;
147
+ vertexServiceAccountJson?: Record<string, any>;
148
+ vertexStorageBucketName?: string;
149
+ vertexModelName?: string;
150
+ vertexBatchEndpoint?: BatchEndpoints;
151
+ filename?: string;
152
+ afterRequestHooks?: HookObject[];
153
+ beforeRequestHooks?: HookObject[];
154
+ defaultInputGuardrails?: HookObject[];
155
+ defaultOutputGuardrails?: HookObject[];
156
+ /** OpenAI specific */
157
+ openaiProject?: string;
158
+ openaiOrganization?: string;
159
+ openaiBeta?: string;
160
+ /** Azure Inference Specific */
161
+ azureApiVersion?: string;
162
+ azureFoundryUrl?: string;
163
+ azureExtraParameters?: string;
164
+ azureDeploymentName?: string;
165
+ /** The parameter to determine if extra non-openai compliant fields should be returned in response */
166
+ strictOpenAiCompliance?: boolean;
167
+ /** Parameter to determine if fim/completions endpoint is to be used */
168
+ mistralFimCompletion?: string;
169
+ /** Anthropic specific headers */
170
+ anthropicBeta?: string;
171
+ anthropicVersion?: string;
172
+ anthropicApiKey?: string;
173
+ /** Fireworks finetune required fields */
174
+ fireworksAccountId?: string;
175
+ fireworksFileLength?: string;
176
+ /** Cortex specific fields */
177
+ snowflakeAccount?: string;
178
+ /** Azure entra scope */
179
+ azureEntraScope?: string;
180
+ oracleApiVersion?: string;
181
+ oracleRegion?: string;
182
+ oracleCompartmentId?: string;
183
+ oracleServingMode?: string;
184
+ oracleTenancy?: string;
185
+ oracleUser?: string;
186
+ oracleFingerprint?: string;
187
+ oraclePrivateKey?: string;
188
+ oracleKeyPassphrase?: string;
189
+ /** Model pricing config */
190
+ modelPricingConfig?: Record<string, any>;
191
+ }
192
+ /**
193
+ * TODO: make this a union type
194
+ * A message content type.
195
+ * @interface
196
+ */
197
+ interface ContentType extends PromptCache {
198
+ type: string;
199
+ text?: string;
200
+ thinking?: string;
201
+ signature?: string;
202
+ image_url?: {
203
+ url: string;
204
+ detail?: string;
205
+ mime_type?: string;
206
+ };
207
+ data?: string;
208
+ file?: {
209
+ file_data?: string;
210
+ file_id?: string;
211
+ file_name?: string;
212
+ file_url?: string;
213
+ mime_type?: string;
214
+ };
215
+ input_audio?: {
216
+ data: string;
217
+ format: 'mp3' | 'wav' | string;
218
+ };
219
+ }
220
+ type OpenAIMessageRole = 'system' | 'user' | 'assistant' | 'function' | 'tool' | 'developer';
221
+ /**
222
+ * A message in the conversation.
223
+ * @interface
224
+ */
225
+ interface Message {
226
+ /** The role of the message sender. It can be 'system', 'user', 'assistant', or 'function'. */
227
+ role: OpenAIMessageRole;
228
+ /** The content of the message. */
229
+ content?: string | ContentType[];
230
+ /** The content blocks of the message. */
231
+ content_blocks?: ContentType[];
232
+ /** The name of the function to call, if any. */
233
+ name?: string;
234
+ /** The function call to make, if any. */
235
+ function_call?: any;
236
+ tool_calls?: any;
237
+ tool_call_id?: string;
238
+ citationMetadata?: CitationMetadata;
239
+ /** Reasoning details for models that support extended thinking/reasoning. (Gemini) */
240
+ reasoning_details?: any[];
241
+ }
242
+ interface PromptCache {
243
+ cache_control?: {
244
+ type: 'ephemeral';
245
+ };
246
+ }
247
+ interface CitationMetadata {
248
+ citationSources?: CitationSource[];
249
+ }
250
+ interface CitationSource {
251
+ startIndex?: number;
252
+ endIndex?: number;
253
+ uri?: string;
254
+ license?: string;
255
+ }
256
+ /**
257
+ * A JSON schema.
258
+ * @interface
259
+ */
260
+ interface JsonSchema {
261
+ /** The schema definition, indexed by key. */
262
+ [key: string]: any;
263
+ }
264
+ /**
265
+ * A function in the conversation.
266
+ * @interface
267
+ */
268
+ interface Function {
269
+ /** The name of the function. */
270
+ name: string;
271
+ /** A description of the function. */
272
+ description?: string;
273
+ /** The parameters for the function. */
274
+ parameters?: JsonSchema;
275
+ /** Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the parameters field. Only a subset of JSON Schema is supported when strict is true */
276
+ strict?: boolean;
277
+ /**
278
+ * When true, this tool is not loaded into context initially.
279
+ * Claude discovers it via Tool Search Tool on-demand.
280
+ * Part of Anthropic's advanced tool use beta features.
281
+ */
282
+ defer_loading?: boolean;
283
+ /**
284
+ * List of tool types that can call this tool programmatically.
285
+ * E.g., ["code_execution_20250825"] enables Programmatic Tool Calling.
286
+ * Part of Anthropic's advanced tool use beta features.
287
+ */
288
+ allowed_callers?: string[];
289
+ /**
290
+ * Example inputs demonstrating how to use this tool.
291
+ * Helps Claude understand usage patterns beyond JSON schema.
292
+ * Part of Anthropic's advanced tool use beta features.
293
+ */
294
+ input_examples?: Record<string, any>[];
295
+ }
296
+ interface ToolChoiceObject {
297
+ type: string;
298
+ function: {
299
+ name: string;
300
+ };
301
+ }
302
+ interface CustomToolChoice {
303
+ type: 'custom';
304
+ custom: {
305
+ name?: string;
306
+ };
307
+ }
308
+ type ToolChoice = ToolChoiceObject | CustomToolChoice | 'none' | 'auto' | 'required';
309
+ /**
310
+ * A tool in the conversation.
311
+ *
312
+ * `cache_control` is extended to support for prompt-cache
313
+ *
314
+ * @interface
315
+ */
316
+ interface Tool extends PromptCache {
317
+ /** The name of the function. */
318
+ type: string;
319
+ /** A description of the function. */
320
+ function?: Function;
321
+ [key: string]: any;
322
+ }
323
+ /**
324
+ * The parameters for the request.
325
+ * @interface
326
+ */
327
+ interface Params {
328
+ model?: string;
329
+ prompt?: string | string[];
330
+ messages?: Message[];
331
+ functions?: Function[];
332
+ function_call?: 'none' | 'auto' | {
333
+ name: string;
334
+ };
335
+ max_tokens?: number;
336
+ max_completion_tokens?: number;
337
+ temperature?: number;
338
+ top_p?: number;
339
+ n?: number;
340
+ stream?: boolean;
341
+ logprobs?: number;
342
+ top_logprobs?: boolean;
343
+ echo?: boolean;
344
+ stop?: string | string[];
345
+ presence_penalty?: number;
346
+ frequency_penalty?: number;
347
+ best_of?: number;
348
+ logit_bias?: {
349
+ [key: string]: number;
350
+ };
351
+ user?: string;
352
+ context?: string;
353
+ examples?: Examples[];
354
+ top_k?: number;
355
+ tools?: Tool[];
356
+ tool_choice?: ToolChoice;
357
+ reasoning_effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | string;
358
+ response_format?: {
359
+ type: 'json_object' | 'text' | 'json_schema';
360
+ json_schema?: any;
361
+ };
362
+ seed?: number;
363
+ store?: boolean;
364
+ metadata?: object;
365
+ modalities?: string[];
366
+ audio?: {
367
+ voice: string;
368
+ format: string;
369
+ };
370
+ service_tier?: string;
371
+ prediction?: {
372
+ type: string;
373
+ content: {
374
+ type: string;
375
+ text: string;
376
+ }[] | string;
377
+ };
378
+ safety_settings?: any;
379
+ anthropic_beta?: string;
380
+ anthropic_version?: string;
381
+ thinking?: {
382
+ type?: string;
383
+ budget_tokens: number;
384
+ };
385
+ dimensions?: number;
386
+ parameters?: any;
387
+ version?: number;
388
+ }
389
+ interface Examples {
390
+ input?: Message;
391
+ output?: Message;
392
+ }
393
+ /**
394
+ * The full structure of the request body.
395
+ * @interface
396
+ */
397
+ //#endregion
398
+ //#region src/providers/types.d.ts
399
+
400
+ type endpointStrings = 'complete' | 'chatComplete' | 'embed' | 'rerank' | 'moderate' | 'stream-complete' | 'stream-chatComplete' | 'stream-messages' | 'proxy' | 'imageGenerate' | 'imageEdit' | 'createSpeech' | 'createTranscription' | 'createTranslation' | 'realtime' | 'uploadFile' | 'listFiles' | 'retrieveFile' | 'deleteFile' | 'retrieveFileContent' | 'createBatch' | 'retrieveBatch' | 'cancelBatch' | 'listBatches' | 'getBatchOutput' | 'listFinetunes' | 'createFinetune' | 'retrieveFinetune' | 'cancelFinetune' | 'createModelResponse' | 'getModelResponse' | 'deleteModelResponse' | 'listResponseInputItems' | 'messages' | 'messagesCountTokens';
401
+ type RequestHandler<T = Params | FormData | ArrayBuffer | ReadableStream> = (Params: {
402
+ c: Context;
403
+ providerOptions: Options;
404
+ requestURL: string;
405
+ requestHeaders: Record<string, string>;
406
+ requestBody: T;
407
+ }) => Promise<Response>;
408
+ type RequestHandlers = Partial<Record<endpointStrings, RequestHandler<any>>>;
409
+ /**
410
+ * A collection of configurations for multiple AI providers.
411
+ * @interface
412
+ */
413
+ interface ProviderConfigs {
414
+ /** The configuration for each provider, indexed by provider name. */
415
+ [key: string]: any;
416
+ requestHandlers?: RequestHandlers;
417
+ getConfig?: ({
418
+ params,
419
+ providerOptions
420
+ }: {
421
+ params: Params;
422
+ providerOptions: Options;
423
+ }) => any;
424
+ }
425
+ //#endregion
426
+ //#region src/providers/index.d.ts
427
+ declare const Providers: {
428
+ [key: string]: ProviderConfigs;
429
+ };
430
+ //#endregion
431
+ //#region src/index.d.ts
432
+ declare const app: Hono<hono_types0.BlankEnv, hono_types0.BlankSchema, "/">;
433
+ //#endregion
434
+ export { Providers, app as default };
package/dist/index.mjs CHANGED
@@ -4,6 +4,7 @@ import { prettyJSON } from "hono/pretty-json";
4
4
  import { HTTPException } from "hono/http-exception";
5
5
  import { compress } from "hono/compress";
6
6
  import { env, getRuntimeKey } from "hono/adapter";
7
+ import * as path from "path";
7
8
  import { Validator } from "@cfworker/json-schema";
8
9
  import { Sha256 } from "@aws-crypto/sha256-js";
9
10
  import { SignatureV4 } from "@smithy/signature-v4";
@@ -11,7 +12,6 @@ import { Agent } from "https";
11
12
  import { importJWK, jwtVerify } from "jose";
12
13
  import retry from "async-retry";
13
14
  import * as fs from "fs/promises";
14
- import * as path from "path";
15
15
  import Redis from "ioredis";
16
16
 
17
17
  //#region rolldown:runtime
@@ -4160,8 +4160,8 @@ const isNodeInstance = getRuntimeKey() == "node";
4160
4160
  let path$1;
4161
4161
  let fs$1;
4162
4162
  if (isNodeInstance) {
4163
- path$1 = await import("path");
4164
- fs$1 = await import("fs");
4163
+ path$1 = __require("path");
4164
+ fs$1 = __require("fs");
4165
4165
  }
4166
4166
  function getValueOrFileContents(value, ignore) {
4167
4167
  if (!value || ignore) return value;
@@ -9953,7 +9953,7 @@ const retryRequest = async (url, options, retryCount, statusCodesToRetry, timeou
9953
9953
 
9954
9954
  //#endregion
9955
9955
  //#region package.json
9956
- var version = "0.1.0-beta.12";
9956
+ var version = "0.1.0-beta.13";
9957
9957
 
9958
9958
  //#endregion
9959
9959
  //#region src/providers/bytez/api.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llmops/gateway",
3
- "version": "0.1.0-beta.12",
3
+ "version": "0.1.0-beta.13",
4
4
  "description": "AI gateway for LLMOps (forked from Portkey)",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -23,11 +23,20 @@
23
23
  "files": [
24
24
  "dist"
25
25
  ],
26
- "main": "./dist/index.mjs",
26
+ "main": "./dist/index.cjs",
27
27
  "module": "./dist/index.mjs",
28
28
  "types": "./dist/index.d.mts",
29
29
  "exports": {
30
- ".": "./dist/index.mjs",
30
+ ".": {
31
+ "import": {
32
+ "types": "./dist/index.d.mts",
33
+ "default": "./dist/index.mjs"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ },
31
40
  "./package.json": "./package.json"
32
41
  },
33
42
  "publishConfig": {