dsh-theone 0.3.9 → 0.3.12

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 (44) hide show
  1. package/README.md +77 -53
  2. package/README.zh.md +82 -58
  3. package/cordis.patch.yml +0 -0
  4. package/dist/catalog-types.d.ts +0 -0
  5. package/dist/catalog-types.js +0 -0
  6. package/dist/client-locales.d.ts +11 -0
  7. package/dist/client-locales.js +22 -0
  8. package/dist/client-navigation.d.ts +0 -0
  9. package/dist/client-navigation.js +0 -0
  10. package/dist/client.d.ts +0 -0
  11. package/dist/client.js +130 -10
  12. package/dist/gateway-compaction.d.ts +0 -0
  13. package/dist/gateway-compaction.js +0 -0
  14. package/dist/history-catalog.d.ts +0 -0
  15. package/dist/history-catalog.js +0 -0
  16. package/dist/index.d.ts +13 -3
  17. package/dist/index.js +102 -22
  18. package/dist/linkage.d.ts +0 -0
  19. package/dist/linkage.js +0 -0
  20. package/dist/llm-router.d.ts +0 -0
  21. package/dist/llm-router.js +0 -0
  22. package/dist/model-json.d.ts +0 -0
  23. package/dist/model-json.js +0 -0
  24. package/dist/router.d.ts +0 -0
  25. package/dist/router.js +0 -0
  26. package/dist/routing-policy.d.ts +0 -0
  27. package/dist/routing-policy.js +0 -0
  28. package/dist/run.d.ts +0 -0
  29. package/dist/run.js +0 -0
  30. package/dist/settings-types.d.ts +0 -0
  31. package/dist/settings-types.js +0 -0
  32. package/dist/settings.d.ts +0 -0
  33. package/dist/settings.js +0 -0
  34. package/dist/store.d.ts +0 -0
  35. package/dist/store.js +0 -0
  36. package/dist/types.d.ts +0 -0
  37. package/dist/types.js +0 -0
  38. package/dist/update.d.ts +55 -0
  39. package/dist/update.js +121 -0
  40. package/docs/plugin-v0.1.md +0 -0
  41. package/docs/plugin-v0.1.zh.md +0 -0
  42. package/docs/plugin-v0.2.md +0 -0
  43. package/docs/plugin-v0.2.zh.md +0 -0
  44. package/package.json +1 -1
package/dist/update.js ADDED
@@ -0,0 +1,121 @@
1
+ export const REPOSITORY = 'YunongDai2005/dsh-theone';
2
+ export const PACKAGE_NAME = 'dsh-theone';
3
+ /** Compare dotted versions numerically; a pre-release sorts before its release. */
4
+ export function compareVersions(a, b) {
5
+ const parse = (value) => {
6
+ const [core, pre] = value.trim().replace(/^v/, '').split('-', 2);
7
+ return { parts: core.split('.').map(part => Number.parseInt(part, 10) || 0), pre };
8
+ };
9
+ const x = parse(a), y = parse(b);
10
+ for (let index = 0; index < Math.max(x.parts.length, y.parts.length); index++) {
11
+ const difference = (x.parts[index] ?? 0) - (y.parts[index] ?? 0);
12
+ if (difference)
13
+ return Math.sign(difference);
14
+ }
15
+ if (x.pre === y.pre)
16
+ return 0;
17
+ return x.pre === undefined ? 1 : y.pre === undefined ? -1 : x.pre < y.pre ? -1 : 1;
18
+ }
19
+ /** Read the dependency spec DSH saved for this plugin: GitHub, npm, or something else (a local path, a tarball). */
20
+ export function installSource(spec) {
21
+ if (!spec)
22
+ return 'other';
23
+ if (spec.toLowerCase().includes(REPOSITORY.toLowerCase()))
24
+ return 'github';
25
+ if (/^(?:npm:dsh-theone@)?[\^~>=<\s]*\d|^latest$|^\*$/.test(spec))
26
+ return 'npm';
27
+ return 'other';
28
+ }
29
+ const HOUR = 3600000;
30
+ /** Checks for a newer TheOne and installs it through DSH's own plugin manager. */
31
+ export class Updater {
32
+ current;
33
+ spec;
34
+ fetcher;
35
+ now;
36
+ checked;
37
+ state;
38
+ error;
39
+ pending;
40
+ constructor(current, spec, fetcher = fetch, now = Date.now) {
41
+ this.current = current;
42
+ this.spec = spec;
43
+ this.fetcher = fetcher;
44
+ this.now = now;
45
+ }
46
+ get source() { return installSource(this.spec()); }
47
+ /** The latest known status; checks again at most every six hours (or now, when forced). */
48
+ async status(force = false) {
49
+ const age = this.checked ? this.now() - this.checked.at : Infinity;
50
+ if (this.state !== 'installing' && (force || age > (this.checked?.error ? HOUR / 2 : 6 * HOUR))) {
51
+ this.pending ??= this.check().finally(() => { this.pending = undefined; });
52
+ await this.pending;
53
+ }
54
+ return this.snapshot();
55
+ }
56
+ /**
57
+ * Install the newer version. With `reload`, TheOne then restarts itself so the new version runs
58
+ * without restarting DSH; otherwise it is loaded the next time DSH starts.
59
+ */
60
+ async install(installer, reload) {
61
+ const status = await this.status();
62
+ if (!status.available || !status.installable || !installer || this.state === 'installing' || this.state === 'reloading' || this.state === 'restart')
63
+ return this.snapshot();
64
+ const spec = this.source === 'github' ? `github:${REPOSITORY}#${this.checked.sha}` : `${PACKAGE_NAME}@${this.checked.latest}`;
65
+ this.state = 'installing';
66
+ this.error = undefined;
67
+ try {
68
+ const result = await installer.installBundle(spec, { enabled: true });
69
+ if (result.application === 'applied' || result.application === 'restart-required') {
70
+ this.state = reload ? 'reloading' : 'restart';
71
+ reload?.(result.bundle ?? PACKAGE_NAME);
72
+ }
73
+ else {
74
+ this.state = 'failed';
75
+ const error = result.error;
76
+ this.error = String(error?.code ?? error?.message ?? result.application).slice(0, 120);
77
+ }
78
+ }
79
+ catch (error) {
80
+ this.state = 'failed';
81
+ this.error = (error instanceof Error ? error.message : String(error)).slice(0, 120);
82
+ }
83
+ return this.snapshot();
84
+ }
85
+ snapshot() {
86
+ const latest = this.checked?.latest;
87
+ const source = this.source;
88
+ const available = !!latest && compareVersions(latest, this.current) > 0;
89
+ return { current: this.current, ...(latest ? { latest } : {}), available, source,
90
+ installable: available && (source === 'npm' || (source === 'github' && !!this.checked?.sha)),
91
+ ...(this.state ? { state: this.state } : {}), ...(this.error ?? this.checked?.error ? { error: this.error ?? this.checked?.error } : {}) };
92
+ }
93
+ async check() {
94
+ const signal = AbortSignal.timeout(10000);
95
+ try {
96
+ if (this.source === 'npm') {
97
+ const response = await this.fetcher(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { signal });
98
+ if (!response.ok)
99
+ throw new Error(`npm ${response.status}`);
100
+ this.checked = { at: this.now(), latest: String((await response.json()).version ?? '') || undefined };
101
+ return;
102
+ }
103
+ // A GitHub install updates to the exact commit whose version was read.
104
+ const commit = await this.fetcher(`https://api.github.com/repos/${REPOSITORY}/commits/main`, { signal, headers: { accept: 'application/vnd.github.sha' } });
105
+ if (!commit.ok)
106
+ throw new Error(`GitHub ${commit.status}`);
107
+ const sha = (await commit.text()).trim();
108
+ if (!/^[0-9a-f]{40}$/.test(sha))
109
+ throw new Error('GitHub returned no commit');
110
+ const manifest = await this.fetcher(`https://raw.githubusercontent.com/${REPOSITORY}/${sha}/package.json`, { signal });
111
+ if (!manifest.ok)
112
+ throw new Error(`GitHub ${manifest.status}`);
113
+ const latest = String((await manifest.json()).version ?? '') || undefined;
114
+ this.checked = { at: this.now(), latest, sha };
115
+ }
116
+ catch (error) {
117
+ // Offline or rate-limited: keep what was known and try again later.
118
+ this.checked = { ...this.checked, at: this.now(), error: (error instanceof Error ? error.message : String(error)).slice(0, 120) };
119
+ }
120
+ }
121
+ }
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-theone",
3
- "version": "0.3.9",
3
+ "version": "0.3.12",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Automatic context routing for DeepSeek Harness",