@openbkn/workshop 0.3.0-rc.1 → 0.3.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/{ActionConfirm-BX1dlrAM.js → ActionConfirm-G-F1ZPqU.js} +5 -5
  2. package/dist/{ActionFailure-xcSfKJYC.js → ActionFailure-PXLm8Yrm.js} +2 -2
  3. package/dist/{AgentChat-DHdX_6W7.js → AgentChat-D2h4hYuv.js} +25 -25
  4. package/dist/{AppListPage-DsUvFo6B.js → AppListPage-CjAyblsr.js} +4 -4
  5. package/dist/{AskDrawer-j-CR4yXP.js → AskDrawer-BOZHK2uD.js} +4 -4
  6. package/dist/{ComputedView-dWFlHngu.js → ComputedView-CFB6TLqD.js} +27 -27
  7. package/dist/{ConclusionApply-BAoZpxl-.js → ConclusionApply-QzEgCkEr.js} +4 -4
  8. package/dist/{CypherEditor-CZ5Z4SGH.js → CypherEditor-ChbgNwGj.js} +5 -5
  9. package/dist/{LandingList-BUO6-at_.js → LandingList-D4rN2C_h.js} +5 -5
  10. package/dist/{MenuUnfoldOutlined-DAeIeIap.js → MenuUnfoldOutlined-9J7j6Kim.js} +1 -1
  11. package/dist/{ModelTrial-C7XvLVY7.js → ModelTrial-DWE5fBa4.js} +4 -4
  12. package/dist/{PageRenderer-CkmvW4aO.js → PageRenderer-BYBHi5At.js} +12737 -12687
  13. package/dist/{ScenarioApply-COdlyvrC.js → ScenarioApply-Ck68QOWM.js} +25 -25
  14. package/dist/{SimulateForm-B_9laTIl.js → SimulateForm-QwSu0BWO.js} +4 -4
  15. package/dist/{Subgraph-CDY3wvCA.js → Subgraph-CMIts4-k.js} +3 -3
  16. package/dist/{WorkshopLabPage-BtYnBpk4.js → WorkshopLabPage-N-CVblXc.js} +4930 -4619
  17. package/dist/{WorkshopRunPage-DHMJ3b8k.js → WorkshopRunPage-LtG2nDNS.js} +6 -6
  18. package/dist/{abnfDiagram-WEYOIA3C-Blje2Kbf.js → abnfDiagram-WEYOIA3C-CEkD2Kbr.js} +3 -3
  19. package/dist/{action-type-tool.service-BN-W_Az_.js → action-type-tool.service-DfyMNDaF.js} +1 -1
  20. package/dist/{architectureDiagram-ZHVYKT53-B_FkRXc3.js → architectureDiagram-ZHVYKT53-ypBqmKJn.js} +3 -3
  21. package/dist/{bkn-agent-execution.service-CJalMVIc.js → bkn-agent-execution.service-DpOKT3iR.js} +1 -1
  22. package/dist/{blockDiagram-RJAE7QA3-CYJLthoI.js → blockDiagram-RJAE7QA3-BQiz7ppY.js} +3 -3
  23. package/dist/{c4Diagram-XDPPPE54-CmMaN3M4.js → c4Diagram-XDPPPE54-DoQEicnh.js} +2 -2
  24. package/dist/{channel-Dp24Bgua.js → channel-CLsZYFb3.js} +1 -1
  25. package/dist/{chunk-2E7WHVMD-DrnpfYKB.js → chunk-2E7WHVMD-C7KAk7Aw.js} +1 -1
  26. package/dist/{chunk-2Q5K7J3B-BXqKcHlQ.js → chunk-2Q5K7J3B-DJjZ1fjz.js} +1 -1
  27. package/dist/{chunk-4EMNKR2T-DYgY_0_y.js → chunk-4EMNKR2T-Da2DlW9r.js} +1 -1
  28. package/dist/{chunk-55XCU76K-Bja7bE8g.js → chunk-55XCU76K-Dke6HW5r.js} +1 -1
  29. package/dist/{chunk-5VM5RSS4-CGTnbRRi.js → chunk-5VM5RSS4-CfxCWhgL.js} +1 -1
  30. package/dist/{chunk-JWPE2WC7-2AyjxdJR.js → chunk-JWPE2WC7-BvFVx2S8.js} +1 -1
  31. package/dist/{chunk-VQ5W62QI-B3PGCKOg.js → chunk-VQ5W62QI-BKtRw0gX.js} +1 -1
  32. package/dist/{chunk-XXDRQBXY-RrIsI-B5.js → chunk-XXDRQBXY-BFdjgXiI.js} +1 -1
  33. package/dist/{chunk-ZCHMQSOR-COJTBW1i.js → chunk-ZCHMQSOR-BV9eKUlK.js} +2 -2
  34. package/dist/{classDiagram-v2-4MYWR3UA-DolLxH6t.js → classDiagram-v2-4MYWR3UA-CrCmRIma.js} +5 -5
  35. package/dist/{cose-bilkent-JH36ORCC-DMSYgFxc.js → cose-bilkent-JH36ORCC-BLuhBHgL.js} +2 -2
  36. package/dist/{customParseFormat-C9WAjjqH.js → customParseFormat-LvPG_yWc.js} +1 -1
  37. package/dist/{cynefinDiagram-WF24UDRP-DrksRWCn.js → cynefinDiagram-WF24UDRP-Dkdu7UWf.js} +2 -2
  38. package/dist/{dagre-NK4GIZVX-CFRT2dAc.js → dagre-NK4GIZVX-wQ94w-j-.js} +2 -2
  39. package/dist/{dayjs.min-CziT8yW9.js → dayjs.min-C7Hp2iGA.js} +1 -1
  40. package/dist/{diagram-CBK3MWTC-DzZ_sQCl.js → diagram-CBK3MWTC-DFfVlq-I.js} +3 -3
  41. package/dist/{diagram-I5XIIV2D-RYNBUOF4.js → diagram-I5XIIV2D-kg2lU_ud.js} +2 -2
  42. package/dist/{diagram-ODIL2UCW-DqJETE9R.js → diagram-ODIL2UCW-Cq22spS8.js} +3 -3
  43. package/dist/{diagram-PFBEJUXE-BekIE7hh.js → diagram-PFBEJUXE-6v743_6i.js} +2 -2
  44. package/dist/{diagram-RJA3I4VV-DAIwlMxl.js → diagram-RJA3I4VV-CfpzBZG7.js} +2 -2
  45. package/dist/{diagram-TYUNFSNR-CLJ0Ou9i.js → diagram-TYUNFSNR-DWcS3i5W.js} +6 -6
  46. package/dist/{ebnfDiagram-V4P3TTPT-CRs8ppfT.js → ebnfDiagram-V4P3TTPT-CDdo-DHX.js} +3 -3
  47. package/dist/{elk-QONTBCTQ-Bqoh6AYY.js → elk-QONTBCTQ-tURRkPjL.js} +5 -5
  48. package/dist/{erDiagram-KYQIGQAA-BSp8Z7uQ.js → erDiagram-KYQIGQAA-DOUye_XT.js} +4 -4
  49. package/dist/{flowDiagram-IUGLLWBU-WKILTCDc.js → flowDiagram-IUGLLWBU-DSva8jfA.js} +7 -7
  50. package/dist/{ganttDiagram-R7GPNTJY-CaTn_Mmr.js → ganttDiagram-R7GPNTJY-yY38MCsA.js} +4 -4
  51. package/dist/generateCypher-Cv-1H1ju.js +1088 -0
  52. package/dist/{gitGraphDiagram-PDYL7XHY-DGPs-RF6.js → gitGraphDiagram-PDYL7XHY-Cib4RIM7.js} +3 -3
  53. package/dist/{infoDiagram-MVDRKAX5-HIQg7U3R.js → infoDiagram-MVDRKAX5-C95Rlu7T.js} +1 -1
  54. package/dist/{ishikawaDiagram-HPEHV2GE-C84x8n2j.js → ishikawaDiagram-HPEHV2GE-BAJtxdug.js} +2 -2
  55. package/dist/{journeyDiagram-BOSHW7O7-CvYDNxSY.js → journeyDiagram-BOSHW7O7-D0_UFC4-.js} +4 -4
  56. package/dist/{kanban-definition-FNSA4HC5-B586ryFD.js → kanban-definition-FNSA4HC5-DVGJd60c.js} +2 -2
  57. package/dist/{mermaid.core-3J01L12Z.js → mermaid.core-CaigvKK3.js} +43 -43
  58. package/dist/{mindmap-definition-6OY57UG3-Donc6BMy.js → mindmap-definition-6OY57UG3-Cc9NVGcT.js} +3 -3
  59. package/dist/{models-Rf3LB8wS.js → models-9HukOADg.js} +1 -1
  60. package/dist/{object-metric-numeric-BcgaJ6EW.js → object-metric-numeric-DpQoy02c.js} +1 -1
  61. package/dist/{object-metric.service-CKiaFYcp.js → object-metric.service-Bs69yRkm.js} +2 -2
  62. package/dist/{pegDiagram-ECIUJNBX-CYVi7x6D.js → pegDiagram-ECIUJNBX-DAnSZciK.js} +3 -3
  63. package/dist/{pieDiagram-GNMPY74T-4iWKYTTS.js → pieDiagram-GNMPY74T-CPRmYgcD.js} +2 -2
  64. package/dist/{prompt-BQzBLrua.js → prompt-CdE-v-Ut.js} +124 -113
  65. package/dist/{quadrantDiagram-D57K4MC3-Bm6Cyi1I.js → quadrantDiagram-D57K4MC3--PBqyWig.js} +1 -1
  66. package/dist/{railroadDiagram-Y72NRBL7-Du6iN-Jz.js → railroadDiagram-Y72NRBL7-v4wxw4pH.js} +3 -3
  67. package/dist/{requirementDiagram-EQYSW5RA-BGxpuSlc.js → requirementDiagram-EQYSW5RA-CXUiIggI.js} +3 -3
  68. package/dist/{sankeyDiagram-SY24JHO5-CsHmu__D.js → sankeyDiagram-SY24JHO5-CXWMlyCF.js} +2 -2
  69. package/dist/{sequenceDiagram-BLEHNHQU-DBNi943L.js → sequenceDiagram-BLEHNHQU-BBOTQGfc.js} +3 -3
  70. package/dist/{sizeCapture-INFHLROL-CcGr2ilA.js → sizeCapture-INFHLROL-CoWTXUCl.js} +1 -1
  71. package/dist/{stateDiagram-v2-A6IESKWZ-C78tVzaF.js → stateDiagram-v2-A6IESKWZ-f2F4pX57.js} +4 -4
  72. package/dist/{swimlanes-B3ENRKFQ-BROc4LGM.js → swimlanes-B3ENRKFQ-Cpfk8ZRY.js} +3 -3
  73. package/dist/{swimlanesDiagram-AYQRV4AK-C0RDY4m2.js → swimlanesDiagram-AYQRV4AK-hM77bzoI.js} +3 -3
  74. package/dist/{timeline-definition-JXYKGLGB-C6WGe4xl.js → timeline-definition-JXYKGLGB-BR5tHWmO.js} +1 -1
  75. package/dist/{toolMatchLines-DrXpUwcl.js → toolMatchLines-CvXMA8LD.js} +2 -2
  76. package/dist/{useLabData-B-3UW8zF.js → useLabData-OIsblj-7.js} +3220 -3200
  77. package/dist/{usecaseDiagram-WPOLBNNX-yMP7SDIg.js → usecaseDiagram-WPOLBNNX-DKhBwmOs.js} +3 -3
  78. package/dist/{vennDiagram-Q3Y3IDCW-bZW2LzBB.js → vennDiagram-Q3Y3IDCW-BnwNAM2m.js} +2 -2
  79. package/dist/{wardleyDiagram-IVAIDKWA-DBbog93x.js → wardleyDiagram-IVAIDKWA-BAl9UccR.js} +2 -2
  80. package/dist/{workshop-app-ByYXbgcn.js → workshop-app-7WTuNuCp.js} +7521 -7419
  81. package/dist/workshop-app.css +1 -1
  82. package/dist/workshop-app.js +2 -2
  83. package/dist/{xychartDiagram-4URNHDU4-CVLJNXOt.js → xychartDiagram-4URNHDU4-DAUWzPOU.js} +1 -1
  84. package/dist-cli/workshop.js +179 -169
  85. package/package.json +1 -1
  86. package/skill/SKILL.en-US.md +1 -1
  87. package/skill/SKILL.md +1 -1
  88. package/dist/generateCypher-BE_4YCWB.js +0 -1032
@@ -1,1032 +0,0 @@
1
- import { Z as gt, L as Rt, _ as wt, $ as Nt } from "./workshop-app-ByYXbgcn.js";
2
- import { ap as Ct, O as vt, aq as Pt, ai as $t, aj as _t, ar as Lt } from "./useLabData-B-3UW8zF.js";
3
- import { f as yt, a5 as It } from "./PageRenderer-CkmvW4aO.js";
4
- import { u as qt, g as Bt, a as Yt, f as Jt, s as Dt, i as Ut, p as zt, S as Ft } from "./prompt-BQzBLrua.js";
5
- function Wt(t, r) {
6
- if (!Array.isArray(r)) throw new Error("patch 必须是数组");
7
- const n = { value: structuredClone(t) };
8
- for (const e of r)
9
- switch (e?.op) {
10
- case "add":
11
- st(n, e.path, structuredClone(e.value));
12
- break;
13
- case "replace":
14
- at(n, e.path), st(n, e.path, structuredClone(e.value));
15
- break;
16
- case "remove":
17
- at(n, e.path);
18
- break;
19
- case "move":
20
- st(n, e.path, at(n, e.from));
21
- break;
22
- case "test": {
23
- const [a, i] = lt(n, e.path), d = a[i];
24
- if (JSON.stringify(d) !== JSON.stringify(e.value))
25
- throw new Error(
26
- `patch 校验不符:${e.path} 是 ${JSON.stringify(d)},不是 ${JSON.stringify(e.value)}`
27
- );
28
- break;
29
- }
30
- default:
31
- throw new Error(`不支持的 patch 操作:${JSON.stringify(e)}`);
32
- }
33
- return n.value;
34
- }
35
- const Ht = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
36
- function Vt(t) {
37
- if (typeof t != "string" || !t.startsWith("/")) throw new Error(`patch 路径无效:${t}`);
38
- const r = t.slice(1).split("/").map((n) => n.replace(/~1/g, "/").replace(/~0/g, "~"));
39
- if (r.some((n) => Ht.has(n))) throw new Error(`patch 路径无效:${t}`);
40
- return r;
41
- }
42
- function lt(t, r) {
43
- const n = Vt(r);
44
- let e = t, a = "value";
45
- for (const i of n) {
46
- if (e = e[a], typeof e != "object" || e === null) throw new Error(`patch 路径不存在:${r}`);
47
- a = i;
48
- }
49
- return [e, a];
50
- }
51
- function st(t, r, n) {
52
- const [e, a] = lt(t, r);
53
- if (Array.isArray(e)) {
54
- const i = a === "-" ? e.length : Number(a);
55
- if (!Number.isInteger(i) || i < 0 || i > e.length)
56
- throw new Error(`patch 下标越界:${r}`);
57
- e.splice(i, 0, n);
58
- } else
59
- e[a] = n;
60
- }
61
- function at(t, r) {
62
- const [n, e] = lt(t, r);
63
- if (Array.isArray(n)) {
64
- const i = Number(e);
65
- if (!Number.isInteger(i) || i < 0 || i >= n.length)
66
- throw new Error(`patch 下标越界:${r}`);
67
- return n.splice(i, 1)[0];
68
- }
69
- if (!(e in n)) throw new Error(`patch 路径不存在:${r}`);
70
- const a = n[e];
71
- return delete n[e], a;
72
- }
73
- const I = (t) => typeof t == "object" && t !== null && !Array.isArray(t);
74
- function Gt(t, r) {
75
- const n = I(t) ? t : {}, e = I(r) ? Object.keys(r) : [], a = gt.find(
76
- (d) => e.length > 0 && e.every((m) => Rt[d].includes(m))
77
- ), i = gt.includes(n.type) ? n.type : a ?? "dashboard";
78
- return { ...It[i], ...n, type: i };
79
- }
80
- function Kt(t, r) {
81
- if (!I(t)) return t;
82
- const n = {
83
- variables: [],
84
- ...Ct(t),
85
- apiVersion: vt
86
- };
87
- if (!Array.isArray(n.pages) && I(n.regions)) {
88
- n.pages = [
89
- {
90
- id: "main",
91
- title: typeof n.title == "string" ? n.title : "页面",
92
- layout: n.layout,
93
- regions: n.regions,
94
- ...n.detail ? { detail: n.detail } : {}
95
- }
96
- ];
97
- for (const m of ["version", "title", "layout", "regions", "detail"]) delete n[m];
98
- }
99
- Array.isArray(n.pages) && (n.pages = n.pages.map(
100
- (m) => I(m) ? {
101
- regions: {},
102
- ...m,
103
- layout: Gt(m.layout, m.regions)
104
- } : m
105
- ));
106
- const e = I(n.app) ? n.app : {}, a = Array.isArray(n.pages) && I(n.pages[0]) ? n.pages[0].title : void 0;
107
- n.app = {
108
- id: "app",
109
- name: typeof a == "string" ? a : "应用",
110
- ...e
111
- }, n.dependencies = { knowledgeNetwork: { id: r.id, name: r.name } };
112
- const i = I(n.theme) ? n.theme : {}, d = yt[typeof i.name == "string" ? i.name : ""] ?? yt.default;
113
- return n.theme = { ...d, ...i }, n;
114
- }
115
- const Xt = [
116
- "对应:一组数字卡合成一个 metricCards;表格、列表做成 objectTable 或 objectList;图表做成 trendChart,类型照原型(柱、线、饼);下拉、分段按钮、搜索框、日期框做成 dropdownFilter、segmentedFilter、searchBox、dateRange;结论和说明文字做成 text;导航、页眉、装饰不做。",
117
- "原型里的数字、表格行和图上的值都是示例:按列名、指标名、图例对应到知识网络中含义相同的对象类和属性,统计方式照原型(计数、合计、按月等),一律从知识网络取数,不要把示例数字写进配置。",
118
- "对应不上知识网络的项去掉;整个区块都对应不上时不做这个区块。不要编造对象类、属性或关系。",
119
- "主题参照原型的底色、文字色、强调色和深浅,仍须满足对比度要求;原型的区块有底色、边框或阴影时 theme.surface 用 card,否则用 plain。",
120
- "原型里对对象的操作按钮(如“催交”“新建采购单”),网络里有对应行动时配成组件的行动,没有就不做。",
121
- "这次以原型的排布为准,不用遵守“页面写法”里首屏先放结论、数字个数的要求。"
122
- ], Te = 8 * 1024 * 1024, kt = 1440, it = 4e4, Zt = 25e3, St = {
123
- /** Views read, the opening one too: as many as an app's pages should be. */
124
- viewsMax: 7,
125
- /** Navigation items clicked through. */
126
- navMax: 8,
127
- /** How long a view is given to show after its item is clicked. */
128
- clickMs: 400,
129
- /** Blocks and items read in one view. */
130
- nodesMax: 600
131
- }, Qt = 1e3, te = 1e4, ee = [
132
- "default-src 'none'",
133
- "script-src 'unsafe-inline' 'unsafe-eval' https:",
134
- "style-src 'unsafe-inline' https:",
135
- "img-src data: blob: https:",
136
- "font-src data: https:",
137
- "media-src data: blob: https:",
138
- "connect-src 'none'",
139
- "form-action 'none'",
140
- "frame-src 'none'"
141
- ].join("; "), je = (t) => /\.html?$/i.test(t);
142
- async function ne(t, r, n) {
143
- const e = t.document, a = Math.max(e.documentElement.clientWidth || t.innerWidth || 1, 1), i = (o, s = 120) => {
144
- const c = (o ?? "").replace(/\s+/g, " ").trim();
145
- return c.length > s ? `${c.slice(0, s)}…` : c;
146
- }, d = (o, s = 120) => i(o.innerText ?? o.textContent, s), m = (o) => t.getComputedStyle(o), y = (o) => {
147
- const s = o.getBoundingClientRect();
148
- if (s.width < 2 || s.height < 2) return !1;
149
- const c = m(o);
150
- return c.display !== "none" && c.visibility !== "hidden" && Number(c.opacity || "1") > 0.05;
151
- };
152
- let x = null, O = 0;
153
- const w = () => {
154
- x = null, O = 0;
155
- const o = Math.max(t.innerHeight * 0.5, 200);
156
- for (const s of Array.from(e.querySelectorAll("aside, nav, [role=navigation]"))) {
157
- if (!y(s)) continue;
158
- let c = null;
159
- for (let p = s; p && p !== e.body; p = p.parentElement) {
160
- const h = p.getBoundingClientRect();
161
- if (h.left > 8 || h.width > a * 0.3) break;
162
- c = p;
163
- }
164
- if (!c) continue;
165
- const g = c.getBoundingClientRect();
166
- g.height >= o && g.right > O && (O = g.right, x = c);
167
- }
168
- }, M = (o) => {
169
- const s = o.getBoundingClientRect();
170
- return [s.left + (t.scrollX || 0), s.top + (t.scrollY || 0), s.width, s.height];
171
- }, E = (o) => {
172
- let s = 1 / 0, c = -1 / 0;
173
- const g = (f) => {
174
- for (const l of f)
175
- "at" in l && (s = Math.min(s, l.at[0]), c = Math.max(c, l.at[0] + l.at[2])), l.k === "box" && g(l.items);
176
- };
177
- g(o);
178
- const p = Math.max(c - s, 1), h = ([f, l, T, u]) => {
179
- const b = Math.min(11, Math.max(0, Math.round((f - s) / p * 12))), v = Math.min(12 - b, Math.max(1, Math.round(T / p * 12)));
180
- return [b, Math.max(0, Math.round(l / 40)), v, Math.max(1, Math.round(u / 40))];
181
- }, k = (f) => f.map(
182
- (l) => l.k === "box" ? { k: "box", at: h(l.at), items: k(l.items) } : "at" in l ? { ...l, at: h(l.at) } : l
183
- );
184
- return k(o);
185
- }, $ = e.createElement("canvas");
186
- $.width = 1, $.height = 1;
187
- let S = null;
188
- try {
189
- S = $.getContext("2d", { willReadFrequently: !0 });
190
- } catch {
191
- S = null;
192
- }
193
- const R = (o, s, c) => `#${[o, s, c].map((g) => Math.round(g).toString(16).padStart(2, "0")).join("")}`, A = (o) => {
194
- if (!o || o === "transparent" || o === "none") return null;
195
- if (S)
196
- try {
197
- S.clearRect(0, 0, 1, 1), S.fillStyle = "rgba(0, 0, 0, 0)", S.fillStyle = o, S.fillRect(0, 0, 1, 1);
198
- const [k = 0, f = 0, l = 0, T = 0] = S.getImageData(0, 0, 1, 1).data;
199
- return T < 26 ? null : R(k, f, l);
200
- } catch {
201
- }
202
- const s = /rgba?\(([^)]+)\)/.exec(o);
203
- if (!s) return null;
204
- const [c = 0, g = 0, p = 0, h = 1] = (s[1] ?? "").split(/[\s,/]+/).filter(Boolean).map(Number);
205
- return h < 0.1 ? null : R(c, g, p);
206
- }, N = (o) => {
207
- for (let s = o; s; s = s.parentElement) {
208
- const c = A(m(s).backgroundColor);
209
- if (c) return c;
210
- }
211
- return null;
212
- }, P = (o) => {
213
- const s = o.getBoundingClientRect();
214
- if (s.width < 60 || s.height < 32) return !1;
215
- const c = m(o);
216
- if (c.boxShadow && c.boxShadow !== "none" || c.backgroundImage && c.backgroundImage !== "none" || ["top", "right", "bottom", "left"].filter(
217
- (h) => parseFloat(c.getPropertyValue(`border-${h}-width`)) >= 1 && c.getPropertyValue(`border-${h}-style`) !== "none" && A(c.getPropertyValue(`border-${h}-color`)) !== null
218
- ).length >= 3) return !0;
219
- const p = A(c.backgroundColor);
220
- return p !== null && p !== N(o.parentElement);
221
- }, F = (o) => {
222
- const s = o.parentElement;
223
- if (!s || s === e.body) return !1;
224
- const c = m(s);
225
- if (!(c.display.includes("grid") || c.display.includes("flex") && !c.flexDirection.startsWith("column"))) return !1;
226
- const p = o.getBoundingClientRect();
227
- return p.width < 80 || p.height < 40 ? !1 : Array.from(s.children).some((h) => h !== o && y(h));
228
- }, W = t, K = Array.from(e.querySelectorAll("script:not([src]):not([data-workshop-reader])")).map((o) => o.textContent ?? "").join(`
229
- `), et = /type\s*:\s*['"](line|bar|pie|scatter|radar|gauge|funnel|heatmap|sankey|treemap|area|doughnut|map)['"]/g, D = (o, s) => (Array.isArray(o) ? o : []).map(
230
- (c) => typeof c == "string" || typeof c == "number" ? String(c) : c && typeof c == "object" && "name" in c ? String(c.name) : ""
231
- ).map((c) => i(c, 24)).filter(Boolean).slice(0, s), _ = (o) => {
232
- const s = Array.isArray(o) ? o[0] : o;
233
- return s && typeof s == "object" ? s : {};
234
- }, U = (o) => {
235
- const s = o.getBoundingClientRect();
236
- if (s.width < 100 || s.height < 60) return !1;
237
- const c = o.tagName.toLowerCase();
238
- if (o.hasAttribute("_echarts_instance_") || c === "canvas") return !0;
239
- if (c === "svg") return s.width >= 120 && s.height >= 80;
240
- const g = `${o.id} ${o.getAttribute("class") ?? ""}`;
241
- return /chart|graph|plot|echart/i.test(g) && i(o.textContent) === "";
242
- }, L = (o) => {
243
- const s = { k: "chart", at: M(o) };
244
- try {
245
- const h = o.hasAttribute("_echarts_instance_") ? W.echarts?.getInstanceByDom?.(o) : void 0;
246
- if (h) {
247
- const f = h.getOption(), l = Array.isArray(f.series) ? f.series : [], T = [
248
- ...new Set(l.map((B) => String(_(B).type ?? "")).filter(Boolean))
249
- ];
250
- T.length > 0 && (s.types = T);
251
- const u = D(l, 8);
252
- u.length > 0 && (s.series = u);
253
- const b = D(_(f.xAxis).data, 12);
254
- b.length > 0 && (s.axis = b);
255
- const v = i(String(_(f.title).text ?? ""), 40);
256
- return v && (s.title = v), s;
257
- }
258
- const k = o.tagName.toLowerCase() === "canvas" ? W.Chart?.getChart?.(o) : void 0;
259
- if (k) {
260
- k.config?.type && (s.types = [String(k.config.type)]);
261
- const f = k.data ?? {}, l = D(f.labels, 12);
262
- l.length > 0 && (s.axis = l);
263
- const T = D(
264
- (Array.isArray(f.datasets) ? f.datasets : []).map((u) => _(u).label),
265
- 8
266
- );
267
- return T.length > 0 && (s.series = T), s;
268
- }
269
- } catch {
270
- }
271
- const c = o.id || o.parentElement?.id, g = c ? [`"${c}"`, `'${c}'`, `#${c}`, `\`${c}\``].map((h) => K.indexOf(h)).filter((h) => h >= 0) : [], p = g.length > 0 ? Math.min(...g) : -1;
272
- if (p >= 0) {
273
- const h = K.slice(p + 1, p + 4e3), k = h.search(
274
- /getElementById|querySelector|echarts\.init|new Chart|\b(draw|render|init)\w*\(/
275
- ), f = k > 0 ? h.slice(0, k) : h, l = [...new Set(Array.from(f.matchAll(et), (T) => T[1] ?? ""))];
276
- l.length > 0 && (s.types = l.filter(Boolean).slice(0, 4));
277
- }
278
- return s;
279
- }, X = (o) => {
280
- const s = o.getAttribute("role"), c = o.tagName.toLowerCase() === "table" ? Array.from(o.rows) : Array.from(o.querySelectorAll("[role=row]")), g = (f) => Array.from(
281
- f.tagName.toLowerCase() === "tr" ? f.cells : f.querySelectorAll("[role=columnheader],[role=cell],[role=gridcell]")
282
- ).map((l) => d(l, 30)), p = c.filter(y), h = p.find((f) => f.querySelector("th,[role=columnheader]")) ?? (s ? void 0 : p[0]), k = p.filter((f) => f !== h);
283
- return {
284
- k: "table",
285
- at: M(o),
286
- columns: h ? g(h) : [],
287
- rows: k.length,
288
- sample: k.slice(0, 2).map(g)
289
- };
290
- }, j = (o) => [
291
- ...new Set(
292
- Array.from(o.querySelectorAll("a,button,[role=tab],[role=menuitem],li")).filter(y).map((s) => d(s, 20)).filter((s) => s.length > 0 && s.length <= 12)
293
- )
294
- ].slice(0, 12), Z = /* @__PURE__ */ new Set([
295
- "script",
296
- "style",
297
- "noscript",
298
- "template",
299
- "link",
300
- "meta",
301
- "iframe",
302
- "object",
303
- "embed",
304
- "br",
305
- "hr",
306
- "head",
307
- "title"
308
- ]), nt = "div,p,section,article,main,header,footer,aside,nav,ul,ol,li,table,canvas,svg,select,input,textarea,button,img,h1,h2,h3,h4,h5,h6,form,label,dl,figure,[role=table],[role=grid],[role=tab]";
309
- let H = 0;
310
- const C = (o) => {
311
- const s = o.tagName.toLowerCase();
312
- if (H >= r.nodesMax || Z.has(s) || !y(o)) return [];
313
- H++;
314
- const c = o.getAttribute("role");
315
- if (o === x || s === "nav" || c === "navigation" || c === "tablist") {
316
- const u = j(o);
317
- return u.length > 0 ? [{ k: "nav", items: u }] : [];
318
- }
319
- if (s === "table" || c === "table" || c === "grid") return [X(o)];
320
- if (U(o)) return [L(o)];
321
- if (s === "svg") return [];
322
- if (s === "select")
323
- return [
324
- {
325
- k: "select",
326
- options: Array.from(o.options).map((u) => i(u.text, 20)).filter(Boolean).slice(0, 8)
327
- }
328
- ];
329
- if (s === "input" || s === "textarea") {
330
- const u = s === "textarea" ? "text" : o.type || "text";
331
- if (u === "submit" || u === "button")
332
- return [{ k: "button", text: i(o.value, 30) }];
333
- if (u === "hidden" || u === "checkbox" || u === "radio") return [];
334
- const b = i(o.getAttribute("placeholder") || o.getAttribute("aria-label"), 40);
335
- return [{ k: "input", type: u, ...b ? { hint: b } : {} }];
336
- }
337
- if (s === "button" || c === "button" || c === "tab") {
338
- const u = d(o, 30) || i(o.getAttribute("aria-label") || o.getAttribute("title"), 30);
339
- return u ? [{ k: "button", text: u }] : [];
340
- }
341
- if (s === "img") {
342
- const u = o.getBoundingClientRect();
343
- if (u.width < 60 || u.height < 40) return [];
344
- const b = i(o.getAttribute("alt"), 40);
345
- return [{ k: "image", at: M(o), ...b ? { text: b } : {} }];
346
- }
347
- if (/^h[1-6]$/.test(s)) {
348
- const u = d(o, 80);
349
- return u ? [{ k: "heading", text: u }] : [];
350
- }
351
- const g = o !== e.body && (P(o) || F(o));
352
- if (!o.querySelector(nt)) {
353
- const u = d(o);
354
- if (!u) return [];
355
- const b = { k: "text", text: u };
356
- return g ? [{ k: "box", at: M(o), items: [b] }] : [b];
357
- }
358
- const p = [];
359
- let h = "", k = 0, f = 0;
360
- const l = () => {
361
- f > 0 && p.push({ k: "more", count: f }), f = 0;
362
- };
363
- for (const u of Array.from(o.childNodes)) {
364
- if (u.nodeType === 3) {
365
- const B = i(u.textContent);
366
- if (!B) continue;
367
- l(), h = "", p.push({ k: "text", text: B });
368
- continue;
369
- }
370
- if (u.nodeType !== 1) continue;
371
- const b = u;
372
- if (!y(b)) continue;
373
- const v = `${b.tagName}.${b.getAttribute("class") ?? ""}`;
374
- if (v === h ? k++ : (l(), h = v, k = 1), k > 3) {
375
- f++;
376
- continue;
377
- }
378
- p.push(...C(b));
379
- }
380
- return l(), !g || p.length === 0 || o.getBoundingClientRect().width >= (a - O) * 0.9 && p.some((u) => u.k === "box") ? p : [{ k: "box", at: M(o), items: p }];
381
- }, V = () => (t.scrollTo(0, 0), H = 0, w(), e.body ? E(C(e.body)) : []);
382
- e.addEventListener(
383
- "click",
384
- (o) => {
385
- const c = o.target?.closest?.("a[href]");
386
- c && !/^\s*(#|javascript:)/i.test(c.getAttribute("href") ?? "") && o.preventDefault();
387
- },
388
- !0
389
- );
390
- const G = "nav a, nav button, aside a, aside button, header a, header button, [role=tab], [role=tablist] button, [role=menuitem]", rt = () => Array.from(e.querySelectorAll(G)).filter((o) => {
391
- const s = d(o, 20);
392
- return y(o) && s.length > 0 && s.length <= 12;
393
- }), Tt = [...new Set(rt().map((o) => d(o, 20)))].slice(0, r.navMax), ft = rt().find(
394
- (o) => o.getAttribute("aria-current") === "page" || o.getAttribute("aria-current") === "true" || o.getAttribute("aria-selected") === "true" || /(^|[\s_-])(active|selected|current)($|[\s_-])/i.test(o.getAttribute("class") ?? "")
395
- ), pt = e.querySelector("h1"), dt = i(e.title, 40) || (pt ? d(pt, 40) : ""), mt = (o) => JSON.stringify(o).replace(/\d+/g, "#"), Q = [
396
- { name: (ft ? d(ft, 20) : "") || dt, nodes: V() }
397
- ], jt = () => {
398
- const o = e.body ?? e.documentElement, s = N(o) ?? "#ffffff", c = (f) => {
399
- const [l, T, u] = [1, 3, 5].map((B) => parseInt(f.slice(B, B + 2), 16) / 255), b = Math.max(l ?? 0, T ?? 0, u ?? 0), v = Math.min(l ?? 0, T ?? 0, u ?? 0);
400
- return b > 0 && (b - v) / b > 0.35;
401
- };
402
- let g;
403
- for (const f of Array.from(e.querySelectorAll("button,a,[role=tab],[role=button]"))) {
404
- if (!y(f)) continue;
405
- const l = A(m(f).backgroundColor);
406
- if (l && c(l)) {
407
- g = l;
408
- break;
409
- }
410
- }
411
- if (!g)
412
- for (const f of Array.from(e.querySelectorAll("a,h1,h2,h3"))) {
413
- const l = y(f) ? A(m(f).color) : null;
414
- if (l && c(l) && l !== "#0000ee" && l !== "#551a8b") {
415
- g = l;
416
- break;
417
- }
418
- }
419
- const p = (f) => {
420
- const [l, T, u] = [1, 3, 5].map((b) => parseInt(f.slice(b, b + 2), 16) / 255);
421
- return 0.2126 * (l ?? 0) + 0.7152 * (T ?? 0) + 0.0722 * (u ?? 0);
422
- }, h = A(m(o).color), k = parseFloat(m(o).fontSize);
423
- return {
424
- background: s,
425
- ...h ? { text: h } : {},
426
- ...g ? { accent: g } : {},
427
- ...Number.isFinite(k) ? { fontSize: Math.round(k) } : {},
428
- dark: p(s) < 0.4
429
- };
430
- }, ot = () => ({ title: dt, views: [...Q], theme: jt() }), ht = new Set(Q.map((o) => mt(o.nodes)));
431
- n?.(ot());
432
- for (const o of Tt) {
433
- if (Q.length >= r.viewsMax) break;
434
- const s = rt().find((p) => d(p, 20) === o);
435
- if (!s) continue;
436
- s.click(), await new Promise((p) => t.setTimeout(p, r.clickMs));
437
- const c = V(), g = mt(c);
438
- ht.has(g) || (ht.add(g), Q.push({ name: o, nodes: c }), n?.(ot()));
439
- }
440
- return ot();
441
- }
442
- const re = (t) => t.replace(/<\/(script)/gi, "<\\/$1");
443
- function oe() {
444
- return re(`(() => {
445
- const collect = ${ne.toString()};
446
- let started = false;
447
- const run = () => {
448
- if (started) return;
449
- started = true;
450
- collect(window, ${JSON.stringify(St)}, (outline) =>
451
- parent.postMessage({ t: "workshop:prototype", outline, partial: true }, "*"),
452
- ).then(
453
- (outline) => parent.postMessage({ t: "workshop:prototype", outline }, "*"),
454
- (error) => parent.postMessage(
455
- { t: "workshop:prototype", error: String((error && error.message) || error) }, "*"),
456
- );
457
- };
458
- addEventListener("load", () => setTimeout(run, ${Qt}));
459
- setTimeout(run, ${te});
460
- })();`);
461
- }
462
- function se(t) {
463
- const r = t.replace(/^?\s*<!doctype[^>]*>/i, "");
464
- return [
465
- "<!doctype html>",
466
- `<meta http-equiv="Content-Security-Policy" content="${ee}">`,
467
- `<script data-workshop-reader>${oe()}<\/script>`,
468
- r
469
- ].join(`
470
- `);
471
- }
472
- class ae extends Error {
473
- constructor() {
474
- super("prototype not read in time");
475
- }
476
- }
477
- const z = (t) => typeof t == "object" && t !== null && !Array.isArray(t), q = (t, r = 200) => typeof t == "string" ? t.slice(0, r) : "", Y = (t, r, n = 60) => Array.isArray(t) ? t.slice(0, r).map((e) => q(e, n)) : [], ie = (t) => {
478
- if (!Array.isArray(t) || t.length !== 4) return null;
479
- const [r, n, e, a] = t.map((i) => typeof i == "number" && Number.isFinite(i) ? i : NaN);
480
- return [r, n, e, a].some((i) => i === void 0 || Number.isNaN(i)) ? null : [r, n, e, a];
481
- }, ct = (t) => typeof t == "string" && /^#[0-9a-f]{6}$/i.test(t) ? t : void 0;
482
- function ce(t, r) {
483
- if (!z(t) || r > 40) return null;
484
- const n = ie(t.at);
485
- switch (t.k) {
486
- case "box":
487
- return n ? { k: "box", at: n, items: At(t.items, r + 1) } : null;
488
- case "heading":
489
- case "text":
490
- case "button": {
491
- const e = q(t.text);
492
- return e ? { k: t.k, text: e } : null;
493
- }
494
- case "table":
495
- return n ? {
496
- k: "table",
497
- at: n,
498
- columns: Y(t.columns, 40, 40),
499
- rows: typeof t.rows == "number" ? t.rows : 0,
500
- sample: Array.isArray(t.sample) ? t.sample.slice(0, 2).map((e) => Y(e, 40, 40)) : []
501
- } : null;
502
- case "chart": {
503
- if (!n) return null;
504
- const e = Y(t.types, 4, 20).filter(Boolean), a = Y(t.series, 8, 30).filter(Boolean), i = Y(t.axis, 12, 30).filter(Boolean), d = q(t.title, 60);
505
- return {
506
- k: "chart",
507
- at: n,
508
- ...e.length > 0 ? { types: e } : {},
509
- ...d ? { title: d } : {},
510
- ...a.length > 0 ? { series: a } : {},
511
- ...i.length > 0 ? { axis: i } : {}
512
- };
513
- }
514
- case "select":
515
- return { k: "select", options: Y(t.options, 8, 30).filter(Boolean) };
516
- case "input": {
517
- const e = q(t.hint, 60);
518
- return { k: "input", type: q(t.type, 20) || "text", ...e ? { hint: e } : {} };
519
- }
520
- case "image": {
521
- if (!n) return null;
522
- const e = q(t.text, 60);
523
- return { k: "image", at: n, ...e ? { text: e } : {} };
524
- }
525
- case "nav": {
526
- const e = Y(t.items, 12, 30).filter(Boolean);
527
- return e.length > 0 ? { k: "nav", items: e } : null;
528
- }
529
- case "more":
530
- return typeof t.count == "number" && t.count > 0 ? { k: "more", count: Math.round(t.count) } : null;
531
- default:
532
- return null;
533
- }
534
- }
535
- function At(t, r = 0) {
536
- return (Array.isArray(t) ? t.slice(0, 1e3) : []).map((n) => ce(n, r)).filter((n) => n !== null);
537
- }
538
- function bt(t) {
539
- const r = z(t) ? t : {}, n = z(r.theme) ? r.theme : {}, e = ct(n.background), a = ct(n.text), i = ct(n.accent);
540
- return {
541
- title: q(r.title, 60),
542
- views: (Array.isArray(r.views) ? r.views.slice(0, St.viewsMax) : []).filter(z).map((d) => ({ name: q(d.name, 40), nodes: At(d.nodes) })),
543
- theme: {
544
- ...e ? { background: e } : {},
545
- ...a ? { text: a } : {},
546
- ...i ? { accent: i } : {},
547
- ...typeof n.fontSize == "number" && n.fontSize > 0 ? { fontSize: Math.round(n.fontSize) } : {},
548
- ...typeof n.dark == "boolean" ? { dark: n.dark } : {}
549
- }
550
- };
551
- }
552
- function Re(t, { signal: r, wait: n = Zt } = {}) {
553
- return new Promise((e, a) => {
554
- if (r?.aborted) {
555
- a(r.reason);
556
- return;
557
- }
558
- const i = document.createElement("iframe");
559
- i.setAttribute("sandbox", "allow-scripts"), i.setAttribute("referrerpolicy", "no-referrer"), i.setAttribute("aria-hidden", "true"), i.tabIndex = -1, i.title = "prototype", Object.assign(i.style, {
560
- position: "fixed",
561
- left: "0",
562
- top: "0",
563
- width: `${kt}px`,
564
- height: "900px",
565
- border: "0",
566
- opacity: "0",
567
- pointerEvents: "none",
568
- zIndex: "-1"
569
- });
570
- let d = 0, m, y = 0;
571
- const x = (E, $) => {
572
- window.clearTimeout(d), window.removeEventListener("message", O), r?.removeEventListener("abort", w), i.remove(), E ? a(E) : e($);
573
- }, O = (E) => {
574
- if (E.source !== i.contentWindow) return;
575
- const $ = E.data;
576
- !z($) || $.t !== "workshop:prototype" || ($.partial === !0 ? m = bt($.outline) : typeof $.error == "string" ? x(new Error($.error.slice(0, 500))) : x(null, bt($.outline)));
577
- }, w = () => x(r?.reason ?? new Error("stopped")), M = () => {
578
- y += 1, y > 1 && m && x(null, m);
579
- };
580
- window.addEventListener("message", O), r?.addEventListener("abort", w), i.addEventListener("load", M), d = window.setTimeout(
581
- () => m ? x(null, m) : x(new ae()),
582
- n
583
- ), i.srcdoc = se(t), document.body.appendChild(i);
584
- });
585
- }
586
- function Ne(t) {
587
- const r = (n) => n.reduce(
588
- (e, a) => e + (a.k === "box" ? 1 + r(a.items) : "at" in a ? 1 : 0),
589
- 0
590
- );
591
- return t.views.reduce((n, e) => n + r(e.nodes), 0);
592
- }
593
- const tt = ([t, r, n, e]) => `[x${t} y${r} w${n} h${e}]`, J = (t) => `「${t}」`;
594
- function Et(t, r) {
595
- const n = (e) => `${r}- ${e}`;
596
- switch (t.k) {
597
- case "box":
598
- return [
599
- n(`${tt(t.at)} 区块`),
600
- ...t.items.flatMap((e) => Et(e, `${r} `))
601
- ];
602
- case "heading":
603
- return [n(`标题${J(t.text)}`)];
604
- case "text":
605
- return [n(`文字${J(t.text)}`)];
606
- case "table":
607
- return [
608
- n(
609
- [
610
- `${tt(t.at)} 表格:列 ${t.columns.filter(Boolean).join("、") || "(无列头)"}`,
611
- `${t.rows} 行`,
612
- ...t.sample.length > 0 ? [`示例 ${t.sample.map((e) => e.join("|")).join(";")}`] : []
613
- ].join(";")
614
- )
615
- ];
616
- case "chart":
617
- return [
618
- n(
619
- [
620
- `${tt(t.at)} 图表(${t.types?.join("、") || "类型未知"})`,
621
- ...t.title ? [`标题${J(t.title)}`] : [],
622
- ...t.series ? [`系列 ${t.series.join("、")}`] : [],
623
- ...t.axis ? [`横轴 ${t.axis.join("、")}`] : []
624
- ].join(":")
625
- )
626
- ];
627
- case "select":
628
- return [n(`下拉框:选项 ${t.options.join("、") || "(无)"}`)];
629
- case "input":
630
- return [
631
- n(
632
- `${t.type === "date" || t.type === "datetime-local" || t.type === "month" ? "日期框" : `输入框(${t.type})`}${t.hint ? `:提示${J(t.hint)}` : ""}`
633
- )
634
- ];
635
- case "button":
636
- return [n(`按钮${J(t.text)}`)];
637
- case "image":
638
- return [n(`${tt(t.at)} 图片${t.text ? J(t.text) : ""}`)];
639
- case "nav":
640
- return [n(`导航:${t.items.join("、")}`)];
641
- case "more":
642
- return [n(`另有 ${t.count} 个同样的项`)];
643
- }
644
- }
645
- function Ce(t) {
646
- const { theme: r } = t, n = [
647
- `原型标题:${t.title || "(无)"}`,
648
- `按 ${kt} 像素宽渲染;方括号为区块在自由布局中的位置 [x y 宽 高](12 列,每行 40 像素)。`,
649
- `主题:${[
650
- r.background ? `底色 ${r.background}` : "",
651
- r.text ? `文字色 ${r.text}` : "",
652
- r.accent ? `强调色 ${r.accent}` : "",
653
- r.fontSize ? `正文 ${r.fontSize} 像素` : "",
654
- r.dark === void 0 ? "" : r.dark ? "深色" : "浅色"
655
- ].filter(Boolean).join(",")}`
656
- ], e = t.views.map(
657
- (m, y) => [
658
- `视图 ${y + 1}${J(m.name || `视图 ${y + 1}`)}`,
659
- ...m.nodes.flatMap((x) => Et(x, ""))
660
- ].join(`
661
- `)
662
- );
663
- let a = e.length;
664
- const i = (m) => [...n, ...e.slice(0, m)].join(`
665
-
666
- `);
667
- for (; a > 1 && i(a).length > it; ) a--;
668
- const d = i(a);
669
- return {
670
- text: d.length > it ? `${d.slice(0, it)}…` : d,
671
- views: a
672
- };
673
- }
674
- function ve(t) {
675
- const { name: r, outline: n, words: e, hasPages: a } = t;
676
- return [
677
- `附件《${r}》是一个 HTML 原型。下面是它在浏览器里渲染后读出的结构(不是原文)。请照着它,在当前知识网络上做成 Workshop 应用:`,
678
- `- 每个视图做成一页,页面标题用视图名称;${a ? "应用已有的页面保留不动,原型的页面加在后面" : "按原型新建应用"};不改应用名称。`,
679
- "- 页面用 free 布局:组件的 frame 照区块方括号里的 [x y 宽 高];为满足组件最小尺寸可以适当调整,组件之间不要重叠。",
680
- ...Xt.map((i) => `- ${i}`),
681
- `- 输出 {"spec": 完整 App Spec, "notes": [...]}${a ? ',或 {"patch": [...], "notes": [...]}' : ""};notes 只写没有照做、或做法与原型明显不同的项和原因,每条一句,如“表格列‘承运商’在网络中没有对应属性,已去掉”;按上面的对应关系做的(导航做成页面、数字卡合成指标卡组等)不用写;都照做了时为空列表。`,
682
- ...e ? ["", `用户另外的要求:${e}`] : [],
683
- "",
684
- "原型结构:",
685
- "<<<",
686
- n,
687
- ">>>"
688
- ].join(`
689
- `);
690
- }
691
- function le(t) {
692
- return !z(t) || !Array.isArray(t.notes) ? null : t.notes.filter((r) => typeof r == "string" && r.trim() !== "").map((r) => r.trim().slice(0, 200)).slice(0, 30);
693
- }
694
- function Ot(t) {
695
- if (typeof t != "object" || t === null) return !1;
696
- const r = t;
697
- return r.spec !== void 0 || r.patch !== void 0 || "apiVersion" in r || "pages" in r;
698
- }
699
- class xt extends Error {
700
- constructor(r) {
701
- super(r.join(";")), this.errors = r;
702
- }
703
- errors;
704
- }
705
- function ue(t, r) {
706
- return `${t?.scheduleModel ? `当前调度模型:
707
- ${JSON.stringify(t.scheduleModel)}
708
-
709
- ` : ""}用户对调度的描述:${r}
710
-
711
- 按“调度模型”一节只输出 {"scheduleModel": ..., "needs": [...]},不要输出 spec 或 patch。`;
712
- }
713
- function fe(t) {
714
- if (typeof t != "object" || t === null || Ot(t)) return null;
715
- const r = t.component;
716
- if (typeof r != "object" || r === null) return null;
717
- const { explicit: n, reason: e } = r;
718
- return { explicit: n === !0, reason: typeof e == "string" ? e.trim() : "" };
719
- }
720
- const ut = 16384, pe = 65536, de = 2e3;
721
- async function me(t) {
722
- const {
723
- model: r,
724
- system: n,
725
- messages: e,
726
- signal: a,
727
- stream: i,
728
- onProgress: d,
729
- maxOutputTokens: m = ut
730
- } = t, y = {
731
- model: r,
732
- system: n,
733
- messages: e,
734
- maxOutputTokens: m,
735
- maxRetries: 0,
736
- abortSignal: a
737
- };
738
- if (!i) return (await wt(y)).text;
739
- let x;
740
- const O = Nt({
741
- ...y,
742
- onError: ({ error: E }) => {
743
- x = E;
744
- }
745
- });
746
- let w = "", M = 0;
747
- for await (const E of O.textStream)
748
- w += E, w.length - M >= de && (M = w.length, d(w.length));
749
- if (x) throw x instanceof Error ? x : new Error(String(x));
750
- if (a?.aborted)
751
- throw a.reason instanceof Error ? a.reason : new Error(String(a.reason));
752
- return w;
753
- }
754
- function Mt(t) {
755
- return t.replace(/<think>[\s\S]*?<\/think>/g, "");
756
- }
757
- function he(t) {
758
- const r = Mt(t), n = r.indexOf("{"), e = r.lastIndexOf("}");
759
- if (n < 0 || e <= n) throw new Error("no JSON object");
760
- return JSON.parse(r.slice(n, e + 1));
761
- }
762
- function ge(t, r) {
763
- if (typeof t != "object" || t === null) throw new Error("输出不是 JSON 对象");
764
- const n = t;
765
- if (n.patch !== void 0) {
766
- if (!r) throw new Error("还没有页面,不能输出 patch,请输出完整的 spec");
767
- return { mode: "patch", spec: Wt(r, n.patch) };
768
- }
769
- return n.spec !== void 0 ? { mode: "spec", spec: n.spec } : { mode: "spec", spec: t };
770
- }
771
- function ye(t, r) {
772
- if (typeof t != "object" || t === null || Array.isArray(t)) return t;
773
- const n = { ...t };
774
- return delete n.scheduleModel, r?.scheduleModel ? { ...n, scheduleModel: r.scheduleModel } : n;
775
- }
776
- function be(t, r) {
777
- const n = (a) => (a?.pages ?? []).flatMap(
778
- (i) => Object.values(i.regions).flat().map((d) => d?.type)
779
- ), e = new Set(n(t));
780
- return [
781
- ...new Set(
782
- n(r).filter(
783
- (a) => typeof a == "string" && !e.has(a) && Ft.includes(a)
784
- )
785
- )
786
- ];
787
- }
788
- async function Pe(t) {
789
- const {
790
- model: r,
791
- kn: n,
792
- current: e,
793
- instruction: a,
794
- target: i,
795
- signal: d,
796
- maxAttempts: m = 3,
797
- onStep: y,
798
- scenarios: x = !0,
799
- ruleTools: O,
800
- scheduleOnly: w = !1,
801
- importing: M = !1,
802
- replicating: E = !1
803
- } = t, $ = M || E, S = performance.now(), R = [
804
- {
805
- role: "user",
806
- content: w ? ue(e, a) : qt(e, a, i?.note)
807
- }
808
- ];
809
- let A = [], N = e;
810
- const P = w ? `${a} scheduleGantt` : a, F = await Bt(e, P, i ? [i.type] : []), W = w || Yt(e, P).includes("scheduleGantt"), K = !$ && (w || O !== void 0 && W), et = Jt(
811
- n,
812
- e,
813
- M ? `${a}
814
- ${JSON.stringify(e)}` : a
815
- ), D = Dt(n, et, F, {
816
- scenarios: x,
817
- ...O ? { ruleTools: O } : w ? { ruleTools: [] } : {},
818
- scheduling: W,
819
- newComponents: !w && !$ && e !== null
820
- });
821
- let _ = w, U = [];
822
- for (let L = 1; L <= m; L++) {
823
- y?.({ kind: "generating", attempt: L });
824
- const X = await me({
825
- model: r,
826
- system: D,
827
- messages: R,
828
- signal: d,
829
- stream: $,
830
- onProgress: (j) => y?.({ kind: "progress", chars: j }),
831
- maxOutputTokens: $ ? pe : ut
832
- });
833
- try {
834
- const j = he(X);
835
- E && (U = le(j) ?? U);
836
- const Z = !w && !$ && e ? fe(j) : null;
837
- if (Z)
838
- return y?.({ kind: "valid", mode: "component" }), { ok: !0, component: Z, attempts: L, ms: performance.now() - S };
839
- if (w || K && Ut(j) && !Ot(j)) {
840
- _ = !0;
841
- const G = zt(j, n, O ?? [], e?.scheduleModel);
842
- if (G.ok)
843
- return y?.({ kind: "valid", mode: "schedule" }), {
844
- ok: !0,
845
- schedule: G.proposal,
846
- attempts: L,
847
- ms: performance.now() - S
848
- };
849
- throw new xt(G.errors);
850
- }
851
- _ = !1;
852
- const { mode: nt, spec: H } = ge(j, N);
853
- N = Kt(ye(H, e), n);
854
- const C = Pt(N, n), V = x ? [] : be(e, C.ok ? C.app : null);
855
- if (C.ok && V.length > 0)
856
- A = [
857
- `方案推演需要企业版,当前环境不提供:去掉新加的方案类组件(${V.join("、")})`
858
- ];
859
- else {
860
- if (C.ok)
861
- return y?.({ kind: "valid", mode: nt }), {
862
- ok: !0,
863
- spec: C.app,
864
- attempts: L,
865
- ms: performance.now() - S,
866
- ...U.length > 0 ? { notes: U } : {}
867
- };
868
- A = C.errors;
869
- }
870
- } catch (j) {
871
- A = j instanceof xt ? j.errors : [j instanceof Error ? j.message : String(j)];
872
- }
873
- y?.({ kind: "invalid", errors: A }), R.push(
874
- { role: "assistant", content: X },
875
- {
876
- role: "user",
877
- content: _ ? `上次输出的调度模型答案不合法:
878
- - ${A.slice(0, 20).join(`
879
- - `)}
880
- 请修正后重新输出 {"scheduleModel": ..., "needs": [...]}。` : `上次输出不合法:
881
- - ${A.slice(0, 20).join(`
882
- - `)}
883
- 请修正:可以输出完整的 {"spec": ...}${N ? ',或输出相对你上次结果的 {"patch": [...]}' : ""}。`
884
- }
885
- );
886
- }
887
- return {
888
- ok: !1,
889
- errors: A,
890
- attempts: m,
891
- ms: performance.now() - S
892
- };
893
- }
894
- function xe(t) {
895
- const r = Object.values(t.objectTypes).filter((e) => !Lt(e.id)).map(
896
- (e) => `- ${e.id}(${e.name})主键 ${e.primaryKeys.join("、") || "无"}
897
- ${e.properties.map((a) => `${a.name}:${a.type}(${a.label})`).join(",")}`
898
- ), n = t.relations.map(
899
- (e) => `- ${e.id}(${e.name}):(${e.source})-[:${e.id}]->(${e.target})`
900
- );
901
- return `对象类(id(名称)、主键、属性名:类型(显示名)):
902
- ${r.join(`
903
- `)}
904
-
905
- 关系类(方向从左到右):
906
- ${n.join(`
907
- `)}`;
908
- }
909
- function we(t, r) {
910
- const n = r.filter((e) => _t.includes(e.kind));
911
- return `你为业务应用的数据源编写只读 Cypher 查询,在知识网络「${t.name}」上运行。
912
-
913
- 规则:
914
- - 只写一条只读查询:MATCH … [WHERE …] [WITH …] RETURN … [ORDER BY …] LIMIT n。不能用 CREATE、MERGE、SET、DELETE、REMOVE、CALL。
915
- - 标签、关系类型和属性名都用下面的 id,并用反引号括起来,如 (a:\`对象类id\`)-[:\`关系id\`]->(b:\`对象类id\`)、a.\`属性名\`;关系方向必须与清单一致,反向时写 <-[:…]-。
916
- - 属性名只能用清单里该对象类的属性,原样写,不要猜。
917
- - RETURN 的每一列都用 AS 起简短的英文别名(字母开头,可含字母、数字、下划线),别名就是数据源的列名。
918
- - 要能当主键的列:通常返回主对象的主键,每行唯一。
919
- - 可以用 count、sum、avg、min、max 聚合;聚合时非聚合列就是分组键。
920
- - 结果最多 10000 行,一定要写 LIMIT。
921
- - 需要跟随页面变量时,用 $变量名 作为参数,只能用下面列出的变量;不要把变量值直接写进查询。
922
- - 日期属性(date、datetime、timestamp)通常以 ISO 文本存储,可与 'YYYY-MM-DD' 或日期变量比较大小;查询结果为空时,可能是这个属性的存储格式不同,在说明里提一句。
923
-
924
- 页面变量(可作 $参数):
925
- ${n.map((e) => `- $${e.name}:${e.label}(${e.kind})`).join(`
926
- `) || "(无)"}
927
-
928
- ${xe(t)}
929
-
930
- 只输出 JSON:{"query": "…", "explanation": "一句话说明经过哪些关系、怎么聚合"}。`;
931
- }
932
- function $e(t) {
933
- const r = Mt(t), n = r.match(/\{[\s\S]*\}/);
934
- if (n)
935
- try {
936
- const a = JSON.parse(n[0]);
937
- if (typeof a.query == "string" && a.query.trim())
938
- return {
939
- query: a.query.trim(),
940
- explanation: typeof a.explanation == "string" ? a.explanation : ""
941
- };
942
- } catch {
943
- }
944
- const e = r.match(/```(?:cypher)?\s*([\s\S]*?)```/);
945
- if (e) return { query: e[1].trim(), explanation: "" };
946
- throw new Error("回复里没有找到查询");
947
- }
948
- async function _e(t) {
949
- const { model: r, kn: n, variables: e, values: a, instruction: i, current: d, query: m, signal: y, onStep: x } = t, O = t.maxAttempts ?? 3, w = [
950
- {
951
- role: "user",
952
- content: d?.trim() ? `当前查询:
953
- ${d}
954
-
955
- 修改要求:${i}` : i
956
- }
957
- ];
958
- let M = { query: "", error: "" };
959
- for (let E = 1; E <= O; E++) {
960
- x?.({ kind: "generating", attempt: E });
961
- const { text: $ } = await wt({
962
- model: r,
963
- system: we(n, e),
964
- messages: w,
965
- maxOutputTokens: ut,
966
- maxRetries: 0,
967
- abortSignal: y
968
- });
969
- let S = "";
970
- try {
971
- const R = $e($);
972
- S = R.query;
973
- const A = $t(S).filter(
974
- (P) => !e.some((F) => F.name === P)
975
- );
976
- if (A.length > 0)
977
- throw new Error(`参数 ${A.map((P) => `$${P}`).join("、")} 不是页面变量`);
978
- x?.({ kind: "running", query: S });
979
- const N = await m(S, ke(S, a), y);
980
- return {
981
- ok: !0,
982
- query: S,
983
- explanation: R.explanation,
984
- result: N,
985
- attempts: E
986
- };
987
- } catch (R) {
988
- if (y?.aborted) throw R;
989
- const A = Se(R);
990
- M = { query: S, error: A }, x?.({ kind: "failed", error: A }), w.push(
991
- { role: "assistant", content: $ },
992
- {
993
- role: "user",
994
- content: `运行失败:${A}
995
- 请对照对象类、属性和关系方向修正,仍只输出 JSON。`
996
- }
997
- );
998
- }
999
- }
1000
- return { ok: !1, error: M.error, query: M.query, attempts: O };
1001
- }
1002
- function ke(t, r) {
1003
- return Object.fromEntries(
1004
- $t(t).map((n) => {
1005
- const e = r[n];
1006
- return Array.isArray(e) ? [n, e.map(String)] : [n, e == null ? null : String(e)];
1007
- })
1008
- );
1009
- }
1010
- function Se(t) {
1011
- const r = t.response?.data;
1012
- return r && (typeof r.details == "string" || typeof r.description == "string") ? [r.description, r.details].filter((n) => typeof n == "string").join(":") : t instanceof Error ? t.message : String(t);
1013
- }
1014
- export {
1015
- ut as M,
1016
- Te as P,
1017
- Zt as R,
1018
- he as a,
1019
- Pe as b,
1020
- ae as c,
1021
- xe as d,
1022
- Se as e,
1023
- Ne as f,
1024
- _e as g,
1025
- ve as h,
1026
- je as i,
1027
- me as m,
1028
- Ce as o,
1029
- ke as p,
1030
- Re as r,
1031
- Mt as w
1032
- };