UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

87 lines • 3.47 kB
import { normalizeWaitItems } from "./lifecycle-wait-items.js"; export function isRecord(value) { return typeof value === "object" && value !== null && !Array.isArray(value); } /** Parse owned JSONL data once, at restoration; unknown future records fail closed. */ export function readWorkCustody(value) { if (!isRecord(value) || typeof value.id !== "string" || typeof value.key !== "string") return undefined; if (value.kind !== "children" && value.kind !== "background") return undefined; switch (value.state) { case "open": case "queued": case "consumed": case "settled": case "held": case "cancelled": case "passive": break; default: return undefined; } const payload = readPayload(value.payload); return { id: value.id, key: value.key, kind: value.kind, state: value.state, ...normalizeWaitItems(value.items, value.omittedItems), ...(typeof value.source === "string" ? { source: value.source } : {}), ...(typeof value.activeCount === "number" ? { activeCount: value.activeCount } : {}), ...(typeof value.detail === "string" ? { detail: value.detail } : {}), ...(typeof value.ticketId === "string" ? { ticketId: value.ticketId } : {}), ...(payload ? { payload } : {}), ...(typeof value.runId === "string" ? { runId: value.runId } : {}), ...(typeof value.transcriptEntryId === "string" ? { transcriptEntryId: value.transcriptEntryId } : {}), ...(typeof value.noticeId === "string" ? { noticeId: value.noticeId } : {}), ...(value.delivery === "failed" || value.delivery === "retired" ? { delivery: value.delivery } : {}), }; } function readPayload(value) { if (!isRecord(value) || !isRecord(value.message)) return undefined; const message = value.message; if (typeof message.customType !== "string" || typeof message.display !== "boolean") return undefined; // Queued delivery accepts the same text/content boundary as CustomMessage. if (!isMessageContent(message.content)) return undefined; return { message: { customType: message.customType, content: message.content, display: message.display, details: message.details, }, ...(value.deliverAs === "steer" || value.deliverAs === "followUp" || value.deliverAs === "nextTurn" ? { deliverAs: value.deliverAs } : {}), ...(Array.isArray(value.itemIds) && value.itemIds.every((id) => typeof id === "string") ? { itemIds: value.itemIds } : {}), }; } function isMessageContent(value) { return (typeof value === "string" || (Array.isArray(value) && value.every((part) => isRecord(part) && ((part.type === "text" && typeof part.text === "string") || (part.type === "image" && typeof part.data === "string" && typeof part.mimeType === "string"))))); } export function custodyIsOpen(record) { switch (record.state) { case "open": case "queued": case "consumed": return true; case "settled": case "held": case "cancelled": case "passive": return false; default: return record.state; } } //# sourceMappingURL=work-custody-record.js.map