@leitwerk-dev/models 0.1.0
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.
- package/README.md +41 -0
- package/dist/LICENSE +13 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/models-provider.d.ts +48 -0
- package/dist/models-provider.d.ts.map +1 -0
- package/dist/models-provider.js +172 -0
- package/dist/models-provider.js.map +1 -0
- package/dist/provider-auth.d.ts +5 -0
- package/dist/provider-auth.d.ts.map +1 -0
- package/dist/provider-auth.js +53 -0
- package/dist/provider-auth.js.map +1 -0
- package/package.json +48 -0
- package/src/index.ts +16 -0
- package/src/models-provider.ts +269 -0
- package/src/provider-auth.ts +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Models extension
|
|
2
|
+
|
|
3
|
+
The `models` extension owns Leitwerk's standard Pi providers and configuration-defined custom gateways. Custom gateways use the managed, credential-blind `models.json` snapshot; API keys are seeded into the encrypted provider credential store and projected separately through managed `auth.json`.
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
extension_loading:
|
|
9
|
+
sources:
|
|
10
|
+
- ./extensions/models
|
|
11
|
+
|
|
12
|
+
extensions:
|
|
13
|
+
models:
|
|
14
|
+
openai:
|
|
15
|
+
api_key: env:OPENAI_API_KEY
|
|
16
|
+
anthropic:
|
|
17
|
+
api_key: env:ANTHROPIC_API_KEY
|
|
18
|
+
custom_gateways:
|
|
19
|
+
internal-gateway:
|
|
20
|
+
base_url: https://llm-gateway.example.com/v1
|
|
21
|
+
api_key: false
|
|
22
|
+
api: openai-completions
|
|
23
|
+
models:
|
|
24
|
+
- id: gemma-4-31b-it
|
|
25
|
+
name: Gemma 4 31B IT
|
|
26
|
+
reasoning: true
|
|
27
|
+
context_window: 262144
|
|
28
|
+
max_tokens: 32768
|
|
29
|
+
|
|
30
|
+
pi:
|
|
31
|
+
model_profiles:
|
|
32
|
+
- id: gateway-gemma
|
|
33
|
+
provider: internal-gateway
|
|
34
|
+
model_id: gemma-4-31b-it
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`api_key` accepts a literal value or `env:VARIABLE`. It only initializes an empty durable credential store; a stored revision wins on restart. Set it to `false` only for an endpoint that intentionally accepts unauthenticated requests.
|
|
38
|
+
|
|
39
|
+
The extension uses a code-defined standard-provider list with explicit environment-variable mappings. Pi upgrades do not implicitly enable new providers. Providers with ambient or OAuth-only authentication, including Bedrock and OpenAI Codex, require dedicated extensions.
|
|
40
|
+
|
|
41
|
+
Custom gateways support `openai-completions`, `openai-responses`, `anthropic-messages`, and `google-generative-ai`. They support worker LLM turns. Because they do not declare a server adapter, they cannot be selected for process-title generation.
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2026 Leitwerk contributors.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const manifest: {
|
|
2
|
+
readonly id: "models";
|
|
3
|
+
readonly version: "0.1.0";
|
|
4
|
+
};
|
|
5
|
+
declare const modelsExtension: {
|
|
6
|
+
manifest: {
|
|
7
|
+
readonly id: "models";
|
|
8
|
+
readonly version: "0.1.0";
|
|
9
|
+
};
|
|
10
|
+
modelProviders: import("@leitwerk-dev/process-sdk").ModelProviderSet;
|
|
11
|
+
};
|
|
12
|
+
export default modelsExtension;
|
|
13
|
+
export * from "./models-provider.js";
|
|
14
|
+
export * from "./provider-auth.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ;;;CAGX,CAAC;AAEX,QAAA,MAAM,eAAe;;;;;;CAGc,CAAC;AAEpC,eAAe,eAAe,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineModelProviders } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import { resolveModelProviders } from "./models-provider.js";
|
|
3
|
+
export const manifest = {
|
|
4
|
+
id: "models",
|
|
5
|
+
version: "0.1.0",
|
|
6
|
+
};
|
|
7
|
+
const modelsExtension = {
|
|
8
|
+
manifest,
|
|
9
|
+
modelProviders: defineModelProviders(resolveModelProviders),
|
|
10
|
+
};
|
|
11
|
+
export default modelsExtension;
|
|
12
|
+
export * from "./models-provider.js";
|
|
13
|
+
export * from "./provider-auth.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAgC,MAAM,2BAA2B,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE,OAAO;CACP,CAAC;AAEX,MAAM,eAAe,GAAG;IACvB,QAAQ;IACR,cAAc,EAAE,oBAAoB,CAAC,qBAAqB,CAAC;CACzB,CAAC;AAEpC,eAAe,eAAe,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ModelProviderDefinition, type ModelProviderModelsContext, type ModelProviderSetEntry, type ProviderModelStatus } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
export type EmptyProviderConfig = Record<string, never>;
|
|
4
|
+
export interface ApiKeyCredential {
|
|
5
|
+
readonly apiKey: string;
|
|
6
|
+
}
|
|
7
|
+
declare const customModelSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
8
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>;
|
|
9
|
+
readonly name: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
10
|
+
readonly reasoning: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
11
|
+
readonly context_window: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>, undefined>;
|
|
12
|
+
readonly max_tokens: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>, undefined>;
|
|
13
|
+
}, undefined>, v.TransformAction<{
|
|
14
|
+
id: string;
|
|
15
|
+
name?: string | undefined;
|
|
16
|
+
reasoning?: boolean | undefined;
|
|
17
|
+
context_window?: number | undefined;
|
|
18
|
+
max_tokens?: number | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
maxTokens?: number | undefined;
|
|
21
|
+
contextWindow?: number | undefined;
|
|
22
|
+
id: string;
|
|
23
|
+
name?: string | undefined;
|
|
24
|
+
reasoning?: boolean | undefined;
|
|
25
|
+
}>]>;
|
|
26
|
+
export type CustomModelDefinition = v.InferOutput<typeof customModelSchema>;
|
|
27
|
+
export interface CustomGatewayConfig {
|
|
28
|
+
readonly providerId: string;
|
|
29
|
+
readonly baseUrl: string;
|
|
30
|
+
readonly api: string;
|
|
31
|
+
readonly keyless: boolean;
|
|
32
|
+
readonly models: CustomModelDefinition[];
|
|
33
|
+
}
|
|
34
|
+
export declare function parseApiKeyCredential(value: unknown, providerId: string): ApiKeyCredential;
|
|
35
|
+
export declare function parseStandardProviderConfig(raw: unknown, providerId: string): {
|
|
36
|
+
config: EmptyProviderConfig;
|
|
37
|
+
credential?: ApiKeyCredential;
|
|
38
|
+
};
|
|
39
|
+
export declare function evaluateStandardModelStatuses(providerId: string, ctx: ModelProviderModelsContext): readonly ProviderModelStatus[];
|
|
40
|
+
export declare function createStandardModelProvider(providerId: string): ModelProviderDefinition<EmptyProviderConfig, ApiKeyCredential>;
|
|
41
|
+
export declare function parseCustomGatewayConfig(providerId: string, raw: unknown): {
|
|
42
|
+
config: CustomGatewayConfig;
|
|
43
|
+
credential?: ApiKeyCredential;
|
|
44
|
+
};
|
|
45
|
+
export declare function createCustomGatewayProvider(providerId: string, keyless: boolean): ModelProviderDefinition<CustomGatewayConfig, ApiKeyCredential>;
|
|
46
|
+
export declare function resolveModelProviders(raw: unknown): readonly ModelProviderSetEntry[];
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=models-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models-provider.d.ts","sourceRoot":"","sources":["../src/models-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAIN,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,KAAK,qBAAqB,EAE1B,KAAK,mBAAmB,EACxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAO7B,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAA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B,CAAC,CAYhE;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,qBAAqB,EAAE,CAwBpF"}
|
|
@@ -0,0 +1,172 @@
|
|
|
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 customModelSchema = v.pipe(v.strictObject({
|
|
8
|
+
id: nonEmptyStringSchema,
|
|
9
|
+
name: v.optional(nonEmptyStringSchema),
|
|
10
|
+
reasoning: v.optional(v.boolean()),
|
|
11
|
+
context_window: v.optional(positiveIntegerSchema),
|
|
12
|
+
max_tokens: v.optional(positiveIntegerSchema),
|
|
13
|
+
}), v.transform(({ context_window, max_tokens, ...model }) => ({
|
|
14
|
+
...model,
|
|
15
|
+
...(context_window === undefined ? {} : { contextWindow: context_window }),
|
|
16
|
+
...(max_tokens === undefined ? {} : { maxTokens: max_tokens }),
|
|
17
|
+
})));
|
|
18
|
+
const customGatewaySchema = v.strictObject({
|
|
19
|
+
base_url: v.pipe(nonEmptyStringSchema, v.url(), v.check((value) => ["http:", "https:"].includes(new URL(value).protocol)), v.transform((value) => new URL(value).toString().replace(/\/$/, ""))),
|
|
20
|
+
api_key: v.optional(v.nullable(v.union([v.literal(false), nonEmptyStringSchema]))),
|
|
21
|
+
api: v.optional(v.picklist([
|
|
22
|
+
"openai-completions",
|
|
23
|
+
"openai-responses",
|
|
24
|
+
"anthropic-messages",
|
|
25
|
+
"google-generative-ai",
|
|
26
|
+
]), "openai-completions"),
|
|
27
|
+
models: v.pipe(v.array(customModelSchema), v.minLength(1)),
|
|
28
|
+
});
|
|
29
|
+
function isRecord(value) {
|
|
30
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
function assertKnownFields(value, allowed, location = "configuration") {
|
|
33
|
+
const known = new Set(allowed);
|
|
34
|
+
const unknown = Object.keys(value).find((key) => !known.has(key));
|
|
35
|
+
if (unknown)
|
|
36
|
+
throw new Error(`${location} contains unknown field '${unknown}'`);
|
|
37
|
+
}
|
|
38
|
+
function nonEmptyString(value, location) {
|
|
39
|
+
if (typeof value !== "string")
|
|
40
|
+
throw new Error(`${location} must be a string`);
|
|
41
|
+
const normalized = value.trim();
|
|
42
|
+
if (!normalized)
|
|
43
|
+
throw new Error(`${location} must not be empty`);
|
|
44
|
+
return normalized;
|
|
45
|
+
}
|
|
46
|
+
function resolveSecret(value, location) {
|
|
47
|
+
const configured = nonEmptyString(value, location);
|
|
48
|
+
if (!configured.startsWith("env:"))
|
|
49
|
+
return configured;
|
|
50
|
+
const variable = nonEmptyString(configured.slice(4), `${location} environment variable`);
|
|
51
|
+
const resolved = process.env[variable]?.trim();
|
|
52
|
+
if (!resolved)
|
|
53
|
+
throw new Error(`${location} references unset environment variable '${variable}'`);
|
|
54
|
+
return resolved;
|
|
55
|
+
}
|
|
56
|
+
export function parseApiKeyCredential(value, providerId) {
|
|
57
|
+
if (!isRecord(value))
|
|
58
|
+
throw new Error(`${providerId} credential must be an object`);
|
|
59
|
+
assertKnownFields(value, ["apiKey"], `${providerId} credential`);
|
|
60
|
+
return { apiKey: nonEmptyString(value.apiKey, `${providerId} credential apiKey`) };
|
|
61
|
+
}
|
|
62
|
+
function apiKeySecrets(credential) {
|
|
63
|
+
return credential ? { apiKey: credential.apiKey } : {};
|
|
64
|
+
}
|
|
65
|
+
export function parseStandardProviderConfig(raw, providerId) {
|
|
66
|
+
if (raw !== undefined && raw !== null && !isRecord(raw)) {
|
|
67
|
+
throw new Error("configuration must be an object");
|
|
68
|
+
}
|
|
69
|
+
const config = (raw ?? {});
|
|
70
|
+
assertKnownFields(config, ["api_key"]);
|
|
71
|
+
const apiKey = config.api_key === undefined || config.api_key === null
|
|
72
|
+
? getStandardEnvApiKey(providerId)
|
|
73
|
+
: resolveSecret(config.api_key, "api_key");
|
|
74
|
+
return { config: {}, ...(apiKey ? { credential: { apiKey } } : {}) };
|
|
75
|
+
}
|
|
76
|
+
function catalogModelStatuses(ctx, knownModelIds, credentialsAvailable, missingReason, credentialReason) {
|
|
77
|
+
return [...new Set(ctx.configuredModels.map(({ modelId }) => modelId))].map((modelId) => !knownModelIds.has(modelId)
|
|
78
|
+
? { modelId, availability: "unavailable", safeReason: missingReason(modelId) }
|
|
79
|
+
: credentialsAvailable
|
|
80
|
+
? { modelId, availability: "available" }
|
|
81
|
+
: { modelId, availability: "unavailable", safeReason: credentialReason });
|
|
82
|
+
}
|
|
83
|
+
export function evaluateStandardModelStatuses(providerId, ctx) {
|
|
84
|
+
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 ")})`);
|
|
85
|
+
}
|
|
86
|
+
export function createStandardModelProvider(providerId) {
|
|
87
|
+
const reference = builtinPiProvider(providerId);
|
|
88
|
+
return defineModelProvider({
|
|
89
|
+
id: providerId,
|
|
90
|
+
parseConfig: (raw) => parseStandardProviderConfig(raw, providerId),
|
|
91
|
+
worker: reference,
|
|
92
|
+
server: reference,
|
|
93
|
+
models: (ctx) => evaluateStandardModelStatuses(providerId, ctx),
|
|
94
|
+
credential: { parse: (value) => parseApiKeyCredential(value, providerId) },
|
|
95
|
+
secrets: ({ credential }) => apiKeySecrets(credential),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export function parseCustomGatewayConfig(providerId, raw) {
|
|
99
|
+
const parsed = v.parse(customGatewaySchema, raw);
|
|
100
|
+
const ids = new Set();
|
|
101
|
+
for (const model of parsed.models) {
|
|
102
|
+
if (ids.has(model.id))
|
|
103
|
+
throw new Error(`duplicate custom model id '${model.id}'`);
|
|
104
|
+
ids.add(model.id);
|
|
105
|
+
}
|
|
106
|
+
const keyless = parsed.api_key === false;
|
|
107
|
+
const apiKey = keyless || parsed.api_key === undefined || parsed.api_key === null
|
|
108
|
+
? undefined
|
|
109
|
+
: resolveSecret(parsed.api_key, "api_key");
|
|
110
|
+
return {
|
|
111
|
+
config: {
|
|
112
|
+
providerId,
|
|
113
|
+
baseUrl: parsed.base_url,
|
|
114
|
+
api: parsed.api,
|
|
115
|
+
keyless,
|
|
116
|
+
models: parsed.models,
|
|
117
|
+
},
|
|
118
|
+
...(apiKey ? { credential: { apiKey } } : {}),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function customGatewayPiModels(config) {
|
|
122
|
+
return {
|
|
123
|
+
providers: {
|
|
124
|
+
[config.providerId]: {
|
|
125
|
+
baseUrl: config.baseUrl,
|
|
126
|
+
api: config.api,
|
|
127
|
+
models: config.models,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function customGatewayModelStatuses(config, ctx) {
|
|
133
|
+
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`);
|
|
134
|
+
}
|
|
135
|
+
export function createCustomGatewayProvider(providerId, keyless) {
|
|
136
|
+
return defineModelProvider({
|
|
137
|
+
id: providerId,
|
|
138
|
+
parseConfig: (raw) => parseCustomGatewayConfig(providerId, raw),
|
|
139
|
+
worker: configuredPiProvider(providerId, ({ config }) => customGatewayPiModels(config)),
|
|
140
|
+
models: (ctx) => customGatewayModelStatuses(ctx.config, ctx),
|
|
141
|
+
...(keyless
|
|
142
|
+
? {}
|
|
143
|
+
: { credential: { parse: (value) => parseApiKeyCredential(value, providerId) } }),
|
|
144
|
+
secrets: ({ credential }) => apiKeySecrets(credential ?? (keyless ? { apiKey: "leitwerk-keyless" } : null)),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
export function resolveModelProviders(raw) {
|
|
148
|
+
if (raw !== undefined && raw !== null && !isRecord(raw)) {
|
|
149
|
+
throw new Error("configuration must be an object");
|
|
150
|
+
}
|
|
151
|
+
const owner = (raw ?? {});
|
|
152
|
+
const standardIds = getSupportedStandardProviders();
|
|
153
|
+
assertKnownFields(owner, [...standardIds, "custom_gateways"]);
|
|
154
|
+
const entries = standardIds.map((providerId) => ({
|
|
155
|
+
definition: createStandardModelProvider(providerId),
|
|
156
|
+
rawConfig: owner[providerId],
|
|
157
|
+
}));
|
|
158
|
+
if (owner.custom_gateways === undefined)
|
|
159
|
+
return entries;
|
|
160
|
+
if (!isRecord(owner.custom_gateways))
|
|
161
|
+
throw new Error("custom_gateways must be an object");
|
|
162
|
+
for (const [providerId, gateway] of Object.entries(owner.custom_gateways)) {
|
|
163
|
+
if (!providerId.trim())
|
|
164
|
+
throw new Error("custom gateway provider id must not be empty");
|
|
165
|
+
entries.push({
|
|
166
|
+
definition: createCustomGatewayProvider(providerId, isRecord(gateway) && gateway.api_key === false),
|
|
167
|
+
rawConfig: gateway,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return entries;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=models-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAC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AK,CAAC,8CAA8C,CAAC,CAAC;QACxF,OAAO,CAAC,IAAI,CAAC;YACZ,UAAU,EAAE,2BAA2B,CACtC,UAAU,EACV,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,CAC9C;YACD,SAAS,EAAE,OAAO;SAClB,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getKnownEnvKeys(providerId: string): readonly string[];
|
|
2
|
+
export declare function getStandardEnvApiKey(providerId: string): string | undefined;
|
|
3
|
+
/** Built-in providers whose credentials fit Leitwerk's standard API-key projection. */
|
|
4
|
+
export declare function getSupportedStandardProviders(): readonly string[];
|
|
5
|
+
//# sourceMappingURL=provider-auth.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const STANDARD_PROVIDER_ENV_KEYS = {
|
|
2
|
+
"ant-ling": ["ANT_LING_API_KEY"],
|
|
3
|
+
anthropic: ["ANTHROPIC_OAUTH_TOKEN", "ANTHROPIC_API_KEY"],
|
|
4
|
+
"azure-openai-responses": ["AZURE_OPENAI_API_KEY"],
|
|
5
|
+
cerebras: ["CEREBRAS_API_KEY"],
|
|
6
|
+
"cloudflare-ai-gateway": ["CLOUDFLARE_API_KEY"],
|
|
7
|
+
"cloudflare-workers-ai": ["CLOUDFLARE_API_KEY"],
|
|
8
|
+
deepseek: ["DEEPSEEK_API_KEY"],
|
|
9
|
+
fireworks: ["FIREWORKS_API_KEY"],
|
|
10
|
+
"github-copilot": ["COPILOT_GITHUB_TOKEN"],
|
|
11
|
+
google: ["GEMINI_API_KEY"],
|
|
12
|
+
"google-vertex": ["GOOGLE_CLOUD_API_KEY"],
|
|
13
|
+
groq: ["GROQ_API_KEY"],
|
|
14
|
+
huggingface: ["HF_TOKEN"],
|
|
15
|
+
"kimi-coding": ["KIMI_API_KEY"],
|
|
16
|
+
minimax: ["MINIMAX_API_KEY"],
|
|
17
|
+
"minimax-cn": ["MINIMAX_CN_API_KEY"],
|
|
18
|
+
mistral: ["MISTRAL_API_KEY"],
|
|
19
|
+
moonshotai: ["MOONSHOT_API_KEY"],
|
|
20
|
+
"moonshotai-cn": ["MOONSHOT_API_KEY"],
|
|
21
|
+
nvidia: ["NVIDIA_API_KEY"],
|
|
22
|
+
openai: ["OPENAI_API_KEY"],
|
|
23
|
+
opencode: ["OPENCODE_API_KEY"],
|
|
24
|
+
"opencode-go": ["OPENCODE_API_KEY"],
|
|
25
|
+
openrouter: ["OPENROUTER_API_KEY"],
|
|
26
|
+
"qwen-token-plan": ["QWEN_TOKEN_PLAN_API_KEY"],
|
|
27
|
+
"qwen-token-plan-cn": ["QWEN_TOKEN_PLAN_CN_API_KEY"],
|
|
28
|
+
together: ["TOGETHER_API_KEY"],
|
|
29
|
+
"vercel-ai-gateway": ["AI_GATEWAY_API_KEY"],
|
|
30
|
+
xai: ["XAI_API_KEY"],
|
|
31
|
+
xiaomi: ["XIAOMI_API_KEY"],
|
|
32
|
+
"xiaomi-token-plan-ams": ["XIAOMI_TOKEN_PLAN_AMS_API_KEY"],
|
|
33
|
+
"xiaomi-token-plan-cn": ["XIAOMI_TOKEN_PLAN_CN_API_KEY"],
|
|
34
|
+
"xiaomi-token-plan-sgp": ["XIAOMI_TOKEN_PLAN_SGP_API_KEY"],
|
|
35
|
+
zai: ["ZAI_API_KEY"],
|
|
36
|
+
"zai-coding-cn": ["ZAI_CODING_CN_API_KEY"],
|
|
37
|
+
};
|
|
38
|
+
export function getKnownEnvKeys(providerId) {
|
|
39
|
+
return STANDARD_PROVIDER_ENV_KEYS[providerId] ?? [];
|
|
40
|
+
}
|
|
41
|
+
export function getStandardEnvApiKey(providerId) {
|
|
42
|
+
for (const key of getKnownEnvKeys(providerId)) {
|
|
43
|
+
const value = process.env[key]?.trim();
|
|
44
|
+
if (value)
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/** Built-in providers whose credentials fit Leitwerk's standard API-key projection. */
|
|
50
|
+
export function getSupportedStandardProviders() {
|
|
51
|
+
return Object.keys(STANDARD_PROVIDER_ENV_KEYS);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=provider-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-auth.js","sourceRoot":"","sources":["../src/provider-auth.ts"],"names":[],"mappings":"AAAA,MAAM,0BAA0B,GAAgD;IAC/E,UAAU,EAAE,CAAC,kBAAkB,CAAC;IAChC,SAAS,EAAE,CAAC,uBAAuB,EAAE,mBAAmB,CAAC;IACzD,wBAAwB,EAAE,CAAC,sBAAsB,CAAC;IAClD,QAAQ,EAAE,CAAC,kBAAkB,CAAC;IAC9B,uBAAuB,EAAE,CAAC,oBAAoB,CAAC;IAC/C,uBAAuB,EAAE,CAAC,oBAAoB,CAAC;IAC/C,QAAQ,EAAE,CAAC,kBAAkB,CAAC;IAC9B,SAAS,EAAE,CAAC,mBAAmB,CAAC;IAChC,gBAAgB,EAAE,CAAC,sBAAsB,CAAC;IAC1C,MAAM,EAAE,CAAC,gBAAgB,CAAC;IAC1B,eAAe,EAAE,CAAC,sBAAsB,CAAC;IACzC,IAAI,EAAE,CAAC,cAAc,CAAC;IACtB,WAAW,EAAE,CAAC,UAAU,CAAC;IACzB,aAAa,EAAE,CAAC,cAAc,CAAC;IAC/B,OAAO,EAAE,C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MAAM,UAAU,6BAA6B;IAC5C,OAAO,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;AAChD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leitwerk-dev/models",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
7
|
+
"directory": "extensions/models"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"leitwerk": {
|
|
11
|
+
"extension": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"discover": false
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"source": "./src/index.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup --silent --config tsup.config.ts"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@earendil-works/pi-ai": "^0.81.1",
|
|
29
|
+
"@leitwerk-dev/process-sdk": "0.1.0",
|
|
30
|
+
"valibot": "^1.3.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.5.1"
|
|
34
|
+
},
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=22"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist/**",
|
|
44
|
+
"src/**",
|
|
45
|
+
"!dist/**/*.test.*",
|
|
46
|
+
"!src/**/*.test.ts"
|
|
47
|
+
]
|
|
48
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineModelProviders, type LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import { resolveModelProviders } from "./models-provider.js";
|
|
3
|
+
|
|
4
|
+
export const manifest = {
|
|
5
|
+
id: "models",
|
|
6
|
+
version: "0.1.0",
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
const modelsExtension = {
|
|
10
|
+
manifest,
|
|
11
|
+
modelProviders: defineModelProviders(resolveModelProviders),
|
|
12
|
+
} satisfies LeitwerkExtensionModule;
|
|
13
|
+
|
|
14
|
+
export default modelsExtension;
|
|
15
|
+
export * from "./models-provider.js";
|
|
16
|
+
export * from "./provider-auth.js";
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
|
|
2
|
+
import {
|
|
3
|
+
builtinPiProvider,
|
|
4
|
+
configuredPiProvider,
|
|
5
|
+
defineModelProvider,
|
|
6
|
+
type ModelProviderDefinition,
|
|
7
|
+
type ModelProviderModelsContext,
|
|
8
|
+
type ModelProviderSetEntry,
|
|
9
|
+
type ProviderJsonObject,
|
|
10
|
+
type ProviderModelStatus,
|
|
11
|
+
} from "@leitwerk-dev/process-sdk";
|
|
12
|
+
import * as v from "valibot";
|
|
13
|
+
import {
|
|
14
|
+
getKnownEnvKeys,
|
|
15
|
+
getStandardEnvApiKey,
|
|
16
|
+
getSupportedStandardProviders,
|
|
17
|
+
} from "./provider-auth.js";
|
|
18
|
+
|
|
19
|
+
export type EmptyProviderConfig = Record<string, never>;
|
|
20
|
+
|
|
21
|
+
export interface ApiKeyCredential {
|
|
22
|
+
readonly apiKey: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const nonEmptyStringSchema = v.pipe(
|
|
26
|
+
v.string(),
|
|
27
|
+
v.transform((value) => value.trim()),
|
|
28
|
+
v.minLength(1),
|
|
29
|
+
);
|
|
30
|
+
const positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
|
|
31
|
+
const customModelSchema = v.pipe(
|
|
32
|
+
v.strictObject({
|
|
33
|
+
id: nonEmptyStringSchema,
|
|
34
|
+
name: v.optional(nonEmptyStringSchema),
|
|
35
|
+
reasoning: v.optional(v.boolean()),
|
|
36
|
+
context_window: v.optional(positiveIntegerSchema),
|
|
37
|
+
max_tokens: v.optional(positiveIntegerSchema),
|
|
38
|
+
}),
|
|
39
|
+
v.transform(({ context_window, max_tokens, ...model }) => ({
|
|
40
|
+
...model,
|
|
41
|
+
...(context_window === undefined ? {} : { contextWindow: context_window }),
|
|
42
|
+
...(max_tokens === undefined ? {} : { maxTokens: max_tokens }),
|
|
43
|
+
})),
|
|
44
|
+
);
|
|
45
|
+
const customGatewaySchema = v.strictObject({
|
|
46
|
+
base_url: v.pipe(
|
|
47
|
+
nonEmptyStringSchema,
|
|
48
|
+
v.url(),
|
|
49
|
+
v.check((value) => ["http:", "https:"].includes(new URL(value).protocol)),
|
|
50
|
+
v.transform((value) => new URL(value).toString().replace(/\/$/, "")),
|
|
51
|
+
),
|
|
52
|
+
api_key: v.optional(v.nullable(v.union([v.literal(false), nonEmptyStringSchema]))),
|
|
53
|
+
api: v.optional(
|
|
54
|
+
v.picklist([
|
|
55
|
+
"openai-completions",
|
|
56
|
+
"openai-responses",
|
|
57
|
+
"anthropic-messages",
|
|
58
|
+
"google-generative-ai",
|
|
59
|
+
]),
|
|
60
|
+
"openai-completions",
|
|
61
|
+
),
|
|
62
|
+
models: v.pipe(v.array(customModelSchema), v.minLength(1)),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export type CustomModelDefinition = v.InferOutput<typeof customModelSchema>;
|
|
66
|
+
|
|
67
|
+
export interface CustomGatewayConfig {
|
|
68
|
+
readonly providerId: string;
|
|
69
|
+
readonly baseUrl: string;
|
|
70
|
+
readonly api: string;
|
|
71
|
+
readonly keyless: boolean;
|
|
72
|
+
readonly models: CustomModelDefinition[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
76
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function assertKnownFields(
|
|
80
|
+
value: Record<string, unknown>,
|
|
81
|
+
allowed: readonly string[],
|
|
82
|
+
location = "configuration",
|
|
83
|
+
): void {
|
|
84
|
+
const known = new Set(allowed);
|
|
85
|
+
const unknown = Object.keys(value).find((key) => !known.has(key));
|
|
86
|
+
if (unknown) throw new Error(`${location} contains unknown field '${unknown}'`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function nonEmptyString(value: unknown, location: string): string {
|
|
90
|
+
if (typeof value !== "string") throw new Error(`${location} must be a string`);
|
|
91
|
+
const normalized = value.trim();
|
|
92
|
+
if (!normalized) throw new Error(`${location} must not be empty`);
|
|
93
|
+
return normalized;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function resolveSecret(value: unknown, location: string): string {
|
|
97
|
+
const configured = nonEmptyString(value, location);
|
|
98
|
+
if (!configured.startsWith("env:")) return configured;
|
|
99
|
+
const variable = nonEmptyString(configured.slice(4), `${location} environment variable`);
|
|
100
|
+
const resolved = process.env[variable]?.trim();
|
|
101
|
+
if (!resolved) throw new Error(`${location} references unset environment variable '${variable}'`);
|
|
102
|
+
return resolved;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function parseApiKeyCredential(value: unknown, providerId: string): ApiKeyCredential {
|
|
106
|
+
if (!isRecord(value)) throw new Error(`${providerId} credential must be an object`);
|
|
107
|
+
assertKnownFields(value, ["apiKey"], `${providerId} credential`);
|
|
108
|
+
return { apiKey: nonEmptyString(value.apiKey, `${providerId} credential apiKey`) };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function apiKeySecrets(credential: ApiKeyCredential | null): Readonly<Record<string, string>> {
|
|
112
|
+
return credential ? { apiKey: credential.apiKey } : {};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function parseStandardProviderConfig(
|
|
116
|
+
raw: unknown,
|
|
117
|
+
providerId: string,
|
|
118
|
+
): { config: EmptyProviderConfig; credential?: ApiKeyCredential } {
|
|
119
|
+
if (raw !== undefined && raw !== null && !isRecord(raw)) {
|
|
120
|
+
throw new Error("configuration must be an object");
|
|
121
|
+
}
|
|
122
|
+
const config = (raw ?? {}) as Record<string, unknown>;
|
|
123
|
+
assertKnownFields(config, ["api_key"]);
|
|
124
|
+
const apiKey =
|
|
125
|
+
config.api_key === undefined || config.api_key === null
|
|
126
|
+
? getStandardEnvApiKey(providerId)
|
|
127
|
+
: resolveSecret(config.api_key, "api_key");
|
|
128
|
+
return { config: {}, ...(apiKey ? { credential: { apiKey } } : {}) };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function catalogModelStatuses(
|
|
132
|
+
ctx: ModelProviderModelsContext,
|
|
133
|
+
knownModelIds: ReadonlySet<string>,
|
|
134
|
+
credentialsAvailable: boolean,
|
|
135
|
+
missingReason: (modelId: string) => string,
|
|
136
|
+
credentialReason: string,
|
|
137
|
+
): readonly ProviderModelStatus[] {
|
|
138
|
+
return [...new Set(ctx.configuredModels.map(({ modelId }) => modelId))].map((modelId) =>
|
|
139
|
+
!knownModelIds.has(modelId)
|
|
140
|
+
? { modelId, availability: "unavailable", safeReason: missingReason(modelId) }
|
|
141
|
+
: credentialsAvailable
|
|
142
|
+
? { modelId, availability: "available" }
|
|
143
|
+
: { modelId, availability: "unavailable", safeReason: credentialReason },
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function evaluateStandardModelStatuses(
|
|
148
|
+
providerId: string,
|
|
149
|
+
ctx: ModelProviderModelsContext,
|
|
150
|
+
): readonly ProviderModelStatus[] {
|
|
151
|
+
return catalogModelStatuses(
|
|
152
|
+
ctx,
|
|
153
|
+
new Set(getBuiltinModels(providerId as never).map(({ id }) => id)),
|
|
154
|
+
ctx.credentialStatus.available,
|
|
155
|
+
(modelId) => `Canonical Pi model '${providerId}/${modelId}' is not found in catalog`,
|
|
156
|
+
`${providerId} credentials are unavailable (set ${getKnownEnvKeys(providerId).join(" or ")})`,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function createStandardModelProvider(
|
|
161
|
+
providerId: string,
|
|
162
|
+
): ModelProviderDefinition<EmptyProviderConfig, ApiKeyCredential> {
|
|
163
|
+
const reference = builtinPiProvider(providerId);
|
|
164
|
+
return defineModelProvider({
|
|
165
|
+
id: providerId,
|
|
166
|
+
parseConfig: (raw) => parseStandardProviderConfig(raw, providerId),
|
|
167
|
+
worker: reference,
|
|
168
|
+
server: reference,
|
|
169
|
+
models: (ctx) => evaluateStandardModelStatuses(providerId, ctx),
|
|
170
|
+
credential: { parse: (value) => parseApiKeyCredential(value, providerId) },
|
|
171
|
+
secrets: ({ credential }) => apiKeySecrets(credential),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function parseCustomGatewayConfig(
|
|
176
|
+
providerId: string,
|
|
177
|
+
raw: unknown,
|
|
178
|
+
): { config: CustomGatewayConfig; credential?: ApiKeyCredential } {
|
|
179
|
+
const parsed = v.parse(customGatewaySchema, raw);
|
|
180
|
+
const ids = new Set<string>();
|
|
181
|
+
for (const model of parsed.models) {
|
|
182
|
+
if (ids.has(model.id)) throw new Error(`duplicate custom model id '${model.id}'`);
|
|
183
|
+
ids.add(model.id);
|
|
184
|
+
}
|
|
185
|
+
const keyless = parsed.api_key === false;
|
|
186
|
+
const apiKey =
|
|
187
|
+
keyless || parsed.api_key === undefined || parsed.api_key === null
|
|
188
|
+
? undefined
|
|
189
|
+
: resolveSecret(parsed.api_key, "api_key");
|
|
190
|
+
return {
|
|
191
|
+
config: {
|
|
192
|
+
providerId,
|
|
193
|
+
baseUrl: parsed.base_url,
|
|
194
|
+
api: parsed.api,
|
|
195
|
+
keyless,
|
|
196
|
+
models: parsed.models,
|
|
197
|
+
},
|
|
198
|
+
...(apiKey ? { credential: { apiKey } } : {}),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function customGatewayPiModels(config: CustomGatewayConfig): ProviderJsonObject {
|
|
203
|
+
return {
|
|
204
|
+
providers: {
|
|
205
|
+
[config.providerId]: {
|
|
206
|
+
baseUrl: config.baseUrl,
|
|
207
|
+
api: config.api,
|
|
208
|
+
models: config.models,
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function customGatewayModelStatuses(
|
|
215
|
+
config: CustomGatewayConfig,
|
|
216
|
+
ctx: ModelProviderModelsContext<CustomGatewayConfig>,
|
|
217
|
+
): readonly ProviderModelStatus[] {
|
|
218
|
+
return catalogModelStatuses(
|
|
219
|
+
ctx,
|
|
220
|
+
new Set(config.models.map(({ id }) => id)),
|
|
221
|
+
config.keyless || ctx.credentialStatus.available,
|
|
222
|
+
(modelId) =>
|
|
223
|
+
`Canonical model '${config.providerId}/${modelId}' is not found in custom gateway definition`,
|
|
224
|
+
`Gateway provider '${config.providerId}' credentials are unavailable`,
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function createCustomGatewayProvider(
|
|
229
|
+
providerId: string,
|
|
230
|
+
keyless: boolean,
|
|
231
|
+
): ModelProviderDefinition<CustomGatewayConfig, ApiKeyCredential> {
|
|
232
|
+
return defineModelProvider({
|
|
233
|
+
id: providerId,
|
|
234
|
+
parseConfig: (raw) => parseCustomGatewayConfig(providerId, raw),
|
|
235
|
+
worker: configuredPiProvider(providerId, ({ config }) => customGatewayPiModels(config)),
|
|
236
|
+
models: (ctx) => customGatewayModelStatuses(ctx.config, ctx),
|
|
237
|
+
...(keyless
|
|
238
|
+
? {}
|
|
239
|
+
: { credential: { parse: (value: unknown) => parseApiKeyCredential(value, providerId) } }),
|
|
240
|
+
secrets: ({ credential }) =>
|
|
241
|
+
apiKeySecrets(credential ?? (keyless ? { apiKey: "leitwerk-keyless" } : null)),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function resolveModelProviders(raw: unknown): readonly ModelProviderSetEntry[] {
|
|
246
|
+
if (raw !== undefined && raw !== null && !isRecord(raw)) {
|
|
247
|
+
throw new Error("configuration must be an object");
|
|
248
|
+
}
|
|
249
|
+
const owner = (raw ?? {}) as Record<string, unknown>;
|
|
250
|
+
const standardIds = getSupportedStandardProviders();
|
|
251
|
+
assertKnownFields(owner, [...standardIds, "custom_gateways"]);
|
|
252
|
+
const entries: ModelProviderSetEntry[] = standardIds.map((providerId) => ({
|
|
253
|
+
definition: createStandardModelProvider(providerId),
|
|
254
|
+
rawConfig: owner[providerId],
|
|
255
|
+
}));
|
|
256
|
+
if (owner.custom_gateways === undefined) return entries;
|
|
257
|
+
if (!isRecord(owner.custom_gateways)) throw new Error("custom_gateways must be an object");
|
|
258
|
+
for (const [providerId, gateway] of Object.entries(owner.custom_gateways)) {
|
|
259
|
+
if (!providerId.trim()) throw new Error("custom gateway provider id must not be empty");
|
|
260
|
+
entries.push({
|
|
261
|
+
definition: createCustomGatewayProvider(
|
|
262
|
+
providerId,
|
|
263
|
+
isRecord(gateway) && gateway.api_key === false,
|
|
264
|
+
),
|
|
265
|
+
rawConfig: gateway,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return entries;
|
|
269
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const STANDARD_PROVIDER_ENV_KEYS: Readonly<Record<string, readonly string[]>> = {
|
|
2
|
+
"ant-ling": ["ANT_LING_API_KEY"],
|
|
3
|
+
anthropic: ["ANTHROPIC_OAUTH_TOKEN", "ANTHROPIC_API_KEY"],
|
|
4
|
+
"azure-openai-responses": ["AZURE_OPENAI_API_KEY"],
|
|
5
|
+
cerebras: ["CEREBRAS_API_KEY"],
|
|
6
|
+
"cloudflare-ai-gateway": ["CLOUDFLARE_API_KEY"],
|
|
7
|
+
"cloudflare-workers-ai": ["CLOUDFLARE_API_KEY"],
|
|
8
|
+
deepseek: ["DEEPSEEK_API_KEY"],
|
|
9
|
+
fireworks: ["FIREWORKS_API_KEY"],
|
|
10
|
+
"github-copilot": ["COPILOT_GITHUB_TOKEN"],
|
|
11
|
+
google: ["GEMINI_API_KEY"],
|
|
12
|
+
"google-vertex": ["GOOGLE_CLOUD_API_KEY"],
|
|
13
|
+
groq: ["GROQ_API_KEY"],
|
|
14
|
+
huggingface: ["HF_TOKEN"],
|
|
15
|
+
"kimi-coding": ["KIMI_API_KEY"],
|
|
16
|
+
minimax: ["MINIMAX_API_KEY"],
|
|
17
|
+
"minimax-cn": ["MINIMAX_CN_API_KEY"],
|
|
18
|
+
mistral: ["MISTRAL_API_KEY"],
|
|
19
|
+
moonshotai: ["MOONSHOT_API_KEY"],
|
|
20
|
+
"moonshotai-cn": ["MOONSHOT_API_KEY"],
|
|
21
|
+
nvidia: ["NVIDIA_API_KEY"],
|
|
22
|
+
openai: ["OPENAI_API_KEY"],
|
|
23
|
+
opencode: ["OPENCODE_API_KEY"],
|
|
24
|
+
"opencode-go": ["OPENCODE_API_KEY"],
|
|
25
|
+
openrouter: ["OPENROUTER_API_KEY"],
|
|
26
|
+
"qwen-token-plan": ["QWEN_TOKEN_PLAN_API_KEY"],
|
|
27
|
+
"qwen-token-plan-cn": ["QWEN_TOKEN_PLAN_CN_API_KEY"],
|
|
28
|
+
together: ["TOGETHER_API_KEY"],
|
|
29
|
+
"vercel-ai-gateway": ["AI_GATEWAY_API_KEY"],
|
|
30
|
+
xai: ["XAI_API_KEY"],
|
|
31
|
+
xiaomi: ["XIAOMI_API_KEY"],
|
|
32
|
+
"xiaomi-token-plan-ams": ["XIAOMI_TOKEN_PLAN_AMS_API_KEY"],
|
|
33
|
+
"xiaomi-token-plan-cn": ["XIAOMI_TOKEN_PLAN_CN_API_KEY"],
|
|
34
|
+
"xiaomi-token-plan-sgp": ["XIAOMI_TOKEN_PLAN_SGP_API_KEY"],
|
|
35
|
+
zai: ["ZAI_API_KEY"],
|
|
36
|
+
"zai-coding-cn": ["ZAI_CODING_CN_API_KEY"],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function getKnownEnvKeys(providerId: string): readonly string[] {
|
|
40
|
+
return STANDARD_PROVIDER_ENV_KEYS[providerId] ?? [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getStandardEnvApiKey(providerId: string): string | undefined {
|
|
44
|
+
for (const key of getKnownEnvKeys(providerId)) {
|
|
45
|
+
const value = process.env[key]?.trim();
|
|
46
|
+
if (value) return value;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Built-in providers whose credentials fit Leitwerk's standard API-key projection. */
|
|
52
|
+
export function getSupportedStandardProviders(): readonly string[] {
|
|
53
|
+
return Object.keys(STANDARD_PROVIDER_ENV_KEYS);
|
|
54
|
+
}
|