← Files RivetARCHIVED FILE

node_modules/rivet-design/dist/cli/runtimeInterruption.js

3.14 KB · Nov 5, 2026 · 12:09 UTC

↓ Download file

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.readRuntimeInterruptions = exports.recordRuntimeInterruption = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const zod_1 = require("zod");
const crypto_1 = require("crypto");
const serverHandshake_1 = require("./serverHandshake");
const telemetry_1 = require("../config/telemetry");
const writeFileAtomic_1 = require("../utils/writeFileAtomic");
const interruptionSchema = zod_1.z.object({
    receiptPath: zod_1.z.string(),
    serverVersion: zod_1.z.string().nullable(),
    clientVersion: zod_1.z.string(),
    createdAt: zod_1.z.string(),
    workIds: zod_1.z.array(zod_1.z.string()),
    message: zod_1.z.string(),
});
const interruptionDirectory = (projectPath) => path_1.default.join((0, serverHandshake_1.serverRuntimeDirectory)(projectPath), 'interruptions');
const collectWorkIds = (value) => {
    if (Array.isArray(value))
        return value.flatMap(collectWorkIds);
    if (!value || typeof value !== 'object')
        return [];
    if ('status' in value &&
        ['succeeded', 'failed', 'cancelled'].includes(String(value.status)))
        return 'refinement' in value ? collectWorkIds(value.refinement) : [];
    return Object.entries(value).flatMap(([key, item]) => {
        if (['workId', 'workItemId', 'requestId', 'agentRunId', 'traceId'].includes(key) &&
            typeof item === 'string')
            return [item];
        return collectWorkIds(item);
    });
};
const recordRuntimeInterruption = ({ attached, snapshot, }) => {
    const directory = interruptionDirectory(attached.handshake.projectPath);
    fs_1.default.mkdirSync(directory, { recursive: true, mode: 0o700 });
    const receiptPath = path_1.default.join(directory, `${(0, crypto_1.randomUUID)()}.json`);
    const interruption = {
        receiptPath,
        serverVersion: attached.handshake.rivetVersion ?? null,
        clientVersion: telemetry_1.RIVET_VERSION,
        createdAt: new Date().toISOString(),
        workIds: Array.from(new Set(collectWorkIds(snapshot))),
        message: 'Rivet interrupted this work to upgrade its server. Restart the original request with the updated CLI. Saved completed directions remain in history; the previous session and leases no longer apply.',
    };
    (0, writeFileAtomic_1.writeFileAtomicSync)(receiptPath, JSON.stringify({ ...interruption, snapshot }), { mode: 0o600 });
    return interruption;
};
exports.recordRuntimeInterruption = recordRuntimeInterruption;
const readRuntimeInterruptions = (projectPath) => {
    const directory = interruptionDirectory(projectPath);
    if (!fs_1.default.existsSync(directory))
        return [];
    return fs_1.default
        .readdirSync(directory)
        .filter((name) => name.endsWith('.json'))
        .map((name) => interruptionSchema.parse(JSON.parse(fs_1.default.readFileSync(path_1.default.join(directory, name), 'utf8'))));
};
exports.readRuntimeInterruptions = readRuntimeInterruptions;
//# sourceMappingURL=runtimeInterruption.js.map

SHA-256: 2edc491520c07091cd5b42edbfeac6e4d1ff825e58110c9390927b0ce0bbd6f1