feat: add profile auth method for bedrock (#695)
This commit is contained in:
@@ -8,6 +8,10 @@ import {
|
||||
startLocalOAuthServer,
|
||||
startOpenAIOAuth,
|
||||
} from "../../auth/openai-oauth";
|
||||
import {
|
||||
getProviderByName,
|
||||
removeProviderByName,
|
||||
} from "../../providers/byok-providers";
|
||||
import {
|
||||
createOrUpdateMinimaxProvider,
|
||||
getMinimaxProvider,
|
||||
@@ -116,18 +120,23 @@ export async function handleConnect(
|
||||
ctx.buffersRef,
|
||||
ctx.refreshDerived,
|
||||
msg,
|
||||
"Usage: /connect <provider> [options]\n\nAvailable providers:\n \u2022 codex - Connect via OAuth to authenticate with ChatGPT Plus/Pro\n \u2022 zai <api_key> - Connect to zAI with your API key\n \u2022 minimax <api_key> - Connect to MiniMax with your API key",
|
||||
"Usage: /connect <provider> [options]\n\nAvailable providers:\n \u2022 codex - Connect via OAuth to authenticate with ChatGPT Plus/Pro\n \u2022 zai <api_key> - Connect to zAI with your API key\n \u2022 minimax <api_key> - Connect to MiniMax with your API key\n \u2022 bedrock <method> - Connect to AWS Bedrock (iam/profile/default)",
|
||||
false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (provider !== "codex" && provider !== "zai" && provider !== "minimax") {
|
||||
if (
|
||||
provider !== "codex" &&
|
||||
provider !== "zai" &&
|
||||
provider !== "minimax" &&
|
||||
provider !== "bedrock"
|
||||
) {
|
||||
addCommandResult(
|
||||
ctx.buffersRef,
|
||||
ctx.refreshDerived,
|
||||
msg,
|
||||
`Error: Unknown provider "${provider}"\n\nAvailable providers: codex, zai, minimax\nUsage: /connect <provider> [options]`,
|
||||
`Error: Unknown provider "${provider}"\n\nAvailable providers: codex, zai, minimax, bedrock\nUsage: /connect <provider> [options]`,
|
||||
false,
|
||||
);
|
||||
return;
|
||||
@@ -145,6 +154,12 @@ export async function handleConnect(
|
||||
return;
|
||||
}
|
||||
|
||||
// Bedrock is handled here
|
||||
if (provider === "bedrock") {
|
||||
await handleConnectBedrock(ctx, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle /connect codex
|
||||
await handleConnectCodex(ctx, msg);
|
||||
}
|
||||
@@ -445,6 +460,69 @@ async function handleDisconnectMinimax(
|
||||
}
|
||||
}
|
||||
|
||||
const BEDROCK_PROVIDER_NAME = "lc-bedrock";
|
||||
|
||||
/**
|
||||
* Handle /disconnect bedrock
|
||||
*/
|
||||
async function handleDisconnectBedrock(
|
||||
ctx: ConnectCommandContext,
|
||||
msg: string,
|
||||
): Promise<void> {
|
||||
// Check if Bedrock provider exists
|
||||
const existing = await getProviderByName(BEDROCK_PROVIDER_NAME);
|
||||
if (!existing) {
|
||||
addCommandResult(
|
||||
ctx.buffersRef,
|
||||
ctx.refreshDerived,
|
||||
msg,
|
||||
'Not currently connected to AWS Bedrock.\n\nUse /connect and select "AWS Bedrock" to connect.',
|
||||
false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Show running status
|
||||
const cmdId = addCommandResult(
|
||||
ctx.buffersRef,
|
||||
ctx.refreshDerived,
|
||||
msg,
|
||||
"Disconnecting from AWS Bedrock...",
|
||||
true,
|
||||
"running",
|
||||
);
|
||||
|
||||
ctx.setCommandRunning(true);
|
||||
|
||||
try {
|
||||
// Remove provider from Letta
|
||||
await removeProviderByName(BEDROCK_PROVIDER_NAME);
|
||||
|
||||
updateCommandResult(
|
||||
ctx.buffersRef,
|
||||
ctx.refreshDerived,
|
||||
cmdId,
|
||||
msg,
|
||||
`\u2713 Disconnected from AWS Bedrock.\n\n` +
|
||||
`Provider '${BEDROCK_PROVIDER_NAME}' removed from Letta.`,
|
||||
true,
|
||||
"finished",
|
||||
);
|
||||
} catch (error) {
|
||||
updateCommandResult(
|
||||
ctx.buffersRef,
|
||||
ctx.refreshDerived,
|
||||
cmdId,
|
||||
msg,
|
||||
`\u2717 Failed to disconnect from Bedrock: ${getErrorMessage(error)}`,
|
||||
false,
|
||||
"finished",
|
||||
);
|
||||
} finally {
|
||||
ctx.setCommandRunning(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle /connect minimax command
|
||||
* Usage: /connect minimax <api_key>
|
||||
@@ -515,6 +593,27 @@ export async function handleConnectMinimax(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle /connect bedrock command
|
||||
* Redirects users to use the interactive /connect UI
|
||||
*/
|
||||
export async function handleConnectBedrock(
|
||||
ctx: ConnectCommandContext,
|
||||
msg: string,
|
||||
): Promise<void> {
|
||||
addCommandResult(
|
||||
ctx.buffersRef,
|
||||
ctx.refreshDerived,
|
||||
msg,
|
||||
'To connect AWS Bedrock, use /connect and select "AWS Bedrock" from the list.\n\n' +
|
||||
"The interactive UI will guide you through:\n" +
|
||||
" • Choosing an authentication method (IAM, Profile, or Default)\n" +
|
||||
" • Entering your credentials\n" +
|
||||
" • Validating the connection",
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle /disconnect command
|
||||
* Usage: /disconnect <provider>
|
||||
@@ -532,7 +631,7 @@ export async function handleDisconnect(
|
||||
ctx.buffersRef,
|
||||
ctx.refreshDerived,
|
||||
msg,
|
||||
"Usage: /disconnect <provider>\n\nAvailable providers: codex, claude, zai, minimax",
|
||||
"Usage: /disconnect <provider>\n\nAvailable providers: codex, claude, zai, minimax, bedrock",
|
||||
false,
|
||||
);
|
||||
return;
|
||||
@@ -550,6 +649,12 @@ export async function handleDisconnect(
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle /disconnect bedrock
|
||||
if (provider === "bedrock") {
|
||||
await handleDisconnectBedrock(ctx, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle /disconnect codex
|
||||
if (provider === "codex") {
|
||||
await handleDisconnectCodex(ctx, msg);
|
||||
@@ -567,7 +672,7 @@ export async function handleDisconnect(
|
||||
ctx.buffersRef,
|
||||
ctx.refreshDerived,
|
||||
msg,
|
||||
`Error: Unknown provider "${provider}"\n\nAvailable providers: codex, claude, zai, minimax\nUsage: /disconnect <provider>`,
|
||||
`Error: Unknown provider "${provider}"\n\nAvailable providers: codex, claude, zai, minimax, bedrock\nUsage: /disconnect <provider>`,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user