dsh-edge 0.1.0

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 (159) hide show
  1. package/LICENSE +21 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +183 -0
  4. package/README.zh.md +183 -0
  5. package/THIRD_PARTY_NOTICES.md +199 -0
  6. package/dist/_headers +3 -0
  7. package/dist/assets/fonts/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  8. package/dist/assets/fonts/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  9. package/dist/assets/fonts/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  10. package/dist/assets/fonts/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  11. package/dist/assets/fonts/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  12. package/dist/assets/fonts/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  13. package/dist/assets/fonts/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  14. package/dist/assets/fonts/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  15. package/dist/assets/fonts/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  16. package/dist/assets/fonts/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  17. package/dist/assets/fonts/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  18. package/dist/assets/fonts/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  19. package/dist/assets/fonts/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  20. package/dist/assets/fonts/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  21. package/dist/assets/fonts/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  22. package/dist/assets/fonts/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  23. package/dist/assets/fonts/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  24. package/dist/assets/fonts/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  25. package/dist/assets/fonts/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  26. package/dist/assets/fonts/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  27. package/dist/assets/fonts/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  28. package/dist/assets/fonts/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  29. package/dist/assets/fonts/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  30. package/dist/assets/fonts/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  31. package/dist/assets/fonts/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  32. package/dist/assets/fonts/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  33. package/dist/assets/fonts/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  34. package/dist/assets/fonts/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  35. package/dist/assets/fonts/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  36. package/dist/assets/fonts/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  37. package/dist/assets/fonts/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  38. package/dist/assets/fonts/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  39. package/dist/assets/fonts/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  40. package/dist/assets/fonts/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  41. package/dist/assets/fonts/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  42. package/dist/assets/fonts/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  43. package/dist/assets/fonts/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  44. package/dist/assets/fonts/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  45. package/dist/assets/fonts/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  46. package/dist/assets/fonts/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  47. package/dist/assets/fonts/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  48. package/dist/assets/fonts/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  49. package/dist/assets/fonts/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  50. package/dist/assets/fonts/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  51. package/dist/assets/fonts/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  52. package/dist/assets/fonts/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  53. package/dist/assets/fonts/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  54. package/dist/assets/fonts/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  55. package/dist/assets/fonts/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  56. package/dist/assets/fonts/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  57. package/dist/assets/fonts/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  58. package/dist/assets/fonts/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  59. package/dist/assets/fonts/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  60. package/dist/assets/fonts/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  61. package/dist/assets/fonts/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  62. package/dist/assets/fonts/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  63. package/dist/assets/fonts/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  64. package/dist/assets/fonts/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  65. package/dist/assets/fonts/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  66. package/dist/assets/index-C-1AiF3k.js +112 -0
  67. package/dist/assets/index-CSGf6Qzd.css +1 -0
  68. package/dist/assets/langs/c-BIGW1oBm.js +2 -0
  69. package/dist/assets/langs/cpp-DIPi6g--.js +2 -0
  70. package/dist/assets/langs/csharp-DSvCPggb.js +2 -0
  71. package/dist/assets/langs/css-CLj8gQPS.js +2 -0
  72. package/dist/assets/langs/go-C27-OAKa.js +2 -0
  73. package/dist/assets/langs/html-CfGypltT.js +2 -0
  74. package/dist/assets/langs/ini-BEwlwnbL.js +2 -0
  75. package/dist/assets/langs/java-CylS5w8V.js +2 -0
  76. package/dist/assets/langs/kotlin-BdnUsdx6.js +2 -0
  77. package/dist/assets/langs/less-B1dDrJ26.js +2 -0
  78. package/dist/assets/langs/lua-BaeVxFsk.js +2 -0
  79. package/dist/assets/langs/markdown-Cvjx9yec.js +2 -0
  80. package/dist/assets/langs/mdx-Cmh6b_Ma.js +2 -0
  81. package/dist/assets/langs/php-D-uCvoST.js +2 -0
  82. package/dist/assets/langs/python-B6aJPvgy.js +2 -0
  83. package/dist/assets/langs/ruby-DEItuUFs.js +2 -0
  84. package/dist/assets/langs/rust-B1yitclQ.js +2 -0
  85. package/dist/assets/langs/scss-D5BDwBP9.js +2 -0
  86. package/dist/assets/langs/sql-CRqJ_cUM.js +2 -0
  87. package/dist/assets/langs/swift-D82vCrfD.js +2 -0
  88. package/dist/assets/langs/toml-vGWfd6FD.js +2 -0
  89. package/dist/assets/langs/xml-sdJ4AIDG.js +2 -0
  90. package/dist/assets/langs/yaml-Buea-lGh.js +2 -0
  91. package/dist/assets/vendor-Cjbwl5VI.js +411 -0
  92. package/dist/assets/vendor-CjyC-hUb.css +1 -0
  93. package/dist/favicon.svg +8 -0
  94. package/dist/index.html +35 -0
  95. package/dist/manifest.webmanifest +16 -0
  96. package/dist/plugins/@deepseek-ai/dsh-api-gateway/client.js +420 -0
  97. package/dist/plugins/@deepseek-ai/dsh-api-remotes/client.js +5937 -0
  98. package/dist/plugins/@deepseek-ai/dsh-client-connection/client.js +10207 -0
  99. package/dist/plugins/@deepseek-ai/dsh-client-locale/client.js +1231 -0
  100. package/dist/plugins/@deepseek-ai/dsh-client-modules/client.js +259 -0
  101. package/dist/plugins/@deepseek-ai/dsh-client-runtime/client.js +10539 -0
  102. package/dist/plugins/@deepseek-ai/dsh-client-ui-agent-preset/client.js +1725 -0
  103. package/dist/plugins/@deepseek-ai/dsh-client-ui-commands/client.js +1116 -0
  104. package/dist/plugins/@deepseek-ai/dsh-client-ui-conversation/client.js +9832 -0
  105. package/dist/plugins/@deepseek-ai/dsh-client-ui-deliverables/client.js +373 -0
  106. package/dist/plugins/@deepseek-ai/dsh-client-ui-edge/client.js +549 -0
  107. package/dist/plugins/@deepseek-ai/dsh-client-ui-input-trigger/client.js +859 -0
  108. package/dist/plugins/@deepseek-ai/dsh-client-ui-jobs/client.js +280 -0
  109. package/dist/plugins/@deepseek-ai/dsh-client-ui-layout/client.js +456 -0
  110. package/dist/plugins/@deepseek-ai/dsh-client-ui-model-selection/client.js +804 -0
  111. package/dist/plugins/@deepseek-ai/dsh-client-ui-permission-presets/client.js +461 -0
  112. package/dist/plugins/@deepseek-ai/dsh-client-ui-settings/client.js +254 -0
  113. package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-general/client.js +609 -0
  114. package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar/client.js +292 -0
  115. package/dist/plugins/@deepseek-ai/dsh-client-ui-skill/client.js +327 -0
  116. package/dist/plugins/@deepseek-ai/dsh-client-ui-subagent/client.js +710 -0
  117. package/dist/plugins/@deepseek-ai/dsh-client-ui-theme/client.js +1312 -0
  118. package/dist/plugins/@deepseek-ai/dsh-client-ui-tool/client.js +1630 -0
  119. package/dist/plugins/@deepseek-ai/dsh-client-ui-trajectory/client.js +7370 -0
  120. package/dist/plugins/@deepseek-ai/dsh-client-ui-user-questions/client.js +700 -0
  121. package/dist/plugins/@deepseek-ai/dsh-client-ui-workflow-run/client.js +474 -0
  122. package/dist/plugins/@deepseek-ai/dsh-client-ui-workspace/client.js +2426 -0
  123. package/dist/plugins/@deepseek-ai/dsh-typert-registry/client.js +1372 -0
  124. package/package.json +97 -0
  125. package/scripts/assemble-web.mjs +230 -0
  126. package/scripts/bundle-size.d.mts +2 -0
  127. package/scripts/bundle-size.mjs +26 -0
  128. package/scripts/bundle.mjs +53 -0
  129. package/scripts/cli.d.mts +39 -0
  130. package/scripts/cli.mjs +496 -0
  131. package/scripts/install.d.mts +149 -0
  132. package/scripts/install.mjs +989 -0
  133. package/scripts/legal-files.mjs +24 -0
  134. package/scripts/verify-packed.mjs +32 -0
  135. package/scripts/wrangler-config.d.mts +18 -0
  136. package/scripts/wrangler-config.mjs +84 -0
  137. package/src/agent.ts +119 -0
  138. package/src/auth.ts +352 -0
  139. package/src/deepseek.ts +231 -0
  140. package/src/deployment.ts +147 -0
  141. package/src/direct-shell-core-empty.ts +10 -0
  142. package/src/direct-shell-protocol.ts +5 -0
  143. package/src/direct-shell.ts +341 -0
  144. package/src/do-session-persistence.ts +1064 -0
  145. package/src/edge-api.ts +796 -0
  146. package/src/edge-credentials.ts +56 -0
  147. package/src/edge-remotes.ts +41 -0
  148. package/src/edge-workspace-store.ts +339 -0
  149. package/src/http.ts +212 -0
  150. package/src/index.ts +196 -0
  151. package/src/instance.ts +1007 -0
  152. package/src/isolated-direct-shell-unavailable.ts +11 -0
  153. package/src/protocol.ts +39 -0
  154. package/src/release.ts +9 -0
  155. package/src/session-store.ts +1110 -0
  156. package/src/sse.ts +86 -0
  157. package/src/web-search.ts +38 -0
  158. package/src/workspace.ts +270 -0
  159. package/wrangler.jsonc +56 -0
@@ -0,0 +1,1231 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@deepseek-ai/dsh-client-locale",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react_jsx_runtime = require("react/jsx-runtime");
8
+ let react = require("react");
9
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
10
+ let _deepseek_ai_dsh_client_runtime_client = require("@deepseek-ai/dsh-client-runtime/client");
11
+ //#region ../../../vendor/cosmokit/src/misc.ts
12
+ /** Return true when a value is `null` or `undefined`. */
13
+ function isNullable(value) {
14
+ return value === null || value === void 0;
15
+ }
16
+ /** Return true for non-array object values. */
17
+ function isPlainObject(data) {
18
+ return data && typeof data === "object" && !Array.isArray(data);
19
+ }
20
+ /** Filter object entries and return a new object. */
21
+ function filterKeys(object, filter) {
22
+ return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
23
+ }
24
+ /** Map object values while preserving the original key set. */
25
+ function mapValues(object, transform) {
26
+ return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
27
+ }
28
+ /** Pick selected keys from an object, optionally including `undefined` values. */
29
+ function pick(source, keys, forced) {
30
+ if (!keys) return { ...source };
31
+ const result = {};
32
+ for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
33
+ return result;
34
+ }
35
+ //#endregion
36
+ //#region ../../../vendor/cosmokit/src/types.ts
37
+ /** Test values using `instanceof` with a `toStringTag` fallback. */
38
+ function is(type, value) {
39
+ if (arguments.length === 1) return (value) => is(type, value);
40
+ return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
41
+ }
42
+ function isArrayBufferLike(value) {
43
+ return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
44
+ }
45
+ function isArrayBufferSource(value) {
46
+ return isArrayBufferLike(value) || ArrayBuffer.isView(value);
47
+ }
48
+ let Binary;
49
+ (function(_Binary) {
50
+ _Binary.is = isArrayBufferLike;
51
+ _Binary.isSource = isArrayBufferSource;
52
+ function fromSource(source) {
53
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
54
+ else return source;
55
+ }
56
+ _Binary.fromSource = fromSource;
57
+ function toBase64(source) {
58
+ source = fromSource(source);
59
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
60
+ let binary = "";
61
+ const bytes = new Uint8Array(source);
62
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
63
+ return btoa(binary);
64
+ }
65
+ _Binary.toBase64 = toBase64;
66
+ function fromBase64(source) {
67
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
68
+ return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
69
+ }
70
+ _Binary.fromBase64 = fromBase64;
71
+ function toHex(source) {
72
+ source = fromSource(source);
73
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
74
+ return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
75
+ }
76
+ _Binary.toHex = toHex;
77
+ function fromHex(source) {
78
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
79
+ const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
80
+ const buffer = [];
81
+ for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
82
+ return Uint8Array.from(buffer).buffer;
83
+ }
84
+ _Binary.fromHex = fromHex;
85
+ })(Binary || (Binary = {}));
86
+ Binary.fromBase64;
87
+ Binary.toBase64;
88
+ Binary.fromHex;
89
+ Binary.toHex;
90
+ /** Deep-clone common JavaScript values while preserving prototypes and cycles. */
91
+ function clone(source, refs = /* @__PURE__ */ new Map()) {
92
+ if (!source || typeof source !== "object") return source;
93
+ if (is("Date", source)) return new Date(source.valueOf());
94
+ if (is("RegExp", source)) return new RegExp(source.source, source.flags);
95
+ if (isArrayBufferLike(source)) return source.slice(0);
96
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
97
+ const cached = refs.get(source);
98
+ if (cached) return cached;
99
+ if (Array.isArray(source)) {
100
+ const result = [];
101
+ refs.set(source, result);
102
+ source.forEach((value, index) => {
103
+ result[index] = Reflect.apply(clone, null, [value, refs]);
104
+ });
105
+ return result;
106
+ }
107
+ const result = Object.create(Object.getPrototypeOf(source));
108
+ refs.set(source, result);
109
+ for (const key of Reflect.ownKeys(source)) {
110
+ const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
111
+ if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
112
+ Reflect.defineProperty(result, key, descriptor);
113
+ }
114
+ return result;
115
+ }
116
+ /** Deeply compare arrays, dates, regexps, buffers, and plain object fields. */
117
+ function deepEqual(a, b, strict) {
118
+ if (a === b) return true;
119
+ if (!strict && isNullable(a) && isNullable(b)) return true;
120
+ if (typeof a !== typeof b) return false;
121
+ if (typeof a !== "object") return false;
122
+ if (!a || !b) return false;
123
+ function check(test, then) {
124
+ return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
125
+ }
126
+ return check(Array.isArray, (a, b) => a.length === b.length && a.every((item, index) => deepEqual(item, b[index]))) ?? check(is("Date"), (a, b) => a.valueOf() === b.valueOf()) ?? check(is("RegExp"), (a, b) => a.source === b.source && a.flags === b.flags) ?? check(isArrayBufferLike, (a, b) => {
127
+ if (a.byteLength !== b.byteLength) return false;
128
+ const viewA = new Uint8Array(a);
129
+ const viewB = new Uint8Array(b);
130
+ for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
131
+ return true;
132
+ }) ?? Object.keys({
133
+ ...a,
134
+ ...b
135
+ }).every((key) => deepEqual(a[key], b[key], strict));
136
+ }
137
+ //#endregion
138
+ //#region ../../../vendor/cosmokit/src/time.ts
139
+ let Time;
140
+ (function(_Time) {
141
+ _Time.millisecond = 1;
142
+ const second = _Time.second = 1e3;
143
+ const minute = _Time.minute = second * 60;
144
+ const hour = _Time.hour = minute * 60;
145
+ const day = _Time.day = hour * 24;
146
+ const week = _Time.week = day * 7;
147
+ let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
148
+ function setTimezoneOffset(offset) {
149
+ timezoneOffset = offset;
150
+ }
151
+ _Time.setTimezoneOffset = setTimezoneOffset;
152
+ function getTimezoneOffset() {
153
+ return timezoneOffset;
154
+ }
155
+ _Time.getTimezoneOffset = getTimezoneOffset;
156
+ function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
157
+ if (typeof date === "number") date = new Date(date);
158
+ if (offset === void 0) offset = timezoneOffset;
159
+ return Math.floor((date.valueOf() / minute - offset) / 1440);
160
+ }
161
+ _Time.getDateNumber = getDateNumber;
162
+ function fromDateNumber(value, offset) {
163
+ const date = new Date(value * day);
164
+ if (offset === void 0) offset = timezoneOffset;
165
+ return new Date(+date + offset * minute);
166
+ }
167
+ _Time.fromDateNumber = fromDateNumber;
168
+ const numeric = /\d+(?:\.\d+)?/.source;
169
+ const timeRegExp = new RegExp(`^${[
170
+ "w(?:eek(?:s)?)?",
171
+ "d(?:ay(?:s)?)?",
172
+ "h(?:our(?:s)?)?",
173
+ "m(?:in(?:ute)?(?:s)?)?",
174
+ "s(?:ec(?:ond)?(?:s)?)?"
175
+ ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
176
+ function parseTime(source) {
177
+ const capture = timeRegExp.exec(source);
178
+ if (!capture) return 0;
179
+ 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);
180
+ }
181
+ _Time.parseTime = parseTime;
182
+ function parseDate(date) {
183
+ const parsed = parseTime(date);
184
+ if (parsed) date = Date.now() + parsed;
185
+ else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
186
+ else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
187
+ return date ? new Date(date) : /* @__PURE__ */ new Date();
188
+ }
189
+ _Time.parseDate = parseDate;
190
+ function format(ms) {
191
+ const abs = Math.abs(ms);
192
+ if (abs >= day - hour / 2) return Math.round(ms / day) + "d";
193
+ else if (abs >= hour - minute / 2) return Math.round(ms / hour) + "h";
194
+ else if (abs >= minute - second / 2) return Math.round(ms / minute) + "m";
195
+ else if (abs >= second) return Math.round(ms / second) + "s";
196
+ return ms + "ms";
197
+ }
198
+ _Time.format = format;
199
+ function toDigits(source, length = 2) {
200
+ return source.toString().padStart(length, "0");
201
+ }
202
+ _Time.toDigits = toDigits;
203
+ function template(template, time = /* @__PURE__ */ new Date()) {
204
+ 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));
205
+ }
206
+ _Time.template = template;
207
+ })(Time || (Time = {}));
208
+ //#endregion
209
+ //#region ../../../vendor/schemastery/src/index.ts
210
+ const kSchema = Symbol.for("schemastery");
211
+ const kValidationError = Symbol.for("ValidationError");
212
+ globalThis.__schemastery_index__ ??= 0;
213
+ globalThis.__schemastery_refs__ = void 0;
214
+ var ValidationError = class extends TypeError {
215
+ options;
216
+ name = "ValidationError";
217
+ constructor(message, options) {
218
+ let prefix = "$";
219
+ for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
220
+ else if (typeof segment === "number") prefix += "[" + segment + "]";
221
+ else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
222
+ if (prefix.startsWith(".")) prefix = prefix.slice(1);
223
+ super((prefix === "$" ? "" : `${prefix} `) + message);
224
+ this.options = options;
225
+ }
226
+ static is(error) {
227
+ return !!error?.[kValidationError];
228
+ }
229
+ };
230
+ Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
231
+ const Schema = function(options) {
232
+ const schema = function(data, options = {}) {
233
+ return Schema.resolve(data, schema, options)[0];
234
+ };
235
+ if (options.refs) {
236
+ const refs = mapValues(options.refs, (options) => new Schema(options));
237
+ const getRef = (uid) => refs[uid];
238
+ for (const key in refs) {
239
+ const options = refs[key];
240
+ options.sKey = getRef(options.sKey);
241
+ options.inner = getRef(options.inner);
242
+ options.list = options.list && options.list.map(getRef);
243
+ options.dict = options.dict && mapValues(options.dict, getRef);
244
+ }
245
+ return refs[options.uid];
246
+ }
247
+ Object.assign(schema, options);
248
+ if (typeof schema.callback === "string") try {
249
+ schema.callback = new Function("return " + schema.callback)();
250
+ } catch {}
251
+ Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
252
+ Object.setPrototypeOf(schema, Schema.prototype);
253
+ schema.meta ||= {};
254
+ schema.toString = schema.toString.bind(schema);
255
+ return schema;
256
+ };
257
+ Schema.prototype = Object.create(Function.prototype);
258
+ Schema.prototype[kSchema] = true;
259
+ Object.defineProperty(Schema.prototype, "~standard", { get() {
260
+ return {
261
+ version: 1,
262
+ vendor: "schemastery",
263
+ validate: (value) => {
264
+ try {
265
+ return { value: Schema.resolve(value, this, {})[0] };
266
+ } catch (error) {
267
+ if (ValidationError.is(error)) return { issues: [{
268
+ message: error.message,
269
+ path: error.options.path
270
+ }] };
271
+ throw error;
272
+ }
273
+ }
274
+ };
275
+ } });
276
+ Schema.ValidationError = ValidationError;
277
+ Schema.prototype.toJSON = function toJSON() {
278
+ if (globalThis.__schemastery_refs__) {
279
+ globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
280
+ return this.uid;
281
+ }
282
+ globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
283
+ globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
284
+ const result = {
285
+ uid: this.uid,
286
+ refs: globalThis.__schemastery_refs__
287
+ };
288
+ globalThis.__schemastery_refs__ = void 0;
289
+ return result;
290
+ };
291
+ Schema.prototype.set = function set(key, value) {
292
+ this.dict[key] = value;
293
+ return this;
294
+ };
295
+ Schema.prototype.push = function push(value) {
296
+ this.list.push(value);
297
+ return this;
298
+ };
299
+ function mergeDesc(original, messages) {
300
+ const result = typeof original === "string" ? { "": original } : { ...original };
301
+ for (const locale in messages) {
302
+ const value = messages[locale];
303
+ if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
304
+ else if (typeof value === "string") result[locale] = value;
305
+ }
306
+ return result;
307
+ }
308
+ function getInner(value) {
309
+ return value?.$value ?? value?.$inner;
310
+ }
311
+ function extractKeys(data) {
312
+ return filterKeys(data ?? {}, (key) => !key.startsWith("$"));
313
+ }
314
+ Schema.prototype.i18n = function i18n(messages) {
315
+ const schema = Schema(this);
316
+ const desc = mergeDesc(schema.meta.description, messages);
317
+ if (Object.keys(desc).length) schema.meta.description = desc;
318
+ if (schema.dict) schema.dict = mapValues(schema.dict, (inner, key) => {
319
+ return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
320
+ });
321
+ if (schema.list) schema.list = schema.list.map((inner, index) => {
322
+ return inner.i18n(mapValues(messages, (data = {}) => {
323
+ if (Array.isArray(getInner(data))) return getInner(data)[index];
324
+ if (Array.isArray(data)) return data[index];
325
+ return extractKeys(data);
326
+ }));
327
+ });
328
+ if (schema.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
329
+ if (getInner(data)) return getInner(data);
330
+ return extractKeys(data);
331
+ }));
332
+ if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
333
+ return schema;
334
+ };
335
+ Schema.prototype.extra = function extra(key, value) {
336
+ const schema = Schema(this);
337
+ schema.meta = {
338
+ ...schema.meta,
339
+ [key]: value
340
+ };
341
+ return schema;
342
+ };
343
+ for (const key of [
344
+ "required",
345
+ "disabled",
346
+ "collapse",
347
+ "hidden",
348
+ "loose"
349
+ ]) Object.assign(Schema.prototype, { [key](value = true) {
350
+ const schema = Schema(this);
351
+ schema.meta = {
352
+ ...schema.meta,
353
+ [key]: value
354
+ };
355
+ return schema;
356
+ } });
357
+ Schema.prototype.deprecated = function deprecated() {
358
+ const schema = Schema(this);
359
+ schema.meta.badges ||= [];
360
+ schema.meta.badges.push({
361
+ text: "deprecated",
362
+ type: "danger"
363
+ });
364
+ return schema;
365
+ };
366
+ Schema.prototype.experimental = function experimental() {
367
+ const schema = Schema(this);
368
+ schema.meta.badges ||= [];
369
+ schema.meta.badges.push({
370
+ text: "experimental",
371
+ type: "warning"
372
+ });
373
+ return schema;
374
+ };
375
+ Schema.prototype.pattern = function pattern(regexp) {
376
+ const schema = Schema(this);
377
+ const pattern = pick(regexp, ["source", "flags"]);
378
+ schema.meta = {
379
+ ...schema.meta,
380
+ pattern
381
+ };
382
+ return schema;
383
+ };
384
+ Schema.prototype.simplify = function simplify(value) {
385
+ if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
386
+ if (isNullable(value)) return value;
387
+ if (this.type === "object" || this.type === "dict") {
388
+ const result = {};
389
+ for (const key in value) {
390
+ const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
391
+ if (this.type === "dict" || !isNullable(item)) result[key] = item;
392
+ }
393
+ if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
394
+ return result;
395
+ } else if (this.type === "array" || this.type === "tuple") {
396
+ const result = [];
397
+ value.forEach((value, index) => {
398
+ const schema = this.type === "array" ? this.inner : this.list[index];
399
+ const item = schema ? schema.simplify(value) : value;
400
+ result.push(item);
401
+ });
402
+ return result;
403
+ } else if (this.type === "intersect") {
404
+ const result = {};
405
+ for (const item of this.list) Object.assign(result, item.simplify(value));
406
+ return result;
407
+ } else if (this.type === "union") for (const schema of this.list) try {
408
+ Schema.resolve(value, schema, {});
409
+ return schema.simplify(value);
410
+ } catch {}
411
+ return value;
412
+ };
413
+ Schema.prototype.toString = function toString(inline) {
414
+ return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
415
+ };
416
+ Schema.prototype.role = function role(role, extra) {
417
+ const schema = Schema(this);
418
+ schema.meta = {
419
+ ...schema.meta,
420
+ role,
421
+ extra
422
+ };
423
+ return schema;
424
+ };
425
+ for (const key of [
426
+ "default",
427
+ "link",
428
+ "comment",
429
+ "description",
430
+ "max",
431
+ "min",
432
+ "step"
433
+ ]) Object.assign(Schema.prototype, { [key](value) {
434
+ const schema = Schema(this);
435
+ schema.meta = {
436
+ ...schema.meta,
437
+ [key]: value
438
+ };
439
+ return schema;
440
+ } });
441
+ const resolvers = {};
442
+ Schema.extend = function extend(type, resolve) {
443
+ resolvers[type] = resolve;
444
+ };
445
+ Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
446
+ if (!schema) return [data];
447
+ if (options.ignore?.(data, schema)) return [data];
448
+ if (isNullable(data) && schema.type !== "lazy") {
449
+ if (schema.meta.required) throw new ValidationError(`missing required value`, options);
450
+ let current = schema;
451
+ let fallback = schema.meta.default;
452
+ while (current?.type === "intersect" && isNullable(fallback)) {
453
+ current = current.list[0];
454
+ fallback = current?.meta.default;
455
+ }
456
+ if (isNullable(fallback)) return [data];
457
+ data = clone(fallback);
458
+ }
459
+ const callback = resolvers[schema.type];
460
+ if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
461
+ try {
462
+ return callback(data, schema, options, strict);
463
+ } catch (error) {
464
+ if (!schema.meta.loose) throw error;
465
+ return [schema.meta.default];
466
+ }
467
+ };
468
+ Schema.from = function from(source) {
469
+ if (isNullable(source)) return Schema.any();
470
+ else if ([
471
+ "string",
472
+ "number",
473
+ "boolean"
474
+ ].includes(typeof source)) return Schema.const(source).required();
475
+ else if (source[kSchema]) return source;
476
+ else if (typeof source === "function") switch (source) {
477
+ case String: return Schema.string().required();
478
+ case Number: return Schema.number().required();
479
+ case Boolean: return Schema.boolean().required();
480
+ case Function: return Schema.function().required();
481
+ default: return Schema.is(source).required();
482
+ }
483
+ else throw new TypeError(`cannot infer schema from ${source}`);
484
+ };
485
+ Schema.lazy = function lazy(builder) {
486
+ const toJSON = () => {
487
+ if (!schema.inner[kSchema]) {
488
+ schema.inner = schema.builder();
489
+ schema.inner.meta = {
490
+ ...schema.meta,
491
+ ...schema.inner.meta
492
+ };
493
+ }
494
+ return schema.inner.toJSON();
495
+ };
496
+ const schema = new Schema({
497
+ type: "lazy",
498
+ builder,
499
+ inner: { toJSON }
500
+ });
501
+ return schema;
502
+ };
503
+ Schema.natural = function natural() {
504
+ return Schema.number().step(1).min(0);
505
+ };
506
+ Schema.percent = function percent() {
507
+ return Schema.number().step(.01).min(0).max(1).role("slider");
508
+ };
509
+ Schema.date = function date() {
510
+ return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
511
+ const date = new Date(value);
512
+ if (isNaN(+date)) throw new ValidationError(`invalid date "${value}"`, options);
513
+ return date;
514
+ }, true)]);
515
+ };
516
+ Schema.regExp = function regExp(flag = "") {
517
+ return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
518
+ try {
519
+ return new RegExp(value, flag);
520
+ } catch (e) {
521
+ throw new ValidationError(e.message, options);
522
+ }
523
+ }, true)]);
524
+ };
525
+ Schema.arrayBuffer = function arrayBuffer(encoding) {
526
+ return Schema.union([
527
+ Schema.is(ArrayBuffer),
528
+ Schema.is(SharedArrayBuffer),
529
+ Schema.transform(Schema.any(), (value, options) => {
530
+ if (Binary.isSource(value)) return Binary.fromSource(value);
531
+ throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
532
+ }, true),
533
+ ...encoding ? [Schema.transform(Schema.string(), (value, options) => {
534
+ try {
535
+ return encoding === "base64" ? Binary.fromBase64(value) : Binary.fromHex(value);
536
+ } catch (e) {
537
+ throw new ValidationError(e.message, options);
538
+ }
539
+ }, true)] : []
540
+ ]);
541
+ };
542
+ Schema.extend("lazy", (data, schema, options, strict) => {
543
+ if (!schema.inner[kSchema]) {
544
+ schema.inner = schema.builder();
545
+ schema.inner.meta = {
546
+ ...schema.meta,
547
+ ...schema.inner.meta
548
+ };
549
+ }
550
+ return Schema.resolve(data, schema.inner, options, strict);
551
+ });
552
+ Schema.extend("any", (data) => {
553
+ return [data];
554
+ });
555
+ Schema.extend("never", (data, _, options) => {
556
+ throw new ValidationError(`expected nullable but got ${data}`, options);
557
+ });
558
+ Schema.extend("const", (data, { value }, options) => {
559
+ if (deepEqual(data, value)) return [value];
560
+ throw new ValidationError(`expected ${value} but got ${data}`, options);
561
+ });
562
+ function checkWithinRange(data, meta, description, options, skipMin = false) {
563
+ const { max = Infinity, min = -Infinity } = meta;
564
+ if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
565
+ if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
566
+ }
567
+ Schema.extend("string", (data, { meta }, options) => {
568
+ if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
569
+ if (meta.pattern) {
570
+ const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
571
+ if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
572
+ }
573
+ checkWithinRange(data.length, meta, "string length", options);
574
+ return [data];
575
+ });
576
+ function decimalShift(data, digits) {
577
+ const str = data.toString();
578
+ if (str.includes("e")) return data * Math.pow(10, digits);
579
+ const index = str.indexOf(".");
580
+ if (index === -1) return data * Math.pow(10, digits);
581
+ const frac = str.slice(index + 1);
582
+ const integer = str.slice(0, index);
583
+ if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
584
+ return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
585
+ }
586
+ function isMultipleOf(data, min, step) {
587
+ step = Math.abs(step);
588
+ if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
589
+ const index = step.toString().indexOf(".");
590
+ const digits = step.toString().slice(index + 1).length;
591
+ return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
592
+ }
593
+ Schema.extend("number", (data, { meta }, options) => {
594
+ if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
595
+ checkWithinRange(data, meta, "number", options);
596
+ const { step } = meta;
597
+ if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
598
+ return [data];
599
+ });
600
+ Schema.extend("boolean", (data, _, options) => {
601
+ if (typeof data === "boolean") return [data];
602
+ throw new ValidationError(`expected boolean but got ${data}`, options);
603
+ });
604
+ Schema.extend("bitset", (data, { bits, meta }, options) => {
605
+ let value = 0, keys = [];
606
+ if (typeof data === "number") {
607
+ value = data;
608
+ for (const key in bits) if (data & bits[key]) keys.push(key);
609
+ } else if (Array.isArray(data)) {
610
+ keys = data;
611
+ for (const key of keys) {
612
+ if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
613
+ if (key in bits) value |= bits[key];
614
+ }
615
+ } else throw new ValidationError(`expected number or array but got ${data}`, options);
616
+ if (value === meta.default) return [value];
617
+ return [value, keys];
618
+ });
619
+ Schema.extend("function", (data, _, options) => {
620
+ if (typeof data === "function") return [data];
621
+ throw new ValidationError(`expected function but got ${data}`, options);
622
+ });
623
+ Schema.extend("is", (data, { constructor }, options) => {
624
+ if (typeof constructor === "function") {
625
+ if (data instanceof constructor) return [data];
626
+ throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
627
+ } else {
628
+ if (isNullable(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
629
+ let prototype = Object.getPrototypeOf(data);
630
+ while (prototype) {
631
+ if (prototype.constructor?.name === constructor) return [data];
632
+ prototype = Object.getPrototypeOf(prototype);
633
+ }
634
+ throw new ValidationError(`expected ${constructor} but got ${data}`, options);
635
+ }
636
+ });
637
+ function property(data, key, schema, options) {
638
+ try {
639
+ const [value, adapted] = Schema.resolve(data[key], schema, {
640
+ ...options,
641
+ path: [...options.path || [], key]
642
+ });
643
+ if (adapted !== void 0) data[key] = adapted;
644
+ return value;
645
+ } catch (e) {
646
+ if (!options?.autofix) throw e;
647
+ delete data[key];
648
+ return schema.meta.default;
649
+ }
650
+ }
651
+ Schema.extend("array", (data, { inner, meta }, options) => {
652
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
653
+ checkWithinRange(data.length, meta, "array length", options, !isNullable(inner.meta.default));
654
+ return [data.map((_, index) => property(data, index, inner, options))];
655
+ });
656
+ Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
657
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
658
+ const result = {};
659
+ for (const key in data) {
660
+ let rKey;
661
+ try {
662
+ rKey = Schema.resolve(key, sKey, options)[0];
663
+ } catch (error) {
664
+ if (strict) continue;
665
+ throw error;
666
+ }
667
+ result[rKey] = property(data, key, inner, options);
668
+ data[rKey] = data[key];
669
+ if (key !== rKey) delete data[key];
670
+ }
671
+ return [result];
672
+ });
673
+ Schema.extend("tuple", (data, { list }, options, strict) => {
674
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
675
+ const result = list.map((inner, index) => property(data, index, inner, options));
676
+ if (strict) return [result];
677
+ result.push(...data.slice(list.length));
678
+ return [result];
679
+ });
680
+ function merge(result, data) {
681
+ for (const key in data) {
682
+ if (key in result) continue;
683
+ result[key] = data[key];
684
+ }
685
+ }
686
+ Schema.extend("object", (data, { dict }, options, strict) => {
687
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
688
+ const result = {};
689
+ for (const key in dict) {
690
+ const value = property(data, key, dict[key], options);
691
+ if (!isNullable(value) || key in data) result[key] = value;
692
+ }
693
+ if (!strict) merge(result, data);
694
+ return [result];
695
+ });
696
+ Schema.extend("union", (data, { list, toString }, options, strict) => {
697
+ const messages = [];
698
+ for (const inner of list) try {
699
+ return Schema.resolve(data, inner, options, strict);
700
+ } catch (error) {
701
+ messages.push(error);
702
+ }
703
+ throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
704
+ });
705
+ Schema.extend("intersect", (data, { list, toString }, options, strict) => {
706
+ if (!list.length) return [data];
707
+ let result;
708
+ for (const inner of list) {
709
+ const value = Schema.resolve(data, inner, options, true)[0];
710
+ if (isNullable(value)) continue;
711
+ if (isNullable(result)) result = value;
712
+ else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
713
+ else if (typeof value === "object") merge(result ??= {}, value);
714
+ else if (result !== value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
715
+ }
716
+ if (!strict && isPlainObject(data)) merge(result, data);
717
+ return [result];
718
+ });
719
+ Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
720
+ const [result, adapted = data] = Schema.resolve(data, inner, options, true);
721
+ if (preserve) return [callback(result)];
722
+ else return [callback(result), callback(adapted)];
723
+ });
724
+ const formatters = {};
725
+ function defineMethod(name, keys, format) {
726
+ formatters[name] = format;
727
+ Object.assign(Schema, { [name](...args) {
728
+ const schema = new Schema({ type: name });
729
+ keys.forEach((key, index) => {
730
+ switch (key) {
731
+ case "sKey":
732
+ schema.sKey = args[index] ?? Schema.string();
733
+ break;
734
+ case "inner":
735
+ schema.inner = Schema.from(args[index]);
736
+ break;
737
+ case "list":
738
+ schema.list = args[index].map(Schema.from);
739
+ break;
740
+ case "dict":
741
+ schema.dict = mapValues(args[index], Schema.from);
742
+ break;
743
+ case "bits":
744
+ schema.bits = {};
745
+ for (const key in args[index]) {
746
+ if (typeof args[index][key] !== "number") continue;
747
+ schema.bits[key] = args[index][key];
748
+ }
749
+ break;
750
+ case "callback": {
751
+ const callback = schema.callback = args[index];
752
+ callback["toJSON"] ||= () => callback.toString();
753
+ break;
754
+ }
755
+ case "constructor": {
756
+ const constructor = schema.constructor = args[index];
757
+ if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
758
+ break;
759
+ }
760
+ default: schema[key] = args[index];
761
+ }
762
+ });
763
+ if (name === "object" || name === "dict") schema.meta.default = {};
764
+ else if (name === "array" || name === "tuple") schema.meta.default = [];
765
+ else if (name === "bitset") schema.meta.default = 0;
766
+ return schema;
767
+ } });
768
+ }
769
+ defineMethod("is", ["constructor"], ({ constructor }) => {
770
+ if (typeof constructor === "function") return constructor.name;
771
+ else return constructor;
772
+ });
773
+ defineMethod("any", [], () => "any");
774
+ defineMethod("never", [], () => "never");
775
+ defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
776
+ defineMethod("string", [], () => "string");
777
+ defineMethod("number", [], () => "number");
778
+ defineMethod("boolean", [], () => "boolean");
779
+ defineMethod("bitset", ["bits"], () => "bitset");
780
+ defineMethod("function", [], () => "function");
781
+ defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
782
+ defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
783
+ defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
784
+ defineMethod("object", ["dict"], ({ dict }) => {
785
+ if (Object.keys(dict).length === 0) return "{}";
786
+ return `{ ${Object.entries(dict).map(([key, inner]) => {
787
+ return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
788
+ }).join(", ")} }`;
789
+ });
790
+ defineMethod("union", ["list"], ({ list }, inline) => {
791
+ const result = list.map(({ toString: format }) => format()).join(" | ");
792
+ return inline ? `(${result})` : result;
793
+ });
794
+ defineMethod("intersect", ["list"], ({ list }) => {
795
+ return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
796
+ });
797
+ defineMethod("transform", [
798
+ "inner",
799
+ "callback",
800
+ "preserve"
801
+ ], ({ inner }, isInner) => inner.toString(isInner));
802
+ //#endregion
803
+ //#region lib/types/locale-settings.js
804
+ /** Locale preference stored in the Host user-settings document. */
805
+ /** Settings namespace owned by the locale plugin. */
806
+ const LOCALE_SETTINGS_NAMESPACE = "locale";
807
+ /** Field carrying an explicit locale selection; absence delegates to the browser. */
808
+ const LOCALE_PREFERENCE_FIELD = "preference";
809
+ /** Locale identifiers shipped by the browser client. */
810
+ const LOCALE_IDS = ["zh", "en"];
811
+ Schema.object({ [LOCALE_PREFERENCE_FIELD]: Schema.union([...LOCALE_IDS]).required(false) });
812
+ //#endregion
813
+ //#region lib/types/locales/zh.js
814
+ /** zh base dictionary for the common namespace: cross-feature standard words. */
815
+ const zh$1 = {
816
+ "ok": "确定",
817
+ "cancel": "取消",
818
+ "close": "关闭",
819
+ "copy": "复制",
820
+ "copied": "复制成功",
821
+ "retry": "重试",
822
+ "loading": "加载中…",
823
+ "load.failed": "加载失败",
824
+ "submit": "提交",
825
+ "submitting": "正在提交…",
826
+ "next": "下一步",
827
+ "previous": "上一步",
828
+ "skip": "跳过",
829
+ "delete": "删除",
830
+ "edit": "编辑",
831
+ "save": "保存",
832
+ "search": "搜索",
833
+ "more": "更多",
834
+ "collapse": "收起",
835
+ "expand": "展开",
836
+ "back": "返回",
837
+ "unknown": "未知",
838
+ "none": "无",
839
+ "truncated": "已截断"
840
+ };
841
+ //#endregion
842
+ //#region lib/types/locales/en.js
843
+ /** en base dictionary for the common namespace, checked complete against the zh key set. */
844
+ const en$1 = {
845
+ "ok": "OK",
846
+ "cancel": "Cancel",
847
+ "close": "Close",
848
+ "copy": "Copy",
849
+ "copied": "Copied",
850
+ "retry": "Retry",
851
+ "loading": "Loading…",
852
+ "load.failed": "Failed to load",
853
+ "submit": "Submit",
854
+ "submitting": "Submitting…",
855
+ "next": "Next",
856
+ "previous": "Previous",
857
+ "skip": "Skip",
858
+ "delete": "Delete",
859
+ "edit": "Edit",
860
+ "save": "Save",
861
+ "search": "Search",
862
+ "more": "More",
863
+ "collapse": "Collapse",
864
+ "expand": "Expand",
865
+ "back": "Back",
866
+ "unknown": "Unknown",
867
+ "none": "None",
868
+ "truncated": "Truncated"
869
+ };
870
+ //#endregion
871
+ //#region lib/types/locales/settings.js
872
+ /** `settings.locale` namespace dictionaries (the Language row's copy). */
873
+ /** Simplified Chinese dictionary (the key-set source of truth). */
874
+ const zh = { "language.title": "语言" };
875
+ /** English dictionary, checked complete against the zh key set. */
876
+ const en = { "language.title": "Language" };
877
+ //#endregion
878
+ //#region \0dsh-css:/private/var/folders/nm/n5smty9962gf5rhjc5855kt80000gn/T/dsh-edge-release-worktree.XXXXXX.RcJjogaGt4/repo/packages/client/locale/src/client/LanguageRow.module.css.mjs
879
+ const css = "._77eVXq_row{border-bottom:1px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}._77eVXq_rowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}._77eVXq_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}._77eVXq_selector{background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;border-radius:18px;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex}._77eVXq_selector:hover{background:var(--dsw-alias-interactive-bg-hover)}._77eVXq_chevron{flex:none}";
880
+ const tagId = "@deepseek-ai/dsh-client-locale/LanguageRow.module.css";
881
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
882
+ const tag = document.createElement("style");
883
+ tag.dataset.plugin = "@deepseek-ai/dsh-client-locale";
884
+ tag.dataset.pluginCss = tagId;
885
+ tag.textContent = css;
886
+ document.head.appendChild(tag);
887
+ }
888
+ var LanguageRow_module_css_default = {
889
+ "chevron": "_77eVXq_chevron",
890
+ "rowText": "_77eVXq_rowText",
891
+ "row": "_77eVXq_row",
892
+ "title": "_77eVXq_title",
893
+ "selector": "_77eVXq_selector"
894
+ };
895
+ //#endregion
896
+ //#region lib/types/client/LanguageRow.js
897
+ /**
898
+ * Language preference row registered into the General section item slot
899
+ * (figma 501:30011 'Setting-Cell'): title + selector pill opening the locale
900
+ * menu. Registered by this package — the locale feature owns its own
901
+ * settings surface.
902
+ */
903
+ /**
904
+ * Render the Language row.
905
+ * @param props - composed slot props.
906
+ * @returns the row element tree.
907
+ */
908
+ function LanguageRow({ t, setLocale, useStore }) {
909
+ const active = useStore((s) => s.active);
910
+ const options = useStore((s) => s.options);
911
+ const [open, setOpen] = (0, react.useState)(false);
912
+ const activeLabel = options.find((o) => o.id === active)?.label ?? active;
913
+ return (0, react_jsx_runtime.jsxs)("div", {
914
+ className: LanguageRow_module_css_default.row,
915
+ children: [(0, react_jsx_runtime.jsx)("div", {
916
+ className: LanguageRow_module_css_default.rowText,
917
+ children: (0, react_jsx_runtime.jsx)("div", {
918
+ className: LanguageRow_module_css_default.title,
919
+ children: t("language.title")
920
+ })
921
+ }), (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
922
+ open,
923
+ onClose: () => {
924
+ setOpen(false);
925
+ },
926
+ items: options.map((o) => ({
927
+ id: o.id,
928
+ label: o.label
929
+ })),
930
+ selectedId: active,
931
+ onSelect: (id) => {
932
+ setLocale(id);
933
+ setOpen(false);
934
+ },
935
+ align: "end",
936
+ portal: true,
937
+ anchor: (0, react_jsx_runtime.jsxs)("button", {
938
+ type: "button",
939
+ className: LanguageRow_module_css_default.selector,
940
+ "aria-haspopup": "menu",
941
+ "aria-expanded": open,
942
+ onClick: () => {
943
+ setOpen((v) => !v);
944
+ },
945
+ children: [activeLabel, (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutline14, { className: LanguageRow_module_css_default.chevron })]
946
+ })
947
+ })]
948
+ });
949
+ }
950
+ //#endregion
951
+ //#region lib/types/client/settings-store.js
952
+ /**
953
+ * Language row slot store: a mirror of the locale service snapshot. The
954
+ * plugin's apply-world change listener is the only writer; the row component
955
+ * reads via props.useStore.
956
+ */
957
+ /**
958
+ * Declares the Language row state and write surface.
959
+ * @returns the store handle.
960
+ */
961
+ function createLanguageRowStore() {
962
+ return (0, _deepseek_ai_dsh_client_runtime_client.defineStore)({
963
+ init: () => ({
964
+ active: "",
965
+ options: [],
966
+ revision: -1
967
+ }),
968
+ actions: { sync: (d, active, options, revision) => {
969
+ if (revision <= d.revision) return;
970
+ d.active = active;
971
+ d.options = options;
972
+ d.revision = revision;
973
+ } }
974
+ });
975
+ }
976
+ //#endregion
977
+ //#region lib/types/client/index.js
978
+ /** Fallback locale consulted after the active locale misses (also the last-resort initial locale). */
979
+ const FALLBACK_LOCALE = "zh";
980
+ /** Shared namespace for shell-level texts. */
981
+ const COMMON_NS = "common";
982
+ /** Namespace owning this feature's settings-row copy. */
983
+ const SETTINGS_NS = "settings.locale";
984
+ /** The two shipped locales. */
985
+ const LOCALES = Object.freeze([{
986
+ id: "zh",
987
+ label: "中文"
988
+ }, {
989
+ id: "en",
990
+ label: "English"
991
+ }]);
992
+ /**
993
+ * Dictionary registry plus locale preference. Lookup chain per key: the
994
+ * entry's namespace in the active locale -> that namespace's zh fallback ->
995
+ * the shared common namespace (active, then zh) -> the key itself (missing
996
+ * text stays visible, fail loud in the UI rather than blank). Reads go
997
+ * through {@link getLocale}; writes only through {@link setLocale};
998
+ * continuous sync through the `locale/change` event, or through the
999
+ * LocaleFace getSnapshot/subscribe pair the render machinery consumes
1000
+ * (installed via `ctx.slots.installLocale`).
1001
+ */
1002
+ var LocaleRuntime = class {
1003
+ dicts = /* @__PURE__ */ new Map();
1004
+ bound = /* @__PURE__ */ new Map();
1005
+ snapshot;
1006
+ listeners = /* @__PURE__ */ new Set();
1007
+ ctx;
1008
+ host;
1009
+ /** Browser-derived locale standing wherever no explicit Host selection does. */
1010
+ provisional;
1011
+ /**
1012
+ * @param ctx - owning context (change events are emitted on it; the scope
1013
+ * listener is released through ctx.effect on dispose).
1014
+ * @param host - durable preference scope owned by the providing plugin;
1015
+ * absent compositions (standalone dictionary registries) stay process-local.
1016
+ */
1017
+ constructor(ctx, host) {
1018
+ this.ctx = ctx;
1019
+ this.host = host;
1020
+ this.provisional = resolveInitialLocale();
1021
+ this.snapshot = Object.freeze({
1022
+ active: this.provisional,
1023
+ locales: LOCALES,
1024
+ revision: 0
1025
+ });
1026
+ if (host !== void 0) {
1027
+ ctx.effect(() => host.subscribe(() => {
1028
+ this.adopt(host);
1029
+ }), "locale: settings scope adoption");
1030
+ this.adopt(host);
1031
+ }
1032
+ }
1033
+ /**
1034
+ * Read the current immutable locale snapshot.
1035
+ * @returns the current snapshot (stable reference until the next change).
1036
+ */
1037
+ getLocale() {
1038
+ return this.snapshot;
1039
+ }
1040
+ /**
1041
+ * LocaleFace getSnapshot: the current snapshot (carries `revision`; stable
1042
+ * reference between changes, uSES-safe).
1043
+ * @returns the current snapshot.
1044
+ */
1045
+ getSnapshot() {
1046
+ return this.snapshot;
1047
+ }
1048
+ /**
1049
+ * LocaleFace subscribe: notified on every snapshot change (locale switch
1050
+ * or dictionary registration — registrations bump the revision so already
1051
+ * rendered outlets pick up late-arriving dictionaries).
1052
+ * @param fn - change callback.
1053
+ * @returns unsubscribe.
1054
+ */
1055
+ subscribe(fn) {
1056
+ this.listeners.add(fn);
1057
+ return () => {
1058
+ this.listeners.delete(fn);
1059
+ };
1060
+ }
1061
+ /**
1062
+ * Switch the active locale — the only user preference write entry.
1063
+ * @param id - a registered locale id; unknown ids throw.
1064
+ */
1065
+ setLocale(id) {
1066
+ const match = this.snapshot.locales.find((l) => l.id === id);
1067
+ if (match === void 0) throw new Error(`locale "${id}" is not registered`);
1068
+ if (this.snapshot.active === match.id) return;
1069
+ this.publish(match.id, true);
1070
+ this.host?.set(LOCALE_PREFERENCE_FIELD, match.id);
1071
+ }
1072
+ /**
1073
+ * Adopt the scope's accepted durable selection without writing it back; an
1074
+ * absent selection returns to the browser-derived locale.
1075
+ * @param host - the constructor-narrowed scope driving this adoption.
1076
+ */
1077
+ adopt(host) {
1078
+ const section = host.getSnapshot().value;
1079
+ if (section === void 0) return;
1080
+ const target = section.preference ?? this.provisional;
1081
+ if (this.snapshot.active === target) return;
1082
+ this.publish(target, true);
1083
+ }
1084
+ register(ns, localeOrDicts, dict) {
1085
+ const pairs = typeof localeOrDicts === "string" ? [[localeOrDicts, dict]] : Object.entries(localeOrDicts);
1086
+ let locales = this.dicts.get(ns);
1087
+ if (!locales) {
1088
+ locales = /* @__PURE__ */ new Map();
1089
+ this.dicts.set(ns, locales);
1090
+ }
1091
+ for (const [locale] of pairs) if (locales.has(locale)) throw new Error(`locale namespace "${ns}" already has locale "${locale}"`);
1092
+ for (const [locale, entries] of pairs) locales.set(locale, entries);
1093
+ this.publish(this.snapshot.active, false);
1094
+ return () => {
1095
+ const owner = this.dicts.get(ns);
1096
+ /* v8 ignore next -- defensive: a namespace's locales map is created on
1097
+ * first register and never removed, so the disposer always finds it. */
1098
+ if (!owner) return;
1099
+ let removed = false;
1100
+ for (const [locale, entries] of pairs) if (owner.get(locale) === entries) {
1101
+ owner.delete(locale);
1102
+ removed = true;
1103
+ }
1104
+ if (removed) this.publish(this.snapshot.active, false);
1105
+ };
1106
+ }
1107
+ bind(ns) {
1108
+ let t = this.bound.get(ns);
1109
+ if (!t) {
1110
+ t = (key, params) => this.translate(ns, key, params);
1111
+ this.bound.set(ns, t);
1112
+ return t;
1113
+ }
1114
+ return t;
1115
+ }
1116
+ translate(ns, key, params) {
1117
+ const template = this.lookup(ns, key) ?? (ns !== "common" ? this.lookup("common", key) : void 0) ?? key;
1118
+ if (!params) return template;
1119
+ return template.replace(/\{(\w+)\}/g, (match, name) => name in params ? String(params[name]) : match);
1120
+ }
1121
+ lookup(ns, key) {
1122
+ const locales = this.dicts.get(ns);
1123
+ return locales?.get(this.snapshot.active)?.[key] ?? locales?.get("zh")?.[key];
1124
+ }
1125
+ /**
1126
+ * Advance the snapshot revision and notify LocaleFace subscribers (render
1127
+ * refresh). Only an active-locale switch additionally emits
1128
+ * `locale/change` — dictionary registrations stay off the event so
1129
+ * registration-heavy boot cannot storm event listeners (which may
1130
+ * re-register slots in response).
1131
+ */
1132
+ publish(active, localeChanged) {
1133
+ this.snapshot = Object.freeze({
1134
+ active,
1135
+ locales: this.snapshot.locales,
1136
+ revision: this.snapshot.revision + 1
1137
+ });
1138
+ if (localeChanged) this.ctx.emit("locale/change", this.snapshot);
1139
+ for (const fn of [...this.listeners]) try {
1140
+ fn();
1141
+ } catch (error) {
1142
+ console.error("locale subscriber crashed:", error);
1143
+ }
1144
+ }
1145
+ };
1146
+ /**
1147
+ * The browser's own language wins over {@link FALLBACK_LOCALE}; an explicit
1148
+ * Host preference may replace this provisional value after plugin activation.
1149
+ */
1150
+ function resolveInitialLocale() {
1151
+ return detectBrowserLocale() ?? "zh";
1152
+ }
1153
+ /**
1154
+ * The first shipped locale the browser asks for, matched on the primary
1155
+ * subtag so every regional variant lands on its language (`zh-Hans-CN` -> zh,
1156
+ * `en-GB` -> en). `window` is the browser test, not `navigator`: Node exposes
1157
+ * a global `navigator` reporting the machine's own language, which would
1158
+ * otherwise decide the locale for non-browser runs (node e2e booting the
1159
+ * client tree). `navigator.language` trails the ordered `languages` list and
1160
+ * covers its absence on hosts that expose only the single tag.
1161
+ */
1162
+ function detectBrowserLocale() {
1163
+ if (typeof window === "undefined") return void 0;
1164
+ for (const tag of [...navigator.languages ?? [], navigator.language]) {
1165
+ const primary = tag.toLowerCase().split("-")[0];
1166
+ const match = LOCALES.find((locale) => locale.id === primary);
1167
+ if (match) return match.id;
1168
+ }
1169
+ }
1170
+ /** Required services: slot registration plus the settings transport. */
1171
+ const inject = [
1172
+ "slots",
1173
+ "connection",
1174
+ "remote",
1175
+ "settingsScope"
1176
+ ];
1177
+ /**
1178
+ * Client plugin body: provide the locale service with base dictionaries and
1179
+ * register the feature-owned Language preference row into the General
1180
+ * section's item slot (a feature owns its settings surface).
1181
+ * @param ctx - client cordis context.
1182
+ */
1183
+ function apply(ctx) {
1184
+ const locale = new LocaleRuntime(ctx, ctx.settingsScope.bind({ namespace: LOCALE_SETTINGS_NAMESPACE }));
1185
+ locale.register(COMMON_NS, {
1186
+ zh: zh$1,
1187
+ en: en$1
1188
+ });
1189
+ locale.register(SETTINGS_NS, {
1190
+ zh,
1191
+ en
1192
+ });
1193
+ ctx.provide("locale", locale);
1194
+ ctx.slots.installLocale(locale);
1195
+ const store = createLanguageRowStore();
1196
+ let bound;
1197
+ const sync = (snapshot) => {
1198
+ bound?.sync(snapshot.active, snapshot.locales.map((l) => ({
1199
+ id: l.id,
1200
+ label: l.label
1201
+ })), snapshot.revision);
1202
+ };
1203
+ ctx.on("locale/change", sync);
1204
+ const injected = (actions) => {
1205
+ bound = actions;
1206
+ sync(locale.getLocale());
1207
+ return { setLocale: (id) => {
1208
+ locale.setLocale(id);
1209
+ } };
1210
+ };
1211
+ ctx.slots.inject("settings.general.item", () => ctx.slots.register({
1212
+ name: "settings.general.item",
1213
+ id: "language",
1214
+ order: 0,
1215
+ store,
1216
+ locale: SETTINGS_NS,
1217
+ inject: injected
1218
+ }, LanguageRow));
1219
+ }
1220
+ //#endregion
1221
+ exports.COMMON_NS = COMMON_NS;
1222
+ exports.FALLBACK_LOCALE = FALLBACK_LOCALE;
1223
+ exports.LocaleRuntime = LocaleRuntime;
1224
+ exports.SETTINGS_NS = SETTINGS_NS;
1225
+ exports.apply = apply;
1226
+ exports.inject = inject;
1227
+ return module.exports;
1228
+ }
1229
+ });
1230
+
1231
+ //# sourceMappingURL=client.js.map