@leitwerk-dev/models 0.1.9 → 0.2.1

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.
@@ -1,4 +1,5 @@
1
1
  import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
2
+ import { isUnknownRecord as isRecord } from "@leitwerk-dev/domain";
2
3
  import {
3
4
  builtinPiProvider,
4
5
  configuredPiProvider,
@@ -6,7 +7,6 @@ import {
6
7
  type ModelProviderDefinition,
7
8
  type ModelProviderModelsContext,
8
9
  type ModelProviderSetEntry,
9
- type ProviderJsonObject,
10
10
  type ProviderModelStatus,
11
11
  } from "@leitwerk-dev/process-sdk";
12
12
  import * as v from "valibot";
@@ -16,11 +16,17 @@ import {
16
16
  getSupportedStandardProviders,
17
17
  } from "./provider-auth.js";
18
18
 
19
+ /** @internal */
19
20
  export interface StandardProviderConfig {
21
+ /** @internal */
20
22
  readonly baseUrl?: string;
23
+ /** @internal */
24
+ readonly models?: ReturnType<typeof normalizeStandardModels>;
21
25
  }
22
26
 
27
+ /** @internal */
23
28
  export interface ApiKeyCredential {
29
+ /** @internal */
24
30
  readonly apiKey: string;
25
31
  }
26
32
 
@@ -30,6 +36,67 @@ const nonEmptyStringSchema = v.pipe(
30
36
  v.minLength(1),
31
37
  );
32
38
  const positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
39
+ const nonNegativeNumberSchema = v.pipe(v.number(), v.finite(), v.minValue(0));
40
+ const thinkingLevelValueSchema = v.optional(v.nullable(nonEmptyStringSchema));
41
+ const thinkingLevelMapSchema = v.strictObject({
42
+ /** @internal */
43
+ off: thinkingLevelValueSchema,
44
+ /** @internal */
45
+ minimal: thinkingLevelValueSchema,
46
+ /** @internal */
47
+ low: thinkingLevelValueSchema,
48
+ /** @internal */
49
+ medium: thinkingLevelValueSchema,
50
+ /** @internal */
51
+ high: thinkingLevelValueSchema,
52
+ /** @internal */
53
+ xhigh: thinkingLevelValueSchema,
54
+ /** @internal */
55
+ max: thinkingLevelValueSchema,
56
+ });
57
+ // Compatibility options use Pi's names so they can be copied from models.json.
58
+ /** @internal */
59
+ const compatibilitySchema = v.strictObject({
60
+ /** @internal */
61
+ supportsStore: v.optional(v.boolean()),
62
+ /** @internal */
63
+ supportsDeveloperRole: v.optional(v.boolean()),
64
+ /** @internal */
65
+ supportsReasoningEffort: v.optional(v.boolean()),
66
+ /** @internal */
67
+ supportsUsageInStreaming: v.optional(v.boolean()),
68
+ /** @internal */
69
+ maxTokensField: v.optional(v.picklist(["max_tokens", "max_completion_tokens"])),
70
+ /** @internal */
71
+ supportsStrictMode: v.optional(v.boolean()),
72
+ /** @internal */
73
+ requiresReasoningContentOnAssistantMessages: v.optional(v.boolean()),
74
+ /** @internal */
75
+ thinkingFormat: v.optional(
76
+ v.picklist([
77
+ "openai",
78
+ "openrouter",
79
+ "deepseek",
80
+ "together",
81
+ "zai",
82
+ "qwen",
83
+ "chat-template",
84
+ "qwen-chat-template",
85
+ "string-thinking",
86
+ "ant-ling",
87
+ ]),
88
+ ),
89
+ });
90
+ const modelCostSchema = v.strictObject({
91
+ /** @internal */
92
+ input: nonNegativeNumberSchema,
93
+ /** @internal */
94
+ output: nonNegativeNumberSchema,
95
+ /** @internal */
96
+ cacheRead: nonNegativeNumberSchema,
97
+ /** @internal */
98
+ cacheWrite: nonNegativeNumberSchema,
99
+ });
33
100
  const baseUrlSchema = v.pipe(
34
101
  nonEmptyStringSchema,
35
102
  v.url(),
@@ -40,20 +107,58 @@ const baseUrlSchema = v.pipe(
40
107
  return url.toString().replace(/\/$/u, "");
41
108
  }),
42
109
  );
110
+ /** @internal */
43
111
  const customModelSchema = v.pipe(
44
112
  v.strictObject({
113
+ /** @internal */
45
114
  id: nonEmptyStringSchema,
115
+ /** @internal */
46
116
  name: v.optional(nonEmptyStringSchema),
117
+ /** @internal */
47
118
  reasoning: v.optional(v.boolean()),
119
+ /** @internal */
120
+ thinking_level_map: v.optional(thinkingLevelMapSchema),
121
+ /** @internal */
122
+ input: v.optional(v.pipe(v.array(v.picklist(["text", "image"])), v.minLength(1))),
123
+ /** @internal */
124
+ cost: v.optional(modelCostSchema),
125
+ /** @internal */
126
+ compat: v.optional(compatibilitySchema),
127
+ /** @internal */
48
128
  context_window: v.optional(positiveIntegerSchema),
129
+ /** @internal */
49
130
  max_tokens: v.optional(positiveIntegerSchema),
50
131
  }),
51
- v.transform(({ context_window, max_tokens, ...model }) => ({
132
+ v.transform(({ context_window, max_tokens, thinking_level_map, ...model }) => ({
52
133
  ...model,
53
- ...(context_window === undefined ? {} : { contextWindow: context_window }),
54
- ...(max_tokens === undefined ? {} : { maxTokens: max_tokens }),
134
+ ...(thinking_level_map === undefined
135
+ ? {}
136
+ : {
137
+ /** @internal */
138
+ thinkingLevelMap: thinking_level_map,
139
+ }),
140
+ ...(context_window === undefined
141
+ ? {}
142
+ : {
143
+ /** @internal */
144
+ contextWindow: context_window,
145
+ }),
146
+ ...(max_tokens === undefined
147
+ ? {}
148
+ : {
149
+ /** @internal */
150
+ maxTokens: max_tokens,
151
+ }),
55
152
  })),
56
153
  );
154
+ const modelDefinitionsSchema = v.pipe(
155
+ v.array(customModelSchema),
156
+ v.minLength(1),
157
+ v.check(
158
+ (models) => new Set(models.map(({ id }) => id)).size === models.length,
159
+ "Duplicate model id",
160
+ ),
161
+ );
57
162
  const customGatewaySchema = v.strictObject({
58
163
  base_url: baseUrlSchema,
59
164
  api_key: v.optional(v.nullable(v.union([v.literal(false), nonEmptyStringSchema]))),
@@ -66,21 +171,62 @@ const customGatewaySchema = v.strictObject({
66
171
  ]),
67
172
  "openai-completions",
68
173
  ),
69
- models: v.pipe(v.array(customModelSchema), v.minLength(1)),
174
+ compat: v.optional(compatibilitySchema),
175
+ models: modelDefinitionsSchema,
70
176
  });
71
177
 
178
+ /** @internal */
72
179
  export type CustomModelDefinition = v.InferOutput<typeof customModelSchema>;
73
180
 
181
+ /** @internal */
74
182
  export interface CustomGatewayConfig {
183
+ /** @internal */
75
184
  readonly providerId: string;
185
+ /** @internal */
76
186
  readonly baseUrl: string;
187
+ /** @internal */
77
188
  readonly api: string;
189
+ /** @internal */
78
190
  readonly keyless: boolean;
191
+ /** @internal */
192
+ readonly compat?: v.InferOutput<typeof compatibilitySchema>;
193
+ /** @internal */
79
194
  readonly models: CustomModelDefinition[];
80
195
  }
81
196
 
82
- function isRecord(value: unknown): value is Record<string, unknown> {
83
- return typeof value === "object" && value !== null && !Array.isArray(value);
197
+ /** @internal */
198
+ function normalizeStandardModels(
199
+ providerId: string,
200
+ models: CustomModelDefinition[],
201
+ baseUrl?: string,
202
+ ) {
203
+ const catalog = getBuiltinModels(providerId as never);
204
+ return models.map((model) => {
205
+ const reference = catalog.find(({ id }) => id === model.id) ?? catalog[0];
206
+ if (!reference) throw new Error(`Provider '${providerId}' has no canonical API definition`);
207
+ return {
208
+ ...model,
209
+ /** @internal */
210
+ provider: providerId,
211
+ /** @internal */
212
+ api: reference.api,
213
+ /** @internal */
214
+ baseUrl: baseUrl ?? reference.baseUrl,
215
+ /** @internal */
216
+ name: model.name ?? model.id,
217
+ /** @internal */
218
+ reasoning: model.reasoning ?? false,
219
+ /** @internal */
220
+ input: model.input ?? ["text" as const],
221
+ /** @internal */
222
+ cost: model.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
223
+ // Match Pi's defaults for explicitly configured models.
224
+ /** @internal */
225
+ contextWindow: model.contextWindow ?? 128_000,
226
+ /** @internal */
227
+ maxTokens: model.maxTokens ?? 16_384,
228
+ };
229
+ });
84
230
  }
85
231
 
86
232
  function assertKnownFields(
@@ -109,6 +255,7 @@ function resolveSecret(value: unknown, location: string): string {
109
255
  return resolved;
110
256
  }
111
257
 
258
+ /** @internal */
112
259
  export function parseApiKeyCredential(value: unknown, providerId: string): ApiKeyCredential {
113
260
  if (!isRecord(value)) throw new Error(`${providerId} credential must be an object`);
114
261
  assertKnownFields(value, ["apiKey"], `${providerId} credential`);
@@ -119,15 +266,21 @@ function apiKeySecrets(credential: ApiKeyCredential | null): Readonly<Record<str
119
266
  return credential ? { apiKey: credential.apiKey } : {};
120
267
  }
121
268
 
269
+ /** @internal */
122
270
  export function parseStandardProviderConfig(
123
271
  raw: unknown,
124
272
  providerId: string,
125
- ): { config: StandardProviderConfig; credential?: ApiKeyCredential } {
273
+ ): {
274
+ /** @internal */
275
+ config: StandardProviderConfig;
276
+ /** @internal */
277
+ credential?: ApiKeyCredential;
278
+ } {
126
279
  if (raw !== undefined && raw !== null && !isRecord(raw)) {
127
280
  throw new Error("configuration must be an object");
128
281
  }
129
282
  const rawConfig = (raw ?? {}) as Record<string, unknown>;
130
- assertKnownFields(rawConfig, ["api_key", "base_url"]);
283
+ assertKnownFields(rawConfig, ["api_key", "base_url", "models"]);
131
284
  const apiKey =
132
285
  rawConfig.api_key === undefined || rawConfig.api_key === null
133
286
  ? getStandardEnvApiKey(providerId)
@@ -136,8 +289,16 @@ export function parseStandardProviderConfig(
136
289
  rawConfig.base_url === undefined || rawConfig.base_url === null
137
290
  ? undefined
138
291
  : v.parse(baseUrlSchema, resolveSecret(rawConfig.base_url, "base_url"));
292
+ const models =
293
+ rawConfig.models === undefined
294
+ ? undefined
295
+ : normalizeStandardModels(
296
+ providerId,
297
+ v.parse(modelDefinitionsSchema, rawConfig.models),
298
+ baseUrl,
299
+ );
139
300
  return {
140
- config: { ...(baseUrl ? { baseUrl } : {}) },
301
+ config: { ...(baseUrl ? { baseUrl } : {}), ...(models ? { models } : {}) },
141
302
  ...(apiKey ? { credential: { apiKey } } : {}),
142
303
  };
143
304
  }
@@ -158,19 +319,24 @@ function catalogModelStatuses(
158
319
  );
159
320
  }
160
321
 
322
+ /** @internal */
161
323
  export function evaluateStandardModelStatuses(
162
324
  providerId: string,
163
- ctx: ModelProviderModelsContext,
325
+ ctx: ModelProviderModelsContext<StandardProviderConfig>,
164
326
  ): readonly ProviderModelStatus[] {
165
327
  return catalogModelStatuses(
166
328
  ctx,
167
- new Set(getBuiltinModels(providerId as never).map(({ id }) => id)),
329
+ new Set([
330
+ ...getBuiltinModels(providerId as never).map(({ id }) => id),
331
+ ...(ctx.config.models ?? []).map(({ id }) => id),
332
+ ]),
168
333
  ctx.credentialStatus.available,
169
334
  (modelId) => `Canonical Pi model '${providerId}/${modelId}' is not found in catalog`,
170
335
  `${providerId} credentials are unavailable (set ${getKnownEnvKeys(providerId).join(" or ")})`,
171
336
  );
172
337
  }
173
338
 
339
+ /** @internal */
174
340
  export function createStandardModelProvider(
175
341
  providerId: string,
176
342
  ): ModelProviderDefinition<StandardProviderConfig, ApiKeyCredential> {
@@ -179,7 +345,7 @@ export function createStandardModelProvider(
179
345
  id: providerId,
180
346
  parseConfig: (raw) => parseStandardProviderConfig(raw, providerId),
181
347
  worker: configuredPiProvider(providerId, ({ config }) => ({
182
- providers: config.baseUrl ? { [providerId]: { baseUrl: config.baseUrl } } : {},
348
+ providers: config.baseUrl || config.models ? { [providerId]: { ...config } } : {},
183
349
  })),
184
350
  server: reference,
185
351
  models: (ctx) => evaluateStandardModelStatuses(providerId, ctx),
@@ -188,16 +354,17 @@ export function createStandardModelProvider(
188
354
  });
189
355
  }
190
356
 
357
+ /** @internal */
191
358
  export function parseCustomGatewayConfig(
192
359
  providerId: string,
193
360
  raw: unknown,
194
- ): { config: CustomGatewayConfig; credential?: ApiKeyCredential } {
361
+ ): {
362
+ /** @internal */
363
+ config: CustomGatewayConfig;
364
+ /** @internal */
365
+ credential?: ApiKeyCredential;
366
+ } {
195
367
  const parsed = v.parse(customGatewaySchema, raw);
196
- const ids = new Set<string>();
197
- for (const model of parsed.models) {
198
- if (ids.has(model.id)) throw new Error(`duplicate custom model id '${model.id}'`);
199
- ids.add(model.id);
200
- }
201
368
  const keyless = parsed.api_key === false;
202
369
  const apiKey =
203
370
  keyless || parsed.api_key === undefined || parsed.api_key === null
@@ -209,38 +376,14 @@ export function parseCustomGatewayConfig(
209
376
  baseUrl: parsed.base_url,
210
377
  api: parsed.api,
211
378
  keyless,
379
+ ...(parsed.compat === undefined ? {} : { compat: parsed.compat }),
212
380
  models: parsed.models,
213
381
  },
214
382
  ...(apiKey ? { credential: { apiKey } } : {}),
215
383
  };
216
384
  }
217
385
 
218
- function customGatewayPiModels(config: CustomGatewayConfig): ProviderJsonObject {
219
- return {
220
- providers: {
221
- [config.providerId]: {
222
- baseUrl: config.baseUrl,
223
- api: config.api,
224
- models: config.models,
225
- },
226
- },
227
- };
228
- }
229
-
230
- function customGatewayModelStatuses(
231
- config: CustomGatewayConfig,
232
- ctx: ModelProviderModelsContext<CustomGatewayConfig>,
233
- ): readonly ProviderModelStatus[] {
234
- return catalogModelStatuses(
235
- ctx,
236
- new Set(config.models.map(({ id }) => id)),
237
- config.keyless || ctx.credentialStatus.available,
238
- (modelId) =>
239
- `Canonical model '${config.providerId}/${modelId}' is not found in custom gateway definition`,
240
- `Gateway provider '${config.providerId}' credentials are unavailable`,
241
- );
242
- }
243
-
386
+ /** @internal */
244
387
  export function createCustomGatewayProvider(
245
388
  providerId: string,
246
389
  keyless: boolean,
@@ -248,8 +391,25 @@ export function createCustomGatewayProvider(
248
391
  return defineModelProvider({
249
392
  id: providerId,
250
393
  parseConfig: (raw) => parseCustomGatewayConfig(providerId, raw),
251
- worker: configuredPiProvider(providerId, ({ config }) => customGatewayPiModels(config)),
252
- models: (ctx) => customGatewayModelStatuses(ctx.config, ctx),
394
+ worker: configuredPiProvider(providerId, ({ config }) => ({
395
+ providers: {
396
+ [config.providerId]: {
397
+ baseUrl: config.baseUrl,
398
+ api: config.api,
399
+ ...(config.compat === undefined ? {} : { compat: config.compat }),
400
+ models: config.models,
401
+ },
402
+ },
403
+ })),
404
+ models: (ctx) =>
405
+ catalogModelStatuses(
406
+ ctx,
407
+ new Set(ctx.config.models.map(({ id }) => id)),
408
+ ctx.config.keyless || ctx.credentialStatus.available,
409
+ (modelId) =>
410
+ `Canonical model '${ctx.config.providerId}/${modelId}' is not found in custom gateway definition`,
411
+ `Gateway provider '${ctx.config.providerId}' credentials are unavailable`,
412
+ ),
253
413
  ...(keyless
254
414
  ? {}
255
415
  : { credential: { parse: (value: unknown) => parseApiKeyCredential(value, providerId) } }),
@@ -258,6 +418,7 @@ export function createCustomGatewayProvider(
258
418
  });
259
419
  }
260
420
 
421
+ /** @internal */
261
422
  export function resolveModelProviders(raw: unknown): readonly ModelProviderSetEntry[] {
262
423
  if (raw !== undefined && raw !== null && !isRecord(raw)) {
263
424
  throw new Error("configuration must be an object");
@@ -36,10 +36,12 @@ const STANDARD_PROVIDER_ENV_KEYS: Readonly<Record<string, readonly string[]>> =
36
36
  "zai-coding-cn": ["ZAI_CODING_CN_API_KEY"],
37
37
  };
38
38
 
39
+ /** @internal */
39
40
  export function getKnownEnvKeys(providerId: string): readonly string[] {
40
41
  return STANDARD_PROVIDER_ENV_KEYS[providerId] ?? [];
41
42
  }
42
43
 
44
+ /** @internal */
43
45
  export function getStandardEnvApiKey(providerId: string): string | undefined {
44
46
  for (const key of getKnownEnvKeys(providerId)) {
45
47
  const value = process.env[key]?.trim();
@@ -48,7 +50,7 @@ export function getStandardEnvApiKey(providerId: string): string | undefined {
48
50
  return undefined;
49
51
  }
50
52
 
51
- /** Built-in providers whose credentials fit Leitwerk's standard API-key projection. */
53
+ /** Built-in providers whose credentials fit Leitwerk's standard API-key projection. @internal */
52
54
  export function getSupportedStandardProviders(): readonly string[] {
53
55
  return Object.keys(STANDARD_PROVIDER_ENV_KEYS);
54
56
  }
@@ -1,185 +0,0 @@
1
- import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
2
- import { builtinPiProvider, configuredPiProvider, defineModelProvider, } from "@leitwerk-dev/process-sdk";
3
- import * as v from "valibot";
4
- import { getKnownEnvKeys, getStandardEnvApiKey, getSupportedStandardProviders, } from "./provider-auth.js";
5
- const nonEmptyStringSchema = v.pipe(v.string(), v.transform((value) => value.trim()), v.minLength(1));
6
- const positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
7
- const baseUrlSchema = v.pipe(nonEmptyStringSchema, v.url(), v.check((value) => ["http:", "https:"].includes(new URL(value).protocol)), v.transform((value) => {
8
- const url = new URL(value);
9
- url.pathname = url.pathname.replace(/\/+$/u, "");
10
- return url.toString().replace(/\/$/u, "");
11
- }));
12
- const customModelSchema = v.pipe(v.strictObject({
13
- id: nonEmptyStringSchema,
14
- name: v.optional(nonEmptyStringSchema),
15
- reasoning: v.optional(v.boolean()),
16
- context_window: v.optional(positiveIntegerSchema),
17
- max_tokens: v.optional(positiveIntegerSchema),
18
- }), v.transform(({ context_window, max_tokens, ...model }) => ({
19
- ...model,
20
- ...(context_window === undefined ? {} : { contextWindow: context_window }),
21
- ...(max_tokens === undefined ? {} : { maxTokens: max_tokens }),
22
- })));
23
- const customGatewaySchema = v.strictObject({
24
- base_url: baseUrlSchema,
25
- api_key: v.optional(v.nullable(v.union([v.literal(false), nonEmptyStringSchema]))),
26
- api: v.optional(v.picklist([
27
- "openai-completions",
28
- "openai-responses",
29
- "anthropic-messages",
30
- "google-generative-ai",
31
- ]), "openai-completions"),
32
- models: v.pipe(v.array(customModelSchema), v.minLength(1)),
33
- });
34
- function isRecord(value) {
35
- return typeof value === "object" && value !== null && !Array.isArray(value);
36
- }
37
- function assertKnownFields(value, allowed, location = "configuration") {
38
- const known = new Set(allowed);
39
- const unknown = Object.keys(value).find((key) => !known.has(key));
40
- if (unknown)
41
- throw new Error(`${location} contains unknown field '${unknown}'`);
42
- }
43
- function nonEmptyString(value, location) {
44
- if (typeof value !== "string")
45
- throw new Error(`${location} must be a string`);
46
- const normalized = value.trim();
47
- if (!normalized)
48
- throw new Error(`${location} must not be empty`);
49
- return normalized;
50
- }
51
- function resolveSecret(value, location) {
52
- const configured = nonEmptyString(value, location);
53
- if (!configured.startsWith("env:"))
54
- return configured;
55
- const variable = nonEmptyString(configured.slice(4), `${location} environment variable`);
56
- const resolved = process.env[variable]?.trim();
57
- if (!resolved)
58
- throw new Error(`${location} references unset environment variable '${variable}'`);
59
- return resolved;
60
- }
61
- export function parseApiKeyCredential(value, providerId) {
62
- if (!isRecord(value))
63
- throw new Error(`${providerId} credential must be an object`);
64
- assertKnownFields(value, ["apiKey"], `${providerId} credential`);
65
- return { apiKey: nonEmptyString(value.apiKey, `${providerId} credential apiKey`) };
66
- }
67
- function apiKeySecrets(credential) {
68
- return credential ? { apiKey: credential.apiKey } : {};
69
- }
70
- export function parseStandardProviderConfig(raw, providerId) {
71
- if (raw !== undefined && raw !== null && !isRecord(raw)) {
72
- throw new Error("configuration must be an object");
73
- }
74
- const rawConfig = (raw ?? {});
75
- assertKnownFields(rawConfig, ["api_key", "base_url"]);
76
- const apiKey = rawConfig.api_key === undefined || rawConfig.api_key === null
77
- ? getStandardEnvApiKey(providerId)
78
- : resolveSecret(rawConfig.api_key, "api_key");
79
- const baseUrl = rawConfig.base_url === undefined || rawConfig.base_url === null
80
- ? undefined
81
- : v.parse(baseUrlSchema, resolveSecret(rawConfig.base_url, "base_url"));
82
- return {
83
- config: { ...(baseUrl ? { baseUrl } : {}) },
84
- ...(apiKey ? { credential: { apiKey } } : {}),
85
- };
86
- }
87
- function catalogModelStatuses(ctx, knownModelIds, credentialsAvailable, missingReason, credentialReason) {
88
- return [...new Set(ctx.configuredModels.map(({ modelId }) => modelId))].map((modelId) => !knownModelIds.has(modelId)
89
- ? { modelId, availability: "unavailable", safeReason: missingReason(modelId) }
90
- : credentialsAvailable
91
- ? { modelId, availability: "available" }
92
- : { modelId, availability: "unavailable", safeReason: credentialReason });
93
- }
94
- export function evaluateStandardModelStatuses(providerId, ctx) {
95
- return catalogModelStatuses(ctx, new Set(getBuiltinModels(providerId).map(({ id }) => id)), ctx.credentialStatus.available, (modelId) => `Canonical Pi model '${providerId}/${modelId}' is not found in catalog`, `${providerId} credentials are unavailable (set ${getKnownEnvKeys(providerId).join(" or ")})`);
96
- }
97
- export function createStandardModelProvider(providerId) {
98
- const reference = builtinPiProvider(providerId);
99
- return defineModelProvider({
100
- id: providerId,
101
- parseConfig: (raw) => parseStandardProviderConfig(raw, providerId),
102
- worker: configuredPiProvider(providerId, ({ config }) => ({
103
- providers: config.baseUrl ? { [providerId]: { baseUrl: config.baseUrl } } : {},
104
- })),
105
- server: reference,
106
- models: (ctx) => evaluateStandardModelStatuses(providerId, ctx),
107
- credential: { parse: (value) => parseApiKeyCredential(value, providerId) },
108
- secrets: ({ credential }) => apiKeySecrets(credential),
109
- });
110
- }
111
- export function parseCustomGatewayConfig(providerId, raw) {
112
- const parsed = v.parse(customGatewaySchema, raw);
113
- const ids = new Set();
114
- for (const model of parsed.models) {
115
- if (ids.has(model.id))
116
- throw new Error(`duplicate custom model id '${model.id}'`);
117
- ids.add(model.id);
118
- }
119
- const keyless = parsed.api_key === false;
120
- const apiKey = keyless || parsed.api_key === undefined || parsed.api_key === null
121
- ? undefined
122
- : resolveSecret(parsed.api_key, "api_key");
123
- return {
124
- config: {
125
- providerId,
126
- baseUrl: parsed.base_url,
127
- api: parsed.api,
128
- keyless,
129
- models: parsed.models,
130
- },
131
- ...(apiKey ? { credential: { apiKey } } : {}),
132
- };
133
- }
134
- function customGatewayPiModels(config) {
135
- return {
136
- providers: {
137
- [config.providerId]: {
138
- baseUrl: config.baseUrl,
139
- api: config.api,
140
- models: config.models,
141
- },
142
- },
143
- };
144
- }
145
- function customGatewayModelStatuses(config, ctx) {
146
- return catalogModelStatuses(ctx, new Set(config.models.map(({ id }) => id)), config.keyless || ctx.credentialStatus.available, (modelId) => `Canonical model '${config.providerId}/${modelId}' is not found in custom gateway definition`, `Gateway provider '${config.providerId}' credentials are unavailable`);
147
- }
148
- export function createCustomGatewayProvider(providerId, keyless) {
149
- return defineModelProvider({
150
- id: providerId,
151
- parseConfig: (raw) => parseCustomGatewayConfig(providerId, raw),
152
- worker: configuredPiProvider(providerId, ({ config }) => customGatewayPiModels(config)),
153
- models: (ctx) => customGatewayModelStatuses(ctx.config, ctx),
154
- ...(keyless
155
- ? {}
156
- : { credential: { parse: (value) => parseApiKeyCredential(value, providerId) } }),
157
- secrets: ({ credential }) => apiKeySecrets(credential ?? (keyless ? { apiKey: "leitwerk-keyless" } : null)),
158
- });
159
- }
160
- export function resolveModelProviders(raw) {
161
- if (raw !== undefined && raw !== null && !isRecord(raw)) {
162
- throw new Error("configuration must be an object");
163
- }
164
- const owner = (raw ?? {});
165
- const standardIds = getSupportedStandardProviders();
166
- assertKnownFields(owner, [...standardIds, "custom_gateways"]);
167
- const entries = standardIds.map((providerId) => ({
168
- definition: createStandardModelProvider(providerId),
169
- rawConfig: owner[providerId],
170
- }));
171
- if (owner.custom_gateways === undefined)
172
- return entries;
173
- if (!isRecord(owner.custom_gateways))
174
- throw new Error("custom_gateways must be an object");
175
- for (const [providerId, gateway] of Object.entries(owner.custom_gateways)) {
176
- if (!providerId.trim())
177
- throw new Error("custom gateway provider id must not be empty");
178
- entries.push({
179
- definition: createCustomGatewayProvider(providerId, isRecord(gateway) && gateway.api_key === false),
180
- rawConfig: gateway,
181
- });
182
- }
183
- return entries;
184
- }
185
- //# sourceMappingURL=models-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"models-provider.js","sourceRoot":"","sources":["../src/models-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EACN,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,GAMnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EACN,eAAe,EACf,oBAAoB,EACpB,6BAA6B,GAC7B,MAAM,oBAAoB,CAAC;AAU5B,MAAM,oBAAoB,GAAG,CAAC,CAAC,IAAI,CAClC,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EACpC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CACd,CAAC;AACF,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAA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