UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

32 lines (31 loc) • 1.31 kB
export const DEFAULT_RESOURCE_TTL_MS = 30 * 24 * 60 * 60 * 1000; export const USAGE_WINDOW_REAP_MARGIN_MS = 60 * 60 * 1000; export const DEFAULT_UNATTENDED_APPROVAL_TTL_MS = 30 * 24 * 60 * 60 * 1000; export function sanitizedTtlMs(ttlMs) { if (ttlMs === undefined) return undefined; return Number.isFinite(ttlMs) && ttlMs > 0 ? ttlMs : DEFAULT_RESOURCE_TTL_MS; } export function gatedCallIdOf(p) { return p.pausedRef.current?.gatedCallId; } export function parkContaminationMarker(refs) { if (refs.pausedRef.current === undefined) return undefined; const gatedCallId = gatedCallIdOf(refs); return { code: "gate.parked", ...(gatedCallId !== undefined ? { gatedCallId } : {}) }; } export function publishCommittedSuspend(refs, token, gate, scope, remoteHandle, checkpointId, pendingAction) { const pause = { cause: { kind: "paused", gate, token, ...(checkpointId !== undefined ? { checkpointId } : {}), ...(remoteHandle !== undefined ? { restoreMode: remoteHandle.restoreMode === "park_only" ? "park_only" : "snapshot" } : {}), }, scope, ...(pendingAction?.kind === "tool_approval" ? { gatedCallId: pendingAction.toolCallId } : {}), }; refs.pausedRef.current = pause; }