dsh-context 0.17.0 → 0.19.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 +128 -21
- package/lib/index.js +1 -843
- package/package.json +21 -6
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
|
|
@@ -103,7 +103,13 @@ var DICT_ZH = {
|
|
|
103
103
|
"tool.params": "\u53C2\u6570",
|
|
104
104
|
"tool.paramsEmpty": "\uFF08\u65E0\u53C2\u6570\uFF09",
|
|
105
105
|
"tool.jsonToggle": "\u67E5\u770B\u539F\u59CB JSON",
|
|
106
|
-
"tool.jsonHide": "\u6536\u8D77"
|
|
106
|
+
"tool.jsonHide": "\u6536\u8D77",
|
|
107
|
+
// Detail-card view switch (system prompt / tool description / message and
|
|
108
|
+
// injection bodies): a segmented pill — segment labels + tooltips.
|
|
109
|
+
"rich.raw": "\u539F\u6587",
|
|
110
|
+
"rich.md": "Markdown",
|
|
111
|
+
"rich.toMd": "\u6309 Markdown \u6E32\u67D3\u67E5\u770B",
|
|
112
|
+
"rich.toRaw": "\u67E5\u770B\u539F\u59CB\u6587\u672C"
|
|
107
113
|
};
|
|
108
114
|
var DICT_EN = {
|
|
109
115
|
"tab": "Context",
|
|
@@ -201,7 +207,13 @@ var DICT_EN = {
|
|
|
201
207
|
"tool.params": "Parameters",
|
|
202
208
|
"tool.paramsEmpty": "(no parameters)",
|
|
203
209
|
"tool.jsonToggle": "View Raw JSON",
|
|
204
|
-
"tool.jsonHide": "Collapse"
|
|
210
|
+
"tool.jsonHide": "Collapse",
|
|
211
|
+
// Detail-card view switch (system prompt / tool description / message and
|
|
212
|
+
// injection bodies): a segmented pill — segment labels + tooltips.
|
|
213
|
+
"rich.raw": "Raw",
|
|
214
|
+
"rich.md": "Markdown",
|
|
215
|
+
"rich.toMd": "View as Markdown",
|
|
216
|
+
"rich.toRaw": "View Raw Text"
|
|
205
217
|
};
|
|
206
218
|
|
|
207
219
|
// src/client/modalStore.ts
|
|
@@ -393,6 +405,42 @@ function makeNodeList(kit) {
|
|
|
393
405
|
};
|
|
394
406
|
}
|
|
395
407
|
|
|
408
|
+
// src/client/components/richText.tsx
|
|
409
|
+
var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
410
|
+
function makeRichText(kit) {
|
|
411
|
+
const { t } = kit;
|
|
412
|
+
function useRichMode() {
|
|
413
|
+
const [mode, setMode] = React.useState("md");
|
|
414
|
+
return [mode, setMode];
|
|
415
|
+
}
|
|
416
|
+
function RichSwitch(props) {
|
|
417
|
+
const seg = (m, label, tip) => /* @__PURE__ */ React.createElement(
|
|
418
|
+
"button",
|
|
419
|
+
{
|
|
420
|
+
type: "button",
|
|
421
|
+
className: "lc-rich-seg-btn" + (props.mode === m ? " lc-rich-seg-on" : ""),
|
|
422
|
+
title: tip,
|
|
423
|
+
onClick: () => {
|
|
424
|
+
props.onPick(m);
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
label
|
|
428
|
+
);
|
|
429
|
+
return /* @__PURE__ */ React.createElement("span", { className: "lc-rich-seg" + (props.inHead === true ? " lc-rich-seg-head" : "") }, seg("raw", t("rich.raw"), t("rich.toRaw")), seg("md", t("rich.md"), t("rich.toMd")));
|
|
430
|
+
}
|
|
431
|
+
function RichText(props) {
|
|
432
|
+
if (props.mode === "md") {
|
|
433
|
+
return /* @__PURE__ */ React.createElement("div", { className: props.mdClass ?? "lc-br-md" }, /* @__PURE__ */ React.createElement(import_dsh_client_ui_primitives.MarkdownText, { text: props.text }));
|
|
434
|
+
}
|
|
435
|
+
return /* @__PURE__ */ React.createElement("pre", { className: props.rawClass ?? "lc-br-pre" }, props.text);
|
|
436
|
+
}
|
|
437
|
+
function RichCard(props) {
|
|
438
|
+
const [mode, setMode] = useRichMode();
|
|
439
|
+
return /* @__PURE__ */ React.createElement("div", { className: props.className ?? "lc-br-content" }, /* @__PURE__ */ React.createElement(RichSwitch, { mode, onPick: setMode }), props.render(mode));
|
|
440
|
+
}
|
|
441
|
+
return { RichText, RichCard, RichSwitch, useRichMode };
|
|
442
|
+
}
|
|
443
|
+
|
|
396
444
|
// src/client/components/browser.tsx
|
|
397
445
|
function unionTypesOf(p) {
|
|
398
446
|
const branches = [];
|
|
@@ -449,7 +497,9 @@ function ParamRow(props) {
|
|
|
449
497
|
return /* @__PURE__ */ React.createElement("div", { className: "lc-ts-param-row" }, /* @__PURE__ */ React.createElement("span", { className: "lc-ts-param-name" }, props.name), /* @__PURE__ */ React.createElement("span", { className: "lc-ts-param-type" }, typeLabel), /* @__PURE__ */ React.createElement("span", { className: props.required ? "lc-ts-param-req" : "lc-ts-param-req-off" }, props.required ? "\u2713" : "\xB7"), typeof desc === "string" && desc !== "" ? /* @__PURE__ */ React.createElement("span", { className: "lc-ts-param-desc" }, desc) : null);
|
|
450
498
|
}
|
|
451
499
|
function ToolSchema(props) {
|
|
500
|
+
const { rich } = props;
|
|
452
501
|
const [jsonOpen, setJsonOpen] = React.useState(false);
|
|
502
|
+
const [descMode, setDescMode] = rich.useRichMode();
|
|
453
503
|
const params = React.useMemo(() => paramsOf(props.schema), [props.schema]);
|
|
454
504
|
const rows = React.useMemo(() => {
|
|
455
505
|
if (params === null) return [];
|
|
@@ -468,7 +518,15 @@ function ToolSchema(props) {
|
|
|
468
518
|
() => props.schema !== void 0 ? JSON.stringify(props.schema, null, 2) : "",
|
|
469
519
|
[props.schema]
|
|
470
520
|
);
|
|
471
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.description !== void 0 ? /* @__PURE__ */ React.createElement("div", { className: "lc-ts-card" }, /* @__PURE__ */ React.createElement("div", { className: "lc-ts-card-head" }, /* @__PURE__ */ React.createElement("b", null, props.labels.desc)
|
|
521
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.description !== void 0 ? /* @__PURE__ */ React.createElement("div", { className: "lc-ts-card" }, /* @__PURE__ */ React.createElement("div", { className: "lc-ts-card-head" }, /* @__PURE__ */ React.createElement("b", null, props.labels.desc), /* @__PURE__ */ React.createElement(rich.RichSwitch, { mode: descMode, onPick: setDescMode, inHead: true })), /* @__PURE__ */ React.createElement(
|
|
522
|
+
rich.RichText,
|
|
523
|
+
{
|
|
524
|
+
text: props.description,
|
|
525
|
+
mode: descMode,
|
|
526
|
+
rawClass: "lc-ts-desc-body",
|
|
527
|
+
mdClass: "lc-ts-desc-md"
|
|
528
|
+
}
|
|
529
|
+
)) : null, params !== null && rows.length > 0 ? /* @__PURE__ */ React.createElement("div", { className: "lc-ts-card" }, /* @__PURE__ */ React.createElement("div", { className: "lc-ts-card-head" }, /* @__PURE__ */ React.createElement("b", null, props.labels.title), /* @__PURE__ */ React.createElement("span", { className: "lc-ts-card-count" }, rows.length)), rows.map((r) => /* @__PURE__ */ React.createElement(ParamRow, { key: r.name, name: r.name, schema: r.schema, required: r.required }))) : params !== null ? /* @__PURE__ */ React.createElement("div", { className: "lc-ts-params-empty" }, props.labels.empty) : null, schemaJson !== "" ? /* @__PURE__ */ React.createElement("div", { className: "lc-ts-json" }, /* @__PURE__ */ React.createElement(
|
|
472
530
|
"button",
|
|
473
531
|
{
|
|
474
532
|
type: "button",
|
|
@@ -481,27 +539,37 @@ function ToolSchema(props) {
|
|
|
481
539
|
), jsonOpen ? /* @__PURE__ */ React.createElement("pre", { className: "lc-br-pre lc-br-dim" }, schemaJson) : null) : null);
|
|
482
540
|
}
|
|
483
541
|
function RawBlocks(props) {
|
|
542
|
+
const { rich } = props;
|
|
484
543
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.blocks.map((b, i) => {
|
|
485
544
|
const blk = b;
|
|
486
545
|
if (blk !== null && typeof blk === "object" && (blk.type === "text" || blk.type === "reasoning") && typeof blk.text === "string") {
|
|
487
|
-
|
|
546
|
+
if (blk.type === "reasoning") {
|
|
547
|
+
return /* @__PURE__ */ React.createElement("pre", { key: i, className: "lc-br-pre lc-br-dim" }, blk.text);
|
|
548
|
+
}
|
|
549
|
+
return /* @__PURE__ */ React.createElement(rich.RichText, { key: i, text: blk.text, mode: props.mode });
|
|
488
550
|
}
|
|
489
551
|
if (blk !== null && typeof blk === "object" && blk.type === "tool-result" && Array.isArray(blk.content)) {
|
|
490
|
-
return /* @__PURE__ */ React.createElement(RawBlocks, { key: i, blocks: blk.content });
|
|
552
|
+
return /* @__PURE__ */ React.createElement(RawBlocks, { key: i, blocks: blk.content, mode: props.mode, rich });
|
|
491
553
|
}
|
|
492
554
|
return /* @__PURE__ */ React.createElement("pre", { key: i, className: "lc-br-pre lc-br-dim" }, JSON.stringify(b, null, 2));
|
|
493
555
|
}));
|
|
494
556
|
}
|
|
495
557
|
function NodeContent(props) {
|
|
496
|
-
const { node, conv } = props;
|
|
558
|
+
const { node, conv, rich } = props;
|
|
559
|
+
const richable = node.cat === "user" || node.cat === "assistant" || node.cat === "inject";
|
|
560
|
+
const wrap = (render) => richable ? /* @__PURE__ */ React.createElement(rich.RichCard, { render }) : /* @__PURE__ */ React.createElement("div", { className: "lc-br-content" }, render("raw"));
|
|
497
561
|
if (conv === void 0) {
|
|
498
|
-
|
|
562
|
+
if (node.text === void 0 || node.text === "") {
|
|
563
|
+
return /* @__PURE__ */ React.createElement("div", { className: "lc-br-content" }, /* @__PURE__ */ React.createElement("div", { className: "lc-br-note" }, props.hint));
|
|
564
|
+
}
|
|
565
|
+
return wrap((mode) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(rich.RichText, { text: node.text ?? "", mode }), /* @__PURE__ */ React.createElement("div", { className: "lc-br-note" }, props.hint)));
|
|
499
566
|
}
|
|
500
567
|
if (conv.kind === "assistant" && Array.isArray(conv.blocks)) {
|
|
501
|
-
|
|
568
|
+
const blocks = conv.blocks;
|
|
569
|
+
return wrap((mode) => /* @__PURE__ */ React.createElement(React.Fragment, null, blocks.map((b, i) => {
|
|
502
570
|
const blk = b;
|
|
503
571
|
if (blk.kind === "text" && typeof blk.text === "string") {
|
|
504
|
-
return /* @__PURE__ */ React.createElement(
|
|
572
|
+
return /* @__PURE__ */ React.createElement(rich.RichText, { key: i, text: blk.text, mode });
|
|
505
573
|
}
|
|
506
574
|
if (blk.kind === "reasoning" && typeof blk.text === "string") {
|
|
507
575
|
return /* @__PURE__ */ React.createElement("pre", { key: i, className: "lc-br-pre lc-br-dim" }, blk.text);
|
|
@@ -510,16 +578,16 @@ function NodeContent(props) {
|
|
|
510
578
|
return /* @__PURE__ */ React.createElement("div", { key: i, className: "lc-br-call" }, /* @__PURE__ */ React.createElement("span", { className: "lc-br-tag" }, "\u2192 " + String(blk.name ?? "?")), typeof blk.argsRaw === "string" && blk.argsRaw !== "" ? /* @__PURE__ */ React.createElement("pre", { className: "lc-br-pre lc-br-dim" }, blk.argsRaw) : null);
|
|
511
579
|
}
|
|
512
580
|
return null;
|
|
513
|
-
}));
|
|
581
|
+
})));
|
|
514
582
|
}
|
|
515
583
|
if (conv.kind === "tool-result") {
|
|
516
|
-
return /* @__PURE__ */ React.createElement("div", { className: "lc-br-content" }, conv.call != null ? /* @__PURE__ */ React.createElement("div", { className: "lc-br-call" }, /* @__PURE__ */ React.createElement("span", { className: "lc-br-tag" }, "\u2190 " + conv.call.name), conv.call.argsRaw !== "" ? /* @__PURE__ */ React.createElement("pre", { className: "lc-br-pre lc-br-dim" }, conv.call.argsRaw) : null) : null, Array.isArray(conv.content) ? /* @__PURE__ */ React.createElement(RawBlocks, { blocks: conv.content }) : null);
|
|
584
|
+
return /* @__PURE__ */ React.createElement("div", { className: "lc-br-content" }, conv.call != null ? /* @__PURE__ */ React.createElement("div", { className: "lc-br-call" }, /* @__PURE__ */ React.createElement("span", { className: "lc-br-tag" }, "\u2190 " + conv.call.name), conv.call.argsRaw !== "" ? /* @__PURE__ */ React.createElement("pre", { className: "lc-br-pre lc-br-dim" }, conv.call.argsRaw) : null) : null, Array.isArray(conv.content) ? /* @__PURE__ */ React.createElement(RawBlocks, { blocks: conv.content, mode: "raw", rich }) : null);
|
|
517
585
|
}
|
|
518
586
|
if (conv.kind === "compaction") {
|
|
519
|
-
return /* @__PURE__ */ React.createElement(
|
|
587
|
+
return wrap((mode) => /* @__PURE__ */ React.createElement(React.Fragment, null, typeof conv.summary === "string" && conv.summary !== "" ? /* @__PURE__ */ React.createElement(rich.RichText, { text: conv.summary, mode }) : null));
|
|
520
588
|
}
|
|
521
589
|
if (Array.isArray(conv.content)) {
|
|
522
|
-
return
|
|
590
|
+
return wrap((mode) => /* @__PURE__ */ React.createElement(RawBlocks, { blocks: conv.content, mode, rich }));
|
|
523
591
|
}
|
|
524
592
|
return /* @__PURE__ */ React.createElement("div", { className: "lc-br-content" }, /* @__PURE__ */ React.createElement("div", { className: "lc-br-note" }, props.hint));
|
|
525
593
|
}
|
|
@@ -541,6 +609,7 @@ function lastOfTurn(requests, turn) {
|
|
|
541
609
|
function makeContextBrowser(kit, StackedBar) {
|
|
542
610
|
const { t, fmt: fmt3, fmtTime: fmtTime2, catLabel } = kit;
|
|
543
611
|
const nodeText = makeNodeText(kit);
|
|
612
|
+
const rich = makeRichText(kit);
|
|
544
613
|
const catColor = {};
|
|
545
614
|
for (const c of CATS) catColor[c.key] = c.color;
|
|
546
615
|
const MAX_AUTO_PAGES = 20;
|
|
@@ -637,7 +706,7 @@ function makeContextBrowser(kit, StackedBar) {
|
|
|
637
706
|
system.replace(/\s+/g, " ").trim().slice(0, 80),
|
|
638
707
|
breakdown.system,
|
|
639
708
|
void 0,
|
|
640
|
-
/* @__PURE__ */ React.createElement(
|
|
709
|
+
/* @__PURE__ */ React.createElement(rich.RichCard, { render: (mode) => /* @__PURE__ */ React.createElement(rich.RichText, { text: system, mode }) })
|
|
641
710
|
);
|
|
642
711
|
}
|
|
643
712
|
if (c === "tools") {
|
|
@@ -656,7 +725,7 @@ function makeContextBrowser(kit, StackedBar) {
|
|
|
656
725
|
tool.name,
|
|
657
726
|
tool.tokens,
|
|
658
727
|
void 0,
|
|
659
|
-
/* @__PURE__ */ React.createElement("div", { className: "lc-br-content" }, /* @__PURE__ */ React.createElement(ToolSchema, { description: tool.description, schema: tool.schema, labels }))
|
|
728
|
+
/* @__PURE__ */ React.createElement("div", { className: "lc-br-content" }, /* @__PURE__ */ React.createElement(ToolSchema, { description: tool.description, schema: tool.schema, rich, labels }))
|
|
660
729
|
);
|
|
661
730
|
});
|
|
662
731
|
}
|
|
@@ -684,6 +753,7 @@ function makeContextBrowser(kit, StackedBar) {
|
|
|
684
753
|
{
|
|
685
754
|
node: n,
|
|
686
755
|
conv: bySeq.get(n.seq),
|
|
756
|
+
rich,
|
|
687
757
|
hint: bySeq.get(n.seq) === void 0 && awaiting ? t("browser.loading") : t("browser.noContent")
|
|
688
758
|
}
|
|
689
759
|
)
|
|
@@ -1086,8 +1156,13 @@ var STYLES = [
|
|
|
1086
1156
|
".lc-chart-dim .lc-turn-on { opacity: 1; }",
|
|
1087
1157
|
".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
1158
|
".lc-bar:hover { background: var(--dsw-alias-bg-layer-2); }",
|
|
1089
|
-
|
|
1159
|
+
// Hovering previews a bar with a thin dashed frame; a CLICKED (locked)
|
|
1160
|
+
// bar must always show the strong solid frame, so the selected rule is
|
|
1161
|
+
// declared LAST (equal specificity) — otherwise the dashed hover frame
|
|
1162
|
+
// would keep overriding it while the pointer is still on the just-clicked
|
|
1163
|
+
// bar and the lock would only become visible after the pointer leaves.
|
|
1090
1164
|
".lc-bar-hovered { outline: 1px dashed var(--dsw-alias-brand-primary); outline-offset: 1px; }",
|
|
1165
|
+
".lc-bar-selected { outline: 2px solid var(--dsw-alias-label-primary); outline-offset: 1px; }",
|
|
1091
1166
|
".lc-bar-in-turn { background: rgba(128,128,128,0.14); }",
|
|
1092
1167
|
".lc-bar-stack { display: flex; flex-direction: column-reverse; width: 100%; }",
|
|
1093
1168
|
".lc-bar-stack > div { width: 100%; }",
|
|
@@ -1257,11 +1332,42 @@ var STYLES = [
|
|
|
1257
1332
|
// body compact).
|
|
1258
1333
|
".lc-ts-json { display: flex; flex-direction: column; gap: 4px; }",
|
|
1259
1334
|
".lc-ts-json-toggle { align-self: flex-start; border: 0; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 11px; padding: 0; cursor: pointer; }",
|
|
1260
|
-
".lc-ts-json-toggle:hover { color: var(--dsw-alias-label-primary); text-decoration: underline; }"
|
|
1335
|
+
".lc-ts-json-toggle:hover { color: var(--dsw-alias-label-primary); text-decoration: underline; }",
|
|
1336
|
+
// ---- Raw/markdown view switch (detail cards: system prompt, tool
|
|
1337
|
+
// description, user/assistant message + injection bodies). A segmented
|
|
1338
|
+
// pill mirroring the trend chart's 步骤/轮次 control (`lc-gran`), riding
|
|
1339
|
+
// the card's top-right corner as a self-end item of the content column
|
|
1340
|
+
// (no absolute overlay, so it never covers text); the `in-head` variant
|
|
1341
|
+
// sits at the right end of the tool description card's title row. The
|
|
1342
|
+
// markdown box reuses the raw <pre> chrome minus the pre whitespace. ----
|
|
1343
|
+
".lc-rich-seg { align-self: flex-end; display: flex; gap: 2px; background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; padding: 1px; }",
|
|
1344
|
+
".lc-rich-seg-btn { border: 0; background: transparent; color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 1; padding: 3px 8px; border-radius: 5px; cursor: pointer; font-family: inherit; }",
|
|
1345
|
+
".lc-rich-seg-btn:hover { color: var(--dsw-alias-label-primary); }",
|
|
1346
|
+
".lc-rich-seg-on, .lc-rich-seg-on:hover { background: var(--dsw-alias-button-primary-fill); color: var(--dsw-alias-label-primary-foreground); }",
|
|
1347
|
+
".lc-rich-seg-head { align-self: auto; margin-left: auto; }",
|
|
1348
|
+
".lc-br-md { padding: 4px 10px; background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; color: var(--dsw-alias-label-primary); font-size: 12px; line-height: 1.55; word-break: break-word; max-height: 320px; overflow-y: auto; scrollbar-width: thin; }",
|
|
1349
|
+
".lc-ts-desc-md { padding: 4px 10px; color: var(--dsw-alias-label-primary); font-size: 12px; line-height: 1.55; word-break: break-word; max-height: 160px; overflow-y: auto; scrollbar-width: thin; }",
|
|
1350
|
+
// The shared markdown renderer sizes its root/headings for chat bubbles;
|
|
1351
|
+
// inside a detail card the base size sits one step ABOVE the raw text
|
|
1352
|
+
// (13px vs 12px — a proportional face at 13px matches the visual weight
|
|
1353
|
+
// of the raw view's 12px monospace) and the heading scale collapses to a
|
|
1354
|
+
// weight-only bump (specificity beats the renderer's one-class rules).
|
|
1355
|
+
// Inline code keeps the FULL size too — the renderer shrinks it to
|
|
1356
|
+
// 0.875em (!important) and table code to 13px, both visibly off. Its
|
|
1357
|
+
// `font` shorthand also drags in a ~22px line-height, TALLER than the
|
|
1358
|
+
// 13px/1.55 paragraph line (~20px), so a code chip wrapping onto the
|
|
1359
|
+
// next line sticks to the neighbor line's chip; pin the chip just under
|
|
1360
|
+
// the paragraph line (1.3em + 1px padding ≈ 19px) to reopen the gap.
|
|
1361
|
+
".lc-br-md > div, .lc-ts-desc-md > div { font-size: 13px; line-height: 1.55; }",
|
|
1362
|
+
".lc-br-md div :is(h1, h2, h3, h4, h5, h6), .lc-ts-desc-md div :is(h1, h2, h3, h4, h5, h6) { font-size: 13px; font-weight: 600; margin: 10px 0 4px; }",
|
|
1363
|
+
".lc-br-md div p, .lc-ts-desc-md div p { margin: 6px 0; }",
|
|
1364
|
+
".lc-br-md div pre, .lc-ts-desc-md div pre { margin: 6px 0; }",
|
|
1365
|
+
".lc-br-md div :not(pre) > code, .lc-ts-desc-md div :not(pre) > code { font-size: 1em !important; line-height: 1.3; padding: 1px 5px; box-decoration-break: clone; }",
|
|
1366
|
+
".lc-br-md div table code, .lc-ts-desc-md div table code { font-size: inherit; }"
|
|
1261
1367
|
].join("\n");
|
|
1262
1368
|
|
|
1263
1369
|
// src/client/components/events.tsx
|
|
1264
|
-
var
|
|
1370
|
+
var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
1265
1371
|
|
|
1266
1372
|
// src/client/format.ts
|
|
1267
1373
|
function fmt(n) {
|
|
@@ -1329,7 +1435,7 @@ function makeEventList(kit) {
|
|
|
1329
1435
|
return /* @__PURE__ */ React.createElement("div", { className: "lc-events", ref: rootRef }, sorted.map((ev, i) => {
|
|
1330
1436
|
const label = eventLabel(ev);
|
|
1331
1437
|
const at = eventAt(ev);
|
|
1332
|
-
const glyph = ev.kind === "inject" ? /* @__PURE__ */ React.createElement(
|
|
1438
|
+
const glyph = ev.kind === "inject" ? /* @__PURE__ */ React.createElement(import_dsh_client_ui_primitives2.IconPlusOutline16, null) : ev.kind === "model" ? /* @__PURE__ */ React.createElement(import_dsh_client_ui_primitives2.IconBranchOutline16, null) : EVENT_ICONS[ev.kind] || "\u2022";
|
|
1333
1439
|
return /* @__PURE__ */ React.createElement("div", { key: ev.seq + "-" + i, className: "lc-event" }, /* @__PURE__ */ React.createElement("span", { className: "lc-event-icon lc-event-" + ev.kind }, glyph), /* @__PURE__ */ React.createElement("span", { className: "lc-kind lc-kind-" + ev.kind }, t("kind." + ev.kind)), /* @__PURE__ */ React.createElement("span", { className: "lc-event-label" }, label), at !== null ? /* @__PURE__ */ React.createElement("span", { className: "lc-event-at" }, at) : null, ev.tokens ? /* @__PURE__ */ React.createElement("span", { className: "lc-event-tokens" + (ev.kind === "inject" ? " lc-up" : " lc-down") }, (ev.kind === "inject" ? "+" : "\u2212") + fmt3(ev.tokens)) : null, /* @__PURE__ */ React.createElement("span", { className: "lc-event-time" }, fmtTime2(ev.time)));
|
|
1334
1440
|
}));
|
|
1335
1441
|
};
|
|
@@ -1337,7 +1443,7 @@ function makeEventList(kit) {
|
|
|
1337
1443
|
|
|
1338
1444
|
// src/client/meta.ts
|
|
1339
1445
|
var PLUGIN_NAME = "dsh-context";
|
|
1340
|
-
var PLUGIN_VERSION = true ? "0.
|
|
1446
|
+
var PLUGIN_VERSION = true ? "0.19.0" : "0.0.0-dev";
|
|
1341
1447
|
var PLUGIN_REPO = true ? "https://github.com/bowenliang123/dsh-context" : "https://github.com/bowenliang123/dsh-context";
|
|
1342
1448
|
var PLUGIN_REPO_SHORT = PLUGIN_REPO.replace(/^https?:\/\/github\.com\//, "");
|
|
1343
1449
|
|
|
@@ -1852,3 +1958,4 @@ module.exports = {
|
|
|
1852
1958
|
return module.exports;
|
|
1853
1959
|
},
|
|
1854
1960
|
});
|
|
1961
|
+
|
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.
|
|
3
|
+
"version": "0.19.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,8 @@
|
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "
|
|
28
|
+
"build": "tsup",
|
|
29
|
+
"watch": "tsup --watch",
|
|
29
30
|
"register": "bash scripts/register.sh",
|
|
30
31
|
"typecheck": "tsc --noEmit",
|
|
31
32
|
"test": "npm run typecheck && node tests/host.test.mjs && node tests/client.test.mjs",
|
|
@@ -61,17 +62,31 @@
|
|
|
61
62
|
"dependencies": {
|
|
62
63
|
"zod": "^4.4.3"
|
|
63
64
|
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
67
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.8",
|
|
68
|
+
"@deepseek-ai/dsh-session": "^0.1.0-rc.8",
|
|
69
|
+
"react": "^18.3.1"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"@deepseek-ai/dsh-client-ui-primitives": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"react": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
78
|
+
},
|
|
64
79
|
"devDependencies": {
|
|
65
80
|
"@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",
|
|
81
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.8",
|
|
82
|
+
"@deepseek-ai/dsh-session": "^0.1.0-rc.8",
|
|
83
|
+
"@deepseek-ai/dsh-session-projection": "^0.1.0-rc.8",
|
|
69
84
|
"@types/react": "^18.3.31",
|
|
70
|
-
"esbuild": "^0.28.2",
|
|
71
85
|
"jsdom": "^30.0.1",
|
|
72
86
|
"playwright-core": "^1.62.1",
|
|
73
87
|
"react": "^18.3.1",
|
|
74
88
|
"react-dom": "^18.3.1",
|
|
89
|
+
"tsup": "^8.5.1",
|
|
75
90
|
"typescript": "^7.0.2"
|
|
76
91
|
},
|
|
77
92
|
"packageManager": "pnpm@11.9.0"
|