33 type LoadedProjectConfig ,
44 type ProjectRuntimeContext ,
55 resolveProjectConfig ,
6- UserError ,
76} from "@openagentpack/sdk" ;
7+ import { BailianError , ExitCode } from "bailian-cli-core" ;
88import {
99 assertProviderCredentials ,
1010 type CredentialHost ,
@@ -20,12 +20,14 @@ export { CREDENTIALS_NOTE, OFFLINE_NOTE } from "./credentials.ts";
2020
2121/**
2222 * Whether this run requires provider keys:
23- * - "all" (default) — online command: every provider declared in agents.yaml
24- * must have a non-empty key after injection
23+ * - "all" (default) — online command: the Bailian provider must have a
24+ * non-empty key after injection
2525 * - "none" — offline command (local config/state only), skip the check
2626 */
2727export type CredentialScope = "all" | "none" ;
2828
29+ export const BAILIAN_PROVIDER = "bailian" ;
30+
2931interface AgentConfigOptions {
3032 resolveEnv ?: boolean ;
3133 projectName ?: string ;
@@ -42,7 +44,8 @@ interface AgentConfigOptions {
4244 * 3. override the bailian block with the CLI auth chain's credential (in-memory)
4345 * 4. scrub all credential vars from process.env (real values now live only in
4446 * the config object → provider adapters, never the environment)
45- * 5. fail with a CLI-authoritative AUTH error if any provider's key is empty
47+ * 5. enforce Bailian-only config and fail with a CLI-authoritative AUTH error
48+ * if its key is empty
4649 * (offline commands pass `credentials: "none"` to skip the check)
4750 */
4851export async function resolveAgentProjectConfig (
@@ -55,6 +58,7 @@ export async function resolveAgentProjectConfig(
5558 normalizeInterpolatedProviderBlocks ( resolved . config . providers ) ;
5659 injectProviderCredentials ( resolved . config . providers , host ) ;
5760 scrubCredentialEnv ( ) ;
61+ assertBailianOnlyProviders ( resolved . config . providers ) ;
5862 if ( ( options . credentials ?? "all" ) !== "none" ) {
5963 assertProviderCredentials ( resolved . config . providers ) ;
6064 }
@@ -91,15 +95,23 @@ export async function buildAgentRuntime(
9195 return { ...ctx , configPath } ;
9296}
9397
94- /** Ensure a user-supplied --provider value is actually configured in agents.yaml. */
95- export function assertProviderConfigured (
96- ctx : ProjectRuntimeContext ,
97- provider : string | undefined ,
98- ) : void {
99- if ( ! provider || provider === "all" ) return ;
100- if ( ctx . providers . has ( provider ) ) return ;
101- const available = Array . from ( ctx . providers . keys ( ) ) . join ( ", " ) || "none" ;
102- throw new UserError (
103- `Provider '${ provider } ' is not configured. Available providers: ${ available } .` ,
98+ /** Enforce the bl product boundary while the shared SDK remains multi-provider capable. */
99+ export function assertBailianOnlyProviders ( providers : Record < string , unknown > ) : void {
100+ const configuredProviders = Object . keys ( providers ) ;
101+ const unsupportedProviders = configuredProviders . filter (
102+ ( provider ) => provider !== BAILIAN_PROVIDER ,
104103 ) ;
104+ if ( unsupportedProviders . length > 0 ) {
105+ const names = unsupportedProviders . join ( ", " ) ;
106+ throw new BailianError (
107+ `bl managed-agent only supports provider '${ BAILIAN_PROVIDER } '; remove unsupported providers: ${ names } . / bl managed-agent 仅支持 Provider '${ BAILIAN_PROVIDER } ';请移除不支持的 Provider:${ names } 。` ,
108+ ExitCode . USAGE ,
109+ ) ;
110+ }
111+ if ( ! ( BAILIAN_PROVIDER in providers ) ) {
112+ throw new BailianError (
113+ `bl managed-agent requires a '${ BAILIAN_PROVIDER } ' provider configuration. / bl managed-agent 需要配置 Provider '${ BAILIAN_PROVIDER } '。` ,
114+ ExitCode . USAGE ,
115+ ) ;
116+ }
105117}
0 commit comments