skillar 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +280 -0
- package/README.md +37 -5
- package/dist/analysis/finding.js +8 -190
- package/dist/analysis/kernel.js +896 -0
- package/dist/analysis/tree.js +7 -154
- package/dist/analysis/usage.js +9 -394
- package/dist/api/flows.js +42 -212
- package/dist/api/report-kernel.js +1063 -0
- package/dist/api/routes.js +12 -2
- package/dist/catalog/fields.js +138 -146
- package/dist/catalog/watcher.js +7 -2
- package/dist/cli/init.js +45 -0
- package/dist/cli/main.js +76 -3
- package/dist/cli/private-skills.js +122 -0
- package/dist/cli/serve.js +15 -1
- package/dist/cli/sync.js +124 -0
- package/dist/dashboard/NOTICE +280 -0
- package/dist/dashboard/assets/app.js +737 -275
- package/dist/dashboard/assets/astryx-reset.css +407 -0
- package/dist/dashboard/assets/astryx.css +1077 -0
- package/dist/dashboard/assets/charts.css +54 -0
- package/dist/dashboard/assets/chunk-TPGDA2J4.js +1 -0
- package/dist/dashboard/assets/chunk-YLWHVDMP.js +36 -0
- package/dist/dashboard/assets/controls.css +207 -0
- package/dist/dashboard/assets/overlays.css +132 -0
- package/dist/dashboard/assets/p1.css +135 -0
- package/dist/dashboard/assets/shell.css +71 -0
- package/dist/dashboard/assets/skillar-theme.css +692 -0
- package/dist/dashboard/assets/styles.css +224 -121
- package/dist/dashboard/assets/tokens.css +278 -0
- package/dist/dashboard/assets/widgets.css +83 -0
- package/dist/dashboard/index.html +11 -2
- package/dist/dashboard/viewers/viewers.css +61 -0
- package/dist/ingest/attribution.js +5 -1
- package/dist/ingest/pipeline.js +2 -0
- package/dist/ingest/request-recorder.js +39 -0
- package/dist/mcp/dispatch.js +2 -2
- package/dist/mcp/http.js +43 -3
- package/dist/mcp/skills-extension.js +42 -15
- package/dist/mcp/stdio-proxy.js +24 -3
- package/dist/mcp/tools.js +38 -24
- package/dist/packs/claude-code.js +22 -11
- package/dist/packs/cursor.js +9 -4
- package/dist/packs/gemini.js +9 -4
- package/dist/packs/json-config.js +41 -0
- package/dist/packs/omo.js +15 -6
- package/dist/request-status.js +81 -0
- package/dist/search/fts.js +93 -58
- package/dist/search/fusion.js +49 -47
- package/dist/search/guidance.js +18 -6
- package/dist/search/index.js +291 -70
- package/dist/search/lexical.js +71 -63
- package/dist/server.js +12 -0
- package/dist/skills/apply.js +130 -0
- package/dist/skills/capture.js +54 -0
- package/dist/skills/cloud-plan.js +57 -0
- package/dist/skills/cloud.js +81 -0
- package/dist/skills/fs.js +133 -0
- package/dist/skills/package.js +734 -0
- package/dist/skills/plan.js +83 -0
- package/dist/skills/receipt.js +44 -0
- package/dist/skills/rollback.js +119 -0
- package/dist/skills/transfer.js +51 -0
- package/dist/store/db.js +7 -1
- package/dist/store/execution.js +2 -34
- package/dist/store/export.js +25 -4
- package/dist/store/migrations/007_sync.sql +49 -0
- package/dist/store/migrations/008_connector_commands.sql +12 -0
- package/dist/store/queries.js +33 -7
- package/dist/store/writes.js +38 -5
- package/dist/sync/cloud-blobs.js +175 -0
- package/dist/sync/cloud-commands.js +101 -0
- package/dist/sync/cloud-connection.js +105 -0
- package/dist/sync/cloud-delivery.js +114 -0
- package/dist/sync/cloud-documents.js +103 -0
- package/dist/sync/cloud-export.js +67 -0
- package/dist/sync/cloud-http.js +150 -0
- package/dist/sync/cloud-jobs.js +94 -0
- package/dist/sync/cloud-pending.js +143 -0
- package/dist/sync/cloud-prepare.js +101 -0
- package/dist/sync/cloud-restore.js +136 -0
- package/dist/sync/cloud-rollback.js +24 -0
- package/dist/sync/cloud-runner.js +86 -0
- package/dist/sync/cloud-runtime.js +293 -0
- package/dist/sync/cloud-schema.js +32 -0
- package/dist/sync/cloud-stage.js +112 -0
- package/dist/sync/cloud-wire.js +693 -0
- package/dist/sync/cloud-worker.js +57 -0
- package/dist/sync/cloud.js +157 -0
- package/dist/sync/command-apply.js +140 -0
- package/dist/sync/command-control.js +25 -0
- package/dist/sync/command-wire.js +437 -0
- package/dist/sync/consent.js +130 -0
- package/dist/sync/journal.js +43 -0
- package/dist/sync/outbox.js +134 -0
- package/dist/sync/restore-rows.js +125 -0
- package/dist/sync/restore.js +174 -0
- package/dist/sync/snapshot.js +78 -0
- package/dist/sync/spool-request.js +103 -0
- package/dist/sync/tables.js +27 -0
- package/dist/sync/triggers.js +34 -0
- package/dist/workflow/compare.js +3 -43
- package/docs/cloud-sync.md +94 -0
- package/docs/private-skills.md +75 -0
- package/docs/sync-p4.md +102 -0
- package/docs/sync-restore.md +167 -0
- package/package.json +18 -5
- package/src/store/migrations/007_sync.sql +49 -0
- package/src/store/migrations/008_connector_commands.sql +12 -0
- package/dist/dashboard/assets/chunk-5DFWNJC2.js +0 -1
- package/dist/dashboard/assets/chunk-S6B2HJQA.js +0 -17
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { CloudSyncError } from "./cloud-blobs.js";
|
|
4
|
+
import { ActivityContractError, MAX_CONTENT_BYTES, MAX_CONTENT_CHUNK_BYTES, contentDocumentSchema, parseContentChunkUpload, transformContentRows, MAX_SNAPSHOT_PAGES, MAX_SNAPSHOT_ROWS, } from "./cloud-wire.js";
|
|
5
|
+
import { shape } from "./restore-rows.js";
|
|
6
|
+
import { mutationSchema, scalarSchema, targetTables } from "./tables.js";
|
|
7
|
+
export const blobReferenceSchema = z.strictObject({
|
|
8
|
+
hash: z.string().regex(/^[a-f0-9]{64}$/), bytes: z.number().int().min(1).max(256 * 1024),
|
|
9
|
+
});
|
|
10
|
+
export const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
11
|
+
/** Frozen local backup reader; explicit pressure is never a truncated snapshot. */
|
|
12
|
+
export function snapshotRecords(db, cut) {
|
|
13
|
+
const records = [];
|
|
14
|
+
let total = 0;
|
|
15
|
+
for (const table of targetTables) {
|
|
16
|
+
const { columns, keys } = shape(db, table);
|
|
17
|
+
const quote = (name) => `"${name.replaceAll('"', '""')}"`;
|
|
18
|
+
const order = table === "load_candidates" ? keys.map(quote).join(",") : "rowid";
|
|
19
|
+
const length = columns.map(name => `COALESCE(length(CAST(${quote(name)} AS BLOB)),0)`).join("+");
|
|
20
|
+
if (db.prepare(`SELECT 1 FROM "${table}" WHERE ${length}>? LIMIT 1`).get(MAX_CONTENT_BYTES)) {
|
|
21
|
+
throw new CloudSyncError("snapshot_pressure");
|
|
22
|
+
}
|
|
23
|
+
const cursor = db.prepare(`SELECT *,${table === "load_candidates" ? "NULL" : "rowid"}
|
|
24
|
+
AS cloud_source_order FROM "${table}" ORDER BY ${order}`).iterate();
|
|
25
|
+
for (const raw of cursor) {
|
|
26
|
+
const values = Object.fromEntries(columns.map(name => [name, scalarSchema.parse(raw[name])]));
|
|
27
|
+
const record = mutationSchema.parse({
|
|
28
|
+
table, key: JSON.stringify(keys.map(name => values[name])), revision: cut,
|
|
29
|
+
operation: "upsert", sourceOrder: raw["cloud_source_order"], values,
|
|
30
|
+
});
|
|
31
|
+
total += Buffer.byteLength(JSON.stringify(record));
|
|
32
|
+
if (total > MAX_CONTENT_BYTES || records.length >= MAX_SNAPSHOT_ROWS) {
|
|
33
|
+
throw new CloudSyncError("snapshot_pressure");
|
|
34
|
+
}
|
|
35
|
+
records.push(record);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return records;
|
|
39
|
+
}
|
|
40
|
+
/** A record outside explicit temporal coverage is not silently widened to all history. */
|
|
41
|
+
export async function coveredRows(consent, scope, records) {
|
|
42
|
+
const rows = [];
|
|
43
|
+
let excluded = 0;
|
|
44
|
+
for (const record of records) {
|
|
45
|
+
try {
|
|
46
|
+
const document = await transformContentRows(consent, scope, [record]);
|
|
47
|
+
if (document === null)
|
|
48
|
+
throw new CloudSyncError("local_only");
|
|
49
|
+
rows.push(...contentDocumentSchema.parse(document).rows);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error instanceof ActivityContractError && error.code === "range_not_allowed") {
|
|
53
|
+
excluded++;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { rows, excluded };
|
|
61
|
+
}
|
|
62
|
+
export function snapshotDocuments(rows) {
|
|
63
|
+
const pages = [];
|
|
64
|
+
let current = [];
|
|
65
|
+
for (const row of rows) {
|
|
66
|
+
const next = [...current, row];
|
|
67
|
+
if (current.length > 0 &&
|
|
68
|
+
(next.length > 100 || Buffer.byteLength(JSON.stringify({ schemaVersion: 2, rows: next })) > 256 * 1024)) {
|
|
69
|
+
pages.push({ schemaVersion: 2, rows: current });
|
|
70
|
+
current = [];
|
|
71
|
+
}
|
|
72
|
+
current.push(row);
|
|
73
|
+
if (Buffer.byteLength(JSON.stringify({ schemaVersion: 2, rows: current })) > MAX_CONTENT_BYTES) {
|
|
74
|
+
throw new CloudSyncError("snapshot_pressure");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (current.length > 0 || pages.length === 0)
|
|
78
|
+
pages.push({ schemaVersion: 2, rows: current });
|
|
79
|
+
if (pages.length > MAX_SNAPSHOT_PAGES)
|
|
80
|
+
throw new CloudSyncError("snapshot_pressure");
|
|
81
|
+
return pages;
|
|
82
|
+
}
|
|
83
|
+
/** Store exact HTTP request bytes, after consent transformation and before manifest commit. */
|
|
84
|
+
export function spoolDocumentChunks(blobs, document, common, revision) {
|
|
85
|
+
const bytes = Buffer.from(JSON.stringify(document));
|
|
86
|
+
if (bytes.byteLength > MAX_CONTENT_BYTES)
|
|
87
|
+
throw new CloudSyncError("snapshot_pressure");
|
|
88
|
+
const refs = [];
|
|
89
|
+
const chunks = [];
|
|
90
|
+
for (let offset = 0; offset < bytes.length; offset += MAX_CONTENT_CHUNK_BYTES) {
|
|
91
|
+
const part = bytes.subarray(offset, offset + MAX_CONTENT_CHUNK_BYTES);
|
|
92
|
+
const chunk = parseContentChunkUpload({
|
|
93
|
+
...common, revision, index: chunks.length, plaintextHash: sha256(part),
|
|
94
|
+
bytes: part.length, body: part.toString("base64"),
|
|
95
|
+
});
|
|
96
|
+
refs.push(blobs.put(Buffer.from(JSON.stringify(chunk))));
|
|
97
|
+
chunks.push({
|
|
98
|
+
index: chunk.index, revision: chunk.revision,
|
|
99
|
+
plaintextHash: chunk.plaintextHash, bytes: chunk.bytes,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return { refs, chunks, totalBytes: bytes.length, contentHash: sha256(bytes) };
|
|
103
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CloudSyncError } from "./cloud-blobs.js";
|
|
3
|
+
import { receiptSchema } from "./cloud-delivery.js";
|
|
4
|
+
import { sha256 } from "./cloud-documents.js";
|
|
5
|
+
import { contentDocumentSchema, migrationReferenceSchema, migrationStatusSchema, parseContentBatch, summarizeSnapshot, } from "./cloud-wire.js";
|
|
6
|
+
const cursorSchema = z.strictObject({
|
|
7
|
+
sequence: z.number().int().nonnegative(), journalThrough: z.number().int().nonnegative(),
|
|
8
|
+
});
|
|
9
|
+
export const exportPageSchema = z.strictObject({
|
|
10
|
+
schemaVersion: z.literal(1), deviceId: z.string(), sourceDomain: z.string(),
|
|
11
|
+
generation: z.number().int().positive(), afterSequence: z.number().int().nonnegative(),
|
|
12
|
+
throughSequence: z.number().int().nonnegative(),
|
|
13
|
+
start: cursorSchema.nullable(), cursor: cursorSchema.nullable(), head: cursorSchema.nullable(),
|
|
14
|
+
hasMore: z.boolean(),
|
|
15
|
+
batches: z.array(z.strictObject({
|
|
16
|
+
batch: z.unknown().transform(value => parseContentBatch(value)),
|
|
17
|
+
receipt: receiptSchema, document: contentDocumentSchema,
|
|
18
|
+
})).max(1),
|
|
19
|
+
});
|
|
20
|
+
function migrationExport(input) {
|
|
21
|
+
const { document, ...status } = z.record(z.string(), z.unknown()).parse(input);
|
|
22
|
+
return { ...migrationStatusSchema.parse(status), document: contentDocumentSchema.nullable().parse(document) };
|
|
23
|
+
}
|
|
24
|
+
/** Exact HTTP size/hash and canonical whole-snapshot verification precede restore. */
|
|
25
|
+
export async function downloadSnapshot(http, input) {
|
|
26
|
+
const reference = migrationReferenceSchema.parse(input);
|
|
27
|
+
const request = (page) => http.request("/v1/activity/migrations/export", {
|
|
28
|
+
body: JSON.stringify({ ...reference, ...(page === undefined ? {} : { page }) }),
|
|
29
|
+
maxResponseBytes: 18 * 1024 * 1024,
|
|
30
|
+
});
|
|
31
|
+
const manifest = migrationExport(await request());
|
|
32
|
+
if (!manifest.accepted || manifest.stagedPages.length !== manifest.migration.pageCount ||
|
|
33
|
+
manifest.migration.counts.recording_clock !== 1)
|
|
34
|
+
throw new CloudSyncError("full_snapshot_required");
|
|
35
|
+
const rows = [];
|
|
36
|
+
for (const [index, page] of manifest.stagedPages.entries()) {
|
|
37
|
+
const exported = migrationExport(await request(index));
|
|
38
|
+
const document = exported.document;
|
|
39
|
+
if (!exported.accepted || document === null || page.index !== index ||
|
|
40
|
+
JSON.stringify(exported.migration) !== JSON.stringify(manifest.migration) ||
|
|
41
|
+
JSON.stringify(exported.stagedPages) !== JSON.stringify(manifest.stagedPages)) {
|
|
42
|
+
throw new CloudSyncError("invalid_remote_receipt");
|
|
43
|
+
}
|
|
44
|
+
const bytes = Buffer.from(JSON.stringify(document)), summary = await summarizeSnapshot(document.rows);
|
|
45
|
+
if (bytes.length !== page.totalBytes || sha256(bytes) !== page.contentHash ||
|
|
46
|
+
JSON.stringify(summary.counts) !== JSON.stringify(page.counts)) {
|
|
47
|
+
throw new CloudSyncError("invalid_remote_receipt");
|
|
48
|
+
}
|
|
49
|
+
rows.push(...document.rows);
|
|
50
|
+
}
|
|
51
|
+
const summary = await summarizeSnapshot(rows);
|
|
52
|
+
if (summary.snapshotHash !== manifest.migration.snapshotHash ||
|
|
53
|
+
JSON.stringify(summary.counts) !== JSON.stringify(manifest.migration.counts)) {
|
|
54
|
+
throw new CloudSyncError("invalid_remote_receipt");
|
|
55
|
+
}
|
|
56
|
+
return { manifest, rows };
|
|
57
|
+
}
|
|
58
|
+
export function verifyExportBatch(item) {
|
|
59
|
+
const { batch, receipt, document } = item;
|
|
60
|
+
if (batch.batchId !== receipt.batchId || batch.sequence !== receipt.sequence ||
|
|
61
|
+
batch.journal.through !== receipt.projectedThrough ||
|
|
62
|
+
sha256(JSON.stringify(batch)) !== receipt.payloadHash ||
|
|
63
|
+
sha256(JSON.stringify(document)) !== batch.contentHash ||
|
|
64
|
+
Buffer.byteLength(JSON.stringify(document)) !== batch.totalBytes) {
|
|
65
|
+
throw new CloudSyncError("invalid_remote_receipt");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { deploymentOriginSchema } from "./cloud-wire.js";
|
|
3
|
+
import { CloudSyncError } from "./cloud-blobs.js";
|
|
4
|
+
import { PRIVATE_SKILL_MAX_REQUEST_BYTES } from "../skills/package.js";
|
|
5
|
+
export const cloudOriginSchema = deploymentOriginSchema.refine(value => value.startsWith("https://"));
|
|
6
|
+
export class CloudRequestError extends CloudSyncError {
|
|
7
|
+
state;
|
|
8
|
+
status;
|
|
9
|
+
retryAtMs;
|
|
10
|
+
constructor(state, code, status, retryAtMs = null) {
|
|
11
|
+
super(code);
|
|
12
|
+
this.state = state;
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.retryAtMs = retryAtMs;
|
|
15
|
+
this.name = "CloudRequestError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function retryAt(header, attempt, now = Date.now(), random = Math.random) {
|
|
19
|
+
const base = Math.min(60_000, 1000 * 2 ** Math.min(Math.max(attempt, 0), 20));
|
|
20
|
+
const seconds = header !== null && /^\d+$/.test(header) ? Number(header) : null;
|
|
21
|
+
const date = header === null ? NaN : Date.parse(header);
|
|
22
|
+
const specified = seconds !== null ? now + seconds * 1000 : date;
|
|
23
|
+
const floor = Number.isFinite(specified) ? Math.max(now, specified) : now + base;
|
|
24
|
+
return floor + Math.floor(random() * base / 4);
|
|
25
|
+
}
|
|
26
|
+
function isNetworkError(error) {
|
|
27
|
+
return error instanceof TypeError || (error instanceof DOMException &&
|
|
28
|
+
(error.name === "AbortError" || error.name === "TimeoutError"));
|
|
29
|
+
}
|
|
30
|
+
async function discardBody(body, failure) {
|
|
31
|
+
try {
|
|
32
|
+
await body?.cancel();
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (!isNetworkError(error))
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
throw failure;
|
|
39
|
+
}
|
|
40
|
+
async function readJson(response, limit) {
|
|
41
|
+
if (response.body === null)
|
|
42
|
+
throw new CloudRequestError("quarantined", "invalid_response", response.status);
|
|
43
|
+
const reader = response.body.getReader(), chunks = [];
|
|
44
|
+
let size = 0;
|
|
45
|
+
try {
|
|
46
|
+
for (;;) {
|
|
47
|
+
const next = await reader.read();
|
|
48
|
+
if (next.done)
|
|
49
|
+
break;
|
|
50
|
+
size += next.value.byteLength;
|
|
51
|
+
if (size > limit) {
|
|
52
|
+
return await discardBody(reader, new CloudRequestError("quarantined", "response_too_large", response.status));
|
|
53
|
+
}
|
|
54
|
+
chunks.push(next.value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
reader.releaseLock();
|
|
59
|
+
}
|
|
60
|
+
const bytes = new Uint8Array(size);
|
|
61
|
+
let offset = 0;
|
|
62
|
+
for (const chunk of chunks) {
|
|
63
|
+
bytes.set(chunk, offset);
|
|
64
|
+
offset += chunk.byteLength;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error instanceof SyntaxError || error instanceof TypeError) {
|
|
71
|
+
throw new CloudRequestError("quarantined", "invalid_response", response.status);
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** One bounded attempt. The durable scheduler, not a sleeping request, owns retries. */
|
|
77
|
+
export class CloudHttp {
|
|
78
|
+
token;
|
|
79
|
+
fetcher;
|
|
80
|
+
timeoutMs;
|
|
81
|
+
attempt;
|
|
82
|
+
origin;
|
|
83
|
+
constructor(origin, token, fetcher = fetch, timeoutMs = 30_000, attempt = 0) {
|
|
84
|
+
this.token = token;
|
|
85
|
+
this.fetcher = fetcher;
|
|
86
|
+
this.timeoutMs = timeoutMs;
|
|
87
|
+
this.attempt = attempt;
|
|
88
|
+
this.origin = cloudOriginSchema.parse(origin);
|
|
89
|
+
z.number().int().min(1).max(30_000).parse(timeoutMs);
|
|
90
|
+
z.number().int().nonnegative().parse(attempt);
|
|
91
|
+
}
|
|
92
|
+
async request(path, options = {}) {
|
|
93
|
+
const url = new URL(path, this.origin);
|
|
94
|
+
if (url.origin !== this.origin || !path.startsWith("/v1/")) {
|
|
95
|
+
throw new CloudSyncError("invalid_remote_target");
|
|
96
|
+
}
|
|
97
|
+
const requestLimit = options.maxRequestBytes === undefined ? 256 * 1024 :
|
|
98
|
+
z.number().int().min(1).max(url.pathname.startsWith("/v1/skills/") ?
|
|
99
|
+
PRIVATE_SKILL_MAX_REQUEST_BYTES : 3 * 1024 * 1024).parse(options.maxRequestBytes);
|
|
100
|
+
if (options.body !== undefined && Buffer.byteLength(options.body) > requestLimit) {
|
|
101
|
+
throw new CloudSyncError("request_too_large");
|
|
102
|
+
}
|
|
103
|
+
let response;
|
|
104
|
+
try {
|
|
105
|
+
response = await this.fetcher(url, {
|
|
106
|
+
method: options.body === undefined ? "GET" : "POST",
|
|
107
|
+
headers: {
|
|
108
|
+
...(this.token === null ? {} : { authorization: `Bearer ${this.token}` }),
|
|
109
|
+
...(options.body === undefined ? {} : { "content-type": "application/json" }),
|
|
110
|
+
},
|
|
111
|
+
body: options.body, redirect: "manual", credentials: "omit", cache: "no-store",
|
|
112
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (isNetworkError(error)) {
|
|
117
|
+
throw new CloudRequestError("retry", "network_unavailable", 0, retryAt(null, options.attempt ?? this.attempt));
|
|
118
|
+
}
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
if (response.status >= 300 && response.status < 400) {
|
|
122
|
+
return discardBody(response.body, new CloudRequestError("quarantined", "unsafe_redirect", response.status));
|
|
123
|
+
}
|
|
124
|
+
if (response.status === 429 || response.status >= 500) {
|
|
125
|
+
return discardBody(response.body, new CloudRequestError("retry", response.status === 429 ? "rate_limited" : "remote_unavailable", response.status, retryAt(response.headers.get("retry-after"), options.attempt ?? this.attempt)));
|
|
126
|
+
}
|
|
127
|
+
let value;
|
|
128
|
+
try {
|
|
129
|
+
value = await readJson(response, options.maxResponseBytes ?? 256 * 1024);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
if (isNetworkError(error)) {
|
|
133
|
+
throw new CloudRequestError("retry", "network_unavailable", response.status, retryAt(null, options.attempt ?? this.attempt));
|
|
134
|
+
}
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
if (response.ok)
|
|
138
|
+
return value;
|
|
139
|
+
const parsed = z.object({ error: z.string().regex(/^[a-z0-9_]{1,100}$/) }).safeParse(value);
|
|
140
|
+
const code = parsed.success ? parsed.data.error : "remote_error";
|
|
141
|
+
if (response.status === 401 || response.status === 403) {
|
|
142
|
+
const state = ["consent_required", "content_not_allowed", "range_not_allowed"].includes(code)
|
|
143
|
+
? "consent-required" : "auth-required";
|
|
144
|
+
throw new CloudRequestError(state, code, response.status);
|
|
145
|
+
}
|
|
146
|
+
if (response.status === 404)
|
|
147
|
+
throw new CloudRequestError("disabled", code, response.status);
|
|
148
|
+
throw new CloudRequestError("quarantined", code, response.status);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { CloudSyncError } from "./cloud-blobs.js";
|
|
4
|
+
import { blobReferenceSchema, sha256, snapshotDocuments, spoolDocumentChunks, } from "./cloud-documents.js";
|
|
5
|
+
import { migrationBeginSchema, migrationPageSchema, parseContentBatch, summarizeSnapshot, } from "./cloud-wire.js";
|
|
6
|
+
export const migrationJobSchema = z.strictObject({
|
|
7
|
+
kind: z.literal("migration"), begin: migrationBeginSchema,
|
|
8
|
+
pages: z.array(z.strictObject({
|
|
9
|
+
page: migrationPageSchema, refs: z.array(blobReferenceSchema).min(1).max(128),
|
|
10
|
+
})).min(1).max(128),
|
|
11
|
+
excluded: z.number().int().nonnegative(),
|
|
12
|
+
});
|
|
13
|
+
export const cdcJobSchema = z.strictObject({
|
|
14
|
+
kind: z.literal("cdc"), refs: z.array(blobReferenceSchema).min(1).max(128),
|
|
15
|
+
body: z.string().max(256 * 1024), payloadHash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
16
|
+
excluded: z.number().int().nonnegative(),
|
|
17
|
+
});
|
|
18
|
+
export const cloudJobSchema = z.discriminatedUnion("kind", [migrationJobSchema, cdcJobSchema]);
|
|
19
|
+
export function liveStream(instanceId, sourceDomain) {
|
|
20
|
+
return `cloud-live:${instanceId}:${sourceDomain}`;
|
|
21
|
+
}
|
|
22
|
+
export async function stageMigrationJob(blobs, input) {
|
|
23
|
+
const reference = input.reference;
|
|
24
|
+
const documents = snapshotDocuments(input.rows);
|
|
25
|
+
const summary = await summarizeSnapshot(input.rows);
|
|
26
|
+
const begin = migrationBeginSchema.parse({
|
|
27
|
+
...reference, schemaVersion: 1, consentVersion: input.scope.consentVersion,
|
|
28
|
+
projectId: input.scope.projectId, rootId: input.scope.rootId,
|
|
29
|
+
range: { fromMs: input.scope.fromMs, toMs: input.scope.toMs },
|
|
30
|
+
backfill: input.scope.backfill, pageCount: documents.length,
|
|
31
|
+
counts: summary.counts, snapshotHash: summary.snapshotHash,
|
|
32
|
+
});
|
|
33
|
+
const pages = [];
|
|
34
|
+
for (const [index, document] of documents.entries()) {
|
|
35
|
+
const batchId = `${reference.snapshotId}:page:${index}`;
|
|
36
|
+
const chunks = spoolDocumentChunks(blobs, document, {
|
|
37
|
+
schemaVersion: 2, batchId, deviceId: reference.deviceId,
|
|
38
|
+
sourceDomain: reference.sourceDomain, generation: reference.generation,
|
|
39
|
+
consentVersion: begin.consentVersion, projectId: begin.projectId, rootId: begin.rootId,
|
|
40
|
+
range: begin.range, backfill: begin.backfill,
|
|
41
|
+
}, reference.cut);
|
|
42
|
+
pages.push({
|
|
43
|
+
page: migrationPageSchema.parse({
|
|
44
|
+
deviceId: reference.deviceId, sourceDomain: reference.sourceDomain,
|
|
45
|
+
generation: reference.generation, snapshotId: reference.snapshotId,
|
|
46
|
+
index, batchId, chunks: chunks.chunks, contentHash: chunks.contentHash,
|
|
47
|
+
totalBytes: chunks.totalBytes, counts: (await summarizeSnapshot(document.rows)).counts,
|
|
48
|
+
}),
|
|
49
|
+
refs: chunks.refs,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return blobs.enqueue({
|
|
53
|
+
streamId: input.streamId, batchId: reference.snapshotId,
|
|
54
|
+
sourceDomain: reference.sourceDomain,
|
|
55
|
+
consent: input.consent, scope: input.scope,
|
|
56
|
+
journal: { from: 0, through: reference.cut },
|
|
57
|
+
blobHashes: pages.flatMap(page => page.refs.map(ref => ref.hash)),
|
|
58
|
+
build: () => migrationJobSchema.parse({
|
|
59
|
+
kind: "migration", begin, pages, excluded: input.excluded,
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export function stageCdcJob(blobs, input) {
|
|
64
|
+
const batchId = randomUUID();
|
|
65
|
+
const common = {
|
|
66
|
+
schemaVersion: 2, batchId, deviceId: input.deviceId,
|
|
67
|
+
sourceDomain: input.sourceDomain, generation: input.generation,
|
|
68
|
+
consentVersion: input.scope.consentVersion, projectId: input.scope.projectId,
|
|
69
|
+
rootId: input.scope.rootId, range: { fromMs: input.scope.fromMs, toMs: input.scope.toMs },
|
|
70
|
+
backfill: input.scope.backfill,
|
|
71
|
+
};
|
|
72
|
+
const chunks = spoolDocumentChunks(blobs, { schemaVersion: 2, rows: input.rows }, common, input.cut);
|
|
73
|
+
return blobs.enqueue({
|
|
74
|
+
streamId: input.streamId, batchId, consent: input.consent, scope: input.scope,
|
|
75
|
+
sourceDomain: input.sourceDomain, blobHashes: chunks.refs.map(ref => ref.hash),
|
|
76
|
+
journal: { from: input.after, through: input.cut },
|
|
77
|
+
build: sequence => {
|
|
78
|
+
const body = JSON.stringify(parseContentBatch({
|
|
79
|
+
...common, sequence, journal: { from: input.after, through: input.cut },
|
|
80
|
+
metadataMutations: [], chunks: chunks.chunks,
|
|
81
|
+
totalBytes: chunks.totalBytes, contentHash: chunks.contentHash,
|
|
82
|
+
}));
|
|
83
|
+
return cdcJobSchema.parse({
|
|
84
|
+
kind: "cdc", refs: chunks.refs, body, payloadHash: sha256(body), excluded: input.excluded,
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
export function requireJob(value) {
|
|
90
|
+
const result = cloudJobSchema.safeParse(JSON.parse(value));
|
|
91
|
+
if (!result.success)
|
|
92
|
+
throw new CloudSyncError("invalid_spool_job");
|
|
93
|
+
return result.data;
|
|
94
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { hostname } from "node:os";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { CloudSyncError } from "./cloud-blobs.js";
|
|
7
|
+
import { CloudHttp, CloudRequestError } from "./cloud-http.js";
|
|
8
|
+
import { atomicCloudJson, cloudHome, connectCloud, readConnection, } from "./cloud-connection.js";
|
|
9
|
+
/** The CLI asks for exactly these scopes; the approval page shows them for comparison. */
|
|
10
|
+
export const PENDING_CONNECT_SCOPES = ["activity:read", "activity:ingest"];
|
|
11
|
+
/** Private-skill read needs only the read scope; publishing adds the write scope. */
|
|
12
|
+
export const PENDING_SKILLS_READ_SCOPES = ["skills:read"];
|
|
13
|
+
export const PENDING_SKILLS_WRITE_SCOPES = ["skills:read", "skills:write"];
|
|
14
|
+
const issueSchema = z.strictObject({
|
|
15
|
+
userCode: z.string().min(8).max(16), pollToken: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
16
|
+
expiresIn: z.number().int().positive(), pollInterval: z.number().int().positive(),
|
|
17
|
+
});
|
|
18
|
+
const pollPendingSchema = z.strictObject({
|
|
19
|
+
state: z.literal("pending"), retryAfter: z.number().int().positive().optional(),
|
|
20
|
+
});
|
|
21
|
+
const pollIssuedSchema = z.strictObject({
|
|
22
|
+
grant: z.string().min(32).max(128), deviceId: z.string().min(1), expiresAt: z.number().int().positive(),
|
|
23
|
+
});
|
|
24
|
+
export function pendingApproveUrl(origin, userCode) {
|
|
25
|
+
return `${origin}/connections/?code=${encodeURIComponent(userCode)}`;
|
|
26
|
+
}
|
|
27
|
+
export function defaultDeviceLabel() {
|
|
28
|
+
const name = hostname().trim();
|
|
29
|
+
return (name === "" ? "skillar-cli" : name).slice(0, 120);
|
|
30
|
+
}
|
|
31
|
+
export async function createPendingConnect(origin, input, fetcher = fetch) {
|
|
32
|
+
const http = new CloudHttp(origin, null, fetcher);
|
|
33
|
+
return issueSchema.parse(await http.request("/v1/devices/pending", {
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
deviceLabel: input.deviceLabel, scopes: [...input.scopes],
|
|
36
|
+
...(input.deviceId === undefined ? {} : { deviceId: input.deviceId }),
|
|
37
|
+
}),
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
41
|
+
/**
|
|
42
|
+
* Polls until the browser approves or the request expires. The single-use
|
|
43
|
+
* grant comes back exactly once; the caller redeems it through the existing
|
|
44
|
+
* /v1/devices/exchange boundary (connectCloud).
|
|
45
|
+
*/
|
|
46
|
+
export async function pollPendingConnect(origin, issue, options = {}) {
|
|
47
|
+
const http = new CloudHttp(origin, null, options.fetcher ?? fetch);
|
|
48
|
+
const wait = options.wait ?? sleep, now = options.now ?? Date.now;
|
|
49
|
+
const deadline = now() + issue.expiresIn * 1000;
|
|
50
|
+
for (;;) {
|
|
51
|
+
if (now() >= deadline)
|
|
52
|
+
throw new CloudSyncError("pending_expired");
|
|
53
|
+
try {
|
|
54
|
+
const value = await http.request("/v1/devices/pending/poll", {
|
|
55
|
+
body: JSON.stringify({ pollToken: issue.pollToken }),
|
|
56
|
+
});
|
|
57
|
+
const pending = pollPendingSchema.safeParse(value);
|
|
58
|
+
if (pending.success) {
|
|
59
|
+
await wait((pending.data.retryAfter ?? issue.pollInterval) * 1000);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
return pollIssuedSchema.parse(value);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error instanceof CloudRequestError && error.code === "rate_limited") {
|
|
66
|
+
await wait(Math.max(issue.pollInterval * 1000, (error.retryAtMs ?? 0) - now()));
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (error instanceof CloudRequestError && error.state === "disabled") {
|
|
70
|
+
throw new CloudSyncError("pending_expired");
|
|
71
|
+
}
|
|
72
|
+
if (error instanceof CloudRequestError && error.status === 410) {
|
|
73
|
+
throw new CloudSyncError("pending_consumed");
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function openBrowser(url, env) {
|
|
80
|
+
if (env.SKILLAR_NO_CLI ?? env.GISOOL_NO_CLI)
|
|
81
|
+
return Promise.resolve(false);
|
|
82
|
+
const opener = process.platform === "darwin" ? "open" : "xdg-open";
|
|
83
|
+
return new Promise(resolve => {
|
|
84
|
+
const child = spawn(opener, [url], { env, stdio: "ignore", detached: true });
|
|
85
|
+
child.once("error", () => resolve(false));
|
|
86
|
+
child.once("spawn", () => { child.unref(); resolve(true); });
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const noticeSchema = z.strictObject({ deviceId: z.string().min(1), noticedAtMs: z.number() });
|
|
90
|
+
export function markConsentNoticed(home, deviceId) {
|
|
91
|
+
atomicCloudJson(home, "consent-notice.json", { deviceId, noticedAtMs: Date.now() });
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Once per device: the URL where upload consent is managed. Returns null when
|
|
95
|
+
* this device already got the notice; a reconnect (new device id) resets it.
|
|
96
|
+
*/
|
|
97
|
+
export function consentReviewNotice(home, connection) {
|
|
98
|
+
const path = join(cloudHome(home), "consent-notice.json");
|
|
99
|
+
if (existsSync(path)) {
|
|
100
|
+
const saved = noticeSchema.safeParse(JSON.parse(readFileSync(path, "utf8")));
|
|
101
|
+
if (saved.success && saved.data.deviceId === connection.deviceId)
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
markConsentNoticed(home, connection.deviceId);
|
|
105
|
+
return `${connection.origin}/connections/`;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Browser-approval connect: pending code -> approval page -> single-use grant
|
|
109
|
+
* -> existing exchange. --upload is terminal guidance only; consent itself is
|
|
110
|
+
* always off by default and can only be switched on in the browser.
|
|
111
|
+
*/
|
|
112
|
+
export async function connectCloudDeviceFlow(home, options) {
|
|
113
|
+
if (options.upgradeDeviceId === undefined && readConnection(home) !== null) {
|
|
114
|
+
throw new CloudSyncError("already_connected");
|
|
115
|
+
}
|
|
116
|
+
const issue = await createPendingConnect(options.origin, {
|
|
117
|
+
deviceLabel: options.deviceLabel ?? defaultDeviceLabel(),
|
|
118
|
+
scopes: options.scopes ?? PENDING_CONNECT_SCOPES,
|
|
119
|
+
...(options.upgradeDeviceId === undefined ? {} : { deviceId: options.upgradeDeviceId }),
|
|
120
|
+
}, options.fetcher);
|
|
121
|
+
const url = pendingApproveUrl(options.origin, issue.userCode);
|
|
122
|
+
const io = options.io;
|
|
123
|
+
io?.out(`연결 코드: ${issue.userCode}\n`);
|
|
124
|
+
io?.out(`브라우저에서 ${Math.max(1, Math.floor(issue.expiresIn / 60))}분 안에 승인하세요: ${url}\n`);
|
|
125
|
+
if (options.uploadIntent === true) {
|
|
126
|
+
io?.out("--upload: 브라우저 화면에서 업로드 동의를 직접 선택해야 업로드가 켜집니다(기본은 로컬 전용).\n");
|
|
127
|
+
}
|
|
128
|
+
if (options.open !== false) {
|
|
129
|
+
const opened = await openBrowser(url, options.env ?? process.env);
|
|
130
|
+
if (!opened)
|
|
131
|
+
io?.out("브라우저를 열지 못했습니다. 위 주소를 직접 여세요.\n");
|
|
132
|
+
}
|
|
133
|
+
io?.out("승인을 기다리는 중…\n");
|
|
134
|
+
const issued = await pollPendingConnect(options.origin, issue, {
|
|
135
|
+
fetcher: options.fetcher, wait: options.wait,
|
|
136
|
+
});
|
|
137
|
+
const connected = await connectCloud(home, {
|
|
138
|
+
origin: options.origin, grant: issued.grant,
|
|
139
|
+
...(options.upgradeDeviceId === undefined ? {} : { replaceDeviceId: options.upgradeDeviceId }),
|
|
140
|
+
}, options.fetcher);
|
|
141
|
+
markConsentNoticed(home, connected.deviceId);
|
|
142
|
+
return connected;
|
|
143
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, renameSync, unlinkSync, } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { backup, DatabaseSync } from "node:sqlite";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { openDb } from "../store/db.js";
|
|
7
|
+
import { CloudSyncError } from "./cloud-blobs.js";
|
|
8
|
+
import { atomicCloudJson, cloudHome, readConnection, } from "./cloud-connection.js";
|
|
9
|
+
import { journalHead } from "./journal.js";
|
|
10
|
+
export const preparedSchema = z.strictObject({
|
|
11
|
+
version: z.literal(1), snapshotId: z.string().uuid(), instanceId: z.string().uuid(),
|
|
12
|
+
deviceId: z.string().min(1), generation: z.number().int().positive(),
|
|
13
|
+
sourceDomain: z.string().min(1), cut: z.number().int().nonnegative(),
|
|
14
|
+
capturedAtMs: z.number().int(), expiresAtMs: z.number().int(),
|
|
15
|
+
});
|
|
16
|
+
export function preparedPath(home, snapshotId) {
|
|
17
|
+
return join(cloudHome(home), "prepared", `${z.string().uuid().parse(snapshotId)}.sqlite`);
|
|
18
|
+
}
|
|
19
|
+
/** A new device binding forks future recording, not the original row vectors. */
|
|
20
|
+
export function bindSource(path, connection) {
|
|
21
|
+
const db = openDb(path);
|
|
22
|
+
try {
|
|
23
|
+
const marker = db.prepare("SELECT value FROM meta WHERE key='cloud.binding'").get();
|
|
24
|
+
if (marker?.["value"] === connection.instanceId)
|
|
25
|
+
return;
|
|
26
|
+
if (db.prepare("SELECT 1 FROM sync_outbox LIMIT 1").get() !== undefined) {
|
|
27
|
+
throw new CloudSyncError("pending_identity_change");
|
|
28
|
+
}
|
|
29
|
+
db.exec("BEGIN IMMEDIATE");
|
|
30
|
+
try {
|
|
31
|
+
// Fork identity without moving the durable clock backwards. Existing row
|
|
32
|
+
// vectors retain their original domains; future marks use this new domain.
|
|
33
|
+
db.prepare("UPDATE recording_clock SET domain=? WHERE singleton=1").run(randomUUID());
|
|
34
|
+
db.prepare("UPDATE sync_identity SET source_domain=? WHERE singleton=1").run(randomUUID());
|
|
35
|
+
db.prepare(`INSERT INTO meta(key,value) VALUES('cloud.binding',?)
|
|
36
|
+
ON CONFLICT(key) DO UPDATE SET value=excluded.value`).run(connection.instanceId);
|
|
37
|
+
db.exec("COMMIT");
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
db.exec("ROLLBACK");
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
db.close();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A LOCAL SQLite backup, not a cloud payload or outbox. Prepare exposes only its
|
|
50
|
+
* cut/lineage/id so a later browser backfill grant can bind exactly this snapshot.
|
|
51
|
+
* No request serialization, token transmission or raw upload happens here.
|
|
52
|
+
*/
|
|
53
|
+
export async function prepareCloudSnapshot(home, sourcePath, backupDatabase = backup) {
|
|
54
|
+
const connection = readConnection(home);
|
|
55
|
+
if (connection === null)
|
|
56
|
+
throw new CloudSyncError("not_connected");
|
|
57
|
+
bindSource(sourcePath, connection);
|
|
58
|
+
const snapshotId = randomUUID(), target = preparedPath(home, snapshotId);
|
|
59
|
+
mkdirSync(join(cloudHome(home), "prepared"), { recursive: true, mode: 0o700 });
|
|
60
|
+
const temporary = `${target}.tmp`;
|
|
61
|
+
closeSync(openSync(temporary, "wx", 0o600));
|
|
62
|
+
const source = new DatabaseSync(sourcePath, { readOnly: true });
|
|
63
|
+
try {
|
|
64
|
+
await backupDatabase(source, temporary);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (existsSync(temporary))
|
|
68
|
+
unlinkSync(temporary);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
source.close();
|
|
73
|
+
}
|
|
74
|
+
renameSync(temporary, target);
|
|
75
|
+
for (const path of [target, join(cloudHome(home), "prepared")]) {
|
|
76
|
+
const fd = openSync(path, "r");
|
|
77
|
+
try {
|
|
78
|
+
fsyncSync(fd);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
closeSync(fd);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const frozen = new DatabaseSync(target, { readOnly: true });
|
|
85
|
+
let head;
|
|
86
|
+
try {
|
|
87
|
+
head = journalHead(frozen);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
frozen.close();
|
|
91
|
+
}
|
|
92
|
+
const now = Date.now();
|
|
93
|
+
const prepared = preparedSchema.parse({
|
|
94
|
+
version: 1, snapshotId, instanceId: connection.instanceId,
|
|
95
|
+
deviceId: connection.deviceId, generation: connection.generation,
|
|
96
|
+
sourceDomain: head.sourceDomain, cut: head.cut, capturedAtMs: now,
|
|
97
|
+
expiresAtMs: now + 86_400_000,
|
|
98
|
+
});
|
|
99
|
+
atomicCloudJson(home, "prepared.json", prepared);
|
|
100
|
+
return prepared;
|
|
101
|
+
}
|