@leitwerk-dev/models 0.2.0 → 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,53 +1,96 @@
1
1
  import { type ModelProviderDefinition, type ModelProviderModelsContext, type ModelProviderSetEntry, type ProviderModelStatus } from "@leitwerk-dev/process-sdk";
2
2
  import * as v from "valibot";
3
+ /** @internal */
3
4
  export interface StandardProviderConfig {
5
+ /** @internal */
4
6
  readonly baseUrl?: string;
7
+ /** @internal */
5
8
  readonly models?: ReturnType<typeof normalizeStandardModels>;
6
9
  }
10
+ /** @internal */
7
11
  export interface ApiKeyCredential {
12
+ /** @internal */
8
13
  readonly apiKey: string;
9
14
  }
15
+ /** @internal */
10
16
  declare const compatibilitySchema: v.StrictObjectSchema<{
17
+ /** @internal */
11
18
  readonly supportsStore: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
19
+ /** @internal */
12
20
  readonly supportsDeveloperRole: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
21
+ /** @internal */
13
22
  readonly supportsReasoningEffort: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
23
+ /** @internal */
14
24
  readonly supportsUsageInStreaming: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
25
+ /** @internal */
15
26
  readonly maxTokensField: v.OptionalSchema<v.PicklistSchema<["max_tokens", "max_completion_tokens"], undefined>, undefined>;
27
+ /** @internal */
16
28
  readonly supportsStrictMode: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
29
+ /** @internal */
17
30
  readonly requiresReasoningContentOnAssistantMessages: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
31
+ /** @internal */
18
32
  readonly thinkingFormat: v.OptionalSchema<v.PicklistSchema<["openai", "openrouter", "deepseek", "together", "zai", "qwen", "chat-template", "qwen-chat-template", "string-thinking", "ant-ling"], undefined>, undefined>;
19
33
  }, undefined>;
34
+ /** @internal */
20
35
  declare const customModelSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
36
+ /** @internal */
21
37
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>;
38
+ /** @internal */
22
39
  readonly name: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
40
+ /** @internal */
23
41
  readonly reasoning: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
42
+ /** @internal */
24
43
  readonly thinking_level_map: v.OptionalSchema<v.StrictObjectSchema<{
44
+ /** @internal */
25
45
  readonly off: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>, undefined>;
46
+ /** @internal */
26
47
  readonly minimal: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>, undefined>;
48
+ /** @internal */
27
49
  readonly low: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>, undefined>;
50
+ /** @internal */
28
51
  readonly medium: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>, undefined>;
52
+ /** @internal */
29
53
  readonly high: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>, undefined>;
54
+ /** @internal */
30
55
  readonly xhigh: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>, undefined>;
56
+ /** @internal */
31
57
  readonly max: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>, undefined>;
32
58
  }, undefined>, undefined>;
59
+ /** @internal */
33
60
  readonly input: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<["text", "image"], undefined>, undefined>, v.MinLengthAction<("text" | "image")[], 1, undefined>]>, undefined>;
61
+ /** @internal */
34
62
  readonly cost: v.OptionalSchema<v.StrictObjectSchema<{
63
+ /** @internal */
35
64
  readonly input: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
65
+ /** @internal */
36
66
  readonly output: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
67
+ /** @internal */
37
68
  readonly cacheRead: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
69
+ /** @internal */
38
70
  readonly cacheWrite: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
39
71
  }, undefined>, undefined>;
72
+ /** @internal */
40
73
  readonly compat: v.OptionalSchema<v.StrictObjectSchema<{
74
+ /** @internal */
41
75
  readonly supportsStore: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
76
+ /** @internal */
42
77
  readonly supportsDeveloperRole: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
78
+ /** @internal */
43
79
  readonly supportsReasoningEffort: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
80
+ /** @internal */
44
81
  readonly supportsUsageInStreaming: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
82
+ /** @internal */
45
83
  readonly maxTokensField: v.OptionalSchema<v.PicklistSchema<["max_tokens", "max_completion_tokens"], undefined>, undefined>;
84
+ /** @internal */
46
85
  readonly supportsStrictMode: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
86
+ /** @internal */
47
87
  readonly requiresReasoningContentOnAssistantMessages: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
88
+ /** @internal */
48
89
  readonly thinkingFormat: v.OptionalSchema<v.PicklistSchema<["openai", "openrouter", "deepseek", "together", "zai", "qwen", "chat-template", "qwen-chat-template", "string-thinking", "ant-ling"], undefined>, undefined>;
49
90
  }, undefined>, undefined>;
91
+ /** @internal */
50
92
  readonly context_window: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>, undefined>;
93
+ /** @internal */
51
94
  readonly max_tokens: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>, undefined>;
52
95
  }, undefined>, v.TransformAction<{
53
96
  id: string;
@@ -114,29 +157,47 @@ declare const customModelSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema
114
157
  thinkingFormat?: "ant-ling" | "deepseek" | "openai" | "openrouter" | "together" | "zai" | "qwen" | "chat-template" | "qwen-chat-template" | "string-thinking" | undefined;
115
158
  } | undefined;
116
159
  }>]>;
160
+ /** @internal */
117
161
  export type CustomModelDefinition = v.InferOutput<typeof customModelSchema>;
162
+ /** @internal */
118
163
  export interface CustomGatewayConfig {
164
+ /** @internal */
119
165
  readonly providerId: string;
166
+ /** @internal */
120
167
  readonly baseUrl: string;
168
+ /** @internal */
121
169
  readonly api: string;
170
+ /** @internal */
122
171
  readonly keyless: boolean;
172
+ /** @internal */
123
173
  readonly compat?: v.InferOutput<typeof compatibilitySchema>;
174
+ /** @internal */
124
175
  readonly models: CustomModelDefinition[];
125
176
  }
177
+ /** @internal */
126
178
  declare function normalizeStandardModels(providerId: string, models: CustomModelDefinition[], baseUrl?: string): {
179
+ /** @internal */
127
180
  provider: string;
181
+ /** @internal */
128
182
  api: never;
183
+ /** @internal */
129
184
  baseUrl: string;
185
+ /** @internal */
130
186
  name: string;
187
+ /** @internal */
131
188
  reasoning: boolean;
189
+ /** @internal */
132
190
  input: ("text" | "image")[];
191
+ /** @internal */
133
192
  cost: {
134
193
  input: number;
135
194
  output: number;
136
195
  cacheRead: number;
137
196
  cacheWrite: number;
138
197
  };
198
+ /** @internal */
139
199
  contextWindow: number;
200
+ /** @internal */
140
201
  maxTokens: number;
141
202
  thinkingLevelMap?: {
142
203
  off?: string | null | undefined;
@@ -159,18 +220,29 @@ declare function normalizeStandardModels(providerId: string, models: CustomModel
159
220
  thinkingFormat?: "ant-ling" | "deepseek" | "openai" | "openrouter" | "together" | "zai" | "qwen" | "chat-template" | "qwen-chat-template" | "string-thinking" | undefined;
160
221
  } | undefined;
161
222
  }[];
223
+ /** @internal */
162
224
  export declare function parseApiKeyCredential(value: unknown, providerId: string): ApiKeyCredential;
225
+ /** @internal */
163
226
  export declare function parseStandardProviderConfig(raw: unknown, providerId: string): {
227
+ /** @internal */
164
228
  config: StandardProviderConfig;
229
+ /** @internal */
165
230
  credential?: ApiKeyCredential;
166
231
  };
232
+ /** @internal */
167
233
  export declare function evaluateStandardModelStatuses(providerId: string, ctx: ModelProviderModelsContext<StandardProviderConfig>): readonly ProviderModelStatus[];
234
+ /** @internal */
168
235
  export declare function createStandardModelProvider(providerId: string): ModelProviderDefinition<StandardProviderConfig, ApiKeyCredential>;
236
+ /** @internal */
169
237
  export declare function parseCustomGatewayConfig(providerId: string, raw: unknown): {
238
+ /** @internal */
170
239
  config: CustomGatewayConfig;
240
+ /** @internal */
171
241
  credential?: ApiKeyCredential;
172
242
  };
243
+ /** @internal */
173
244
  export declare function createCustomGatewayProvider(providerId: string, keyless: boolean): ModelProviderDefinition<CustomGatewayConfig, ApiKeyCredential>;
245
+ /** @internal */
174
246
  export declare function resolveModelProviders(raw: unknown): readonly ModelProviderSetEntry[];
175
247
  export {};
176
248
  //# s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,EAAE,gBAAgB,CAAC,CAanE;AAED,gBAAgB;AAChB,wBAAgB,wBAAwB,CACvC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,OAAO,GACV;IACF,gBAAgB;IAChB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,gBAAgB;IAChB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B,CAkBA;AAED,gBAAgB;AAChB,wBAAgB,2BAA2B,CAC1C,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,GACd,uBAAuB,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CA6BhE;AAED,gBAAgB;AAChB,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,qBAAqB,EAAE,CAwBpF"}
@@ -1,5 +1,7 @@
1
+ /** @internal */
1
2
  export declare function getKnownEnvKeys(providerId: string): readonly string[];
3
+ /** @internal */
2
4
  export declare function getStandardEnvApiKey(providerId: string): string | undefined;
3
- /** Built-in providers whose credentials fit Leitwerk's standard API-key projection. */
5
+ /** Built-in providers whose credentials fit Leitwerk's standard API-key projection. @internal */
4
6
  export declare function getSupportedStandardProviders(): readonly string[];
5
7
  //# sourceMappingURL=provider-auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider-auth.d.ts","sourceRoot":"","sources":["../src/provider-auth.ts"],"names":[],"mappings":"AAsCA,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAErE;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAM3E;AAED,uFAAuF;AACvF,wBAAgB,6BAA6B,IAAI,SAAS,MAAM,EAAE,CAEjE"}
1
+ {"version":3,"file":"provider-auth.d.ts","sourceRoot":"","sources":["../src/provider-auth.ts"],"names":[],"mappings":"AAsCA,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAErE;AAED,gBAAgB;AAChB,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAM3E;AAED,iGAAiG;AACjG,wBAAgB,6BAA6B,IAAI,SAAS,MAAM,EAAE,CAEjE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leitwerk-dev/models",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/leitwerk-dev/leitwerk.git",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@earendil-works/pi-ai": "^0.81.1",
29
- "@leitwerk-dev/process-sdk": "0.2.0",
29
+ "@leitwerk-dev/process-sdk": "0.2.1",
30
30
  "valibot": "^1.3.1"
31
31
  },
32
32
  "devDependencies": {
package/src/index.ts CHANGED
@@ -1,16 +1,20 @@
1
1
  import { defineModelProviders, type LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
2
2
  import { resolveModelProviders } from "./models-provider.js";
3
3
 
4
- export const manifest = {
4
+ /** @internal */
5
+ const manifest = {
6
+ /** @internal */
5
7
  id: "models",
8
+ /** @internal */
6
9
  version: "0.1.0",
7
10
  } as const;
8
11
 
9
- const modelsExtension = {
12
+ /** @public */
13
+ const modelsExtension: LeitwerkExtensionModule = {
14
+ /** @internal */
10
15
  manifest,
16
+ /** @internal */
11
17
  modelProviders: defineModelProviders(resolveModelProviders),
12
- } satisfies LeitwerkExtensionModule;
18
+ };
13
19
 
14
20
  export default modelsExtension;
15
- export * from "./models-provider.js";
16
- export * from "./provider-auth.js";
@@ -16,12 +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 */
21
24
  readonly models?: ReturnType<typeof normalizeStandardModels>;
22
25
  }
23
26
 
27
+ /** @internal */
24
28
  export interface ApiKeyCredential {
29
+ /** @internal */
25
30
  readonly apiKey: string;
26
31
  }
27
32
 
@@ -34,23 +39,39 @@ const positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
34
39
  const nonNegativeNumberSchema = v.pipe(v.number(), v.finite(), v.minValue(0));
35
40
  const thinkingLevelValueSchema = v.optional(v.nullable(nonEmptyStringSchema));
36
41
  const thinkingLevelMapSchema = v.strictObject({
42
+ /** @internal */
37
43
  off: thinkingLevelValueSchema,
44
+ /** @internal */
38
45
  minimal: thinkingLevelValueSchema,
46
+ /** @internal */
39
47
  low: thinkingLevelValueSchema,
48
+ /** @internal */
40
49
  medium: thinkingLevelValueSchema,
50
+ /** @internal */
41
51
  high: thinkingLevelValueSchema,
52
+ /** @internal */
42
53
  xhigh: thinkingLevelValueSchema,
54
+ /** @internal */
43
55
  max: thinkingLevelValueSchema,
44
56
  });
45
57
  // Compatibility options use Pi's names so they can be copied from models.json.
58
+ /** @internal */
46
59
  const compatibilitySchema = v.strictObject({
60
+ /** @internal */
47
61
  supportsStore: v.optional(v.boolean()),
62
+ /** @internal */
48
63
  supportsDeveloperRole: v.optional(v.boolean()),
64
+ /** @internal */
49
65
  supportsReasoningEffort: v.optional(v.boolean()),
66
+ /** @internal */
50
67
  supportsUsageInStreaming: v.optional(v.boolean()),
68
+ /** @internal */
51
69
  maxTokensField: v.optional(v.picklist(["max_tokens", "max_completion_tokens"])),
70
+ /** @internal */
52
71
  supportsStrictMode: v.optional(v.boolean()),
72
+ /** @internal */
53
73
  requiresReasoningContentOnAssistantMessages: v.optional(v.boolean()),
74
+ /** @internal */
54
75
  thinkingFormat: v.optional(
55
76
  v.picklist([
56
77
  "openai",
@@ -67,9 +88,13 @@ const compatibilitySchema = v.strictObject({
67
88
  ),
68
89
  });
69
90
  const modelCostSchema = v.strictObject({
91
+ /** @internal */
70
92
  input: nonNegativeNumberSchema,
93
+ /** @internal */
71
94
  output: nonNegativeNumberSchema,
95
+ /** @internal */
72
96
  cacheRead: nonNegativeNumberSchema,
97
+ /** @internal */
73
98
  cacheWrite: nonNegativeNumberSchema,
74
99
  });
75
100
  const baseUrlSchema = v.pipe(
@@ -82,23 +107,48 @@ const baseUrlSchema = v.pipe(
82
107
  return url.toString().replace(/\/$/u, "");
83
108
  }),
84
109
  );
110
+ /** @internal */
85
111
  const customModelSchema = v.pipe(
86
112
  v.strictObject({
113
+ /** @internal */
87
114
  id: nonEmptyStringSchema,
115
+ /** @internal */
88
116
  name: v.optional(nonEmptyStringSchema),
117
+ /** @internal */
89
118
  reasoning: v.optional(v.boolean()),
119
+ /** @internal */
90
120
  thinking_level_map: v.optional(thinkingLevelMapSchema),
121
+ /** @internal */
91
122
  input: v.optional(v.pipe(v.array(v.picklist(["text", "image"])), v.minLength(1))),
123
+ /** @internal */
92
124
  cost: v.optional(modelCostSchema),
125
+ /** @internal */
93
126
  compat: v.optional(compatibilitySchema),
127
+ /** @internal */
94
128
  context_window: v.optional(positiveIntegerSchema),
129
+ /** @internal */
95
130
  max_tokens: v.optional(positiveIntegerSchema),
96
131
  }),
97
132
  v.transform(({ context_window, max_tokens, thinking_level_map, ...model }) => ({
98
133
  ...model,
99
- ...(thinking_level_map === undefined ? {} : { thinkingLevelMap: thinking_level_map }),
100
- ...(context_window === undefined ? {} : { contextWindow: context_window }),
101
- ...(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
+ }),
102
152
  })),
103
153
  );
104
154
  const modelDefinitionsSchema = v.pipe(
@@ -125,17 +175,26 @@ const customGatewaySchema = v.strictObject({
125
175
  models: modelDefinitionsSchema,
126
176
  });
127
177
 
178
+ /** @internal */
128
179
  export type CustomModelDefinition = v.InferOutput<typeof customModelSchema>;
129
180
 
181
+ /** @internal */
130
182
  export interface CustomGatewayConfig {
183
+ /** @internal */
131
184
  readonly providerId: string;
185
+ /** @internal */
132
186
  readonly baseUrl: string;
187
+ /** @internal */
133
188
  readonly api: string;
189
+ /** @internal */
134
190
  readonly keyless: boolean;
191
+ /** @internal */
135
192
  readonly compat?: v.InferOutput<typeof compatibilitySchema>;
193
+ /** @internal */
136
194
  readonly models: CustomModelDefinition[];
137
195
  }
138
196
 
197
+ /** @internal */
139
198
  function normalizeStandardModels(
140
199
  providerId: string,
141
200
  models: CustomModelDefinition[],
@@ -147,15 +206,24 @@ function normalizeStandardModels(
147
206
  if (!reference) throw new Error(`Provider '${providerId}' has no canonical API definition`);
148
207
  return {
149
208
  ...model,
209
+ /** @internal */
150
210
  provider: providerId,
211
+ /** @internal */
151
212
  api: reference.api,
213
+ /** @internal */
152
214
  baseUrl: baseUrl ?? reference.baseUrl,
215
+ /** @internal */
153
216
  name: model.name ?? model.id,
217
+ /** @internal */
154
218
  reasoning: model.reasoning ?? false,
219
+ /** @internal */
155
220
  input: model.input ?? ["text" as const],
221
+ /** @internal */
156
222
  cost: model.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
157
223
  // Match Pi's defaults for explicitly configured models.
224
+ /** @internal */
158
225
  contextWindow: model.contextWindow ?? 128_000,
226
+ /** @internal */
159
227
  maxTokens: model.maxTokens ?? 16_384,
160
228
  };
161
229
  });
@@ -187,6 +255,7 @@ function resolveSecret(value: unknown, location: string): string {
187
255
  return resolved;
188
256
  }
189
257
 
258
+ /** @internal */
190
259
  export function parseApiKeyCredential(value: unknown, providerId: string): ApiKeyCredential {
191
260
  if (!isRecord(value)) throw new Error(`${providerId} credential must be an object`);
192
261
  assertKnownFields(value, ["apiKey"], `${providerId} credential`);
@@ -197,10 +266,16 @@ function apiKeySecrets(credential: ApiKeyCredential | null): Readonly<Record<str
197
266
  return credential ? { apiKey: credential.apiKey } : {};
198
267
  }
199
268
 
269
+ /** @internal */
200
270
  export function parseStandardProviderConfig(
201
271
  raw: unknown,
202
272
  providerId: string,
203
- ): { config: StandardProviderConfig; credential?: ApiKeyCredential } {
273
+ ): {
274
+ /** @internal */
275
+ config: StandardProviderConfig;
276
+ /** @internal */
277
+ credential?: ApiKeyCredential;
278
+ } {
204
279
  if (raw !== undefined && raw !== null && !isRecord(raw)) {
205
280
  throw new Error("configuration must be an object");
206
281
  }
@@ -214,19 +289,16 @@ export function parseStandardProviderConfig(
214
289
  rawConfig.base_url === undefined || rawConfig.base_url === null
215
290
  ? undefined
216
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
+ );
217
300
  return {
218
- config: {
219
- ...(baseUrl ? { baseUrl } : {}),
220
- ...(rawConfig.models === undefined
221
- ? {}
222
- : {
223
- models: normalizeStandardModels(
224
- providerId,
225
- v.parse(modelDefinitionsSchema, rawConfig.models),
226
- baseUrl,
227
- ),
228
- }),
229
- },
301
+ config: { ...(baseUrl ? { baseUrl } : {}), ...(models ? { models } : {}) },
230
302
  ...(apiKey ? { credential: { apiKey } } : {}),
231
303
  };
232
304
  }
@@ -247,6 +319,7 @@ function catalogModelStatuses(
247
319
  );
248
320
  }
249
321
 
322
+ /** @internal */
250
323
  export function evaluateStandardModelStatuses(
251
324
  providerId: string,
252
325
  ctx: ModelProviderModelsContext<StandardProviderConfig>,
@@ -263,6 +336,7 @@ export function evaluateStandardModelStatuses(
263
336
  );
264
337
  }
265
338
 
339
+ /** @internal */
266
340
  export function createStandardModelProvider(
267
341
  providerId: string,
268
342
  ): ModelProviderDefinition<StandardProviderConfig, ApiKeyCredential> {
@@ -280,10 +354,16 @@ export function createStandardModelProvider(
280
354
  });
281
355
  }
282
356
 
357
+ /** @internal */
283
358
  export function parseCustomGatewayConfig(
284
359
  providerId: string,
285
360
  raw: unknown,
286
- ): { config: CustomGatewayConfig; credential?: ApiKeyCredential } {
361
+ ): {
362
+ /** @internal */
363
+ config: CustomGatewayConfig;
364
+ /** @internal */
365
+ credential?: ApiKeyCredential;
366
+ } {
287
367
  const parsed = v.parse(customGatewaySchema, raw);
288
368
  const keyless = parsed.api_key === false;
289
369
  const apiKey =
@@ -303,6 +383,7 @@ export function parseCustomGatewayConfig(
303
383
  };
304
384
  }
305
385
 
386
+ /** @internal */
306
387
  export function createCustomGatewayProvider(
307
388
  providerId: string,
308
389
  keyless: boolean,
@@ -337,6 +418,7 @@ export function createCustomGatewayProvider(
337
418
  });
338
419
  }
339
420
 
421
+ /** @internal */
340
422
  export function resolveModelProviders(raw: unknown): readonly ModelProviderSetEntry[] {
341
423
  if (raw !== undefined && raw !== null && !isRecord(raw)) {
342
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
  }