dsh-context 0.17.0 → 0.18.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/lib/client.js CHANGED
@@ -1,9 +1,9 @@
1
- /* dsh-context client bundle — generated by scripts/build.mjs from src/client/ */
2
1
  window.__ModuleLoader__.load({
3
2
  id: "dsh-context",
4
3
  factory: (require) => {
5
4
  var module = { exports: {} };
6
5
  var exports = module.exports;
6
+
7
7
  "use strict";
8
8
 
9
9
  // src/client/i18n.ts
@@ -1086,8 +1086,13 @@ var STYLES = [
1086
1086
  ".lc-chart-dim .lc-turn-on { opacity: 1; }",
1087
1087
  ".lc-chart-tip { position: absolute; top: 0; transform: translateX(-50%); z-index: 5; white-space: nowrap; background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; padding: 3px 8px; font-size: 12px; color: var(--dsw-alias-label-primary); box-shadow: 0 2px 8px rgba(0,0,0,0.18); pointer-events: none; }",
1088
1088
  ".lc-bar:hover { background: var(--dsw-alias-bg-layer-2); }",
1089
- ".lc-bar-selected { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }",
1089
+ // Hovering previews a bar with a thin dashed frame; a CLICKED (locked)
1090
+ // bar must always show the strong solid frame, so the selected rule is
1091
+ // declared LAST (equal specificity) — otherwise the dashed hover frame
1092
+ // would keep overriding it while the pointer is still on the just-clicked
1093
+ // bar and the lock would only become visible after the pointer leaves.
1090
1094
  ".lc-bar-hovered { outline: 1px dashed var(--dsw-alias-brand-primary); outline-offset: 1px; }",
1095
+ ".lc-bar-selected { outline: 2px solid var(--dsw-alias-label-primary); outline-offset: 1px; }",
1091
1096
  ".lc-bar-in-turn { background: rgba(128,128,128,0.14); }",
1092
1097
  ".lc-bar-stack { display: flex; flex-direction: column-reverse; width: 100%; }",
1093
1098
  ".lc-bar-stack > div { width: 100%; }",
@@ -1337,7 +1342,7 @@ function makeEventList(kit) {
1337
1342
 
1338
1343
  // src/client/meta.ts
1339
1344
  var PLUGIN_NAME = "dsh-context";
1340
- var PLUGIN_VERSION = true ? "0.17.0" : "0.0.0-dev";
1345
+ var PLUGIN_VERSION = true ? "0.18.0" : "0.0.0-dev";
1341
1346
  var PLUGIN_REPO = true ? "https://github.com/bowenliang123/dsh-context" : "https://github.com/bowenliang123/dsh-context";
1342
1347
  var PLUGIN_REPO_SHORT = PLUGIN_REPO.replace(/^https?:\/\/github\.com\//, "");
1343
1348
 
@@ -1852,3 +1857,4 @@ module.exports = {
1852
1857
  return module.exports;
1853
1858
  },
1854
1859
  });
1860
+
package/lib/index.js CHANGED
@@ -152,850 +152,8 @@ function createContextHeadersDefinition() {
152
152
  // src/host/timeline.ts
153
153
  import { z as z3 } from "zod";
154
154
 
155
- // node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.2/node_modules/@deepseek-ai/cosmokit/lib/index.js
156
- function isNullable(value) {
157
- return value === null || value === void 0;
158
- }
159
- function isPlainObject(data) {
160
- return data && typeof data === "object" && !Array.isArray(data);
161
- }
162
- function filterKeys(object, filter) {
163
- return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
164
- }
165
- function mapValues(object, transform) {
166
- return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
167
- }
168
- function pick(source, keys, forced) {
169
- if (!keys) return { ...source };
170
- const result = {};
171
- for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
172
- return result;
173
- }
174
- function is(type, value) {
175
- if (arguments.length === 1) return (value2) => is(type, value2);
176
- return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
177
- }
178
- function isArrayBufferLike(value) {
179
- return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
180
- }
181
- function isArrayBufferSource(value) {
182
- return isArrayBufferLike(value) || ArrayBuffer.isView(value);
183
- }
184
- var Binary;
185
- (function(Binary2) {
186
- Binary2.is = isArrayBufferLike;
187
- Binary2.isSource = isArrayBufferSource;
188
- function fromSource(source) {
189
- if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
190
- else return source;
191
- }
192
- Binary2.fromSource = fromSource;
193
- function toBase64(source) {
194
- source = fromSource(source);
195
- if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
196
- let binary = "";
197
- const bytes = new Uint8Array(source);
198
- for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
199
- return btoa(binary);
200
- }
201
- Binary2.toBase64 = toBase64;
202
- function fromBase64(source) {
203
- if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
204
- return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
205
- }
206
- Binary2.fromBase64 = fromBase64;
207
- function toHex(source) {
208
- source = fromSource(source);
209
- if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
210
- return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
211
- }
212
- Binary2.toHex = toHex;
213
- function fromHex(source) {
214
- if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
215
- const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
216
- const buffer = [];
217
- for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
218
- return Uint8Array.from(buffer).buffer;
219
- }
220
- Binary2.fromHex = fromHex;
221
- })(Binary || (Binary = {}));
222
- var base64ToArrayBuffer = Binary.fromBase64;
223
- var arrayBufferToBase64 = Binary.toBase64;
224
- var hexToArrayBuffer = Binary.fromHex;
225
- var arrayBufferToHex = Binary.toHex;
226
- function clone(source, refs = /* @__PURE__ */ new Map()) {
227
- if (!source || typeof source !== "object") return source;
228
- if (is("Date", source)) return new Date(source.valueOf());
229
- if (is("RegExp", source)) return new RegExp(source.source, source.flags);
230
- if (isArrayBufferLike(source)) return source.slice(0);
231
- if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
232
- const cached = refs.get(source);
233
- if (cached) return cached;
234
- if (Array.isArray(source)) {
235
- const result2 = [];
236
- refs.set(source, result2);
237
- source.forEach((value, index) => {
238
- result2[index] = Reflect.apply(clone, null, [value, refs]);
239
- });
240
- return result2;
241
- }
242
- const result = Object.create(Object.getPrototypeOf(source));
243
- refs.set(source, result);
244
- for (const key of Reflect.ownKeys(source)) {
245
- const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
246
- if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
247
- Reflect.defineProperty(result, key, descriptor);
248
- }
249
- return result;
250
- }
251
- function deepEqual(a, b, strict) {
252
- if (a === b) return true;
253
- if (!strict && isNullable(a) && isNullable(b)) return true;
254
- if (typeof a !== typeof b) return false;
255
- if (typeof a !== "object") return false;
256
- if (!a || !b) return false;
257
- function check(test, then) {
258
- return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
259
- }
260
- return check(Array.isArray, (a2, b2) => a2.length === b2.length && a2.every((item, index) => deepEqual(item, b2[index]))) ?? check(is("Date"), (a2, b2) => a2.valueOf() === b2.valueOf()) ?? check(is("RegExp"), (a2, b2) => a2.source === b2.source && a2.flags === b2.flags) ?? check(isArrayBufferLike, (a2, b2) => {
261
- if (a2.byteLength !== b2.byteLength) return false;
262
- const viewA = new Uint8Array(a2);
263
- const viewB = new Uint8Array(b2);
264
- for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
265
- return true;
266
- }) ?? Object.keys({
267
- ...a,
268
- ...b
269
- }).every((key) => deepEqual(a[key], b[key], strict));
270
- }
271
- var Time;
272
- (function(Time2) {
273
- Time2.millisecond = 1;
274
- Time2.second = 1e3;
275
- Time2.minute = Time2.second * 60;
276
- Time2.hour = Time2.minute * 60;
277
- Time2.day = Time2.hour * 24;
278
- Time2.week = Time2.day * 7;
279
- let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
280
- function setTimezoneOffset(offset) {
281
- timezoneOffset = offset;
282
- }
283
- Time2.setTimezoneOffset = setTimezoneOffset;
284
- function getTimezoneOffset() {
285
- return timezoneOffset;
286
- }
287
- Time2.getTimezoneOffset = getTimezoneOffset;
288
- function getDateNumber(date2 = /* @__PURE__ */ new Date(), offset) {
289
- if (typeof date2 === "number") date2 = new Date(date2);
290
- if (offset === void 0) offset = timezoneOffset;
291
- return Math.floor((date2.valueOf() / Time2.minute - offset) / 1440);
292
- }
293
- Time2.getDateNumber = getDateNumber;
294
- function fromDateNumber(value, offset) {
295
- const date2 = new Date(value * Time2.day);
296
- if (offset === void 0) offset = timezoneOffset;
297
- return new Date(+date2 + offset * Time2.minute);
298
- }
299
- Time2.fromDateNumber = fromDateNumber;
300
- const numeric = /\d+(?:\.\d+)?/.source;
301
- const timeRegExp = new RegExp(`^${[
302
- "w(?:eek(?:s)?)?",
303
- "d(?:ay(?:s)?)?",
304
- "h(?:our(?:s)?)?",
305
- "m(?:in(?:ute)?(?:s)?)?",
306
- "s(?:ec(?:ond)?(?:s)?)?"
307
- ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
308
- function parseTime(source) {
309
- const capture = timeRegExp.exec(source);
310
- if (!capture) return 0;
311
- return (parseFloat(capture[1]) * Time2.week || 0) + (parseFloat(capture[2]) * Time2.day || 0) + (parseFloat(capture[3]) * Time2.hour || 0) + (parseFloat(capture[4]) * Time2.minute || 0) + (parseFloat(capture[5]) * Time2.second || 0);
312
- }
313
- Time2.parseTime = parseTime;
314
- function parseDate(date2) {
315
- const parsed = parseTime(date2);
316
- if (parsed) date2 = Date.now() + parsed;
317
- else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date2)) date2 = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date2}`;
318
- else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date2)) date2 = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date2}`;
319
- return date2 ? new Date(date2) : /* @__PURE__ */ new Date();
320
- }
321
- Time2.parseDate = parseDate;
322
- function format(ms) {
323
- const abs = Math.abs(ms);
324
- if (abs >= Time2.day - Time2.hour / 2) return Math.round(ms / Time2.day) + "d";
325
- else if (abs >= Time2.hour - Time2.minute / 2) return Math.round(ms / Time2.hour) + "h";
326
- else if (abs >= Time2.minute - Time2.second / 2) return Math.round(ms / Time2.minute) + "m";
327
- else if (abs >= Time2.second) return Math.round(ms / Time2.second) + "s";
328
- return ms + "ms";
329
- }
330
- Time2.format = format;
331
- function toDigits(source, length = 2) {
332
- return source.toString().padStart(length, "0");
333
- }
334
- Time2.toDigits = toDigits;
335
- function template(template2, time = /* @__PURE__ */ new Date()) {
336
- return template2.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));
337
- }
338
- Time2.template = template;
339
- })(Time || (Time = {}));
340
-
341
- // node_modules/.pnpm/@deepseek-ai+dsh-llm@0.1.0-rc.6_@deepseek-ai+cordis@4.0.1_@deepseek-ai+dsh-attachment@0_4ed4e5c71eb965b0bd6912871e829940/node_modules/@deepseek-ai/dsh-llm/lib/index.js
342
- import { createRequire } from "node:module";
343
-
344
- // node_modules/.pnpm/@deepseek-ai+schemastery@3.18.1/node_modules/@deepseek-ai/schemastery/lib/index.mjs
345
- var kSchema = /* @__PURE__ */ Symbol.for("schemastery");
346
- var kValidationError = /* @__PURE__ */ Symbol.for("ValidationError");
347
- globalThis.__schemastery_index__ ??= 0;
348
- globalThis.__schemastery_refs__ = void 0;
349
- var ValidationError = class extends TypeError {
350
- options;
351
- name = "ValidationError";
352
- constructor(message, options) {
353
- let prefix = "$";
354
- for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
355
- else if (typeof segment === "number") prefix += "[" + segment + "]";
356
- else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
357
- if (prefix.startsWith(".")) prefix = prefix.slice(1);
358
- super((prefix === "$" ? "" : `${prefix} `) + message);
359
- this.options = options;
360
- }
361
- static is(error) {
362
- return !!error?.[kValidationError];
363
- }
364
- };
365
- Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
366
- var Schema = function(options) {
367
- const schema = function(data, options2 = {}) {
368
- return Schema.resolve(data, schema, options2)[0];
369
- };
370
- if (options.refs) {
371
- const refs = mapValues(options.refs, (options2) => new Schema(options2));
372
- const getRef = (uid) => refs[uid];
373
- for (const key in refs) {
374
- const options2 = refs[key];
375
- options2.sKey = getRef(options2.sKey);
376
- options2.inner = getRef(options2.inner);
377
- options2.list = options2.list && options2.list.map(getRef);
378
- options2.dict = options2.dict && mapValues(options2.dict, getRef);
379
- }
380
- return refs[options.uid];
381
- }
382
- Object.assign(schema, options);
383
- if (typeof schema.callback === "string") try {
384
- schema.callback = new Function("return " + schema.callback)();
385
- } catch {
386
- }
387
- Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
388
- Object.setPrototypeOf(schema, Schema.prototype);
389
- schema.meta ||= {};
390
- schema.toString = schema.toString.bind(schema);
391
- return schema;
392
- };
393
- Schema.prototype = Object.create(Function.prototype);
394
- Schema.prototype[kSchema] = true;
395
- Object.defineProperty(Schema.prototype, "~standard", { get() {
396
- return {
397
- version: 1,
398
- vendor: "schemastery",
399
- validate: (value) => {
400
- try {
401
- return { value: Schema.resolve(value, this, {})[0] };
402
- } catch (error) {
403
- if (ValidationError.is(error)) return { issues: [{
404
- message: error.message,
405
- path: error.options.path
406
- }] };
407
- throw error;
408
- }
409
- }
410
- };
411
- } });
412
- Schema.ValidationError = ValidationError;
413
- Schema.prototype.toJSON = function toJSON() {
414
- if (globalThis.__schemastery_refs__) {
415
- globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
416
- return this.uid;
417
- }
418
- globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
419
- globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
420
- const result = {
421
- uid: this.uid,
422
- refs: globalThis.__schemastery_refs__
423
- };
424
- globalThis.__schemastery_refs__ = void 0;
425
- return result;
426
- };
427
- Schema.prototype.set = function set(key, value) {
428
- this.dict[key] = value;
429
- return this;
430
- };
431
- Schema.prototype.push = function push(value) {
432
- this.list.push(value);
433
- return this;
434
- };
435
- function mergeDesc(original, messages) {
436
- const result = typeof original === "string" ? { "": original } : { ...original };
437
- for (const locale in messages) {
438
- const value = messages[locale];
439
- if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
440
- else if (typeof value === "string") result[locale] = value;
441
- }
442
- return result;
443
- }
444
- function getInner(value) {
445
- return value?.$value ?? value?.$inner;
446
- }
447
- function extractKeys(data) {
448
- return filterKeys(data ?? {}, (key) => !key.startsWith("$"));
449
- }
450
- Schema.prototype.i18n = function i18n(messages) {
451
- const schema = Schema(this);
452
- const desc = mergeDesc(schema.meta.description, messages);
453
- if (Object.keys(desc).length) schema.meta.description = desc;
454
- if (schema.dict) schema.dict = mapValues(schema.dict, (inner, key) => {
455
- return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
456
- });
457
- if (schema.list) schema.list = schema.list.map((inner, index) => {
458
- return inner.i18n(mapValues(messages, (data = {}) => {
459
- if (Array.isArray(getInner(data))) return getInner(data)[index];
460
- if (Array.isArray(data)) return data[index];
461
- return extractKeys(data);
462
- }));
463
- });
464
- if (schema.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
465
- if (getInner(data)) return getInner(data);
466
- return extractKeys(data);
467
- }));
468
- if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
469
- return schema;
470
- };
471
- Schema.prototype.extra = function extra(key, value) {
472
- const schema = Schema(this);
473
- schema.meta = {
474
- ...schema.meta,
475
- [key]: value
476
- };
477
- return schema;
478
- };
479
- for (const key of [
480
- "required",
481
- "disabled",
482
- "collapse",
483
- "hidden",
484
- "loose"
485
- ]) Object.assign(Schema.prototype, { [key](value = true) {
486
- const schema = Schema(this);
487
- schema.meta = {
488
- ...schema.meta,
489
- [key]: value
490
- };
491
- return schema;
492
- } });
493
- Schema.prototype.deprecated = function deprecated() {
494
- const schema = Schema(this);
495
- schema.meta.badges ||= [];
496
- schema.meta.badges.push({
497
- text: "deprecated",
498
- type: "danger"
499
- });
500
- return schema;
501
- };
502
- Schema.prototype.experimental = function experimental() {
503
- const schema = Schema(this);
504
- schema.meta.badges ||= [];
505
- schema.meta.badges.push({
506
- text: "experimental",
507
- type: "warning"
508
- });
509
- return schema;
510
- };
511
- Schema.prototype.pattern = function pattern(regexp) {
512
- const schema = Schema(this);
513
- const pattern2 = pick(regexp, ["source", "flags"]);
514
- schema.meta = {
515
- ...schema.meta,
516
- pattern: pattern2
517
- };
518
- return schema;
519
- };
520
- Schema.prototype.simplify = function simplify(value) {
521
- if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
522
- if (isNullable(value)) return value;
523
- if (this.type === "object" || this.type === "dict") {
524
- const result = {};
525
- for (const key in value) {
526
- const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
527
- if (this.type === "dict" || !isNullable(item)) result[key] = item;
528
- }
529
- if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
530
- return result;
531
- } else if (this.type === "array" || this.type === "tuple") {
532
- const result = [];
533
- value.forEach((value2, index) => {
534
- const schema = this.type === "array" ? this.inner : this.list[index];
535
- const item = schema ? schema.simplify(value2) : value2;
536
- result.push(item);
537
- });
538
- return result;
539
- } else if (this.type === "intersect") {
540
- const result = {};
541
- for (const item of this.list) Object.assign(result, item.simplify(value));
542
- return result;
543
- } else if (this.type === "union") for (const schema of this.list) try {
544
- Schema.resolve(value, schema, {});
545
- return schema.simplify(value);
546
- } catch {
547
- }
548
- return value;
549
- };
550
- Schema.prototype.toString = function toString(inline) {
551
- return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
552
- };
553
- Schema.prototype.role = function role(role, extra2) {
554
- const schema = Schema(this);
555
- schema.meta = {
556
- ...schema.meta,
557
- role,
558
- extra: extra2
559
- };
560
- return schema;
561
- };
562
- for (const key of [
563
- "default",
564
- "link",
565
- "comment",
566
- "description",
567
- "max",
568
- "min",
569
- "step"
570
- ]) Object.assign(Schema.prototype, { [key](value) {
571
- const schema = Schema(this);
572
- schema.meta = {
573
- ...schema.meta,
574
- [key]: value
575
- };
576
- return schema;
577
- } });
578
- var resolvers = {};
579
- Schema.extend = function extend(type, resolve2) {
580
- resolvers[type] = resolve2;
581
- };
582
- Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
583
- if (!schema) return [data];
584
- if (options.ignore?.(data, schema)) return [data];
585
- if (isNullable(data) && schema.type !== "lazy") {
586
- if (schema.meta.required) throw new ValidationError(`missing required value`, options);
587
- let current = schema;
588
- let fallback = schema.meta.default;
589
- while (current?.type === "intersect" && isNullable(fallback)) {
590
- current = current.list[0];
591
- fallback = current?.meta.default;
592
- }
593
- if (isNullable(fallback)) return [data];
594
- data = clone(fallback);
595
- }
596
- const callback = resolvers[schema.type];
597
- if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
598
- try {
599
- return callback(data, schema, options, strict);
600
- } catch (error) {
601
- if (!schema.meta.loose) throw error;
602
- return [schema.meta.default];
603
- }
604
- };
605
- Schema.from = function from(source) {
606
- if (isNullable(source)) return Schema.any();
607
- else if ([
608
- "string",
609
- "number",
610
- "boolean"
611
- ].includes(typeof source)) return Schema.const(source).required();
612
- else if (source[kSchema]) return source;
613
- else if (typeof source === "function") switch (source) {
614
- case String:
615
- return Schema.string().required();
616
- case Number:
617
- return Schema.number().required();
618
- case Boolean:
619
- return Schema.boolean().required();
620
- case Function:
621
- return Schema.function().required();
622
- default:
623
- return Schema.is(source).required();
624
- }
625
- else throw new TypeError(`cannot infer schema from ${source}`);
626
- };
627
- Schema.lazy = function lazy(builder) {
628
- const toJSON2 = () => {
629
- if (!schema.inner[kSchema]) {
630
- schema.inner = schema.builder();
631
- schema.inner.meta = {
632
- ...schema.meta,
633
- ...schema.inner.meta
634
- };
635
- }
636
- return schema.inner.toJSON();
637
- };
638
- const schema = new Schema({
639
- type: "lazy",
640
- builder,
641
- inner: { toJSON: toJSON2 }
642
- });
643
- return schema;
644
- };
645
- Schema.natural = function natural() {
646
- return Schema.number().step(1).min(0);
647
- };
648
- Schema.percent = function percent() {
649
- return Schema.number().step(0.01).min(0).max(1).role("slider");
650
- };
651
- Schema.date = function date() {
652
- return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
653
- const date2 = new Date(value);
654
- if (isNaN(+date2)) throw new ValidationError(`invalid date "${value}"`, options);
655
- return date2;
656
- }, true)]);
657
- };
658
- Schema.regExp = function regExp(flag = "") {
659
- return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
660
- try {
661
- return new RegExp(value, flag);
662
- } catch (e) {
663
- throw new ValidationError(e.message, options);
664
- }
665
- }, true)]);
666
- };
667
- Schema.arrayBuffer = function arrayBuffer(encoding) {
668
- return Schema.union([
669
- Schema.is(ArrayBuffer),
670
- Schema.is(SharedArrayBuffer),
671
- Schema.transform(Schema.any(), (value, options) => {
672
- if (Binary.isSource(value)) return Binary.fromSource(value);
673
- throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
674
- }, true),
675
- ...encoding ? [Schema.transform(Schema.string(), (value, options) => {
676
- try {
677
- return encoding === "base64" ? Binary.fromBase64(value) : Binary.fromHex(value);
678
- } catch (e) {
679
- throw new ValidationError(e.message, options);
680
- }
681
- }, true)] : []
682
- ]);
683
- };
684
- Schema.extend("lazy", (data, schema, options, strict) => {
685
- if (!schema.inner[kSchema]) {
686
- schema.inner = schema.builder();
687
- schema.inner.meta = {
688
- ...schema.meta,
689
- ...schema.inner.meta
690
- };
691
- }
692
- return Schema.resolve(data, schema.inner, options, strict);
693
- });
694
- Schema.extend("any", (data) => {
695
- return [data];
696
- });
697
- Schema.extend("never", (data, _, options) => {
698
- throw new ValidationError(`expected nullable but got ${data}`, options);
699
- });
700
- Schema.extend("const", (data, { value }, options) => {
701
- if (deepEqual(data, value)) return [value];
702
- throw new ValidationError(`expected ${value} but got ${data}`, options);
703
- });
704
- function checkWithinRange(data, meta, description, options, skipMin = false) {
705
- const { max = Infinity, min = -Infinity } = meta;
706
- if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
707
- if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
708
- }
709
- Schema.extend("string", (data, { meta }, options) => {
710
- if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
711
- if (meta.pattern) {
712
- const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
713
- if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
714
- }
715
- checkWithinRange(data.length, meta, "string length", options);
716
- return [data];
717
- });
718
- function decimalShift(data, digits) {
719
- const str = data.toString();
720
- if (str.includes("e")) return data * Math.pow(10, digits);
721
- const index = str.indexOf(".");
722
- if (index === -1) return data * Math.pow(10, digits);
723
- const frac = str.slice(index + 1);
724
- const integer = str.slice(0, index);
725
- if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
726
- return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
727
- }
728
- function isMultipleOf(data, min, step) {
729
- step = Math.abs(step);
730
- if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
731
- const index = step.toString().indexOf(".");
732
- const digits = step.toString().slice(index + 1).length;
733
- return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
734
- }
735
- Schema.extend("number", (data, { meta }, options) => {
736
- if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
737
- checkWithinRange(data, meta, "number", options);
738
- const { step } = meta;
739
- if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
740
- return [data];
741
- });
742
- Schema.extend("boolean", (data, _, options) => {
743
- if (typeof data === "boolean") return [data];
744
- throw new ValidationError(`expected boolean but got ${data}`, options);
745
- });
746
- Schema.extend("bitset", (data, { bits, meta }, options) => {
747
- let value = 0, keys = [];
748
- if (typeof data === "number") {
749
- value = data;
750
- for (const key in bits) if (data & bits[key]) keys.push(key);
751
- } else if (Array.isArray(data)) {
752
- keys = data;
753
- for (const key of keys) {
754
- if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
755
- if (key in bits) value |= bits[key];
756
- }
757
- } else throw new ValidationError(`expected number or array but got ${data}`, options);
758
- if (value === meta.default) return [value];
759
- return [value, keys];
760
- });
761
- Schema.extend("function", (data, _, options) => {
762
- if (typeof data === "function") return [data];
763
- throw new ValidationError(`expected function but got ${data}`, options);
764
- });
765
- Schema.extend("is", (data, { constructor }, options) => {
766
- if (typeof constructor === "function") {
767
- if (data instanceof constructor) return [data];
768
- throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
769
- } else {
770
- if (isNullable(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
771
- let prototype = Object.getPrototypeOf(data);
772
- while (prototype) {
773
- if (prototype.constructor?.name === constructor) return [data];
774
- prototype = Object.getPrototypeOf(prototype);
775
- }
776
- throw new ValidationError(`expected ${constructor} but got ${data}`, options);
777
- }
778
- });
779
- function property(data, key, schema, options) {
780
- try {
781
- const [value, adapted] = Schema.resolve(data[key], schema, {
782
- ...options,
783
- path: [...options.path || [], key]
784
- });
785
- if (adapted !== void 0) data[key] = adapted;
786
- return value;
787
- } catch (e) {
788
- if (!options?.autofix) throw e;
789
- delete data[key];
790
- return schema.meta.default;
791
- }
792
- }
793
- Schema.extend("array", (data, { inner, meta }, options) => {
794
- if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
795
- checkWithinRange(data.length, meta, "array length", options, !isNullable(inner.meta.default));
796
- return [data.map((_, index) => property(data, index, inner, options))];
797
- });
798
- Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
799
- if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
800
- const result = {};
801
- for (const key in data) {
802
- let rKey;
803
- try {
804
- rKey = Schema.resolve(key, sKey, options)[0];
805
- } catch (error) {
806
- if (strict) continue;
807
- throw error;
808
- }
809
- result[rKey] = property(data, key, inner, options);
810
- data[rKey] = data[key];
811
- if (key !== rKey) delete data[key];
812
- }
813
- return [result];
814
- });
815
- Schema.extend("tuple", (data, { list }, options, strict) => {
816
- if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
817
- const result = list.map((inner, index) => property(data, index, inner, options));
818
- if (strict) return [result];
819
- result.push(...data.slice(list.length));
820
- return [result];
821
- });
822
- function merge(result, data) {
823
- for (const key in data) {
824
- if (key in result) continue;
825
- result[key] = data[key];
826
- }
827
- }
828
- Schema.extend("object", (data, { dict }, options, strict) => {
829
- if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
830
- const result = {};
831
- for (const key in dict) {
832
- const value = property(data, key, dict[key], options);
833
- if (!isNullable(value) || key in data) result[key] = value;
834
- }
835
- if (!strict) merge(result, data);
836
- return [result];
837
- });
838
- Schema.extend("union", (data, { list, toString: toString2 }, options, strict) => {
839
- const messages = [];
840
- for (const inner of list) try {
841
- return Schema.resolve(data, inner, options, strict);
842
- } catch (error) {
843
- messages.push(error);
844
- }
845
- throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
846
- });
847
- Schema.extend("intersect", (data, { list, toString: toString2 }, options, strict) => {
848
- if (!list.length) return [data];
849
- let result;
850
- for (const inner of list) {
851
- const value = Schema.resolve(data, inner, options, true)[0];
852
- if (isNullable(value)) continue;
853
- if (isNullable(result)) result = value;
854
- else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
855
- else if (typeof value === "object") merge(result ??= {}, value);
856
- else if (result !== value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
857
- }
858
- if (!strict && isPlainObject(data)) merge(result, data);
859
- return [result];
860
- });
861
- Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
862
- const [result, adapted = data] = Schema.resolve(data, inner, options, true);
863
- if (preserve) return [callback(result)];
864
- else return [callback(result), callback(adapted)];
865
- });
866
- var formatters = {};
867
- function defineMethod(name2, keys, format) {
868
- formatters[name2] = format;
869
- Object.assign(Schema, { [name2](...args) {
870
- const schema = new Schema({ type: name2 });
871
- keys.forEach((key, index) => {
872
- switch (key) {
873
- case "sKey":
874
- schema.sKey = args[index] ?? Schema.string();
875
- break;
876
- case "inner":
877
- schema.inner = Schema.from(args[index]);
878
- break;
879
- case "list":
880
- schema.list = args[index].map(Schema.from);
881
- break;
882
- case "dict":
883
- schema.dict = mapValues(args[index], Schema.from);
884
- break;
885
- case "bits":
886
- schema.bits = {};
887
- for (const key2 in args[index]) {
888
- if (typeof args[index][key2] !== "number") continue;
889
- schema.bits[key2] = args[index][key2];
890
- }
891
- break;
892
- case "callback": {
893
- const callback = schema.callback = args[index];
894
- callback["toJSON"] ||= () => callback.toString();
895
- break;
896
- }
897
- case "constructor": {
898
- const constructor = schema.constructor = args[index];
899
- if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
900
- break;
901
- }
902
- default:
903
- schema[key] = args[index];
904
- }
905
- });
906
- if (name2 === "object" || name2 === "dict") schema.meta.default = {};
907
- else if (name2 === "array" || name2 === "tuple") schema.meta.default = [];
908
- else if (name2 === "bitset") schema.meta.default = 0;
909
- return schema;
910
- } });
911
- }
912
- defineMethod("is", ["constructor"], ({ constructor }) => {
913
- if (typeof constructor === "function") return constructor.name;
914
- else return constructor;
915
- });
916
- defineMethod("any", [], () => "any");
917
- defineMethod("never", [], () => "never");
918
- defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
919
- defineMethod("string", [], () => "string");
920
- defineMethod("number", [], () => "number");
921
- defineMethod("boolean", [], () => "boolean");
922
- defineMethod("bitset", ["bits"], () => "bitset");
923
- defineMethod("function", [], () => "function");
924
- defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
925
- defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
926
- defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
927
- defineMethod("object", ["dict"], ({ dict }) => {
928
- if (Object.keys(dict).length === 0) return "{}";
929
- return `{ ${Object.entries(dict).map(([key, inner]) => {
930
- return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
931
- }).join(", ")} }`;
932
- });
933
- defineMethod("union", ["list"], ({ list }, inline) => {
934
- const result = list.map(({ toString: format }) => format()).join(" | ");
935
- return inline ? `(${result})` : result;
936
- });
937
- defineMethod("intersect", ["list"], ({ list }) => {
938
- return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
939
- });
940
- defineMethod("transform", [
941
- "inner",
942
- "callback",
943
- "preserve"
944
- ], ({ inner }, isInner) => inner.toString(isInner));
945
-
946
- // node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.1.0-rc.6_@deepseek-ai+cordis@4.0.1_@deepseek-ai+dsh-invarian_8c173ab999b05cf1db05d479dd44e888/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
947
- var MAX_TIMER_DELAY_MS = 2147483647;
948
-
949
- // node_modules/.pnpm/@deepseek-ai+dsh-llm@0.1.0-rc.6_@deepseek-ai+cordis@4.0.1_@deepseek-ai+dsh-attachment@0_4ed4e5c71eb965b0bd6912871e829940/node_modules/@deepseek-ai/dsh-llm/lib/index.js
950
- var EMPTY_RESPONSE_CODE = "EMPTY_RESPONSE";
951
- var STRUCTURED_CONTEXT_OVERFLOW = new RegExp(String.raw`(?:^|[^a-z0-9])context[\s_-](?:length|window)[\s_-]` + String.raw`(?:exceed(?:ed|s)?|overflow(?:ed)?|limit[\s_-]exceeded)(?:$|[^a-z0-9])`, "i");
952
- var TOO_LARGE_FOR_CONTEXT = new RegExp(String.raw`\b(?:request|prompt|input|messages?)\s+(?:is\s+|are\s+)?` + String.raw`too\s+(?:large|long)\s+for\s+(?:(?:this|the)\s+)?` + String.raw`(?:model(?:'s)?\s+)?context(?:\s+window)?\b`, "i");
953
- var EXCEEDS_MODEL_CONTEXT = new RegExp(String.raw`\b(?:input|prompt|request|messages?)\b.{0,40}` + String.raw`\b(?:exceed(?:s|ed)?|overflows?|is\s+larger\s+than)\b.{0,40}` + String.raw`\b(?:the\s+)?(?:model(?:'s)?\s+)?context(?:\s+(?:length|window))?\b`, "i");
954
- var DEFAULT_MAX_RETRIES = 2;
955
- var DEFAULT_INITIAL_DELAY_MS = 500;
956
- var DEFAULT_MAX_DELAY_MS = 1e4;
957
- var DEFAULT_JITTER_RATIO = 0.1;
958
- var DEFAULT_RETRYABLE_CODES = Object.freeze([
959
- EMPTY_RESPONSE_CODE,
960
- "RATE_LIMIT",
961
- "SERVER",
962
- "TIMEOUT",
963
- "TRANSPORT"
964
- ]);
965
- var backoffSchema = Schema.object({
966
- initialDelayMs: Schema.number().max(MAX_TIMER_DELAY_MS).default(DEFAULT_INITIAL_DELAY_MS),
967
- maxDelayMs: Schema.number().max(MAX_TIMER_DELAY_MS).default(DEFAULT_MAX_DELAY_MS),
968
- jitterRatio: Schema.number().min(0).max(1).default(DEFAULT_JITTER_RATIO)
969
- });
970
- var normalPolicySchema = Schema.object({
971
- mode: Schema.const("normal").required(),
972
- maxRetries: Schema.number().step(1).min(0).max(Number.MAX_SAFE_INTEGER).default(DEFAULT_MAX_RETRIES),
973
- retryableCodes: Schema.array(Schema.string()).default([...DEFAULT_RETRYABLE_CODES]),
974
- backoff: backoffSchema
975
- });
976
- var alwaysPolicySchema = Schema.object({
977
- mode: Schema.const("always").required(),
978
- backoff: backoffSchema
979
- });
980
- var RetryPolicySchema = Schema.union([normalPolicySchema, alwaysPolicySchema]);
981
- var { version } = createRequire(import.meta.url)("../package.json");
982
-
983
- // node_modules/.pnpm/@deepseek-ai+dsh-session@0.1.0-rc.8_6fd26f59436a18b115f326d6060415e6/node_modules/@deepseek-ai/dsh-session/lib/index.js
984
- function deriveEventMessage(event) {
985
- switch (event.type) {
986
- case "user/message":
987
- return event.data;
988
- case "assistant/message":
989
- if (event.data.message.content.length === 0) return null;
990
- return event.data.message;
991
- case "tool/result":
992
- return event.data.message;
993
- default:
994
- return null;
995
- }
996
- }
997
-
998
155
  // src/host/fold.ts
156
+ import { deriveEventMessage } from "@deepseek-ai/dsh-session";
999
157
  function trimToLastTurns(requests, maxTurns) {
1000
158
  let runs = 0;
1001
159
  let start = requests.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-context",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "A DeepSeek Harness plugin for context insight and management, with context dashboard and context command, for understanding how the context is made of, and how it evolves.",
5
5
  "author": "bowenliang123",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "LICENSE"
26
26
  ],
27
27
  "scripts": {
28
- "build": "node scripts/build.mjs",
28
+ "build": "tsup",
29
29
  "register": "bash scripts/register.sh",
30
30
  "typecheck": "tsc --noEmit",
31
31
  "test": "npm run typecheck && node tests/host.test.mjs && node tests/client.test.mjs",
@@ -61,17 +61,31 @@
61
61
  "dependencies": {
62
62
  "zod": "^4.4.3"
63
63
  },
64
+ "peerDependencies": {
65
+ "@deepseek-ai/cordis": "^4.0.1",
66
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.8",
67
+ "@deepseek-ai/dsh-session": "^0.1.0-rc.8",
68
+ "react": "^18.3.1"
69
+ },
70
+ "peerDependenciesMeta": {
71
+ "@deepseek-ai/dsh-client-ui-primitives": {
72
+ "optional": true
73
+ },
74
+ "react": {
75
+ "optional": true
76
+ }
77
+ },
64
78
  "devDependencies": {
65
79
  "@deepseek-ai/cordis": "^4.0.1",
66
- "@deepseek-ai/dsh-client-ui-primitives": "0.1.0-rc.8",
67
- "@deepseek-ai/dsh-session": "0.1.0-rc.8",
68
- "@deepseek-ai/dsh-session-projection": "0.1.0-rc.8",
80
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.8",
81
+ "@deepseek-ai/dsh-session": "^0.1.0-rc.8",
82
+ "@deepseek-ai/dsh-session-projection": "^0.1.0-rc.8",
69
83
  "@types/react": "^18.3.31",
70
- "esbuild": "^0.28.2",
71
84
  "jsdom": "^30.0.1",
72
85
  "playwright-core": "^1.62.1",
73
86
  "react": "^18.3.1",
74
87
  "react-dom": "^18.3.1",
88
+ "tsup": "^8.5.1",
75
89
  "typescript": "^7.0.2"
76
90
  },
77
91
  "packageManager": "pnpm@11.9.0"