gestalt-mobile 0.79.1 → 0.80.0
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/README.md +16 -15
- package/dist/client/assets/{index-PmiNsocJ.css → index-BVmjeerO.css} +1 -1
- package/dist/client/assets/index-J5jOs7dz.js +191 -0
- package/dist/client/index.html +2 -2
- package/dist/server/server/cli.js +3 -1
- package/dist/server/server/composition.contracts.js +106 -0
- package/dist/server/server/composition.js +83 -19
- package/dist/server/server/config.js +20 -10
- package/dist/server/server/features/catalog/get-bootstrap/use-case.js +3 -2
- package/dist/server/server/features/previews/application/service.js +4 -1
- package/dist/server/server/features/previews/open-preview/endpoint.js +7 -1
- package/dist/server/server/features/sessions/start-session/endpoint.js +8 -0
- package/dist/server/server/features/sessions/start-session/replace-session.js +91 -0
- package/dist/server/server/features/sessions/start-session/request.js +1 -0
- package/dist/server/server/features/sessions/start-session/use-case.js +15 -6
- package/dist/server/server/platform/previews/host-config.js +51 -0
- package/dist/server/server/platform/previews/publication.js +58 -0
- package/dist/server/server/platform/scratch/filesystem-session-scratch.js +12 -1
- package/package.json +1 -1
- package/dist/client/assets/index-t6olwrqi.js +0 -189
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { constants } from 'node:fs';
|
|
7
|
+
import { open } from 'node:fs/promises';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { createPreviewConfig } from '../../config.js';
|
|
11
|
+
const previewSettings = z.strictObject({
|
|
12
|
+
relayOrigin: z.string(),
|
|
13
|
+
origin: z.string(),
|
|
14
|
+
gatewayPort: z.number().optional(),
|
|
15
|
+
targetPort: z.number().optional(),
|
|
16
|
+
});
|
|
17
|
+
const previewFile = z.union([previewSettings, z.array(previewSettings)]);
|
|
18
|
+
function previewHostConfigPath(home) {
|
|
19
|
+
return join(home, '.codex-gestalt', 'gestalt-mobile', 'preview.json');
|
|
20
|
+
}
|
|
21
|
+
export async function readPreviewHostConfig(home, publicOrigin, relayPort) {
|
|
22
|
+
const file = await open(previewHostConfigPath(home), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK).catch((error) => {
|
|
23
|
+
if (error.code !== 'ENOENT')
|
|
24
|
+
throw error;
|
|
25
|
+
});
|
|
26
|
+
if (!file)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
const metadata = await file.stat();
|
|
30
|
+
if (!metadata.isFile() ||
|
|
31
|
+
metadata.uid !== process.getuid?.() ||
|
|
32
|
+
(metadata.mode & 0o022) !== 0 ||
|
|
33
|
+
metadata.size > 4096)
|
|
34
|
+
throw new Error('Invalid preview configuration file');
|
|
35
|
+
const buffer = Buffer.alloc(4097);
|
|
36
|
+
const { bytesRead } = await file.read(buffer);
|
|
37
|
+
if (bytesRead === buffer.length)
|
|
38
|
+
throw new Error('Invalid preview configuration file');
|
|
39
|
+
const fileSettings = previewFile.parse(JSON.parse(buffer.toString('utf8', 0, bytesRead)));
|
|
40
|
+
const entries = Array.isArray(fileSettings) ? fileSettings : [fileSettings];
|
|
41
|
+
const matching = entries.filter((entry) => entry.relayOrigin === publicOrigin);
|
|
42
|
+
if (matching.length > 1)
|
|
43
|
+
throw new Error('Duplicate relay origin in preview configuration');
|
|
44
|
+
const [settings] = matching;
|
|
45
|
+
if (settings)
|
|
46
|
+
return createPreviewConfig(settings, publicOrigin, relayPort, true);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
await file.close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { createPreviewGateway } from './gateway.js';
|
|
7
|
+
export class PreviewPublication {
|
|
8
|
+
service;
|
|
9
|
+
load;
|
|
10
|
+
impeccableHelper;
|
|
11
|
+
current;
|
|
12
|
+
pending;
|
|
13
|
+
closing = false;
|
|
14
|
+
constructor(service, load, impeccableHelper) {
|
|
15
|
+
this.service = service;
|
|
16
|
+
this.load = load;
|
|
17
|
+
this.impeccableHelper = impeccableHelper;
|
|
18
|
+
}
|
|
19
|
+
async start(config) {
|
|
20
|
+
const gateway = createPreviewGateway({ ...config, impeccableHelper: this.impeccableHelper }, this.service);
|
|
21
|
+
await gateway.start();
|
|
22
|
+
this.current = { config, gateway };
|
|
23
|
+
return config.origin;
|
|
24
|
+
}
|
|
25
|
+
refresh() {
|
|
26
|
+
if (this.closing)
|
|
27
|
+
return Promise.resolve(undefined);
|
|
28
|
+
this.pending ??= this.apply().finally(() => {
|
|
29
|
+
this.pending = undefined;
|
|
30
|
+
});
|
|
31
|
+
return this.pending;
|
|
32
|
+
}
|
|
33
|
+
async apply() {
|
|
34
|
+
const config = await this.load().catch(() => undefined);
|
|
35
|
+
if (this.closing)
|
|
36
|
+
return;
|
|
37
|
+
const previous = this.current?.config;
|
|
38
|
+
if (config &&
|
|
39
|
+
previous?.origin === config.origin &&
|
|
40
|
+
previous.port === config.port &&
|
|
41
|
+
previous.targetPort === config.targetPort)
|
|
42
|
+
return previous.origin;
|
|
43
|
+
await this.withdraw();
|
|
44
|
+
if (config && !this.closing)
|
|
45
|
+
return this.start(config).catch(() => undefined);
|
|
46
|
+
}
|
|
47
|
+
async withdraw() {
|
|
48
|
+
const previous = this.current;
|
|
49
|
+
this.current = undefined;
|
|
50
|
+
this.service.clear();
|
|
51
|
+
await previous?.gateway.close();
|
|
52
|
+
}
|
|
53
|
+
async close() {
|
|
54
|
+
this.closing = true;
|
|
55
|
+
await this.pending;
|
|
56
|
+
await this.withdraw();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
7
|
import { constants } from 'node:fs';
|
|
8
|
-
import { lstat, mkdir, open, readdir, realpath, rename, rmdir, unlink } from 'node:fs/promises';
|
|
8
|
+
import { lstat, mkdir, open, readdir, realpath, rename, rmdir, unlink, writeFile, } from 'node:fs/promises';
|
|
9
9
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
10
10
|
import { claimOwnerFence } from './owner-fence.js';
|
|
11
11
|
import { mobileScratchOwnerId, privateDirectory, readMarker, scratchMarkerName, scratchContextVariable, } from './scratch-filesystem.js';
|
|
@@ -286,6 +286,17 @@ export class FilesystemSessionScratch {
|
|
|
286
286
|
}
|
|
287
287
|
}));
|
|
288
288
|
}
|
|
289
|
+
async writeHandoff(session, contents) {
|
|
290
|
+
const lease = await this.borrow(session);
|
|
291
|
+
try {
|
|
292
|
+
const path = join(lease.directory, 'previous-session.json');
|
|
293
|
+
await writeFile(path, contents, { mode: 0o600, flag: 'wx' });
|
|
294
|
+
return path;
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
await lease.release();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
289
300
|
async associateProviderThread(session, provider, threadId) {
|
|
290
301
|
validId(session.id);
|
|
291
302
|
this.assertAvailable(session.id);
|