@leitwerk-dev/models 0.1.2 → 0.1.3
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/dist/index.d.ts +6 -58
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -268
- package/dist/index.js.map +1 -1
- 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 +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,58 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { ModelProviderDefinition, ModelProviderModelsContext, ProviderModelStatus, ModelProviderSetEntry } from '@leitwerk-dev/process-sdk';
|
|
3
|
-
import * as v from 'valibot';
|
|
4
|
-
|
|
5
|
-
type EmptyProviderConfig = Record<string, never>;
|
|
6
|
-
interface ApiKeyCredential {
|
|
7
|
-
readonly apiKey: string;
|
|
8
|
-
}
|
|
9
|
-
declare const customModelSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
10
|
-
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>;
|
|
11
|
-
readonly name: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
12
|
-
readonly reasoning: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
13
|
-
readonly context_window: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>, undefined>;
|
|
14
|
-
readonly max_tokens: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>, undefined>;
|
|
15
|
-
}, undefined>, v.TransformAction<{
|
|
16
|
-
id: string;
|
|
17
|
-
name?: string | undefined;
|
|
18
|
-
reasoning?: boolean | undefined;
|
|
19
|
-
context_window?: number | undefined;
|
|
20
|
-
max_tokens?: number | undefined;
|
|
21
|
-
}, {
|
|
22
|
-
maxTokens?: number | undefined;
|
|
23
|
-
contextWindow?: number | undefined;
|
|
24
|
-
id: string;
|
|
25
|
-
name?: string | undefined;
|
|
26
|
-
reasoning?: boolean | undefined;
|
|
27
|
-
}>]>;
|
|
28
|
-
type CustomModelDefinition = v.InferOutput<typeof customModelSchema>;
|
|
29
|
-
interface CustomGatewayConfig {
|
|
30
|
-
readonly providerId: string;
|
|
31
|
-
readonly baseUrl: string;
|
|
32
|
-
readonly api: string;
|
|
33
|
-
readonly keyless: boolean;
|
|
34
|
-
readonly models: CustomModelDefinition[];
|
|
35
|
-
}
|
|
36
|
-
declare function parseApiKeyCredential(value: unknown, providerId: string): ApiKeyCredential;
|
|
37
|
-
declare function parseStandardProviderConfig(raw: unknown, providerId: string): {
|
|
38
|
-
config: EmptyProviderConfig;
|
|
39
|
-
credential?: ApiKeyCredential;
|
|
40
|
-
};
|
|
41
|
-
declare function evaluateStandardModelStatuses(providerId: string, ctx: ModelProviderModelsContext): readonly ProviderModelStatus[];
|
|
42
|
-
declare function createStandardModelProvider(providerId: string): ModelProviderDefinition<EmptyProviderConfig, ApiKeyCredential>;
|
|
43
|
-
declare function parseCustomGatewayConfig(providerId: string, raw: unknown): {
|
|
44
|
-
config: CustomGatewayConfig;
|
|
45
|
-
credential?: ApiKeyCredential;
|
|
46
|
-
};
|
|
47
|
-
declare function createCustomGatewayProvider(providerId: string, keyless: boolean): ModelProviderDefinition<CustomGatewayConfig, ApiKeyCredential>;
|
|
48
|
-
declare function resolveModelProviders(raw: unknown): readonly ModelProviderSetEntry[];
|
|
49
|
-
|
|
50
|
-
declare function getKnownEnvKeys(providerId: string): readonly string[];
|
|
51
|
-
declare function getStandardEnvApiKey(providerId: string): string | undefined;
|
|
52
|
-
/** Built-in providers whose credentials fit Leitwerk's standard API-key projection. */
|
|
53
|
-
declare function getSupportedStandardProviders(): readonly string[];
|
|
54
|
-
|
|
55
|
-
declare const manifest: {
|
|
1
|
+
export declare const manifest: {
|
|
56
2
|
readonly id: "models";
|
|
57
3
|
readonly version: "0.1.0";
|
|
58
4
|
};
|
|
@@ -61,7 +7,9 @@ declare const modelsExtension: {
|
|
|
61
7
|
readonly id: "models";
|
|
62
8
|
readonly version: "0.1.0";
|
|
63
9
|
};
|
|
64
|
-
modelProviders:
|
|
10
|
+
modelProviders: import("@leitwerk-dev/process-sdk").ModelProviderSet;
|
|
65
11
|
};
|
|
66
|
-
|
|
67
|
-
export
|
|
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
CHANGED
|
@@ -1,270 +1,14 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
1
|
import { defineModelProviders } from "@leitwerk-dev/process-sdk";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"ant-ling": ["ANT_LING_API_KEY"],
|
|
16
|
-
anthropic: ["ANTHROPIC_OAUTH_TOKEN", "ANTHROPIC_API_KEY"],
|
|
17
|
-
"azure-openai-responses": ["AZURE_OPENAI_API_KEY"],
|
|
18
|
-
cerebras: ["CEREBRAS_API_KEY"],
|
|
19
|
-
"cloudflare-ai-gateway": ["CLOUDFLARE_API_KEY"],
|
|
20
|
-
"cloudflare-workers-ai": ["CLOUDFLARE_API_KEY"],
|
|
21
|
-
deepseek: ["DEEPSEEK_API_KEY"],
|
|
22
|
-
fireworks: ["FIREWORKS_API_KEY"],
|
|
23
|
-
"github-copilot": ["COPILOT_GITHUB_TOKEN"],
|
|
24
|
-
google: ["GEMINI_API_KEY"],
|
|
25
|
-
"google-vertex": ["GOOGLE_CLOUD_API_KEY"],
|
|
26
|
-
groq: ["GROQ_API_KEY"],
|
|
27
|
-
huggingface: ["HF_TOKEN"],
|
|
28
|
-
"kimi-coding": ["KIMI_API_KEY"],
|
|
29
|
-
minimax: ["MINIMAX_API_KEY"],
|
|
30
|
-
"minimax-cn": ["MINIMAX_CN_API_KEY"],
|
|
31
|
-
mistral: ["MISTRAL_API_KEY"],
|
|
32
|
-
moonshotai: ["MOONSHOT_API_KEY"],
|
|
33
|
-
"moonshotai-cn": ["MOONSHOT_API_KEY"],
|
|
34
|
-
nvidia: ["NVIDIA_API_KEY"],
|
|
35
|
-
openai: ["OPENAI_API_KEY"],
|
|
36
|
-
opencode: ["OPENCODE_API_KEY"],
|
|
37
|
-
"opencode-go": ["OPENCODE_API_KEY"],
|
|
38
|
-
openrouter: ["OPENROUTER_API_KEY"],
|
|
39
|
-
"qwen-token-plan": ["QWEN_TOKEN_PLAN_API_KEY"],
|
|
40
|
-
"qwen-token-plan-cn": ["QWEN_TOKEN_PLAN_CN_API_KEY"],
|
|
41
|
-
together: ["TOGETHER_API_KEY"],
|
|
42
|
-
"vercel-ai-gateway": ["AI_GATEWAY_API_KEY"],
|
|
43
|
-
xai: ["XAI_API_KEY"],
|
|
44
|
-
xiaomi: ["XIAOMI_API_KEY"],
|
|
45
|
-
"xiaomi-token-plan-ams": ["XIAOMI_TOKEN_PLAN_AMS_API_KEY"],
|
|
46
|
-
"xiaomi-token-plan-cn": ["XIAOMI_TOKEN_PLAN_CN_API_KEY"],
|
|
47
|
-
"xiaomi-token-plan-sgp": ["XIAOMI_TOKEN_PLAN_SGP_API_KEY"],
|
|
48
|
-
zai: ["ZAI_API_KEY"],
|
|
49
|
-
"zai-coding-cn": ["ZAI_CODING_CN_API_KEY"]
|
|
50
|
-
};
|
|
51
|
-
function getKnownEnvKeys(providerId) {
|
|
52
|
-
return STANDARD_PROVIDER_ENV_KEYS[providerId] ?? [];
|
|
53
|
-
}
|
|
54
|
-
function getStandardEnvApiKey(providerId) {
|
|
55
|
-
for (const key of getKnownEnvKeys(providerId)) {
|
|
56
|
-
const value = process.env[key]?.trim();
|
|
57
|
-
if (value) return value;
|
|
58
|
-
}
|
|
59
|
-
return void 0;
|
|
60
|
-
}
|
|
61
|
-
function getSupportedStandardProviders() {
|
|
62
|
-
return Object.keys(STANDARD_PROVIDER_ENV_KEYS);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/models-provider.ts
|
|
66
|
-
var nonEmptyStringSchema = v.pipe(
|
|
67
|
-
v.string(),
|
|
68
|
-
v.transform((value) => value.trim()),
|
|
69
|
-
v.minLength(1)
|
|
70
|
-
);
|
|
71
|
-
var positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1));
|
|
72
|
-
var customModelSchema = v.pipe(
|
|
73
|
-
v.strictObject({
|
|
74
|
-
id: nonEmptyStringSchema,
|
|
75
|
-
name: v.optional(nonEmptyStringSchema),
|
|
76
|
-
reasoning: v.optional(v.boolean()),
|
|
77
|
-
context_window: v.optional(positiveIntegerSchema),
|
|
78
|
-
max_tokens: v.optional(positiveIntegerSchema)
|
|
79
|
-
}),
|
|
80
|
-
v.transform(({ context_window, max_tokens, ...model }) => ({
|
|
81
|
-
...model,
|
|
82
|
-
...context_window === void 0 ? {} : { contextWindow: context_window },
|
|
83
|
-
...max_tokens === void 0 ? {} : { maxTokens: max_tokens }
|
|
84
|
-
}))
|
|
85
|
-
);
|
|
86
|
-
var customGatewaySchema = v.strictObject({
|
|
87
|
-
base_url: v.pipe(
|
|
88
|
-
nonEmptyStringSchema,
|
|
89
|
-
v.url(),
|
|
90
|
-
v.check((value) => ["http:", "https:"].includes(new URL(value).protocol)),
|
|
91
|
-
v.transform((value) => new URL(value).toString().replace(/\/$/, ""))
|
|
92
|
-
),
|
|
93
|
-
api_key: v.optional(v.nullable(v.union([v.literal(false), nonEmptyStringSchema]))),
|
|
94
|
-
api: v.optional(
|
|
95
|
-
v.picklist([
|
|
96
|
-
"openai-completions",
|
|
97
|
-
"openai-responses",
|
|
98
|
-
"anthropic-messages",
|
|
99
|
-
"google-generative-ai"
|
|
100
|
-
]),
|
|
101
|
-
"openai-completions"
|
|
102
|
-
),
|
|
103
|
-
models: v.pipe(v.array(customModelSchema), v.minLength(1))
|
|
104
|
-
});
|
|
105
|
-
function isRecord(value) {
|
|
106
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
107
|
-
}
|
|
108
|
-
function assertKnownFields(value, allowed, location = "configuration") {
|
|
109
|
-
const known = new Set(allowed);
|
|
110
|
-
const unknown = Object.keys(value).find((key) => !known.has(key));
|
|
111
|
-
if (unknown) throw new Error(`${location} contains unknown field '${unknown}'`);
|
|
112
|
-
}
|
|
113
|
-
function nonEmptyString(value, location) {
|
|
114
|
-
if (typeof value !== "string") throw new Error(`${location} must be a string`);
|
|
115
|
-
const normalized = value.trim();
|
|
116
|
-
if (!normalized) throw new Error(`${location} must not be empty`);
|
|
117
|
-
return normalized;
|
|
118
|
-
}
|
|
119
|
-
function resolveSecret(value, location) {
|
|
120
|
-
const configured = nonEmptyString(value, location);
|
|
121
|
-
if (!configured.startsWith("env:")) return configured;
|
|
122
|
-
const variable = nonEmptyString(configured.slice(4), `${location} environment variable`);
|
|
123
|
-
const resolved = process.env[variable]?.trim();
|
|
124
|
-
if (!resolved) throw new Error(`${location} references unset environment variable '${variable}'`);
|
|
125
|
-
return resolved;
|
|
126
|
-
}
|
|
127
|
-
function parseApiKeyCredential(value, providerId) {
|
|
128
|
-
if (!isRecord(value)) throw new Error(`${providerId} credential must be an object`);
|
|
129
|
-
assertKnownFields(value, ["apiKey"], `${providerId} credential`);
|
|
130
|
-
return { apiKey: nonEmptyString(value.apiKey, `${providerId} credential apiKey`) };
|
|
131
|
-
}
|
|
132
|
-
function apiKeySecrets(credential) {
|
|
133
|
-
return credential ? { apiKey: credential.apiKey } : {};
|
|
134
|
-
}
|
|
135
|
-
function parseStandardProviderConfig(raw, providerId) {
|
|
136
|
-
if (raw !== void 0 && raw !== null && !isRecord(raw)) {
|
|
137
|
-
throw new Error("configuration must be an object");
|
|
138
|
-
}
|
|
139
|
-
const config = raw ?? {};
|
|
140
|
-
assertKnownFields(config, ["api_key"]);
|
|
141
|
-
const apiKey = config.api_key === void 0 || config.api_key === null ? getStandardEnvApiKey(providerId) : resolveSecret(config.api_key, "api_key");
|
|
142
|
-
return { config: {}, ...apiKey ? { credential: { apiKey } } : {} };
|
|
143
|
-
}
|
|
144
|
-
function catalogModelStatuses(ctx, knownModelIds, credentialsAvailable, missingReason, credentialReason) {
|
|
145
|
-
return [...new Set(ctx.configuredModels.map(({ modelId }) => modelId))].map(
|
|
146
|
-
(modelId) => !knownModelIds.has(modelId) ? { modelId, availability: "unavailable", safeReason: missingReason(modelId) } : credentialsAvailable ? { modelId, availability: "available" } : { modelId, availability: "unavailable", safeReason: credentialReason }
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
function evaluateStandardModelStatuses(providerId, ctx) {
|
|
150
|
-
return catalogModelStatuses(
|
|
151
|
-
ctx,
|
|
152
|
-
new Set(getBuiltinModels(providerId).map(({ id }) => id)),
|
|
153
|
-
ctx.credentialStatus.available,
|
|
154
|
-
(modelId) => `Canonical Pi model '${providerId}/${modelId}' is not found in catalog`,
|
|
155
|
-
`${providerId} credentials are unavailable (set ${getKnownEnvKeys(providerId).join(" or ")})`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
function createStandardModelProvider(providerId) {
|
|
159
|
-
const reference = builtinPiProvider(providerId);
|
|
160
|
-
return defineModelProvider({
|
|
161
|
-
id: providerId,
|
|
162
|
-
parseConfig: (raw) => parseStandardProviderConfig(raw, providerId),
|
|
163
|
-
worker: reference,
|
|
164
|
-
server: reference,
|
|
165
|
-
models: (ctx) => evaluateStandardModelStatuses(providerId, ctx),
|
|
166
|
-
credential: { parse: (value) => parseApiKeyCredential(value, providerId) },
|
|
167
|
-
secrets: ({ credential }) => apiKeySecrets(credential)
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
function parseCustomGatewayConfig(providerId, raw) {
|
|
171
|
-
const parsed = v.parse(customGatewaySchema, raw);
|
|
172
|
-
const ids = /* @__PURE__ */ new Set();
|
|
173
|
-
for (const model of parsed.models) {
|
|
174
|
-
if (ids.has(model.id)) throw new Error(`duplicate custom model id '${model.id}'`);
|
|
175
|
-
ids.add(model.id);
|
|
176
|
-
}
|
|
177
|
-
const keyless = parsed.api_key === false;
|
|
178
|
-
const apiKey = keyless || parsed.api_key === void 0 || parsed.api_key === null ? void 0 : resolveSecret(parsed.api_key, "api_key");
|
|
179
|
-
return {
|
|
180
|
-
config: {
|
|
181
|
-
providerId,
|
|
182
|
-
baseUrl: parsed.base_url,
|
|
183
|
-
api: parsed.api,
|
|
184
|
-
keyless,
|
|
185
|
-
models: parsed.models
|
|
186
|
-
},
|
|
187
|
-
...apiKey ? { credential: { apiKey } } : {}
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
function customGatewayPiModels(config) {
|
|
191
|
-
return {
|
|
192
|
-
providers: {
|
|
193
|
-
[config.providerId]: {
|
|
194
|
-
baseUrl: config.baseUrl,
|
|
195
|
-
api: config.api,
|
|
196
|
-
models: config.models
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
function customGatewayModelStatuses(config, ctx) {
|
|
202
|
-
return catalogModelStatuses(
|
|
203
|
-
ctx,
|
|
204
|
-
new Set(config.models.map(({ id }) => id)),
|
|
205
|
-
config.keyless || ctx.credentialStatus.available,
|
|
206
|
-
(modelId) => `Canonical model '${config.providerId}/${modelId}' is not found in custom gateway definition`,
|
|
207
|
-
`Gateway provider '${config.providerId}' credentials are unavailable`
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
function createCustomGatewayProvider(providerId, keyless) {
|
|
211
|
-
return defineModelProvider({
|
|
212
|
-
id: providerId,
|
|
213
|
-
parseConfig: (raw) => parseCustomGatewayConfig(providerId, raw),
|
|
214
|
-
worker: configuredPiProvider(providerId, ({ config }) => customGatewayPiModels(config)),
|
|
215
|
-
models: (ctx) => customGatewayModelStatuses(ctx.config, ctx),
|
|
216
|
-
...keyless ? {} : { credential: { parse: (value) => parseApiKeyCredential(value, providerId) } },
|
|
217
|
-
secrets: ({ credential }) => apiKeySecrets(credential ?? (keyless ? { apiKey: "leitwerk-keyless" } : null))
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
function resolveModelProviders(raw) {
|
|
221
|
-
if (raw !== void 0 && raw !== null && !isRecord(raw)) {
|
|
222
|
-
throw new Error("configuration must be an object");
|
|
223
|
-
}
|
|
224
|
-
const owner = raw ?? {};
|
|
225
|
-
const standardIds = getSupportedStandardProviders();
|
|
226
|
-
assertKnownFields(owner, [...standardIds, "custom_gateways"]);
|
|
227
|
-
const entries = standardIds.map((providerId) => ({
|
|
228
|
-
definition: createStandardModelProvider(providerId),
|
|
229
|
-
rawConfig: owner[providerId]
|
|
230
|
-
}));
|
|
231
|
-
if (owner.custom_gateways === void 0) return entries;
|
|
232
|
-
if (!isRecord(owner.custom_gateways)) throw new Error("custom_gateways must be an object");
|
|
233
|
-
for (const [providerId, gateway] of Object.entries(owner.custom_gateways)) {
|
|
234
|
-
if (!providerId.trim()) throw new Error("custom gateway provider id must not be empty");
|
|
235
|
-
entries.push({
|
|
236
|
-
definition: createCustomGatewayProvider(
|
|
237
|
-
providerId,
|
|
238
|
-
isRecord(gateway) && gateway.api_key === false
|
|
239
|
-
),
|
|
240
|
-
rawConfig: gateway
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
return entries;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// src/index.ts
|
|
247
|
-
var manifest = {
|
|
248
|
-
id: "models",
|
|
249
|
-
version: "0.1.0"
|
|
250
|
-
};
|
|
251
|
-
var modelsExtension = {
|
|
252
|
-
manifest,
|
|
253
|
-
modelProviders: defineModelProviders(resolveModelProviders)
|
|
254
|
-
};
|
|
255
|
-
var index_default = modelsExtension;
|
|
256
|
-
export {
|
|
257
|
-
createCustomGatewayProvider,
|
|
258
|
-
createStandardModelProvider,
|
|
259
|
-
index_default as default,
|
|
260
|
-
evaluateStandardModelStatuses,
|
|
261
|
-
getKnownEnvKeys,
|
|
262
|
-
getStandardEnvApiKey,
|
|
263
|
-
getSupportedStandardProviders,
|
|
264
|
-
manifest,
|
|
265
|
-
parseApiKeyCredential,
|
|
266
|
-
parseCustomGatewayConfig,
|
|
267
|
-
parseStandardProviderConfig,
|
|
268
|
-
resolveModelProviders
|
|
269
|
-
};
|
|
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";
|
|
270
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/models-provider.ts","../src/provider-auth.ts"],"sourcesContent":["import { defineModelProviders, type LeitwerkExtensionModule } from \"@leitwerk-dev/process-sdk\";\nimport { resolveModelProviders } from \"./models-provider.js\";\n\nexport const manifest = {\n\tid: \"models\",\n\tversion: \"0.1.0\",\n} as const;\n\nconst modelsExtension = {\n\tmanifest,\n\tmodelProviders: defineModelProviders(resolveModelProviders),\n} satisfies LeitwerkExtensionModule;\n\nexport default modelsExtension;\nexport * from \"./models-provider.js\";\nexport * from \"./provider-auth.js\";\n","import { getBuiltinModels } from \"@earendil-works/pi-ai/providers/all\";\nimport {\n\tbuiltinPiProvider,\n\tconfiguredPiProvider,\n\tdefineModelProvider,\n\ttype ModelProviderDefinition,\n\ttype ModelProviderModelsContext,\n\ttype ModelProviderSetEntry,\n\ttype ProviderJsonObject,\n\ttype ProviderModelStatus,\n} from \"@leitwerk-dev/process-sdk\";\nimport * as v from \"valibot\";\nimport {\n\tgetKnownEnvKeys,\n\tgetStandardEnvApiKey,\n\tgetSupportedStandardProviders,\n} from \"./provider-auth.js\";\n\nexport type EmptyProviderConfig = Record<string, never>;\n\nexport interface ApiKeyCredential {\n\treadonly apiKey: string;\n}\n\nconst nonEmptyStringSchema = v.pipe(\n\tv.string(),\n\tv.transform((value) => value.trim()),\n\tv.minLength(1),\n);\nconst positiveIntegerSchema = v.pipe(v.number(), v.integer(), v.minValue(1));\nconst customModelSchema = v.pipe(\n\tv.strictObject({\n\t\tid: nonEmptyStringSchema,\n\t\tname: v.optional(nonEmptyStringSchema),\n\t\treasoning: v.optional(v.boolean()),\n\t\tcontext_window: v.optional(positiveIntegerSchema),\n\t\tmax_tokens: v.optional(positiveIntegerSchema),\n\t}),\n\tv.transform(({ context_window, max_tokens, ...model }) => ({\n\t\t...model,\n\t\t...(context_window === undefined ? {} : { contextWindow: context_window }),\n\t\t...(max_tokens === undefined ? {} : { maxTokens: max_tokens }),\n\t})),\n);\nconst customGatewaySchema = v.strictObject({\n\tbase_url: v.pipe(\n\t\tnonEmptyStringSchema,\n\t\tv.url(),\n\t\tv.check((value) => [\"http:\", \"https:\"].includes(new URL(value).protocol)),\n\t\tv.transform((value) => new URL(value).toString().replace(/\\/$/, \"\")),\n\t),\n\tapi_key: v.optional(v.nullable(v.union([v.literal(false), nonEmptyStringSchema]))),\n\tapi: v.optional(\n\t\tv.picklist([\n\t\t\t\"openai-completions\",\n\t\t\t\"openai-responses\",\n\t\t\t\"anthropic-messages\",\n\t\t\t\"google-generative-ai\",\n\t\t]),\n\t\t\"openai-completions\",\n\t),\n\tmodels: v.pipe(v.array(customModelSchema), v.minLength(1)),\n});\n\nexport type CustomModelDefinition = v.InferOutput<typeof customModelSchema>;\n\nexport interface CustomGatewayConfig {\n\treadonly providerId: string;\n\treadonly baseUrl: string;\n\treadonly api: string;\n\treadonly keyless: boolean;\n\treadonly models: CustomModelDefinition[];\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction assertKnownFields(\n\tvalue: Record<string, unknown>,\n\tallowed: readonly string[],\n\tlocation = \"configuration\",\n): void {\n\tconst known = new Set(allowed);\n\tconst unknown = Object.keys(value).find((key) => !known.has(key));\n\tif (unknown) throw new Error(`${location} contains unknown field '${unknown}'`);\n}\n\nfunction nonEmptyString(value: unknown, location: string): string {\n\tif (typeof value !== \"string\") throw new Error(`${location} must be a string`);\n\tconst normalized = value.trim();\n\tif (!normalized) throw new Error(`${location} must not be empty`);\n\treturn normalized;\n}\n\nfunction resolveSecret(value: unknown, location: string): string {\n\tconst configured = nonEmptyString(value, location);\n\tif (!configured.startsWith(\"env:\")) return configured;\n\tconst variable = nonEmptyString(configured.slice(4), `${location} environment variable`);\n\tconst resolved = process.env[variable]?.trim();\n\tif (!resolved) throw new Error(`${location} references unset environment variable '${variable}'`);\n\treturn resolved;\n}\n\nexport function parseApiKeyCredential(value: unknown, providerId: string): ApiKeyCredential {\n\tif (!isRecord(value)) throw new Error(`${providerId} credential must be an object`);\n\tassertKnownFields(value, [\"apiKey\"], `${providerId} credential`);\n\treturn { apiKey: nonEmptyString(value.apiKey, `${providerId} credential apiKey`) };\n}\n\nfunction apiKeySecrets(credential: ApiKeyCredential | null): Readonly<Record<string, string>> {\n\treturn credential ? { apiKey: credential.apiKey } : {};\n}\n\nexport function parseStandardProviderConfig(\n\traw: unknown,\n\tproviderId: string,\n): { config: EmptyProviderConfig; credential?: ApiKeyCredential } {\n\tif (raw !== undefined && raw !== null && !isRecord(raw)) {\n\t\tthrow new Error(\"configuration must be an object\");\n\t}\n\tconst config = (raw ?? {}) as Record<string, unknown>;\n\tassertKnownFields(config, [\"api_key\"]);\n\tconst apiKey =\n\t\tconfig.api_key === undefined || config.api_key === null\n\t\t\t? getStandardEnvApiKey(providerId)\n\t\t\t: resolveSecret(config.api_key, \"api_key\");\n\treturn { config: {}, ...(apiKey ? { credential: { apiKey } } : {}) };\n}\n\nfunction catalogModelStatuses(\n\tctx: ModelProviderModelsContext,\n\tknownModelIds: ReadonlySet<string>,\n\tcredentialsAvailable: boolean,\n\tmissingReason: (modelId: string) => string,\n\tcredentialReason: string,\n): readonly ProviderModelStatus[] {\n\treturn [...new Set(ctx.configuredModels.map(({ modelId }) => modelId))].map((modelId) =>\n\t\t!knownModelIds.has(modelId)\n\t\t\t? { modelId, availability: \"unavailable\", safeReason: missingReason(modelId) }\n\t\t\t: credentialsAvailable\n\t\t\t\t? { modelId, availability: \"available\" }\n\t\t\t\t: { modelId, availability: \"unavailable\", safeReason: credentialReason },\n\t);\n}\n\nexport function evaluateStandardModelStatuses(\n\tproviderId: string,\n\tctx: ModelProviderModelsContext,\n): readonly ProviderModelStatus[] {\n\treturn catalogModelStatuses(\n\t\tctx,\n\t\tnew Set(getBuiltinModels(providerId as never).map(({ id }) => id)),\n\t\tctx.credentialStatus.available,\n\t\t(modelId) => `Canonical Pi model '${providerId}/${modelId}' is not found in catalog`,\n\t\t`${providerId} credentials are unavailable (set ${getKnownEnvKeys(providerId).join(\" or \")})`,\n\t);\n}\n\nexport function createStandardModelProvider(\n\tproviderId: string,\n): ModelProviderDefinition<EmptyProviderConfig, ApiKeyCredential> {\n\tconst reference = builtinPiProvider(providerId);\n\treturn defineModelProvider({\n\t\tid: providerId,\n\t\tparseConfig: (raw) => parseStandardProviderConfig(raw, providerId),\n\t\tworker: reference,\n\t\tserver: reference,\n\t\tmodels: (ctx) => evaluateStandardModelStatuses(providerId, ctx),\n\t\tcredential: { parse: (value) => parseApiKeyCredential(value, providerId) },\n\t\tsecrets: ({ credential }) => apiKeySecrets(credential),\n\t});\n}\n\nexport function parseCustomGatewayConfig(\n\tproviderId: string,\n\traw: unknown,\n): { config: CustomGatewayConfig; credential?: ApiKeyCredential } {\n\tconst parsed = v.parse(customGatewaySchema, raw);\n\tconst ids = new Set<string>();\n\tfor (const model of parsed.models) {\n\t\tif (ids.has(model.id)) throw new Error(`duplicate custom model id '${model.id}'`);\n\t\tids.add(model.id);\n\t}\n\tconst keyless = parsed.api_key === false;\n\tconst apiKey =\n\t\tkeyless || parsed.api_key === undefined || parsed.api_key === null\n\t\t\t? undefined\n\t\t\t: resolveSecret(parsed.api_key, \"api_key\");\n\treturn {\n\t\tconfig: {\n\t\t\tproviderId,\n\t\t\tbaseUrl: parsed.base_url,\n\t\t\tapi: parsed.api,\n\t\t\tkeyless,\n\t\t\tmodels: parsed.models,\n\t\t},\n\t\t...(apiKey ? { credential: { apiKey } } : {}),\n\t};\n}\n\nfunction customGatewayPiModels(config: CustomGatewayConfig): ProviderJsonObject {\n\treturn {\n\t\tproviders: {\n\t\t\t[config.providerId]: {\n\t\t\t\tbaseUrl: config.baseUrl,\n\t\t\t\tapi: config.api,\n\t\t\t\tmodels: config.models,\n\t\t\t},\n\t\t},\n\t};\n}\n\nfunction customGatewayModelStatuses(\n\tconfig: CustomGatewayConfig,\n\tctx: ModelProviderModelsContext<CustomGatewayConfig>,\n): readonly ProviderModelStatus[] {\n\treturn catalogModelStatuses(\n\t\tctx,\n\t\tnew Set(config.models.map(({ id }) => id)),\n\t\tconfig.keyless || ctx.credentialStatus.available,\n\t\t(modelId) =>\n\t\t\t`Canonical model '${config.providerId}/${modelId}' is not found in custom gateway definition`,\n\t\t`Gateway provider '${config.providerId}' credentials are unavailable`,\n\t);\n}\n\nexport function createCustomGatewayProvider(\n\tproviderId: string,\n\tkeyless: boolean,\n): ModelProviderDefinition<CustomGatewayConfig, ApiKeyCredential> {\n\treturn defineModelProvider({\n\t\tid: providerId,\n\t\tparseConfig: (raw) => parseCustomGatewayConfig(providerId, raw),\n\t\tworker: configuredPiProvider(providerId, ({ config }) => customGatewayPiModels(config)),\n\t\tmodels: (ctx) => customGatewayModelStatuses(ctx.config, ctx),\n\t\t...(keyless\n\t\t\t? {}\n\t\t\t: { credential: { parse: (value: unknown) => parseApiKeyCredential(value, providerId) } }),\n\t\tsecrets: ({ credential }) =>\n\t\t\tapiKeySecrets(credential ?? (keyless ? { apiKey: \"leitwerk-keyless\" } : null)),\n\t});\n}\n\nexport function resolveModelProviders(raw: unknown): readonly ModelProviderSetEntry[] {\n\tif (raw !== undefined && raw !== null && !isRecord(raw)) {\n\t\tthrow new Error(\"configuration must be an object\");\n\t}\n\tconst owner = (raw ?? {}) as Record<string, unknown>;\n\tconst standardIds = getSupportedStandardProviders();\n\tassertKnownFields(owner, [...standardIds, \"custom_gateways\"]);\n\tconst entries: ModelProviderSetEntry[] = standardIds.map((providerId) => ({\n\t\tdefinition: createStandardModelProvider(providerId),\n\t\trawConfig: owner[providerId],\n\t}));\n\tif (owner.custom_gateways === undefined) return entries;\n\tif (!isRecord(owner.custom_gateways)) throw new Error(\"custom_gateways must be an object\");\n\tfor (const [providerId, gateway] of Object.entries(owner.custom_gateways)) {\n\t\tif (!providerId.trim()) throw new Error(\"custom gateway provider id must not be empty\");\n\t\tentries.push({\n\t\t\tdefinition: createCustomGatewayProvider(\n\t\t\t\tproviderId,\n\t\t\t\tisRecord(gateway) && gateway.api_key === false,\n\t\t\t),\n\t\t\trawConfig: gateway,\n\t\t});\n\t}\n\treturn entries;\n}\n","const STANDARD_PROVIDER_ENV_KEYS: Readonly<Record<string, readonly string[]>> = {\n\t\"ant-ling\": [\"ANT_LING_API_KEY\"],\n\tanthropic: [\"ANTHROPIC_OAUTH_TOKEN\", \"ANTHROPIC_API_KEY\"],\n\t\"azure-openai-responses\": [\"AZURE_OPENAI_API_KEY\"],\n\tcerebras: [\"CEREBRAS_API_KEY\"],\n\t\"cloudflare-ai-gateway\": [\"CLOUDFLARE_API_KEY\"],\n\t\"cloudflare-workers-ai\": [\"CLOUDFLARE_API_KEY\"],\n\tdeepseek: [\"DEEPSEEK_API_KEY\"],\n\tfireworks: [\"FIREWORKS_API_KEY\"],\n\t\"github-copilot\": [\"COPILOT_GITHUB_TOKEN\"],\n\tgoogle: [\"GEMINI_API_KEY\"],\n\t\"google-vertex\": [\"GOOGLE_CLOUD_API_KEY\"],\n\tgroq: [\"GROQ_API_KEY\"],\n\thuggingface: [\"HF_TOKEN\"],\n\t\"kimi-coding\": [\"KIMI_API_KEY\"],\n\tminimax: [\"MINIMAX_API_KEY\"],\n\t\"minimax-cn\": [\"MINIMAX_CN_API_KEY\"],\n\tmistral: [\"MISTRAL_API_KEY\"],\n\tmoonshotai: [\"MOONSHOT_API_KEY\"],\n\t\"moonshotai-cn\": [\"MOONSHOT_API_KEY\"],\n\tnvidia: [\"NVIDIA_API_KEY\"],\n\topenai: [\"OPENAI_API_KEY\"],\n\topencode: [\"OPENCODE_API_KEY\"],\n\t\"opencode-go\": [\"OPENCODE_API_KEY\"],\n\topenrouter: [\"OPENROUTER_API_KEY\"],\n\t\"qwen-token-plan\": [\"QWEN_TOKEN_PLAN_API_KEY\"],\n\t\"qwen-token-plan-cn\": [\"QWEN_TOKEN_PLAN_CN_API_KEY\"],\n\ttogether: [\"TOGETHER_API_KEY\"],\n\t\"vercel-ai-gateway\": [\"AI_GATEWAY_API_KEY\"],\n\txai: [\"XAI_API_KEY\"],\n\txiaomi: [\"XIAOMI_API_KEY\"],\n\t\"xiaomi-token-plan-ams\": [\"XIAOMI_TOKEN_PLAN_AMS_API_KEY\"],\n\t\"xiaomi-token-plan-cn\": [\"XIAOMI_TOKEN_PLAN_CN_API_KEY\"],\n\t\"xiaomi-token-plan-sgp\": [\"XIAOMI_TOKEN_PLAN_SGP_API_KEY\"],\n\tzai: [\"ZAI_API_KEY\"],\n\t\"zai-coding-cn\": [\"ZAI_CODING_CN_API_KEY\"],\n};\n\nexport function getKnownEnvKeys(providerId: string): readonly string[] {\n\treturn STANDARD_PROVIDER_ENV_KEYS[providerId] ?? [];\n}\n\nexport function getStandardEnvApiKey(providerId: string): string | undefined {\n\tfor (const key of getKnownEnvKeys(providerId)) {\n\t\tconst value = process.env[key]?.trim();\n\t\tif (value) return value;\n\t}\n\treturn undefined;\n}\n\n/** Built-in providers whose credentials fit Leitwerk's standard API-key projection. */\nexport function getSupportedStandardProviders(): readonly string[] {\n\treturn Object.keys(STANDARD_PROVIDER_ENV_KEYS);\n}\n"],"mappings":";AAAA,SAAS,4BAA0D;;;ACAnE,SAAS,wBAAwB;AACjC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAMM;AACP,YAAY,OAAO;;;ACXnB,IAAM,6BAA0E;AAAA,EAC/E,YAAY,CAAC,kBAAkB;AAAA,EAC/B,WAAW,CAAC,yBAAyB,mBAAmB;AAAA,EACxD,0BAA0B,CAAC,sBAAsB;AAAA,EACjD,UAAU,CAAC,kBAAkB;AAAA,EAC7B,yBAAyB,CAAC,oBAAoB;AAAA,EAC9C,yBAAyB,CAAC,oBAAoB;AAAA,EAC9C,UAAU,CAAC,kBAAkB;AAAA,EAC7B,WAAW,CAAC,mBAAmB;AAAA,EAC/B,kBAAkB,CAAC,sBAAsB;AAAA,EACzC,QAAQ,CAAC,gBAAgB;AAAA,EACzB,iBAAiB,CAAC,sBAAsB;AAAA,EACxC,MAAM,CAAC,cAAc;AAAA,EACrB,aAAa,CAAC,UAAU;AAAA,EACxB,eAAe,CAAC,cAAc;AAAA,EAC9B,SAAS,CAAC,iBAAiB;AAAA,EAC3B,cAAc,CAAC,o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ings":"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
|
+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EAAE,gBAAgB,CAAC,CAWhE;AAED,wBAAgB,wBAAwB,CACvC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,OAAO,GACV;IAAE,MAAM,EAAE,mBAAmB,CAAC;IAAC,UAAU,CAAC,EAAE,gBAAgB,CAAA;CAAE,CAsBhE;AA4BD,wBAAgB,2BAA2B,CAC1C,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,GACd,uBAAuB,CAAC,mBAAmB,EAAE,gBAAgB,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-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AO,OAAO,CAAC;IACxD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAC3F,KAAK,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC;QAC3E,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,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,kB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C;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAkB;IACtD,KAAK,MAAM,GAAG,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;QACvC,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IACzB,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,6BAA6B;IAC5C,OAAO,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leitwerk-dev/models",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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.1.
|
|
29
|
+
"@leitwerk-dev/process-sdk": "0.1.3",
|
|
30
30
|
"valibot": "^1.3.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|