@openbkn/workshop 0.2.2-rc.5 → 0.2.2-rc.6
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/README.md +79 -8
- package/component.d.ts +10 -0
- package/dist/ActionConfirm-DJ91X3ml.js +236 -0
- package/dist/ActionFailure-ZgPt_3B-.js +37 -0
- package/dist/AgentChat-CRYai8ge.js +1062 -0
- package/dist/AppFormModal-D73ucaHK.js +4282 -0
- package/dist/AppListPage-D87piiOw.js +1364 -0
- package/dist/AskDrawer-BUMYsRnt.js +38 -0
- package/dist/ComputedView-CgYrDbx1.js +3221 -0
- package/dist/ConclusionApply-sjGfoEBY.js +153 -0
- package/dist/CypherEditor-lus6FA5L.js +485 -0
- package/dist/LandingList-6JI6864C.js +230 -0
- package/dist/MenuUnfoldOutlined-Cdg24l2h.js +27 -0
- package/dist/ModelTrial-ClHFGTpQ.js +359 -0
- package/dist/PageRenderer-DBd_g6mN.js +85480 -0
- package/dist/README-DjRyTQSR.js +76 -0
- package/dist/ScenarioApply-DtW_hh47.js +590 -0
- package/dist/SimulateForm-C-i08Jjd.js +153 -0
- package/dist/Subgraph-CnrkH9AN.js +32586 -0
- package/dist/WorkshopLabPage-DiVXQL9e.js +11364 -0
- package/dist/WorkshopRunPage-6hjRUf64.js +253 -0
- package/dist/abnfDiagram-WEYOIA3C-beRNhN3c.js +87 -0
- package/dist/action-type-tool.service-B2B74fKC.js +1060 -0
- package/dist/actionButton-DA5CNEzx.js +94 -0
- package/dist/actionButton.en-US-qjeqA7hs.js +94 -0
- package/dist/agentChat-EoDznd58.js +116 -0
- package/dist/agentChat.en-US-B6-pFd9Y.js +116 -0
- package/dist/alertList-DqditwM8.js +84 -0
- package/dist/alertList.en-US-BAXAgltP.js +84 -0
- package/dist/architectureDiagram-ZHVYKT53-DY2l1qxx.js +4779 -0
- package/dist/asOfSlider-QPvHWUMV.js +83 -0
- package/dist/asOfSlider.en-US-BI4jVfSn.js +83 -0
- package/dist/bkn-agent-execution.service-DVh-SHyl.js +205 -0
- package/dist/blockDiagram-RJAE7QA3-DR0mjN2h.js +1435 -0
- package/dist/c4Diagram-XDPPPE54-DH5zsGug.js +1518 -0
- package/dist/channel-B034hcOF.js +5 -0
- package/dist/china-C6m7zXIv.js +9 -0
- package/dist/chunk-2E7WHVMD-Ba3svxgx.js +664 -0
- package/dist/chunk-2Q5K7J3B-rT4eU6_y.js +15 -0
- package/dist/chunk-4EMNKR2T-C1kQZYHK.js +262 -0
- package/dist/chunk-55XCU76K-dcpLOktb.js +68 -0
- package/dist/chunk-5VM5RSS4-BdpQuzmO.js +19 -0
- package/dist/chunk-JWPE2WC7-CDBrSjU7.js +8 -0
- package/dist/chunk-VQ5W62QI-BiVKc40w.js +19 -0
- package/dist/chunk-XXDRQBXY-CPYrcdVW.js +8 -0
- package/dist/chunk-ZCHMQSOR-BG8OLpvb.js +451 -0
- package/dist/classDiagram-v2-4MYWR3UA-DqbpQpwI.js +1564 -0
- package/dist/component.d-DFoMKuUv.js +179 -0
- package/dist/cose-bilkent-JH36ORCC-CdXk4sPf.js +2609 -0
- package/dist/customComponents-DasaZ6pq.js +4 -0
- package/dist/customComponents.en-US-CkabuCXg.js +79 -0
- package/dist/customParseFormat-C0uLEpdq.js +182 -0
- package/dist/cynefin-EF2NZ3EQ-D7MVnMHu.js +21746 -0
- package/dist/cynefinDiagram-WF24UDRP-BYT_KpDL.js +299 -0
- package/dist/cytoscape.esm-BCV9V6aO.js +18760 -0
- package/dist/d3-scale-DA8IHmf0.js +1841 -0
- package/dist/dagre-NK4GIZVX-l-ghPdM8.js +2154 -0
- package/dist/dateRange-BbkLMg8L.js +79 -0
- package/dist/dateRange.en-US-CV12Q02G.js +79 -0
- package/dist/dayjs.min-DZ-YV8Mv.js +284 -0
- package/dist/diagram-CBK3MWTC-Bt3HiwvA.js +542 -0
- package/dist/diagram-I5XIIV2D-DcbqfBjx.js +150 -0
- package/dist/diagram-ODIL2UCW-9PC1n3n5.js +346 -0
- package/dist/diagram-PFBEJUXE-DGhr2kc7.js +478 -0
- package/dist/diagram-RJA3I4VV-DwzpOjZ_.js +219 -0
- package/dist/diagram-TYUNFSNR-B3Bd3TDU.js +2583 -0
- package/dist/dropdownFilter-DOi_8-ZT.js +76 -0
- package/dist/dropdownFilter.en-US-BiXpvXtF.js +76 -0
- package/dist/ebnfDiagram-V4P3TTPT-E5NN2oKc.js +109 -0
- package/dist/elk-QONTBCTQ-dFjcujl_.js +49170 -0
- package/dist/erDiagram-KYQIGQAA-BMrasBzB.js +1061 -0
- package/dist/eventList-CnsAwfDS.js +115 -0
- package/dist/eventList.en-US-Cof3rCLq.js +115 -0
- package/dist/eventReport-XS-HegnH.js +76 -0
- package/dist/eventReport.en-US-DTx4vzWT.js +76 -0
- package/dist/flowDiagram-IUGLLWBU-BGIBH0q0.js +1769 -0
- package/dist/ganttChart-DEeSvTJA.js +77 -0
- package/dist/ganttChart.en-US-SwRKrnoD.js +77 -0
- package/dist/ganttDiagram-R7GPNTJY-C0tb1Lpp.js +1741 -0
- package/dist/generateCypher-Ch9_lQa6.js +399 -0
- package/dist/gitGraphDiagram-PDYL7XHY-DBqcOa-c.js +815 -0
- package/dist/graph-CKJmgLki.js +1541 -0
- package/dist/index-BA-GzCXt.js +441 -0
- package/dist/infoDiagram-MVDRKAX5-Bwuki4JA.js +24 -0
- package/dist/ishikawaDiagram-HPEHV2GE-Dz4d6ygx.js +622 -0
- package/dist/journeyDiagram-BOSHW7O7-C99m34Bb.js +834 -0
- package/dist/kanban-definition-FNSA4HC5-mdqjODsT.js +724 -0
- package/dist/katex-BsrBVQKd.js +11314 -0
- package/dist/manifest-BjV1PJ6u.js +41 -0
- package/dist/mermaid.core-yQghUlIz.js +17642 -0
- package/dist/metricCards-CSb-_cT2.js +104 -0
- package/dist/metricCards.en-US-BLLhRsQU.js +104 -0
- package/dist/mindmap-definition-6OY57UG3-BZhO2wX4.js +834 -0
- package/dist/modelTrial-Bvb-RhGt.js +137 -0
- package/dist/modelTrial.en-US-DYcuor-G.js +137 -0
- package/dist/models-DekiCOuZ.js +6 -0
- package/dist/object-metric-numeric-vs3BeDkH.js +42 -0
- package/dist/object-metric.service-flZgBMRX.js +233 -0
- package/dist/objectDetail-SQUbp4Py.js +117 -0
- package/dist/objectDetail.en-US-DW3mlONM.js +117 -0
- package/dist/objectList-D99wPtJH.js +97 -0
- package/dist/objectList.en-US-PBBNyVLW.js +97 -0
- package/dist/objectTable-0jsFFMN3.js +127 -0
- package/dist/objectTable.en-US-yWEs8qc_.js +127 -0
- package/dist/pegDiagram-ECIUJNBX-BDa5RfZt.js +95 -0
- package/dist/pieDiagram-GNMPY74T-DNVtzXPv.js +165 -0
- package/dist/pivotTable-CHmQw18-.js +102 -0
- package/dist/pivotTable.en-US-B4uv4P08.js +102 -0
- package/dist/prompt-DYrjlEFr.js +373 -0
- package/dist/quadrantDiagram-D57K4MC3-vK0f2OvQ.js +1023 -0
- package/dist/railroadDiagram-Y72NRBL7-j6ZrTmRp.js +77 -0
- package/dist/regionMap-Cme-JyV_.js +128 -0
- package/dist/regionMap.en-US-Bwr2_p32.js +128 -0
- package/dist/requirementDiagram-EQYSW5RA-DgfEyljA.js +886 -0
- package/dist/sankeyDiagram-SY24JHO5-CImx-IX0.js +1160 -0
- package/dist/scenarioBar-BV43p7n-.js +122 -0
- package/dist/scenarioBar.en-US-5KqMQ2Bg.js +122 -0
- package/dist/scheduleGantt-CTYO-zYP.js +180 -0
- package/dist/scheduleGantt.en-US-hE7mvVUW.js +180 -0
- package/dist/searchBox-Ca7w0f_6.js +67 -0
- package/dist/searchBox.en-US-ArS_XBvB.js +67 -0
- package/dist/segmentedFilter-MhjVcWo0.js +80 -0
- package/dist/segmentedFilter.en-US-BxNrQO5T.js +80 -0
- package/dist/sequenceDiagram-BLEHNHQU-nWmjd1ci.js +2969 -0
- package/dist/sizeCapture-INFHLROL-D3jlbt7h.js +46 -0
- package/dist/stageChain-BxBafwjD.js +74 -0
- package/dist/stageChain.en-US-CP0G27n8.js +74 -0
- package/dist/stateDiagram-v2-A6IESKWZ-DG1ZetEu.js +1514 -0
- package/dist/subgraph-7n4SwliR.js +71 -0
- package/dist/subgraph.en-US-BNvY18IW.js +71 -0
- package/dist/swimlanes-B3ENRKFQ-cCmJE8AU.js +4991 -0
- package/dist/swimlanesDiagram-AYQRV4AK-CtuhyguU.js +14 -0
- package/dist/taskInbox-DGWYeI2b.js +118 -0
- package/dist/taskInbox.en-US-B-OzDmVl.js +118 -0
- package/dist/text-BqSVQKS6.js +78 -0
- package/dist/text.en-US-BhAxy_LE.js +78 -0
- package/dist/timeline-definition-JXYKGLGB-Cc-INsOv.js +1057 -0
- package/dist/trendChart-BjEeRS5_.js +135 -0
- package/dist/trendChart.en-US-BBGqWUKM.js +135 -0
- package/dist/useLabData-Df-jEHKs.js +20470 -0
- package/dist/usecaseDiagram-WPOLBNNX-r8wVjopm.js +7920 -0
- package/dist/vennDiagram-Q3Y3IDCW-BZiOcgrj.js +1579 -0
- package/dist/wardleyDiagram-IVAIDKWA-16jd07C_.js +675 -0
- package/dist/workshop-app-DnHNjBqy.js +86038 -0
- package/dist/workshop-app.css +1 -0
- package/dist/workshop-app.js +4 -0
- package/dist/world-Djau1JyJ.js +9 -0
- package/dist/xychartDiagram-4URNHDU4-C8DwWQNh.js +1460 -0
- package/dist-cli/workshop.js +340 -217
- package/example/host.js +109 -0
- package/example/index.html +93 -0
- package/example/server.mjs +237 -0
- package/index.d.ts +48 -0
- package/lib/validate.js +47 -1
- package/package.json +17 -5
- package/runtime/frame-runtime.js +13 -1
- package/workshop-component.js +32 -12
- package/workshop.js +2 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { O as q, L as F, Q as _ } from "./workshop-app-DnHNjBqy.js";
|
|
2
|
+
import { a6 as G, O as H, a7 as V, a8 as I, a9 as W, aa as K } from "./useLabData-Df-jEHKs.js";
|
|
3
|
+
import { f as C, M as z } from "./PageRenderer-DBd_g6mN.js";
|
|
4
|
+
import { u as B, g as Q, a as X, s as Z, f as ee, i as te, p as re, S as ne } from "./prompt-DYrjlEFr.js";
|
|
5
|
+
function oe(r, n) {
|
|
6
|
+
if (!Array.isArray(n)) throw new Error("patch 必须是数组");
|
|
7
|
+
const e = { value: structuredClone(r) };
|
|
8
|
+
for (const t of n)
|
|
9
|
+
switch (t?.op) {
|
|
10
|
+
case "add":
|
|
11
|
+
x(e, t.path, structuredClone(t.value));
|
|
12
|
+
break;
|
|
13
|
+
case "replace":
|
|
14
|
+
N(e, t.path), x(e, t.path, structuredClone(t.value));
|
|
15
|
+
break;
|
|
16
|
+
case "remove":
|
|
17
|
+
N(e, t.path);
|
|
18
|
+
break;
|
|
19
|
+
case "move":
|
|
20
|
+
x(e, t.path, N(e, t.from));
|
|
21
|
+
break;
|
|
22
|
+
case "test": {
|
|
23
|
+
const [o, s] = j(e, t.path), i = o[s];
|
|
24
|
+
if (JSON.stringify(i) !== JSON.stringify(t.value))
|
|
25
|
+
throw new Error(
|
|
26
|
+
`patch 校验不符:${t.path} 是 ${JSON.stringify(i)},不是 ${JSON.stringify(t.value)}`
|
|
27
|
+
);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
default:
|
|
31
|
+
throw new Error(`不支持的 patch 操作:${JSON.stringify(t)}`);
|
|
32
|
+
}
|
|
33
|
+
return e.value;
|
|
34
|
+
}
|
|
35
|
+
const se = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
36
|
+
function ae(r) {
|
|
37
|
+
if (typeof r != "string" || !r.startsWith("/")) throw new Error(`patch 路径无效:${r}`);
|
|
38
|
+
const n = r.slice(1).split("/").map((e) => e.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
39
|
+
if (n.some((e) => se.has(e))) throw new Error(`patch 路径无效:${r}`);
|
|
40
|
+
return n;
|
|
41
|
+
}
|
|
42
|
+
function j(r, n) {
|
|
43
|
+
const e = ae(n);
|
|
44
|
+
let t = r, o = "value";
|
|
45
|
+
for (const s of e) {
|
|
46
|
+
if (t = t[o], typeof t != "object" || t === null) throw new Error(`patch 路径不存在:${n}`);
|
|
47
|
+
o = s;
|
|
48
|
+
}
|
|
49
|
+
return [t, o];
|
|
50
|
+
}
|
|
51
|
+
function x(r, n, e) {
|
|
52
|
+
const [t, o] = j(r, n);
|
|
53
|
+
if (Array.isArray(t)) {
|
|
54
|
+
const s = o === "-" ? t.length : Number(o);
|
|
55
|
+
if (!Number.isInteger(s) || s < 0 || s > t.length)
|
|
56
|
+
throw new Error(`patch 下标越界:${n}`);
|
|
57
|
+
t.splice(s, 0, e);
|
|
58
|
+
} else
|
|
59
|
+
t[o] = e;
|
|
60
|
+
}
|
|
61
|
+
function N(r, n) {
|
|
62
|
+
const [e, t] = j(r, n);
|
|
63
|
+
if (Array.isArray(e)) {
|
|
64
|
+
const s = Number(t);
|
|
65
|
+
if (!Number.isInteger(s) || s < 0 || s >= e.length)
|
|
66
|
+
throw new Error(`patch 下标越界:${n}`);
|
|
67
|
+
return e.splice(s, 1)[0];
|
|
68
|
+
}
|
|
69
|
+
if (!(t in e)) throw new Error(`patch 路径不存在:${n}`);
|
|
70
|
+
const o = e[t];
|
|
71
|
+
return delete e[t], o;
|
|
72
|
+
}
|
|
73
|
+
const h = (r) => typeof r == "object" && r !== null && !Array.isArray(r);
|
|
74
|
+
function ie(r, n) {
|
|
75
|
+
const e = h(r) ? r : {}, t = h(n) ? Object.keys(n) : [], o = q.find(
|
|
76
|
+
(i) => t.length > 0 && t.every((a) => F[i].includes(a))
|
|
77
|
+
), s = q.includes(e.type) ? e.type : o ?? "dashboard";
|
|
78
|
+
return { ...z[s], ...e, type: s };
|
|
79
|
+
}
|
|
80
|
+
function ce(r, n) {
|
|
81
|
+
if (!h(r)) return r;
|
|
82
|
+
const e = {
|
|
83
|
+
variables: [],
|
|
84
|
+
...G(r),
|
|
85
|
+
apiVersion: H
|
|
86
|
+
};
|
|
87
|
+
if (!Array.isArray(e.pages) && h(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 a of ["version", "title", "layout", "regions", "detail"]) delete e[a];
|
|
98
|
+
}
|
|
99
|
+
Array.isArray(e.pages) && (e.pages = e.pages.map(
|
|
100
|
+
(a) => h(a) ? {
|
|
101
|
+
regions: {},
|
|
102
|
+
...a,
|
|
103
|
+
layout: ie(a.layout, a.regions)
|
|
104
|
+
} : a
|
|
105
|
+
));
|
|
106
|
+
const t = h(e.app) ? e.app : {}, o = Array.isArray(e.pages) && h(e.pages[0]) ? e.pages[0].title : void 0;
|
|
107
|
+
e.app = {
|
|
108
|
+
id: "app",
|
|
109
|
+
name: typeof o == "string" ? o : "应用",
|
|
110
|
+
...t
|
|
111
|
+
}, e.dependencies = { knowledgeNetwork: { id: n.id, name: n.name } };
|
|
112
|
+
const s = h(e.theme) ? e.theme : {}, i = C[typeof s.name == "string" ? s.name : ""] ?? C.default;
|
|
113
|
+
return e.theme = { ...i, ...s }, e;
|
|
114
|
+
}
|
|
115
|
+
function J(r) {
|
|
116
|
+
if (typeof r != "object" || r === null) return !1;
|
|
117
|
+
const n = r;
|
|
118
|
+
return n.spec !== void 0 || n.patch !== void 0 || "apiVersion" in n || "pages" in n;
|
|
119
|
+
}
|
|
120
|
+
class P extends Error {
|
|
121
|
+
constructor(n) {
|
|
122
|
+
super(n.join(";")), this.errors = n;
|
|
123
|
+
}
|
|
124
|
+
errors;
|
|
125
|
+
}
|
|
126
|
+
function le(r, n) {
|
|
127
|
+
return `${r?.scheduleModel ? `当前调度模型:
|
|
128
|
+
${JSON.stringify(r.scheduleModel)}
|
|
129
|
+
|
|
130
|
+
` : ""}用户对调度的描述:${n}
|
|
131
|
+
|
|
132
|
+
按“调度模型”一节只输出 {"scheduleModel": ..., "needs": [...]},不要输出 spec 或 patch。`;
|
|
133
|
+
}
|
|
134
|
+
function ue(r) {
|
|
135
|
+
if (typeof r != "object" || r === null || J(r)) return null;
|
|
136
|
+
const n = r.component;
|
|
137
|
+
if (typeof n != "object" || n === null) return null;
|
|
138
|
+
const { explicit: e, reason: t } = n;
|
|
139
|
+
return { explicit: e === !0, reason: typeof t == "string" ? t.trim() : "" };
|
|
140
|
+
}
|
|
141
|
+
const L = 16384;
|
|
142
|
+
function Y(r) {
|
|
143
|
+
return r.replace(/<think>[\s\S]*?<\/think>/g, "");
|
|
144
|
+
}
|
|
145
|
+
function pe(r) {
|
|
146
|
+
const n = Y(r), e = n.indexOf("{"), t = n.lastIndexOf("}");
|
|
147
|
+
if (e < 0 || t <= e) throw new Error("no JSON object");
|
|
148
|
+
return JSON.parse(n.slice(e, t + 1));
|
|
149
|
+
}
|
|
150
|
+
function de(r, n) {
|
|
151
|
+
if (typeof r != "object" || r === null) throw new Error("输出不是 JSON 对象");
|
|
152
|
+
const e = r;
|
|
153
|
+
if (e.patch !== void 0) {
|
|
154
|
+
if (!n) throw new Error("还没有页面,不能输出 patch,请输出完整的 spec");
|
|
155
|
+
return { mode: "patch", spec: oe(n, e.patch) };
|
|
156
|
+
}
|
|
157
|
+
return e.spec !== void 0 ? { mode: "spec", spec: e.spec } : { mode: "spec", spec: r };
|
|
158
|
+
}
|
|
159
|
+
function fe(r, n) {
|
|
160
|
+
if (typeof r != "object" || r === null || Array.isArray(r)) return r;
|
|
161
|
+
const e = { ...r };
|
|
162
|
+
return delete e.scheduleModel, n?.scheduleModel ? { ...e, scheduleModel: n.scheduleModel } : e;
|
|
163
|
+
}
|
|
164
|
+
function me(r, n) {
|
|
165
|
+
const e = (o) => (o?.pages ?? []).flatMap(
|
|
166
|
+
(s) => Object.values(s.regions).flat().map((i) => i?.type)
|
|
167
|
+
), t = new Set(e(r));
|
|
168
|
+
return [
|
|
169
|
+
...new Set(
|
|
170
|
+
e(n).filter(
|
|
171
|
+
(o) => typeof o == "string" && !t.has(o) && ne.includes(o)
|
|
172
|
+
)
|
|
173
|
+
)
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
async function be(r) {
|
|
177
|
+
const {
|
|
178
|
+
model: n,
|
|
179
|
+
kn: e,
|
|
180
|
+
current: t,
|
|
181
|
+
instruction: o,
|
|
182
|
+
target: s,
|
|
183
|
+
signal: i,
|
|
184
|
+
maxAttempts: a = 3,
|
|
185
|
+
onStep: d,
|
|
186
|
+
scenarios: S = !0,
|
|
187
|
+
ruleTools: g,
|
|
188
|
+
scheduleOnly: c = !1
|
|
189
|
+
} = r, f = performance.now(), w = [
|
|
190
|
+
{
|
|
191
|
+
role: "user",
|
|
192
|
+
content: c ? le(t, o) : B(t, o, s?.note)
|
|
193
|
+
}
|
|
194
|
+
];
|
|
195
|
+
let p = [], l = t;
|
|
196
|
+
const m = c ? `${o} scheduleGantt` : o, y = await Q(t, m, s ? [s.type] : []), O = c || X(t, m).includes("scheduleGantt"), k = c || g !== void 0 && O, b = Z(e, ee(e, t, o), y, {
|
|
197
|
+
scenarios: S,
|
|
198
|
+
...g ? { ruleTools: g } : c ? { ruleTools: [] } : {},
|
|
199
|
+
scheduling: O,
|
|
200
|
+
newComponents: !c && t !== null
|
|
201
|
+
});
|
|
202
|
+
let A = c;
|
|
203
|
+
for (let E = 1; E <= a; E++) {
|
|
204
|
+
d?.({ kind: "generating", attempt: E });
|
|
205
|
+
const { text: M } = await _({
|
|
206
|
+
model: n,
|
|
207
|
+
system: b,
|
|
208
|
+
messages: w,
|
|
209
|
+
maxOutputTokens: L,
|
|
210
|
+
maxRetries: 0,
|
|
211
|
+
abortSignal: i
|
|
212
|
+
});
|
|
213
|
+
try {
|
|
214
|
+
const u = pe(M), v = !c && t ? ue(u) : null;
|
|
215
|
+
if (v)
|
|
216
|
+
return d?.({ kind: "valid", mode: "component" }), { ok: !0, component: v, attempts: E, ms: performance.now() - f };
|
|
217
|
+
if (c || k && te(u) && !J(u)) {
|
|
218
|
+
A = !0;
|
|
219
|
+
const T = re(u, e, g ?? [], t?.scheduleModel);
|
|
220
|
+
if (T.ok)
|
|
221
|
+
return d?.({ kind: "valid", mode: "schedule" }), {
|
|
222
|
+
ok: !0,
|
|
223
|
+
schedule: T.proposal,
|
|
224
|
+
attempts: E,
|
|
225
|
+
ms: performance.now() - f
|
|
226
|
+
};
|
|
227
|
+
throw new P(T.errors);
|
|
228
|
+
}
|
|
229
|
+
A = !1;
|
|
230
|
+
const { mode: U, spec: D } = de(u, l);
|
|
231
|
+
l = ce(fe(D, t), e);
|
|
232
|
+
const $ = V(l, e), R = S ? [] : me(t, $.ok ? $.app : null);
|
|
233
|
+
if ($.ok && R.length > 0)
|
|
234
|
+
p = [
|
|
235
|
+
`方案推演需要企业版,当前环境不提供:去掉新加的方案类组件(${R.join("、")})`
|
|
236
|
+
];
|
|
237
|
+
else {
|
|
238
|
+
if ($.ok)
|
|
239
|
+
return d?.({ kind: "valid", mode: U }), {
|
|
240
|
+
ok: !0,
|
|
241
|
+
spec: $.app,
|
|
242
|
+
attempts: E,
|
|
243
|
+
ms: performance.now() - f
|
|
244
|
+
};
|
|
245
|
+
p = $.errors;
|
|
246
|
+
}
|
|
247
|
+
} catch (u) {
|
|
248
|
+
p = u instanceof P ? u.errors : [u instanceof Error ? u.message : String(u)];
|
|
249
|
+
}
|
|
250
|
+
d?.({ kind: "invalid", errors: p }), w.push(
|
|
251
|
+
{ role: "assistant", content: M },
|
|
252
|
+
{
|
|
253
|
+
role: "user",
|
|
254
|
+
content: A ? `上次输出的调度模型答案不合法:
|
|
255
|
+
- ${p.slice(0, 20).join(`
|
|
256
|
+
- `)}
|
|
257
|
+
请修正后重新输出 {"scheduleModel": ..., "needs": [...]}。` : `上次输出不合法:
|
|
258
|
+
- ${p.slice(0, 20).join(`
|
|
259
|
+
- `)}
|
|
260
|
+
请修正:可以输出完整的 {"spec": ...}${l ? ',或输出相对你上次结果的 {"patch": [...]}' : ""}。`
|
|
261
|
+
}
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
ok: !1,
|
|
266
|
+
errors: p,
|
|
267
|
+
attempts: a,
|
|
268
|
+
ms: performance.now() - f
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function ye(r) {
|
|
272
|
+
const n = Object.values(r.objectTypes).filter((t) => !K(t.id)).map(
|
|
273
|
+
(t) => `- ${t.id}(${t.name})主键 ${t.primaryKeys.join("、") || "无"}
|
|
274
|
+
${t.properties.map((o) => `${o.name}:${o.type}(${o.label})`).join(",")}`
|
|
275
|
+
), e = r.relations.map(
|
|
276
|
+
(t) => `- ${t.id}(${t.name}):(${t.source})-[:${t.id}]->(${t.target})`
|
|
277
|
+
);
|
|
278
|
+
return `对象类(id(名称)、主键、属性名:类型(显示名)):
|
|
279
|
+
${n.join(`
|
|
280
|
+
`)}
|
|
281
|
+
|
|
282
|
+
关系类(方向从左到右):
|
|
283
|
+
${e.join(`
|
|
284
|
+
`)}`;
|
|
285
|
+
}
|
|
286
|
+
function he(r, n) {
|
|
287
|
+
const e = n.filter((t) => W.includes(t.kind));
|
|
288
|
+
return `你为业务应用的数据源编写只读 Cypher 查询,在知识网络「${r.name}」上运行。
|
|
289
|
+
|
|
290
|
+
规则:
|
|
291
|
+
- 只写一条只读查询:MATCH … [WHERE …] [WITH …] RETURN … [ORDER BY …] LIMIT n。不能用 CREATE、MERGE、SET、DELETE、REMOVE、CALL。
|
|
292
|
+
- 标签、关系类型和属性名都用下面的 id,并用反引号括起来,如 (a:\`对象类id\`)-[:\`关系id\`]->(b:\`对象类id\`)、a.\`属性名\`;关系方向必须与清单一致,反向时写 <-[:…]-。
|
|
293
|
+
- 属性名只能用清单里该对象类的属性,原样写,不要猜。
|
|
294
|
+
- RETURN 的每一列都用 AS 起简短的英文别名(字母开头,可含字母、数字、下划线),别名就是数据源的列名。
|
|
295
|
+
- 要能当主键的列:通常返回主对象的主键,每行唯一。
|
|
296
|
+
- 可以用 count、sum、avg、min、max 聚合;聚合时非聚合列就是分组键。
|
|
297
|
+
- 结果最多 10000 行,一定要写 LIMIT。
|
|
298
|
+
- 需要跟随页面变量时,用 $变量名 作为参数,只能用下面列出的变量;不要把变量值直接写进查询。
|
|
299
|
+
- 日期属性(date、datetime、timestamp)通常以 ISO 文本存储,可与 'YYYY-MM-DD' 或日期变量比较大小;查询结果为空时,可能是这个属性的存储格式不同,在说明里提一句。
|
|
300
|
+
|
|
301
|
+
页面变量(可作 $参数):
|
|
302
|
+
${e.map((t) => `- $${t.name}:${t.label}(${t.kind})`).join(`
|
|
303
|
+
`) || "(无)"}
|
|
304
|
+
|
|
305
|
+
${ye(r)}
|
|
306
|
+
|
|
307
|
+
只输出 JSON:{"query": "…", "explanation": "一句话说明经过哪些关系、怎么聚合"}。`;
|
|
308
|
+
}
|
|
309
|
+
function ge(r) {
|
|
310
|
+
const n = Y(r), e = n.match(/\{[\s\S]*\}/);
|
|
311
|
+
if (e)
|
|
312
|
+
try {
|
|
313
|
+
const o = JSON.parse(e[0]);
|
|
314
|
+
if (typeof o.query == "string" && o.query.trim())
|
|
315
|
+
return {
|
|
316
|
+
query: o.query.trim(),
|
|
317
|
+
explanation: typeof o.explanation == "string" ? o.explanation : ""
|
|
318
|
+
};
|
|
319
|
+
} catch {
|
|
320
|
+
}
|
|
321
|
+
const t = n.match(/```(?:cypher)?\s*([\s\S]*?)```/);
|
|
322
|
+
if (t) return { query: t[1].trim(), explanation: "" };
|
|
323
|
+
throw new Error("回复里没有找到查询");
|
|
324
|
+
}
|
|
325
|
+
async function Ae(r) {
|
|
326
|
+
const { model: n, kn: e, variables: t, values: o, instruction: s, current: i, query: a, signal: d, onStep: S } = r, g = r.maxAttempts ?? 3, c = [
|
|
327
|
+
{
|
|
328
|
+
role: "user",
|
|
329
|
+
content: i?.trim() ? `当前查询:
|
|
330
|
+
${i}
|
|
331
|
+
|
|
332
|
+
修改要求:${s}` : s
|
|
333
|
+
}
|
|
334
|
+
];
|
|
335
|
+
let f = { query: "", error: "" };
|
|
336
|
+
for (let w = 1; w <= g; w++) {
|
|
337
|
+
S?.({ kind: "generating", attempt: w });
|
|
338
|
+
const { text: p } = await _({
|
|
339
|
+
model: n,
|
|
340
|
+
system: he(e, t),
|
|
341
|
+
messages: c,
|
|
342
|
+
maxOutputTokens: L,
|
|
343
|
+
maxRetries: 0,
|
|
344
|
+
abortSignal: d
|
|
345
|
+
});
|
|
346
|
+
let l = "";
|
|
347
|
+
try {
|
|
348
|
+
const m = ge(p);
|
|
349
|
+
l = m.query;
|
|
350
|
+
const y = I(l).filter(
|
|
351
|
+
(k) => !t.some((b) => b.name === k)
|
|
352
|
+
);
|
|
353
|
+
if (y.length > 0)
|
|
354
|
+
throw new Error(`参数 ${y.map((k) => `$${k}`).join("、")} 不是页面变量`);
|
|
355
|
+
S?.({ kind: "running", query: l });
|
|
356
|
+
const O = await a(l, we(l, o), d);
|
|
357
|
+
return {
|
|
358
|
+
ok: !0,
|
|
359
|
+
query: l,
|
|
360
|
+
explanation: m.explanation,
|
|
361
|
+
result: O,
|
|
362
|
+
attempts: w
|
|
363
|
+
};
|
|
364
|
+
} catch (m) {
|
|
365
|
+
if (d?.aborted) throw m;
|
|
366
|
+
const y = Se(m);
|
|
367
|
+
f = { query: l, error: y }, S?.({ kind: "failed", error: y }), c.push(
|
|
368
|
+
{ role: "assistant", content: p },
|
|
369
|
+
{
|
|
370
|
+
role: "user",
|
|
371
|
+
content: `运行失败:${y}
|
|
372
|
+
请对照对象类、属性和关系方向修正,仍只输出 JSON。`
|
|
373
|
+
}
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return { ok: !1, error: f.error, query: f.query, attempts: g };
|
|
378
|
+
}
|
|
379
|
+
function we(r, n) {
|
|
380
|
+
return Object.fromEntries(
|
|
381
|
+
I(r).map((e) => {
|
|
382
|
+
const t = n[e];
|
|
383
|
+
return Array.isArray(t) ? [e, t.map(String)] : [e, t == null ? null : String(t)];
|
|
384
|
+
})
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
function Se(r) {
|
|
388
|
+
const n = r.response?.data;
|
|
389
|
+
return n && (typeof n.details == "string" || typeof n.description == "string") ? [n.description, n.details].filter((e) => typeof e == "string").join(":") : r instanceof Error ? r.message : String(r);
|
|
390
|
+
}
|
|
391
|
+
export {
|
|
392
|
+
L as M,
|
|
393
|
+
be as a,
|
|
394
|
+
ye as d,
|
|
395
|
+
Se as e,
|
|
396
|
+
Ae as g,
|
|
397
|
+
we as p,
|
|
398
|
+
Y as w
|
|
399
|
+
};
|