@openbkn/workshop 0.2.2 → 0.3.0-rc.1

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 (96) hide show
  1. package/README.md +1 -1
  2. package/dist/{ActionConfirm-DJ91X3ml.js → ActionConfirm-BX1dlrAM.js} +5 -5
  3. package/dist/{ActionFailure-ZgPt_3B-.js → ActionFailure-xcSfKJYC.js} +2 -2
  4. package/dist/{AgentChat-CRYai8ge.js → AgentChat-DHdX_6W7.js} +407 -383
  5. package/dist/AppListPage-DsUvFo6B.js +1549 -0
  6. package/dist/{AskDrawer-BUMYsRnt.js → AskDrawer-j-CR4yXP.js} +4 -4
  7. package/dist/{ComputedView-CgYrDbx1.js → ComputedView-dWFlHngu.js} +1035 -1016
  8. package/dist/{ConclusionApply-sjGfoEBY.js → ConclusionApply-BAoZpxl-.js} +4 -4
  9. package/dist/{CypherEditor-lus6FA5L.js → CypherEditor-CZ5Z4SGH.js} +47 -47
  10. package/dist/{LandingList-6JI6864C.js → LandingList-BUO6-at_.js} +5 -5
  11. package/dist/{MenuUnfoldOutlined-Cdg24l2h.js → MenuUnfoldOutlined-DAeIeIap.js} +3 -3
  12. package/dist/{ModelTrial-ClHFGTpQ.js → ModelTrial-C7XvLVY7.js} +4 -4
  13. package/dist/{PageRenderer-DBd_g6mN.js → PageRenderer-CkmvW4aO.js} +21264 -20549
  14. package/dist/{ScenarioApply-DtW_hh47.js → ScenarioApply-COdlyvrC.js} +6 -6
  15. package/dist/{SimulateForm-C-i08Jjd.js → SimulateForm-B_9laTIl.js} +4 -4
  16. package/dist/{Subgraph-CnrkH9AN.js → Subgraph-CDY3wvCA.js} +3 -3
  17. package/dist/WorkshopLabPage-BtYnBpk4.js +12020 -0
  18. package/dist/{WorkshopRunPage-6hjRUf64.js → WorkshopRunPage-DHMJ3b8k.js} +24 -24
  19. package/dist/{abnfDiagram-WEYOIA3C-beRNhN3c.js → abnfDiagram-WEYOIA3C-Blje2Kbf.js} +3 -3
  20. package/dist/{action-type-tool.service-B2B74fKC.js → action-type-tool.service-BN-W_Az_.js} +1 -1
  21. package/dist/{architectureDiagram-ZHVYKT53-DY2l1qxx.js → architectureDiagram-ZHVYKT53-B_FkRXc3.js} +3 -3
  22. package/dist/{bkn-agent-execution.service-DVh-SHyl.js → bkn-agent-execution.service-CJalMVIc.js} +1 -1
  23. package/dist/{blockDiagram-RJAE7QA3-DR0mjN2h.js → blockDiagram-RJAE7QA3-CYJLthoI.js} +3 -3
  24. package/dist/{c4Diagram-XDPPPE54-DH5zsGug.js → c4Diagram-XDPPPE54-CmMaN3M4.js} +2 -2
  25. package/dist/{channel-B034hcOF.js → channel-Dp24Bgua.js} +1 -1
  26. package/dist/{chunk-2E7WHVMD-Ba3svxgx.js → chunk-2E7WHVMD-DrnpfYKB.js} +1 -1
  27. package/dist/{chunk-2Q5K7J3B-rT4eU6_y.js → chunk-2Q5K7J3B-BXqKcHlQ.js} +1 -1
  28. package/dist/{chunk-4EMNKR2T-C1kQZYHK.js → chunk-4EMNKR2T-DYgY_0_y.js} +1 -1
  29. package/dist/{chunk-55XCU76K-dcpLOktb.js → chunk-55XCU76K-Bja7bE8g.js} +1 -1
  30. package/dist/{chunk-5VM5RSS4-BdpQuzmO.js → chunk-5VM5RSS4-CGTnbRRi.js} +1 -1
  31. package/dist/{chunk-JWPE2WC7-CDBrSjU7.js → chunk-JWPE2WC7-2AyjxdJR.js} +1 -1
  32. package/dist/{chunk-VQ5W62QI-BiVKc40w.js → chunk-VQ5W62QI-B3PGCKOg.js} +1 -1
  33. package/dist/{chunk-XXDRQBXY-CPYrcdVW.js → chunk-XXDRQBXY-RrIsI-B5.js} +1 -1
  34. package/dist/{chunk-ZCHMQSOR-BG8OLpvb.js → chunk-ZCHMQSOR-COJTBW1i.js} +2 -2
  35. package/dist/{classDiagram-v2-4MYWR3UA-DqbpQpwI.js → classDiagram-v2-4MYWR3UA-DolLxH6t.js} +5 -5
  36. package/dist/{cose-bilkent-JH36ORCC-CdXk4sPf.js → cose-bilkent-JH36ORCC-DMSYgFxc.js} +2 -2
  37. package/dist/customComponents-DasaZ6pq.js +1 -1
  38. package/dist/customComponents.en-US-CkabuCXg.js +1 -1
  39. package/dist/{customParseFormat-C0uLEpdq.js → customParseFormat-C9WAjjqH.js} +1 -1
  40. package/dist/{cynefinDiagram-WF24UDRP-BYT_KpDL.js → cynefinDiagram-WF24UDRP-DrksRWCn.js} +2 -2
  41. package/dist/{dagre-NK4GIZVX-l-ghPdM8.js → dagre-NK4GIZVX-CFRT2dAc.js} +2 -2
  42. package/dist/{dayjs.min-DZ-YV8Mv.js → dayjs.min-CziT8yW9.js} +1 -1
  43. package/dist/{diagram-CBK3MWTC-Bt3HiwvA.js → diagram-CBK3MWTC-DzZ_sQCl.js} +3 -3
  44. package/dist/{diagram-I5XIIV2D-DcbqfBjx.js → diagram-I5XIIV2D-RYNBUOF4.js} +2 -2
  45. package/dist/{diagram-ODIL2UCW-9PC1n3n5.js → diagram-ODIL2UCW-DqJETE9R.js} +3 -3
  46. package/dist/{diagram-PFBEJUXE-DGhr2kc7.js → diagram-PFBEJUXE-BekIE7hh.js} +2 -2
  47. package/dist/{diagram-RJA3I4VV-DwzpOjZ_.js → diagram-RJA3I4VV-DAIwlMxl.js} +2 -2
  48. package/dist/{diagram-TYUNFSNR-B3Bd3TDU.js → diagram-TYUNFSNR-CLJ0Ou9i.js} +6 -6
  49. package/dist/{ebnfDiagram-V4P3TTPT-E5NN2oKc.js → ebnfDiagram-V4P3TTPT-CRs8ppfT.js} +3 -3
  50. package/dist/{elk-QONTBCTQ-dFjcujl_.js → elk-QONTBCTQ-Bqoh6AYY.js} +5 -5
  51. package/dist/{erDiagram-KYQIGQAA-BMrasBzB.js → erDiagram-KYQIGQAA-BSp8Z7uQ.js} +4 -4
  52. package/dist/{flowDiagram-IUGLLWBU-BGIBH0q0.js → flowDiagram-IUGLLWBU-WKILTCDc.js} +7 -7
  53. package/dist/{ganttDiagram-R7GPNTJY-C0tb1Lpp.js → ganttDiagram-R7GPNTJY-CaTn_Mmr.js} +4 -4
  54. package/dist/generateCypher-BE_4YCWB.js +1032 -0
  55. package/dist/{gitGraphDiagram-PDYL7XHY-DBqcOa-c.js → gitGraphDiagram-PDYL7XHY-DGPs-RF6.js} +3 -3
  56. package/dist/{infoDiagram-MVDRKAX5-Bwuki4JA.js → infoDiagram-MVDRKAX5-HIQg7U3R.js} +1 -1
  57. package/dist/{ishikawaDiagram-HPEHV2GE-Dz4d6ygx.js → ishikawaDiagram-HPEHV2GE-C84x8n2j.js} +2 -2
  58. package/dist/{journeyDiagram-BOSHW7O7-C99m34Bb.js → journeyDiagram-BOSHW7O7-CvYDNxSY.js} +4 -4
  59. package/dist/{kanban-definition-FNSA4HC5-mdqjODsT.js → kanban-definition-FNSA4HC5-B586ryFD.js} +2 -2
  60. package/dist/{mermaid.core-yQghUlIz.js → mermaid.core-3J01L12Z.js} +5803 -5740
  61. package/dist/{mindmap-definition-6OY57UG3-BZhO2wX4.js → mindmap-definition-6OY57UG3-Donc6BMy.js} +3 -3
  62. package/dist/{models-DekiCOuZ.js → models-Rf3LB8wS.js} +1 -1
  63. package/dist/{object-metric-numeric-vs3BeDkH.js → object-metric-numeric-BcgaJ6EW.js} +1 -1
  64. package/dist/{object-metric.service-flZgBMRX.js → object-metric.service-CKiaFYcp.js} +2 -2
  65. package/dist/{pegDiagram-ECIUJNBX-BDa5RfZt.js → pegDiagram-ECIUJNBX-CYVi7x6D.js} +3 -3
  66. package/dist/{pieDiagram-GNMPY74T-DNVtzXPv.js → pieDiagram-GNMPY74T-4iWKYTTS.js} +2 -2
  67. package/dist/{prompt-DYrjlEFr.js → prompt-BQzBLrua.js} +110 -100
  68. package/dist/{quadrantDiagram-D57K4MC3-vK0f2OvQ.js → quadrantDiagram-D57K4MC3-Bm6Cyi1I.js} +1 -1
  69. package/dist/{railroadDiagram-Y72NRBL7-j6ZrTmRp.js → railroadDiagram-Y72NRBL7-Du6iN-Jz.js} +3 -3
  70. package/dist/{requirementDiagram-EQYSW5RA-DgfEyljA.js → requirementDiagram-EQYSW5RA-BGxpuSlc.js} +3 -3
  71. package/dist/{sankeyDiagram-SY24JHO5-CImx-IX0.js → sankeyDiagram-SY24JHO5-CsHmu__D.js} +2 -2
  72. package/dist/{sequenceDiagram-BLEHNHQU-nWmjd1ci.js → sequenceDiagram-BLEHNHQU-DBNi943L.js} +3 -3
  73. package/dist/{sizeCapture-INFHLROL-D3jlbt7h.js → sizeCapture-INFHLROL-CcGr2ilA.js} +1 -1
  74. package/dist/{stateDiagram-v2-A6IESKWZ-DG1ZetEu.js → stateDiagram-v2-A6IESKWZ-C78tVzaF.js} +4 -4
  75. package/dist/{swimlanes-B3ENRKFQ-cCmJE8AU.js → swimlanes-B3ENRKFQ-BROc4LGM.js} +3 -3
  76. package/dist/{swimlanesDiagram-AYQRV4AK-CtuhyguU.js → swimlanesDiagram-AYQRV4AK-C0RDY4m2.js} +3 -3
  77. package/dist/{text-BqSVQKS6.js → text-CzC6K33E.js} +7 -3
  78. package/dist/{text.en-US-BhAxy_LE.js → text.en-US-D8mxBP0p.js} +6 -2
  79. package/dist/{timeline-definition-JXYKGLGB-Cc-INsOv.js → timeline-definition-JXYKGLGB-C6WGe4xl.js} +1 -1
  80. package/dist/toolMatchLines-DrXpUwcl.js +4675 -0
  81. package/dist/{useLabData-Df-jEHKs.js → useLabData-B-3UW8zF.js} +8008 -7251
  82. package/dist/{usecaseDiagram-WPOLBNNX-r8wVjopm.js → usecaseDiagram-WPOLBNNX-yMP7SDIg.js} +3 -3
  83. package/dist/{vennDiagram-Q3Y3IDCW-BZiOcgrj.js → vennDiagram-Q3Y3IDCW-bZW2LzBB.js} +2 -2
  84. package/dist/{wardleyDiagram-IVAIDKWA-16jd07C_.js → wardleyDiagram-IVAIDKWA-DBbog93x.js} +2 -2
  85. package/dist/{workshop-app-DnHNjBqy.js → workshop-app-ByYXbgcn.js} +5060 -4721
  86. package/dist/workshop-app.css +1 -1
  87. package/dist/workshop-app.js +1 -1
  88. package/dist/{xychartDiagram-4URNHDU4-C8DwWQNh.js → xychartDiagram-4URNHDU4-CVLJNXOt.js} +1 -1
  89. package/dist-cli/workshop.js +182 -140
  90. package/package.json +1 -1
  91. package/skill/SKILL.en-US.md +5 -0
  92. package/skill/SKILL.md +3 -0
  93. package/dist/AppFormModal-D73ucaHK.js +0 -4282
  94. package/dist/AppListPage-D87piiOw.js +0 -1364
  95. package/dist/WorkshopLabPage-DiVXQL9e.js +0 -11364
  96. package/dist/generateCypher-Ch9_lQa6.js +0 -399
@@ -1,399 +0,0 @@
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
- };