You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: enhance credential handling for managed-agent and memory APIs
- Updated README.md to clarify API key usage and access restrictions for TokenPlan and pay-as-you-go keys.
- Introduced shared credential validation logic to prevent TokenPlan keys from being used in incompatible contexts.
- Enhanced error messaging for credential resolution failures in managed-agent and memory plugins.
- Added tests for credential classification and workspace endpoint composition.
- Updated documentation to reflect changes in credential handling and workspace-scoped agentstudio endpoint requirements.
"Bailian credentials come from bl's auth chain: --api-key > DASHSCOPE_API_KEY > `bl auth login` (active config profile).",
53
+
"The agentstudio endpoint is workspace-scoped: the base URL is composed from the workspace id (agents.yaml workspace_id > $BAILIAN_WORKSPACE_ID > bl's configured workspace_id) as https://{workspace}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio, and the key must belong to that workspace.",
53
54
"Other providers read the env vars referenced in agents.yaml (e.g. ${ANTHROPIC_API_KEY}), including .env and ~/.agents/config.json.",
54
55
"Resolved credentials are injected into the SDK in-memory and cleared from the environment; they never persist in process env.",
55
56
];
@@ -85,13 +86,19 @@ export function prepareProviderEnv(): void {
85
86
* the block references them and the interpolated value is empty (a literal in
86
87
* agents.yaml is respected).
87
88
*
88
-
* `base_url` carries {@link AGENTSTUDIO_API_PATH} because the SDK appends resource
89
-
* paths onto it verbatim; a value already ending in the suffix is left as-is.
90
-
* It is filled even without a credential — `client.baseUrl` is readable
91
-
* credential-less (defaults to the CLI's model-domain base URL) — so offline
92
-
* commands (which skip the credential assert) still satisfy the SDK's
93
-
* "workspace_id or base_url" schema. With no credential the `api_key` is left
94
-
* untouched: online commands reject it via {@link assertProviderCredentials}.
89
+
* `base_url` is composed from the workspace when one is known — block
90
+
* `workspace_id` (agents.yaml literal or interpolated `${BAILIAN_WORKSPACE_ID}`)
91
+
* first, then bl's configured `workspace_id` — because agentstudio is served
92
+
* only on the workspace-scoped host; the bare model-domain origin 404s it
93
+
* (managed-agents API overview: `https://{workspace_id}.cn-beijing.maas.
94
+
* aliyuncs.com/api/v1/agentstudio`, region cn-beijing only). Only with no
95
+
* workspace at all does the model-domain origin get {@link AGENTSTUDIO_API_PATH}
96
+
* suffixed. A value already ending in the suffix is left as-is. base_url is
97
+
* filled even without a credential — `client.baseUrl` is readable
98
+
* credential-less — so offline commands (which skip the credential assert)
99
+
* still satisfy the SDK's "workspace_id or base_url" schema. With no
100
+
* credential the `api_key` is left untouched: online commands reject it via
101
+
* {@link assertProviderCredentials}.
95
102
*/
96
103
exportfunctioninjectProviderCredentials(
97
104
providers: Record<string,unknown>,
@@ -103,16 +110,27 @@ export function injectProviderCredentials(
103
110
104
111
constcred=host.client.exportApiCredential();
105
112
if(cred)block.api_key=cred.token;
106
-
if("base_url"inblock&&!block.base_url){
107
-
// Defensive normalization: the auth chain already normalizes base_url to
108
-
// an origin, but never let a trailing slash produce "//api/v1/agentstudio".
0 commit comments