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