feat(kiro): headless API-key auth + direct Claude/Kiro route

Adds long-lived API-key (ksk_) authentication for Kiro/AWS CodeWhisperer
and a direct claude:kiro / kiro:claude translation route that avoids the
lossy OpenAI two-hop pivot.

- translator: claude-to-kiro request + kiro-to-claude response translators,
  registered on the exact source:target pair (direct route ahead of the
  OpenAI pivot in index.js). claude-to-kiro uses shared schema constants
  (ROLE/CLAUDE_BLOCK/DEFAULT_IMAGE_MIME) per app convention.
- auth: POST /api/oauth/kiro/api-key imports + validates a key via
  ListAvailableProfiles, persists authMethod="api_key" (no refresh token).
- executor: send tokentype: API_KEY header and try *.amazonaws.com hosts
  first for api-key creds; OAuth keeps kiro.dev first.
- fix: never inject the default placeholder profileArn for api-key auth
  (CodeWhisperer 403s an ARN not owned by the key's account).
- ui: API Key method in the Kiro connect modal; surface api-key accounts
  on the Quota Tracker and provider count.
- stream: env-overridable TTFT vs stall timeouts + Kiro keepalive frame.
- tests: claude-kiro-direct + kiro-profile-arn (11 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
thienpv
2026-06-17 10:01:30 +07:00
committed by decolua
co-authored by Claude Opus 4.8 Cursor
parent 3de6ce157c
commit 706e6513c9
20 changed files with 1437 additions and 57 deletions
+109
View File
@@ -13,6 +13,8 @@ export default function KiroAuthModal({ isOpen, onMethodSelect, onClose }) {
const [idcStartUrl, setIdcStartUrl] = useState("");
const [idcRegion, setIdcRegion] = useState("us-east-1");
const [refreshToken, setRefreshToken] = useState("");
const [apiKey, setApiKey] = useState("");
const [apiKeyRegion, setApiKeyRegion] = useState("us-east-1");
const [error, setError] = useState(null);
const [importing, setImporting] = useState(false);
const [autoDetecting, setAutoDetecting] = useState(false);
@@ -96,6 +98,40 @@ export default function KiroAuthModal({ isOpen, onMethodSelect, onClose }) {
onMethodSelect("idc", { startUrl: idcStartUrl.trim(), region: idcRegion });
};
const handleApiKeyImport = async () => {
if (!apiKey.trim()) {
setError("Please enter an API key");
return;
}
setImporting(true);
setError(null);
try {
const res = await fetch("/api/oauth/kiro/api-key", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
apiKey: apiKey.trim(),
region: apiKeyRegion.trim() || "us-east-1",
}),
});
const data = await res.json();
if (!res.ok) {
throw new Error(data.error || "Import failed");
}
// Success - notify parent to refresh connections
onMethodSelect("api-key");
} catch (err) {
setError(err.message);
} finally {
setImporting(false);
}
};
const handleSocialLogin = (provider) => {
onMethodSelect("social", { provider });
};
@@ -142,6 +178,22 @@ export default function KiroAuthModal({ isOpen, onMethodSelect, onClose }) {
</div>
</button>
{/* AWS API Key */}
<button
onClick={() => handleMethodSelect("api-key")}
className="w-full p-4 text-left border border-border rounded-lg hover:bg-sidebar transition-colors"
>
<div className="flex items-start gap-3">
<span className="material-symbols-outlined text-primary mt-0.5">key</span>
<div className="flex-1">
<h3 className="font-semibold mb-1">API Key</h3>
<p className="text-sm text-text-muted">
Use a long-lived Kiro/CodeWhisperer API key (headless auth).
</p>
</div>
</div>
</button>
{/* Google Social Login - HIDDEN */}
<button
onClick={() => handleMethodSelect("social-google")}
@@ -240,6 +292,63 @@ export default function KiroAuthModal({ isOpen, onMethodSelect, onClose }) {
</div>
)}
{/* API Key */}
{selectedMethod === "api-key" && (
<div className="space-y-4">
<div className="bg-blue-50 dark:bg-blue-900/20 p-3 rounded-lg border border-blue-200 dark:border-blue-800">
<div className="flex gap-2">
<span className="material-symbols-outlined text-blue-600 dark:text-blue-400">info</span>
<p className="text-sm text-blue-800 dark:text-blue-200">
Paste a long-lived Kiro/CodeWhisperer API key. It is validated
against AWS and stored directly as a bearer credential (no refresh).
</p>
</div>
</div>
<div>
<label className="block text-sm font-medium mb-2">
API Key <span className="text-red-500">*</span>
</label>
<Input
value={apiKey}
onChange={(e) => setApiKey(e.target.value)}
placeholder="Paste your Kiro API key..."
className="font-mono text-sm"
/>
</div>
<div>
<label className="block text-sm font-medium mb-2">
AWS Region
</label>
<Input
value={apiKeyRegion}
onChange={(e) => setApiKeyRegion(e.target.value)}
placeholder="us-east-1"
className="font-mono text-sm"
/>
<p className="text-xs text-text-muted mt-1">
AWS region for the key (default: us-east-1)
</p>
</div>
{error && (
<div className="bg-red-50 dark:bg-red-900/20 p-3 rounded-lg border border-red-200 dark:border-red-800">
<p className="text-sm text-red-600 dark:text-red-400">{error}</p>
</div>
)}
<div className="flex gap-2">
<Button onClick={handleApiKeyImport} fullWidth disabled={importing || !apiKey.trim()}>
{importing ? "Validating..." : "Add API Key"}
</Button>
<Button onClick={handleBack} variant="ghost" fullWidth>
Back
</Button>
</div>
</div>
)}
{/* Social Login Info (Google) */}
{selectedMethod === "social-google" && (
<div className="space-y-4">
+2 -2
View File
@@ -27,8 +27,8 @@ export default function KiroOAuthWrapper({ isOpen, providerInfo, onSuccess, onCl
// Use social login with manual callback
setAuthMethod("social");
setSocialProvider(config.provider);
} else if (method === "import") {
// Import handled in KiroAuthModal, just close
} else if (method === "import" || method === "api-key") {
// Import / API-key handled in KiroAuthModal, just close
onSuccess?.();
}
}, [onSuccess]);