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