mirror of
https://github.com/decolua/9router.git
synced 2026-05-08 12:01:28 +00:00
Fix Kiro token refresh logic
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { BaseExecutor } from "./base.js";
|
||||
import { PROVIDERS } from "../config/constants.js";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { refreshKiroToken } from "../services/tokenRefresh.js";
|
||||
|
||||
/**
|
||||
* KiroExecutor - Executor for Kiro AI (AWS CodeWhisperer)
|
||||
@@ -319,31 +320,13 @@ export class KiroExecutor extends BaseExecutor {
|
||||
if (!credentials.refreshToken) return null;
|
||||
|
||||
try {
|
||||
const response = await fetch(this.config.tokenUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "kiro-cli/1.0.0"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
refreshToken: credentials.refreshToken
|
||||
})
|
||||
});
|
||||
// Use centralized refreshKiroToken function (handles both AWS SSO OIDC and Social Auth)
|
||||
const result = await refreshKiroToken(
|
||||
credentials.refreshToken,
|
||||
credentials.providerSpecificData,
|
||||
log
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
log?.error?.("TOKEN", `Kiro refresh failed: ${response.status}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
const result = {
|
||||
accessToken: data.accessToken,
|
||||
refreshToken: data.refreshToken || credentials.refreshToken,
|
||||
expiresIn: data.expiresIn || 3600
|
||||
};
|
||||
|
||||
log?.info?.("TOKEN", "Kiro token refreshed");
|
||||
return result;
|
||||
} catch (error) {
|
||||
log?.error?.("TOKEN", `Kiro refresh error: ${error.message}`);
|
||||
|
||||
@@ -228,6 +228,13 @@ export async function appendRequestLog({ model, provider, connectionId, tokens,
|
||||
const line = `${timestamp} | ${m} | ${p} | ${account} | ${sent} | ${received} | ${status}\n`;
|
||||
|
||||
fs.appendFileSync(LOG_FILE, line);
|
||||
|
||||
// Trim to keep only last 200 lines
|
||||
const content = fs.readFileSync(LOG_FILE, "utf-8");
|
||||
const lines = content.trim().split("\n");
|
||||
if (lines.length > 200) {
|
||||
fs.writeFileSync(LOG_FILE, lines.slice(-200).join("\n") + "\n");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to append to log.txt:", error.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user