@freecallai/pro 0.0.0-stage → 0.0.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 (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -2
  3. package/dist/FkpRichText.vue_vue_type_script_setup_true_lang-DnknqQTh.js +4115 -0
  4. package/dist/KnowledgeArea-OPR7smbt.js +923 -0
  5. package/dist/ToolForm-CWpUIVTl.js +185 -0
  6. package/dist/choice-DDg5gNtS.js +29 -0
  7. package/dist/guard-BCatAeT4.js +749 -0
  8. package/dist/index-5a9mHHzg.js +41 -0
  9. package/dist/index-BsQLwz91.js +5 -0
  10. package/dist/index-CJlAseSN.js +15 -0
  11. package/dist/index-CzpY61Qj.js +6 -0
  12. package/dist/index-D8bcFtWR.js +6 -0
  13. package/dist/index-DOEijEGU.js +49 -0
  14. package/dist/index-DSgEWJGP.js +6 -0
  15. package/dist/index-DxxX09iY.js +6 -0
  16. package/dist/index-nnvfy5q0.js +31 -0
  17. package/dist/index-urNonkMH.js +6 -0
  18. package/dist/index-xAjlBylT.js +5 -0
  19. package/dist/index.js +16 -0
  20. package/dist/inline-TT_dl8Y3.js +17 -0
  21. package/dist/knowledge-BZCmalF_.js +6 -0
  22. package/dist/knowledge-DnYGicjn.js +13 -0
  23. package/dist/media-extensions-ZoxmhIhH.js +276 -0
  24. package/dist/media-migration-CGOFwdYm.js +59 -0
  25. package/dist/media-upload-Dx45yv6a.js +69 -0
  26. package/dist/operations-JgnjGx3H.js +19 -0
  27. package/dist/question-D1--acV8.js +10 -0
  28. package/dist/question-DGC6JHy5.js +6 -0
  29. package/dist/rich-text/index.js +224 -0
  30. package/dist/rich-text/legacy-converter/index.js +485 -0
  31. package/dist/selection-state-D47jhx0U.js +20 -0
  32. package/dist/state-KfOqha3d.js +16 -0
  33. package/dist/style.css +1 -0
  34. package/dist/types/index.d.ts +10 -0
  35. package/dist/types/rich-text/FkpRichText.vue.d.ts +242 -0
  36. package/dist/types/rich-text/MediaView.vue.d.ts +92 -0
  37. package/dist/types/rich-text/__demo__/conversion-fixtures.d.ts +35 -0
  38. package/dist/types/rich-text/config/catalog.d.ts +3 -0
  39. package/dist/types/rich-text/config/descriptor.d.ts +58 -0
  40. package/dist/types/rich-text/config/media-options.d.ts +6 -0
  41. package/dist/types/rich-text/config/resolve.d.ts +17 -0
  42. package/dist/types/rich-text/config/selection-options.d.ts +6 -0
  43. package/dist/types/rich-text/extensions.d.ts +6 -0
  44. package/dist/types/rich-text/index.d.ts +17 -0
  45. package/dist/types/rich-text/legacy-converter/index.d.ts +45 -0
  46. package/dist/types/rich-text/media-extensions.d.ts +4 -0
  47. package/dist/types/rich-text/media-id.d.ts +2 -0
  48. package/dist/types/rich-text/model/agent-context.d.ts +7 -0
  49. package/dist/types/rich-text/model/capability-diff.d.ts +14 -0
  50. package/dist/types/rich-text/model/condition-contract.d.ts +10 -0
  51. package/dist/types/rich-text/model/convert.d.ts +6 -0
  52. package/dist/types/rich-text/model/guard.d.ts +7 -0
  53. package/dist/types/rich-text/model/json-value.d.ts +2 -0
  54. package/dist/types/rich-text/model/media-migration.d.ts +8 -0
  55. package/dist/types/rich-text/model/node-contract.d.ts +10 -0
  56. package/dist/types/rich-text/model/node-identity.d.ts +8 -0
  57. package/dist/types/rich-text/model/persistence-contract.d.ts +25 -0
  58. package/dist/types/rich-text/model/preview.d.ts +2 -0
  59. package/dist/types/rich-text/model/question-text.d.ts +15 -0
  60. package/dist/types/rich-text/model/reasoning-context.d.ts +24 -0
  61. package/dist/types/rich-text/model/scene-snapshot.d.ts +4 -0
  62. package/dist/types/rich-text/model/validate.d.ts +19 -0
  63. package/dist/types/rich-text/model/web-url.d.ts +2 -0
  64. package/dist/types/rich-text/plugins/agentSelect/descriptor.d.ts +2 -0
  65. package/dist/types/rich-text/plugins/attribute/descriptor.d.ts +2 -0
  66. package/dist/types/rich-text/plugins/attribute/index.d.ts +2 -0
  67. package/dist/types/rich-text/plugins/block.d.ts +3 -0
  68. package/dist/types/rich-text/plugins/choice.d.ts +4 -0
  69. package/dist/types/rich-text/plugins/image/descriptor.d.ts +2 -0
  70. package/dist/types/rich-text/plugins/image/index.d.ts +2 -0
  71. package/dist/types/rich-text/plugins/inline.d.ts +3 -0
  72. package/dist/types/rich-text/plugins/media-upload.d.ts +3 -0
  73. package/dist/types/rich-text/plugins/memory/descriptor.d.ts +2 -0
  74. package/dist/types/rich-text/plugins/memory/index.d.ts +2 -0
  75. package/dist/types/rich-text/plugins/operations.d.ts +86 -0
  76. package/dist/types/rich-text/plugins/originalReply/descriptor.d.ts +2 -0
  77. package/dist/types/rich-text/plugins/originalReply/knowledge.d.ts +2 -0
  78. package/dist/types/rich-text/plugins/originalReply/question.d.ts +2 -0
  79. package/dist/types/rich-text/plugins/reasoningPolish/descriptor.d.ts +2 -0
  80. package/dist/types/rich-text/plugins/reasoningPolish/index.d.ts +3 -0
  81. package/dist/types/rich-text/plugins/reasoningTemplate/descriptor.d.ts +2 -0
  82. package/dist/types/rich-text/plugins/reasoningTemplate/index.d.ts +3 -0
  83. package/dist/types/rich-text/plugins/registry.d.ts +14 -0
  84. package/dist/types/rich-text/plugins/selection-state.d.ts +4 -0
  85. package/dist/types/rich-text/plugins/separator/descriptor.d.ts +2 -0
  86. package/dist/types/rich-text/plugins/separator/index.d.ts +2 -0
  87. package/dist/types/rich-text/plugins/state.d.ts +3 -0
  88. package/dist/types/rich-text/plugins/tagged/descriptor.d.ts +2 -0
  89. package/dist/types/rich-text/plugins/tagged/index.d.ts +2 -0
  90. package/dist/types/rich-text/plugins/ticket/descriptor.d.ts +2 -0
  91. package/dist/types/rich-text/plugins/ticket/index.d.ts +2 -0
  92. package/dist/types/rich-text/plugins/todo/descriptor.d.ts +2 -0
  93. package/dist/types/rich-text/plugins/todo/knowledge.d.ts +2 -0
  94. package/dist/types/rich-text/plugins/todo/question.d.ts +2 -0
  95. package/dist/types/rich-text/plugins/tool/descriptor.d.ts +2 -0
  96. package/dist/types/rich-text/plugins/tool/index.d.ts +2 -0
  97. package/dist/types/rich-text/plugins/tool/operations.d.ts +4 -0
  98. package/dist/types/rich-text/plugins/tool/presentation.d.ts +7 -0
  99. package/dist/types/rich-text/plugins/variable/descriptor.d.ts +2 -0
  100. package/dist/types/rich-text/plugins/variable/index.d.ts +2 -0
  101. package/dist/types/rich-text/plugins/video/descriptor.d.ts +2 -0
  102. package/dist/types/rich-text/plugins/video/index.d.ts +2 -0
  103. package/dist/types/rich-text/public/types.d.ts +588 -0
  104. package/dist/types/rich-text/runtime/action-ports.d.ts +15 -0
  105. package/dist/types/rich-text/runtime/media-state.d.ts +6 -0
  106. package/dist/types/rich-text/runtime/media-target.d.ts +8 -0
  107. package/dist/types/rich-text/runtime/media-upload-session.d.ts +59 -0
  108. package/dist/types/rich-text/runtime/operations.d.ts +48 -0
  109. package/dist/types/rich-text/runtime/option-menu-session.d.ts +28 -0
  110. package/dist/types/rich-text/runtime/option-source.d.ts +10 -0
  111. package/dist/types/rich-text/runtime/port-result.d.ts +21 -0
  112. package/dist/types/rich-text/runtime/schema-plan.d.ts +17 -0
  113. package/dist/types/rich-text/runtime/tool-form-session.d.ts +39 -0
  114. package/dist/types/rich-text/runtime/tool-params.d.ts +5 -0
  115. package/dist/types/rich-text/types.d.ts +40 -0
  116. package/dist/types/rich-text/ui/CapabilityHelp.vue.d.ts +9 -0
  117. package/dist/types/rich-text/ui/KnowledgeArea.vue.d.ts +117 -0
  118. package/dist/types/rich-text/ui/ToolForm.vue.d.ts +14 -0
  119. package/dist/types/rich-text/ui/VariableOptionList.vue.d.ts +15 -0
  120. package/package.json +70 -3
@@ -0,0 +1,485 @@
1
+ import { h as et, b as tt, j as nt } from "../../guard-BCatAeT4.js";
2
+ import { a as at } from "../../media-migration-CGOFwdYm.js";
3
+ function a(t, u, i) {
4
+ return { ok: !1, issues: [{ path: u, message: i }], raw: t };
5
+ }
6
+ function T(t) {
7
+ return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
8
+ }
9
+ function rt(t) {
10
+ if (typeof DOMParser > "u")
11
+ return a(t, "web_content", "当前环境不支持 HTML 解析");
12
+ const u = new DOMParser().parseFromString(t, "text/html"), i = [[]];
13
+ let p = null;
14
+ const g = (d) => i[i.length - 1].push(d), l = (d = !1) => {
15
+ (d || i[i.length - 1].length) && i.push([]);
16
+ }, c = (d, s) => {
17
+ var C, b, E, j;
18
+ if (p) return;
19
+ if (d.nodeType === 3) {
20
+ (d.textContent || "").replace(/\r\n?/g, `
21
+ `).split(`
22
+ `).forEach((f, x) => {
23
+ x && l(!0), f && g({ kind: "text", value: f });
24
+ });
25
+ return;
26
+ }
27
+ if (d.nodeType !== 1) return;
28
+ const n = d, r = n.tagName.toLowerCase(), m = n.getAttribute("data-tag-type") || (n.getAttribute("data-tag") === "true" ? "todo" : "") || (n.getAttribute("data-divider") === "true" ? "separator" : "") || (n.getAttribute("data-retelling") === "true" ? "original_repeat" : "") || (n.getAttribute("data-variable") === "true" ? "variable" : "") || (n.getAttribute("data-agent") === "true" ? "custom_agent" : "") || (n.getAttribute("data-reasoning") === "true" ? "reasoning" : "") || (n.getAttribute("data-memory-trigger") === "true" ? "memory_trigger" : "");
29
+ if (r === "span" && m) {
30
+ const y = n.getAttribute("data-tag-name") || n.getAttribute("data-variable-name") || "", f = n.textContent || "", x = {
31
+ todo: ((C = f.match(/\{待办@[^{}]+\}/u)) == null ? void 0 : C[0]) || (y ? `{待办@${y}}` : ""),
32
+ cdp_tag: ((b = f.match(/\{(?:顾客标签|意图标签)@[^{}]+\}/u)) == null ? void 0 : b[0]) || (y ? `{顾客标签@${y}}` : ""),
33
+ separator: "{分隔符}",
34
+ original_repeat: "{原话复述}",
35
+ variable: ((E = f.match(/#[^#\s]+#/u)) == null ? void 0 : E[0]) || (y ? `#${y}#` : ""),
36
+ custom_agent: ((j = f.match(/\{自定义Agent\}@[\s\S]+/u)) == null ? void 0 : j[0]) || (y ? `{自定义Agent}@${y}` : ""),
37
+ reasoning: "{推理}",
38
+ memory_trigger: "{记忆触发点}"
39
+ };
40
+ x[m] ? g({ kind: "text", value: x[m] }) : p = { path: s, message: `旧标签 ${m} 无法映射到新模型` };
41
+ return;
42
+ }
43
+ if (r === "img" && n.getAttribute("data-tag-icon") === "true") return;
44
+ if (r === "img" || r === "video") {
45
+ const y = n.getAttribute("src") || "";
46
+ nt(y) ? g({
47
+ kind: "media",
48
+ media: r === "img" ? "image" : "video",
49
+ src: y,
50
+ path: s
51
+ }) : p = { path: s, message: "媒体地址无效" };
52
+ return;
53
+ }
54
+ if (r === "br") {
55
+ l(!0);
56
+ return;
57
+ }
58
+ if (!["p", "div", "span"].includes(r) || r === "span" && n.attributes.length > 0) {
59
+ p = { path: s, message: `HTML 标签 ${r} 无法无损转换` };
60
+ return;
61
+ }
62
+ (r === "p" || r === "div") && l();
63
+ const $ = i.length;
64
+ Array.from(n.childNodes).forEach(
65
+ (y, f) => c(y, `${s}.childNodes[${f}]`)
66
+ ), (r === "p" || r === "div") && (i.length === $ || i[i.length - 1].length) && l(!0);
67
+ };
68
+ return Array.from(u.body.childNodes).forEach(
69
+ (d, s) => c(d, `web_content.childNodes[${s}]`)
70
+ ), p ? { ok: !1, issues: [p], raw: t } : (i.length > 1 && !i[i.length - 1].length && i.pop(), { ok: !0, value: i });
71
+ }
72
+ function W(t) {
73
+ return t.every((u) => u.kind === "text") ? t.map((u) => u.value).join("") : null;
74
+ }
75
+ function K(t, u, i) {
76
+ var c;
77
+ const p = [], g = /(#@[^#]+@#|##[^#]+##|#[^#\s]+#|\{[^{}]+\}|\[sep\])/gu;
78
+ let l = 0;
79
+ for (const d of t.matchAll(g)) {
80
+ const s = d.index || 0;
81
+ s > l && p.push({ type: "text", text: t.slice(l, s) });
82
+ const n = d[0];
83
+ if (n === "{分隔符}" || n === "[sep]")
84
+ p.push({
85
+ type: "businessToken",
86
+ attrs: {
87
+ kind: "separator",
88
+ key: "separator",
89
+ label: "分隔符",
90
+ token: "{分隔符}"
91
+ }
92
+ });
93
+ else if (/^#[^#\s]+#$/u.test(n)) {
94
+ const r = n.slice(1, -1), m = (c = i.variable) == null ? void 0 : c.call(i, r);
95
+ if (!(m != null && m.key) || !m.label)
96
+ return a(t, u, `变量 ${r} 缺少可解析的引用`);
97
+ p.push({
98
+ type: "businessToken",
99
+ attrs: { kind: "variable", key: m.key, label: m.label, token: n }
100
+ });
101
+ } else return a(t, u, `正文标记 ${n} 无法在当前位置转换`);
102
+ l = s + n.length;
103
+ }
104
+ return l < t.length && p.push({ type: "text", text: t.slice(l) }), { ok: !0, value: p };
105
+ }
106
+ function it(t) {
107
+ var u, i, p, g, l;
108
+ for (let c = 0; c < t.length; c++) {
109
+ const d = t[c], s = (u = d.content) == null ? void 0 : u[0];
110
+ if (d.type !== "paragraph" || ((i = d.content) == null ? void 0 : i.length) !== 1 || (s == null ? void 0 : s.type) !== "businessToken" || ((p = s.attrs) == null ? void 0 : p.kind) !== "separator")
111
+ continue;
112
+ const n = t[c - 1], r = t[c + 1];
113
+ if ((n == null ? void 0 : n.type) === "paragraph" && ((g = n.content) != null && g.length))
114
+ n.content.push(s);
115
+ else if ((r == null ? void 0 : r.type) === "paragraph" && ((l = r.content) != null && l.length))
116
+ r.content.unshift(s);
117
+ else continue;
118
+ t.splice(c--, 1);
119
+ }
120
+ }
121
+ function lt(t, u, i = {}, p = {}) {
122
+ var B, F, J, U, Q;
123
+ if (!t || typeof t != "object" || Array.isArray(t))
124
+ return a(t, "item", "旧知识记录格式不正确");
125
+ if (!(u != null && u.trim()))
126
+ return a(t, "sourceRecordKey", "需要稳定的来源记录键");
127
+ const g = typeof t.web_content == "string" && t.web_content ? "web_content" : "content", l = t[g];
128
+ if (typeof l != "string") return a(t, g, "旧知识缺少内容");
129
+ const c = rt(l);
130
+ if (!c.ok) return { ...c, raw: t };
131
+ const d = c.value, s = W(d[0] || []), n = s == null ? void 0 : s.match(/^\s*【([^【】\r\n]+)】([\s\S]*)$/u), r = n ? n[1] : p.questionText ?? "";
132
+ if (et(r))
133
+ return a(t, "questionText", "顾客问法包含保留分隔符");
134
+ const m = new DOMParser().parseFromString(l, "text/html"), $ = Array.from(
135
+ m.querySelectorAll('span[data-tag-type="todo"], span[data-tag="true"]')
136
+ ).filter((e) => e.getAttribute("data-tag-type") !== "cdp_tag").map(
137
+ (e) => {
138
+ var o;
139
+ return ((o = (e.textContent || "").match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : o[1]) || e.getAttribute("data-tag-name") || "";
140
+ }
141
+ ), C = Array.from(
142
+ m.querySelectorAll('span[data-tag-type="cdp_tag"]')
143
+ ).map((e) => {
144
+ var o;
145
+ return {
146
+ name: ((o = (e.textContent || "").match(
147
+ /\{(?:顾客标签|意图标签)@([^{}]+)\}/u
148
+ )) == null ? void 0 : o[1]) || e.getAttribute("data-tag-name") || "",
149
+ id: e.getAttribute("data-tag-id") || ""
150
+ };
151
+ });
152
+ if ($.length > 1)
153
+ return a(t, g, "新模型每条问法只能选择一个待办方案");
154
+ if (C.length > 1)
155
+ return a(t, g, "新模型每条问法只能选择一个顾客标签");
156
+ const b = {}, E = !n && s && /^(?:\{(?:待办|顾客标签|意图标签)@[^{}]+\})+$/u.test(s.trim());
157
+ let j = (n == null ? void 0 : n[2].trim()) || (E ? s.trim() : "");
158
+ for (; j; ) {
159
+ const e = j.match(
160
+ /^\{(待办|顾客标签|意图标签)@([^{}]+)\}|^\{(原话复述|记忆触发点)\}/u
161
+ );
162
+ if (!e) return a(t, g, `问法后的标记无法转换:${j}`);
163
+ if (e[1]) {
164
+ const o = e[1] === "待办" ? "todo" : "tagged", h = o === "todo" ? $.find((O) => O === e[2]) : C.find((O) => O.name === e[2]);
165
+ if (!h)
166
+ return a(
167
+ t,
168
+ g,
169
+ `${e[1]} ${e[2]} 不是有效的旧版富文本标签`
170
+ );
171
+ const H = o === "todo" && t.todo_plan_name === e[2] ? String(t.todo_plan_id || "") : o === "tagged" ? h.id : "", k = H ? { id: H, label: e[2] } : (B = i.selection) == null ? void 0 : B.call(i, o, e[2]);
172
+ if (!(k != null && k.id) || !k.label || k.label !== e[2])
173
+ return a(
174
+ t,
175
+ g,
176
+ `${e[1]} ${e[2]} 缺少匹配的方案 ID`
177
+ );
178
+ if (b[o]) return a(t, g, `${e[1]}重复`);
179
+ b[o] = { version: 1, data: { enabled: !0, tag: k } };
180
+ } else {
181
+ const o = e[3] === "原话复述" ? "originalReply" : "memory";
182
+ if (b[o]) return a(t, g, `${e[3]}重复`);
183
+ b[o] = { version: 1, data: { enabled: !0 } };
184
+ }
185
+ j = j.slice(e[0].length).trimStart();
186
+ }
187
+ if (Array.isArray(t.tag_meta))
188
+ for (const [e, o] of t.tag_meta.entries()) {
189
+ if (!o || typeof o != "object")
190
+ return a(t, `tag_meta[${e}]`, "标签元数据格式错误");
191
+ const h = o;
192
+ if (![
193
+ "cdp_tag",
194
+ "todo",
195
+ "variable",
196
+ "reasoning",
197
+ "original_repeat",
198
+ "custom_agent",
199
+ "memory",
200
+ "separator"
201
+ ].includes(String(h.type)))
202
+ return a(
203
+ t,
204
+ `tag_meta[${e}]`,
205
+ "旧标签元数据无法映射到新模型"
206
+ );
207
+ if (h.invalid)
208
+ return a(t, `tag_meta[${e}]`, "失效标签需要只读保全");
209
+ if (h.type === "cdp_tag" && (!b.tagged || b.tagged.data.tag.id !== String(h.value || "") || b.tagged.data.tag.label !== String(h.name || "")))
210
+ return a(
211
+ t,
212
+ `tag_meta[${e}]`,
213
+ "顾客标签 ID 与富文本标签不一致"
214
+ );
215
+ }
216
+ const y = t.todo_plan_id;
217
+ if (y != null && String(y).trim()) {
218
+ const e = t.todo_plan_name;
219
+ if (typeof e != "string" || !e.trim())
220
+ return a(t, "todo_plan_name", "待办方案 ID 存在但名称缺失");
221
+ if (!$.includes(e))
222
+ return a(t, "web_content", "待办方案字段缺少对应的富文本标签");
223
+ const o = { id: String(y), label: e };
224
+ if (b.todo && JSON.stringify(b.todo.data.tag) !== JSON.stringify(o))
225
+ return a(t, "todo_plan_id", "待办字段与正文标签不一致");
226
+ b.todo = { version: 1, data: { enabled: !0, tag: o } };
227
+ }
228
+ const f = n || E ? d.slice(1) : [...d], x = Number(t.knowledge_type || 0);
229
+ let A = x === 2 ? "reasoning" : x === 3 ? "agent" : "normal";
230
+ if (t.knowledge_type !== void 0 && ![0, 1, 2, 3].includes(x))
231
+ return a(t, "knowledge_type", "未知的旧知识类型");
232
+ if (Array.isArray(t.tag_meta)) {
233
+ if (t.tag_meta.some(
234
+ (e) => e && typeof e == "object" && e.type === "reasoning"
235
+ ) && x === 1)
236
+ return a(t, "tag_meta", "推理标签与知识类型不一致");
237
+ if (t.tag_meta.some(
238
+ (e) => e && typeof e == "object" && e.type === "custom_agent"
239
+ ) && (x === 1 || x === 2))
240
+ return a(t, "tag_meta", "Agent 标签与知识类型不一致");
241
+ }
242
+ let I = null;
243
+ if (f.length && ((F = W(f[0])) == null ? void 0 : F.trim()) === "{推理}") {
244
+ if (A === "agent")
245
+ return a(t, g, "推理标记与 Agent 类型冲突");
246
+ A = "reasoning", f.shift();
247
+ }
248
+ if (f.length && ((J = W(f[0])) != null && J.trim().startsWith("{自定义Agent}@"))) {
249
+ if (A === "reasoning")
250
+ return a(t, g, "Agent 标记与推理类型冲突");
251
+ A = "agent";
252
+ const e = W(f[0]).trim().slice(11), o = Array.isArray(t.tag_meta) ? t.tag_meta.find(
253
+ (h) => h && typeof h == "object" && h.type === "custom_agent" && h.agent_name === e
254
+ ) : void 0;
255
+ if (I = typeof (o == null ? void 0 : o.agent_id) == "string" && o.agent_id ? { id: o.agent_id, name: e } : ((U = i.agent) == null ? void 0 : U.call(i, e)) || null, !(I != null && I.id) || I.name !== e)
256
+ return a(t, g, `Agent ${e} 缺少匹配的 ID`);
257
+ f.shift();
258
+ }
259
+ if (A !== "normal" && b.todo)
260
+ return a(t, g, "非常规知识的问法行不能包含待办标签");
261
+ if (A !== "normal" && b.originalReply)
262
+ return a(t, g, "此类型的问法行不能包含原话标签");
263
+ if (A === "agent" && !I)
264
+ return a(t, g, "Agent 知识缺少可解析的 Agent 标记");
265
+ const L = [];
266
+ for (let e = 0; e < f.length; e++) {
267
+ const o = f[e], h = `${g}.line[${e + 2}]`;
268
+ if (((Q = W(o)) == null ? void 0 : Q.trim()) === "{原话复述}" && A === "reasoning") {
269
+ const w = f[++e];
270
+ if (!w) return a(t, h, "原话块缺少内容");
271
+ const N = W(w);
272
+ if (N === null) return a(t, h, "原话块包含无法转换的媒体");
273
+ const M = K(N, h, i);
274
+ if (!M.ok) return { ...M, raw: t };
275
+ L.push({
276
+ type: "originalReply",
277
+ content: [{ type: "paragraph", content: M.value }]
278
+ });
279
+ continue;
280
+ }
281
+ if (A === "agent") {
282
+ if (o.some(
283
+ (w) => w.kind === "media" || w.kind === "text" && w.value.trim()
284
+ ))
285
+ return a(t, h, "Agent 知识不能包含正文");
286
+ continue;
287
+ }
288
+ let k = [];
289
+ const O = () => {
290
+ k.length && (L.push({ type: "paragraph", content: k }), k = []);
291
+ };
292
+ for (const w of o)
293
+ if (w.kind === "media")
294
+ O(), L.push({
295
+ type: "mediaBlock",
296
+ attrs: { kind: w.media, src: w.src, status: "ready" }
297
+ });
298
+ else {
299
+ const N = K(w.value, h, i);
300
+ if (!N.ok) return { ...N, raw: t };
301
+ k.push(...N.value);
302
+ }
303
+ (k.length || !o.length) && L.push({ type: "paragraph", content: k });
304
+ }
305
+ it(L);
306
+ const V = {
307
+ type: "doc",
308
+ content: L.length ? L : [{ type: "paragraph" }]
309
+ }, z = A === "agent" ? null : at(V, u).doc, D = {
310
+ schemaVersion: 1,
311
+ type: A,
312
+ question: { text: r },
313
+ knowledge: { doc: z, agentRef: I },
314
+ extensionState: b
315
+ }, P = tt(D);
316
+ return P ? a(t, P, "转换后的场景未通过新模型校验") : { ok: !0, value: D };
317
+ }
318
+ function ot(t, u) {
319
+ var i, p, g;
320
+ if (t.type === "text" && !((i = t.marks) != null && i.length))
321
+ return {
322
+ ok: !0,
323
+ value: { html: T(t.text || ""), text: t.text || "" }
324
+ };
325
+ if (t.type === "businessToken" && ((p = t.attrs) == null ? void 0 : p.kind) === "variable") {
326
+ const l = `#${String(t.attrs.label || t.attrs.key)}#`;
327
+ return {
328
+ ok: !0,
329
+ value: {
330
+ html: `<span data-tag-type="variable" data-variable="true" data-variable-name="${T(
331
+ String(t.attrs.label || t.attrs.key)
332
+ )}">${T(l)}</span>`,
333
+ text: l
334
+ }
335
+ };
336
+ }
337
+ return t.type === "businessToken" && ((g = t.attrs) == null ? void 0 : g.kind) === "separator" ? {
338
+ ok: !0,
339
+ value: {
340
+ html: '<span data-tag-type="separator" data-divider="true" contenteditable="false">分隔符</span>',
341
+ text: "[sep]"
342
+ }
343
+ } : a(t, u, `节点 ${t.type} 无法映射到旧格式`);
344
+ }
345
+ function dt(t, u = {}, i = {}) {
346
+ var C, b, E, j, y, f, x, A, I, L, V, z, D, P, B, F, J, U, Q, e, o, h, H, k, O, w, N, M;
347
+ const p = tt(t);
348
+ if (p) return a(t, p, "场景未通过新模型校验");
349
+ const g = `【${t.question.text}】`, l = [], c = [];
350
+ for (const [v, _] of [
351
+ ["todo", "待办"],
352
+ ["tagged", "顾客标签"]
353
+ ]) {
354
+ const S = (C = t.extensionState[v]) == null ? void 0 : C.data;
355
+ if (S != null && S.enabled) {
356
+ const R = `{${_}@${(b = S.tag) == null ? void 0 : b.label}}`;
357
+ l.push(R), c.push(
358
+ v === "todo" ? `<span contenteditable="false" data-tag="true" data-tag-type="todo" data-tag-name="${T(
359
+ ((E = S.tag) == null ? void 0 : E.label) || ""
360
+ )}">${T(R)}</span>` : `<span contenteditable="false" data-tag="true" data-tag-type="cdp_tag" data-tag-name="${T(
361
+ ((j = S.tag) == null ? void 0 : j.label) || ""
362
+ )}" data-tag-id="${T(((y = S.tag) == null ? void 0 : y.id) || "")}">${T(
363
+ R
364
+ )}</span>`
365
+ );
366
+ }
367
+ }
368
+ (x = (f = t.extensionState.originalReply) == null ? void 0 : f.data) != null && x.enabled && (l.push("{原话复述}"), c.push(
369
+ '<span data-tag-type="original_repeat" data-retelling="true">{原话复述}</span>'
370
+ )), (I = (A = t.extensionState.memory) == null ? void 0 : A.data) != null && I.enabled && (l.push("{记忆触发点}"), c.push(
371
+ '<span data-tag-type="memory_trigger" data-memory-trigger="true">{记忆触发点}</span>'
372
+ ));
373
+ for (const v of Object.keys(t.extensionState))
374
+ if (!["todo", "tagged", "originalReply", "memory"].includes(v))
375
+ return a(
376
+ t,
377
+ `extensionState.${v}`,
378
+ "旧格式无法表示此插件状态"
379
+ );
380
+ const d = i.questionStorage || (/^\s*(?:<(?:div|p)>\s*)?【[^【】]+】/u.test(
381
+ String(u.web_content || "")
382
+ ) ? "inline" : "external");
383
+ if (d === "external" && l.some(
384
+ (v) => !v.startsWith("{待办@") && !v.startsWith("{顾客标签@")
385
+ ))
386
+ return a(
387
+ t,
388
+ "extensionState",
389
+ "外部问法字段的这些标签尚无确定的旧字段映射"
390
+ );
391
+ const s = d === "inline" ? [`<div>${T(g)}${c.join("")}</div>`] : c.length ? [`<div>${c.join("")}</div>`] : [], n = d === "inline" ? [g + l.join("")] : l.length ? [l.join("")] : [];
392
+ if (t.type === "reasoning" && (s.push("<div>{推理}</div>"), n.push("{推理}")), t.type === "agent") {
393
+ if ((V = (L = t.extensionState.tagged) == null ? void 0 : L.data) != null && V.enabled)
394
+ return a(
395
+ t,
396
+ "extensionState.tagged",
397
+ "旧系统的 Agent 与顾客标签不能组合"
398
+ );
399
+ if (t.knowledge.retainedDoc)
400
+ return a(
401
+ t,
402
+ "knowledge.retainedDoc",
403
+ "旧格式不能保留 Agent 切换前的正文"
404
+ );
405
+ if (!t.knowledge.agentRef)
406
+ return a(t, "knowledge.agentRef", "旧格式需要 Agent 引用");
407
+ const v = `{自定义Agent}@${t.knowledge.agentRef.name}`;
408
+ s.push(
409
+ `<div><span data-tag-type="custom_agent" data-agent="true" data-agent-id="${T(
410
+ t.knowledge.agentRef.id
411
+ )}">${T(v)}</span></div>`
412
+ ), n.push(v);
413
+ } else
414
+ for (const [v, _] of (((z = t.knowledge.doc) == null ? void 0 : z.content) || []).entries()) {
415
+ const S = `knowledge.doc.content[${v}]`;
416
+ if (_.type === "messageSeparator") {
417
+ s.push(
418
+ '<div><span data-tag-type="separator" data-divider="true">{分隔符}</span></div>'
419
+ ), n.push("[sep]");
420
+ continue;
421
+ }
422
+ if (_.type === "mediaBlock" && ((D = _.attrs) == null ? void 0 : D.status) === "ready") {
423
+ const q = _.attrs.kind === "image" ? "img" : "video", G = T(String(_.attrs.src));
424
+ s.push(
425
+ `<div><${q} src="${G}"${q === "video" ? "></video>" : ">"}</div>`
426
+ ), n.push(
427
+ `<${q} src="${G}"${q === "video" ? ' width="240" controls/>' : ' width="120"/>'}`
428
+ );
429
+ continue;
430
+ }
431
+ const R = _.type === "originalReply", X = R ? (P = _.content) == null ? void 0 : P[0] : _;
432
+ if (!X || X.type !== "paragraph" || R && ((B = _.content) == null ? void 0 : B.length) !== 1)
433
+ return a(t, S, `节点 ${_.type} 无法映射到旧格式`);
434
+ R && (s.push(
435
+ '<div><span data-tag-type="original_repeat" data-retelling="true">{原话复述}</span></div>'
436
+ ), n.push("{原话复述}"));
437
+ const Y = [];
438
+ for (const [q, G] of (X.content || []).entries()) {
439
+ const Z = ot(G, `${S}.content[${q}]`);
440
+ if (!Z.ok) return { ...Z, raw: t };
441
+ Y.push(Z.value);
442
+ }
443
+ s.push(
444
+ `<div>${Y.map((q) => q.html).join("")}</div>`
445
+ ), n.push(Y.map((q) => q.text).join(""));
446
+ }
447
+ const r = (F = t.extensionState.todo) == null ? void 0 : F.data, m = (J = t.extensionState.tagged) == null ? void 0 : J.data, $ = [];
448
+ if (m != null && m.enabled) {
449
+ $.push({
450
+ type: "cdp_tag",
451
+ name: (U = m.tag) == null ? void 0 : U.label,
452
+ value: (Q = m.tag) == null ? void 0 : Q.id
453
+ }), r != null && r.enabled && $.push({ type: "todo", name: (e = r.tag) == null ? void 0 : e.label }), t.type === "reasoning" && $.push({ type: "reasoning", name: "推理" }), (h = (o = t.extensionState.originalReply) == null ? void 0 : o.data) != null && h.enabled && $.push({ type: "original_repeat", name: "原话复述" }), (k = (H = t.extensionState.memory) == null ? void 0 : H.data) != null && k.enabled && $.push({ type: "memory", name: "" });
454
+ const v = (_) => {
455
+ var S, R;
456
+ _.type === "businessToken" && ((S = _.attrs) == null ? void 0 : S.kind) === "variable" && $.push({
457
+ type: "variable",
458
+ variable_name: _.attrs.label || _.attrs.key
459
+ }), _.type === "originalReply" && $.push({ type: "original_repeat", name: "原话复述" }), (R = _.content) == null || R.forEach(v);
460
+ };
461
+ (w = (O = t.knowledge.doc) == null ? void 0 : O.content) == null || w.forEach(v), t.type === "agent" && t.knowledge.agentRef && $.push({
462
+ type: "custom_agent",
463
+ agent_id: t.knowledge.agentRef.id,
464
+ agent_name: t.knowledge.agentRef.name
465
+ });
466
+ }
467
+ return {
468
+ ok: !0,
469
+ value: {
470
+ ...u,
471
+ knowledge_type: t.type === "reasoning" ? 2 : t.type === "agent" ? 3 : 1,
472
+ todo_plan_id: r != null && r.enabled ? (N = r.tag) == null ? void 0 : N.id : "",
473
+ todo_tag_type: r != null && r.enabled ? 2 : 0,
474
+ todo_plan_name: r != null && r.enabled ? (M = r.tag) == null ? void 0 : M.label : "",
475
+ tag_meta: $,
476
+ web_content: s.join(""),
477
+ content: n.join(`
478
+ `)
479
+ }
480
+ };
481
+ }
482
+ export {
483
+ lt as legacyItemToScene,
484
+ dt as sceneToLegacyItem
485
+ };
@@ -0,0 +1,20 @@
1
+ const d = {
2
+ execute(n, t, r) {
3
+ var o;
4
+ const e = (o = r.extensionState[n]) == null ? void 0 : o.data, a = e && typeof e == "object" && !Array.isArray(e) ? e : {};
5
+ return [
6
+ {
7
+ kind: "setOwnState",
8
+ capabilityId: n,
9
+ data: t.option ? {
10
+ ...a,
11
+ enabled: !0,
12
+ tag: { id: t.option.id, label: t.option.label }
13
+ } : { ...a, enabled: !a.enabled }
14
+ }
15
+ ];
16
+ }
17
+ };
18
+ export {
19
+ d as s
20
+ };
@@ -0,0 +1,16 @@
1
+ const c = {
2
+ execute(e, o, r) {
3
+ var n;
4
+ const t = (n = r.extensionState[e]) == null ? void 0 : n.data, a = t && typeof t == "object" && !Array.isArray(t) ? t : {};
5
+ return [
6
+ {
7
+ kind: "setOwnState",
8
+ capabilityId: e,
9
+ data: { ...a, enabled: !a.enabled }
10
+ }
11
+ ];
12
+ }
13
+ };
14
+ export {
15
+ c as m
16
+ };