UNPKG

@sellable/install

Version:

One-command installer for Sellable MCP in Claude Code, Codex, and Hermes

85 lines (80 loc) • 2.01 kB
const CUSTOMER_RUNTIME_PHASES = new Set([ "runtime_secrets", "snapshot_restore", "legacy_migration", "profile_materialization", "default_profile_bundle", "profile_configuration", "memory_cron", "pre_serving_snapshot", "slack_serving_proof", "customer_program_crons", "post_cron_snapshot", "native_skill_proof", "serving_observation", "operation_completion", ]); function phaseFailureCode(error) { const code = error instanceof Error ? error.message : ""; return /^[A-Za-z0-9_:-]{1,160}$/.test(code) ? code : "customer_runtime_phase_failed"; } export function createCustomerRuntimePhaseTelemetry({ bootSessionId, operationId, now = () => Date.now(), write = (entry) => { process.stderr.write(`${JSON.stringify(entry)}\n`); }, }) { if ( typeof bootSessionId !== "string" || bootSessionId.length < 1 || typeof operationId !== "string" || operationId.length < 1 ) { throw new Error("customer_runtime_phase_identity_rejected"); } const run = async (phase, work) => { if (!CUSTOMER_RUNTIME_PHASES.has(phase) || typeof work !== "function") { throw new Error("customer_runtime_phase_rejected"); } const startedAt = now(); write({ ok: true, code: "customer_runtime_phase", phase, status: "started", elapsedMs: 0, bootSessionId, operationId, }); try { const result = await work(); write({ ok: true, code: "customer_runtime_phase", phase, status: "completed", elapsedMs: Math.max(0, now() - startedAt), bootSessionId, operationId, }); return result; } catch (error) { write({ ok: false, code: "customer_runtime_phase", phase, status: "failed", elapsedMs: Math.max(0, now() - startedAt), bootSessionId, operationId, errorCode: phaseFailureCode(error), }); throw error; } }; return { run }; }