dp-worker 0.1.1 → 0.1.3
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/dist/agent/agent.d.ts +6 -13
- package/dist/agent/agent.js +9 -19
- package/dist/agent/agent.js.map +1 -1
- package/dist/browser/chrome-process.d.ts +3 -0
- package/dist/browser/chrome-process.js +174 -25
- package/dist/browser/chrome-process.js.map +1 -1
- package/dist/browser/manager.d.ts +4 -4
- package/dist/browser/manager.js +94 -44
- package/dist/browser/manager.js.map +1 -1
- package/dist/center/session-sync.d.ts +16 -77
- package/dist/center/session-sync.js +62 -302
- package/dist/center/session-sync.js.map +1 -1
- package/dist/chrome-extension/omni-flow/background.js +561 -0
- package/dist/chrome-extension/omni-flow/content.js +29 -0
- package/dist/chrome-extension/omni-flow/icon.png +0 -0
- package/dist/chrome-extension/omni-flow/inject.js +173 -0
- package/dist/chrome-extension/omni-flow/manifest.json +44 -0
- package/dist/chrome-extension/omni-flow/popup.css +819 -0
- package/dist/chrome-extension/omni-flow/popup.html +284 -0
- package/dist/chrome-extension/omni-flow/popup.js +1021 -0
- package/dist/chrome-extension/omni-flow/usage_guide.md +139 -0
- package/dist/index.js +15 -45
- package/dist/index.js.map +1 -1
- package/node_modules/dp-shared/dist/domain.d.ts +4 -4
- package/node_modules/dp-shared/dist/domain.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/domain.js +4 -4
- package/node_modules/dp-shared/dist/domain.js.map +1 -1
- package/node_modules/dp-shared/dist/identities.d.ts +22 -0
- package/node_modules/dp-shared/dist/identities.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/identities.js +3 -0
- package/node_modules/dp-shared/dist/identities.js.map +1 -1
- package/node_modules/dp-shared/dist/index.d.ts +1 -0
- package/node_modules/dp-shared/dist/index.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/index.js +1 -0
- package/node_modules/dp-shared/dist/index.js.map +1 -1
- package/node_modules/dp-shared/dist/omni-flow-session.d.ts +85 -0
- package/node_modules/dp-shared/dist/omni-flow-session.d.ts.map +1 -0
- package/node_modules/dp-shared/dist/omni-flow-session.js +59 -0
- package/node_modules/dp-shared/dist/omni-flow-session.js.map +1 -0
- package/node_modules/dp-shared/dist/rest-contracts.d.ts +12 -1
- package/node_modules/dp-shared/dist/rest-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/rest-contracts.js +5 -3
- package/node_modules/dp-shared/dist/rest-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/ws-protocol.d.ts +4 -4
- package/node_modules/dp-shared/src/admin-broadcast.ts +38 -0
- package/node_modules/dp-shared/src/audit-contracts.ts +33 -0
- package/node_modules/dp-shared/src/configs-contracts.ts +206 -0
- package/node_modules/dp-shared/src/db-rows.ts +280 -0
- package/node_modules/dp-shared/src/deploy-contracts.ts +38 -0
- package/node_modules/dp-shared/src/domain.ts +124 -0
- package/node_modules/dp-shared/src/identities.ts +36 -0
- package/node_modules/dp-shared/src/index.ts +25 -0
- package/node_modules/dp-shared/src/omni-flow-session.ts +80 -0
- package/node_modules/dp-shared/src/rest-contracts.ts +409 -0
- package/node_modules/dp-shared/src/task-history-contracts.ts +115 -0
- package/node_modules/dp-shared/src/worker-detail-contracts.ts +230 -0
- package/node_modules/dp-shared/src/ws-protocol.ts +435 -0
- package/package.json +2 -4
|
@@ -1,230 +1,24 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import
|
|
4
|
+
import { OmniFlowSessionExportSchema } from "dp-shared";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* (for center upload), and apply a center-provided zip back onto the local browser
|
|
8
|
-
* profile.
|
|
6
|
+
* Center session sync.
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* - Default/Local Storage/leveldb/*
|
|
16
|
-
* - Default/IndexedDB/*
|
|
17
|
-
* - Default/Preferences
|
|
18
|
-
* - Default/Service Worker/Database (SW registration index)
|
|
19
|
-
* - Local State (sibling of Default/)
|
|
20
|
-
*
|
|
21
|
-
* Tightened drops: Cache, Code Cache, GPUCache, CacheStorage, ShaderCache,
|
|
22
|
-
* GrShaderCache, blob_storage, Sessions (open-tab restore state), Session
|
|
23
|
-
* Storage (per-tab volatile), File System (sandbox), Service Worker/
|
|
24
|
-
* {CacheStorage,ScriptCache}, all top-level cache dirs, lock/sentinel files.
|
|
25
|
-
*
|
|
26
|
-
* This module only handles the filesystem side. Network IO (fetching the
|
|
27
|
-
* R2 GET URL) and zip framing live behind injectable deps so the swap flow
|
|
28
|
-
* can be unit-tested without a real browser or live R2.
|
|
8
|
+
* dp-center stores the OmniFlow extension JSON export. dp-worker only pulls
|
|
9
|
+
* that artifact into the local workspace when the center content hash changes;
|
|
10
|
+
* Chrome startup then copies it into the bundled OmniFlow extension, and the
|
|
11
|
+
* extension imports proxy/timezone/cookies before browser launch is considered
|
|
12
|
+
* complete.
|
|
29
13
|
*/
|
|
30
14
|
const SESSION_META_FILENAME = ".session-meta.json";
|
|
31
|
-
|
|
32
|
-
* Directories under `<browser-data>/` that are pure caches / runtime state.
|
|
33
|
-
* Path entries are slash-joined posix-style and matched against entries
|
|
34
|
-
* relative to the browser-data root.
|
|
35
|
-
*/
|
|
36
|
-
const EXCLUDED_DIR_PREFIXES = [
|
|
37
|
-
// Profile-local caches.
|
|
38
|
-
"Default/Cache",
|
|
39
|
-
"Default/Code Cache",
|
|
40
|
-
"Default/GPUCache",
|
|
41
|
-
"Default/CacheStorage",
|
|
42
|
-
// The Service Worker DIR is partially kept: "Default/Service Worker/Database"
|
|
43
|
-
// holds the SW registration index and must travel with a logged-in session,
|
|
44
|
-
// but "Default/Service Worker/CacheStorage" and "Default/Service Worker/ScriptCache"
|
|
45
|
-
// are caches. Kept-vs-dropped is enforced via SERVICE_WORKER_KEEP_PREFIXES.
|
|
46
|
-
"Default/Service Worker/CacheStorage",
|
|
47
|
-
"Default/Service Worker/ScriptCache",
|
|
48
|
-
"Default/ShaderCache",
|
|
49
|
-
"Default/GrShaderCache",
|
|
50
|
-
"Default/DawnCache",
|
|
51
|
-
"Default/DawnGraphiteCache",
|
|
52
|
-
"Default/DawnWebGPUCache",
|
|
53
|
-
"Default/blob_storage",
|
|
54
|
-
// "Sessions" holds restore-state for currently-open tabs. Volatile.
|
|
55
|
-
"Default/Sessions",
|
|
56
|
-
"Default/Session Storage",
|
|
57
|
-
"Default/File System",
|
|
58
|
-
// Download metadata + optimization-guide model files: regenerable, can be 10s of MB.
|
|
59
|
-
"Default/Download Service",
|
|
60
|
-
"Default/optimization_guide_hint_cache_store",
|
|
61
|
-
"Default/optimization_guide_model_store",
|
|
62
|
-
"Default/optimization_guide_prediction_model_downloads",
|
|
63
|
-
// Top-level caches/runtime.
|
|
64
|
-
"ShaderCache",
|
|
65
|
-
"GrShaderCache",
|
|
66
|
-
"GPUCache",
|
|
67
|
-
"GraphiteDawnCache",
|
|
68
|
-
"Crashpad",
|
|
69
|
-
"BrowserMetrics",
|
|
70
|
-
"component_crx_cache",
|
|
71
|
-
"extensions_crx_cache",
|
|
72
|
-
// Lock files / sentinels.
|
|
73
|
-
"Singleton",
|
|
74
|
-
];
|
|
75
|
-
const EXCLUDED_DIR_PREFIXES_NORMALIZED = EXCLUDED_DIR_PREFIXES.map((p) => p.replace(/\\/g, "/"));
|
|
76
|
-
/** Sub-paths under Default/Service Worker that we DO keep. Whitelist beats blacklist. */
|
|
77
|
-
const SERVICE_WORKER_KEEP_PREFIXES = [
|
|
78
|
-
"Default/Service Worker/Database",
|
|
79
|
-
];
|
|
80
|
-
const EXCLUDED_FILENAME_PATTERNS = [
|
|
81
|
-
/\.tmp$/i,
|
|
82
|
-
/\.bak$/i,
|
|
83
|
-
/-journal$/i,
|
|
84
|
-
/^LOCK$/,
|
|
85
|
-
/^LOG\.old$/,
|
|
86
|
-
/^chrome_debug\.log$/,
|
|
87
|
-
/^SingletonLock$/,
|
|
88
|
-
/^SingletonCookie$/,
|
|
89
|
-
/^SingletonSocket$/,
|
|
90
|
-
];
|
|
91
|
-
/**
|
|
92
|
-
* Walks a Chrome user-data-dir and returns the inclusion list per §worker-session.
|
|
93
|
-
* Symlinks are followed; deep dirs are walked depth-first. Returns sorted
|
|
94
|
-
* absolute paths so callers building a zip get deterministic ordering for
|
|
95
|
-
* stable content hashes.
|
|
96
|
-
*/
|
|
97
|
-
export async function buildSessionFileList(browserDataDir) {
|
|
98
|
-
const root = path.resolve(browserDataDir);
|
|
99
|
-
const include = [];
|
|
100
|
-
const excluded = [];
|
|
101
|
-
const walk = (absDir) => {
|
|
102
|
-
let entries;
|
|
103
|
-
try {
|
|
104
|
-
entries = fs.readdirSync(absDir, { withFileTypes: true });
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
for (const ent of entries) {
|
|
110
|
-
const absPath = path.join(absDir, ent.name);
|
|
111
|
-
const rel = path.relative(root, absPath).split(path.sep).join("/");
|
|
112
|
-
if (ent.isDirectory()) {
|
|
113
|
-
if (isExcludedDir(rel)) {
|
|
114
|
-
// Don't even descend; everything under here is excluded.
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
walk(absPath);
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (!ent.isFile())
|
|
121
|
-
continue;
|
|
122
|
-
if (isExcludedFile(rel, ent.name)) {
|
|
123
|
-
excluded.push(absPath);
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
include.push(absPath);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
walk(root);
|
|
130
|
-
include.sort();
|
|
131
|
-
excluded.sort();
|
|
132
|
-
return { include, excluded };
|
|
133
|
-
}
|
|
134
|
-
function isExcludedDir(relDir) {
|
|
135
|
-
// The Service Worker whitelist trumps the Service Worker blacklist entry.
|
|
136
|
-
for (const keep of SERVICE_WORKER_KEEP_PREFIXES) {
|
|
137
|
-
if (relDir === keep || relDir.startsWith(keep + "/"))
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
for (const ex of EXCLUDED_DIR_PREFIXES_NORMALIZED) {
|
|
141
|
-
if (relDir === ex || relDir.startsWith(ex + "/"))
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
/* ============================================================================
|
|
147
|
-
* Packager: turn a browser-data dir into a deterministic zip buffer.
|
|
148
|
-
*
|
|
149
|
-
* Used by the `dipclaw package-session` CLI subcommand and (future) the
|
|
150
|
-
* worker-side push path. The buffer is the canonical thing whose sha256 becomes
|
|
151
|
-
* `chrome_sessions.content_hash` — same dir contents must produce the same
|
|
152
|
-
* hash so the content-addressed R2 layout (`sessions/<worker>/<hash>.zip`) is
|
|
153
|
-
* idempotent.
|
|
154
|
-
*
|
|
155
|
-
* Determinism comes from:
|
|
156
|
-
* - buildSessionFileList sorts include paths
|
|
157
|
-
* - AdmZip adds entries in insertion order (we feed them sorted)
|
|
158
|
-
* - entry mtimes are pinned to a fixed epoch so two packagings of the
|
|
159
|
-
* same bytes hash identically regardless of filesystem timestamps
|
|
160
|
-
* ============================================================================ */
|
|
161
|
-
/**
|
|
162
|
-
* Fixed timestamp baked into every zip entry so the resulting buffer is
|
|
163
|
-
* byte-identical for the same file contents across hosts/runs. We pick
|
|
164
|
-
* 2020-01-01T00:00:00Z (well after DOS time epoch) so the legacy zip date
|
|
165
|
-
* fields encode cleanly.
|
|
166
|
-
*/
|
|
167
|
-
const DETERMINISTIC_ENTRY_DATE = new Date(Date.UTC(2020, 0, 1, 0, 0, 0));
|
|
168
|
-
/**
|
|
169
|
-
* Build the session zip for `<workspace>/browser-data`. Returns the zip
|
|
170
|
-
* buffer plus its sha256-hex digest and byte length. Caller is expected to
|
|
171
|
-
* have stopped Chrome before reading the profile (open Cookies/IndexedDB
|
|
172
|
-
* files give torn reads on macOS/Windows).
|
|
173
|
-
*/
|
|
174
|
-
export async function packageSessionToZip(workspace) {
|
|
175
|
-
const browserData = path.join(workspace, "browser-data");
|
|
176
|
-
const { include } = await buildSessionFileList(browserData);
|
|
177
|
-
const root = path.resolve(browserData);
|
|
178
|
-
const zip = new AdmZip();
|
|
179
|
-
for (const absPath of include) {
|
|
180
|
-
const rel = path.relative(root, absPath).split(path.sep).join("/");
|
|
181
|
-
let data;
|
|
182
|
-
try {
|
|
183
|
-
data = fs.readFileSync(absPath);
|
|
184
|
-
}
|
|
185
|
-
catch {
|
|
186
|
-
// File vanished between listing and read (e.g. Chrome rotating logs);
|
|
187
|
-
// skip rather than abort. Determinism still holds because the include
|
|
188
|
-
// list was sorted before this loop.
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
const entry = zip.addFile(rel, data);
|
|
192
|
-
// Pin entry metadata for deterministic byte output.
|
|
193
|
-
entry.header.time = DETERMINISTIC_ENTRY_DATE;
|
|
194
|
-
}
|
|
195
|
-
const nodeBuf = zip.toBuffer();
|
|
196
|
-
const buf = new Uint8Array(nodeBuf.buffer, nodeBuf.byteOffset, nodeBuf.byteLength);
|
|
197
|
-
const content_hash = createHash("sha256").update(nodeBuf).digest("hex");
|
|
198
|
-
return { buf, content_hash, size_bytes: buf.byteLength };
|
|
199
|
-
}
|
|
200
|
-
function isExcludedFile(relPath, basename) {
|
|
201
|
-
// First: a file inside an excluded dir is itself excluded (we usually
|
|
202
|
-
// skip these earlier by not descending, but this is the safety net for
|
|
203
|
-
// files reached via symlink loops or callers passing prefiltered dirs).
|
|
204
|
-
// Skip the SW whitelist check — files under "Database" are kept by walk()
|
|
205
|
-
// already because isExcludedDir lets them through.
|
|
206
|
-
for (const ex of EXCLUDED_DIR_PREFIXES_NORMALIZED) {
|
|
207
|
-
if (relPath.startsWith(ex + "/")) {
|
|
208
|
-
let onWhitelist = false;
|
|
209
|
-
for (const keep of SERVICE_WORKER_KEEP_PREFIXES) {
|
|
210
|
-
if (relPath.startsWith(keep + "/")) {
|
|
211
|
-
onWhitelist = true;
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (!onWhitelist)
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
for (const re of EXCLUDED_FILENAME_PATTERNS) {
|
|
220
|
-
if (re.test(basename))
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
15
|
+
const OMNI_FLOW_SESSION_FILENAME = "omni-flow-session.json";
|
|
225
16
|
export function sessionMetaPath(workspace) {
|
|
226
17
|
return path.join(workspace, SESSION_META_FILENAME);
|
|
227
18
|
}
|
|
19
|
+
export function omniFlowSessionPath(workspace) {
|
|
20
|
+
return path.join(workspace, ".dipclaw", OMNI_FLOW_SESSION_FILENAME);
|
|
21
|
+
}
|
|
228
22
|
export async function readLocalSessionMeta(workspace) {
|
|
229
23
|
const p = sessionMetaPath(workspace);
|
|
230
24
|
if (!fs.existsSync(p))
|
|
@@ -247,99 +41,65 @@ export async function writeLocalSessionMeta(workspace, meta) {
|
|
|
247
41
|
const p = sessionMetaPath(workspace);
|
|
248
42
|
fs.writeFileSync(p, JSON.stringify(meta, null, 2) + "\n", "utf-8");
|
|
249
43
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
* browser-data, or leave the local copy alone. Returns null when a pull
|
|
253
|
-
* should proceed, or a short reason string when it should be skipped.
|
|
254
|
-
*
|
|
255
|
-
* Skip conditions:
|
|
256
|
-
* - "hash-match": local hash equals server hash — no work to do
|
|
257
|
-
* - "local-newer": local has changed since the server's copy was uploaded
|
|
258
|
-
* (probably the worker logged into a new account during a task; that login
|
|
259
|
-
* state would be lost if we overwrote it with the older server copy)
|
|
260
|
-
*/
|
|
261
|
-
export async function shouldSkipSessionSwap(workspace, blob) {
|
|
44
|
+
export async function syncOmniFlowSessionBlob(workspace, blob, depsOverride) {
|
|
45
|
+
const dest = omniFlowSessionPath(workspace);
|
|
262
46
|
const local = await readLocalSessionMeta(workspace);
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
const DEFAULT_DEPS = {
|
|
276
|
-
fetchUrlToBuffer: async (url) => {
|
|
277
|
-
const res = await fetch(url);
|
|
278
|
-
if (!res.ok) {
|
|
279
|
-
throw new Error(`Session blob fetch failed: ${res.status} ${res.statusText}`);
|
|
47
|
+
if (local?.content_hash === blob.content_hash && fs.existsSync(dest)) {
|
|
48
|
+
const localHash = createHash("sha256")
|
|
49
|
+
.update(fs.readFileSync(dest))
|
|
50
|
+
.digest("hex");
|
|
51
|
+
if (localHash === blob.content_hash) {
|
|
52
|
+
return {
|
|
53
|
+
status: "skipped",
|
|
54
|
+
reason: "hash-match",
|
|
55
|
+
content_hash: blob.content_hash,
|
|
56
|
+
path: dest,
|
|
57
|
+
};
|
|
280
58
|
}
|
|
281
|
-
return new Uint8Array(await res.arrayBuffer());
|
|
282
|
-
},
|
|
283
|
-
extractZipToDir: extractZipBufferToDir,
|
|
284
|
-
};
|
|
285
|
-
/**
|
|
286
|
-
* Extract a zip buffer onto a destination directory. Designed for the
|
|
287
|
-
* Chrome user-data-dir overwrite case:
|
|
288
|
-
*
|
|
289
|
-
* - **No purge first**: we don't wipe destDir. Files in the zip
|
|
290
|
-
* overwrite their counterparts; files NOT in the zip stay put. This
|
|
291
|
-
* keeps any worker-local state that wasn't packaged (logs, transient
|
|
292
|
-
* dirs the §C exclude list dropped) untouched.
|
|
293
|
-
* - **Path traversal guard**: every entry's resolved absolute path
|
|
294
|
-
* must stay inside `destDir`. A malicious "../../etc/passwd" entry
|
|
295
|
-
* gets rejected loudly instead of silently writing outside.
|
|
296
|
-
* - **Mkdir parents**: zip entries don't always include their parent
|
|
297
|
-
* directories explicitly; we resolve each file's dir and recursive-
|
|
298
|
-
* mkdir before writing.
|
|
299
|
-
*
|
|
300
|
-
* Exposed as a named export so callers / tests can plug it directly
|
|
301
|
-
* into ApplySessionDeps.extractZipToDir.
|
|
302
|
-
*/
|
|
303
|
-
export async function extractZipBufferToDir(buf, destDir) {
|
|
304
|
-
const absDest = path.resolve(destDir);
|
|
305
|
-
fs.mkdirSync(absDest, { recursive: true });
|
|
306
|
-
const zip = new AdmZip(Buffer.from(buf));
|
|
307
|
-
for (const entry of zip.getEntries()) {
|
|
308
|
-
if (entry.isDirectory)
|
|
309
|
-
continue;
|
|
310
|
-
const resolved = path.resolve(absDest, entry.entryName);
|
|
311
|
-
// path.resolve handles ".." already, but the security check below
|
|
312
|
-
// makes the prefix relationship explicit so a future refactor can't
|
|
313
|
-
// silently lose the guard. The trailing-sep check stops
|
|
314
|
-
// "destDir/foo" from being accepted as inside "destDir/fo".
|
|
315
|
-
if (resolved !== absDest &&
|
|
316
|
-
!resolved.startsWith(absDest + path.sep)) {
|
|
317
|
-
throw new Error(`zip entry escapes destination: ${entry.entryName} -> ${resolved}`);
|
|
318
|
-
}
|
|
319
|
-
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
320
|
-
fs.writeFileSync(resolved, entry.getData());
|
|
321
59
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
60
|
+
const fetchUrlToBuffer = depsOverride?.fetchUrlToBuffer ?? defaultFetchUrlToBuffer;
|
|
61
|
+
const buf = await fetchUrlToBuffer(blob.r2_get_url);
|
|
62
|
+
if (buf.byteLength !== blob.size_bytes) {
|
|
63
|
+
throw new Error(`OmniFlow session size mismatch: expected ${blob.size_bytes}, got ${buf.byteLength}`);
|
|
64
|
+
}
|
|
65
|
+
const actualHash = createHash("sha256").update(Buffer.from(buf)).digest("hex");
|
|
66
|
+
if (actualHash !== blob.content_hash) {
|
|
67
|
+
throw new Error(`OmniFlow session hash mismatch: expected ${blob.content_hash}, got ${actualHash}`);
|
|
68
|
+
}
|
|
69
|
+
const raw = Buffer.from(buf).toString("utf8");
|
|
70
|
+
let json;
|
|
71
|
+
try {
|
|
72
|
+
json = JSON.parse(raw);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
throw new Error("OmniFlow session is not valid JSON");
|
|
76
|
+
}
|
|
77
|
+
const parsed = OmniFlowSessionExportSchema.safeParse(json);
|
|
78
|
+
if (!parsed.success) {
|
|
79
|
+
throw new Error(`Invalid OmniFlow session: ${parsed.error.issues
|
|
80
|
+
.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`)
|
|
81
|
+
.join("; ")}`);
|
|
82
|
+
}
|
|
83
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
84
|
+
fs.writeFileSync(dest, Buffer.from(buf));
|
|
85
|
+
const now = (depsOverride?.now ?? Date.now)();
|
|
338
86
|
const isoNow = new Date(now).toISOString();
|
|
339
87
|
await writeLocalSessionMeta(workspace, {
|
|
340
88
|
content_hash: blob.content_hash,
|
|
341
89
|
synced_at: isoNow,
|
|
342
90
|
last_local_modified_at: isoNow,
|
|
343
91
|
});
|
|
92
|
+
return {
|
|
93
|
+
status: "applied",
|
|
94
|
+
content_hash: blob.content_hash,
|
|
95
|
+
path: dest,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async function defaultFetchUrlToBuffer(url) {
|
|
99
|
+
const res = await fetch(url);
|
|
100
|
+
if (!res.ok) {
|
|
101
|
+
throw new Error(`Session blob fetch failed: ${res.status} ${res.statusText}`);
|
|
102
|
+
}
|
|
103
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
344
104
|
}
|
|
345
105
|
//# sourceMappingURL=session-sync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-sync.js","sourceRoot":"","sources":["../../src/center/session-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"session-sync.js","sourceRoot":"","sources":["../../src/center/session-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAoB,MAAM,WAAW,CAAC;AAE1E;;;;;;;;GAQG;AAEH,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AACnD,MAAM,0BAA0B,GAAG,wBAAwB,CAAC;AAuB5D,MAAM,UAAU,eAAe,CAAC,SAAiB;IAC/C,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACnD,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,0BAA0B,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,SAAiB;IAEjB,MAAM,CAAC,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;QACvD,IACE,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ;YACvC,OAAO,MAAM,CAAC,sBAA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