@sema-agent/core
Version:
Stateless, task-oriented AI agent core
31 lines (30 loc) • 1.26 kB
JavaScript
export const REFUSED_REQUEST_PARTS = Object.freeze(["input_too_long", "image_unprocessable", "tool_schema_refused", "output_cap_too_large", "media_items_refused"]);
export function outputCapReportOf(v) {
if (typeof v !== "object" || v === null)
return undefined;
const requested = v.requested;
const allowed = v.allowed;
if (typeof requested !== "number" || typeof allowed !== "number")
return undefined;
return Number.isSafeInteger(requested) && Number.isSafeInteger(allowed) && allowed >= 1 && requested > allowed ? { requested, allowed } : undefined;
}
export const PROMPT_BLOCK_CAUSES = Object.freeze(["block", "crashed", "timeout", "cancelled"]);
const PROMPT_BLOCK_CAUSE_SET = new Set(PROMPT_BLOCK_CAUSES);
export function isPromptBlockCause(v) {
return PROMPT_BLOCK_CAUSE_SET.has(v);
}
export const TERMINAL_CAUSE_IS_REPLAYABLE = {
completed: true,
failed: false,
blocked: false,
paused: false,
};
Object.freeze(TERMINAL_CAUSE_IS_REPLAYABLE);
export function isTerminalCauseKind(kind) {
return typeof kind === "string" && Object.hasOwn(TERMINAL_CAUSE_IS_REPLAYABLE, kind);
}
export function runAbortedError() {
const e = new Error("run aborted");
e.name = "AbortError";
return e;
}