gestalt-mobile 0.50.2 → 0.51.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/dist/client/assets/{index-DEzZEQhF.css → index-BEI00R5B.css} +1 -1
- package/dist/client/assets/{index-BePEZpgl.js → index-j6bx7PQU.js} +34 -34
- package/dist/client/index.html +2 -2
- package/dist/server/server/app.js +5 -1
- package/dist/server/server/composition.contracts.js +2 -0
- package/dist/server/server/composition.js +10 -0
- package/dist/server/server/features/catalog/get-codex-allowance/endpoint.js +20 -0
- package/dist/server/server/features/catalog/register-routes.js +3 -0
- package/dist/server/server/platform/codex/codex-allowance.js +92 -0
- package/dist/server/shared/contracts/codex-allowance.js +6 -0
- package/package.json +1 -1
package/dist/client/index.html
CHANGED
|
@@ -16,8 +16,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
16
16
|
<link rel="icon" href="/icons/gestalt-mobile-192.png" />
|
|
17
17
|
<link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
|
|
18
18
|
<title>Gestalt Mobile</title>
|
|
19
|
-
<script type="module" crossorigin src="/assets/index-
|
|
20
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
19
|
+
<script type="module" crossorigin src="/assets/index-j6bx7PQU.js"></script>
|
|
20
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BEI00R5B.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
23
23
|
<div id="app"></div>
|
|
@@ -46,7 +46,11 @@ export async function buildApp(deps) {
|
|
|
46
46
|
});
|
|
47
47
|
registerGetHealth(app, deps.health);
|
|
48
48
|
registerAuthRoutes(app, deps);
|
|
49
|
-
registerCatalogRoutes(app, {
|
|
49
|
+
registerCatalogRoutes(app, {
|
|
50
|
+
bootstrap: deps.bootstrap,
|
|
51
|
+
sessionDefaults: deps.sessionDefaults,
|
|
52
|
+
codexAllowance: deps.codexAllowance,
|
|
53
|
+
});
|
|
50
54
|
registerSessionRoutes(app, deps);
|
|
51
55
|
if (deps.selfDebug)
|
|
52
56
|
registerSelfDebug(app, deps.selfDebug);
|
|
@@ -4058,6 +4058,8 @@ describe('production composition', () => {
|
|
|
4058
4058
|
['DELETE', '/api/auth/devices/:deviceId', '/api/auth/devices/device-1', 'protected'],
|
|
4059
4059
|
['GET', '/api/bootstrap', '/api/bootstrap', 'protected'],
|
|
4060
4060
|
['HEAD', '/api/bootstrap', '/api/bootstrap', 'protected'],
|
|
4061
|
+
['GET', '/api/codex/allowance', '/api/codex/allowance', 'protected'],
|
|
4062
|
+
['HEAD', '/api/codex/allowance', '/api/codex/allowance', 'protected'],
|
|
4061
4063
|
['GET', '/api/xerj', '/api/xerj', 'protected'],
|
|
4062
4064
|
['HEAD', '/api/xerj', '/api/xerj', 'protected'],
|
|
4063
4065
|
['GET', '/api/session-defaults', '/api/session-defaults', 'protected'],
|
|
@@ -20,6 +20,7 @@ import { FilesystemWorkspaceFiles } from './platform/filesystem/filesystem-works
|
|
|
20
20
|
import { protocolCompatibility } from './platform/codex/protocol-compatibility.js';
|
|
21
21
|
import { launchCodexAppServer } from './platform/codex/codex-process-launcher.js';
|
|
22
22
|
import { CodexModelCatalog } from './platform/codex/codex-model-catalog.js';
|
|
23
|
+
import { CodexAllowanceReader } from './platform/codex/codex-allowance.js';
|
|
23
24
|
import { ProviderModelCatalog } from './platform/catalog/provider-model-catalog.js';
|
|
24
25
|
import { createRecentThreadLister } from './platform/codex/recent-thread-lister.js';
|
|
25
26
|
import { CodexSessionRuntime } from './platform/codex/session-runtime.js';
|
|
@@ -1304,6 +1305,15 @@ export async function composeRelayApp(options) {
|
|
|
1304
1305
|
pwaIcon: options.pwaIcon,
|
|
1305
1306
|
recentThreads: recentThreadsForRelay,
|
|
1306
1307
|
sessionDefaults,
|
|
1308
|
+
codexAllowance: options.installedCodexVersion === null
|
|
1309
|
+
? {
|
|
1310
|
+
read: async () => ({
|
|
1311
|
+
weeklyRemainingPercent: null,
|
|
1312
|
+
weeklyResetsAt: null,
|
|
1313
|
+
resetsAvailable: null,
|
|
1314
|
+
}),
|
|
1315
|
+
}
|
|
1316
|
+
: new CodexAllowanceReader(root, options.launchAppServer ?? launchCodexAppServer),
|
|
1307
1317
|
bootstrap: {
|
|
1308
1318
|
xerj: () => xerjIndexer.status(),
|
|
1309
1319
|
sessionDefaults,
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { problem } from '../../../platform/http/problem.js';
|
|
7
|
+
export function registerGetCodexAllowance(app, reader) {
|
|
8
|
+
app.get('/api/codex/allowance', async (_request, reply) => {
|
|
9
|
+
reply.header('Cache-Control', 'no-store');
|
|
10
|
+
try {
|
|
11
|
+
return await reader.read();
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return reply
|
|
15
|
+
.code(503)
|
|
16
|
+
.type('application/problem+json')
|
|
17
|
+
.send(problem('CODEX_ALLOWANCE_UNAVAILABLE', 503, 'Codex allowance is temporarily unavailable.'));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
import { registerXerjStatus } from './get-xerj-status/endpoint.js';
|
|
7
7
|
import { registerGetBootstrap } from './get-bootstrap/endpoint.js';
|
|
8
8
|
import { registerSessionDefaults } from './session-defaults/endpoint.js';
|
|
9
|
+
import { registerGetCodexAllowance, } from './get-codex-allowance/endpoint.js';
|
|
9
10
|
export function registerCatalogRoutes(app, deps) {
|
|
10
11
|
if (deps.bootstrap)
|
|
11
12
|
registerGetBootstrap(app, deps.bootstrap);
|
|
13
|
+
if (deps.codexAllowance)
|
|
14
|
+
registerGetCodexAllowance(app, deps.codexAllowance);
|
|
12
15
|
if (deps.bootstrap?.xerj)
|
|
13
16
|
registerXerjStatus(app, deps.bootstrap.xerj);
|
|
14
17
|
if (deps.sessionDefaults)
|
|
@@ -0,0 +1,92 @@
|
|
|
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 { z } from 'zod';
|
|
7
|
+
import { launchCodexAppServer } from './codex-process-launcher.js';
|
|
8
|
+
const windowSchema = z.object({
|
|
9
|
+
windowDurationMins: z.literal(10_080),
|
|
10
|
+
usedPercent: z.number().finite(),
|
|
11
|
+
resetsAt: z.unknown().optional(),
|
|
12
|
+
});
|
|
13
|
+
const recordSchema = z.record(z.string(), z.unknown());
|
|
14
|
+
/** Return only account-wide counters, never account identifiers or credit details. */
|
|
15
|
+
export function decodeCodexAllowance(value) {
|
|
16
|
+
const response = recordSchema.safeParse(value);
|
|
17
|
+
const data = response.success ? response.data : {};
|
|
18
|
+
const buckets = recordSchema.safeParse(data.rateLimitsByLimitId);
|
|
19
|
+
const bucket = recordSchema.safeParse(buckets.success && 'codex' in buckets.data ? buckets.data.codex : data.rateLimits);
|
|
20
|
+
const limits = bucket.success && (bucket.data.limitId == null || bucket.data.limitId === 'codex')
|
|
21
|
+
? bucket.data
|
|
22
|
+
: {};
|
|
23
|
+
const weekly = [limits.primary, limits.secondary]
|
|
24
|
+
.map((window) => windowSchema.safeParse(window))
|
|
25
|
+
.find((window) => window.success);
|
|
26
|
+
const credits = z
|
|
27
|
+
.object({ availableCount: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER) })
|
|
28
|
+
.safeParse(data.rateLimitResetCredits);
|
|
29
|
+
const reset = z
|
|
30
|
+
.number()
|
|
31
|
+
.int()
|
|
32
|
+
.nonnegative()
|
|
33
|
+
.max(8_640_000_000_000)
|
|
34
|
+
.safeParse(weekly?.success ? weekly.data.resetsAt : null);
|
|
35
|
+
return {
|
|
36
|
+
weeklyRemainingPercent: weekly?.success
|
|
37
|
+
? Math.round(Math.max(0, Math.min(100, 100 - weekly.data.usedPercent)))
|
|
38
|
+
: null,
|
|
39
|
+
resetsAvailable: credits.success ? credits.data.availableCount : null,
|
|
40
|
+
weeklyResetsAt: reset.success ? reset.data : null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** A bounded account read also works before a user has opened a session. */
|
|
44
|
+
export class CodexAllowanceReader {
|
|
45
|
+
cwd;
|
|
46
|
+
launch;
|
|
47
|
+
timeoutMs;
|
|
48
|
+
pending;
|
|
49
|
+
cached;
|
|
50
|
+
constructor(cwd, launch = launchCodexAppServer, timeoutMs = 5_000) {
|
|
51
|
+
this.cwd = cwd;
|
|
52
|
+
this.launch = launch;
|
|
53
|
+
this.timeoutMs = timeoutMs;
|
|
54
|
+
}
|
|
55
|
+
read() {
|
|
56
|
+
if (this.cached && this.cached.expires > Date.now())
|
|
57
|
+
return Promise.resolve(this.cached.value);
|
|
58
|
+
if (this.pending)
|
|
59
|
+
return this.pending;
|
|
60
|
+
this.pending = this.readFresh()
|
|
61
|
+
.then((value) => {
|
|
62
|
+
this.cached = { value, expires: Date.now() + 30_000 };
|
|
63
|
+
return value;
|
|
64
|
+
})
|
|
65
|
+
.finally(() => {
|
|
66
|
+
this.pending = undefined;
|
|
67
|
+
});
|
|
68
|
+
return this.pending;
|
|
69
|
+
}
|
|
70
|
+
async readFresh() {
|
|
71
|
+
const server = this.launch({ profile: '', cwd: this.cwd });
|
|
72
|
+
let timer;
|
|
73
|
+
try {
|
|
74
|
+
return await Promise.race([
|
|
75
|
+
(async () => {
|
|
76
|
+
await server.rpc.request('initialize', {
|
|
77
|
+
clientInfo: { name: 'gestalt-mobile', version: '0.1.0' },
|
|
78
|
+
capabilities: null,
|
|
79
|
+
});
|
|
80
|
+
return decodeCodexAllowance(await server.rpc.request('account/rateLimits/read', {}));
|
|
81
|
+
})(),
|
|
82
|
+
new Promise((_, reject) => {
|
|
83
|
+
timer = setTimeout(() => reject(new Error('CODEX_ALLOWANCE_UNAVAILABLE')), this.timeoutMs);
|
|
84
|
+
}),
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
clearTimeout(timer);
|
|
89
|
+
server.close();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|