@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
44 lines • 1.92 kB
JavaScript
import { classifySdkError } from "../core/extensions/builtin/anthropic-subscription/errors.js";
import { assistantSchema } from "./content-schema.js";
import { providerEventSchema } from "./schema.js";
const messages = {
auth: "Subscription authentication failed.",
rate_limited: "Subscription accounts are rate limited.",
unavailable: "Subscription provider unavailable.",
aborted: "Operation aborted.",
invalid_request: "Invalid subscription request.",
};
export function failure(error, aborted) {
if (aborted)
return { code: "aborted", retryable: false };
const classified = classifySdkError(error);
switch (classified.kind) {
case "auth_error":
case "org_not_allowed":
return { code: "auth", retryable: classified.retryable };
case "rate_limit":
return { code: "rate_limited", retryable: classified.retryable };
default:
return { code: "unavailable", retryable: classified.retryable };
}
}
export function projectAssistant(message, code) {
// JSON conversion matches wire semantics (including omitted undefined tool arguments).
// The schema strips provider-private fields; callers never receive a live partial reference.
return assistantSchema.parse(JSON.parse(JSON.stringify({
role: message.role,
content: message.content,
api: message.api,
provider: message.provider,
model: message.model,
usage: message.usage,
stopReason: code === "aborted" ? "aborted" : code ? "error" : message.stopReason,
timestamp: message.timestamp,
...(code ? { errorMessage: messages[code] } : {}),
})));
}
export function projectEvent(event) {
const projected = { ...event, partial: projectAssistant(event.partial) };
return providerEventSchema.parse(JSON.parse(JSON.stringify(projected)));
}
//# sourceMappingURL=projection.js.map