dsh-lcx-codex 0.4.2 → 0.4.3-pre.2
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 +116 -202
- package/cordis.patch.yml +3 -20
- package/lib/client.js +273 -146
- package/lib/compact-v2.js +218 -199
- package/lib/dsh-compat.js +227 -100
- package/lib/dsh-responses.js +445 -277
- package/lib/index.js +851 -757
- package/lib/json-store.js +50 -31
- package/lib/native-checkpoint.js +520 -194
- package/lib/responses-request.js +106 -121
- package/lib/responses-stream.js +972 -443
- package/lib/route.js +229 -355
- package/lib/service-mutex.js +73 -64
- package/lib/token-budget.js +176 -108
- package/lib/transport.js +277 -67
- package/lib/types/client/index.d.ts +6 -0
- package/lib/types/compact-v2.d.ts +104 -0
- package/lib/types/dsh-compat.d.ts +78 -0
- package/lib/types/dsh-responses.d.ts +82 -0
- package/lib/types/index.d.ts +83 -0
- package/lib/types/json-store.d.ts +10 -0
- package/lib/types/native-checkpoint.d.ts +213 -0
- package/lib/types/responses-request.d.ts +58 -0
- package/lib/types/responses-stream.d.ts +51 -0
- package/lib/types/route.d.ts +132 -0
- package/lib/types/service-mutex.d.ts +14 -0
- package/lib/types/token-budget.d.ts +50 -0
- package/lib/types/transport.d.ts +20 -0
- package/lib/types/web-run-output.d.ts +29 -0
- package/lib/types/web-search-alpha.d.ts +286 -0
- package/lib/types/web-search-capability.d.ts +26 -0
- package/lib/types/web-search-hosted.d.ts +246 -0
- package/lib/types/web-search-ref-store.d.ts +22 -0
- package/lib/web-run-output.js +167 -18
- package/lib/web-search-alpha.js +865 -163
- package/lib/web-search-capability.js +55 -65
- package/lib/web-search-hosted.js +210 -32
- package/lib/web-search-ref-store.js +63 -59
- package/package.json +79 -27
- package/ARCHITECTURE.md +0 -117
- package/CHANGELOG.md +0 -224
- package/README_EN.md +0 -277
- package/assets/dsh-lcx-codex-banner.jpg +0 -0
- package/lib/legacy-v3.js +0 -20
- package/lib/responses-replay.js +0 -68
- package/scripts/probe-alpha.mjs +0 -43
- package/scripts/validate-dsh-schema.mjs +0 -31
package/lib/json-store.js
CHANGED
|
@@ -1,34 +1,53 @@
|
|
|
1
|
-
import { mkdirSync, readFileSync, renameSync, writeFileSync,
|
|
2
|
-
import { dirname } from
|
|
3
|
-
|
|
1
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
function errorCode(error) {
|
|
4
|
+
return error instanceof Error && "code" in error
|
|
5
|
+
? error.code
|
|
6
|
+
: undefined;
|
|
7
|
+
}
|
|
4
8
|
export class JsonStore {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
file;
|
|
10
|
+
empty;
|
|
11
|
+
validate;
|
|
12
|
+
corruptCode;
|
|
13
|
+
data;
|
|
14
|
+
constructor(file, empty, validate, corruptCode = "LCX_STORE_CORRUPT") {
|
|
15
|
+
this.file = file;
|
|
16
|
+
this.empty = empty;
|
|
17
|
+
this.validate = validate;
|
|
18
|
+
this.corruptCode = corruptCode;
|
|
19
|
+
this.data = empty();
|
|
20
|
+
this.refresh();
|
|
21
|
+
}
|
|
22
|
+
refresh() {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(readFileSync(this.file, "utf8"));
|
|
25
|
+
if (!this.validate(parsed))
|
|
26
|
+
throw new Error("invalid store");
|
|
27
|
+
this.data = parsed;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (errorCode(error) === "ENOENT") {
|
|
31
|
+
this.data = this.empty();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const wrapped = Object.assign(new Error(`Invalid LCX store ${this.file}`, { cause: error }), { code: this.corruptCode });
|
|
35
|
+
throw wrapped;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
update(mutator) {
|
|
39
|
+
this.refresh();
|
|
40
|
+
const next = mutator(structuredClone(this.data));
|
|
41
|
+
if (!this.validate(next))
|
|
42
|
+
throw new Error(`Refusing to write invalid LCX store ${this.file}`);
|
|
43
|
+
mkdirSync(dirname(this.file), { recursive: true });
|
|
44
|
+
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
45
|
+
writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
|
|
46
|
+
try {
|
|
47
|
+
chmodSync(tmp, 0o600);
|
|
48
|
+
}
|
|
49
|
+
catch { }
|
|
50
|
+
renameSync(tmp, this.file);
|
|
51
|
+
this.data = next;
|
|
21
52
|
}
|
|
22
|
-
}
|
|
23
|
-
update(mutator) {
|
|
24
|
-
this.refresh()
|
|
25
|
-
const next = mutator(structuredClone(this.data))
|
|
26
|
-
if (!this.validate(next)) throw new Error(`Refusing to write invalid LCX store ${this.file}`)
|
|
27
|
-
mkdirSync(dirname(this.file), { recursive: true })
|
|
28
|
-
const tmp = `${this.file}.${process.pid}.tmp`
|
|
29
|
-
writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 })
|
|
30
|
-
try { chmodSync(tmp, 0o600) } catch {}
|
|
31
|
-
renameSync(tmp, this.file)
|
|
32
|
-
this.data = next
|
|
33
|
-
}
|
|
34
53
|
}
|