codex-relay 1.3.0 → 1.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/dist/paths.js +98 -11
- package/package.json +4 -2
package/dist/paths.js
CHANGED
|
@@ -1,9 +1,96 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { mkdir } from "node:fs/promises";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { fromByteArray, toByteArray } from "base64-js";
|
|
6
|
+
import { createClient } from "@libsql/client/node";
|
|
6
7
|
import { homedir, networkInterfaces, platform } from "node:os";
|
|
8
|
+
//#region src/libsql-database.ts
|
|
9
|
+
function connect(path) {
|
|
10
|
+
const client = createClient({
|
|
11
|
+
intMode: "number",
|
|
12
|
+
url: databaseUrl(path)
|
|
13
|
+
});
|
|
14
|
+
const lock = createExclusiveLock();
|
|
15
|
+
return {
|
|
16
|
+
...createQueryableDatabase(path === ":memory:" ? { execute(statement) {
|
|
17
|
+
return lock(() => client.execute(statement));
|
|
18
|
+
} } : client),
|
|
19
|
+
exec(sql) {
|
|
20
|
+
return path === ":memory:" ? lock(() => client.executeMultiple(sql)) : client.executeMultiple(sql);
|
|
21
|
+
},
|
|
22
|
+
transaction(callback) {
|
|
23
|
+
if (path === ":memory:") {
|
|
24
|
+
const transactionDatabase = createQueryableDatabase(client);
|
|
25
|
+
return () => lock(async () => {
|
|
26
|
+
await client.execute("BEGIN IMMEDIATE");
|
|
27
|
+
try {
|
|
28
|
+
const result = await callback(transactionDatabase);
|
|
29
|
+
await client.execute("COMMIT");
|
|
30
|
+
return result;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
await client.execute("ROLLBACK");
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return async () => {
|
|
38
|
+
const transaction = await client.transaction("write");
|
|
39
|
+
try {
|
|
40
|
+
const result = await callback(createQueryableDatabase(transaction));
|
|
41
|
+
await transaction.commit();
|
|
42
|
+
return result;
|
|
43
|
+
} finally {
|
|
44
|
+
transaction.close();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function databaseUrl(path) {
|
|
51
|
+
return path === ":memory:" ? path : pathToFileURL(resolve(path)).href;
|
|
52
|
+
}
|
|
53
|
+
function createExclusiveLock() {
|
|
54
|
+
let tail = Promise.resolve();
|
|
55
|
+
return async function withLock(callback) {
|
|
56
|
+
const previous = tail;
|
|
57
|
+
let release;
|
|
58
|
+
tail = new Promise((resolve) => {
|
|
59
|
+
release = resolve;
|
|
60
|
+
});
|
|
61
|
+
await previous;
|
|
62
|
+
try {
|
|
63
|
+
return await callback();
|
|
64
|
+
} finally {
|
|
65
|
+
release();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function createQueryableDatabase(executor) {
|
|
70
|
+
return { prepare(sql) {
|
|
71
|
+
return {
|
|
72
|
+
async all(...args) {
|
|
73
|
+
return (await executor.execute({
|
|
74
|
+
sql,
|
|
75
|
+
args
|
|
76
|
+
})).rows;
|
|
77
|
+
},
|
|
78
|
+
async get(...args) {
|
|
79
|
+
return (await executor.execute({
|
|
80
|
+
sql,
|
|
81
|
+
args
|
|
82
|
+
})).rows[0];
|
|
83
|
+
},
|
|
84
|
+
run(...args) {
|
|
85
|
+
return executor.execute({
|
|
86
|
+
sql,
|
|
87
|
+
args
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
} };
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
7
94
|
//#region src/pairing-store.ts
|
|
8
95
|
async function createTursoPairingSessionStore(path) {
|
|
9
96
|
if (path !== ":memory:") await mkdir(dirname(path), { recursive: true });
|
|
@@ -86,11 +173,11 @@ async function createTursoPairingSessionStore(path) {
|
|
|
86
173
|
};
|
|
87
174
|
},
|
|
88
175
|
async clearAll() {
|
|
89
|
-
return await db.transaction(async () => {
|
|
90
|
-
const sessionRow = await
|
|
91
|
-
const pendingRow = await
|
|
92
|
-
await
|
|
93
|
-
await
|
|
176
|
+
return await db.transaction(async (transaction) => {
|
|
177
|
+
const sessionRow = await transaction.prepare("SELECT COUNT(*) AS count FROM pairing_sessions").get();
|
|
178
|
+
const pendingRow = await transaction.prepare("SELECT COUNT(*) AS count FROM pending_pairings").get();
|
|
179
|
+
await transaction.prepare("DELETE FROM pairing_sessions").run();
|
|
180
|
+
await transaction.prepare("DELETE FROM pending_pairings").run();
|
|
94
181
|
return {
|
|
95
182
|
pendingPairingsCleared: Number(pendingRow?.count ?? 0),
|
|
96
183
|
sessionsCleared: Number(sessionRow?.count ?? 0)
|
|
@@ -171,13 +258,13 @@ async function createTursoPairingSessionStore(path) {
|
|
|
171
258
|
async rotateSession(oldTokenHash, newTokenHash, session) {
|
|
172
259
|
const now = Date.now();
|
|
173
260
|
const secure = encodeSecureSession(session.secureSession);
|
|
174
|
-
await db.transaction(async () => {
|
|
175
|
-
await
|
|
261
|
+
await db.transaction(async (transaction) => {
|
|
262
|
+
await transaction.prepare("DELETE FROM pairing_sessions WHERE token_hash = ?").run(oldTokenHash);
|
|
176
263
|
if (session.clientSessionId) {
|
|
177
|
-
await
|
|
178
|
-
if (session.clientName) await
|
|
264
|
+
await transaction.prepare("DELETE FROM pairing_sessions WHERE client_session_id = ?").run(session.clientSessionId);
|
|
265
|
+
if (session.clientName) await transaction.prepare("DELETE FROM pairing_sessions WHERE client_session_id IS NULL AND client_name = ?").run(session.clientName);
|
|
179
266
|
}
|
|
180
|
-
await
|
|
267
|
+
await transaction.prepare(`INSERT INTO pairing_sessions (
|
|
181
268
|
token_hash,
|
|
182
269
|
client_session_id,
|
|
183
270
|
client_name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-relay",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Local Codex Relay CLI bridge for the Codex Relay mobile app.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -35,19 +35,21 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@commander-js/extra-typings": "^14.0.0",
|
|
37
37
|
"@hono/node-server": "^1.19.6",
|
|
38
|
+
"@libsql/client": "0.17.4",
|
|
38
39
|
"@lydell/node-pty": "1.2.0-beta.12",
|
|
39
40
|
"@modelcontextprotocol/sdk": "^1.24.0",
|
|
40
41
|
"@noble/ciphers": "2.2.0",
|
|
41
42
|
"@noble/curves": "2.2.0",
|
|
42
43
|
"@noble/hashes": "2.2.0",
|
|
43
44
|
"@openai/codex-sdk": "0.144.1",
|
|
44
|
-
"@tursodatabase/database": "^0.5.3",
|
|
45
45
|
"base64-js": "1.5.1",
|
|
46
46
|
"commander": "^14.0.3",
|
|
47
47
|
"es-git": "^0.6.0",
|
|
48
48
|
"hono": "^4.10.7",
|
|
49
|
+
"libsql": "0.5.29",
|
|
49
50
|
"picocolors": "^1.1.1",
|
|
50
51
|
"qrcode-terminal": "^0.12.0",
|
|
52
|
+
"ws": "8.21.0",
|
|
51
53
|
"zod": "^4.1.12"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|