fix(server): recognize Bedrock-backed Claude as authenticated (#3931)
This commit is contained in:
1 parent
dfbda84362
commit
68ea280388
2 files changed
+50
-5
No files matched your search
@@ -480,9 +480,19 @@ function claudeAuthMetadata(input: {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function apiProviderAuthMetadata(
|
||||
apiProvider: string | undefined,
|
||||
): { readonly type: string; readonly label: string } | undefined {
|
||||
return apiProvider === "bedrock" ? { type: "bedrock", label: "Amazon Bedrock" } : undefined;
|
||||
}
|
||||
|
||||
// ── SDK capability probe ────────────────────────────────────────────
|
||||
|
||||
const CAPABILITIES_PROBE_TIMEOUT_MS = 8_000;
|
||||
// Amazon Bedrock initializes far slower than first-party auth: the SDK boots the
|
||||
// Bedrock backend and runs the `awsAuthRefresh` credential hook before returning
|
||||
// account info. The previous 8s budget expired mid-init, so the probe returned
|
||||
// `undefined` and left the provider unverified and unselectable in the picker.
|
||||
const CAPABILITIES_PROBE_TIMEOUT_MS = 25_000;
|
||||
|
||||
function nonEmptyProbeString(value: string): string | undefined {
|
||||
const candidate = value.trim();
|
||||
@@ -493,6 +503,12 @@ type ClaudeCapabilitiesProbe = {
|
||||
readonly email: string | undefined;
|
||||
readonly subscriptionType: string | undefined;
|
||||
readonly tokenSource: string | undefined;
|
||||
/**
|
||||
* Active API backend reported by the SDK's `AccountInfo`. Anthropic OAuth
|
||||
* login only applies when `"firstParty"`; for Amazon Bedrock (`"bedrock"`)
|
||||
* the subscription/token fields are absent and auth is external AWS creds.
|
||||
*/
|
||||
readonly apiProvider: string | undefined;
|
||||
readonly slashCommands: ReadonlyArray<ServerProviderSlashCommand>;
|
||||
};
|
||||
|
||||
@@ -618,12 +634,14 @@ const probeClaudeCapabilities = (
|
||||
readonly email?: string;
|
||||
readonly subscriptionType?: string;
|
||||
readonly tokenSource?: string;
|
||||
readonly apiProvider?: string;
|
||||
}
|
||||
| undefined;
|
||||
return {
|
||||
email: account?.email,
|
||||
subscriptionType: account?.subscriptionType,
|
||||
tokenSource: account?.tokenSource,
|
||||
apiProvider: account?.apiProvider,
|
||||
slashCommands: parseClaudeInitializationCommands(init.commands),
|
||||
} satisfies ClaudeCapabilitiesProbe;
|
||||
});
|
||||
@@ -799,10 +817,11 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
|
||||
});
|
||||
}
|
||||
|
||||
const authMetadata = claudeAuthMetadata({
|
||||
subscriptionType: capabilities.subscriptionType,
|
||||
authMethod: capabilities.tokenSource,
|
||||
});
|
||||
const authMetadata =
|
||||
claudeAuthMetadata({
|
||||
subscriptionType: capabilities.subscriptionType,
|
||||
authMethod: capabilities.tokenSource,
|
||||
}) ?? apiProviderAuthMetadata(capabilities.apiProvider);
|
||||
return buildServerProvider({
|
||||
presentation: CLAUDE_PRESENTATION,
|
||||
enabled: claudeSettings.enabled,
|
||||
|
||||
@@ -100,6 +100,7 @@ type TestClaudeCapabilities = {
|
||||
readonly email: string | undefined;
|
||||
readonly subscriptionType: string | undefined;
|
||||
readonly tokenSource: string | undefined;
|
||||
readonly apiProvider: string | undefined;
|
||||
readonly slashCommands: ReadonlyArray<ServerProviderSlashCommand>;
|
||||
};
|
||||
|
||||
@@ -109,6 +110,7 @@ function claudeCapabilities(overrides: Partial<TestClaudeCapabilities> = {}) {
|
||||
email: undefined,
|
||||
subscriptionType: undefined,
|
||||
tokenSource: undefined,
|
||||
apiProvider: undefined,
|
||||
slashCommands: [],
|
||||
...overrides,
|
||||
});
|
||||
@@ -1492,6 +1494,30 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("returns ready and labels Bedrock-backed Claude as authenticated", () =>
|
||||
Effect.gen(function* () {
|
||||
// Bedrock authenticates via external AWS credentials, so the SDK init
|
||||
// reports only `apiProvider` with no subscription or token.
|
||||
const status = yield* checkClaudeProviderStatus(
|
||||
defaultClaudeSettings,
|
||||
claudeCapabilities({ apiProvider: "bedrock" }),
|
||||
);
|
||||
assert.strictEqual(status.status, "ready");
|
||||
assert.strictEqual(status.installed, true);
|
||||
assert.strictEqual(status.auth.status, "authenticated");
|
||||
assert.strictEqual(status.auth.type, "bedrock");
|
||||
assert.strictEqual(status.auth.label, "Amazon Bedrock");
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
mockSpawnerLayer((args) => {
|
||||
const joined = args.join(" ");
|
||||
if (joined === "--version") return { stdout: "1.0.0\n", stderr: "", code: 0 };
|
||||
throw new Error(`Unexpected args: ${joined}`);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("includes Claude Fable 5 on supported Claude Code versions", () =>
|
||||
Effect.gen(function* () {
|
||||
const status = yield* checkClaudeProviderStatus(
|
||||
|
||||
Reference in new issue
Block a user