@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
40 lines • 1.88 kB
JavaScript
/**
* Classifies how a failed `/login` or API-key dialog ends so interactive mode
* renders a cancellation as a neutral status line and only a genuine
* provider/network/OAuth failure as an error.
*/
import { CredentialSynchronizationError } from "../../core/model-runtime.js";
export const LOGIN_CANCELLED_NOTICE = "Login cancelled";
/**
* A login ends by cancellation when its abort reason is an abort: the dialog's
* `AbortController.abort()` with no reason (a DOMException named `AbortError`
* whose message is "This operation was aborted"), the `AbortError` fabricated by
* `raceWithAbortSignal`, an explicit `"Login cancelled"`, or no reason at all.
*/
export function isLoginCancellation(error) {
if (error === undefined || error === null)
return true;
if (typeof error === "object" && error.name === "AbortError")
return true;
return errorMessage(error) === LOGIN_CANCELLED_NOTICE;
}
export function describeLoginFailure(error, providerName, method) {
if (isLoginCancellation(error))
return { level: "status", message: LOGIN_CANCELLED_NOTICE };
const message = errorMessage(error);
if (error instanceof CredentialSynchronizationError) {
const done = method === "oauth" ? `Logged in to ${providerName}` : `Saved API key for ${providerName}`;
return { level: "error", message: `${done}, but local model state could not be synchronized: ${message}` };
}
const failed = method === "oauth"
? `Sign-in to ${providerName} did not finish`
: `Could not save the API key for ${providerName}`;
return {
level: "error",
message: `${failed}: ${message}${/[.!?]$/.test(message) ? "" : "."} Run /login to try again.`,
};
}
function errorMessage(error) {
return error instanceof Error ? error.message : String(error);
}
//# sourceMappingURL=login-outcome.js.map