@chatcode/chatcode-cli 3.0.4-rc.1 → 3.0.4-rc.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 (123) hide show
  1. package/lib/{command-errors-BkCHTQHj.js → command-errors-CScdshCl.js} +12 -12
  2. package/lib/{command-trees-5HFyC5sI.js → command-trees-Dc17MYfV.js} +2 -2
  3. package/lib/{component-identity-De91VHwW.js → component-identity-DFJD_d-P.js} +3 -3
  4. package/lib/{dist-CsDWUvQ4.js → dist-w_sIm4VD.js} +231 -231
  5. package/lib/{extension-events-CdYCRP0o.js → extension-events-qXmhzmHo.js} +26 -26
  6. package/lib/{frames-DOX-Jgk8.js → frames-B89znn_0.js} +4 -4
  7. package/lib/{host-access-Bk4xps5E.js → host-access-B0CRAwsX.js} +1 -1
  8. package/lib/{keymap-CJ1kvLR2.js → keymap-CIoVICBI.js} +2 -2
  9. package/lib/{plugin-XR7ncbnW.js → plugin-BKQsL2xn.js} +1638 -1363
  10. package/lib/{scenes-CAmWncZD.js → scenes-BRf-zMpF.js} +3 -3
  11. package/lib/{settings-sections-CakcvBv9.js → settings-sections-4gMhveN_.js} +3 -3
  12. package/lib/{statusBarSettings-BPPS_Usm.js → statusBarSettings-CnmdSHkO.js} +3 -3
  13. package/lib/{supports-color-DyChQwlI.js → supports-color-CcW-FGjr.js} +2 -2
  14. package/lib/{themes-OjcUpZzw.js → themes-Ce97Zsri.js} +12 -12
  15. package/lib/tui-compat-command-trees.js +1 -1
  16. package/lib/tui-compat-extensions.js +3 -3
  17. package/lib/tui-compat-plugin-host.js +5 -5
  18. package/lib/tui-compat-scenes.js +1 -1
  19. package/lib/tui-compat-settings-sections.js +1 -1
  20. package/lib/tui-compat-working-activity.js +4 -4
  21. package/lib/tui-compat-workspaces.js +1 -1
  22. package/lib/tui-compat.js +5 -5
  23. package/lib/{workspaces-XY7UdfXp.js → workspaces-1xrm-e3V.js} +2 -2
  24. package/package.json +29 -28
  25. package/runtime/manifest.json +2 -2
  26. package/runtime/node_modules/@deepseek-ai/dsh-agent-default-model/lib/index.js +118 -22
  27. package/runtime/node_modules/@deepseek-ai/dsh-agent-default-model/lib/types/index.d.ts +20 -3
  28. package/runtime/node_modules/@deepseek-ai/dsh-api-remotes/lib/client.js +113 -39
  29. package/runtime/node_modules/@deepseek-ai/dsh-api-remotes/lib/index.js +4 -0
  30. package/runtime/node_modules/@deepseek-ai/dsh-api-remotes/lib/types/remote-events.d.ts +3 -0
  31. package/runtime/node_modules/@deepseek-ai/dsh-api-remotes/lib/types/remote-events.js +1 -0
  32. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/index.js +173 -34
  33. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/typert.host.js +48 -28
  34. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/typert.remote-client.js +24 -19
  35. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/agent.d.ts +9 -1
  36. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/agent.js +36 -6
  37. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/archived-session-gate.js +1 -1
  38. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/catalog.js +4 -1
  39. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/client/sessions/service.d.ts +1 -1
  40. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/commands.d.ts +2 -2
  41. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/commands.js +24 -8
  42. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/index.d.ts +4 -3
  43. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/index.js +31 -14
  44. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/list.d.ts +6 -0
  45. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/list.js +89 -4
  46. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/remote-events.d.ts +1 -1
  47. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/types/types.d.ts +18 -1
  48. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/client.js +30 -0
  49. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/index.js +83 -2
  50. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/typert.host.js +104 -11
  51. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/typert.remote-client.d.ts +5 -1
  52. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/typert.remote-client.js +78 -11
  53. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/types/client/model.d.ts +14 -1
  54. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/types/client/model.js +17 -0
  55. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/types/client/service.d.ts +15 -0
  56. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/types/client/service.js +12 -0
  57. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/types/commands.d.ts +13 -1
  58. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/types/commands.js +44 -2
  59. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/types/index.d.ts +13 -1
  60. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/types/index.js +22 -0
  61. package/runtime/node_modules/@deepseek-ai/dsh-api-workspace-controller/lib/types/types.d.ts +17 -0
  62. package/runtime/node_modules/@deepseek-ai/dsh-client-hmr/lib/client.js +931 -7
  63. package/runtime/node_modules/@deepseek-ai/dsh-client-hmr/lib/index.js +57 -19
  64. package/runtime/node_modules/@deepseek-ai/dsh-client-hmr/lib/types/client/index.d.ts +5 -2
  65. package/runtime/node_modules/@deepseek-ai/dsh-client-hmr/lib/types/config.d.ts +12 -0
  66. package/runtime/node_modules/@deepseek-ai/dsh-client-hmr/lib/types/events.d.ts +4 -4
  67. package/runtime/node_modules/@deepseek-ai/dsh-client-hmr/lib/types/index.d.ts +3 -8
  68. package/runtime/node_modules/@deepseek-ai/dsh-client-hmr/package.json +6 -2
  69. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-commands/lib/client.js +10 -0
  70. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-deliverables/lib/types/client/present-open.d.ts +1 -1
  71. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-model-selection/lib/client.js +8 -4
  72. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-settings-account/lib/client.js +2 -2
  73. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-settings-general/lib/client.js +1 -1
  74. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +3 -1
  75. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/client.js +1917 -206
  76. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/types/client/ArchivedSessions.d.ts +13 -0
  77. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/types/client/contract/slots.d.ts +4 -0
  78. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/types/client/locales.d.ts +40 -0
  79. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/types/client/recent.d.ts +11 -0
  80. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/types/client/rows/RecentList.d.ts +15 -0
  81. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/types/client/rows/Rows.d.ts +6 -1
  82. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/types/client/session-actions/DeleteSession.d.ts +24 -0
  83. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/types/client/stores.d.ts +2 -2
  84. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/types/client/tree.d.ts +15 -13
  85. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-workspace/package.json +3 -1
  86. package/runtime/node_modules/@deepseek-ai/dsh-commands/lib/index.js +16 -0
  87. package/runtime/node_modules/@deepseek-ai/dsh-commands/lib/typert.host.js +7 -3
  88. package/runtime/node_modules/@deepseek-ai/dsh-commands/lib/typert.remote-client.js +6 -2
  89. package/runtime/node_modules/@deepseek-ai/dsh-commands/lib/types/index.js +20 -0
  90. package/runtime/node_modules/@deepseek-ai/dsh-commands/lib/types/types.d.ts +5 -0
  91. package/runtime/node_modules/@deepseek-ai/dsh-cordis-client-runner/lib/client.js +5 -2
  92. package/runtime/node_modules/@deepseek-ai/dsh-schedule/lib/index.js +4 -0
  93. package/runtime/node_modules/@deepseek-ai/dsh-schedule/lib/typert.host.js +5 -5
  94. package/runtime/node_modules/@deepseek-ai/dsh-schedule/lib/typert.remote-client.js +5 -5
  95. package/runtime/node_modules/@deepseek-ai/dsh-schedule/lib/types/index.js +5 -0
  96. package/runtime/node_modules/@deepseek-ai/dsh-session/lib/types/index.d.ts +21 -0
  97. package/runtime/node_modules/@deepseek-ai/dsh-session-persistence/lib/index.js +12 -0
  98. package/runtime/node_modules/@deepseek-ai/dsh-session-persistence/lib/types/index.d.ts +15 -0
  99. package/runtime/node_modules/@deepseek-ai/dsh-session-persistence-jsonl/lib/index.js +95 -2
  100. package/runtime/node_modules/@deepseek-ai/dsh-session-persistence-jsonl/lib/types/index.d.ts +3 -1
  101. package/runtime/node_modules/@deepseek-ai/dsh-session-projection-cache/lib/index.js +25 -1
  102. package/runtime/node_modules/@deepseek-ai/dsh-session-projection-cache/lib/types/index.d.ts +1 -0
  103. package/runtime/node_modules/@deepseek-ai/dsh-session-projection-cache/package.json +2 -1
  104. package/runtime/node_modules/@deepseek-ai/dsh-session-query/lib/index.js +13 -0
  105. package/runtime/node_modules/@deepseek-ai/dsh-session-query/lib/types/observation.d.ts +5 -0
  106. package/runtime/node_modules/@deepseek-ai/dsh-session-query-sqlite/lib/index.js +26 -0
  107. package/runtime/node_modules/@deepseek-ai/dsh-session-query-sqlite/package.json +2 -1
  108. package/runtime/node_modules/@deepseek-ai/dsh-storage-domain/lib/index.js +5 -1
  109. package/runtime/node_modules/@deepseek-ai/dsh-storage-domain/lib/types/domain.d.ts +2 -2
  110. package/runtime/node_modules/@deepseek-ai/dsh-subagent/lib/types/control.d.ts +1 -1
  111. package/runtime/node_modules/@deepseek-ai/dsh-tianti/lib/index.js +106 -56
  112. package/runtime/node_modules/@deepseek-ai/dsh-tianti/lib/types/config.d.ts +2 -2
  113. package/runtime/node_modules/@deepseek-ai/dsh-tianti/lib/types/index.d.ts +2 -1
  114. package/runtime/node_modules/@deepseek-ai/dsh-tianti/lib/types/services/tianti/config.d.ts +4 -2
  115. package/runtime/node_modules/@deepseek-ai/dsh-tianti/lib/types/tools.d.ts +2 -2
  116. package/runtime/node_modules/@deepseek-ai/dsh-tianti/package.json +2 -0
  117. package/runtime/node_modules/@deepseek-ai/dsh-tool-cordis/lib/types/api-catalog.js +103 -12
  118. package/runtime/node_modules/@deepseek-ai/dsh-workspace/lib/index.js +215 -4
  119. package/runtime/node_modules/@deepseek-ai/dsh-workspace/lib/invariant.js +6 -1
  120. package/runtime/node_modules/@deepseek-ai/dsh-workspace/lib/types/index.d.ts +31 -0
  121. package/runtime/node_modules/@deepseek-ai/dsh-workspace/lib/types/index.js +219 -2
  122. package/runtime/node_modules/@deepseek-ai/dsh-workspace/lib/types/spec.d.ts +4 -0
  123. package/runtime/node_modules/@deepseek-ai/dsh-workspace/lib/types/spec.js +4 -0
@@ -6,14 +6,14 @@ window.__ModuleLoader__.load({
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
7
  //#region lib/types/events.js
8
8
  /**
9
- * Wire protocol of the `/plugins/events` SSE channel — single source for
9
+ * Wire protocol of the `/plugins/events` WebSocket and legacy SSE channel — single source for
10
10
  * both halves of this package. Frames still cross a wire boundary: the
11
11
  * browser half validates them at its JSON parse point; sharing the type keeps
12
12
  * the two ends from drifting, not from parsing.
13
13
  */
14
14
  /**
15
15
  * Validate the frame envelope; the module controller parses the complete graph before updating its index.
16
- * @param value - Parsed JSON value from the EventSource message.
16
+ * @param value - Parsed JSON value from the transport message.
17
17
  * @returns the known frame, an unknown-type marker, or an invalid marker.
18
18
  */
19
19
  function parsePluginsEventFrame(value) {
@@ -44,6 +44,905 @@ window.__ModuleLoader__.load({
44
44
  */
45
45
  const EVENTS_ROUTE = "/plugins/events".slice(1);
46
46
  //#endregion
47
+ //#region ../../../vendor/cosmokit/src/misc.ts
48
+ /** Return true when a value is `null` or `undefined`. */
49
+ function isNullable(value) {
50
+ return value === null || value === void 0;
51
+ }
52
+ /** Return true for non-array object values. */
53
+ function isPlainObject(data) {
54
+ return data && typeof data === "object" && !Array.isArray(data);
55
+ }
56
+ /** Filter object entries and return a new object. */
57
+ function filterKeys(object, filter) {
58
+ return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
59
+ }
60
+ /** Map object values while preserving the original key set. */
61
+ function mapValues(object, transform) {
62
+ return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
63
+ }
64
+ /** Pick selected keys from an object, optionally including `undefined` values. */
65
+ function pick(source, keys, forced) {
66
+ if (!keys) return { ...source };
67
+ const result = {};
68
+ for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
69
+ return result;
70
+ }
71
+ //#endregion
72
+ //#region ../../../vendor/cosmokit/src/volatile.ts
73
+ /** Shared config references used by schema validators and plugin runtimes. */
74
+ const write = Symbol.for("cosmokit.volatile.write");
75
+ function snapshot(value, ancestors = /* @__PURE__ */ new Set()) {
76
+ if (typeof value === "function") throw new TypeError("volatile config cannot contain functions");
77
+ if (value === null || typeof value !== "object") return value;
78
+ if (ancestors.has(value)) throw new TypeError("volatile config cannot contain cycles");
79
+ ancestors.add(value);
80
+ try {
81
+ if (Array.isArray(value)) return Object.freeze(value.map((item) => snapshot(item, ancestors)));
82
+ if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new TypeError("volatile config objects must be plain objects or arrays");
83
+ return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item, ancestors)])));
84
+ } finally {
85
+ ancestors.delete(value);
86
+ }
87
+ }
88
+ /**
89
+ * Create a detached reference containing an immutable copy of the supplied data.
90
+ * @param value - validated config data; class instances and functions are unsupported.
91
+ * @returns a reference whose value is updated only by its owning runtime.
92
+ */
93
+ function createVolatile(value) {
94
+ let current = snapshot(value);
95
+ return Object.freeze({
96
+ get: () => current,
97
+ [write]: (value) => {
98
+ current = value;
99
+ }
100
+ });
101
+ }
102
+ /**
103
+ * Identify references across ESM/CJS copies of the shared library.
104
+ * @param value - a parsed config value.
105
+ * @returns whether the value implements the shared reference protocol.
106
+ */
107
+ function isVolatile(value) {
108
+ return typeof value === "object" && value !== null && write in value;
109
+ }
110
+ //#endregion
111
+ //#region ../../../vendor/cosmokit/src/types.ts
112
+ /** Test values using `instanceof` with a `toStringTag` fallback. */
113
+ function is(type, value) {
114
+ if (arguments.length === 1) return (value) => is(type, value);
115
+ return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
116
+ }
117
+ function isArrayBufferLike(value) {
118
+ return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
119
+ }
120
+ function isArrayBufferSource(value) {
121
+ return isArrayBufferLike(value) || ArrayBuffer.isView(value);
122
+ }
123
+ let Binary;
124
+ (function(_Binary) {
125
+ _Binary.is = isArrayBufferLike;
126
+ _Binary.isSource = isArrayBufferSource;
127
+ function fromSource(source) {
128
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
129
+ else return source;
130
+ }
131
+ _Binary.fromSource = fromSource;
132
+ function toBase64(source) {
133
+ source = fromSource(source);
134
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
135
+ let binary = "";
136
+ const bytes = new Uint8Array(source);
137
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
138
+ return btoa(binary);
139
+ }
140
+ _Binary.toBase64 = toBase64;
141
+ function fromBase64(source) {
142
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
143
+ return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
144
+ }
145
+ _Binary.fromBase64 = fromBase64;
146
+ function toHex(source) {
147
+ source = fromSource(source);
148
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
149
+ return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
150
+ }
151
+ _Binary.toHex = toHex;
152
+ function fromHex(source) {
153
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
154
+ const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
155
+ const buffer = [];
156
+ for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
157
+ return Uint8Array.from(buffer).buffer;
158
+ }
159
+ _Binary.fromHex = fromHex;
160
+ })(Binary || (Binary = {}));
161
+ Binary.fromBase64;
162
+ Binary.toBase64;
163
+ Binary.fromHex;
164
+ Binary.toHex;
165
+ /** Deep-clone common JavaScript values while preserving prototypes and cycles. */
166
+ function clone(source, refs = /* @__PURE__ */ new Map()) {
167
+ if (!source || typeof source !== "object") return source;
168
+ if (is("Date", source)) return new Date(source.valueOf());
169
+ if (is("RegExp", source)) return new RegExp(source.source, source.flags);
170
+ if (isArrayBufferLike(source)) return source.slice(0);
171
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
172
+ const cached = refs.get(source);
173
+ if (cached) return cached;
174
+ if (Array.isArray(source)) {
175
+ const result = [];
176
+ refs.set(source, result);
177
+ source.forEach((value, index) => {
178
+ result[index] = Reflect.apply(clone, null, [value, refs]);
179
+ });
180
+ return result;
181
+ }
182
+ const result = Object.create(Object.getPrototypeOf(source));
183
+ refs.set(source, result);
184
+ for (const key of Reflect.ownKeys(source)) {
185
+ const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
186
+ if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
187
+ Reflect.defineProperty(result, key, descriptor);
188
+ }
189
+ return result;
190
+ }
191
+ /**
192
+ * Compare values recursively, treating two volatile references as equal regardless of value.
193
+ * Strict comparison distinguishes null/undefined, treats opaque objects by identity,
194
+ * compares URLs by normalized href, treats array holes as undefined, and considers distinct cyclic structures unequal.
195
+ * @param a - first value.
196
+ * @param b - second value.
197
+ * @param strict - whether to require strict data equality outside volatile references.
198
+ * @returns whether the values compare equal.
199
+ */
200
+ function deepEqual(a, b, strict) {
201
+ const ancestors = /* @__PURE__ */ new Set();
202
+ function compare(a, b) {
203
+ if (a === b) return true;
204
+ if (isVolatile(a) || isVolatile(b)) return isVolatile(a) && isVolatile(b);
205
+ if (!strict && isNullable(a) && isNullable(b)) return true;
206
+ if (typeof a !== typeof b || typeof a !== "object" || !a || !b) return false;
207
+ if (ancestors.has(a)) return false;
208
+ function check(test, then) {
209
+ return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
210
+ }
211
+ ancestors.add(a);
212
+ try {
213
+ return check(Array.isArray, (a, b) => {
214
+ if (a.length !== b.length) return false;
215
+ for (let index = 0; index < a.length; index++) if (!compare(a[index], b[index])) return false;
216
+ return true;
217
+ }) ?? check(is("Date"), (a, b) => a.valueOf() === b.valueOf()) ?? check(is("URL"), (a, b) => a.href === b.href) ?? check(is("RegExp"), (a, b) => a.source === b.source && a.flags === b.flags) ?? check(isArrayBufferLike, (a, b) => {
218
+ if (a.byteLength !== b.byteLength) return false;
219
+ const viewA = new Uint8Array(a);
220
+ const viewB = new Uint8Array(b);
221
+ for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
222
+ return true;
223
+ }) ?? ((!strict || [a, b].every((value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) && Object.keys({
224
+ ...a,
225
+ ...b
226
+ }).every((key) => compare(a[key], b[key])));
227
+ } finally {
228
+ ancestors.delete(a);
229
+ }
230
+ }
231
+ return compare(a, b);
232
+ }
233
+ //#endregion
234
+ //#region ../../../vendor/cosmokit/src/time.ts
235
+ let Time;
236
+ (function(_Time) {
237
+ _Time.millisecond = 1;
238
+ const second = _Time.second = 1e3;
239
+ const minute = _Time.minute = second * 60;
240
+ const hour = _Time.hour = minute * 60;
241
+ const day = _Time.day = hour * 24;
242
+ const week = _Time.week = day * 7;
243
+ let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
244
+ function setTimezoneOffset(offset) {
245
+ timezoneOffset = offset;
246
+ }
247
+ _Time.setTimezoneOffset = setTimezoneOffset;
248
+ function getTimezoneOffset() {
249
+ return timezoneOffset;
250
+ }
251
+ _Time.getTimezoneOffset = getTimezoneOffset;
252
+ function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
253
+ if (typeof date === "number") date = new Date(date);
254
+ if (offset === void 0) offset = timezoneOffset;
255
+ return Math.floor((date.valueOf() / minute - offset) / 1440);
256
+ }
257
+ _Time.getDateNumber = getDateNumber;
258
+ function fromDateNumber(value, offset) {
259
+ const date = new Date(value * day);
260
+ if (offset === void 0) offset = timezoneOffset;
261
+ return new Date(+date + offset * minute);
262
+ }
263
+ _Time.fromDateNumber = fromDateNumber;
264
+ const numeric = /\d+(?:\.\d+)?/.source;
265
+ const timeRegExp = new RegExp(`^${[
266
+ "w(?:eek(?:s)?)?",
267
+ "d(?:ay(?:s)?)?",
268
+ "h(?:our(?:s)?)?",
269
+ "m(?:in(?:ute)?(?:s)?)?",
270
+ "s(?:ec(?:ond)?(?:s)?)?"
271
+ ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
272
+ function parseTime(source) {
273
+ const capture = timeRegExp.exec(source);
274
+ if (!capture) return 0;
275
+ return (parseFloat(capture[1]) * week || 0) + (parseFloat(capture[2]) * day || 0) + (parseFloat(capture[3]) * hour || 0) + (parseFloat(capture[4]) * minute || 0) + (parseFloat(capture[5]) * second || 0);
276
+ }
277
+ _Time.parseTime = parseTime;
278
+ function parseDate(date) {
279
+ const parsed = parseTime(date);
280
+ if (parsed) date = Date.now() + parsed;
281
+ else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
282
+ else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
283
+ return date ? new Date(date) : /* @__PURE__ */ new Date();
284
+ }
285
+ _Time.parseDate = parseDate;
286
+ function format(ms) {
287
+ const abs = Math.abs(ms);
288
+ if (abs >= day - hour / 2) return Math.round(ms / day) + "d";
289
+ else if (abs >= hour - minute / 2) return Math.round(ms / hour) + "h";
290
+ else if (abs >= minute - second / 2) return Math.round(ms / minute) + "m";
291
+ else if (abs >= second) return Math.round(ms / second) + "s";
292
+ return ms + "ms";
293
+ }
294
+ _Time.format = format;
295
+ function toDigits(source, length = 2) {
296
+ return source.toString().padStart(length, "0");
297
+ }
298
+ _Time.toDigits = toDigits;
299
+ function template(template, time = /* @__PURE__ */ new Date()) {
300
+ return template.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
301
+ }
302
+ _Time.template = template;
303
+ })(Time || (Time = {}));
304
+ //#endregion
305
+ //#region ../../../vendor/schemastery/src/index.ts
306
+ const kSchema = Symbol.for("schemastery");
307
+ const kValidationError = Symbol.for("ValidationError");
308
+ globalThis.__schemastery_index__ ??= 0;
309
+ globalThis.__schemastery_refs__ = void 0;
310
+ var ValidationError = class extends TypeError {
311
+ options;
312
+ name = "ValidationError";
313
+ constructor(message, options) {
314
+ let prefix = "$";
315
+ for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
316
+ else if (typeof segment === "number") prefix += "[" + segment + "]";
317
+ else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
318
+ if (prefix.startsWith(".")) prefix = prefix.slice(1);
319
+ super((prefix === "$" ? "" : `${prefix} `) + message);
320
+ this.options = options;
321
+ }
322
+ static is(error) {
323
+ return !!error?.[kValidationError];
324
+ }
325
+ };
326
+ Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
327
+ const Schema = function(options) {
328
+ const schema = function(data, options = {}) {
329
+ return Schema.resolve(data, schema, options)[0];
330
+ };
331
+ if (options.refs) {
332
+ const refs = mapValues(options.refs, (options) => new Schema(options));
333
+ const getRef = (uid) => refs[uid];
334
+ for (const key in refs) {
335
+ const options = refs[key];
336
+ options.sKey = getRef(options.sKey);
337
+ options.inner = getRef(options.inner);
338
+ options.list = options.list && options.list.map(getRef);
339
+ options.dict = options.dict && mapValues(options.dict, getRef);
340
+ }
341
+ return refs[options.uid];
342
+ }
343
+ Object.assign(schema, options);
344
+ if (typeof schema.callback === "string") try {
345
+ schema.callback = new Function("return " + schema.callback)();
346
+ } catch {}
347
+ Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
348
+ Object.setPrototypeOf(schema, Schema.prototype);
349
+ schema.meta ||= {};
350
+ schema.toString = schema.toString.bind(schema);
351
+ return schema;
352
+ };
353
+ Schema.prototype = Object.create(Function.prototype);
354
+ Schema.prototype[kSchema] = true;
355
+ Object.defineProperty(Schema.prototype, "~standard", { get() {
356
+ return {
357
+ version: 1,
358
+ vendor: "schemastery",
359
+ validate: (value) => {
360
+ try {
361
+ return { value: Schema.resolve(value, this, {})[0] };
362
+ } catch (error) {
363
+ if (ValidationError.is(error)) return { issues: [{
364
+ message: error.message,
365
+ path: error.options.path
366
+ }] };
367
+ throw error;
368
+ }
369
+ }
370
+ };
371
+ } });
372
+ Schema.ValidationError = ValidationError;
373
+ Schema.prototype.toJSON = function toJSON() {
374
+ if (globalThis.__schemastery_refs__) {
375
+ globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
376
+ return this.uid;
377
+ }
378
+ globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
379
+ globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
380
+ const result = {
381
+ uid: this.uid,
382
+ refs: globalThis.__schemastery_refs__
383
+ };
384
+ globalThis.__schemastery_refs__ = void 0;
385
+ return result;
386
+ };
387
+ Schema.prototype.set = function set(key, value) {
388
+ this.dict[key] = value;
389
+ return this;
390
+ };
391
+ Schema.prototype.push = function push(value) {
392
+ this.list.push(value);
393
+ return this;
394
+ };
395
+ function mergeDesc(original, messages) {
396
+ const result = typeof original === "string" ? { "": original } : { ...original };
397
+ for (const locale in messages) {
398
+ const value = messages[locale];
399
+ if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
400
+ else if (typeof value === "string") result[locale] = value;
401
+ }
402
+ return result;
403
+ }
404
+ function getInner(value) {
405
+ return value?.$value ?? value?.$inner;
406
+ }
407
+ function extractKeys(data) {
408
+ return filterKeys(data ?? {}, (key) => !key.startsWith("$"));
409
+ }
410
+ Schema.prototype.i18n = function i18n(messages) {
411
+ const schema = Schema(this);
412
+ const desc = mergeDesc(schema.meta.description, messages);
413
+ if (Object.keys(desc).length) schema.meta.description = desc;
414
+ if (schema.dict) schema.dict = mapValues(schema.dict, (inner, key) => {
415
+ return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
416
+ });
417
+ if (schema.list) schema.list = schema.list.map((inner, index) => {
418
+ return inner.i18n(mapValues(messages, (data = {}) => {
419
+ if (Array.isArray(getInner(data))) return getInner(data)[index];
420
+ if (Array.isArray(data)) return data[index];
421
+ return extractKeys(data);
422
+ }));
423
+ });
424
+ if (schema.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
425
+ if (getInner(data)) return getInner(data);
426
+ return extractKeys(data);
427
+ }));
428
+ if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
429
+ return schema;
430
+ };
431
+ Schema.prototype.extra = function extra(key, value) {
432
+ const schema = Schema(this);
433
+ schema.meta = {
434
+ ...schema.meta,
435
+ [key]: value
436
+ };
437
+ return schema;
438
+ };
439
+ for (const key of [
440
+ "required",
441
+ "disabled",
442
+ "collapse",
443
+ "hidden",
444
+ "loose"
445
+ ]) Object.assign(Schema.prototype, { [key](value = true) {
446
+ const schema = Schema(this);
447
+ schema.meta = {
448
+ ...schema.meta,
449
+ [key]: value
450
+ };
451
+ return schema;
452
+ } });
453
+ Schema.prototype.deprecated = function deprecated() {
454
+ const schema = Schema(this);
455
+ schema.meta.badges ||= [];
456
+ schema.meta.badges.push({
457
+ text: "deprecated",
458
+ type: "danger"
459
+ });
460
+ return schema;
461
+ };
462
+ Schema.prototype.experimental = function experimental() {
463
+ const schema = Schema(this);
464
+ schema.meta.badges ||= [];
465
+ schema.meta.badges.push({
466
+ text: "experimental",
467
+ type: "warning"
468
+ });
469
+ return schema;
470
+ };
471
+ Schema.prototype.pattern = function pattern(regexp) {
472
+ const schema = Schema(this);
473
+ const pattern = pick(regexp, ["source", "flags"]);
474
+ schema.meta = {
475
+ ...schema.meta,
476
+ pattern
477
+ };
478
+ return schema;
479
+ };
480
+ Schema.prototype.simplify = function simplify(value) {
481
+ if (isVolatile(value)) value = value.get();
482
+ if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
483
+ if (isNullable(value)) return value;
484
+ if (this.type === "object" || this.type === "dict") {
485
+ const result = {};
486
+ for (const key in value) {
487
+ const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
488
+ if (this.type === "dict" || !isNullable(item)) result[key] = item;
489
+ }
490
+ if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
491
+ return result;
492
+ } else if (this.type === "array" || this.type === "tuple") {
493
+ const result = [];
494
+ value.forEach((value, index) => {
495
+ const schema = this.type === "array" ? this.inner : this.list[index];
496
+ const item = schema ? schema.simplify(value) : value;
497
+ result.push(item);
498
+ });
499
+ return result;
500
+ } else if (this.type === "intersect") {
501
+ const result = {};
502
+ for (const item of this.list) Object.assign(result, item.simplify(value));
503
+ return result;
504
+ } else if (this.type === "union") for (const schema of this.list) try {
505
+ Schema.resolve(value, schema, {});
506
+ return schema.simplify(value);
507
+ } catch {}
508
+ return value;
509
+ };
510
+ Schema.prototype.toString = function toString(inline) {
511
+ return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
512
+ };
513
+ Schema.prototype.role = function role(role, extra) {
514
+ const schema = Schema(this);
515
+ schema.meta = {
516
+ ...schema.meta,
517
+ role,
518
+ extra
519
+ };
520
+ return schema;
521
+ };
522
+ for (const key of [
523
+ "default",
524
+ "link",
525
+ "comment",
526
+ "description",
527
+ "max",
528
+ "min",
529
+ "step"
530
+ ]) Object.assign(Schema.prototype, { [key](value) {
531
+ const schema = Schema(this);
532
+ schema.meta = {
533
+ ...schema.meta,
534
+ [key]: value
535
+ };
536
+ return schema;
537
+ } });
538
+ Schema.prototype.volatile = function volatile() {
539
+ if (this.meta.volatile) throw new TypeError("volatile schema is already wrapped");
540
+ return this.extra("volatile", true);
541
+ };
542
+ const resolvers = {};
543
+ const checkedVolatile = Symbol("checked-volatile-schema");
544
+ function validateVolatileSchema(schema, path = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
545
+ const states = seen.get(schema) ?? /* @__PURE__ */ new Set();
546
+ if (states.has(blocked)) return;
547
+ states.add(blocked);
548
+ seen.set(schema, states);
549
+ if (schema.meta?.volatile && blocked) throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path });
550
+ const nested = blocked || !!schema.meta?.volatile;
551
+ if (schema.dict) for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path, key], nested, seen);
552
+ if (schema.sKey) validateVolatileSchema(schema.sKey, [...path, "<key>"], true, seen);
553
+ if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) validateVolatileSchema(schema.inner, [...path, "*"], true, seen);
554
+ if (schema.list) for (let index = 0; index < schema.list.length; index++) validateVolatileSchema(schema.list[index], [...path, String(index)], true, seen);
555
+ }
556
+ Schema.extend = function extend(type, resolve) {
557
+ resolvers[type] = resolve;
558
+ };
559
+ Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
560
+ if (!schema) return [data];
561
+ if (!options[checkedVolatile]) {
562
+ validateVolatileSchema(schema, options.path);
563
+ options = {
564
+ ...options,
565
+ [checkedVolatile]: true
566
+ };
567
+ }
568
+ if (schema.meta?.volatile) {
569
+ const inner = Schema(schema);
570
+ inner.meta = {
571
+ ...schema.meta,
572
+ volatile: false
573
+ };
574
+ const [value, adapted] = Schema.resolve(data, inner, options, strict);
575
+ try {
576
+ return [createVolatile(value), adapted];
577
+ } catch (error) {
578
+ throw new ValidationError(error instanceof Error ? error.message : String(error), options);
579
+ }
580
+ }
581
+ if (options.ignore?.(data, schema)) return [data];
582
+ if (isNullable(data) && schema.type !== "lazy") {
583
+ if (schema.meta.required) throw new ValidationError(`missing required value`, options);
584
+ let current = schema;
585
+ let fallback = schema.meta.default;
586
+ while (current?.type === "intersect" && isNullable(fallback)) {
587
+ current = current.list[0];
588
+ fallback = current?.meta.default;
589
+ }
590
+ if (isNullable(fallback)) return [data];
591
+ data = clone(fallback);
592
+ }
593
+ const callback = resolvers[schema.type];
594
+ if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
595
+ try {
596
+ return callback(data, schema, options, strict);
597
+ } catch (error) {
598
+ if (!schema.meta.loose) throw error;
599
+ return [schema.meta.default];
600
+ }
601
+ };
602
+ Schema.from = function from(source) {
603
+ if (isNullable(source)) return Schema.any();
604
+ else if ([
605
+ "string",
606
+ "number",
607
+ "boolean"
608
+ ].includes(typeof source)) return Schema.const(source).required();
609
+ else if (source[kSchema]) return source;
610
+ else if (typeof source === "function") switch (source) {
611
+ case String: return Schema.string().required();
612
+ case Number: return Schema.number().required();
613
+ case Boolean: return Schema.boolean().required();
614
+ case Function: return Schema.function().required();
615
+ default: return Schema.is(source).required();
616
+ }
617
+ else throw new TypeError(`cannot infer schema from ${source}`);
618
+ };
619
+ Schema.lazy = function lazy(builder) {
620
+ const toJSON = () => {
621
+ if (!schema.inner[kSchema]) {
622
+ schema.inner = schema.builder();
623
+ schema.inner.meta = {
624
+ ...schema.meta,
625
+ ...schema.inner.meta
626
+ };
627
+ }
628
+ return schema.inner.toJSON();
629
+ };
630
+ const schema = new Schema({
631
+ type: "lazy",
632
+ builder,
633
+ inner: { toJSON }
634
+ });
635
+ return schema;
636
+ };
637
+ Schema.natural = function natural() {
638
+ return Schema.number().step(1).min(0);
639
+ };
640
+ Schema.percent = function percent() {
641
+ return Schema.number().step(.01).min(0).max(1).role("slider");
642
+ };
643
+ Schema.date = function date() {
644
+ return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
645
+ const date = new Date(value);
646
+ if (isNaN(+date)) throw new ValidationError(`invalid date "${value}"`, options);
647
+ return date;
648
+ }, true)]);
649
+ };
650
+ Schema.regExp = function regExp(flag = "") {
651
+ return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
652
+ try {
653
+ return new RegExp(value, flag);
654
+ } catch (e) {
655
+ throw new ValidationError(e.message, options);
656
+ }
657
+ }, true)]);
658
+ };
659
+ Schema.arrayBuffer = function arrayBuffer(encoding) {
660
+ return Schema.union([
661
+ Schema.is(ArrayBuffer),
662
+ Schema.is(SharedArrayBuffer),
663
+ Schema.transform(Schema.any(), (value, options) => {
664
+ if (Binary.isSource(value)) return Binary.fromSource(value);
665
+ throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
666
+ }, true),
667
+ ...encoding ? [Schema.transform(Schema.string(), (value, options) => {
668
+ try {
669
+ return encoding === "base64" ? Binary.fromBase64(value) : Binary.fromHex(value);
670
+ } catch (e) {
671
+ throw new ValidationError(e.message, options);
672
+ }
673
+ }, true)] : []
674
+ ]);
675
+ };
676
+ Schema.extend("lazy", (data, schema, options, strict) => {
677
+ if (!schema.inner[kSchema]) {
678
+ schema.inner = schema.builder();
679
+ schema.inner.meta = {
680
+ ...schema.meta,
681
+ ...schema.inner.meta
682
+ };
683
+ validateVolatileSchema(schema.inner, options.path, true);
684
+ }
685
+ return Schema.resolve(data, schema.inner, options, strict);
686
+ });
687
+ Schema.extend("any", (data) => {
688
+ return [data];
689
+ });
690
+ Schema.extend("never", (data, _, options) => {
691
+ throw new ValidationError(`expected nullable but got ${data}`, options);
692
+ });
693
+ Schema.extend("const", (data, { value }, options) => {
694
+ if (deepEqual(data, value)) return [value];
695
+ throw new ValidationError(`expected ${value} but got ${data}`, options);
696
+ });
697
+ function checkWithinRange(data, meta, description, options, skipMin = false) {
698
+ const { max = Infinity, min = -Infinity } = meta;
699
+ if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
700
+ if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
701
+ }
702
+ Schema.extend("string", (data, { meta }, options) => {
703
+ if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
704
+ if (meta.pattern) {
705
+ const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
706
+ if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
707
+ }
708
+ checkWithinRange(data.length, meta, "string length", options);
709
+ return [data];
710
+ });
711
+ function decimalShift(data, digits) {
712
+ const str = data.toString();
713
+ if (str.includes("e")) return data * Math.pow(10, digits);
714
+ const index = str.indexOf(".");
715
+ if (index === -1) return data * Math.pow(10, digits);
716
+ const frac = str.slice(index + 1);
717
+ const integer = str.slice(0, index);
718
+ if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
719
+ return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
720
+ }
721
+ function isMultipleOf(data, min, step) {
722
+ step = Math.abs(step);
723
+ if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
724
+ const index = step.toString().indexOf(".");
725
+ const digits = step.toString().slice(index + 1).length;
726
+ return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
727
+ }
728
+ Schema.extend("number", (data, { meta }, options) => {
729
+ if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
730
+ checkWithinRange(data, meta, "number", options);
731
+ const { step } = meta;
732
+ if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
733
+ return [data];
734
+ });
735
+ Schema.extend("boolean", (data, _, options) => {
736
+ if (typeof data === "boolean") return [data];
737
+ throw new ValidationError(`expected boolean but got ${data}`, options);
738
+ });
739
+ Schema.extend("bitset", (data, { bits, meta }, options) => {
740
+ let value = 0, keys = [];
741
+ if (typeof data === "number") {
742
+ value = data;
743
+ for (const key in bits) if (data & bits[key]) keys.push(key);
744
+ } else if (Array.isArray(data)) {
745
+ keys = data;
746
+ for (const key of keys) {
747
+ if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
748
+ if (key in bits) value |= bits[key];
749
+ }
750
+ } else throw new ValidationError(`expected number or array but got ${data}`, options);
751
+ if (value === meta.default) return [value];
752
+ return [value, keys];
753
+ });
754
+ Schema.extend("function", (data, _, options) => {
755
+ if (typeof data === "function") return [data];
756
+ throw new ValidationError(`expected function but got ${data}`, options);
757
+ });
758
+ Schema.extend("is", (data, { constructor }, options) => {
759
+ if (typeof constructor === "function") {
760
+ if (data instanceof constructor) return [data];
761
+ throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
762
+ } else {
763
+ if (isNullable(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
764
+ let prototype = Object.getPrototypeOf(data);
765
+ while (prototype) {
766
+ if (prototype.constructor?.name === constructor) return [data];
767
+ prototype = Object.getPrototypeOf(prototype);
768
+ }
769
+ throw new ValidationError(`expected ${constructor} but got ${data}`, options);
770
+ }
771
+ });
772
+ function property(data, key, schema, options) {
773
+ try {
774
+ const [value, adapted] = Schema.resolve(data[key], schema, {
775
+ ...options,
776
+ path: [...options.path || [], key]
777
+ });
778
+ if (adapted !== void 0) data[key] = adapted;
779
+ return value;
780
+ } catch (e) {
781
+ if (!options?.autofix) throw e;
782
+ delete data[key];
783
+ return schema.meta.volatile ? createVolatile(schema.meta.default) : schema.meta.default;
784
+ }
785
+ }
786
+ Schema.extend("array", (data, { inner, meta }, options) => {
787
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
788
+ checkWithinRange(data.length, meta, "array length", options, !isNullable(inner.meta.default));
789
+ return [data.map((_, index) => property(data, index, inner, options))];
790
+ });
791
+ Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
792
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
793
+ const result = {};
794
+ for (const key in data) {
795
+ let rKey;
796
+ try {
797
+ rKey = Schema.resolve(key, sKey, options)[0];
798
+ } catch (error) {
799
+ if (strict) continue;
800
+ throw error;
801
+ }
802
+ result[rKey] = property(data, key, inner, options);
803
+ data[rKey] = data[key];
804
+ if (key !== rKey) delete data[key];
805
+ }
806
+ return [result];
807
+ });
808
+ Schema.extend("tuple", (data, { list }, options, strict) => {
809
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
810
+ const result = list.map((inner, index) => property(data, index, inner, options));
811
+ if (strict) return [result];
812
+ result.push(...data.slice(list.length));
813
+ return [result];
814
+ });
815
+ function merge(result, data) {
816
+ for (const key in data) {
817
+ if (key in result) continue;
818
+ result[key] = data[key];
819
+ }
820
+ }
821
+ Schema.extend("object", (data, { dict }, options, strict) => {
822
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
823
+ const result = {};
824
+ for (const key in dict) {
825
+ const value = property(data, key, dict[key], options);
826
+ if (!isNullable(value) || key in data) result[key] = value;
827
+ }
828
+ if (!strict) merge(result, data);
829
+ return [result];
830
+ });
831
+ Schema.extend("union", (data, { list, toString }, options, strict) => {
832
+ const messages = [];
833
+ for (const inner of list) try {
834
+ return Schema.resolve(data, inner, options, strict);
835
+ } catch (error) {
836
+ messages.push(error);
837
+ }
838
+ throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
839
+ });
840
+ Schema.extend("intersect", (data, { list, toString }, options, strict) => {
841
+ if (!list.length) return [data];
842
+ let result;
843
+ for (const inner of list) {
844
+ const value = Schema.resolve(data, inner, options, true)[0];
845
+ if (isNullable(value)) continue;
846
+ if (isNullable(result)) result = value;
847
+ else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
848
+ else if (typeof value === "object") merge(result ??= {}, value);
849
+ else if (result !== value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
850
+ }
851
+ if (!strict && isPlainObject(data)) merge(result, data);
852
+ return [result];
853
+ });
854
+ Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
855
+ const [result, adapted = data] = Schema.resolve(data, inner, options, true);
856
+ if (preserve) return [callback(result)];
857
+ else return [callback(result), callback(adapted)];
858
+ });
859
+ const formatters = {};
860
+ function defineMethod(name, keys, format) {
861
+ formatters[name] = format;
862
+ Object.assign(Schema, { [name](...args) {
863
+ const schema = new Schema({ type: name });
864
+ keys.forEach((key, index) => {
865
+ switch (key) {
866
+ case "sKey":
867
+ schema.sKey = args[index] ?? Schema.string();
868
+ break;
869
+ case "inner":
870
+ schema.inner = Schema.from(args[index]);
871
+ break;
872
+ case "list":
873
+ schema.list = args[index].map(Schema.from);
874
+ break;
875
+ case "dict":
876
+ schema.dict = mapValues(args[index], Schema.from);
877
+ break;
878
+ case "bits":
879
+ schema.bits = {};
880
+ for (const key in args[index]) {
881
+ if (typeof args[index][key] !== "number") continue;
882
+ schema.bits[key] = args[index][key];
883
+ }
884
+ break;
885
+ case "callback": {
886
+ const callback = schema.callback = args[index];
887
+ callback["toJSON"] ||= () => callback.toString();
888
+ break;
889
+ }
890
+ case "constructor": {
891
+ const constructor = schema.constructor = args[index];
892
+ if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
893
+ break;
894
+ }
895
+ default: schema[key] = args[index];
896
+ }
897
+ });
898
+ if (name === "object" || name === "dict") schema.meta.default = {};
899
+ else if (name === "array" || name === "tuple") schema.meta.default = [];
900
+ else if (name === "bitset") schema.meta.default = 0;
901
+ return schema;
902
+ } });
903
+ }
904
+ defineMethod("is", ["constructor"], ({ constructor }) => {
905
+ if (typeof constructor === "function") return constructor.name;
906
+ else return constructor;
907
+ });
908
+ defineMethod("any", [], () => "any");
909
+ defineMethod("never", [], () => "never");
910
+ defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
911
+ defineMethod("string", [], () => "string");
912
+ defineMethod("number", [], () => "number");
913
+ defineMethod("boolean", [], () => "boolean");
914
+ defineMethod("bitset", ["bits"], () => "bitset");
915
+ defineMethod("function", [], () => "function");
916
+ defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
917
+ defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
918
+ defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
919
+ defineMethod("object", ["dict"], ({ dict }) => {
920
+ if (Object.keys(dict).length === 0) return "{}";
921
+ return `{ ${Object.entries(dict).map(([key, inner]) => {
922
+ return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
923
+ }).join(", ")} }`;
924
+ });
925
+ defineMethod("union", ["list"], ({ list }, inline) => {
926
+ const result = list.map(({ toString: format }) => format()).join(" | ");
927
+ return inline ? `(${result})` : result;
928
+ });
929
+ defineMethod("intersect", ["list"], ({ list }) => {
930
+ return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
931
+ });
932
+ defineMethod("transform", [
933
+ "inner",
934
+ "callback",
935
+ "preserve"
936
+ ], ({ inner }, isInner) => inner.toString(isInner));
937
+ //#endregion
938
+ //#region lib/types/config.js
939
+ /** Shared Host polling and browser reconnection configuration. */
940
+ /** Validate both halves against the same defaults. */
941
+ const Config = Schema.object({
942
+ pollIntervalMs: Schema.number().step(1).min(1).default(500),
943
+ reconnectDelayMs: Schema.number().step(1).min(1).default(1e3)
944
+ });
945
+ //#endregion
47
946
  //#region lib/types/client/index.js
48
947
  /** Cordis plugin name. */
49
948
  const name = "client-hmr";
@@ -52,8 +951,9 @@ window.__ModuleLoader__.load({
52
951
  /**
53
952
  * Forward graph snapshots and rebuilds to the page's shared serial controller.
54
953
  * @param ctx - Plugin context with the client module system.
954
+ * @param config - validated browser reconnection timing.
55
955
  */
56
- function apply(ctx) {
956
+ function apply(ctx, config) {
57
957
  const entries = ctx.modules.entries;
58
958
  const handle = (frame) => {
59
959
  (frame.type === "graph" ? Promise.resolve().then(() => entries.sync(frame.graph)) : entries.reload(frame.id, frame.rev)).catch((error) => {
@@ -61,8 +961,13 @@ window.__ModuleLoader__.load({
61
961
  });
62
962
  };
63
963
  ctx.effect(() => {
64
- const source = new EventSource(EVENTS_ROUTE);
65
- source.addEventListener("message", (event) => {
964
+ const url = new URL(EVENTS_ROUTE, document.baseURI);
965
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
966
+ let source;
967
+ let timer;
968
+ let disposed = false;
969
+ const receive = (event) => {
970
+ if (disposed) return;
66
971
  let value;
67
972
  try {
68
973
  value = JSON.parse(event.data);
@@ -73,13 +978,32 @@ window.__ModuleLoader__.load({
73
978
  const parsed = parsePluginsEventFrame(value);
74
979
  if (parsed.kind === "invalid") ctx.logger.warn(`client-hmr: invalid event frame: ${event.data}`);
75
980
  else if (parsed.kind === "frame") handle(parsed.frame);
76
- });
981
+ };
982
+ const connect = () => {
983
+ const socket = new WebSocket(url.href);
984
+ source = socket;
985
+ const onError = () => {
986
+ socket.close();
987
+ };
988
+ socket.addEventListener("message", receive);
989
+ socket.addEventListener("close", () => {
990
+ socket.removeEventListener("message", receive);
991
+ socket.removeEventListener("error", onError);
992
+ if (!disposed) timer = setTimeout(connect, config.reconnectDelayMs);
993
+ }, { once: true });
994
+ socket.addEventListener("error", onError);
995
+ };
996
+ connect();
77
997
  return () => {
998
+ disposed = true;
999
+ clearTimeout(timer);
1000
+ source.removeEventListener("message", receive);
78
1001
  source.close();
79
1002
  };
80
- }, "client-hmr: event source");
1003
+ }, "client-hmr: event socket");
81
1004
  }
82
1005
  //#endregion
1006
+ exports.Config = Config;
83
1007
  exports.apply = apply;
84
1008
  exports.inject = inject;
85
1009
  exports.name = name;