@dungsil/dsh-plugin-ui-setting-skills 0.1.0 → 0.2.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.
package/dist/client.js CHANGED
@@ -11,13 +11,16 @@ var en_default = {
11
11
  },
12
12
  ui: {
13
13
  "nav": "Skills",
14
- "description": "Skills loaded from your shared agent and DSH skill directories. Same-name skills are listed separately for each source.",
15
- "agents": "Shared agent skills",
14
+ "description": "This setting applies only to DSH.",
15
+ "agents": "Shared skills",
16
16
  "dsh": "DSH skills",
17
17
  "loading": "Loading skills…",
18
18
  "empty": "No loaded skills from this source.",
19
19
  "error": "Could not load skills. Close and reopen this settings section to try again.",
20
- "incomplete": "Some skill sources could not be loaded. This list may be incomplete."
20
+ "incomplete": "Some skill sources could not be loaded. This list may be incomplete.",
21
+ "use": "Use",
22
+ "disabled": "Off",
23
+ "saveError": "Could not save the setting. Close and reopen this section to check the saved state before trying again."
21
24
  }
22
25
  };
23
26
  // locale/ko.json
@@ -28,13 +31,16 @@ var ko_default = {
28
31
  },
29
32
  ui: {
30
33
  "nav": "스킬",
31
- "description": "공용 에이전트 및 DSH 스킬 경로에서 불러온 스킬을 표시합니다. 이름이 같은 스킬도 출처별로 각각 표시합니다.",
32
- "agents": "공용 에이전트 스킬",
34
+ "description": "이 설정은 DSH에만 적용됩니다.",
35
+ "agents": "공용 스킬",
33
36
  "dsh": "DSH 스킬",
34
37
  "loading": "스킬을 불러오는 중입니다…",
35
38
  "empty": "이 경로에서 로드된 스킬이 없습니다.",
36
39
  "error": "스킬을 불러오지 못했습니다. 이 설정 항목을 닫았다가 다시 열어 주세요.",
37
- "incomplete": "일부 스킬 소스를 불러오지 못해 목록이 완전하지 않을 수 있습니다."
40
+ "incomplete": "일부 스킬 소스를 불러오지 못해 목록이 완전하지 않을 수 있습니다.",
41
+ "use": "사용",
42
+ "disabled": "꺼짐",
43
+ "saveError": "설정을 저장하지 못했습니다. 이 설정 항목을 닫았다가 다시 열어 저장 상태를 확인한 후 다시 시도해 주세요."
38
44
  }
39
45
  };
40
46
  // locale/zh.json
@@ -45,18 +51,22 @@ var zh_default = {
45
51
  },
46
52
  ui: {
47
53
  "nav": "技能",
48
- "description": "显示从共享代理和 DSH 技能目录加载的技能。同名技能按来源分别列出。",
49
- "agents": "共享代理技能",
54
+ "description": "此设置仅适用于 DSH。",
55
+ "agents": "共享技能",
50
56
  "dsh": "DSH 技能",
51
57
  "loading": "正在加载技能…",
52
58
  "empty": "未从此目录加载任何技能。",
53
59
  "error": "无法加载技能。请关闭并重新打开此设置项后重试。",
54
- "incomplete": "部分技能源无法加载,列表可能不完整。"
60
+ "incomplete": "部分技能源无法加载,列表可能不完整。",
61
+ "use": "使用",
62
+ "disabled": "已关闭",
63
+ "saveError": "无法保存设置。请关闭并重新打开此设置项,确认已保存的状态后重试。"
55
64
  }
56
65
  };
57
66
  // src/protocol.ts
58
67
  const channel = "/api";
59
68
  const method = "dungsil-ui-setting-skills/list";
69
+ const saveMethod = "dungsil-ui-setting-skills/save";
60
70
  // src/client.tsx
61
71
  const name = "dungsil-ui-setting-skills";
62
72
  const inject = [
@@ -73,23 +83,22 @@ const styles = `
73
83
  .dsh-skills-settings ul { list-style: none; margin: 0; padding: 0; }
74
84
  .dsh-skills-settings code { font-size: 12px; overflow-wrap: anywhere; }
75
85
  .dsh-skills-settings [role=alert] { color: var(--dsw-alias-state-error-primary, #b54424); }
76
- .dsh-skills-settings details { border-bottom: .5px solid var(--dsw-alias-border-l2); }
86
+ .dsh-skills-settings li { display: flex; align-items: flex-start; gap: 16px; border-bottom: .5px solid var(--dsw-alias-border-l2); }
87
+ .dsh-skills-settings details { flex: 1; min-width: 0; }
77
88
  .dsh-skills-settings summary { display: flex; align-items: center; gap: 12px; padding: 16px 0; list-style: none; cursor: pointer; border-radius: var(--dsw-radius-md); }
78
89
  .dsh-skills-settings summary::-webkit-details-marker { display: none; }
79
90
  .dsh-skills-settings summary:hover { background: var(--dsw-alias-interactive-bg-hover); }
80
91
  .dsh-skills-settings summary:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color); outline-offset: 2px; }
81
92
  .dsh-skills-settings summary svg { flex: none; }
82
93
  .dsh-skills-settings details[open] summary svg { transform: rotate(90deg); }
83
- .dsh-skills-summary-text { display: flex; align-items: baseline; gap: 16px; min-width: 0; flex: 1; }
84
- .dsh-skills-summary-text strong { max-width: 50%; overflow-wrap: anywhere; }
85
- .dsh-skills-preview { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
86
- .dsh-skills-settings details[open] .dsh-skills-preview { display: none; }
87
- .dsh-skills-settings details[open] .dsh-skills-summary-text strong { max-width: 100%; }
94
+ .dsh-skills-summary-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
95
+ .dsh-skills-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
96
+ .dsh-skills-title strong { min-width: 0; overflow-wrap: anywhere; }
97
+ .dsh-skills-title .dsh-skills-muted { flex: none; font-size: 12px; }
98
+ .dsh-skills-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
88
99
  .dsh-skills-detail { padding: 0 0 16px 28px; overflow-wrap: anywhere; }
89
- @container (max-width: 480px) {
90
- .dsh-skills-summary-text { align-items: stretch; flex-direction: column; gap: 2px; }
91
- .dsh-skills-summary-text strong { max-width: 100%; }
92
- }
100
+ .dsh-skills-toggle { flex: none; padding-top: 27px; }
101
+ .dsh-skills-list-header { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: .5px solid var(--dsw-alias-border-l2); }
93
102
  `;
94
103
  function SkillsSettings({ ctx }) {
95
104
  const locale = (0, react.useSyncExternalStore)((listener) => ctx.locale.subscribe(listener), () => ctx.locale.getSnapshot());
@@ -98,6 +107,10 @@ function SkillsSettings({ ctx }) {
98
107
  const connection = ctx.get("connection");
99
108
  const [view, setView] = (0, react.useState)();
100
109
  const [error, setError] = (0, react.useState)(false);
110
+ const [saveError, setSaveError] = (0, react.useState)(false);
111
+ const [busy, setBusy] = (0, react.useState)(false);
112
+ const pending = (0, react.useRef)(false);
113
+ const mounted = (0, react.useRef)(false);
101
114
  const [source, setSource] = (0, react.useState)("user-agents");
102
115
  const groups = ["user-agents", "user-dsh"].map((value) => ({
103
116
  value,
@@ -106,6 +119,7 @@ function SkillsSettings({ ctx }) {
106
119
  }));
107
120
  (0, react.useEffect)(() => {
108
121
  const controller = new AbortController();
122
+ mounted.current = true;
109
123
  setView(void 0);
110
124
  setError(false);
111
125
  (async () => {
@@ -118,8 +132,34 @@ function SkillsSettings({ ctx }) {
118
132
  if (!controller.signal.aborted) setError(true);
119
133
  }
120
134
  })();
121
- return () => controller.abort();
135
+ return () => {
136
+ mounted.current = false;
137
+ controller.abort();
138
+ };
122
139
  }, [connection]);
140
+ async function save(name, disabled) {
141
+ if (pending.current) return;
142
+ pending.current = true;
143
+ setBusy(true);
144
+ setSaveError(false);
145
+ try {
146
+ const result = await connection.rpc.call(channel, saveMethod, {
147
+ name,
148
+ disabled
149
+ });
150
+ if (!result.ok) throw new Error("Could not save skills");
151
+ const value = result.value;
152
+ if (mounted.current) setView((current) => current && {
153
+ ...current,
154
+ disabled: value.disabled
155
+ });
156
+ } catch {
157
+ if (mounted.current) setSaveError(true);
158
+ } finally {
159
+ pending.current = false;
160
+ if (mounted.current) setBusy(false);
161
+ }
162
+ }
123
163
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
124
164
  className: "dsh-skills-settings",
125
165
  "aria-label": text.nav,
@@ -137,6 +177,10 @@ function SkillsSettings({ ctx }) {
137
177
  role: "alert",
138
178
  children: text.error
139
179
  }),
180
+ saveError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
181
+ role: "alert",
182
+ children: text.saveError
183
+ }),
140
184
  view && !view.complete && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
141
185
  role: "alert",
142
186
  children: text.incomplete
@@ -160,14 +204,28 @@ function SkillsSettings({ ctx }) {
160
204
  children: group.skills.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
161
205
  className: "dsh-skills-muted",
162
206
  children: text.empty
163
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", { children: group.skills.map((skill) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", {
207
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
208
+ className: "dsh-skills-list-header dsh-skills-muted",
209
+ "aria-hidden": "true",
210
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
211
+ text.nav,
212
+ " ",
213
+ group.skills.length
214
+ ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: text.use })]
215
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", { children: group.skills.map((skill) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", {
164
216
  "aria-label": skill.name,
165
217
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronRightOutlineRegular, {
166
218
  size: 16,
167
219
  "aria-hidden": "true"
168
220
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
169
221
  className: "dsh-skills-summary-text",
170
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: skill.name }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
222
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
223
+ className: "dsh-skills-title",
224
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: skill.name }), view.disabled.includes(skill.name) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
225
+ className: "dsh-skills-muted",
226
+ children: text.disabled
227
+ })]
228
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
171
229
  className: "dsh-skills-preview dsh-skills-muted",
172
230
  "aria-hidden": "true",
173
231
  children: skill.description
@@ -179,7 +237,15 @@ function SkillsSettings({ ctx }) {
179
237
  className: "dsh-skills-muted",
180
238
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: skill.path })
181
239
  })]
182
- })] }) }, skill.path ?? skill.name)) })
240
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
241
+ className: "dsh-skills-toggle",
242
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
243
+ label: `${text.use}: ${skill.name}`,
244
+ checked: !view.disabled.includes(skill.name),
245
+ disabled: busy || saveError,
246
+ onChange: (enabled) => void save(skill.name, !enabled)
247
+ })
248
+ })] }, skill.path ?? skill.name)) })] })
183
249
  }, group.value))] })
184
250
  ]
185
251
  });
package/dist/index.js CHANGED
@@ -1,12 +1,926 @@
1
1
  import { clientRequestSchema } from "@deepseek-ai/dsh-client-connection";
2
+ import { SkillRegistry } from "@deepseek-ai/dsh-skill";
2
3
  import { FileSystemSkillProvider } from "@deepseek-ai/dsh-skill-filesystem";
4
+ // ../../node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.6/node_modules/@deepseek-ai/cosmokit/lib/index.js
5
+ /** Return true when a value is `null` or `undefined`. */
6
+ function isNullable(value) {
7
+ return value === null || value === void 0;
8
+ }
9
+ /** Return true for non-array object values. */
10
+ function isPlainObject(data) {
11
+ return data && typeof data === "object" && !Array.isArray(data);
12
+ }
13
+ /** Filter object entries and return a new object. */
14
+ function filterKeys(object, filter) {
15
+ return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
16
+ }
17
+ /** Map object values while preserving the original key set. */
18
+ function mapValues(object, transform) {
19
+ return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
20
+ }
21
+ /** Pick selected keys from an object, optionally including `undefined` values. */
22
+ function pick(source, keys, forced) {
23
+ if (!keys) return { ...source };
24
+ const result = {};
25
+ for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
26
+ return result;
27
+ }
28
+ /** Shared config references used by schema validators and plugin runtimes. */
29
+ const write = Symbol.for("cosmokit.volatile.write");
30
+ function snapshot(value, ancestors = /* @__PURE__ */ new Set()) {
31
+ if (typeof value === "function") throw new TypeError("volatile config cannot contain functions");
32
+ if (value === null || typeof value !== "object") return value;
33
+ if (ancestors.has(value)) throw new TypeError("volatile config cannot contain cycles");
34
+ ancestors.add(value);
35
+ try {
36
+ if (Array.isArray(value)) return Object.freeze(value.map((item) => snapshot(item, ancestors)));
37
+ if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new TypeError("volatile config objects must be plain objects or arrays");
38
+ return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item, ancestors)])));
39
+ } finally {
40
+ ancestors.delete(value);
41
+ }
42
+ }
43
+ /**
44
+ * Create a detached reference containing an immutable copy of the supplied data.
45
+ * @param value - validated config data; class instances and functions are unsupported.
46
+ * @returns a reference whose value is updated only by its owning runtime.
47
+ */
48
+ function createVolatile(value) {
49
+ let current = snapshot(value);
50
+ return Object.freeze({
51
+ get: () => current,
52
+ [write]: (value) => {
53
+ current = value;
54
+ }
55
+ });
56
+ }
57
+ /**
58
+ * Identify references across ESM/CJS copies of the shared library.
59
+ * @param value - a parsed config value.
60
+ * @returns whether the value implements the shared reference protocol.
61
+ */
62
+ function isVolatile(value) {
63
+ return typeof value === "object" && value !== null && write in value;
64
+ }
65
+ /** Test values using `instanceof` with a `toStringTag` fallback. */
66
+ function is(type, value) {
67
+ if (arguments.length === 1) return (value) => is(type, value);
68
+ return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
69
+ }
70
+ function isArrayBufferLike(value) {
71
+ return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
72
+ }
73
+ function isArrayBufferSource(value) {
74
+ return isArrayBufferLike(value) || ArrayBuffer.isView(value);
75
+ }
76
+ /** Binary source detection and base64/hex conversion helpers. */
77
+ var Binary;
78
+ (function(Binary) {
79
+ Binary.is = isArrayBufferLike;
80
+ Binary.isSource = isArrayBufferSource;
81
+ function fromSource(source) {
82
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
83
+ else return source;
84
+ }
85
+ Binary.fromSource = fromSource;
86
+ function toBase64(source) {
87
+ source = fromSource(source);
88
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
89
+ let binary = "";
90
+ const bytes = new Uint8Array(source);
91
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
92
+ return btoa(binary);
93
+ }
94
+ Binary.toBase64 = toBase64;
95
+ function fromBase64(source) {
96
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
97
+ return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
98
+ }
99
+ Binary.fromBase64 = fromBase64;
100
+ function toHex(source) {
101
+ source = fromSource(source);
102
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
103
+ return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
104
+ }
105
+ Binary.toHex = toHex;
106
+ function fromHex(source) {
107
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
108
+ const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
109
+ const buffer = [];
110
+ for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
111
+ return Uint8Array.from(buffer).buffer;
112
+ }
113
+ Binary.fromHex = fromHex;
114
+ })(Binary || (Binary = {}));
115
+ Binary.fromBase64;
116
+ Binary.toBase64;
117
+ Binary.fromHex;
118
+ Binary.toHex;
119
+ /** Deep-clone common JavaScript values while preserving prototypes and cycles. */
120
+ function clone(source, refs = /* @__PURE__ */ new Map()) {
121
+ if (!source || typeof source !== "object") return source;
122
+ if (is("Date", source)) return new Date(source.valueOf());
123
+ if (is("RegExp", source)) return new RegExp(source.source, source.flags);
124
+ if (isArrayBufferLike(source)) return source.slice(0);
125
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
126
+ const cached = refs.get(source);
127
+ if (cached) return cached;
128
+ if (Array.isArray(source)) {
129
+ const result = [];
130
+ refs.set(source, result);
131
+ source.forEach((value, index) => {
132
+ result[index] = Reflect.apply(clone, null, [value, refs]);
133
+ });
134
+ return result;
135
+ }
136
+ const result = Object.create(Object.getPrototypeOf(source));
137
+ refs.set(source, result);
138
+ for (const key of Reflect.ownKeys(source)) {
139
+ const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
140
+ if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
141
+ Reflect.defineProperty(result, key, descriptor);
142
+ }
143
+ return result;
144
+ }
145
+ /**
146
+ * Compare values recursively, treating two volatile references as equal regardless of value.
147
+ * Strict comparison distinguishes null/undefined, treats opaque objects by identity,
148
+ * compares URLs by normalized href, treats array holes as undefined, and considers distinct cyclic structures unequal.
149
+ * @param a - first value.
150
+ * @param b - second value.
151
+ * @param strict - whether to require strict data equality outside volatile references.
152
+ * @returns whether the values compare equal.
153
+ */
154
+ function deepEqual(a, b, strict) {
155
+ const ancestors = /* @__PURE__ */ new Set();
156
+ function compare(a, b) {
157
+ if (a === b) return true;
158
+ if (isVolatile(a) || isVolatile(b)) return isVolatile(a) && isVolatile(b);
159
+ if (!strict && isNullable(a) && isNullable(b)) return true;
160
+ if (typeof a !== typeof b || typeof a !== "object" || !a || !b) return false;
161
+ if (ancestors.has(a)) return false;
162
+ function check(test, then) {
163
+ return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
164
+ }
165
+ ancestors.add(a);
166
+ try {
167
+ return check(Array.isArray, (a, b) => {
168
+ if (a.length !== b.length) return false;
169
+ for (let index = 0; index < a.length; index++) if (!compare(a[index], b[index])) return false;
170
+ return true;
171
+ }) ?? 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) => {
172
+ if (a.byteLength !== b.byteLength) return false;
173
+ const viewA = new Uint8Array(a);
174
+ const viewB = new Uint8Array(b);
175
+ for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
176
+ return true;
177
+ }) ?? ((!strict || [a, b].every((value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) && Object.keys({
178
+ ...a,
179
+ ...b
180
+ }).every((key) => compare(a[key], b[key])));
181
+ } finally {
182
+ ancestors.delete(a);
183
+ }
184
+ }
185
+ return compare(a, b);
186
+ }
187
+ /** Time constants plus parsing and formatting helpers. */
188
+ var Time;
189
+ (function(Time) {
190
+ Time.millisecond = 1;
191
+ Time.second = 1e3;
192
+ Time.minute = Time.second * 60;
193
+ Time.hour = Time.minute * 60;
194
+ Time.day = Time.hour * 24;
195
+ Time.week = Time.day * 7;
196
+ let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
197
+ function setTimezoneOffset(offset) {
198
+ timezoneOffset = offset;
199
+ }
200
+ Time.setTimezoneOffset = setTimezoneOffset;
201
+ function getTimezoneOffset() {
202
+ return timezoneOffset;
203
+ }
204
+ Time.getTimezoneOffset = getTimezoneOffset;
205
+ function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
206
+ if (typeof date === "number") date = new Date(date);
207
+ if (offset === void 0) offset = timezoneOffset;
208
+ return Math.floor((date.valueOf() / Time.minute - offset) / 1440);
209
+ }
210
+ Time.getDateNumber = getDateNumber;
211
+ function fromDateNumber(value, offset) {
212
+ const date = new Date(value * Time.day);
213
+ if (offset === void 0) offset = timezoneOffset;
214
+ return new Date(+date + offset * Time.minute);
215
+ }
216
+ Time.fromDateNumber = fromDateNumber;
217
+ const numeric = /\d+(?:\.\d+)?/.source;
218
+ const timeRegExp = new RegExp(`^${[
219
+ "w(?:eek(?:s)?)?",
220
+ "d(?:ay(?:s)?)?",
221
+ "h(?:our(?:s)?)?",
222
+ "m(?:in(?:ute)?(?:s)?)?",
223
+ "s(?:ec(?:ond)?(?:s)?)?"
224
+ ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
225
+ function parseTime(source) {
226
+ const capture = timeRegExp.exec(source);
227
+ if (!capture) return 0;
228
+ return (parseFloat(capture[1]) * Time.week || 0) + (parseFloat(capture[2]) * Time.day || 0) + (parseFloat(capture[3]) * Time.hour || 0) + (parseFloat(capture[4]) * Time.minute || 0) + (parseFloat(capture[5]) * Time.second || 0);
229
+ }
230
+ Time.parseTime = parseTime;
231
+ function parseDate(date) {
232
+ const parsed = parseTime(date);
233
+ if (parsed) date = Date.now() + parsed;
234
+ else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
235
+ else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
236
+ return date ? new Date(date) : /* @__PURE__ */ new Date();
237
+ }
238
+ Time.parseDate = parseDate;
239
+ function format(ms) {
240
+ const abs = Math.abs(ms);
241
+ if (abs >= Time.day - Time.hour / 2) return Math.round(ms / Time.day) + "d";
242
+ else if (abs >= Time.hour - Time.minute / 2) return Math.round(ms / Time.hour) + "h";
243
+ else if (abs >= Time.minute - Time.second / 2) return Math.round(ms / Time.minute) + "m";
244
+ else if (abs >= Time.second) return Math.round(ms / Time.second) + "s";
245
+ return ms + "ms";
246
+ }
247
+ Time.format = format;
248
+ function toDigits(source, length = 2) {
249
+ return source.toString().padStart(length, "0");
250
+ }
251
+ Time.toDigits = toDigits;
252
+ function template(template, time = /* @__PURE__ */ new Date()) {
253
+ 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));
254
+ }
255
+ Time.template = template;
256
+ })(Time || (Time = {}));
257
+ // ../../node_modules/.pnpm/@deepseek-ai+schemastery@3.18.5/node_modules/@deepseek-ai/schemastery/lib/index.mjs
258
+ const kSchema = Symbol.for("schemastery");
259
+ const kValidationError = Symbol.for("ValidationError");
260
+ globalThis.__schemastery_index__ ??= 0;
261
+ globalThis.__schemastery_refs__ = void 0;
262
+ var ValidationError = class extends TypeError {
263
+ options;
264
+ name = "ValidationError";
265
+ constructor(message, options) {
266
+ let prefix = "$";
267
+ for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
268
+ else if (typeof segment === "number") prefix += "[" + segment + "]";
269
+ else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
270
+ if (prefix.startsWith(".")) prefix = prefix.slice(1);
271
+ super((prefix === "$" ? "" : `${prefix} `) + message);
272
+ this.options = options;
273
+ }
274
+ static is(error) {
275
+ return !!error?.[kValidationError];
276
+ }
277
+ };
278
+ Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
279
+ const Schema = function(options) {
280
+ const schema = function(data, options = {}) {
281
+ return Schema.resolve(data, schema, options)[0];
282
+ };
283
+ if (options.refs) {
284
+ const refs = mapValues(options.refs, (options) => new Schema(options));
285
+ const getRef = (uid) => refs[uid];
286
+ for (const key in refs) {
287
+ const options = refs[key];
288
+ options.sKey = getRef(options.sKey);
289
+ options.inner = getRef(options.inner);
290
+ options.list = options.list && options.list.map(getRef);
291
+ options.dict = options.dict && mapValues(options.dict, getRef);
292
+ }
293
+ return refs[options.uid];
294
+ }
295
+ Object.assign(schema, options);
296
+ if (typeof schema.callback === "string") try {
297
+ schema.callback = new Function("return " + schema.callback)();
298
+ } catch {}
299
+ Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
300
+ Object.setPrototypeOf(schema, Schema.prototype);
301
+ schema.meta ||= {};
302
+ schema.toString = schema.toString.bind(schema);
303
+ return schema;
304
+ };
305
+ Schema.prototype = Object.create(Function.prototype);
306
+ Schema.prototype[kSchema] = true;
307
+ Object.defineProperty(Schema.prototype, "~standard", { get() {
308
+ return {
309
+ version: 1,
310
+ vendor: "schemastery",
311
+ validate: (value) => {
312
+ try {
313
+ return { value: Schema.resolve(value, this, {})[0] };
314
+ } catch (error) {
315
+ if (ValidationError.is(error)) return { issues: [{
316
+ message: error.message,
317
+ path: error.options.path
318
+ }] };
319
+ throw error;
320
+ }
321
+ }
322
+ };
323
+ } });
324
+ Schema.ValidationError = ValidationError;
325
+ Schema.prototype.toJSON = function toJSON() {
326
+ if (globalThis.__schemastery_refs__) {
327
+ globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
328
+ return this.uid;
329
+ }
330
+ globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
331
+ globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
332
+ const result = {
333
+ uid: this.uid,
334
+ refs: globalThis.__schemastery_refs__
335
+ };
336
+ globalThis.__schemastery_refs__ = void 0;
337
+ return result;
338
+ };
339
+ Schema.prototype.set = function set(key, value) {
340
+ this.dict[key] = value;
341
+ return this;
342
+ };
343
+ Schema.prototype.push = function push(value) {
344
+ this.list.push(value);
345
+ return this;
346
+ };
347
+ function mergeDesc(original, messages) {
348
+ const result = typeof original === "string" ? { "": original } : { ...original };
349
+ for (const locale in messages) {
350
+ const value = messages[locale];
351
+ if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
352
+ else if (typeof value === "string") result[locale] = value;
353
+ }
354
+ return result;
355
+ }
356
+ function getInner(value) {
357
+ return value?.$value ?? value?.$inner;
358
+ }
359
+ function extractKeys(data) {
360
+ return filterKeys(data ?? {}, (key) => !key.startsWith("$"));
361
+ }
362
+ Schema.prototype.i18n = function i18n(messages) {
363
+ const schema = Schema(this);
364
+ const desc = mergeDesc(schema.meta.description, messages);
365
+ if (Object.keys(desc).length) schema.meta.description = desc;
366
+ if (schema.dict) schema.dict = mapValues(schema.dict, (inner, key) => {
367
+ return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
368
+ });
369
+ if (schema.list) schema.list = schema.list.map((inner, index) => {
370
+ return inner.i18n(mapValues(messages, (data = {}) => {
371
+ if (Array.isArray(getInner(data))) return getInner(data)[index];
372
+ if (Array.isArray(data)) return data[index];
373
+ return extractKeys(data);
374
+ }));
375
+ });
376
+ if (schema.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
377
+ if (getInner(data)) return getInner(data);
378
+ return extractKeys(data);
379
+ }));
380
+ if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
381
+ return schema;
382
+ };
383
+ Schema.prototype.extra = function extra(key, value) {
384
+ const schema = Schema(this);
385
+ schema.meta = {
386
+ ...schema.meta,
387
+ [key]: value
388
+ };
389
+ return schema;
390
+ };
391
+ for (const key of [
392
+ "required",
393
+ "disabled",
394
+ "collapse",
395
+ "hidden",
396
+ "loose"
397
+ ]) Object.assign(Schema.prototype, { [key](value = true) {
398
+ const schema = Schema(this);
399
+ schema.meta = {
400
+ ...schema.meta,
401
+ [key]: value
402
+ };
403
+ return schema;
404
+ } });
405
+ Schema.prototype.deprecated = function deprecated() {
406
+ const schema = Schema(this);
407
+ schema.meta.badges ||= [];
408
+ schema.meta.badges.push({
409
+ text: "deprecated",
410
+ type: "danger"
411
+ });
412
+ return schema;
413
+ };
414
+ Schema.prototype.experimental = function experimental() {
415
+ const schema = Schema(this);
416
+ schema.meta.badges ||= [];
417
+ schema.meta.badges.push({
418
+ text: "experimental",
419
+ type: "warning"
420
+ });
421
+ return schema;
422
+ };
423
+ Schema.prototype.pattern = function pattern(regexp) {
424
+ const schema = Schema(this);
425
+ const pattern = pick(regexp, ["source", "flags"]);
426
+ schema.meta = {
427
+ ...schema.meta,
428
+ pattern
429
+ };
430
+ return schema;
431
+ };
432
+ Schema.prototype.simplify = function simplify(value) {
433
+ if (isVolatile(value)) value = value.get();
434
+ if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
435
+ if (isNullable(value)) return value;
436
+ if (this.type === "object" || this.type === "dict") {
437
+ const result = {};
438
+ for (const key in value) {
439
+ const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
440
+ if (this.type === "dict" || !isNullable(item)) result[key] = item;
441
+ }
442
+ if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
443
+ return result;
444
+ } else if (this.type === "array" || this.type === "tuple") {
445
+ const result = [];
446
+ value.forEach((value, index) => {
447
+ const schema = this.type === "array" ? this.inner : this.list[index];
448
+ const item = schema ? schema.simplify(value) : value;
449
+ result.push(item);
450
+ });
451
+ return result;
452
+ } else if (this.type === "intersect") {
453
+ const result = {};
454
+ for (const item of this.list) Object.assign(result, item.simplify(value));
455
+ return result;
456
+ } else if (this.type === "union") for (const schema of this.list) try {
457
+ Schema.resolve(value, schema, {});
458
+ return schema.simplify(value);
459
+ } catch {}
460
+ return value;
461
+ };
462
+ Schema.prototype.toString = function toString(inline) {
463
+ return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
464
+ };
465
+ Schema.prototype.role = function role(role, extra) {
466
+ const schema = Schema(this);
467
+ schema.meta = {
468
+ ...schema.meta,
469
+ role,
470
+ extra
471
+ };
472
+ return schema;
473
+ };
474
+ for (const key of [
475
+ "default",
476
+ "link",
477
+ "comment",
478
+ "description",
479
+ "max",
480
+ "min",
481
+ "step"
482
+ ]) Object.assign(Schema.prototype, { [key](value) {
483
+ const schema = Schema(this);
484
+ schema.meta = {
485
+ ...schema.meta,
486
+ [key]: value
487
+ };
488
+ return schema;
489
+ } });
490
+ Schema.prototype.volatile = function volatile() {
491
+ if (this.meta.volatile) throw new TypeError("volatile schema is already wrapped");
492
+ return this.extra("volatile", true);
493
+ };
494
+ const resolvers = {};
495
+ const checkedVolatile = Symbol("checked-volatile-schema");
496
+ function validateVolatileSchema(schema, path = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
497
+ const states = seen.get(schema) ?? /* @__PURE__ */ new Set();
498
+ if (states.has(blocked)) return;
499
+ states.add(blocked);
500
+ seen.set(schema, states);
501
+ if (schema.meta?.volatile && blocked) throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path });
502
+ const nested = blocked || !!schema.meta?.volatile;
503
+ if (schema.dict) for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path, key], nested, seen);
504
+ if (schema.sKey) validateVolatileSchema(schema.sKey, [...path, "<key>"], true, seen);
505
+ if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) validateVolatileSchema(schema.inner, [...path, "*"], true, seen);
506
+ if (schema.list) for (let index = 0; index < schema.list.length; index++) validateVolatileSchema(schema.list[index], [...path, String(index)], true, seen);
507
+ }
508
+ Schema.extend = function extend(type, resolve) {
509
+ resolvers[type] = resolve;
510
+ };
511
+ Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
512
+ if (!schema) return [data];
513
+ if (!options[checkedVolatile]) {
514
+ validateVolatileSchema(schema, options.path);
515
+ options = {
516
+ ...options,
517
+ [checkedVolatile]: true
518
+ };
519
+ }
520
+ if (schema.meta?.volatile) {
521
+ const inner = Schema(schema);
522
+ inner.meta = {
523
+ ...schema.meta,
524
+ volatile: false
525
+ };
526
+ const [value, adapted] = Schema.resolve(data, inner, options, strict);
527
+ try {
528
+ return [createVolatile(value), adapted];
529
+ } catch (error) {
530
+ throw new ValidationError(error instanceof Error ? error.message : String(error), options);
531
+ }
532
+ }
533
+ if (options.ignore?.(data, schema)) return [data];
534
+ if (isNullable(data) && schema.type !== "lazy") {
535
+ if (schema.meta.required) throw new ValidationError(`missing required value`, options);
536
+ let current = schema;
537
+ let fallback = schema.meta.default;
538
+ while (current?.type === "intersect" && isNullable(fallback)) {
539
+ current = current.list[0];
540
+ fallback = current?.meta.default;
541
+ }
542
+ if (isNullable(fallback)) return [data];
543
+ data = clone(fallback);
544
+ }
545
+ const callback = resolvers[schema.type];
546
+ if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
547
+ try {
548
+ return callback(data, schema, options, strict);
549
+ } catch (error) {
550
+ if (!schema.meta.loose) throw error;
551
+ return [schema.meta.default];
552
+ }
553
+ };
554
+ Schema.from = function from(source) {
555
+ if (isNullable(source)) return Schema.any();
556
+ else if ([
557
+ "string",
558
+ "number",
559
+ "boolean"
560
+ ].includes(typeof source)) return Schema.const(source).required();
561
+ else if (source[kSchema]) return source;
562
+ else if (typeof source === "function") switch (source) {
563
+ case String: return Schema.string().required();
564
+ case Number: return Schema.number().required();
565
+ case Boolean: return Schema.boolean().required();
566
+ case Function: return Schema.function().required();
567
+ default: return Schema.is(source).required();
568
+ }
569
+ else throw new TypeError(`cannot infer schema from ${source}`);
570
+ };
571
+ Schema.lazy = function lazy(builder) {
572
+ const toJSON = () => {
573
+ if (!schema.inner[kSchema]) {
574
+ schema.inner = schema.builder();
575
+ schema.inner.meta = {
576
+ ...schema.meta,
577
+ ...schema.inner.meta
578
+ };
579
+ }
580
+ return schema.inner.toJSON();
581
+ };
582
+ const schema = new Schema({
583
+ type: "lazy",
584
+ builder,
585
+ inner: { toJSON }
586
+ });
587
+ return schema;
588
+ };
589
+ Schema.natural = function natural() {
590
+ return Schema.number().step(1).min(0);
591
+ };
592
+ Schema.percent = function percent() {
593
+ return Schema.number().step(.01).min(0).max(1).role("slider");
594
+ };
595
+ Schema.date = function date() {
596
+ return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
597
+ const date = new Date(value);
598
+ if (isNaN(+date)) throw new ValidationError(`invalid date "${value}"`, options);
599
+ return date;
600
+ }, true)]);
601
+ };
602
+ Schema.regExp = function regExp(flag = "") {
603
+ return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
604
+ try {
605
+ return new RegExp(value, flag);
606
+ } catch (e) {
607
+ throw new ValidationError(e.message, options);
608
+ }
609
+ }, true)]);
610
+ };
611
+ Schema.arrayBuffer = function arrayBuffer(encoding) {
612
+ return Schema.union([
613
+ Schema.is(ArrayBuffer),
614
+ Schema.is(SharedArrayBuffer),
615
+ Schema.transform(Schema.any(), (value, options) => {
616
+ if (Binary.isSource(value)) return Binary.fromSource(value);
617
+ throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
618
+ }, true),
619
+ ...encoding ? [Schema.transform(Schema.string(), (value, options) => {
620
+ try {
621
+ return encoding === "base64" ? Binary.fromBase64(value) : Binary.fromHex(value);
622
+ } catch (e) {
623
+ throw new ValidationError(e.message, options);
624
+ }
625
+ }, true)] : []
626
+ ]);
627
+ };
628
+ Schema.extend("lazy", (data, schema, options, strict) => {
629
+ if (!schema.inner[kSchema]) {
630
+ schema.inner = schema.builder();
631
+ schema.inner.meta = {
632
+ ...schema.meta,
633
+ ...schema.inner.meta
634
+ };
635
+ validateVolatileSchema(schema.inner, options.path, true);
636
+ }
637
+ return Schema.resolve(data, schema.inner, options, strict);
638
+ });
639
+ Schema.extend("any", (data) => {
640
+ return [data];
641
+ });
642
+ Schema.extend("never", (data, _, options) => {
643
+ throw new ValidationError(`expected nullable but got ${data}`, options);
644
+ });
645
+ Schema.extend("const", (data, { value }, options) => {
646
+ if (deepEqual(data, value)) return [value];
647
+ throw new ValidationError(`expected ${value} but got ${data}`, options);
648
+ });
649
+ function checkWithinRange(data, meta, description, options, skipMin = false) {
650
+ const { max = Infinity, min = -Infinity } = meta;
651
+ if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
652
+ if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
653
+ }
654
+ Schema.extend("string", (data, { meta }, options) => {
655
+ if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
656
+ if (meta.pattern) {
657
+ const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
658
+ if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
659
+ }
660
+ checkWithinRange(data.length, meta, "string length", options);
661
+ return [data];
662
+ });
663
+ function decimalShift(data, digits) {
664
+ const str = data.toString();
665
+ if (str.includes("e")) return data * Math.pow(10, digits);
666
+ const index = str.indexOf(".");
667
+ if (index === -1) return data * Math.pow(10, digits);
668
+ const frac = str.slice(index + 1);
669
+ const integer = str.slice(0, index);
670
+ if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
671
+ return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
672
+ }
673
+ function isMultipleOf(data, min, step) {
674
+ step = Math.abs(step);
675
+ if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
676
+ const index = step.toString().indexOf(".");
677
+ const digits = step.toString().slice(index + 1).length;
678
+ return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
679
+ }
680
+ Schema.extend("number", (data, { meta }, options) => {
681
+ if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
682
+ checkWithinRange(data, meta, "number", options);
683
+ const { step } = meta;
684
+ if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
685
+ return [data];
686
+ });
687
+ Schema.extend("boolean", (data, _, options) => {
688
+ if (typeof data === "boolean") return [data];
689
+ throw new ValidationError(`expected boolean but got ${data}`, options);
690
+ });
691
+ Schema.extend("bitset", (data, { bits, meta }, options) => {
692
+ let value = 0, keys = [];
693
+ if (typeof data === "number") {
694
+ value = data;
695
+ for (const key in bits) if (data & bits[key]) keys.push(key);
696
+ } else if (Array.isArray(data)) {
697
+ keys = data;
698
+ for (const key of keys) {
699
+ if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
700
+ if (key in bits) value |= bits[key];
701
+ }
702
+ } else throw new ValidationError(`expected number or array but got ${data}`, options);
703
+ if (value === meta.default) return [value];
704
+ return [value, keys];
705
+ });
706
+ Schema.extend("function", (data, _, options) => {
707
+ if (typeof data === "function") return [data];
708
+ throw new ValidationError(`expected function but got ${data}`, options);
709
+ });
710
+ Schema.extend("is", (data, { constructor }, options) => {
711
+ if (typeof constructor === "function") {
712
+ if (data instanceof constructor) return [data];
713
+ throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
714
+ } else {
715
+ if (isNullable(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
716
+ let prototype = Object.getPrototypeOf(data);
717
+ while (prototype) {
718
+ if (prototype.constructor?.name === constructor) return [data];
719
+ prototype = Object.getPrototypeOf(prototype);
720
+ }
721
+ throw new ValidationError(`expected ${constructor} but got ${data}`, options);
722
+ }
723
+ });
724
+ function property(data, key, schema, options) {
725
+ try {
726
+ const [value, adapted] = Schema.resolve(data[key], schema, {
727
+ ...options,
728
+ path: [...options.path || [], key]
729
+ });
730
+ if (adapted !== void 0) data[key] = adapted;
731
+ return value;
732
+ } catch (e) {
733
+ if (!options?.autofix) throw e;
734
+ delete data[key];
735
+ return schema.meta.volatile ? createVolatile(schema.meta.default) : schema.meta.default;
736
+ }
737
+ }
738
+ Schema.extend("array", (data, { inner, meta }, options) => {
739
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
740
+ checkWithinRange(data.length, meta, "array length", options, !isNullable(inner.meta.default));
741
+ return [data.map((_, index) => property(data, index, inner, options))];
742
+ });
743
+ Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
744
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
745
+ const result = {};
746
+ for (const key in data) {
747
+ let rKey;
748
+ try {
749
+ rKey = Schema.resolve(key, sKey, options)[0];
750
+ } catch (error) {
751
+ if (strict) continue;
752
+ throw error;
753
+ }
754
+ result[rKey] = property(data, key, inner, options);
755
+ data[rKey] = data[key];
756
+ if (key !== rKey) delete data[key];
757
+ }
758
+ return [result];
759
+ });
760
+ Schema.extend("tuple", (data, { list }, options, strict) => {
761
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
762
+ const result = list.map((inner, index) => property(data, index, inner, options));
763
+ if (strict) return [result];
764
+ result.push(...data.slice(list.length));
765
+ return [result];
766
+ });
767
+ function merge(result, data) {
768
+ for (const key in data) {
769
+ if (key in result) continue;
770
+ result[key] = data[key];
771
+ }
772
+ }
773
+ Schema.extend("object", (data, { dict }, options, strict) => {
774
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
775
+ const result = {};
776
+ for (const key in dict) {
777
+ const value = property(data, key, dict[key], options);
778
+ if (!isNullable(value) || key in data) result[key] = value;
779
+ }
780
+ if (!strict) merge(result, data);
781
+ return [result];
782
+ });
783
+ Schema.extend("union", (data, { list, toString }, options, strict) => {
784
+ const messages = [];
785
+ for (const inner of list) try {
786
+ return Schema.resolve(data, inner, options, strict);
787
+ } catch (error) {
788
+ messages.push(error);
789
+ }
790
+ throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
791
+ });
792
+ Schema.extend("intersect", (data, { list, toString }, options, strict) => {
793
+ if (!list.length) return [data];
794
+ let result;
795
+ for (const inner of list) {
796
+ const value = Schema.resolve(data, inner, options, true)[0];
797
+ if (isNullable(value)) continue;
798
+ if (isNullable(result)) result = value;
799
+ else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
800
+ else if (typeof value === "object") merge(result ??= {}, value);
801
+ else if (result !== value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
802
+ }
803
+ if (!strict && isPlainObject(data)) merge(result, data);
804
+ return [result];
805
+ });
806
+ Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
807
+ const [result, adapted = data] = Schema.resolve(data, inner, options, true);
808
+ if (preserve) return [callback(result)];
809
+ else return [callback(result), callback(adapted)];
810
+ });
811
+ const formatters = {};
812
+ function defineMethod(name, keys, format) {
813
+ formatters[name] = format;
814
+ Object.assign(Schema, { [name](...args) {
815
+ const schema = new Schema({ type: name });
816
+ keys.forEach((key, index) => {
817
+ switch (key) {
818
+ case "sKey":
819
+ schema.sKey = args[index] ?? Schema.string();
820
+ break;
821
+ case "inner":
822
+ schema.inner = Schema.from(args[index]);
823
+ break;
824
+ case "list":
825
+ schema.list = args[index].map(Schema.from);
826
+ break;
827
+ case "dict":
828
+ schema.dict = mapValues(args[index], Schema.from);
829
+ break;
830
+ case "bits":
831
+ schema.bits = {};
832
+ for (const key in args[index]) {
833
+ if (typeof args[index][key] !== "number") continue;
834
+ schema.bits[key] = args[index][key];
835
+ }
836
+ break;
837
+ case "callback": {
838
+ const callback = schema.callback = args[index];
839
+ callback["toJSON"] ||= () => callback.toString();
840
+ break;
841
+ }
842
+ case "constructor": {
843
+ const constructor = schema.constructor = args[index];
844
+ if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
845
+ break;
846
+ }
847
+ default: schema[key] = args[index];
848
+ }
849
+ });
850
+ if (name === "object" || name === "dict") schema.meta.default = {};
851
+ else if (name === "array" || name === "tuple") schema.meta.default = [];
852
+ else if (name === "bitset") schema.meta.default = 0;
853
+ return schema;
854
+ } });
855
+ }
856
+ defineMethod("is", ["constructor"], ({ constructor }) => {
857
+ if (typeof constructor === "function") return constructor.name;
858
+ else return constructor;
859
+ });
860
+ defineMethod("any", [], () => "any");
861
+ defineMethod("never", [], () => "never");
862
+ defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
863
+ defineMethod("string", [], () => "string");
864
+ defineMethod("number", [], () => "number");
865
+ defineMethod("boolean", [], () => "boolean");
866
+ defineMethod("bitset", ["bits"], () => "bitset");
867
+ defineMethod("function", [], () => "function");
868
+ defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
869
+ defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
870
+ defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
871
+ defineMethod("object", ["dict"], ({ dict }) => {
872
+ if (Object.keys(dict).length === 0) return "{}";
873
+ return `{ ${Object.entries(dict).map(([key, inner]) => {
874
+ return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
875
+ }).join(", ")} }`;
876
+ });
877
+ defineMethod("union", ["list"], ({ list }, inline) => {
878
+ const result = list.map(({ toString: format }) => format()).join(" | ");
879
+ return inline ? `(${result})` : result;
880
+ });
881
+ defineMethod("intersect", ["list"], ({ list }) => {
882
+ return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
883
+ });
884
+ defineMethod("transform", [
885
+ "inner",
886
+ "callback",
887
+ "preserve"
888
+ ], ({ inner }, isInner) => inner.toString(isInner));
3
889
  // src/protocol.ts
4
890
  const channel = "/api";
5
891
  const method = "dungsil-ui-setting-skills/list";
892
+ const saveMethod = "dungsil-ui-setting-skills/save";
6
893
  // src/index.ts
7
894
  const name = "dungsil-ui-setting-skills";
8
- const inject = ["connection"];
9
- function apply(ctx) {
895
+ const inject = ["connection", "configEditor"];
896
+ const Config = Schema.object({ disabled: Schema.array(Schema.string()).default([]) });
897
+ function apply(ctx, config = {}) {
898
+ const editor = ctx.configEditor;
899
+ const entry = () => editor.entries().find((entry) => entry.options.name === "@dungsil/dsh-plugin-ui-setting-skills");
900
+ const disabled = () => entry()?.options.config?.disabled ?? config.disabled ?? [];
901
+ ctx.effect(() => {
902
+ const prototype = SkillRegistry.prototype;
903
+ const originalSnapshot = prototype.snapshot;
904
+ const originalGet = prototype.get;
905
+ const snapshot = async function(options) {
906
+ const result = await originalSnapshot.call(this, options);
907
+ return {
908
+ ...result,
909
+ skills: result.skills.filter((skill) => !disabled().includes(skill.name))
910
+ };
911
+ };
912
+ const get = async function(name, options) {
913
+ if (disabled().includes(name)) return void 0;
914
+ const result = await originalGet.call(this, name, options);
915
+ return disabled().includes(name) ? void 0 : result;
916
+ };
917
+ prototype.snapshot = snapshot;
918
+ prototype.get = get;
919
+ return () => {
920
+ if (prototype.snapshot === snapshot) prototype.snapshot = originalSnapshot;
921
+ if (prototype.get === get) prototype.get = originalGet;
922
+ };
923
+ }, "ui-setting-skills: DSH registry visibility");
10
924
  const lifetime = new AbortController();
11
925
  const provider = new FileSystemSkillProvider(ctx, {
12
926
  signal: lifetime.signal,
@@ -16,8 +930,8 @@ function apply(ctx) {
16
930
  lifetime.abort();
17
931
  await provider.dispose();
18
932
  }, "ui-setting-skills: dispose discovery");
19
- ctx.effect(() => ctx.connection.fetch.register({
20
- path: `${channel}/${method}`,
933
+ for (const endpoint of [method, saveMethod]) ctx.effect(() => ctx.connection.fetch.register({
934
+ path: `${channel}/${endpoint}`,
21
935
  methods: ["POST"],
22
936
  requestBody: "buffered",
23
937
  async fetch(request) {
@@ -27,7 +941,44 @@ function apply(ctx) {
27
941
  } catch {
28
942
  return new Response("Invalid request", { status: 400 });
29
943
  }
30
- if (!body.success || body.data.method !== "dungsil-ui-setting-skills/list") return new Response("Invalid request", { status: 400 });
944
+ if (!body.success || body.data.method !== endpoint) return new Response("Invalid request", { status: 400 });
945
+ if (endpoint === "dungsil-ui-setting-skills/save") {
946
+ const payload = body.data.payload;
947
+ if (!payload || typeof payload.name !== "string" || typeof payload.disabled !== "boolean") return new Response("Invalid request", { status: 400 });
948
+ let result;
949
+ try {
950
+ const target = entry();
951
+ if (!target) throw new Error("Settings entry unavailable");
952
+ const observation = await provider.list({ signal: request.signal });
953
+ if (!("candidates" in observation ? observation.candidates : observation).some((skill) => skill.name === payload.name && ["user-agents", "user-dsh"].includes(skill.source))) throw new Error("Unknown user skill");
954
+ await editor.edit(target, (current) => {
955
+ const names = current.disabled ?? [];
956
+ return {
957
+ ...current,
958
+ disabled: payload.disabled ? [.../* @__PURE__ */ new Set([...names, payload.name])] : names.filter((name) => name !== payload.name)
959
+ };
960
+ });
961
+ ctx.emit("skills/change");
962
+ result = {
963
+ ok: true,
964
+ value: { disabled: disabled() }
965
+ };
966
+ } catch {
967
+ result = {
968
+ ok: false,
969
+ error: {
970
+ code: "save_failed",
971
+ message: "Could not save skill settings.",
972
+ details: {}
973
+ }
974
+ };
975
+ }
976
+ return Response.json({
977
+ type: "server-response",
978
+ rpcId: body.data.rpcId,
979
+ result
980
+ }, { headers: { "Cache-Control": "no-store" } });
981
+ }
31
982
  let result;
32
983
  try {
33
984
  const signal = AbortSignal.any([
@@ -41,6 +992,7 @@ function apply(ctx) {
41
992
  result = {
42
993
  ok: true,
43
994
  value: {
995
+ disabled: disabled(),
44
996
  complete: "candidates" in observation ? observation.complete : true,
45
997
  skills: skills.flatMap((skill) => skill.source === "user-agents" || skill.source === "user-dsh" ? [{
46
998
  name: skill.name,
@@ -68,4 +1020,4 @@ function apply(ctx) {
68
1020
  }
69
1021
  }), "ui-setting-skills: owner-only list");
70
1022
  }
71
- export { apply, inject, name };
1023
+ export { Config, apply, inject, name };
package/locale/en.json CHANGED
@@ -5,12 +5,15 @@
5
5
  },
6
6
  "ui": {
7
7
  "nav": "Skills",
8
- "description": "Skills loaded from your shared agent and DSH skill directories. Same-name skills are listed separately for each source.",
9
- "agents": "Shared agent skills",
8
+ "description": "This setting applies only to DSH.",
9
+ "agents": "Shared skills",
10
10
  "dsh": "DSH skills",
11
11
  "loading": "Loading skills…",
12
12
  "empty": "No loaded skills from this source.",
13
13
  "error": "Could not load skills. Close and reopen this settings section to try again.",
14
- "incomplete": "Some skill sources could not be loaded. This list may be incomplete."
14
+ "incomplete": "Some skill sources could not be loaded. This list may be incomplete.",
15
+ "use": "Use",
16
+ "disabled": "Off",
17
+ "saveError": "Could not save the setting. Close and reopen this section to check the saved state before trying again."
15
18
  }
16
19
  }
package/locale/ko.json CHANGED
@@ -5,12 +5,15 @@
5
5
  },
6
6
  "ui": {
7
7
  "nav": "스킬",
8
- "description": "공용 에이전트 및 DSH 스킬 경로에서 불러온 스킬을 표시합니다. 이름이 같은 스킬도 출처별로 각각 표시합니다.",
9
- "agents": "공용 에이전트 스킬",
8
+ "description": "이 설정은 DSH에만 적용됩니다.",
9
+ "agents": "공용 스킬",
10
10
  "dsh": "DSH 스킬",
11
11
  "loading": "스킬을 불러오는 중입니다…",
12
12
  "empty": "이 경로에서 로드된 스킬이 없습니다.",
13
13
  "error": "스킬을 불러오지 못했습니다. 이 설정 항목을 닫았다가 다시 열어 주세요.",
14
- "incomplete": "일부 스킬 소스를 불러오지 못해 목록이 완전하지 않을 수 있습니다."
14
+ "incomplete": "일부 스킬 소스를 불러오지 못해 목록이 완전하지 않을 수 있습니다.",
15
+ "use": "사용",
16
+ "disabled": "꺼짐",
17
+ "saveError": "설정을 저장하지 못했습니다. 이 설정 항목을 닫았다가 다시 열어 저장 상태를 확인한 후 다시 시도해 주세요."
15
18
  }
16
19
  }
package/locale/zh.json CHANGED
@@ -5,12 +5,15 @@
5
5
  },
6
6
  "ui": {
7
7
  "nav": "技能",
8
- "description": "显示从共享代理和 DSH 技能目录加载的技能。同名技能按来源分别列出。",
9
- "agents": "共享代理技能",
8
+ "description": "此设置仅适用于 DSH。",
9
+ "agents": "共享技能",
10
10
  "dsh": "DSH 技能",
11
11
  "loading": "正在加载技能…",
12
12
  "empty": "未从此目录加载任何技能。",
13
13
  "error": "无法加载技能。请关闭并重新打开此设置项后重试。",
14
- "incomplete": "部分技能源无法加载,列表可能不完整。"
14
+ "incomplete": "部分技能源无法加载,列表可能不完整。",
15
+ "use": "使用",
16
+ "disabled": "已关闭",
17
+ "saveError": "无法保存设置。请关闭并重新打开此设置项,确认已保存的状态后重试。"
15
18
  }
16
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dungsil/dsh-plugin-ui-setting-skills",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "View loaded user skills in DeepSeek Harness settings.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,15 +25,19 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@deepseek-ai/cordis": "4.0.5",
28
+ "@deepseek-ai/dsh-app-boot": "0.2.1-rc.5",
28
29
  "@deepseek-ai/dsh-client-connection": "0.2.1-rc.5",
29
30
  "@deepseek-ai/dsh-client-locale": "0.2.1-rc.5",
30
- "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.5",
31
31
  "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.5",
32
32
  "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.5",
33
+ "@deepseek-ai/dsh-config-editor": "0.2.1-rc.5",
33
34
  "@deepseek-ai/dsh-credentials-local": "0.2.1-rc.5",
35
+ "@deepseek-ai/dsh-skill": "0.2.1-rc.5",
34
36
  "@deepseek-ai/dsh-skill-filesystem": "0.2.1-rc.5",
37
+ "@deepseek-ai/schemastery": "3.18.5",
35
38
  "@dungsil/dsh-tsconfig": "0.0.0",
36
39
  "@dungsil/dsh-tsdown": "0.0.0",
40
+ "@dungsil/dsh-ui": "0.0.0",
37
41
  "@types/react": "18.3.31",
38
42
  "react": "18.3.1",
39
43
  "tsdown": "0.23.4"
@@ -42,6 +46,8 @@
42
46
  "@deepseek-ai/cordis": "^4.0.5",
43
47
  "@deepseek-ai/dsh-client-connection": "^0.2.1-rc.5",
44
48
  "@deepseek-ai/dsh-client-ui-primitives": "^0.2.1-rc.5",
49
+ "@deepseek-ai/dsh-config-editor": "^0.2.1-rc.5",
50
+ "@deepseek-ai/dsh-skill": "^0.2.1-rc.5",
45
51
  "@deepseek-ai/dsh-skill-filesystem": "^0.2.1-rc.5"
46
52
  },
47
53
  "engines": {