|
1 | 1 | import { z } from "zod"; |
2 | 2 | import { canonicalToolName } from "../utils/tool-permissions.ts"; |
| 3 | +import { validateCredentialPolicy } from "../validation/vault-credential.ts"; |
3 | 4 |
|
4 | 5 | const networkingSchema = z.object({ |
5 | 6 | type: z.enum(["unrestricted", "limited"]), |
@@ -366,25 +367,46 @@ const deploymentSchema = z.object({ |
366 | 367 | environment_variables: z.string().optional(), |
367 | 368 | }); |
368 | 369 |
|
369 | | -export const projectConfigSchema = z.object({ |
370 | | - version: z.string(), |
371 | | - providers: z.record(z.string(), z.unknown()), |
372 | | - defaults: z |
373 | | - .object({ |
374 | | - provider: z.string().optional(), |
375 | | - identity: z.string().min(1).optional(), |
376 | | - }) |
377 | | - .optional(), |
378 | | - environments: z.record(z.string(), environmentSchema).optional(), |
379 | | - tunnels: z.record(z.string(), tunnelSchema).optional(), |
380 | | - vaults: z.record(z.string(), vaultSchema).optional(), |
381 | | - memory_stores: z.record(z.string(), memoryStoreSchema).optional(), |
382 | | - skills: z.record(z.string(), skillSchema).optional(), |
383 | | - files: z.record(z.string(), fileSchema).optional(), |
384 | | - identities: z.record(z.string(), identitySchema).optional(), |
385 | | - agents: z.record(z.string(), agentSchema).optional(), |
386 | | - channels: z.record(z.string(), channelSchema).optional(), |
387 | | - deployments: z.record(z.string(), deploymentSchema).optional(), |
388 | | -}); |
| 370 | +export const projectConfigSchema = z |
| 371 | + .object({ |
| 372 | + version: z.string(), |
| 373 | + providers: z.record(z.string(), z.unknown()), |
| 374 | + defaults: z |
| 375 | + .object({ |
| 376 | + provider: z.string().optional(), |
| 377 | + identity: z.string().min(1).optional(), |
| 378 | + }) |
| 379 | + .optional(), |
| 380 | + environments: z.record(z.string(), environmentSchema).optional(), |
| 381 | + tunnels: z.record(z.string(), tunnelSchema).optional(), |
| 382 | + vaults: z.record(z.string(), vaultSchema).optional(), |
| 383 | + memory_stores: z.record(z.string(), memoryStoreSchema).optional(), |
| 384 | + skills: z.record(z.string(), skillSchema).optional(), |
| 385 | + files: z.record(z.string(), fileSchema).optional(), |
| 386 | + identities: z.record(z.string(), identitySchema).optional(), |
| 387 | + agents: z.record(z.string(), agentSchema).optional(), |
| 388 | + channels: z.record(z.string(), channelSchema).optional(), |
| 389 | + deployments: z.record(z.string(), deploymentSchema).optional(), |
| 390 | + }) |
| 391 | + .superRefine((config, context) => { |
| 392 | + const defaultProvider = config.defaults?.provider; |
| 393 | + const targetProviders = |
| 394 | + defaultProvider && defaultProvider !== "all" ? [defaultProvider] : Object.keys(config.providers); |
| 395 | + for (const [vaultName, vault] of Object.entries(config.vaults ?? {})) { |
| 396 | + const providers = vault.provider ? [vault.provider] : targetProviders; |
| 397 | + // Only a positively identified Bailian target may omit type or use injection policy fields. |
| 398 | + for (const provider of providers.length > 0 ? providers : ["unknown"]) { |
| 399 | + for (const [index, credential] of vault.credentials.entries()) { |
| 400 | + for (const issue of validateCredentialPolicy(provider, credential)) { |
| 401 | + context.addIssue({ |
| 402 | + code: "custom", |
| 403 | + path: ["vaults", vaultName, "credentials", index, ...issue.field.split(".")], |
| 404 | + message: issue.message, |
| 405 | + }); |
| 406 | + } |
| 407 | + } |
| 408 | + } |
| 409 | + } |
| 410 | + }); |
389 | 411 |
|
390 | 412 | export type ParsedConfig = z.infer<typeof projectConfigSchema>; |
0 commit comments