@elizaos/plugin-capacitor-bridge 2.0.0-beta.1 → 2.0.3-beta.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.
@@ -0,0 +1,690 @@
1
+ // src/shared/fs-shim.ts
2
+ import * as nodeFs from "fs";
3
+ import * as nodeFsPromises from "fs/promises";
4
+ import { createRequire } from "module";
5
+ import * as nodePath2 from "path";
6
+ import { fileURLToPath as fileURLToPath2 } from "url";
7
+
8
+ // src/shared/fs-sandbox.ts
9
+ import * as realFs from "fs";
10
+ import * as nodePath from "path";
11
+ import { fileURLToPath } from "url";
12
+ function requireMobileFsResolver(moduleName) {
13
+ const resolver = globalThis.__ELIZA_MOBILE_FS_RESOLVE__;
14
+ if (!resolver) {
15
+ throw new Error(
16
+ `${moduleName}: filesystem access before installMobileFsShim()`
17
+ );
18
+ }
19
+ return resolver;
20
+ }
21
+ function mobileFsAccessError(path, message) {
22
+ const err = new Error(message);
23
+ err.code = "EACCES";
24
+ err.path = path;
25
+ return err;
26
+ }
27
+ function guardMobileFsWritePath(resolved, originalPath) {
28
+ const ext = nodePath.extname(resolved).toLowerCase();
29
+ if (ext === ".so" || ext === ".dylib" || ext === ".node") {
30
+ throw mobileFsAccessError(
31
+ originalPath,
32
+ `mobile-fs-shim: writing native binary files is blocked (${ext})`
33
+ );
34
+ }
35
+ }
36
+ function mobileFsPathLikeToString(raw, moduleName) {
37
+ if (raw instanceof URL) {
38
+ if (raw.protocol !== "file:") {
39
+ throw new Error(
40
+ `${moduleName}: only file: URLs are accepted (${raw.protocol})`
41
+ );
42
+ }
43
+ return fileURLToPath(raw);
44
+ }
45
+ if (Buffer.isBuffer(raw)) return raw.toString("utf8");
46
+ return typeof raw === "string" ? raw : null;
47
+ }
48
+ function modeForMobileFsOpenFlags(flags) {
49
+ if (typeof flags === "number") {
50
+ const writeBits = realFs.constants.O_WRONLY | realFs.constants.O_RDWR | realFs.constants.O_APPEND | realFs.constants.O_CREAT | realFs.constants.O_TRUNC;
51
+ return (flags & writeBits) !== 0 ? "write" : "read";
52
+ }
53
+ if (typeof flags !== "string" || flags.length === 0) return "read";
54
+ return /[wa+]/.test(flags) ? "write" : "read";
55
+ }
56
+ function wrapMobileFsPath(moduleName, fn, mode) {
57
+ return function wrappedMobileFsPath(...args) {
58
+ const a = args;
59
+ const pathStr = mobileFsPathLikeToString(a[0], moduleName);
60
+ if (pathStr !== null) {
61
+ const resolved = requireMobileFsResolver(moduleName)(pathStr, mode);
62
+ if (mode === "write") guardMobileFsWritePath(resolved, pathStr);
63
+ a[0] = resolved;
64
+ }
65
+ return fn.apply(this, a);
66
+ };
67
+ }
68
+ function wrapMobileFsOpen(moduleName, fn) {
69
+ return function wrappedMobileFsOpen(...args) {
70
+ const a = args;
71
+ const pathStr = mobileFsPathLikeToString(a[0], moduleName);
72
+ if (pathStr !== null) {
73
+ const mode = modeForMobileFsOpenFlags(a[1]);
74
+ const resolved = requireMobileFsResolver(moduleName)(pathStr, mode);
75
+ if (mode === "write") guardMobileFsWritePath(resolved, pathStr);
76
+ a[0] = resolved;
77
+ }
78
+ return fn.apply(this, a);
79
+ };
80
+ }
81
+ function wrapMobileFsTwoPaths(moduleName, fn, srcMode, dstMode) {
82
+ return function wrappedMobileFsTwoPaths(...args) {
83
+ const a = args;
84
+ const src = mobileFsPathLikeToString(a[0], moduleName);
85
+ const dst = mobileFsPathLikeToString(a[1], moduleName);
86
+ const resolver = requireMobileFsResolver(moduleName);
87
+ if (src !== null) {
88
+ const resolved = resolver(src, srcMode);
89
+ if (srcMode === "write") guardMobileFsWritePath(resolved, src);
90
+ a[0] = resolved;
91
+ }
92
+ if (dst !== null) {
93
+ const resolved = resolver(dst, dstMode);
94
+ if (dstMode === "write") guardMobileFsWritePath(resolved, dst);
95
+ a[1] = resolved;
96
+ }
97
+ return fn.apply(this, a);
98
+ };
99
+ }
100
+
101
+ // src/shared/fs-shim.ts
102
+ var _installed = false;
103
+ var _workspaceRoot = "";
104
+ var _workspaceRootReal = "";
105
+ var _readOnlyRoots = [];
106
+ var _readOnlyRootReals = [];
107
+ var rawExistsSync = nodeFs.existsSync.bind(nodeFs);
108
+ var rawRealpathSync = nodeFs.realpathSync.bind(nodeFs);
109
+ var BLOCKED_ROOT_PREFIXES = [
110
+ "/etc",
111
+ "/usr",
112
+ "/bin",
113
+ "/sbin",
114
+ "/lib",
115
+ "/lib64",
116
+ "/System",
117
+ "/private/etc",
118
+ "/private/var/db",
119
+ "/private/var/root",
120
+ "/dev",
121
+ "/proc",
122
+ "/sys",
123
+ "/boot",
124
+ "/run"
125
+ ];
126
+ function isInsideRoot(pathname, root) {
127
+ const rootWithSep = root.endsWith(nodePath2.sep) ? root : root + nodePath2.sep;
128
+ return pathname === root || pathname.startsWith(rootWithSep);
129
+ }
130
+ function envReadOnlyRoots() {
131
+ const candidates = [
132
+ process.env.ELIZA_IOS_AGENT_PUBLIC_DIR,
133
+ process.env.ELIZA_IOS_AGENT_ASSET_DIR,
134
+ process.env.ELIZA_IOS_AGENT_BUNDLE ? nodePath2.dirname(process.env.ELIZA_IOS_AGENT_BUNDLE) : ""
135
+ ];
136
+ return candidates.filter((value) => Boolean(value?.trim())).map((value) => nodePath2.resolve(value));
137
+ }
138
+ function realpathIfPossible(pathname) {
139
+ try {
140
+ return rawRealpathSync(pathname);
141
+ } catch {
142
+ return nodePath2.resolve(pathname);
143
+ }
144
+ }
145
+ function nearestExistingParent(pathname) {
146
+ let current = nodePath2.resolve(pathname);
147
+ for (; ; ) {
148
+ if (rawExistsSync(current)) return current;
149
+ const parent = nodePath2.dirname(current);
150
+ if (parent === current) return null;
151
+ current = parent;
152
+ }
153
+ }
154
+ function validateResolvedRealPath(inputPath, resolved, mode, allowedReadOnly) {
155
+ if (mode === "read") {
156
+ if (!rawExistsSync(resolved)) return resolved;
157
+ const real2 = realpathIfPossible(resolved);
158
+ if (isInsideRoot(real2, _workspaceRootReal || _workspaceRoot))
159
+ return resolved;
160
+ if (allowedReadOnly && _readOnlyRootReals.some((root) => isInsideRoot(real2, root))) {
161
+ return resolved;
162
+ }
163
+ throw accessError(
164
+ inputPath,
165
+ `mobile-fs-shim: real path escapes allowed roots: ${real2}`
166
+ );
167
+ }
168
+ const existing = nearestExistingParent(resolved);
169
+ if (!existing) return resolved;
170
+ const real = realpathIfPossible(existing);
171
+ if (isInsideRoot(real, _workspaceRootReal || _workspaceRoot)) return resolved;
172
+ throw accessError(
173
+ inputPath,
174
+ `mobile-fs-shim: write parent escapes workspace root: ${real}`
175
+ );
176
+ }
177
+ function resolveViaAncestor(pathname) {
178
+ const existing = nearestExistingParent(pathname);
179
+ if (!existing) return pathname;
180
+ try {
181
+ const realExisting = rawRealpathSync(existing);
182
+ if (realExisting === existing) return pathname;
183
+ return realExisting + pathname.slice(existing.length);
184
+ } catch {
185
+ return pathname;
186
+ }
187
+ }
188
+ function resolveSandboxed(inputPath, mode = "read") {
189
+ if (!_workspaceRoot) {
190
+ throw accessError(
191
+ inputPath,
192
+ "mobile-fs-shim: workspace root not initialised"
193
+ );
194
+ }
195
+ const resolved = nodePath2.isAbsolute(inputPath) ? nodePath2.resolve(inputPath) : nodePath2.resolve(_workspaceRoot, inputPath);
196
+ for (const blocked of BLOCKED_ROOT_PREFIXES) {
197
+ if (resolved === blocked || resolved.startsWith(blocked + nodePath2.sep)) {
198
+ throw accessError(
199
+ inputPath,
200
+ `mobile-fs-shim: path targets a system directory (${blocked})`
201
+ );
202
+ }
203
+ }
204
+ if (isInsideRoot(resolved, _workspaceRoot)) {
205
+ return validateResolvedRealPath(inputPath, resolved, mode, false);
206
+ }
207
+ if (mode === "read" && _readOnlyRoots.some((root) => isInsideRoot(resolved, root))) {
208
+ return validateResolvedRealPath(inputPath, resolved, mode, true);
209
+ }
210
+ if (_workspaceRootReal) {
211
+ const realResolved = resolveViaAncestor(resolved);
212
+ if (realResolved !== resolved) {
213
+ if (isInsideRoot(realResolved, _workspaceRootReal)) {
214
+ return resolved;
215
+ }
216
+ if (mode === "read" && _readOnlyRootReals.some((root) => isInsideRoot(realResolved, root))) {
217
+ return resolved;
218
+ }
219
+ }
220
+ }
221
+ throw accessError(
222
+ inputPath,
223
+ `mobile-fs-shim: path escapes workspace root (${_workspaceRoot}): ${resolved}`
224
+ );
225
+ }
226
+ function sandboxedPath(inputPath) {
227
+ return resolveSandboxed(inputPath);
228
+ }
229
+ function isMobileFsShimInstalled() {
230
+ return _installed;
231
+ }
232
+ function getMobileWorkspaceRoot() {
233
+ return _workspaceRoot;
234
+ }
235
+ function accessError(path, message) {
236
+ return mobileFsAccessError(path, message);
237
+ }
238
+ function pathLikeToString(raw) {
239
+ if (raw instanceof URL) {
240
+ if (raw.protocol !== "file:") {
241
+ throw accessError(
242
+ raw.toString(),
243
+ `mobile-fs-shim: only file: URLs are accepted by fs (${raw.protocol})`
244
+ );
245
+ }
246
+ return fileURLToPath2(raw);
247
+ }
248
+ if (Buffer.isBuffer(raw)) return raw.toString("utf8");
249
+ return typeof raw === "string" ? raw : null;
250
+ }
251
+ function installRequireGuard() {
252
+ const g = globalThis;
253
+ if (!g.require || g.require.__mobileFsShimGuarded) return;
254
+ const original = g.require;
255
+ g.__elizaOriginalRequire = original;
256
+ const guarded = new Proxy(original, {
257
+ apply(target, thisArg, args) {
258
+ const id = args[0];
259
+ if (typeof id === "string") {
260
+ const isBuiltin = id.startsWith("node:") || id.startsWith("bun:") || id === "buffer" || id === "path" || id === "fs" || id === "url" || id === "util" || id === "stream" || id === "events" || id === "crypto" || id === "os" || id === "child_process" || id === "net" || id === "tls";
261
+ const isFilePath = id.startsWith(".") || nodePath2.isAbsolute(id);
262
+ if (isFilePath && !isBuiltin) {
263
+ throw accessError(
264
+ id,
265
+ `mobile-fs-shim: dynamic require of file paths is blocked on mobile (${id}). All code must be bundled.`
266
+ );
267
+ }
268
+ }
269
+ return Reflect.apply(target, thisArg, args);
270
+ }
271
+ });
272
+ guarded.__mobileFsShimGuarded = true;
273
+ g.require = guarded;
274
+ }
275
+ var mobileRequire = createRequire(import.meta.url);
276
+ function optionalRequireObject(id) {
277
+ try {
278
+ const value = mobileRequire(id);
279
+ return value && typeof value === "object" ? value : null;
280
+ } catch {
281
+ return null;
282
+ }
283
+ }
284
+ function objectTargets(...values) {
285
+ const out = [];
286
+ const seen = /* @__PURE__ */ new WeakSet();
287
+ for (const value of values) {
288
+ if (!value || typeof value !== "object") continue;
289
+ const object = value;
290
+ if (seen.has(object)) continue;
291
+ seen.add(object);
292
+ out.push(object);
293
+ }
294
+ return out;
295
+ }
296
+ function setIfMutable(target, key, value) {
297
+ try {
298
+ target[key] = value;
299
+ return target[key] === value;
300
+ } catch {
301
+ return false;
302
+ }
303
+ }
304
+ function wrapFsPath(original, mode = "read") {
305
+ return function sandboxedFsCall(...args) {
306
+ const a = args;
307
+ const raw = a[0];
308
+ const pathStr = pathLikeToString(raw);
309
+ if (pathStr !== null) {
310
+ const resolved = resolveSandboxed(pathStr, mode);
311
+ if (mode === "write") guardWritePath(resolved, pathStr);
312
+ a[0] = resolved;
313
+ }
314
+ return original.apply(this, a);
315
+ };
316
+ }
317
+ function wrapFsOpenPath(original) {
318
+ return function sandboxedOpenCall(...args) {
319
+ const a = args;
320
+ const raw = a[0];
321
+ const pathStr = pathLikeToString(raw);
322
+ if (pathStr !== null) {
323
+ const mode = modeForMobileFsOpenFlags(a[1]);
324
+ const resolved = resolveSandboxed(pathStr, mode);
325
+ if (mode === "write") guardWritePath(resolved, pathStr);
326
+ a[0] = resolved;
327
+ }
328
+ return original.apply(this, a);
329
+ };
330
+ }
331
+ function wrapFsTwoPaths(original, srcMode, dstMode) {
332
+ return function sandboxedFsCall(...args) {
333
+ const a = args;
334
+ const rawSrc = a[0];
335
+ const rawDst = a[1];
336
+ const srcStr = pathLikeToString(rawSrc);
337
+ const dstStr = pathLikeToString(rawDst);
338
+ if (srcStr !== null) {
339
+ const resolved = resolveSandboxed(srcStr, srcMode);
340
+ if (srcMode === "write") guardWritePath(resolved, srcStr);
341
+ a[0] = resolved;
342
+ }
343
+ if (dstStr !== null) {
344
+ const resolved = resolveSandboxed(dstStr, dstMode);
345
+ if (dstMode === "write") guardWritePath(resolved, dstStr);
346
+ a[1] = resolved;
347
+ }
348
+ return original.apply(this, a);
349
+ };
350
+ }
351
+ function wrapFsWriteGuard(original) {
352
+ return function sandboxedFsWrite(...args) {
353
+ const a = args;
354
+ const raw = a[0];
355
+ const pathStr = pathLikeToString(raw);
356
+ if (pathStr !== null) {
357
+ const resolved = resolveSandboxed(pathStr, "write");
358
+ guardWritePath(resolved, pathStr);
359
+ a[0] = resolved;
360
+ }
361
+ return original.apply(this, a);
362
+ };
363
+ }
364
+ function guardWritePath(resolved, originalPath) {
365
+ guardMobileFsWritePath(resolved, originalPath);
366
+ }
367
+ function patchFsModule() {
368
+ const fsTargets = objectTargets(
369
+ optionalRequireObject("node:fs"),
370
+ optionalRequireObject("fs"),
371
+ nodeFs,
372
+ nodeFs.default
373
+ );
374
+ const promiseTargets = objectTargets(
375
+ optionalRequireObject("node:fs/promises"),
376
+ optionalRequireObject("fs/promises"),
377
+ nodeFsPromises,
378
+ nodeFsPromises.default,
379
+ ...fsTargets.map((target) => target.promises)
380
+ );
381
+ const syncOnePath = [
382
+ "accessSync",
383
+ "chmodSync",
384
+ "chownSync",
385
+ "lchmodSync",
386
+ "lchownSync",
387
+ "lstatSync",
388
+ "mkdirSync",
389
+ "mkdtempSync",
390
+ "readdirSync",
391
+ "readFileSync",
392
+ "readlinkSync",
393
+ "realpathSync",
394
+ "rmdirSync",
395
+ "rmSync",
396
+ "statSync",
397
+ "truncateSync",
398
+ "unlinkSync",
399
+ "utimesSync",
400
+ "lutimesSync",
401
+ "existsSync",
402
+ "opendirSync",
403
+ "appendFileSync"
404
+ ];
405
+ const syncWriteOnePath = /* @__PURE__ */ new Set([
406
+ "chmodSync",
407
+ "chownSync",
408
+ "lchmodSync",
409
+ "lchownSync",
410
+ "mkdirSync",
411
+ "mkdtempSync",
412
+ "rmdirSync",
413
+ "rmSync",
414
+ "truncateSync",
415
+ "unlinkSync",
416
+ "utimesSync",
417
+ "lutimesSync",
418
+ "appendFileSync"
419
+ ]);
420
+ for (const target of fsTargets) {
421
+ for (const name of syncOnePath) {
422
+ const key = String(name);
423
+ const orig = target[key];
424
+ if (typeof orig === "function") {
425
+ setIfMutable(
426
+ target,
427
+ key,
428
+ wrapFsPath(
429
+ orig,
430
+ syncWriteOnePath.has(key) ? "write" : "read"
431
+ )
432
+ );
433
+ }
434
+ }
435
+ if (typeof target.writeFileSync === "function") {
436
+ const wrapped = wrapFsWriteGuard(target.writeFileSync);
437
+ setIfMutable(target, "writeFileSync", wrapFsPath(wrapped, "write"));
438
+ }
439
+ if (typeof target.openSync === "function") {
440
+ setIfMutable(
441
+ target,
442
+ "openSync",
443
+ wrapFsOpenPath(target.openSync)
444
+ );
445
+ }
446
+ if (typeof target.createReadStream === "function") {
447
+ setIfMutable(
448
+ target,
449
+ "createReadStream",
450
+ wrapFsPath(target.createReadStream, "read")
451
+ );
452
+ }
453
+ if (typeof target.createWriteStream === "function") {
454
+ setIfMutable(
455
+ target,
456
+ "createWriteStream",
457
+ wrapFsPath(target.createWriteStream, "write")
458
+ );
459
+ }
460
+ if (typeof target.cpSync === "function") {
461
+ setIfMutable(
462
+ target,
463
+ "cpSync",
464
+ wrapFsTwoPaths(target.cpSync, "read", "write")
465
+ );
466
+ }
467
+ const syncTwoPaths = [
468
+ { name: "copyFileSync", srcMode: "read", dstMode: "write" },
469
+ { name: "renameSync", srcMode: "write", dstMode: "write" },
470
+ { name: "linkSync", srcMode: "read", dstMode: "write" },
471
+ { name: "symlinkSync", srcMode: "read", dstMode: "write" }
472
+ ];
473
+ for (const { name, srcMode, dstMode } of syncTwoPaths) {
474
+ const key = String(name);
475
+ const orig = target[key];
476
+ if (typeof orig === "function") {
477
+ setIfMutable(
478
+ target,
479
+ key,
480
+ wrapFsTwoPaths(orig, srcMode, dstMode)
481
+ );
482
+ }
483
+ }
484
+ const callbackOnePath = [
485
+ "access",
486
+ "chmod",
487
+ "chown",
488
+ "lchmod",
489
+ "lchown",
490
+ "lstat",
491
+ "mkdir",
492
+ "mkdtemp",
493
+ "readdir",
494
+ "readFile",
495
+ "readlink",
496
+ "realpath",
497
+ "rmdir",
498
+ "rm",
499
+ "stat",
500
+ "truncate",
501
+ "unlink",
502
+ "utimes",
503
+ "lutimes",
504
+ "opendir",
505
+ "appendFile"
506
+ ];
507
+ const callbackWriteOnePath = /* @__PURE__ */ new Set([
508
+ "chmod",
509
+ "chown",
510
+ "lchmod",
511
+ "lchown",
512
+ "mkdir",
513
+ "mkdtemp",
514
+ "rmdir",
515
+ "rm",
516
+ "truncate",
517
+ "unlink",
518
+ "utimes",
519
+ "lutimes",
520
+ "appendFile"
521
+ ]);
522
+ for (const name of callbackOnePath) {
523
+ const key = String(name);
524
+ const orig = target[key];
525
+ if (typeof orig === "function") {
526
+ setIfMutable(
527
+ target,
528
+ key,
529
+ wrapFsPath(
530
+ orig,
531
+ callbackWriteOnePath.has(key) ? "write" : "read"
532
+ )
533
+ );
534
+ }
535
+ }
536
+ if (typeof target.writeFile === "function") {
537
+ const wrapped = wrapFsWriteGuard(target.writeFile);
538
+ setIfMutable(target, "writeFile", wrapFsPath(wrapped, "write"));
539
+ }
540
+ if (typeof target.open === "function") {
541
+ setIfMutable(target, "open", wrapFsOpenPath(target.open));
542
+ }
543
+ if (typeof target.cp === "function") {
544
+ setIfMutable(
545
+ target,
546
+ "cp",
547
+ wrapFsTwoPaths(target.cp, "read", "write")
548
+ );
549
+ }
550
+ const callbackTwoPaths = [
551
+ { name: "copyFile", srcMode: "read", dstMode: "write" },
552
+ { name: "rename", srcMode: "write", dstMode: "write" },
553
+ { name: "link", srcMode: "read", dstMode: "write" },
554
+ { name: "symlink", srcMode: "read", dstMode: "write" }
555
+ ];
556
+ for (const { name, srcMode, dstMode } of callbackTwoPaths) {
557
+ const key = String(name);
558
+ const orig = target[key];
559
+ if (typeof orig === "function") {
560
+ setIfMutable(
561
+ target,
562
+ key,
563
+ wrapFsTwoPaths(orig, srcMode, dstMode)
564
+ );
565
+ }
566
+ }
567
+ }
568
+ const promisesOnePath = [
569
+ "access",
570
+ "chmod",
571
+ "chown",
572
+ "lchmod",
573
+ "lchown",
574
+ "lstat",
575
+ "mkdir",
576
+ "mkdtemp",
577
+ "readdir",
578
+ "readFile",
579
+ "readlink",
580
+ "realpath",
581
+ "rmdir",
582
+ "rm",
583
+ "stat",
584
+ "truncate",
585
+ "unlink",
586
+ "utimes",
587
+ "lutimes",
588
+ "opendir",
589
+ "appendFile"
590
+ ];
591
+ const promisesWriteOnePath = /* @__PURE__ */ new Set([
592
+ "chmod",
593
+ "chown",
594
+ "lchmod",
595
+ "lchown",
596
+ "mkdir",
597
+ "mkdtemp",
598
+ "rmdir",
599
+ "rm",
600
+ "truncate",
601
+ "unlink",
602
+ "utimes",
603
+ "lutimes",
604
+ "appendFile"
605
+ ]);
606
+ for (const promises of promiseTargets) {
607
+ for (const name of promisesOnePath) {
608
+ const orig = promises[name];
609
+ if (typeof orig === "function") {
610
+ setIfMutable(
611
+ promises,
612
+ name,
613
+ wrapFsPath(
614
+ orig,
615
+ promisesWriteOnePath.has(name) ? "write" : "read"
616
+ )
617
+ );
618
+ }
619
+ }
620
+ if (typeof promises.writeFile === "function") {
621
+ const wrapped = wrapFsWriteGuard(promises.writeFile);
622
+ setIfMutable(promises, "writeFile", wrapFsPath(wrapped, "write"));
623
+ }
624
+ if (typeof promises.open === "function") {
625
+ setIfMutable(promises, "open", wrapFsOpenPath(promises.open));
626
+ }
627
+ if (typeof promises.cp === "function") {
628
+ setIfMutable(
629
+ promises,
630
+ "cp",
631
+ wrapFsTwoPaths(promises.cp, "read", "write")
632
+ );
633
+ }
634
+ const promisesTwoPaths = [
635
+ { name: "copyFile", srcMode: "read", dstMode: "write" },
636
+ { name: "rename", srcMode: "write", dstMode: "write" },
637
+ { name: "link", srcMode: "read", dstMode: "write" },
638
+ { name: "symlink", srcMode: "read", dstMode: "write" }
639
+ ];
640
+ for (const { name, srcMode, dstMode } of promisesTwoPaths) {
641
+ const orig = promises[name];
642
+ if (typeof orig === "function") {
643
+ setIfMutable(
644
+ promises,
645
+ name,
646
+ wrapFsTwoPaths(orig, srcMode, dstMode)
647
+ );
648
+ }
649
+ }
650
+ }
651
+ }
652
+ function installMobileFsShim(workspaceRoot) {
653
+ if (!workspaceRoot || typeof workspaceRoot !== "string") {
654
+ throw new Error(
655
+ "mobile-fs-shim: installMobileFsShim() requires a non-empty workspaceRoot string"
656
+ );
657
+ }
658
+ const canonical = nodePath2.resolve(workspaceRoot);
659
+ if (_installed) {
660
+ if (_workspaceRoot === canonical) {
661
+ return;
662
+ }
663
+ throw new Error(
664
+ `mobile-fs-shim: already installed with root "${_workspaceRoot}"; attempted re-install with "${canonical}" is not allowed`
665
+ );
666
+ }
667
+ _workspaceRoot = canonical;
668
+ _workspaceRootReal = realpathIfPossible(canonical);
669
+ _readOnlyRoots = envReadOnlyRoots().filter(
670
+ (root) => !isInsideRoot(root, canonical)
671
+ );
672
+ _readOnlyRootReals = _readOnlyRoots.map((root) => realpathIfPossible(root));
673
+ _installed = true;
674
+ globalThis.__ELIZA_MOBILE_FS_RESOLVE__ = resolveSandboxed;
675
+ patchFsModule();
676
+ installRequireGuard();
677
+ if (!process.env.MOBILE_WORKSPACE_ROOT) {
678
+ process.env.MOBILE_WORKSPACE_ROOT = canonical;
679
+ }
680
+ }
681
+
682
+ export {
683
+ wrapMobileFsPath,
684
+ wrapMobileFsOpen,
685
+ wrapMobileFsTwoPaths,
686
+ sandboxedPath,
687
+ isMobileFsShimInstalled,
688
+ getMobileWorkspaceRoot,
689
+ installMobileFsShim
690
+ };
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };