@freecallai/pro 0.0.3 → 0.0.4

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 (29) hide show
  1. package/README.md +1 -1
  2. package/dist/{FkpKnowledgeTypePicker.vue_vue_type_script_setup_true_lang-xR8ZhhdJ.js → FkpKnowledgeTypePicker.vue_vue_type_script_setup_true_lang-DYwu7oQs.js} +1 -1
  3. package/dist/{FkpRichText.vue_vue_type_script_setup_true_lang-CaHRIHab.js → FkpRichText.vue_vue_type_script_setup_true_lang-BowbZoTQ.js} +1782 -1761
  4. package/dist/{KnowledgeArea-_rsydhnt.js → KnowledgeArea-BH-_uF6R.js} +3 -3
  5. package/dist/{ToolForm-Czg67cDT.js → ToolForm-C6XW31Y7.js} +1 -1
  6. package/dist/{choice-Bt2xhoN_.js → choice-C1SxozNA.js} +1 -1
  7. package/dist/{guard-B7U3S4F1.js → guard-CXpVx8UR.js} +96 -91
  8. package/dist/{index-BBv72oZe.js → index-B8jg37Wj.js} +1 -1
  9. package/dist/{index-D9yqpH_4.js → index-BqXNMfLG.js} +2 -2
  10. package/dist/{index-BF6MRSMb.js → index-CM0MN2DT.js} +1 -1
  11. package/dist/{index-DYeJRJY1.js → index-CZc2Gyjb.js} +1 -1
  12. package/dist/{index-B4-2_sJI.js → index-Cy4DqT8R.js} +1 -1
  13. package/dist/index-DAZ1ulyA.js +5 -0
  14. package/dist/index-F7lDP1lI.js +5 -0
  15. package/dist/{index-sjDmbR5o.js → index-UjI4WA5F.js} +1 -1
  16. package/dist/{index-trxE5T0w.js → index-bSNw0XAf.js} +1 -1
  17. package/dist/index.js +5 -5
  18. package/dist/{inline-KPGqYMIR.js → inline-Zj7Hqg-_.js} +1 -1
  19. package/dist/{knowledge-CupkY2rK.js → knowledge-DaTnF2IW.js} +1 -1
  20. package/dist/knowledge-type-picker/index.js +1 -1
  21. package/dist/{media-extensions-DhRlLKYM.js → media-extensions-wlcCEdtg.js} +27 -24
  22. package/dist/{media-migration-CbMT2wS0.js → media-migration-C2QLMSpd.js} +1 -1
  23. package/dist/{media-upload-P9WeUHHr.js → media-upload-D9MYBbLg.js} +1 -1
  24. package/dist/rich-text/index.js +6 -6
  25. package/dist/rich-text/legacy-converter/index.js +923 -825
  26. package/dist/style.css +1 -1
  27. package/package.json +4 -4
  28. package/dist/index-BQrYBmwR.js +0 -5
  29. package/dist/index-uCVrA6xK.js +0 -5
@@ -1,6 +1,6 @@
1
- import { b as wt, h as Mt, c as Et, d as zt, e as Nt, j as It, k as St, l as Ht } from "../../guard-B7U3S4F1.js";
2
- import { a as jt } from "../../media-migration-CbMT2wS0.js";
3
- const Pt = [
1
+ import { b as wt, h as zt, c as qt, d as Ht, e as Bt, j as Et, k as St, l as Pt } from "../../guard-CXpVx8UR.js";
2
+ import { a as jt } from "../../media-migration-C2QLMSpd.js";
3
+ const Kt = [
4
4
  { id: 1, key: "focus_goods_name", name: "焦点商品名称" },
5
5
  { id: 2, key: "focus_goods_info", name: "焦点商品信息" },
6
6
  { id: 3, key: "focus_goods_sku", name: "焦点商品sku信息" },
@@ -10,20 +10,20 @@ const Pt = [
10
10
  ];
11
11
  function Ot(t) {
12
12
  if (!Array.isArray(t)) return !1;
13
- const o = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set(), S = /* @__PURE__ */ new Set();
14
- return t.every((a) => !a || !(typeof a.id == "string" && a.id.trim() === a.id && a.id || typeof a.id == "number" && Number.isSafeInteger(a.id) && a.id > 0) || typeof a.key != "string" || !a.key || a.key.trim() !== a.key || typeof a.name != "string" || !a.name || a.name.trim() !== a.name || /[{}<>\r\n]/u.test(a.name) || o.has(String(a.id)) || d.has(a.key) || S.has(a.name) ? !1 : (o.add(String(a.id)), d.add(a.key), S.add(a.name), !0));
13
+ const s = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set(), S = /* @__PURE__ */ new Set();
14
+ return t.every((r) => !r || !(typeof r.id == "string" && r.id.trim() === r.id && r.id || typeof r.id == "number" && Number.isSafeInteger(r.id) && r.id > 0) || typeof r.key != "string" || !r.key || r.key.trim() !== r.key || typeof r.name != "string" || !r.name || r.name.trim() !== r.name || /[{}<>\r\n]/u.test(r.name) || s.has(String(r.id)) || d.has(r.key) || S.has(r.name) ? !1 : (s.add(String(r.id)), d.add(r.key), S.add(r.name), !0));
15
15
  }
16
- const _t = Object.freeze(Pt.map((t) => Object.freeze({ ...t })));
17
- function Dt(t, o = _t) {
18
- return o.find((d) => d.name === t);
16
+ const _t = Object.freeze(Kt.map((t) => Object.freeze({ ...t })));
17
+ function Rt(t, s = _t) {
18
+ return s.find((d) => d.name === t);
19
19
  }
20
- function Kt(t, o = _t) {
21
- return o.find((d) => d.key === t);
20
+ function Ft(t, s = _t) {
21
+ return s.find((d) => d.key === t);
22
22
  }
23
- function Lt(t) {
23
+ function Nt(t) {
24
24
  return `{业务属性@${t}}`;
25
25
  }
26
- const Ft = /* @__PURE__ */ new Set([
26
+ const Jt = /* @__PURE__ */ new Set([
27
27
  "todo",
28
28
  "cdp_tag",
29
29
  "separator",
@@ -41,62 +41,62 @@ const Ft = /* @__PURE__ */ new Set([
41
41
  "external_method",
42
42
  "ticket",
43
43
  "tool"
44
- ]), Jt = /#@[^#\n]+?@#|##[^#\n]+?##|\$\$小额打款@[^$\n]+?\$\$|\^\^订单备注[^\n]+?\^\^|\{自定义Agent\}@[^^\s\n{}]+|\{(?:业务属性|属性|外部方法|智能建单|智能工单|待办|记忆触发点|分隔符|原话复述|顾客标签|意图标签|工具|推理)@?[^}\n]*\}|#[^#\n]+?#/gu;
45
- function Ut(t) {
44
+ ]), Ut = /#@[^#\n]+?@#|##[^#\n]+?##|\$\$小额打款@[^$\n]+?\$\$|\^\^订单备注[^\n]+?\^\^|\{自定义Agent\}@[^^\s\n{}]+|\{(?:业务属性|属性|外部方法|智能建单|智能工单|待办|记忆触发点|分隔符|原话复述|顾客标签|意图标签|工具|推理)@?[^}\n]*\}|#[^#\n]+?#/gu;
45
+ function Vt(t) {
46
46
  return t.replace(
47
47
  /<video\b((?:[^"'<>]|"[^"]*"|'[^']*')*)\/>/giu,
48
48
  "<video$1></video>"
49
49
  );
50
50
  }
51
- function Vt(t) {
51
+ function Qt(t) {
52
52
  return t.startsWith("#@") ? "size_chart" : t.startsWith("##") ? "table_knowledge" : t.startsWith("$$") ? "small_payment" : t.startsWith("^^") ? "order_remark" : t.startsWith("{自定义Agent}") ? "custom_agent" : t.startsWith("#") ? "variable" : t.startsWith("{业务属性@") || t.startsWith("{属性@") ? "biz_attribute" : t.startsWith("{外部方法@") ? "external_method" : t.startsWith("{智能建单@") || t.startsWith("{智能工单@") ? "ticket" : t.startsWith("{待办") ? "todo" : t.startsWith("{记忆触发点") ? "memory_trigger" : t.startsWith("{分隔符") ? "separator" : t.startsWith("{原话复述") ? "original_repeat" : t.startsWith("{推理") ? "reasoning" : t.startsWith("{顾客标签") || t.startsWith("{意图标签") ? "cdp_tag" : "tool";
53
53
  }
54
- function te(t, o) {
55
- var i;
54
+ function ee(t, s) {
55
+ var l;
56
56
  const d = [], S = () => {
57
57
  d.length && d[d.length - 1].type !== "break" && d.push({ type: "break" });
58
- }, a = (g) => {
59
- let f = 0;
60
- for (const p of g.matchAll(Jt))
61
- p.index > f && d.push({ type: "text", text: g.slice(f, p.index) }), d.push({ type: "tag", kind: Vt(p[0]), label: p[0] }), f = p.index + p[0].length;
62
- f < g.length && d.push({ type: "text", text: g.slice(f) });
58
+ }, r = (g) => {
59
+ let y = 0;
60
+ for (const p of g.matchAll(Ut))
61
+ p.index > y && d.push({ type: "text", text: g.slice(y, p.index) }), d.push({ type: "tag", kind: Qt(p[0]), label: p[0] }), y = p.index + p[0].length;
62
+ y < g.length && d.push({ type: "text", text: g.slice(y) });
63
63
  };
64
64
  if (t != null && t.trim() && typeof DOMParser < "u") {
65
65
  const g = new DOMParser().parseFromString(
66
- Ut(t),
66
+ Vt(t),
67
67
  "text/html"
68
- ), f = (p) => {
69
- var n, r;
68
+ ), y = (p) => {
69
+ var e, i;
70
70
  if (p.nodeType === Node.TEXT_NODE) {
71
- a(p.textContent || "");
71
+ r(p.textContent || "");
72
72
  return;
73
73
  }
74
74
  if (!(p instanceof Element)) return;
75
- const y = p.tagName.toLowerCase();
76
- if (["script", "style", "svg", "iframe", "object"].includes(y))
75
+ const b = p.tagName.toLowerCase();
76
+ if (["script", "style", "svg", "iframe", "object"].includes(b))
77
77
  return;
78
- if (y === "br") {
78
+ if (b === "br") {
79
79
  S();
80
80
  return;
81
81
  }
82
- if (y === "img" && p.getAttribute("data-tag-icon") === "true")
82
+ if (b === "img" && p.getAttribute("data-tag-icon") === "true")
83
83
  return;
84
- if (y === "img" || y === "video") {
85
- const u = p.getAttribute("src") || (y === "video" ? (n = p.querySelector("source[src]")) == null ? void 0 : n.getAttribute("src") : null);
86
- wt(u) && d.push({
84
+ if (b === "img" || b === "video") {
85
+ const c = p.getAttribute("src") || (b === "video" ? (e = p.querySelector("source[src]")) == null ? void 0 : e.getAttribute("src") : null);
86
+ wt(c) && d.push({
87
87
  type: "media",
88
- kind: y === "img" ? "image" : "video",
89
- url: u
88
+ kind: b === "img" ? "image" : "video",
89
+ url: c
90
90
  });
91
91
  return;
92
92
  }
93
- const m = p.getAttribute("data-tag-type") || (p.getAttribute("data-size") === "true" ? "size_chart" : "") || (p.getAttribute("data-tableKnowledge") === "true" ? "table_knowledge" : "") || (p.getAttribute("data-variable") === "true" ? "variable" : "") || (p.getAttribute("data-divider") === "true" ? "separator" : "");
94
- if (Ft.has(m)) {
95
- const u = (r = p.textContent) == null ? void 0 : r.trim();
96
- u && d.push({ type: "tag", kind: m, label: u });
93
+ const k = p.getAttribute("data-tag-type") || (p.getAttribute("data-size") === "true" ? "size_chart" : "") || (p.getAttribute("data-tableKnowledge") === "true" ? "table_knowledge" : "") || (p.getAttribute("data-variable") === "true" ? "variable" : "") || (p.getAttribute("data-divider") === "true" ? "separator" : "");
94
+ if (Jt.has(k)) {
95
+ const c = (i = p.textContent) == null ? void 0 : i.trim();
96
+ c && d.push({ type: "tag", kind: k, label: c });
97
97
  return;
98
98
  }
99
- const s = [
99
+ const u = [
100
100
  "div",
101
101
  "p",
102
102
  "li",
@@ -105,183 +105,219 @@ function te(t, o) {
105
105
  "h3",
106
106
  "blockquote",
107
107
  "pre"
108
- ].includes(y);
109
- s && d.length && S(), p.childNodes.forEach(f), s && S();
108
+ ].includes(b);
109
+ u && d.length && S(), p.childNodes.forEach(y), u && S();
110
110
  };
111
- for (g.body.childNodes.forEach(f); ((i = d[d.length - 1]) == null ? void 0 : i.type) === "break"; ) d.pop();
111
+ for (g.body.childNodes.forEach(y); ((l = d[d.length - 1]) == null ? void 0 : l.type) === "break"; ) d.pop();
112
112
  }
113
113
  return d.some(
114
114
  (g) => g.type === "tag" || g.type === "media" || g.type === "text" && !!g.text.trim()
115
- ) || (d.length = 0, o != null && o.trim() && a(o)), d;
115
+ ) || (d.length = 0, s != null && s.trim() && r(s)), d;
116
116
  }
117
- function c(t, o, d) {
118
- return { ok: !1, issues: [{ path: o, message: d }], raw: t };
117
+ function f(t, s, d) {
118
+ return { ok: !1, issues: [{ path: s, message: d }], raw: t };
119
119
  }
120
- function w(t) {
120
+ function A(t) {
121
121
  return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
122
122
  }
123
- function pt(t) {
123
+ function ot(t) {
124
124
  return t.getAttribute("data-tag-type") || (t.getAttribute("data-tag") === "no_send_follow_order" ? "no_send_follow_order" : "") || (t.getAttribute("data-divider") === "true" ? "separator" : "") || (t.getAttribute("data-retelling") === "true" ? "original_repeat" : "") || (t.getAttribute("data-size") === "true" ? "size_chart" : "") || (t.getAttribute("data-tableKnowledge") === "true" ? "table_knowledge" : "") || (t.getAttribute("data-variable") === "true" ? "variable" : "") || (t.getAttribute("data-agent") === "true" ? "custom_agent" : "") || (t.getAttribute("data-reasoning") === "true" ? "reasoning" : "") || (t.getAttribute("data-memory-trigger") === "true" ? "memory_trigger" : "") || (/^\{(?:智能建单|智能工单)@/u.test((t.textContent || "").trim()) ? "ticket" : "") || ((t.textContent || "").trim().startsWith("{外部方法@") ? "external_method" : "") || (t.getAttribute("data-tag") === "true" ? "todo" : "");
125
125
  }
126
- function Ct(t) {
127
- const o = /<\{原话复述\}((?:<(?:img|video)\b[^>]*>|[^<>])*)>|<(?:img|video)\b[^>]*>/gu;
128
- let d = "", S = 0;
129
- for (const a of t.matchAll(o)) {
130
- const i = a.index || 0;
131
- d += w(t.slice(S, i)), d += a[1] === void 0 ? a[0] : `<span data-tag-type="original_repeat" data-original-repeat-template="true"><span data-original-repeat-input="true">${Ct(
132
- a[1]
133
- )}</span></span>`, S = i + a[0].length;
126
+ function Lt(t) {
127
+ let s = "", d = 0;
128
+ const S = /<\{原话复述\}|<(?:img|video|hr)\b(?:[^"'<>]|"[^"]*"|'[^']*')*>/gu;
129
+ for (; d < t.length; ) {
130
+ S.lastIndex = d;
131
+ const r = S.exec(t);
132
+ if (!r) break;
133
+ if (s += A(t.slice(d, r.index)), r[0] !== "<{原话复述}") {
134
+ s += r[0], d = S.lastIndex;
135
+ continue;
136
+ }
137
+ const l = S.lastIndex;
138
+ let g = -1, y = -1;
139
+ for (let p = l; p < t.length && !t.startsWith("<{原话复述}", p); p++) {
140
+ const b = t[p] === "<" && t.slice(p).match(/^<(?:img|video)\b(?:[^"'<>]|"[^"]*"|'[^']*')*>/u);
141
+ if (b) {
142
+ p += b[0].length - 1;
143
+ continue;
144
+ }
145
+ if (t[p] === ">" && (y < 0 && (y = p), /^(?:[ \t]*(?:\r?\n|$)|<\{原话复述\})/u.test(t.slice(p + 1)))) {
146
+ g = p;
147
+ break;
148
+ }
149
+ }
150
+ if (g < 0 && (g = y), g < 0) {
151
+ s += A(r[0]), d = l;
152
+ continue;
153
+ }
154
+ s += `<span data-tag-type="original_repeat" data-original-repeat-template="true"><span data-original-repeat-input="true">${Lt(
155
+ t.slice(l, g)
156
+ )}</span></span>`, d = g + 1;
134
157
  }
135
- return d + w(t.slice(S));
158
+ return s + A(t.slice(d));
136
159
  }
137
- function ht(t, o = !1, d = _t) {
160
+ function ht(t, s = !1, d = _t) {
138
161
  if (typeof DOMParser > "u")
139
- return c(t, "web_content", "当前环境不支持 HTML 解析");
140
- const S = new DOMParser().parseFromString(t, "text/html"), a = [[]];
141
- let i = null, g = [];
142
- const f = (m) => a[a.length - 1].push(
143
- m.kind === "text" && g.length ? { ...m, marks: [...g] } : m
144
- ), p = (m = !1) => {
145
- (m || a[a.length - 1].length) && a.push([]);
146
- }, y = (m, s) => {
147
- var O, P, M, _, B, K, Y, at, rt, D, et, H, Z, W, it;
148
- if (i) return;
149
- if (m.nodeType === 3) {
150
- (m.textContent || "").replace(/\r\n?/g, `
162
+ return f(t, "web_content", "当前环境不支持 HTML 解析");
163
+ const S = new DOMParser().parseFromString(
164
+ t.replace(
165
+ /<video\b((?:[^"'<>]|"[^"]*"|'[^']*')*)\/>/giu,
166
+ "<video$1></video>"
167
+ ),
168
+ "text/html"
169
+ ), r = [[]];
170
+ let l = null, g = [];
171
+ const y = (k) => r[r.length - 1].push(
172
+ k.kind === "text" && g.length ? { ...k, marks: [...g] } : k
173
+ ), p = (k = !1) => {
174
+ (k || r[r.length - 1].length) && r.push([]);
175
+ }, b = (k, u) => {
176
+ var E, P, D, _, q, K, F, G, tt, O, Y, H, Q, j, et;
177
+ if (l) return;
178
+ if (k.nodeType === 3) {
179
+ (k.textContent || "").replace(/\r\n?/g, `
151
180
  `).replace(
152
181
  /\^\^订单备注-[\s\S]*?\^\^|<\{原话复述\}[^<>]*>/gu,
153
- (j) => j.replace(/\n/g, "")
182
+ (C) => C.replace(/\n/g, "")
154
183
  ).split(`
155
- `).forEach((j, U) => {
156
- U && p(!0), j = j.replace(/\uE000/g, `
184
+ `).forEach((C, J) => {
185
+ J && p(!0), C = C.replace(/\uE000/g, `
157
186
  `);
158
187
  let $ = 0;
159
- for (const b of j.matchAll(
188
+ for (const h of C.matchAll(
160
189
  /<\{原话复述\}([^<>]*)>|\{待办(?:@([^{}]+))?\}/gu
161
190
  )) {
162
- if (b[1] === void 0 && !o) continue;
163
- const x = b.index || 0;
164
- x > $ && f({ kind: "text", value: j.slice($, x) }), f(
165
- b[1] !== void 0 ? { kind: "originalReply", html: w(b[1]) } : { kind: "todo", value: b[0] }
166
- ), $ = x + b[0].length;
191
+ if (h[1] === void 0 && !s) continue;
192
+ const x = h.index || 0;
193
+ x > $ && y({ kind: "text", value: C.slice($, x) }), y(
194
+ h[1] !== void 0 ? { kind: "originalReply", html: A(h[1]) } : { kind: "todo", value: h[0] }
195
+ ), $ = x + h[0].length;
167
196
  }
168
- $ < j.length && f({ kind: "text", value: j.slice($) });
197
+ $ < C.length && y({ kind: "text", value: C.slice($) });
169
198
  });
170
199
  return;
171
200
  }
172
- if (m.nodeType !== 1) return;
173
- const n = m, r = n.tagName.toLowerCase(), u = pt(n);
174
- if (r === "span" && u === "original_repeat" && n.getAttribute("data-original-repeat-template") === "true") {
175
- const L = n.querySelectorAll('[data-original-repeat-input="true"]');
176
- if (L.length !== 1) {
177
- i = { path: s, message: "原话模板缺少唯一的回复输入区" };
201
+ if (k.nodeType !== 1) return;
202
+ const e = k, i = e.tagName.toLowerCase(), c = ot(e);
203
+ if (i === "span" && c === "original_repeat" && e.getAttribute("data-original-repeat-template") === "true") {
204
+ const N = e.querySelectorAll('[data-original-repeat-input="true"]');
205
+ if (N.length !== 1) {
206
+ l = { path: u, message: "原话模板缺少唯一的回复输入区" };
178
207
  return;
179
208
  }
180
- f({ kind: "originalReply", html: L[0].innerHTML });
209
+ y({ kind: "originalReply", html: N[0].innerHTML });
181
210
  return;
182
211
  }
183
- if (r === "span" && u) {
184
- if (u === "ticket") {
185
- const $ = (n.textContent || "").trim(), b = Nt($);
186
- !b || n.hasAttribute("data-ticket-id") && n.getAttribute("data-ticket-id") !== b.key || n.hasAttribute("data-ticket-name") && n.getAttribute("data-ticket-name") !== b.label || n.hasAttribute("data-ticket-protocol") && n.getAttribute("data-ticket-protocol") !== (((O = b.params) == null ? void 0 : O.protocol) || "current") || n.getAttribute("data-invalid") === "true" ? i = {
187
- path: s,
212
+ if (i === "span" && c) {
213
+ if (c === "ticket") {
214
+ const $ = (e.textContent || "").trim(), h = Bt($);
215
+ !h || e.hasAttribute("data-ticket-id") && e.getAttribute("data-ticket-id") !== h.key || e.hasAttribute("data-ticket-name") && e.getAttribute("data-ticket-name") !== h.label || e.hasAttribute("data-ticket-protocol") && e.getAttribute("data-ticket-protocol") !== (((E = h.params) == null ? void 0 : E.protocol) || "current") || e.getAttribute("data-invalid") === "true" ? l = {
216
+ path: u,
188
217
  message: "工单标签格式无效、引用已失效或属性与内容不一致"
189
- } : f({ kind: "text", value: $ });
218
+ } : y({ kind: "text", value: $ });
190
219
  return;
191
220
  }
192
- if (u === "external_method") {
193
- const $ = (n.textContent || "").trim(), b = St($);
194
- !b || ((P = b.attrs) == null ? void 0 : P.key) !== "external_method" || n.hasAttribute("data-scene-id") && n.getAttribute("data-scene-id") !== b.attrs.params.sceneId || n.hasAttribute("data-scene-name") && n.getAttribute("data-scene-name") !== b.attrs.params.sceneName || n.getAttribute("data-invalid") === "true" ? i = { path: s, message: "外部方法引用无效或属性与内容不一致" } : f({ kind: "text", value: $ });
221
+ if (c === "external_method") {
222
+ const $ = (e.textContent || "").trim(), h = St($);
223
+ !h || ((P = h.attrs) == null ? void 0 : P.key) !== "external_method" || e.hasAttribute("data-scene-id") && e.getAttribute("data-scene-id") !== h.attrs.params.sceneId || e.hasAttribute("data-scene-name") && e.getAttribute("data-scene-name") !== h.attrs.params.sceneName || e.getAttribute("data-invalid") === "true" ? l = { path: u, message: "外部方法引用无效或属性与内容不一致" } : y({ kind: "text", value: $ });
195
224
  return;
196
225
  }
197
- if (u === "no_send_follow_order") {
198
- i = { path: s, message: "旧不发送跟单标签尚无新知识节点承载" };
226
+ if (c === "no_send_follow_order") {
227
+ l = { path: u, message: "旧不发送跟单标签尚无新知识节点承载" };
199
228
  return;
200
229
  }
201
- if (u === "table_knowledge") {
202
- const $ = (n.textContent || "").trim(), b = n.getAttribute("data-table-name") || ((M = $.match(/^##([^#\r\n]+)##$/u)) == null ? void 0 : M[1]) || "";
203
- !b.trim() || /[#\r\n]/u.test(b) || $ && $ !== `##${b}##` || n.getAttribute("data-invalid") === "true" ? i = {
204
- path: s,
230
+ if (c === "table_knowledge") {
231
+ const $ = (e.textContent || "").trim(), h = e.getAttribute("data-table-name") || ((D = $.match(/^##([^#\r\n]+)##$/u)) == null ? void 0 : D[1]) || "";
232
+ !h.trim() || /[#\r\n]/u.test(h) || $ && $ !== `##${h}##` || e.getAttribute("data-invalid") === "true" ? l = {
233
+ path: u,
205
234
  message: "表格知识名称无效、与标签不一致或引用已失效"
206
- } : f({
235
+ } : y({
207
236
  kind: "tableKnowledge",
208
- name: b,
209
- key: n.getAttribute("data-table-id") || b
237
+ name: h,
238
+ key: e.getAttribute("data-table-id") || h
210
239
  });
211
240
  return;
212
241
  }
213
- if (u === "size_chart") {
214
- i = { path: s, message: `旧${u}标签尚无新知识节点承载` };
242
+ if (c === "size_chart") {
243
+ l = { path: u, message: `旧${c}标签尚无新知识节点承载` };
215
244
  return;
216
245
  }
217
- if (u === "biz_attribute") {
218
- const $ = (n.textContent || "").trim(), b = (_ = $.match(
246
+ if (c === "biz_attribute") {
247
+ const $ = (e.textContent || "").trim(), h = (_ = $.match(
219
248
  /^\{业务属性@([^{}<>\r\n]+)\}$/u
220
- )) == null ? void 0 : _[1], x = ((B = n.getAttribute("data-attr-name")) == null ? void 0 : B.trim()) || b, V = x && Dt(x, d);
221
- !V || $ !== x && $ !== Lt(x) || n.hasAttribute("data-attr-key") && n.getAttribute("data-attr-key") !== V.key || n.hasAttribute("data-attr-id") && n.getAttribute("data-attr-id") !== String(V.id) ? i = { path: s, message: "业务属性标签名称、ID 或 key 无效" } : f({ kind: "attribute", name: x, key: V.key });
249
+ )) == null ? void 0 : _[1], x = ((q = e.getAttribute("data-attr-name")) == null ? void 0 : q.trim()) || h, U = x && Rt(x, d);
250
+ !U || $ !== x && $ !== Nt(x) || e.hasAttribute("data-attr-key") && e.getAttribute("data-attr-key") !== U.key || e.hasAttribute("data-attr-id") && e.getAttribute("data-attr-id") !== String(U.id) ? l = { path: u, message: "业务属性标签名称、ID 或 key 无效" } : y({ kind: "attribute", name: x, key: U.key });
222
251
  return;
223
252
  }
224
- if (u === "small_payment" || u === "order_remark") {
225
- if (u === "order_remark" && n.hasAttribute("data-order-remark")) {
226
- const ot = Ht(
227
- n.getAttribute("data-order-remark") || ""
228
- ), st = ot && It(ot);
229
- st ? f({ kind: "text", value: st }) : i = { path: s, message: "旧订单备注数据无效" };
253
+ if (c === "small_payment" || c === "order_remark") {
254
+ if (c === "order_remark" && e.hasAttribute("data-order-remark")) {
255
+ const at = Pt(
256
+ e.getAttribute("data-order-remark") || ""
257
+ ), nt = at && Et(at);
258
+ nt ? y({ kind: "text", value: nt }) : l = { path: u, message: "旧订单备注数据无效" };
230
259
  return;
231
260
  }
232
- const $ = n.textContent || "", b = St($), x = (K = b == null ? void 0 : b.attrs) == null ? void 0 : K.params;
233
- (u === "small_payment" ? ((Y = b == null ? void 0 : b.attrs) == null ? void 0 : Y.key) === "small_payment" && n.getAttribute("data-max-amount-cent") === String(Number(x == null ? void 0 : x.amount) * 100) : ((at = b == null ? void 0 : b.attrs) == null ? void 0 : at.key) === "order_note" && n.getAttribute("data-remark-id") === (x == null ? void 0 : x.id) && n.getAttribute("data-remark-mode") === ((x == null ? void 0 : x.contentMode) === "fixed" ? "fixed" : "extract") && n.getAttribute("data-remark-flag") === (x == null ? void 0 : x.flag) && n.getAttribute("data-remark-keep-flag") === (x != null && x.preserveFlag ? "1" : "0") && n.getAttribute("data-remark-position") === (x == null ? void 0 : x.position) && n.getAttribute("data-remark-content") === (x == null ? void 0 : x.content)) ? f({ kind: "text", value: $ }) : i = { path: s, message: `${u} 标签属性与内容不一致` };
261
+ const $ = e.textContent || "", h = St($), x = (K = h == null ? void 0 : h.attrs) == null ? void 0 : K.params;
262
+ (c === "small_payment" ? ((F = h == null ? void 0 : h.attrs) == null ? void 0 : F.key) === "small_payment" && e.getAttribute("data-max-amount-cent") === String(Number(x == null ? void 0 : x.amount) * 100) : ((G = h == null ? void 0 : h.attrs) == null ? void 0 : G.key) === "order_note" && e.getAttribute("data-remark-id") === (x == null ? void 0 : x.id) && e.getAttribute("data-remark-mode") === ((x == null ? void 0 : x.contentMode) === "fixed" ? "fixed" : "extract") && e.getAttribute("data-remark-flag") === (x == null ? void 0 : x.flag) && e.getAttribute("data-remark-keep-flag") === (x != null && x.preserveFlag ? "1" : "0") && e.getAttribute("data-remark-position") === (x == null ? void 0 : x.position) && e.getAttribute("data-remark-content") === (x == null ? void 0 : x.content)) ? y({ kind: "text", value: $ }) : l = { path: u, message: `${c} 标签属性与内容不一致` };
234
263
  return;
235
264
  }
236
- if (u === "variable") {
237
- const $ = (n.textContent || "").trim(), b = (D = (rt = $.match(/^#([^#\r\n]+)#$/u)) == null ? void 0 : rt[1]) == null ? void 0 : D.trim(), V = ((et = n.getAttribute("data-variable-name")) == null ? void 0 : et.trim()) || b;
238
- !V || !b || b !== V ? i = { path: s, message: "变量标签名称与显示内容不一致" } : f({
265
+ if (c === "variable") {
266
+ const $ = (e.textContent || "").trim(), h = (O = (tt = $.match(/^#([^#\r\n]+)#$/u)) == null ? void 0 : tt[1]) == null ? void 0 : O.trim(), U = ((Y = e.getAttribute("data-variable-name")) == null ? void 0 : Y.trim()) || h;
267
+ !U || !h || h !== U ? l = { path: u, message: "变量标签名称与显示内容不一致" } : y({
239
268
  kind: "text",
240
- value: V === "订单链接" ? "{订单链接}" : $
269
+ value: U === "订单链接" ? "{订单链接}" : $
241
270
  });
242
271
  return;
243
272
  }
244
- const L = n.getAttribute("data-tag-name") || n.getAttribute("data-variable-name") || n.getAttribute("data-agent-name") || "", j = n.textContent || "";
245
- if (u === "cdp_tag" && (!n.getAttribute("data-tag-id") || /已失效/u.test(j))) {
246
- i = { path: s, message: "失效顾客标签需要只读保全" };
273
+ const N = e.getAttribute("data-tag-name") || e.getAttribute("data-variable-name") || e.getAttribute("data-agent-name") || "", C = e.textContent || "";
274
+ if (c === "cdp_tag" && (!e.getAttribute("data-tag-id") || /已失效/u.test(C))) {
275
+ l = { path: u, message: "失效顾客标签需要只读保全" };
247
276
  return;
248
277
  }
249
- if (u === "todo" || u === "cdp_tag") {
250
- const $ = (H = j.match(
251
- u === "todo" ? /\{待办@([^{}]+)\}/u : /\{(?:顾客标签|意图标签)@([^{}]+)\}/u
252
- )) == null ? void 0 : H[1], b = n.getAttribute("data-tag-name");
253
- if ($ && b && $ !== b) {
254
- i = { path: s, message: `${u} 标签名称与显示内容不一致` };
278
+ if (c === "todo" || c === "cdp_tag") {
279
+ const $ = (H = C.match(
280
+ c === "todo" ? /\{待办@([^{}]+)\}/u : /\{(?:顾客标签|意图标签)@([^{}]+)\}/u
281
+ )) == null ? void 0 : H[1], h = e.getAttribute("data-tag-name");
282
+ if ($ && h && $ !== h) {
283
+ l = { path: u, message: `${c} 标签名称与显示内容不一致` };
255
284
  return;
256
285
  }
257
286
  }
258
- const U = {
259
- todo: ((Z = j.match(/\{待办(?:@[^{}]+)?\}/u)) == null ? void 0 : Z[0]) || (L ? `{待办@${L}}` : ""),
260
- cdp_tag: ((W = j.match(/\{(?:顾客标签|意图标签)@[^{}]+\}/u)) == null ? void 0 : W[0]) || (L ? `{顾客标签@${L}}` : ""),
287
+ const J = {
288
+ todo: ((Q = C.match(/\{待办(?:@[^{}]+)?\}/u)) == null ? void 0 : Q[0]) || (N ? `{待办@${N}}` : ""),
289
+ cdp_tag: ((j = C.match(/\{(?:顾客标签|意图标签)@[^{}]+\}/u)) == null ? void 0 : j[0]) || (N ? `{顾客标签@${N}}` : ""),
261
290
  separator: "{分隔符}",
262
291
  original_repeat: "{原话复述}",
263
- custom_agent: ((it = j.match(/\{自定义Agent\}@[\s\S]+/u)) == null ? void 0 : it[0]) || (L ? `{自定义Agent}@${L}` : ""),
292
+ custom_agent: ((et = C.match(/\{自定义Agent\}@[\s\S]+/u)) == null ? void 0 : et[0]) || (N ? `{自定义Agent}@${N}` : ""),
264
293
  reasoning: "{推理}",
265
294
  memory_trigger: "{记忆触发点}"
266
295
  };
267
- U[u] ? f({
268
- kind: u === "todo" ? "todo" : "text",
269
- value: U[u]
270
- }) : i = { path: s, message: `旧标签 ${u} 无法映射到新模型` };
296
+ J[c] ? y({
297
+ kind: c === "todo" ? "todo" : "text",
298
+ value: J[c]
299
+ }) : l = { path: u, message: `旧标签 ${c} 无法映射到新模型` };
271
300
  return;
272
301
  }
273
- if (r === "img" && n.getAttribute("data-tag-icon") === "true") return;
274
- if (r === "img" || r === "video") {
275
- const L = n.getAttribute("src") || "";
276
- wt(L) ? f({
302
+ if (i === "img" && e.getAttribute("data-tag-icon") === "true") return;
303
+ if (i === "img" || i === "video") {
304
+ const N = e.getAttribute("src") || "";
305
+ wt(N) ? y({
277
306
  kind: "media",
278
- media: r === "img" ? "image" : "video",
279
- src: L,
280
- path: s
281
- }) : i = { path: s, message: "媒体地址无效" };
307
+ media: i === "img" ? "image" : "video",
308
+ src: N,
309
+ path: u,
310
+ metadata: Object.fromEntries(
311
+ [
312
+ ["assetId", e.getAttribute("data-asset-id")],
313
+ ["name", e.getAttribute("data-media-name")],
314
+ ["poster", e.getAttribute("poster")]
315
+ ].filter((C) => C[1] !== null)
316
+ )
317
+ }) : l = { path: u, message: "媒体地址无效" };
282
318
  return;
283
319
  }
284
- const q = {
320
+ const I = {
285
321
  b: "bold",
286
322
  strong: "bold",
287
323
  i: "italic",
@@ -291,78 +327,83 @@ function ht(t, o = !1, d = _t) {
291
327
  strike: "strike",
292
328
  del: "strike",
293
329
  code: "code"
294
- }[r];
295
- if (q || r === "a") {
296
- const L = g, j = n.getAttribute("href");
297
- if (r === "a" && j && !wt(j)) {
298
- i = { path: s, message: "链接地址无效" };
330
+ }[i];
331
+ if (I || i === "a") {
332
+ const N = g, C = e.getAttribute("href");
333
+ if (i === "a" && C && !wt(C)) {
334
+ l = { path: u, message: "链接地址无效" };
299
335
  return;
300
336
  }
301
- const U = q ? { type: q } : j ? {
337
+ const J = I ? { type: I } : C ? {
302
338
  type: "link",
303
339
  attrs: Object.fromEntries(
304
- ["href", "target", "rel", "title", "class"].filter(($) => n.hasAttribute($)).map(($) => [$, n.getAttribute($)])
340
+ ["href", "target", "rel", "title", "class"].filter(($) => e.hasAttribute($)).map(($) => [$, e.getAttribute($)])
305
341
  )
306
342
  } : null;
307
- U && !g.some(($) => $.type === U.type) && (g = [...g, U]), Array.from(n.childNodes).forEach(
308
- ($, b) => y($, `${s}.childNodes[${b}]`)
309
- ), g = L;
343
+ J && !g.some(($) => $.type === J.type) && (g = [...g, J]), Array.from(e.childNodes).forEach(
344
+ ($, h) => b($, `${u}.childNodes[${h}]`)
345
+ ), g = N;
310
346
  return;
311
347
  }
312
- if (["ul", "ol", "blockquote", "pre"].includes(r)) {
313
- p(), f({ kind: "block", tag: r, html: n.outerHTML }), p(!0);
348
+ if (["ul", "ol", "blockquote", "pre", "hr"].includes(i)) {
349
+ p(), y({ kind: "block", tag: i, html: e.outerHTML }), p(!0);
314
350
  return;
315
351
  }
316
- if (r === "br") {
352
+ if (i === "br") {
353
+ if (e.getAttribute("data-hard-break") === "true") {
354
+ y({ kind: "hardBreak" });
355
+ return;
356
+ }
317
357
  p(!0);
318
358
  return;
319
359
  }
320
- if (!["p", "div", "span"].includes(r) || r === "span" && n.attributes.length > 0) {
321
- i = { path: s, message: `HTML 标签 ${r} 无法无损转换` };
360
+ if (!["p", "div", "span"].includes(i) || i === "span" && e.attributes.length > 0) {
361
+ l = { path: u, message: `HTML 标签 ${i} 无法无损转换` };
322
362
  return;
323
363
  }
324
- (r === "p" || r === "div") && p();
325
- const z = a.length;
326
- Array.from(n.childNodes).forEach(
327
- (L, j) => y(L, `${s}.childNodes[${j}]`)
328
- ), (r === "p" || r === "div") && (a.length === z || a[a.length - 1].length) && p(!0);
364
+ (i === "p" || i === "div") && p();
365
+ const z = r.length;
366
+ Array.from(e.childNodes).forEach(
367
+ (N, C) => b(N, `${u}.childNodes[${C}]`)
368
+ ), (i === "p" || i === "div") && (r.length === z || r[r.length - 1].length) && p(!0);
329
369
  };
330
370
  return Array.from(S.body.childNodes).forEach(
331
- (m, s) => y(m, `web_content.childNodes[${s}]`)
332
- ), i ? { ok: !1, issues: [i], raw: t } : (a.length > 1 && !a[a.length - 1].length && a.pop(), { ok: !0, value: a });
371
+ (k, u) => b(k, `web_content.childNodes[${u}]`)
372
+ ), l ? { ok: !1, issues: [l], raw: t } : (r.length > 1 && !r[r.length - 1].length && !t.endsWith(`
373
+ `) && r.pop(), { ok: !0, value: r });
333
374
  }
334
375
  function bt(t) {
335
376
  return t.every(
336
- (o) => o.kind === "text" || o.kind === "todo" || o.kind === "attribute" || o.kind === "tableKnowledge"
377
+ (s) => s.kind === "text" || s.kind === "todo" || s.kind === "attribute" || s.kind === "tableKnowledge"
337
378
  ) ? t.map(
338
- (o) => o.kind === "tableKnowledge" ? `##${o.name}##` : o.kind === "attribute" ? Lt(o.name) : o.value
379
+ (s) => s.kind === "tableKnowledge" ? `##${s.name}##` : s.kind === "attribute" ? Nt(s.name) : s.value
339
380
  ).join("") : null;
340
381
  }
341
- function Qt(t, o, d, S) {
342
- var f, p;
343
- const a = [], i = /(#@[^#]+@#|##[^#]+##|#[^#\r\n]+#|\{[^{}]+\}|\[sep\]|\$\$小额打款@[^$\r\n]*\$\$|\^\^订单备注-[\s\S]*?\^\^)/gu;
382
+ function Xt(t, s, d, S) {
383
+ var y, p;
384
+ const r = [], l = /(#@[^#]+@#|##[^#]+##|#[^#\r\n]+#|\{[^{}]+\}|\[sep\]|\$\$小额打款@[^$\r\n]*\$\$|\^\^订单备注-[\s\S]*?\^\^)/gu;
344
385
  let g = 0;
345
- for (const y of t.matchAll(i)) {
346
- const m = y.index || 0;
347
- if (m > g) {
348
- const n = t.slice(g, m);
386
+ for (const b of t.matchAll(l)) {
387
+ const k = b.index || 0;
388
+ if (k > g) {
389
+ const e = t.slice(g, k);
349
390
  if (/\$\$小额打款|\^\^订单备注-|\{业务属性@|\{(?:智能建单|智能工单|外部方法)@|<不发送跟单>/u.test(
350
- n
391
+ e
351
392
  ))
352
- return c(t, o, "工具、业务属性或不发送跟单标记格式错误");
353
- a.push({ type: "text", text: n });
393
+ return f(t, s, "工具、业务属性或不发送跟单标记格式错误");
394
+ r.push({ type: "text", text: e });
354
395
  }
355
- const s = y[0];
356
- if (/^\{智能(?:建单|工单)/u.test(s)) {
357
- const n = Nt(s);
358
- if (!n) return c(t, o, `工单标记 ${s} 格式错误`);
359
- a.push({ type: "businessToken", attrs: { kind: "ticket", ...n } });
360
- } else if (s.startsWith("$$小额打款@") || s.startsWith("^^订单备注-") || s.startsWith("{外部方法")) {
361
- const n = St(s);
362
- if (!n) return c(t, o, `工具标记 ${s} 格式错误`);
363
- a.push(n);
364
- } else if (s === "{分隔符}" || s === "[sep]")
365
- a.push({
396
+ const u = b[0];
397
+ if (/^\{智能(?:建单|工单)/u.test(u)) {
398
+ const e = Bt(u);
399
+ if (!e) return f(t, s, `工单标记 ${u} 格式错误`);
400
+ r.push({ type: "businessToken", attrs: { kind: "ticket", ...e } });
401
+ } else if (u.startsWith("$$小额打款@") || u.startsWith("^^订单备注-") || u.startsWith("{外部方法")) {
402
+ const e = St(u);
403
+ if (!e) return f(t, s, `工具标记 ${u} 格式错误`);
404
+ r.push(e);
405
+ } else if (u === "{分隔符}" || u === "[sep]")
406
+ r.push({
366
407
  type: "businessToken",
367
408
  attrs: {
368
409
  kind: "separator",
@@ -371,256 +412,256 @@ function Qt(t, o, d, S) {
371
412
  token: "{分隔符}"
372
413
  }
373
414
  });
374
- else if (/^##[^#\r\n]+##$/u.test(s)) {
375
- const n = s.slice(2, -2);
376
- if (!n.trim()) return c(t, o, "表格知识名称不能为空");
377
- a.push({
415
+ else if (/^##[^#\r\n]+##$/u.test(u)) {
416
+ const e = u.slice(2, -2);
417
+ if (!e.trim()) return f(t, s, "表格知识名称不能为空");
418
+ r.push({
378
419
  type: "businessToken",
379
- attrs: { kind: "tableKnowledge", key: n, label: n }
420
+ attrs: { kind: "tableKnowledge", key: e, label: e }
380
421
  });
381
- } else if (s === "{订单链接}" || /^#[^#\r\n]+#$/u.test(s)) {
382
- const n = s === "{订单链接}" ? "订单链接" : s.slice(1, -1).trim(), r = (f = d.variable) == null ? void 0 : f.call(d, n);
383
- if (!n || !(r != null && r.key) || r.label !== n)
384
- return c(t, o, `变量 ${n} 缺少可解析的引用`);
385
- a.push({
422
+ } else if (u === "{订单链接}" || /^#[^#\r\n]+#$/u.test(u)) {
423
+ const e = u === "{订单链接}" ? "订单链接" : u.slice(1, -1).trim(), i = (y = d.variable) == null ? void 0 : y.call(d, e);
424
+ if (!e || !(i != null && i.key) || i.label !== e)
425
+ return f(t, s, `变量 ${e} 缺少可解析的引用`);
426
+ r.push({
386
427
  type: "businessToken",
387
- attrs: { kind: "variable", key: r.key, label: r.label, token: s }
428
+ attrs: { kind: "variable", key: i.key, label: i.label, token: u }
388
429
  });
389
- } else if (s.startsWith("{业务属性@")) {
390
- const n = (p = s.match(/^\{业务属性@([^{}<>\r\n]+)\}$/u)) == null ? void 0 : p[1], r = n && Dt(n, S);
391
- if (!r)
392
- return c(t, o, `业务属性 ${n || s} 不在旧目录中`);
393
- a.push({
430
+ } else if (u.startsWith("{业务属性@")) {
431
+ const e = (p = u.match(/^\{业务属性@([^{}<>\r\n]+)\}$/u)) == null ? void 0 : p[1], i = e && Rt(e, S);
432
+ if (!i)
433
+ return f(t, s, `业务属性 ${e || u} 不在旧目录中`);
434
+ r.push({
394
435
  type: "businessToken",
395
- attrs: { kind: "attribute", key: r.key, label: r.name }
436
+ attrs: { kind: "attribute", key: i.key, label: i.name }
396
437
  });
397
438
  } else {
398
439
  if (/^\{(?:待办|原话复述|推理|记忆触发点|顾客标签|意图标签|自定义Agent)/u.test(
399
- s
400
- ) || s.startsWith("#@"))
401
- return c(t, o, `正文标记 ${s} 无法在当前位置转换`);
402
- a.push({ type: "text", text: s });
440
+ u
441
+ ) || u.startsWith("#@"))
442
+ return f(t, s, `正文标记 ${u} 无法在当前位置转换`);
443
+ r.push({ type: "text", text: u });
403
444
  }
404
- g = m + s.length;
445
+ g = k + u.length;
405
446
  }
406
447
  if (g < t.length) {
407
- const y = t.slice(g);
448
+ const b = t.slice(g);
408
449
  if (/\$\$小额打款|\^\^订单备注-|\{业务属性@|\{(?:智能建单|智能工单|外部方法)@|<不发送跟单>/u.test(
409
- y
450
+ b
410
451
  ))
411
- return c(t, o, "工具、业务属性或不发送跟单标记格式错误");
412
- a.push({ type: "text", text: y });
452
+ return f(t, s, "工具、业务属性或不发送跟单标记格式错误");
453
+ r.push({ type: "text", text: b });
413
454
  }
414
- return { ok: !0, value: a };
455
+ return { ok: !0, value: r };
415
456
  }
416
- function Rt(t, o) {
457
+ function Dt(t, s) {
417
458
  const d = /* @__PURE__ */ new Set();
418
- let S = 0, a = null;
419
- const i = (g, f) => {
420
- var p, y, m;
421
- if (g.type === "businessToken" && ((p = g.attrs) == null ? void 0 : p.kind) === "tool" && (g.attrs.key === "small_payment" && ++S > 1 && (a = f), g.attrs.key === "order_note")) {
422
- const s = String(((y = g.attrs.params) == null ? void 0 : y.id) || "");
423
- d.has(s) && (a = f), d.add(s);
459
+ let S = 0, r = null;
460
+ const l = (g, y) => {
461
+ var p, b, k;
462
+ if (g.type === "businessToken" && ((p = g.attrs) == null ? void 0 : p.kind) === "tool" && (g.attrs.key === "small_payment" && ++S > 1 && (r = y), g.attrs.key === "order_note")) {
463
+ const u = String(((b = g.attrs.params) == null ? void 0 : b.id) || "");
464
+ d.has(u) && (r = y), d.add(u);
424
465
  }
425
- (m = g.content) == null || m.forEach(
426
- (s, n) => i(s, `${f}.content[${n}]`)
466
+ (k = g.content) == null || k.forEach(
467
+ (u, e) => l(u, `${y}.content[${e}]`)
427
468
  );
428
469
  };
429
- return t.forEach((g, f) => i(g, `${o}[${f}]`)), a;
470
+ return t.forEach((g, y) => l(g, `${s}[${y}]`)), r;
430
471
  }
431
- function Xt(t) {
432
- var o, d, S, a, i;
472
+ function Yt(t) {
473
+ var s, d, S, r, l;
433
474
  for (let g = 0; g < t.length; g++) {
434
- const f = t[g], p = (o = f.content) == null ? void 0 : o[0];
435
- if (f.type !== "paragraph" || ((d = f.content) == null ? void 0 : d.length) !== 1 || (p == null ? void 0 : p.type) !== "businessToken" || ((S = p.attrs) == null ? void 0 : S.kind) !== "separator")
475
+ const y = t[g], p = (s = y.content) == null ? void 0 : s[0];
476
+ if (y.type !== "paragraph" || ((d = y.content) == null ? void 0 : d.length) !== 1 || (p == null ? void 0 : p.type) !== "businessToken" || ((S = p.attrs) == null ? void 0 : S.kind) !== "separator")
436
477
  continue;
437
- const y = t[g - 1], m = t[g + 1];
438
- if ((y == null ? void 0 : y.type) === "paragraph" && ((a = y.content) != null && a.length))
439
- y.content.push(p);
440
- else if ((m == null ? void 0 : m.type) === "paragraph" && ((i = m.content) != null && i.length))
441
- m.content.unshift(p);
478
+ const b = t[g - 1], k = t[g + 1];
479
+ if ((b == null ? void 0 : b.type) === "paragraph" && ((r = b.content) != null && r.length))
480
+ b.content.push(p);
481
+ else if ((k == null ? void 0 : k.type) === "paragraph" && ((l = k.content) != null && l.length))
482
+ k.content.unshift(p);
442
483
  else continue;
443
484
  t.splice(g--, 1);
444
485
  }
445
486
  }
446
- function qt(t, o, d = {}, S = {}) {
447
- var yt, v, A, N, J, G, nt, lt, kt;
487
+ function It(t, s, d = {}, S = {}) {
488
+ var ut, dt, gt, ct, pt, ft, mt, yt, kt;
448
489
  if (!t || typeof t != "object" || Array.isArray(t))
449
- return c(t, "item", "旧知识记录格式不正确");
450
- if (!(o != null && o.trim()))
451
- return c(t, "sourceRecordKey", "需要稳定的来源记录键");
452
- const a = S.businessAttributes ?? _t;
453
- if (!Ot(a))
454
- return c(
490
+ return f(t, "item", "旧知识记录格式不正确");
491
+ if (!(s != null && s.trim()))
492
+ return f(t, "sourceRecordKey", "需要稳定的来源记录键");
493
+ const r = S.businessAttributes ?? _t;
494
+ if (!Ot(r))
495
+ return f(
455
496
  t,
456
497
  "businessAttributes",
457
498
  "业务属性目录格式无效或存在重复引用"
458
499
  );
459
- const i = typeof t.web_content == "string" && t.web_content ? "web_content" : "content", g = t[i];
460
- if (typeof g != "string") return c(t, i, "旧知识缺少内容");
461
- const f = !!String(t.todo_plan_id || "").trim() || !!t.todo_tag_metas, p = i === "content" ? Ct(g) : g, y = ht(p, f, a);
462
- if (!y.ok) return { ...y, raw: t };
463
- const m = y.value, s = m[0] || [], n = s.findIndex(
464
- (e) => e.kind === "originalReply" || e.kind === "media" || e.kind === "tableKnowledge"
465
- ), r = bt(
466
- n >= 0 ? s.slice(0, n) : s
467
- ), u = r == null ? void 0 : r.match(/^\s*【([^【】\r\n]*)】([\s\S]*)$/u), q = u ? u[1] : S.questionText ?? "";
468
- if (Mt(q))
469
- return c(t, "questionText", "顾客问法包含保留分隔符");
470
- const z = new DOMParser().parseFromString(p, "text/html"), O = Array.from(
500
+ const l = typeof t.web_content == "string" && t.web_content ? "web_content" : "content", g = t[l];
501
+ if (typeof g != "string") return f(t, l, "旧知识缺少内容");
502
+ const y = !!String(t.todo_plan_id || "").trim() || !!t.todo_tag_metas, p = l === "content" ? Lt(g) : g, b = ht(p, y, r);
503
+ if (!b.ok) return { ...b, raw: t };
504
+ const k = b.value, u = k[0] || [], e = u.findIndex(
505
+ (n) => n.kind === "originalReply" || n.kind === "media" || n.kind === "tableKnowledge"
506
+ ), i = bt(
507
+ e >= 0 ? u.slice(0, e) : u
508
+ ), c = i == null ? void 0 : i.match(/^\s*【([^【】\r\n]*)】([\s\S]*)$/u), I = c ? c[1] : S.questionText ?? "";
509
+ if (zt(I))
510
+ return f(t, "questionText", "顾客问法包含保留分隔符");
511
+ const z = new DOMParser().parseFromString(p, "text/html"), E = Array.from(
471
512
  z.querySelectorAll('span[data-tag-type="todo"], span[data-tag="true"]')
472
- ).filter((e) => pt(e) === "todo").map(
473
- (e) => {
474
- var l;
475
- return ((l = (e.textContent || "").match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : l[1]) || e.getAttribute("data-tag-name") || "";
513
+ ).filter((n) => ot(n) === "todo").map(
514
+ (n) => {
515
+ var a;
516
+ return ((a = (n.textContent || "").match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : a[1]) || n.getAttribute("data-tag-name") || "";
476
517
  }
477
518
  );
478
- f && O.push(
479
- ...Array.from(g.matchAll(/\{待办@([^{}]+)\}/gu), (e) => e[1])
519
+ y && E.push(
520
+ ...Array.from(g.matchAll(/\{待办@([^{}]+)\}/gu), (n) => n[1])
480
521
  );
481
522
  const P = Array.from(
482
523
  z.querySelectorAll('span[data-tag-type="cdp_tag"]')
483
- ).map((e) => {
484
- var l;
524
+ ).map((n) => {
525
+ var a;
485
526
  return {
486
- name: ((l = (e.textContent || "").match(
527
+ name: ((a = (n.textContent || "").match(
487
528
  /\{(?:顾客标签|意图标签)@([^{}]+)\}/u
488
- )) == null ? void 0 : l[1]) || e.getAttribute("data-tag-name") || "",
489
- id: e.getAttribute("data-tag-id") || ""
529
+ )) == null ? void 0 : a[1]) || n.getAttribute("data-tag-name") || "",
530
+ id: n.getAttribute("data-tag-id") || ""
490
531
  };
491
532
  });
492
- if ((yt = z.body.textContent) != null && yt.includes("{待办}") && O.push("默认"), i === "content" && Array.isArray(t.tag_meta))
493
- for (const e of t.tag_meta) {
494
- const l = e;
495
- (l == null ? void 0 : l.type) === "cdp_tag" && typeof l.name == "string" && /\{(?:顾客标签|意图标签)@[^{}]+\}/u.test(g) && (g.includes(`{顾客标签@${l.name}}`) || g.includes(`{意图标签@${l.name}}`)) && P.push({ name: l.name, id: String(l.value || "") });
533
+ if ((ut = z.body.textContent) != null && ut.includes("{待办}") && E.push("默认"), l === "content" && Array.isArray(t.tag_meta))
534
+ for (const n of t.tag_meta) {
535
+ const a = n;
536
+ (a == null ? void 0 : a.type) === "cdp_tag" && typeof a.name == "string" && /\{(?:顾客标签|意图标签)@[^{}]+\}/u.test(g) && (g.includes(`{顾客标签@${a.name}}`) || g.includes(`{意图标签@${a.name}}`)) && P.push({ name: a.name, id: String(a.value || "") });
496
537
  }
497
538
  if (P.length > 1)
498
- return c(t, i, "新模型每条问法只能选择一个顾客标签");
499
- const M = /* @__PURE__ */ new Map();
500
- for (const [e, l] of Array.from(
539
+ return f(t, l, "新模型每条问法只能选择一个顾客标签");
540
+ const D = /* @__PURE__ */ new Map();
541
+ for (const [n, a] of Array.from(
501
542
  z.querySelectorAll('span[data-tag-type="todo"], span[data-tag="true"]')
502
543
  ).entries()) {
503
- if (pt(l) !== "todo") continue;
504
- const k = (v = l.getAttribute("plan_id")) == null ? void 0 : v.trim();
505
- if (!k) continue;
506
- const h = ((A = (l.textContent || "").match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : A[1]) || l.getAttribute("data-tag-name") || "";
507
- if (!h)
508
- return c(t, `${i}.todo[${e}]`, "待办标签缺少方案名称");
509
- const T = M.get(h);
510
- if (T && T.id !== k)
511
- return c(
544
+ if (ot(a) !== "todo") continue;
545
+ const o = (dt = a.getAttribute("plan_id")) == null ? void 0 : dt.trim();
546
+ if (!o) continue;
547
+ const m = ((gt = (a.textContent || "").match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : gt[1]) || a.getAttribute("data-tag-name") || "";
548
+ if (!m)
549
+ return f(t, `${l}.todo[${n}]`, "待办标签缺少方案名称");
550
+ const v = D.get(m);
551
+ if (v && v.id !== o)
552
+ return f(
512
553
  t,
513
- `${i}.todo[${e}]`,
554
+ `${l}.todo[${n}]`,
514
555
  "同名待办对应多个方案 ID"
515
556
  );
516
- M.set(h, { id: k, label: h });
557
+ D.set(m, { id: o, label: m });
517
558
  }
518
559
  if (t.todo_tag_metas !== void 0 && t.todo_tag_metas !== "") {
519
- let e = t.todo_tag_metas;
520
- if (typeof e == "string")
560
+ let n = t.todo_tag_metas;
561
+ if (typeof n == "string")
521
562
  try {
522
- e = JSON.parse(e);
563
+ n = JSON.parse(n);
523
564
  } catch {
524
- return c(t, "todo_tag_metas", "待办方案元数据不是有效 JSON");
565
+ return f(t, "todo_tag_metas", "待办方案元数据不是有效 JSON");
525
566
  }
526
- if (!Array.isArray(e))
527
- return c(t, "todo_tag_metas", "待办方案元数据必须为数组");
528
- for (const [l, k] of e.entries()) {
529
- if (!k || typeof k != "object" || typeof k.plan_id != "string" || !k.plan_id.trim() || typeof k.plan_name != "string" || !k.plan_name.trim() || k.tag_type !== void 0 && k.tag_type !== 2)
530
- return c(
567
+ if (!Array.isArray(n))
568
+ return f(t, "todo_tag_metas", "待办方案元数据必须为数组");
569
+ for (const [a, o] of n.entries()) {
570
+ if (!o || typeof o != "object" || typeof o.plan_id != "string" || !o.plan_id.trim() || typeof o.plan_name != "string" || !o.plan_name.trim() || o.tag_type !== void 0 && o.tag_type !== 2)
571
+ return f(
531
572
  t,
532
- `todo_tag_metas[${l}]`,
573
+ `todo_tag_metas[${a}]`,
533
574
  "待办方案缺少有效 ID、名称或已失效"
534
575
  );
535
- const h = M.get(k.plan_name);
536
- if (h && h.id !== k.plan_id)
537
- return c(
576
+ const m = D.get(o.plan_name);
577
+ if (m && m.id !== o.plan_id)
578
+ return f(
538
579
  t,
539
- `todo_tag_metas[${l}]`,
580
+ `todo_tag_metas[${a}]`,
540
581
  "待办方案元数据与富文本标签的 plan_id 不一致"
541
582
  );
542
- M.set(k.plan_name, {
543
- id: k.plan_id,
544
- label: k.plan_name
583
+ D.set(o.plan_name, {
584
+ id: o.plan_id,
585
+ label: o.plan_name
545
586
  });
546
587
  }
547
588
  }
548
589
  if (String(t.todo_plan_id || "").trim() && typeof t.todo_plan_name == "string") {
549
- const e = M.get(t.todo_plan_name);
550
- if (e && e.id !== String(t.todo_plan_id))
551
- return c(t, "todo_plan_id", "待办方案字段与多方案元数据不一致");
552
- M.set(t.todo_plan_name, {
590
+ const n = D.get(t.todo_plan_name);
591
+ if (n && n.id !== String(t.todo_plan_id))
592
+ return f(t, "todo_plan_id", "待办方案字段与多方案元数据不一致");
593
+ D.set(t.todo_plan_name, {
553
594
  id: String(t.todo_plan_id),
554
595
  label: t.todo_plan_name
555
596
  });
556
597
  }
557
- const _ = {}, B = !u && r && /^(?:\{(?:待办|顾客标签|意图标签)@[^{}]+\}|\{(?:原话复述|记忆触发点|推理)\})+$/u.test(
558
- r.trim()
598
+ const _ = {}, q = !c && i && /^(?:\{(?:待办|顾客标签|意图标签)@[^{}]+\}|\{(?:原话复述|记忆触发点|推理)\})+$/u.test(
599
+ i.trim()
559
600
  ), K = [];
560
- let Y = !1, at = "", rt = "", D = (u == null ? void 0 : u[2].trim()) || (B ? r.trim() : "");
561
- for (; D; ) {
562
- if (D.startsWith("{待办}")) {
563
- K.push({ kind: "todo", value: "{待办}" }), D = D.slice(4).trimStart();
601
+ let F = !1, G = "", tt = "", O = (c == null ? void 0 : c[2].trim()) || (q ? i.trim() : "");
602
+ for (; O; ) {
603
+ if (O.startsWith("{待办}")) {
604
+ K.push({ kind: "todo", value: "{待办}" }), O = O.slice(4).trimStart();
564
605
  continue;
565
606
  }
566
- if (/^\{(?:智能建单|智能工单|外部方法)@/u.test(D)) {
567
- at = D;
607
+ if (/^\{(?:智能建单|智能工单|外部方法)@/u.test(O)) {
608
+ G = O;
568
609
  break;
569
610
  }
570
- if (D.startsWith("{自定义Agent}@")) {
571
- if (rt) return c(t, i, "Agent 标记重复");
572
- const l = D, h = Array.from(z.querySelectorAll("span")).filter((T) => pt(T) === "custom_agent").map((T) => (T.textContent || "").trim()).find(
573
- (T) => T.startsWith("{自定义Agent}@") && l.startsWith(T)
574
- ) || ((N = D.match(/^\{自定义Agent\}@[^{}]+/u)) == null ? void 0 : N[0]);
575
- if (!h) return c(t, i, "Agent 名称为空");
576
- rt = h.trim(), D = D.slice(h.length).trimStart();
611
+ if (O.startsWith("{自定义Agent}@")) {
612
+ if (tt) return f(t, l, "Agent 标记重复");
613
+ const a = O, m = Array.from(z.querySelectorAll("span")).filter((v) => ot(v) === "custom_agent").map((v) => (v.textContent || "").trim()).find(
614
+ (v) => v.startsWith("{自定义Agent}@") && a.startsWith(v)
615
+ ) || ((ct = O.match(/^\{自定义Agent\}@[^{}]+/u)) == null ? void 0 : ct[0]);
616
+ if (!m) return f(t, l, "Agent 名称为空");
617
+ tt = m.trim(), O = O.slice(m.length).trimStart();
577
618
  continue;
578
619
  }
579
- const e = D.match(
620
+ const n = O.match(
580
621
  /^\{(待办|顾客标签|意图标签)@([^{}]+)\}|^\{(原话复述|记忆触发点|推理)\}/u
581
622
  );
582
- if (!e) {
583
- if (D.startsWith("{"))
584
- return c(t, i, `问法后的标记无法转换:${D}`);
585
- at = D;
623
+ if (!n) {
624
+ if (O.startsWith("{"))
625
+ return f(t, l, `问法后的标记无法转换:${O}`);
626
+ G = O;
586
627
  break;
587
628
  }
588
- if (e[1]) {
589
- const l = e[1] === "待办" ? "todo" : "tagged", k = l === "todo" ? O.find((E) => E === e[2]) : P.find((E) => E.name === e[2]);
590
- if (!k)
591
- return c(
629
+ if (n[1]) {
630
+ const a = n[1] === "待办" ? "todo" : "tagged", o = a === "todo" ? E.find((T) => T === n[2]) : P.find((T) => T.name === n[2]);
631
+ if (!o)
632
+ return f(
592
633
  t,
593
- i,
594
- `${e[1]} ${e[2]} 不是有效的旧版富文本标签`
634
+ l,
635
+ `${n[1]} ${n[2]} 不是有效的旧版富文本标签`
595
636
  );
596
- const h = l === "todo" && t.todo_plan_name === e[2] ? String(t.todo_plan_id || "") : l === "tagged" ? k.id : "", T = l === "todo" && M.has(e[2]) ? M.get(e[2]) : h ? { id: h, label: e[2] } : (J = d.selection) == null ? void 0 : J.call(d, l, e[2]);
597
- if (!(T != null && T.id) || !T.label || T.label !== e[2])
598
- return c(
637
+ const m = a === "todo" && t.todo_plan_name === n[2] ? String(t.todo_plan_id || "") : a === "tagged" ? o.id : "", v = a === "todo" && D.has(n[2]) ? D.get(n[2]) : m ? { id: m, label: n[2] } : (pt = d.selection) == null ? void 0 : pt.call(d, a, n[2]);
638
+ if (!(v != null && v.id) || !v.label || v.label !== n[2])
639
+ return f(
599
640
  t,
600
- i,
601
- `${e[1]} ${e[2]} 缺少匹配的方案 ID`
641
+ l,
642
+ `${n[1]} ${n[2]} 缺少匹配的方案 ID`
602
643
  );
603
- if (l === "todo")
604
- K.push({ kind: "todo", value: e[0] });
644
+ if (a === "todo")
645
+ K.push({ kind: "todo", value: n[0] });
605
646
  else {
606
- if (_[l]) return c(t, i, `${e[1]}重复`);
607
- _[l] = { version: 1, data: { enabled: !0, tag: T } };
647
+ if (_[a]) return f(t, l, `${n[1]}重复`);
648
+ _[a] = { version: 1, data: { enabled: !0, tag: v } };
608
649
  }
609
- } else if (e[3] === "推理") {
610
- if (Y) return c(t, i, "推理标记重复");
611
- Y = !0;
650
+ } else if (n[3] === "推理") {
651
+ if (F) return f(t, l, "推理标记重复");
652
+ F = !0;
612
653
  } else {
613
- const l = e[3] === "原话复述" ? "originalReply" : "memory";
614
- if (_[l]) return c(t, i, `${e[3]}重复`);
615
- _[l] = { version: 1, data: { enabled: !0 } };
654
+ const a = n[3] === "原话复述" ? "originalReply" : "memory";
655
+ if (_[a]) return f(t, l, `${n[3]}重复`);
656
+ _[a] = { version: 1, data: { enabled: !0 } };
616
657
  }
617
- D = D.slice(e[0].length).trimStart();
658
+ O = O.slice(n[0].length).trimStart();
618
659
  }
619
660
  if (Array.isArray(t.tag_meta))
620
- for (const [e, l] of t.tag_meta.entries()) {
621
- if (!l || typeof l != "object")
622
- return c(t, `tag_meta[${e}]`, "标签元数据格式错误");
623
- const k = l;
661
+ for (const [n, a] of t.tag_meta.entries()) {
662
+ if (!a || typeof a != "object")
663
+ return f(t, `tag_meta[${n}]`, "标签元数据格式错误");
664
+ const o = a;
624
665
  if (![
625
666
  "cdp_tag",
626
667
  "todo",
@@ -631,307 +672,327 @@ function qt(t, o, d = {}, S = {}) {
631
672
  "memory",
632
673
  "separator",
633
674
  "table_knowledge"
634
- ].includes(String(k.type)))
635
- return c(
675
+ ].includes(String(o.type)))
676
+ return f(
636
677
  t,
637
- `tag_meta[${e}]`,
678
+ `tag_meta[${n}]`,
638
679
  "旧标签元数据无法映射到新模型"
639
680
  );
640
- if (k.invalid)
641
- return c(t, `tag_meta[${e}]`, "失效标签需要只读保全");
642
- if (k.type === "cdp_tag" && (!_.tagged || _.tagged.data.tag.id !== String(k.value || "") || _.tagged.data.tag.label !== String(k.name || "")))
643
- return c(
681
+ if (o.invalid)
682
+ return f(t, `tag_meta[${n}]`, "失效标签需要只读保全");
683
+ if (o.type === "cdp_tag" && (!_.tagged || _.tagged.data.tag.id !== String(o.value || "") || _.tagged.data.tag.label !== String(o.name || "")))
684
+ return f(
644
685
  t,
645
- `tag_meta[${e}]`,
686
+ `tag_meta[${n}]`,
646
687
  "顾客标签 ID 与富文本标签不一致"
647
688
  );
648
689
  }
649
- const et = t.todo_plan_id;
650
- if (et != null && String(et).trim()) {
651
- const e = t.todo_plan_name;
652
- if (typeof e != "string" || !e.trim())
653
- return c(t, "todo_plan_name", "待办方案 ID 存在但名称缺失");
654
- if (!O.includes(e))
655
- return c(t, "web_content", "待办方案字段缺少对应的富文本标签");
690
+ const Y = t.todo_plan_id;
691
+ if (Y != null && String(Y).trim()) {
692
+ const n = t.todo_plan_name;
693
+ if (typeof n != "string" || !n.trim())
694
+ return f(t, "todo_plan_name", "待办方案 ID 存在但名称缺失");
695
+ if (!E.includes(n))
696
+ return f(t, "web_content", "待办方案字段缺少对应的富文本标签");
656
697
  }
657
- const H = u || B ? m.slice(1) : [...m];
658
- u && n >= 0 && H.unshift(s.slice(n)), rt && H.unshift([{ kind: "text", value: rt }]);
659
- const Z = Number(t.knowledge_type || 0);
660
- let W = Z === 2 ? "reasoning" : Z === 3 ? "agent" : "normal";
661
- if (t.knowledge_type !== void 0 && ![0, 1, 2, 3].includes(Z))
662
- return c(t, "knowledge_type", "未知的旧知识类型");
698
+ const H = c || q ? k.slice(1) : [...k];
699
+ c && e >= 0 && H.unshift(u.slice(e)), tt && H.unshift([{ kind: "text", value: tt }]);
700
+ const Q = Number(t.knowledge_type || 0);
701
+ let j = Q === 2 ? "reasoning" : Q === 3 ? "agent" : "normal";
702
+ if (t.knowledge_type !== void 0 && ![0, 1, 2, 3].includes(Q))
703
+ return f(t, "knowledge_type", "未知的旧知识类型");
663
704
  if (Array.isArray(t.tag_meta)) {
664
705
  if (t.tag_meta.some(
665
- (e) => e && typeof e == "object" && e.type === "reasoning"
666
- ) && Z === 1)
667
- return c(t, "tag_meta", "推理标签与知识类型不一致");
706
+ (n) => n && typeof n == "object" && n.type === "reasoning"
707
+ ) && Q === 1)
708
+ return f(t, "tag_meta", "推理标签与知识类型不一致");
668
709
  if (t.tag_meta.some(
669
- (e) => e && typeof e == "object" && e.type === "custom_agent"
670
- ) && (Z === 1 || Z === 2))
671
- return c(t, "tag_meta", "Agent 标签与知识类型不一致");
710
+ (n) => n && typeof n == "object" && n.type === "custom_agent"
711
+ ) && (Q === 1 || Q === 2))
712
+ return f(t, "tag_meta", "Agent 标签与知识类型不一致");
672
713
  }
673
- let it = null;
674
- const L = (G = H[0]) == null ? void 0 : G[0], j = (L == null ? void 0 : L.kind) === "text" && /^\s*\{推理\}/u.test(L.value);
675
- if (Y || j) {
676
- if (W === "agent")
677
- return c(t, i, "推理标记与 Agent 类型冲突");
678
- if (W = "reasoning", j && (L == null ? void 0 : L.kind) === "text") {
679
- const e = L.value.replace(/^\s*\{推理\}\s*/u, ""), l = H[0].slice(1);
680
- for (e && l.unshift({ kind: "text", value: e }); ((nt = l[0]) == null ? void 0 : nt.kind) === "text" && !l[0].value.trim(); )
681
- l.shift();
682
- l.length ? H[0] = l : H.shift();
714
+ let et = null;
715
+ const N = (ft = H[0]) == null ? void 0 : ft[0], C = (N == null ? void 0 : N.kind) === "text" && /^\s*\{推理\}/u.test(N.value);
716
+ if (F || C) {
717
+ if (j === "agent")
718
+ return f(t, l, "推理标记与 Agent 类型冲突");
719
+ if (j = "reasoning", C && (N == null ? void 0 : N.kind) === "text") {
720
+ const n = N.value.replace(/^\s*\{推理\}\s*/u, ""), a = H[0].slice(1);
721
+ for (n && a.unshift({ kind: "text", value: n }); ((mt = a[0]) == null ? void 0 : mt.kind) === "text" && !a[0].value.trim(); )
722
+ a.shift();
723
+ a.length ? H[0] = a : H.shift();
683
724
  }
684
725
  }
685
- if (H.length && ((lt = bt(H[0])) != null && lt.trim().startsWith("{自定义Agent}@"))) {
686
- if (W === "reasoning")
687
- return c(t, i, "Agent 标记与推理类型冲突");
688
- W = "agent";
689
- const e = bt(H[0]).trim().slice(11), l = (I) => I.replace(/(已失效)$/u, "").trim(), k = l(e);
690
- if (!k) return c(t, i, "Agent 名称为空");
691
- const h = Array.isArray(t.tag_meta) ? t.tag_meta.find(
692
- (I) => I && typeof I == "object" && I.type === "custom_agent" && typeof I.agent_name == "string" && l(
693
- I.agent_name
694
- ) === k
695
- ) : void 0, T = Array.from(z.querySelectorAll("span")).find(
696
- (I) => pt(I) === "custom_agent" && ((I.textContent || "").trim() === `{自定义Agent}@${e}` || l(I.getAttribute("data-agent-name") || "") === k || l(I.getAttribute("data-tag-name") || "") === k)
697
- ), E = e.endsWith("(已失效)") || (T == null ? void 0 : T.getAttribute("data-invalid")) === "true", tt = (T == null ? void 0 : T.getAttribute("data-agent-id")) || "";
698
- if (tt && (h != null && h.agent_id) && tt !== h.agent_id)
699
- return c(t, "tag_meta", "Agent ID 与富文本标签不一致");
700
- const F = typeof (h == null ? void 0 : h.agent_id) == "string" && h.agent_id ? { id: h.agent_id, name: k } : tt.trim() ? { id: tt, name: k } : E ? null : (kt = d.agent) == null ? void 0 : kt.call(d, k);
701
- it = {
702
- id: (F == null ? void 0 : F.name) === k ? F.id : "",
703
- name: k,
704
- ...E ? { invalid: !0 } : {}
726
+ if (H.length && ((yt = bt(H[0])) != null && yt.trim().startsWith("{自定义Agent}@"))) {
727
+ if (j === "reasoning")
728
+ return f(t, l, "Agent 标记与推理类型冲突");
729
+ j = "agent";
730
+ const n = bt(H[0]).trim().slice(11), a = (B) => B.replace(/(已失效)$/u, "").trim(), o = a(n);
731
+ if (!o) return f(t, l, "Agent 名称为空");
732
+ const m = Array.isArray(t.tag_meta) ? t.tag_meta.find(
733
+ (B) => B && typeof B == "object" && B.type === "custom_agent" && typeof B.agent_name == "string" && a(
734
+ B.agent_name
735
+ ) === o
736
+ ) : void 0, v = Array.from(z.querySelectorAll("span")).find(
737
+ (B) => ot(B) === "custom_agent" && ((B.textContent || "").trim() === `{自定义Agent}@${n}` || a(B.getAttribute("data-agent-name") || "") === o || a(B.getAttribute("data-tag-name") || "") === o)
738
+ ), T = n.endsWith("(已失效)") || (v == null ? void 0 : v.getAttribute("data-invalid")) === "true", M = (v == null ? void 0 : v.getAttribute("data-agent-id")) || "";
739
+ if (v && ["data-agent-name", "data-tag-name"].some(
740
+ (B) => v.hasAttribute(B) && a(v.getAttribute(B) || "") !== o
741
+ ))
742
+ return f(t, l, "Agent 名称属性与显示内容不一致");
743
+ if (M && (m != null && m.agent_id) && M !== m.agent_id)
744
+ return f(t, "tag_meta", "Agent ID 与富文本标签不一致");
745
+ const R = typeof (m == null ? void 0 : m.agent_id) == "string" && m.agent_id ? { id: m.agent_id, name: o } : M.trim() ? { id: M, name: o } : T ? null : (kt = d.agent) == null ? void 0 : kt.call(d, o);
746
+ et = {
747
+ id: (R == null ? void 0 : R.name) === o ? R.id : "",
748
+ name: o,
749
+ ...T ? { invalid: !0 } : {}
705
750
  }, H.shift();
706
751
  }
707
- if (W === "agent" && !it)
708
- return c(t, i, "Agent 知识缺少可解析的 Agent 标记");
709
- at && H.unshift([{ kind: "text", value: at }]);
710
- const U = (e, l, k = !1, h = !1) => {
711
- var tt, F;
712
- if (e.kind === "originalReply")
713
- return c(t, l, "原话块不可嵌套原话模板");
714
- if (e.kind === "media" || e.kind === "block")
715
- return c(t, l, "块级内容不能作为行内标签转换");
716
- if (e.kind === "tableKnowledge")
752
+ if (j === "agent" && !et)
753
+ return f(t, l, "Agent 知识缺少可解析的 Agent 标记");
754
+ G && H.unshift([{ kind: "text", value: G }]);
755
+ const J = (n, a, o = !1, m = !1) => {
756
+ var M, R;
757
+ if (n.kind === "hardBreak")
758
+ return { ok: !0, value: [{ type: "hardBreak" }] };
759
+ if (n.kind === "originalReply")
760
+ return f(t, a, "原话块不可嵌套原话模板");
761
+ if (n.kind === "media" || n.kind === "block")
762
+ return f(t, a, "块级内容不能作为行内标签转换");
763
+ if (n.kind === "tableKnowledge")
717
764
  return {
718
765
  ok: !0,
719
766
  value: [
720
767
  {
721
768
  type: "businessToken",
722
- attrs: { kind: "tableKnowledge", key: e.key, label: e.name }
769
+ attrs: { kind: "tableKnowledge", key: n.key, label: n.name }
723
770
  }
724
771
  ]
725
772
  };
726
- if (e.kind === "attribute")
727
- return W !== "agent" && (W !== "reasoning" || h) ? c(
773
+ if (n.kind === "attribute")
774
+ return j !== "agent" && (j !== "reasoning" || m) ? f(
728
775
  t,
729
- l,
776
+ a,
730
777
  "业务属性只能位于推理知识正文,不能放入原话"
731
778
  ) : {
732
779
  ok: !0,
733
780
  value: [
734
781
  {
735
782
  type: "businessToken",
736
- attrs: { kind: "attribute", key: e.key, label: e.name }
783
+ attrs: { kind: "attribute", key: n.key, label: n.name }
737
784
  }
738
785
  ]
739
786
  };
740
- if (e.kind !== "todo") {
741
- const I = Qt(
742
- W === "normal" ? e.value.replace(/\{(?:待办(?:@[^{}]+)?|原话复述)\}/gu, "") : e.value,
743
- l,
787
+ if (n.kind !== "todo") {
788
+ const B = Xt(
789
+ j === "normal" ? n.value.replace(/\{(?:待办(?:@[^{}]+)?|原话复述)\}/gu, "") : n.value,
790
+ a,
744
791
  d,
745
- a
792
+ r
746
793
  );
747
- return I.ok ? W !== "agent" && (W !== "reasoning" || h) && I.value.some(
748
- (Q) => {
749
- var ct;
750
- return Q.type === "businessToken" && ((ct = Q.attrs) == null ? void 0 : ct.kind) === "attribute";
794
+ return B.ok ? j !== "agent" && (j !== "reasoning" || m) && B.value.some(
795
+ (L) => {
796
+ var X;
797
+ return L.type === "businessToken" && ((X = L.attrs) == null ? void 0 : X.kind) === "attribute";
751
798
  }
752
- ) ? c(
799
+ ) ? f(
753
800
  t,
754
- l,
801
+ a,
755
802
  "业务属性只能位于推理知识正文,不能放入原话"
756
- ) : I.ok && ((tt = e.marks) != null && tt.length) ? {
803
+ ) : B.ok && ((M = n.marks) != null && M.length) ? {
757
804
  ok: !0,
758
- value: I.value.map((Q) => ({
759
- ...Q,
760
- marks: e.marks
805
+ value: B.value.map((L) => ({
806
+ ...L,
807
+ marks: n.marks
761
808
  }))
762
- } : I : I;
809
+ } : B : B;
763
810
  }
764
- if (W === "normal" && !k) return { ok: !0, value: [] };
765
- const T = e.value === "{待办}" ? "默认" : e.value.slice(4, -1), E = M.get(T) || ((F = d.selection) == null ? void 0 : F.call(d, "todo", T));
766
- return !(E != null && E.id) || E.label !== T ? c(t, l, `待办 ${T} 缺少匹配的方案 ID`) : W === "normal" && _.todo ? c(t, i, "待办重复") : W === "normal" ? (_.todo = { version: 1, data: { enabled: !0, tag: E } }, { ok: !0, value: [] }) : {
811
+ if (j === "normal" && !o) return { ok: !0, value: [] };
812
+ const v = n.value === "{待办}" ? "默认" : n.value.slice(4, -1), T = D.get(v) || ((R = d.selection) == null ? void 0 : R.call(d, "todo", v));
813
+ return !(T != null && T.id) || T.label !== v ? f(t, a, `待办 ${v} 缺少匹配的方案 ID`) : j === "normal" && _.todo ? f(t, l, "待办重复") : j === "normal" ? (_.todo = { version: 1, data: { enabled: !0, tag: T } }, { ok: !0, value: [] }) : {
767
814
  ok: !0,
768
815
  value: [
769
816
  {
770
817
  type: "businessToken",
771
818
  attrs: {
772
819
  kind: "todo",
773
- key: E.id,
774
- label: E.label,
775
- ...e.value === "{待办}" ? { token: "{待办}" } : {}
820
+ key: T.id,
821
+ label: T.label,
822
+ ...n.value === "{待办}" ? { token: "{待办}" } : {}
776
823
  }
777
824
  }
778
825
  ]
779
826
  };
780
827
  };
781
- if (W === "normal") {
782
- !K.length && String(et || "").trim() && typeof t.todo_plan_name == "string" && (_.todo = {
828
+ if (j === "normal") {
829
+ !K.length && String(Y || "").trim() && typeof t.todo_plan_name == "string" && (_.todo = {
783
830
  version: 1,
784
831
  data: {
785
832
  enabled: !0,
786
- tag: { id: String(et), label: t.todo_plan_name }
833
+ tag: { id: String(Y), label: t.todo_plan_name }
787
834
  }
788
835
  });
789
- for (const e of K) {
790
- const l = U(e, i, !0);
791
- if (!l.ok) return { ...l, raw: t };
836
+ for (const n of K) {
837
+ const a = J(n, l, !0);
838
+ if (!a.ok) return { ...a, raw: t };
792
839
  }
793
840
  } else K.length && H.unshift(K);
794
- W !== "normal" && _.originalReply && (delete _.originalReply, H.unshift([{ kind: "text", value: "{原话复述}" }]));
795
- const $ = (e, l, k = !1) => {
796
- var T;
797
- const h = [];
798
- for (let E = 0; E < e.length; E++) {
799
- const tt = e[E], F = `${l}.line[${E + 2}]`, I = (T = bt(tt)) == null ? void 0 : T.trim();
800
- if (I != null && I.startsWith("{原话复述}") && W === "reasoning" && !k) {
801
- const R = I.slice(6), C = R ? ht(w(R), f, a) : null;
802
- if (C && !C.ok) return C;
803
- const X = C != null && C.ok ? C.value[0] : e[++E];
804
- if (!X) return c(t, F, "原话块缺少内容");
805
- if (bt(X) === null)
806
- return c(t, F, "原话块包含无法转换的媒体");
807
- const dt = [];
808
- for (const $t of X) {
809
- const gt = U($t, F, !1, !0);
810
- if (!gt.ok) return { ...gt, raw: t };
811
- dt.push(...gt.value);
841
+ j !== "normal" && _.originalReply && (delete _.originalReply, H.unshift([{ kind: "text", value: "{原话复述}" }]));
842
+ const $ = (n, a, o = !1) => {
843
+ var v;
844
+ const m = [];
845
+ for (let T = 0; T < n.length; T++) {
846
+ const M = n[T], R = `${a}.line[${T + 2}]`, B = (v = bt(M)) == null ? void 0 : v.trim();
847
+ if (B != null && B.startsWith("{原话复述}") && j === "reasoning" && !o) {
848
+ const W = B.slice(6), w = W ? ht(A(W), y, r) : null;
849
+ if (w && !w.ok) return w;
850
+ const V = w != null && w.ok ? w.value[0] : n[++T];
851
+ if (!V) return f(t, R, "原话块缺少内容");
852
+ if (bt(V) === null)
853
+ return f(t, R, "原话块包含无法转换的媒体");
854
+ const rt = [];
855
+ for (const $t of V) {
856
+ const it = J($t, R, !1, !0);
857
+ if (!it.ok) return { ...it, raw: t };
858
+ rt.push(...it.value);
812
859
  }
813
- h.push({
860
+ m.push({
814
861
  type: "originalReply",
815
- content: [{ type: "paragraph", content: dt }]
862
+ content: [{ type: "paragraph", content: rt }]
816
863
  });
817
864
  continue;
818
865
  }
819
- let Q = [];
820
- const ct = () => {
821
- Q.length && (h.push({ type: "paragraph", content: Q }), Q = []);
866
+ let L = [];
867
+ const X = () => {
868
+ L.length && (m.push({ type: "paragraph", content: L }), L = []);
822
869
  };
823
- for (const R of tt)
824
- if (R.kind === "originalReply") {
825
- Q.every((ut) => {
826
- var dt;
827
- return ut.type === "text" && !((dt = ut.text) != null && dt.trim());
828
- }) && (Q = []), ct();
829
- const C = ht(R.html, f, a);
830
- if (!C.ok) return { ...C, raw: t };
831
- if (k) return c(t, F, "原话块不可嵌套原话模板");
832
- const X = $(
833
- C.value,
834
- `${F}.originalReply`,
870
+ for (const W of M)
871
+ if (W.kind === "originalReply") {
872
+ L.every((Z) => {
873
+ var rt;
874
+ return Z.type === "text" && !((rt = Z.text) != null && rt.trim());
875
+ }) && (L = []), X();
876
+ const w = ht(W.html, y, r);
877
+ if (!w.ok) return { ...w, raw: t };
878
+ if (o) return f(t, R, "原话块不可嵌套原话模板");
879
+ const V = $(
880
+ w.value,
881
+ `${R}.originalReply`,
835
882
  !0
836
883
  );
837
- if (!X.ok) return X;
838
- W === "normal" ? h.push(...X.value) : h.push({
884
+ if (!V.ok) return V;
885
+ j === "normal" ? m.push(...V.value) : m.push({
839
886
  type: "originalReply",
840
- content: X.value.length ? X.value : [{ type: "paragraph" }]
887
+ content: V.value.length ? V.value : [{ type: "paragraph" }]
841
888
  });
842
- } else if (R.kind === "media")
843
- ct(), h.push({
889
+ } else if (W.kind === "media")
890
+ X(), m.push({
844
891
  type: "mediaBlock",
845
- attrs: { kind: R.media, src: R.src, status: "ready" }
892
+ attrs: {
893
+ kind: W.media,
894
+ src: W.src,
895
+ status: "ready",
896
+ ...W.metadata
897
+ }
846
898
  });
847
- else if (R.kind === "block") {
848
- if (ct(), k)
849
- return c(t, F, "原话块不支持嵌套列表或引用");
850
- const C = new DOMParser().parseFromString(R.html, "text/html").body.firstElementChild;
851
- if (R.tag === "pre") {
852
- h.push({
899
+ else if (W.kind === "block") {
900
+ if (X(), W.tag === "hr") {
901
+ m.push({ type: "horizontalRule" });
902
+ continue;
903
+ }
904
+ if (o)
905
+ return f(t, R, "原话块不支持嵌套列表或引用");
906
+ const w = new DOMParser().parseFromString(W.html, "text/html").body.firstElementChild;
907
+ if (W.tag === "pre") {
908
+ m.push({
853
909
  type: "codeBlock",
854
- ...C.hasAttribute("data-language") ? { attrs: { language: C.getAttribute("data-language") } } : {},
855
- content: C.textContent ? [{ type: "text", text: C.textContent }] : []
910
+ ...w.hasAttribute("data-language") ? { attrs: { language: w.getAttribute("data-language") } } : {},
911
+ content: w.textContent ? [{ type: "text", text: w.textContent }] : []
856
912
  });
857
913
  continue;
858
914
  }
859
- const X = R.tag === "ul" || R.tag === "ol", ut = [], dt = X ? Array.from(C.children) : [C];
860
- for (const $t of dt) {
861
- if (X && $t.tagName.toLowerCase() !== "li")
862
- return c(t, F, "列表包含非列表项节点");
863
- const gt = ht(
915
+ const V = W.tag === "ul" || W.tag === "ol", Z = [], rt = V ? Array.from(w.children) : [w];
916
+ for (const $t of rt) {
917
+ if (V && $t.tagName.toLowerCase() !== "li")
918
+ return f(t, R, "列表包含非列表项节点");
919
+ const it = ht(
864
920
  $t.innerHTML,
865
- f,
866
- a
921
+ y,
922
+ r
867
923
  );
868
- if (!gt.ok) return { ...gt, raw: t };
869
- const At = $(gt.value, F);
924
+ if (!it.ok) return { ...it, raw: t };
925
+ const At = $(it.value, R);
870
926
  if (!At.ok) return At;
871
927
  const Wt = At.value.length ? At.value : [{ type: "paragraph" }];
872
- X ? ut.push({ type: "listItem", content: Wt }) : ut.push(...Wt);
928
+ V ? Z.push({ type: "listItem", content: Wt }) : Z.push(...Wt);
873
929
  }
874
- h.push({
875
- type: R.tag === "ul" ? "bulletList" : R.tag === "ol" ? "orderedList" : "blockquote",
876
- ...R.tag === "ol" && C.hasAttribute("start") ? { attrs: { start: Number(C.getAttribute("start")) } } : {},
877
- content: ut
930
+ m.push({
931
+ type: W.tag === "ul" ? "bulletList" : W.tag === "ol" ? "orderedList" : "blockquote",
932
+ ...W.tag === "ol" && (w.hasAttribute("start") || w.hasAttribute("type")) ? {
933
+ attrs: {
934
+ ...w.hasAttribute("start") ? { start: Number(w.getAttribute("start")) } : {},
935
+ ...w.hasAttribute("type") ? { type: w.getAttribute("type") } : {}
936
+ }
937
+ } : {},
938
+ content: Z
878
939
  });
879
940
  } else {
880
- const C = U(R, F, !1, k);
881
- if (!C.ok) return { ...C, raw: t };
882
- Q.push(...C.value);
941
+ const w = J(W, R, !1, o);
942
+ if (!w.ok) return { ...w, raw: t };
943
+ L.push(...w.value);
883
944
  }
884
- tt.some((R) => R.kind === "originalReply") && Q.every((R) => {
885
- var C;
886
- return R.type === "text" && !((C = R.text) != null && C.trim());
887
- }) && (Q = []), (Q.length || !tt.length) && h.push({ type: "paragraph", content: Q });
945
+ M.some((W) => W.kind === "originalReply") && L.every((W) => {
946
+ var w;
947
+ return W.type === "text" && !((w = W.text) != null && w.trim());
948
+ }) && (L = []), (L.length || !M.length) && m.push({ type: "paragraph", content: L });
888
949
  }
889
- return { ok: !0, value: h };
890
- }, b = $(H, i);
891
- if (!b.ok) return { ...b, raw: t };
892
- const x = b.value;
893
- Xt(x);
894
- const V = Rt(x, `${i}.block`);
895
- if (V) return c(t, V, "工具标签重复");
896
- const ot = {
950
+ return { ok: !0, value: m };
951
+ }, h = $(H, l);
952
+ if (!h.ok) return { ...h, raw: t };
953
+ const x = h.value;
954
+ Yt(x);
955
+ const U = Dt(x, `${l}.block`);
956
+ if (U) return f(t, U, "工具标签重复");
957
+ const at = {
897
958
  type: "doc",
898
959
  content: x.length ? x : [{ type: "paragraph" }]
899
- }, st = W === "agent" ? null : jt(ot, o).doc, vt = x.some(
900
- (e) => {
901
- var l;
902
- return e.type !== "paragraph" || ((l = e.content) == null ? void 0 : l.some(
903
- (k) => {
904
- var h;
905
- return k.type !== "text" || !!((h = k.text) != null && h.trim());
960
+ }, nt = j === "agent" ? null : jt(at, s).doc, vt = x.some(
961
+ (n) => {
962
+ var a;
963
+ return n.type !== "paragraph" || ((a = n.content) == null ? void 0 : a.some(
964
+ (o) => {
965
+ var m;
966
+ return o.type !== "text" || !!((m = o.text) != null && m.trim());
906
967
  }
907
968
  ));
908
969
  }
909
- ), ft = {
970
+ ), st = {
910
971
  schemaVersion: 1,
911
- type: W,
912
- question: { text: q },
972
+ type: j,
973
+ question: { text: I },
913
974
  knowledge: {
914
- doc: st,
915
- agentRef: it,
916
- ...W === "agent" && vt ? {
917
- agentBody: jt(ot, o).doc
975
+ doc: nt,
976
+ agentRef: et,
977
+ ...j === "agent" && vt ? {
978
+ agentBody: jt(at, s).doc
918
979
  } : {}
919
980
  },
920
981
  extensionState: _
921
- }, mt = Et(ft);
922
- return mt ? c(t, mt, "转换后的场景未通过新模型校验") : { ok: !0, value: ft };
982
+ }, lt = qt(st);
983
+ return lt ? f(t, lt, "转换后的场景未通过新模型校验") : { ok: !0, value: st };
923
984
  }
924
- function Bt(t, o, d) {
925
- var S, a, i, g, f, p, y, m, s, n;
985
+ function Ct(t, s, d) {
986
+ var S, r, l, g, y, p, b, k, u, e;
926
987
  if ((S = t.marks) != null && S.length) {
927
- const r = Bt(
988
+ const i = Ct(
928
989
  { ...t, marks: void 0 },
929
- o,
990
+ s,
930
991
  d
931
992
  );
932
- if (!r.ok) return r;
933
- let { html: u } = r.value;
934
- for (const q of [...t.marks].reverse()) {
993
+ if (!i.ok) return i;
994
+ let { html: c } = i.value;
995
+ for (const I of [...t.marks].reverse()) {
935
996
  const z = {
936
997
  bold: "b",
937
998
  italic: "i",
@@ -939,93 +1000,105 @@ function Bt(t, o, d) {
939
1000
  strike: "s",
940
1001
  code: "code",
941
1002
  link: "a"
942
- }[q.type];
943
- if (!z) return c(t, o, "文字格式无法映射到旧格式");
944
- u = `<${z}${q.type === "link" ? ["href", "target", "rel", "title", "class"].filter((O) => {
1003
+ }[I.type];
1004
+ if (!z) return f(t, s, "文字格式无法映射到旧格式");
1005
+ c = `<${z}${I.type === "link" ? ["href", "target", "rel", "title", "class"].filter((E) => {
945
1006
  var P;
946
- return typeof ((P = q.attrs) == null ? void 0 : P[O]) == "string";
947
- }).map((O) => ` ${O}="${w(q.attrs[O])}"`).join("") : ""}>${u}</${z}>`;
1007
+ return typeof ((P = I.attrs) == null ? void 0 : P[E]) == "string";
1008
+ }).map((E) => ` ${E}="${A(I.attrs[E])}"`).join("") : ""}>${c}</${z}>`;
948
1009
  }
949
- return { ok: !0, value: { html: u, text: r.value.text } };
1010
+ return { ok: !0, value: { html: c, text: i.value.text } };
950
1011
  }
951
- if (t.type === "text" && !((a = t.marks) != null && a.length))
1012
+ if (t.type === "text" && /\{智能(?:建单|工单)@/u.test(t.text || ""))
1013
+ return f(
1014
+ t,
1015
+ s,
1016
+ "请通过工单入口插入工单标签,暂不支持将协议文字自动转换为标签"
1017
+ );
1018
+ if (t.type === "text" && !((r = t.marks) != null && r.length))
1019
+ return {
1020
+ ok: !0,
1021
+ value: { html: A(t.text || ""), text: t.text || "" }
1022
+ };
1023
+ if (t.type === "hardBreak")
952
1024
  return {
953
1025
  ok: !0,
954
- value: { html: w(t.text || ""), text: t.text || "" }
1026
+ value: { html: '<br data-hard-break="true">', text: `
1027
+ ` }
955
1028
  };
956
- if (t.type === "businessToken" && ((i = t.attrs) == null ? void 0 : i.kind) === "ticket") {
957
- const r = String(t.attrs.key), u = String(t.attrs.label), q = zt(r, u, t.attrs.params);
958
- return Nt(q) ? {
1029
+ if (t.type === "businessToken" && ((l = t.attrs) == null ? void 0 : l.kind) === "ticket") {
1030
+ const i = String(t.attrs.key), c = String(t.attrs.label), I = Ht(i, c, t.attrs.params);
1031
+ return Bt(I) ? {
959
1032
  ok: !0,
960
1033
  value: {
961
- html: `<span contenteditable="false" data-tag-type="ticket" data-ticket-id="${w(
962
- r
963
- )}" data-ticket-name="${w(u)}"${((g = t.attrs.params) == null ? void 0 : g.protocol) === "legacy" ? ' data-ticket-protocol="legacy"' : ""}>${w(q)}</span>`,
964
- text: q
1034
+ html: `<span contenteditable="false" data-tag-type="ticket" data-ticket-id="${A(
1035
+ i
1036
+ )}" data-ticket-name="${A(c)}"${((g = t.attrs.params) == null ? void 0 : g.protocol) === "legacy" ? ' data-ticket-protocol="legacy"' : ""}>${A(I)}</span>`,
1037
+ text: I
965
1038
  }
966
- } : c(t, o, "工单引用无法映射到旧格式");
1039
+ } : f(t, s, "工单引用无法映射到旧格式");
967
1040
  }
968
- if (t.type === "businessToken" && ((f = t.attrs) == null ? void 0 : f.kind) === "tableKnowledge") {
969
- const r = String(t.attrs.label);
1041
+ if (t.type === "businessToken" && ((y = t.attrs) == null ? void 0 : y.kind) === "tableKnowledge") {
1042
+ const i = String(t.attrs.label);
970
1043
  return {
971
1044
  ok: !0,
972
1045
  value: {
973
- html: `<span contenteditable="false" data-tableknowledge="true" data-tag-type="table_knowledge" data-table-name="${w(
974
- r
975
- )}" data-table-id="${w(
1046
+ html: `<span contenteditable="false" data-tableknowledge="true" data-tag-type="table_knowledge" data-table-name="${A(
1047
+ i
1048
+ )}" data-table-id="${A(
976
1049
  String(t.attrs.key)
977
- )}">##${w(r)}##</span>`,
978
- text: `##${r}##`
1050
+ )}">##${A(i)}##</span>`,
1051
+ text: `##${i}##`
979
1052
  }
980
1053
  };
981
1054
  }
982
1055
  if (t.type === "businessToken" && ((p = t.attrs) == null ? void 0 : p.kind) === "todo") {
983
- const r = String(t.attrs.label), u = r === "默认" && t.attrs.token === "{待办}" ? "{待办}" : `{待办@${r}}`;
1056
+ const i = String(t.attrs.label), c = i === "默认" && t.attrs.token === "{待办}" ? "{待办}" : `{待办@${i}}`;
984
1057
  return {
985
1058
  ok: !0,
986
1059
  value: {
987
- html: `<span contenteditable="false" data-tag="true" data-tag-type="todo" data-tag-name="${w(
988
- r
989
- )}" plan_id="${w(String(t.attrs.key))}">${w(
990
- u
1060
+ html: `<span contenteditable="false" data-tag="true" data-tag-type="todo" data-tag-name="${A(
1061
+ i
1062
+ )}" plan_id="${A(String(t.attrs.key))}">${A(
1063
+ c
991
1064
  )}</span>`,
992
- text: u
1065
+ text: c
993
1066
  }
994
1067
  };
995
1068
  }
996
- if (t.type === "businessToken" && ((y = t.attrs) == null ? void 0 : y.kind) === "variable") {
997
- const r = String(t.attrs.label || t.attrs.key), u = r === "订单链接" ? "{订单链接}" : `#${r}#`, q = `#${r}#`;
1069
+ if (t.type === "businessToken" && ((b = t.attrs) == null ? void 0 : b.kind) === "variable") {
1070
+ const i = String(t.attrs.label || t.attrs.key), c = i === "订单链接" ? "{订单链接}" : `#${i}#`, I = `#${i}#`;
998
1071
  return {
999
1072
  ok: !0,
1000
1073
  value: {
1001
- html: `<span contenteditable="false" data-tag-type="variable" data-variable="true" data-variable-name="${w(
1002
- r
1003
- )}"${r === "客服昵称" ? ' data-customer="true"' : ""}>${w(
1004
- q
1074
+ html: `<span contenteditable="false" data-tag-type="variable" data-variable="true" data-variable-name="${A(
1075
+ i
1076
+ )}"${i === "客服昵称" ? ' data-customer="true"' : ""}>${A(
1077
+ I
1005
1078
  )}</span>`,
1006
- text: u
1079
+ text: c
1007
1080
  }
1008
1081
  };
1009
1082
  }
1010
- if (t.type === "businessToken" && ((m = t.attrs) == null ? void 0 : m.kind) === "attribute") {
1011
- const r = Kt(
1083
+ if (t.type === "businessToken" && ((k = t.attrs) == null ? void 0 : k.kind) === "attribute") {
1084
+ const i = Ft(
1012
1085
  String(t.attrs.key),
1013
1086
  d
1014
1087
  );
1015
- if (!r || t.attrs.label !== r.name)
1016
- return c(t, o, "业务属性不在旧目录中或名称与 key 不一致");
1017
- const u = w(r.name);
1088
+ if (!i || t.attrs.label !== i.name)
1089
+ return f(t, s, "业务属性不在旧目录中或名称与 key 不一致");
1090
+ const c = A(i.name);
1018
1091
  return {
1019
1092
  ok: !0,
1020
1093
  value: {
1021
- html: `<span contenteditable="false" data-tag="true" data-tag-type="biz_attribute" data-attr-name="${u}" data-attr-key="${w(
1022
- r.key
1023
- )}" data-attr-id="${w(String(r.id))}">${u}</span>`,
1024
- text: Lt(r.name)
1094
+ html: `<span contenteditable="false" data-tag="true" data-tag-type="biz_attribute" data-attr-name="${c}" data-attr-key="${A(
1095
+ i.key
1096
+ )}" data-attr-id="${A(String(i.id))}">${c}</span>`,
1097
+ text: Nt(i.name)
1025
1098
  }
1026
1099
  };
1027
1100
  }
1028
- if (t.type === "businessToken" && ((s = t.attrs) == null ? void 0 : s.kind) === "separator")
1101
+ if (t.type === "businessToken" && ((u = t.attrs) == null ? void 0 : u.kind) === "separator")
1029
1102
  return {
1030
1103
  ok: !0,
1031
1104
  value: {
@@ -1033,37 +1106,56 @@ function Bt(t, o, d) {
1033
1106
  text: "[sep]"
1034
1107
  }
1035
1108
  };
1036
- if (t.type === "businessToken" && ((n = t.attrs) == null ? void 0 : n.kind) === "tool") {
1037
- const r = It(t);
1038
- if (!r) return c(t, o, "工具参数无法映射到旧格式");
1039
- const { params: u } = t.attrs;
1040
- return { ok: !0, value: { html: t.attrs.key === "external_method" ? `<span contenteditable="false" data-tag-type="external_method" data-scene-id="${w(
1041
- u.sceneId
1042
- )}" data-scene-name="${w(u.sceneName)}">${w(
1043
- r
1044
- )}</span>` : t.attrs.key === "small_payment" ? `<span contenteditable="false" data-tag="true" data-tag-type="small_payment" data-max-amount-cent="${Number(u.amount) * 100}">${w(r)}</span>` : `<span contenteditable="false" data-tag="true" data-tag-type="order_remark" data-remark-id="${w(
1045
- u.id
1046
- )}" data-remark-mode="${u.contentMode === "fixed" ? "fixed" : "extract"}" data-remark-flag="${w(
1047
- u.flag
1048
- )}" data-remark-keep-flag="${u.preserveFlag ? "1" : "0"}" data-remark-position="${u.position}" data-remark-content="${w(u.content)}">${w(
1049
- r
1050
- )}</span>`, text: r } };
1109
+ if (t.type === "businessToken" && ((e = t.attrs) == null ? void 0 : e.kind) === "tool") {
1110
+ const i = Et(t);
1111
+ if (!i) return f(t, s, "工具参数无法映射到旧格式");
1112
+ const { params: c } = t.attrs;
1113
+ return { ok: !0, value: { html: t.attrs.key === "external_method" ? `<span contenteditable="false" data-tag-type="external_method" data-scene-id="${A(
1114
+ c.sceneId
1115
+ )}" data-scene-name="${A(c.sceneName)}">${A(
1116
+ i
1117
+ )}</span>` : t.attrs.key === "small_payment" ? `<span contenteditable="false" data-tag="true" data-tag-type="small_payment" data-max-amount-cent="${Number(c.amount) * 100}">${A(i)}</span>` : `<span contenteditable="false" data-tag="true" data-tag-type="order_remark" data-remark-id="${A(
1118
+ c.id
1119
+ )}" data-remark-mode="${c.contentMode === "fixed" ? "fixed" : "extract"}" data-remark-flag="${A(
1120
+ c.flag
1121
+ )}" data-remark-keep-flag="${c.preserveFlag ? "1" : "0"}" data-remark-position="${c.position}" data-remark-content="${A(c.content)}">${A(
1122
+ i
1123
+ )}</span>`, text: i } };
1051
1124
  }
1052
- return c(t, o, `节点 ${t.type} 无法映射到旧格式`);
1125
+ return f(t, s, `节点 ${t.type} 无法映射到旧格式`);
1126
+ }
1127
+ function Mt(t) {
1128
+ const s = (t.content || []).map((d) => d.type === "text" ? d.text || "" : "\0").join("");
1129
+ return /\{智能(?:建单|工单)@/u.test(s);
1053
1130
  }
1054
- function Tt(t, o, d) {
1055
- var g, f, p;
1131
+ function Tt(t, s, d) {
1132
+ var g, y, p, b;
1133
+ if (Mt(t))
1134
+ return f(
1135
+ t,
1136
+ s,
1137
+ "请通过工单入口插入工单标签,暂不支持将协议文字自动转换为标签"
1138
+ );
1139
+ if (t.type === "horizontalRule")
1140
+ return { ok: !0, value: { html: "<hr>", text: "<hr/>" } };
1056
1141
  if (t.type === "mediaBlock" && ((g = t.attrs) == null ? void 0 : g.status) === "ready") {
1057
- const y = t.attrs.kind === "image" ? "img" : "video", m = w(String(t.attrs.src));
1142
+ const k = t.attrs.kind === "image" ? "img" : "video", u = A(String(t.attrs.src)), e = [
1143
+ ["assetId", "data-asset-id"],
1144
+ ["name", "data-media-name"],
1145
+ ["poster", "poster"]
1146
+ ].filter(([i]) => {
1147
+ var c;
1148
+ return typeof ((c = t.attrs) == null ? void 0 : c[i]) == "string";
1149
+ }).map(([i, c]) => ` ${c}="${A(t.attrs[i])}"`).join("");
1058
1150
  return {
1059
1151
  ok: !0,
1060
1152
  value: {
1061
- html: `<${y} src="${m}"${y === "video" ? "></video>" : ">"}`,
1062
- text: `<${y} src="${m}"${y === "video" ? ' width="240" controls/>' : ' width="120"/>'}`
1153
+ html: `<${k} src="${u}"${e}${k === "video" ? "></video>" : ">"}`,
1154
+ text: `<${k} src="${u}"${e}${k === "video" ? ' width="240" controls/>' : ' width="120"/>'}`
1063
1155
  }
1064
1156
  };
1065
1157
  }
1066
- const a = {
1158
+ const r = {
1067
1159
  paragraph: "p",
1068
1160
  bulletList: "ul",
1069
1161
  orderedList: "ol",
@@ -1071,47 +1163,47 @@ function Tt(t, o, d) {
1071
1163
  blockquote: "blockquote",
1072
1164
  codeBlock: "pre"
1073
1165
  }[t.type || ""];
1074
- if (!a) return c(t, o, "块级节点无法映射到旧格式");
1075
- const i = [];
1076
- for (const [y, m] of (t.content || []).entries()) {
1077
- const s = `${o}.content[${y}]`, n = ["paragraph", "codeBlock"].includes(t.type || "") ? Bt(m, s, d) : Tt(m, s, d);
1078
- if (!n.ok) return n;
1079
- i.push(n.value);
1166
+ if (!r) return f(t, s, "块级节点无法映射到旧格式");
1167
+ const l = [];
1168
+ for (const [k, u] of (t.content || []).entries()) {
1169
+ const e = `${s}.content[${k}]`, i = ["paragraph", "codeBlock"].includes(t.type || "") ? Ct(u, e, d) : Tt(u, e, d);
1170
+ if (!i.ok) return i;
1171
+ l.push(i.value);
1080
1172
  }
1081
1173
  return {
1082
1174
  ok: !0,
1083
1175
  value: {
1084
- html: `<${a}${t.type === "orderedList" && ((f = t.attrs) == null ? void 0 : f.start) !== void 0 ? ` start="${t.attrs.start}"` : t.type === "codeBlock" && ((p = t.attrs) != null && p.language) ? ` data-language="${w(t.attrs.language)}"` : ""}>${i.map((y) => y.html).join("")}</${a}>`,
1085
- text: i.map((y) => y.text).join(
1176
+ html: `<${r}${t.type === "orderedList" && ((y = t.attrs) == null ? void 0 : y.start) !== void 0 ? ` start="${A(String(t.attrs.start))}"` : t.type === "codeBlock" && ((p = t.attrs) != null && p.language) ? ` data-language="${A(t.attrs.language)}"` : ""}${t.type === "orderedList" && ((b = t.attrs) != null && b.type) ? ` type="${A(String(t.attrs.type))}"` : ""}>${l.map((k) => k.html).join("")}</${r}>`,
1177
+ text: l.map((k) => k.text).join(
1086
1178
  ["paragraph", "codeBlock"].includes(t.type || "") ? "" : `
1087
1179
  `
1088
1180
  )
1089
1181
  }
1090
1182
  };
1091
1183
  }
1092
- function xt(t, o = !1) {
1093
- const d = (a) => {
1094
- var f, p;
1095
- const i = { ...a.attrs };
1096
- delete i.id, delete i.nodeVersion, o && a.type === "businessToken" && i.kind === "tableKnowledge" && (i.key = i.label);
1097
- const g = o && a.type === "doc" ? (f = a.content) == null ? void 0 : f.filter(
1098
- (y, m, s) => {
1099
- var n, r;
1100
- return !(y.type === "paragraph" && !((n = y.content) != null && n.length) && ((r = s[m + 1]) == null ? void 0 : r.type) === "originalReply");
1184
+ function xt(t, s = !1) {
1185
+ const d = (r) => {
1186
+ var y, p;
1187
+ const l = { ...r.attrs };
1188
+ delete l.id, delete l.nodeVersion, s && r.type === "businessToken" && l.kind === "tableKnowledge" && (l.key = l.label);
1189
+ const g = s && r.type === "doc" ? (y = r.content) == null ? void 0 : y.filter(
1190
+ (b, k, u) => {
1191
+ var e, i;
1192
+ return !(b.type === "paragraph" && !((e = b.content) != null && e.length) && ((i = u[k + 1]) == null ? void 0 : i.type) === "originalReply");
1101
1193
  }
1102
- ) : a.content;
1194
+ ) : r.content;
1103
1195
  return {
1104
- ...a,
1105
- ...o ? {
1196
+ ...r,
1197
+ ...s ? {
1106
1198
  marks: void 0,
1107
- ...a.type === "text" ? { text: (p = a.text) == null ? void 0 : p.replace(/\u00a0/g, " ") } : {}
1199
+ ...r.type === "text" ? { text: (p = r.text) == null ? void 0 : p.replace(/\u00a0/g, " ") } : {}
1108
1200
  } : {},
1109
- attrs: Object.keys(i).length ? i : void 0,
1201
+ attrs: Object.keys(l).length ? l : void 0,
1110
1202
  content: g != null && g.length ? g.map(d) : void 0
1111
1203
  };
1112
- }, S = (a) => Array.isArray(a) ? a.map(S) : a && typeof a == "object" ? Object.fromEntries(
1113
- Object.entries(a).sort(([i], [g]) => i.localeCompare(g)).map(([i, g]) => [i, S(g)])
1114
- ) : a;
1204
+ }, S = (r) => Array.isArray(r) ? r.map(S) : r && typeof r == "object" ? Object.fromEntries(
1205
+ Object.entries(r).sort(([l], [g]) => l.localeCompare(g)).map(([l, g]) => [l, S(g)])
1206
+ ) : r;
1115
1207
  return JSON.stringify(
1116
1208
  S({
1117
1209
  type: t.type,
@@ -1124,249 +1216,255 @@ function xt(t, o = !1) {
1124
1216
  })
1125
1217
  );
1126
1218
  }
1127
- function Yt(t, o, d, S, a) {
1128
- var q, z, O, P, M;
1129
- if (typeof o.content != "string") return !1;
1130
- const i = new DOMParser().parseFromString(
1131
- String(o.web_content || d.web_content),
1219
+ function Zt(t, s, d, S, r) {
1220
+ var I, z, E, P, D;
1221
+ if (typeof s.content != "string") return !1;
1222
+ const l = new DOMParser().parseFromString(
1223
+ String(s.web_content || d.web_content),
1132
1224
  "text/html"
1133
1225
  );
1134
- if (Array.from(i.querySelectorAll("*")).some(
1226
+ if (Array.from(l.querySelectorAll("*")).some(
1135
1227
  (_) => Array.from(_.attributes).some(
1136
- (B) => /^on/iu.test(B.name) || ["srcdoc", "srcset"].includes(B.name.toLowerCase()) || B.name.toLowerCase() === "style" && /url\s*\(|expression\s*\(|@import/iu.test(B.value)
1228
+ (q) => /^on/iu.test(q.name) || ["srcdoc", "srcset"].includes(q.name.toLowerCase()) || q.name.toLowerCase() === "style" && /url\s*\(|expression\s*\(|@import/iu.test(q.value)
1137
1229
  )
1138
1230
  ))
1139
1231
  return !1;
1140
- const g = /^\s*【[^【】\r\n]*】/u.test(o.content);
1232
+ const g = /^\s*【[^【】\r\n]*】/u.test(s.content);
1141
1233
  if (g !== (S === "inline")) return !1;
1142
- const f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), y = (_) => {
1143
- var B, K, Y;
1144
- _.type === "businessToken" && ((B = _.attrs) == null ? void 0 : B.kind) === "variable" && f.set(String(_.attrs.label), {
1234
+ const y = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), b = (_) => {
1235
+ var q, K, F;
1236
+ _.type === "businessToken" && ((q = _.attrs) == null ? void 0 : q.kind) === "variable" && y.set(String(_.attrs.label), {
1145
1237
  key: String(_.attrs.key),
1146
1238
  label: String(_.attrs.label)
1147
1239
  }), _.type === "businessToken" && ((K = _.attrs) == null ? void 0 : K.kind) === "todo" && p.set(String(_.attrs.label), {
1148
1240
  id: String(_.attrs.key),
1149
1241
  label: String(_.attrs.label)
1150
- }), (Y = _.content) == null || Y.forEach(y);
1242
+ }), (F = _.content) == null || F.forEach(b);
1151
1243
  };
1152
- (z = (q = t.knowledge.doc) == null ? void 0 : q.content) == null || z.forEach(y), (P = (O = t.knowledge.agentBody) == null ? void 0 : O.content) == null || P.forEach(y);
1153
- const m = (M = t.extensionState.todo) == null ? void 0 : M.data;
1154
- m != null && m.tag && p.set(m.tag.label, m.tag);
1155
- const s = {
1156
- variable: (_) => f.get(_) || null,
1157
- selection: (_, B) => _ === "todo" && p.get(B) || null
1158
- }, n = qt(
1159
- { ...o, web_content: o.web_content || d.web_content },
1244
+ (z = (I = t.knowledge.doc) == null ? void 0 : I.content) == null || z.forEach(b), (P = (E = t.knowledge.agentBody) == null ? void 0 : E.content) == null || P.forEach(b);
1245
+ const k = (D = t.extensionState.todo) == null ? void 0 : D.data;
1246
+ k != null && k.tag && p.set(k.tag.label, k.tag);
1247
+ const u = {
1248
+ variable: (_) => y.get(_) || null,
1249
+ selection: (_, q) => _ === "todo" && p.get(q) || null
1250
+ }, e = It(
1251
+ { ...s, web_content: s.web_content || d.web_content },
1160
1252
  "layout-proof",
1161
- s,
1253
+ u,
1162
1254
  {
1163
1255
  questionText: t.question.text,
1164
- businessAttributes: a
1256
+ businessAttributes: r
1165
1257
  }
1166
- ), r = xt(t);
1167
- if (!n.ok || xt(n.value) !== r)
1258
+ ), i = xt(t);
1259
+ if (!e.ok || xt(e.value) !== i)
1168
1260
  return !1;
1169
1261
  if (t.type === "normal") {
1170
1262
  const _ = ht(
1171
- String(o.web_content || Ct(o.content))
1263
+ String(s.web_content || Lt(s.content))
1172
1264
  );
1173
1265
  if (!_.ok || _.value.slice(g ? 1 : 0).some(
1174
- (B) => B.some(
1266
+ (q) => q.some(
1175
1267
  (K) => K.kind === "todo" || K.kind === "text" && /\{(?:待办(?:@[^{}]*)?|原话复述)\}/u.test(K.value)
1176
1268
  )
1177
1269
  ))
1178
1270
  return !1;
1179
1271
  }
1180
- const u = qt(
1181
- { ...d, web_content: "", content: o.content },
1272
+ const c = It(
1273
+ { ...d, web_content: "", content: s.content },
1182
1274
  "layout-proof",
1183
1275
  {
1184
- ...s,
1276
+ ...u,
1185
1277
  agent: (_) => {
1186
- var B;
1187
- return ((B = t.knowledge.agentRef) == null ? void 0 : B.name) === _ ? t.knowledge.agentRef : null;
1278
+ var q;
1279
+ return ((q = t.knowledge.agentRef) == null ? void 0 : q.name) === _ ? t.knowledge.agentRef : null;
1188
1280
  }
1189
1281
  },
1190
- { questionText: t.question.text, businessAttributes: a }
1282
+ { questionText: t.question.text, businessAttributes: r }
1191
1283
  );
1192
- return u.ok && xt(u.value, !0) === xt(t, !0);
1284
+ return c.ok && xt(c.value, !0) === xt(t, !0);
1193
1285
  }
1194
- function ee(t, o = {}, d = {}) {
1195
- var K, Y, at, rt, D, et, H, Z, W, it, L, j, U, $, b, x, V, ot, st, vt, ft, mt, yt;
1286
+ function ae(t, s = {}, d = {}) {
1287
+ var G, tt, O, Y, H, Q, j, et, N, C, J, $, h, x, U, at, nt, vt, st, lt, ut, dt, gt, ct, pt, ft, mt, yt, kt, n;
1196
1288
  const S = d.businessAttributes ?? _t;
1197
1289
  if (!Ot(S))
1198
- return c(
1290
+ return f(
1199
1291
  t,
1200
1292
  "businessAttributes",
1201
1293
  "业务属性目录格式无效或存在重复引用"
1202
1294
  );
1203
- const a = Et(t);
1204
- if (a) return c(t, a, "场景未通过新模型校验");
1205
- const i = Rt(
1206
- ((K = t.knowledge.doc) == null ? void 0 : K.content) || [],
1207
- "knowledge.doc.content"
1295
+ const r = qt(t);
1296
+ if (r) return f(t, r, "场景未通过新模型校验");
1297
+ const l = Dt(
1298
+ ((G = t.knowledge.doc || t.knowledge.agentBody || t.knowledge.retainedDoc) == null ? void 0 : G.content) || [],
1299
+ "knowledge.content"
1208
1300
  );
1209
- if (i) return c(t, i, "工具标签重复");
1210
- const g = `【${t.question.text}】`, f = [], p = [];
1211
- for (const [v, A] of [
1301
+ if (l) return f(t, l, "工具标签重复");
1302
+ const g = `【${t.question.text}】`, y = [], p = [];
1303
+ for (const [a, o] of [
1212
1304
  ["todo", "待办"],
1213
1305
  ["tagged", "顾客标签"]
1214
1306
  ]) {
1215
- const N = (Y = t.extensionState[v]) == null ? void 0 : Y.data;
1216
- if (N != null && N.enabled) {
1217
- const J = `{${A}@${(at = N.tag) == null ? void 0 : at.label}}`;
1218
- f.push(J), p.push(
1219
- v === "todo" ? `<span contenteditable="false" data-tag="true" data-tag-type="todo" data-tag-name="${w(
1220
- ((rt = N.tag) == null ? void 0 : rt.label) || ""
1221
- )}" plan_id="${w(((D = N.tag) == null ? void 0 : D.id) || "")}">${w(
1222
- J
1223
- )}</span>` : `<span contenteditable="false" data-tag="true" data-tag-type="cdp_tag" data-tag-name="${w(
1224
- ((et = N.tag) == null ? void 0 : et.label) || ""
1225
- )}" data-tag-id="${w(((H = N.tag) == null ? void 0 : H.id) || "")}">${w(
1226
- J
1307
+ const m = (tt = t.extensionState[a]) == null ? void 0 : tt.data;
1308
+ if (m != null && m.enabled) {
1309
+ const v = `{${o}@${(O = m.tag) == null ? void 0 : O.label}}`;
1310
+ y.push(v), p.push(
1311
+ a === "todo" ? `<span contenteditable="false" data-tag="true" data-tag-type="todo" data-tag-name="${A(
1312
+ ((Y = m.tag) == null ? void 0 : Y.label) || ""
1313
+ )}" plan_id="${A(((H = m.tag) == null ? void 0 : H.id) || "")}">${A(
1314
+ v
1315
+ )}</span>` : `<span contenteditable="false" data-tag="true" data-tag-type="cdp_tag" data-tag-name="${A(
1316
+ ((Q = m.tag) == null ? void 0 : Q.label) || ""
1317
+ )}" data-tag-id="${A(((j = m.tag) == null ? void 0 : j.id) || "")}">${A(
1318
+ v
1227
1319
  )}</span>`
1228
1320
  );
1229
1321
  }
1230
1322
  }
1231
- (W = (Z = t.extensionState.originalReply) == null ? void 0 : Z.data) != null && W.enabled && (f.push("{原话复述}"), p.push(
1323
+ (N = (et = t.extensionState.originalReply) == null ? void 0 : et.data) != null && N.enabled && (y.push("{原话复述}"), p.push(
1232
1324
  '<span data-tag-type="original_repeat" data-retelling="true">{原话复述}</span>'
1233
- )), (L = (it = t.extensionState.memory) == null ? void 0 : it.data) != null && L.enabled && (f.push("{记忆触发点}"), p.push(
1325
+ )), (J = (C = t.extensionState.memory) == null ? void 0 : C.data) != null && J.enabled && (y.push("{记忆触发点}"), p.push(
1234
1326
  '<span data-tag-type="memory_trigger" data-memory-trigger="true">{记忆触发点}</span>'
1235
1327
  ));
1236
- for (const v of Object.keys(t.extensionState))
1237
- if (!["todo", "tagged", "originalReply", "memory"].includes(v))
1238
- return c(
1328
+ for (const a of Object.keys(t.extensionState))
1329
+ if (!["todo", "tagged", "originalReply", "memory"].includes(a))
1330
+ return f(
1239
1331
  t,
1240
- `extensionState.${v}`,
1332
+ `extensionState.${a}`,
1241
1333
  "旧格式无法表示此插件状态"
1242
1334
  );
1243
- const y = d.questionStorage || (/^\s*(?:<(?:div|p)>\s*)?【[^【】\r\n]*】/u.test(
1244
- String(o.web_content || "")
1245
- ) ? "inline" : "external"), m = y === "inline" ? [`<div>${w(g)}${p.join("")}</div>`] : p.length ? [`<div>${p.join("")}</div>`] : [], s = y === "inline" ? [g + f.join("")] : f.length ? [f.join("")] : [];
1246
- if (t.type === "reasoning" && (m.push("<div>{推理}</div>"), s.push("{推理}")), t.type === "agent") {
1335
+ const b = d.questionStorage || (/^\s*(?:<(?:div|p)>\s*)?【[^【】\r\n]*】/u.test(
1336
+ String(s.web_content || "")
1337
+ ) ? "inline" : "external"), k = b === "inline" ? [`<div>${A(g)}${p.join("")}</div>`] : p.length ? [`<div>${p.join("")}</div>`] : [], u = b === "inline" ? [g + y.join("")] : y.length ? [y.join("")] : [];
1338
+ if (t.type === "reasoning" && (k.push("<div>{推理}</div>"), u.push("{推理}")), t.type === "agent") {
1247
1339
  if (!t.knowledge.agentRef)
1248
- return c(t, "knowledge.agentRef", "旧格式需要 Agent 引用");
1249
- const v = t.knowledge.agentRef, A = `{自定义Agent}@${v.name}${v.invalid ? "(已失效)" : ""}`;
1250
- m.push(
1251
- `<div><span data-tag-type="custom_agent" data-agent="true" data-agent-name="${w(
1252
- v.name
1253
- )}"${v.id ? ` data-agent-id="${w(v.id)}"` : ""}${v.invalid ? ' data-invalid="true"' : ""}>${w(A)}</span></div>`
1254
- ), s.push(A);
1340
+ return f(t, "knowledge.agentRef", "旧格式需要 Agent 引用");
1341
+ const a = t.knowledge.agentRef, o = `{自定义Agent}@${a.name}${a.invalid ? "(已失效)" : ""}`;
1342
+ k.push(
1343
+ `<div><span data-tag-type="custom_agent" data-agent="true" data-agent-name="${A(
1344
+ a.name
1345
+ )}"${a.id ? ` data-agent-id="${A(a.id)}"` : ""}${a.invalid ? ' data-invalid="true"' : ""}>${A(o)}</span></div>`
1346
+ ), u.push(o);
1255
1347
  }
1256
- const n = t.type === "agent" ? t.knowledge.agentBody ? "agentBody" : "retainedDoc" : "doc";
1257
- for (const [v, A] of (((j = t.knowledge[n]) == null ? void 0 : j.content) || []).entries()) {
1258
- const N = `knowledge.${n}.content[${v}]`;
1259
- if (A.type === "messageSeparator") {
1260
- m.push(
1261
- '<div><span data-tag-type="separator" data-divider="true">{分隔符}</span></div>'
1262
- ), s.push("[sep]");
1348
+ const e = t.type === "agent" ? t.knowledge.agentBody ? "agentBody" : "retainedDoc" : "doc";
1349
+ for (const [a, o] of ((($ = t.knowledge[e]) == null ? void 0 : $.content) || []).entries()) {
1350
+ const m = `knowledge.${e}.content[${a}]`;
1351
+ if (((x = (h = t.knowledge[e]) == null ? void 0 : h.content) == null ? void 0 : x.length) === 1 && o.type === "paragraph" && !((U = o.content) != null && U.length))
1263
1352
  continue;
1264
- }
1265
- if (A.type === "mediaBlock" && ((U = A.attrs) == null ? void 0 : U.status) === "ready") {
1266
- const e = A.attrs.kind === "image" ? "img" : "video", l = w(String(A.attrs.src));
1267
- m.push(
1268
- `<div><${e} src="${l}"${e === "video" ? "></video>" : ">"}</div>`
1269
- ), s.push(
1270
- `<${e} src="${l}"${e === "video" ? ' width="240" controls/>' : ' width="120"/>'}`
1271
- );
1353
+ if (o.type === "messageSeparator") {
1354
+ k.push(
1355
+ '<div><span data-tag-type="separator" data-divider="true">{分隔符}</span></div>'
1356
+ ), u.push("[sep]");
1272
1357
  continue;
1273
1358
  }
1274
- if (["bulletList", "orderedList", "blockquote", "codeBlock"].includes(
1275
- A.type || ""
1276
- )) {
1277
- const e = Tt(A, N, S);
1278
- if (!e.ok) return { ...e, raw: t };
1279
- m.push(e.value.html), s.push(e.value.text);
1359
+ if ([
1360
+ "mediaBlock",
1361
+ "horizontalRule",
1362
+ "bulletList",
1363
+ "orderedList",
1364
+ "blockquote",
1365
+ "codeBlock"
1366
+ ].includes(o.type || "")) {
1367
+ const L = Tt(o, m, S);
1368
+ if (!L.ok) return { ...L, raw: t };
1369
+ k.push(
1370
+ o.type === "mediaBlock" ? `<div>${L.value.html}</div>` : L.value.html
1371
+ ), u.push(L.value.text);
1280
1372
  continue;
1281
1373
  }
1282
- const J = A.type === "originalReply", G = J ? A.content || [] : [A];
1283
- if (!G.length || G.some(
1284
- (e) => !["paragraph", "mediaBlock", "messageSeparator"].includes(
1285
- e.type || ""
1374
+ const v = o.type === "originalReply", T = v ? o.content || [] : [o];
1375
+ if (!T.length || T.some(
1376
+ (L) => !["paragraph", "mediaBlock", "messageSeparator"].includes(
1377
+ L.type || ""
1286
1378
  )
1287
1379
  ))
1288
- return c(t, N, `节点 ${A.type} 无法映射到旧格式`);
1289
- const nt = [];
1290
- for (const [e, l] of G.entries()) {
1291
- if (l.type === "mediaBlock") {
1292
- const h = Tt(l, N, S);
1293
- if (!h.ok) return { ...h, raw: t };
1294
- nt.push(h.value);
1380
+ return f(t, m, `节点 ${o.type} 无法映射到旧格式`);
1381
+ const M = [];
1382
+ for (const [L, X] of T.entries()) {
1383
+ if (X.type === "mediaBlock") {
1384
+ const w = Tt(X, m, S);
1385
+ if (!w.ok) return { ...w, raw: t };
1386
+ M.push(w.value);
1295
1387
  continue;
1296
1388
  }
1297
- if (l.type === "messageSeparator") {
1298
- nt.push({
1389
+ if (X.type === "messageSeparator") {
1390
+ M.push({
1299
1391
  html: '<span data-tag-type="separator" data-divider="true">分隔符</span>',
1300
1392
  text: "[sep]"
1301
1393
  });
1302
1394
  continue;
1303
1395
  }
1304
- const k = [];
1305
- for (const [h, T] of (l.content || []).entries()) {
1306
- const E = Bt(
1307
- T,
1308
- `${N}.content[${e}].content[${h}]`,
1396
+ if (Mt(X))
1397
+ return f(
1398
+ t,
1399
+ m,
1400
+ "请通过工单入口插入工单标签,暂不支持将协议文字自动转换为标签"
1401
+ );
1402
+ const W = [];
1403
+ for (const [w, V] of (X.content || []).entries()) {
1404
+ const Z = Ct(
1405
+ V,
1406
+ `${m}.content[${L}].content[${w}]`,
1309
1407
  S
1310
1408
  );
1311
- if (!E.ok) return { ...E, raw: t };
1312
- k.push(E.value);
1409
+ if (!Z.ok) return { ...Z, raw: t };
1410
+ W.push(Z.value);
1313
1411
  }
1314
- nt.push({
1315
- html: k.map((h) => h.html).join(""),
1316
- text: k.map((h) => h.text).join("")
1412
+ M.push({
1413
+ html: W.map((w) => w.html).join(""),
1414
+ text: W.map((w) => w.text).join("")
1317
1415
  });
1318
1416
  }
1319
- const lt = nt.map((e) => e.html).join("<br>"), kt = nt.map((e) => e.text).join(`
1417
+ const R = M.map((L) => L.html).join("<br>"), B = M.map((L) => L.text).join(`
1320
1418
  `);
1321
- J ? (m.push(
1322
- `<div><span contenteditable="false" class="original-repeat-template" data-retelling="true" data-tag-type="original_repeat" data-original-repeat-template="true"><span>&lt;</span><span>原话复述</span><span class="original-repeat-input" contenteditable="true" data-original-repeat-input="true">${lt}</span><span>&gt;</span></span></div>`
1323
- ), s.push(`<{原话复述}${kt}>`)) : (m.push(`<div>${lt}</div>`), s.push(kt));
1419
+ v ? (k.push(
1420
+ `<div><span contenteditable="false" class="original-repeat-template" data-retelling="true" data-tag-type="original_repeat" data-original-repeat-template="true"><span>&lt;</span><span>原话复述</span><span class="original-repeat-input" contenteditable="true" data-original-repeat-input="true">${R}</span><span>&gt;</span></span></div>`
1421
+ ), u.push(`<{原话复述}${B}>`)) : (k.push(`<div>${R}</div>`), u.push(B));
1324
1422
  }
1325
- const r = ($ = t.extensionState.todo) == null ? void 0 : $.data, u = [], q = (v) => {
1326
- var A, N;
1327
- v.type === "businessToken" && ((A = v.attrs) == null ? void 0 : A.kind) === "todo" && u.push({
1328
- id: String(v.attrs.key),
1329
- label: String(v.attrs.label)
1330
- }), (N = v.content) == null || N.forEach(q);
1423
+ const i = (at = t.extensionState.todo) == null ? void 0 : at.data, c = [], I = (a) => {
1424
+ var o, m;
1425
+ a.type === "businessToken" && ((o = a.attrs) == null ? void 0 : o.kind) === "todo" && c.push({
1426
+ id: String(a.attrs.key),
1427
+ label: String(a.attrs.label)
1428
+ }), (m = a.content) == null || m.forEach(I);
1331
1429
  };
1332
- (x = (b = t.knowledge[n]) == null ? void 0 : b.content) == null || x.forEach(q);
1333
- const z = r != null && r.enabled && r.tag ? [r.tag, ...u] : u, O = [
1430
+ (vt = (nt = t.knowledge[e]) == null ? void 0 : nt.content) == null || vt.forEach(I);
1431
+ const z = i != null && i.enabled && i.tag ? [i.tag, ...c] : c, E = [
1334
1432
  ...new Map(
1335
- z.map((v) => [JSON.stringify([v.id, v.label]), v])
1433
+ z.map((a) => [JSON.stringify([a.id, a.label]), a])
1336
1434
  ).values()
1337
1435
  ];
1338
- if (new Set(O.map((v) => v.label)).size !== O.length)
1339
- return c(
1436
+ if (new Set(E.map((a) => a.label)).size !== E.length)
1437
+ return f(
1340
1438
  t,
1341
1439
  "knowledge.doc",
1342
1440
  "同名待办对应多个方案 ID,旧格式无法无损保存"
1343
1441
  );
1344
- const P = O.length === 1 ? O[0] : void 0, M = (V = t.extensionState.tagged) == null ? void 0 : V.data, _ = [];
1345
- if (M != null && M.enabled) {
1442
+ const P = E.length === 1 ? E[0] : void 0, D = (st = t.extensionState.tagged) == null ? void 0 : st.data, _ = [];
1443
+ if (D != null && D.enabled) {
1346
1444
  _.push({
1347
1445
  type: "cdp_tag",
1348
- name: (ot = M.tag) == null ? void 0 : ot.label,
1349
- value: (st = M.tag) == null ? void 0 : st.id
1350
- }), O.forEach((A) => _.push({ type: "todo", name: A.label })), t.type === "reasoning" && _.push({ type: "reasoning", name: "推理" }), (ft = (vt = t.extensionState.originalReply) == null ? void 0 : vt.data) != null && ft.enabled && _.push({ type: "original_repeat", name: "原话复述" });
1351
- const v = (A) => {
1352
- var N, J, G;
1353
- A.type === "businessToken" && ((N = A.attrs) == null ? void 0 : N.kind) === "tableKnowledge" && _.push({ type: "table_knowledge", name: A.attrs.label }), A.type === "businessToken" && ((J = A.attrs) == null ? void 0 : J.kind) === "variable" && _.push({
1446
+ name: (lt = D.tag) == null ? void 0 : lt.label,
1447
+ value: (ut = D.tag) == null ? void 0 : ut.id
1448
+ }), E.forEach((o) => _.push({ type: "todo", name: o.label })), t.type === "reasoning" && _.push({ type: "reasoning", name: "推理" }), (gt = (dt = t.extensionState.originalReply) == null ? void 0 : dt.data) != null && gt.enabled && _.push({ type: "original_repeat", name: "原话复述" });
1449
+ const a = (o) => {
1450
+ var m, v, T;
1451
+ o.type === "businessToken" && ((m = o.attrs) == null ? void 0 : m.kind) === "tableKnowledge" && _.push({ type: "table_knowledge", name: o.attrs.label }), o.type === "businessToken" && ((v = o.attrs) == null ? void 0 : v.kind) === "variable" && _.push({
1354
1452
  type: "variable",
1355
- variable_name: A.attrs.label || A.attrs.key
1356
- }), A.type === "originalReply" && _.push({ type: "original_repeat", name: "原话复述" }), (G = A.content) == null || G.forEach(v);
1453
+ variable_name: o.attrs.label || o.attrs.key
1454
+ }), o.type === "originalReply" && _.push({ type: "original_repeat", name: "原话复述" }), (T = o.content) == null || T.forEach(a);
1357
1455
  };
1358
- (yt = (mt = t.knowledge[n]) == null ? void 0 : mt.content) == null || yt.forEach(v);
1456
+ (pt = (ct = t.knowledge[e]) == null ? void 0 : ct.content) == null || pt.forEach(a);
1359
1457
  }
1360
- const B = {
1361
- ...o,
1458
+ const q = ((ft = t.knowledge[e]) == null ? void 0 : ft.content) || [], K = ((mt = q.at(-1)) == null ? void 0 : mt.type) === "paragraph" && !((kt = (yt = q.at(-1)) == null ? void 0 : yt.content) != null && kt.length) && ((n = q.at(-2)) == null ? void 0 : n.type) === "mediaBlock", F = {
1459
+ ...s,
1362
1460
  knowledge_type: t.type === "reasoning" ? 2 : t.type === "agent" ? 3 : 1,
1363
1461
  todo_plan_id: (P == null ? void 0 : P.id) || "",
1364
- todo_tag_type: O.length ? 2 : 0,
1365
- ...z.length || Object.hasOwn(o, "todo_tag_metas") ? {
1462
+ todo_tag_type: E.length ? 2 : 0,
1463
+ ...z.length || Object.hasOwn(s, "todo_tag_metas") ? {
1366
1464
  todo_tag_metas: z.length ? JSON.stringify(
1367
- z.map((v) => ({
1368
- plan_id: v.id,
1369
- plan_name: v.label,
1465
+ z.map((a) => ({
1466
+ plan_id: a.id,
1467
+ plan_name: a.label,
1370
1468
  tag_type: 2
1371
1469
  }))
1372
1470
  ) : ""
@@ -1374,43 +1472,43 @@ function ee(t, o = {}, d = {}) {
1374
1472
  todo_plan_name: (P == null ? void 0 : P.label) || "",
1375
1473
  tag_meta: [
1376
1474
  ...new Map(
1377
- _.map((v) => [
1475
+ _.map((a) => [
1378
1476
  JSON.stringify([
1379
- v.type,
1380
- v.name || "",
1381
- v.value || "",
1382
- v.variable_name || ""
1477
+ a.type,
1478
+ a.name || "",
1479
+ a.value || "",
1480
+ a.variable_name || ""
1383
1481
  ]),
1384
- v
1482
+ a
1385
1483
  ])
1386
1484
  ).values()
1387
1485
  ],
1388
- web_content: m.join(""),
1389
- content: s.join(`
1390
- `).replace(/^\n+|\n+$/gu, "")
1486
+ web_content: k.join(""),
1487
+ content: (K ? u.slice(0, -1) : u).join(`
1488
+ `)
1391
1489
  };
1392
- if (Yt(t, o, B, y, S)) {
1393
- const v = new DOMParser().parseFromString(
1394
- String(o.web_content || B.web_content),
1490
+ if (Zt(t, s, F, b, S)) {
1491
+ const a = new DOMParser().parseFromString(
1492
+ String(s.web_content || F.web_content),
1395
1493
  "text/html"
1396
1494
  );
1397
- if (!o.web_content && /^【[^【】\r\n]*】\{推理\}/u.test(o.content || "")) {
1398
- const [A, N] = Array.from(v.body.children);
1399
- A && (N == null ? void 0 : N.textContent) === "{推理}" && (A.append(...Array.from(N.childNodes)), N.remove());
1495
+ if (!s.web_content && /^【[^【】\r\n]*】\{推理\}/u.test(s.content || "")) {
1496
+ const [o, m] = Array.from(a.body.children);
1497
+ o && (m == null ? void 0 : m.textContent) === "{推理}" && (o.append(...Array.from(m.childNodes)), m.remove());
1400
1498
  }
1401
- v.querySelectorAll("span").forEach((A) => {
1402
- var G, nt;
1403
- if (pt(A) !== "todo") return;
1404
- const N = A.getAttribute("data-tag-name") || ((nt = (G = A.textContent) == null ? void 0 : G.match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : nt[1]), J = O.find((lt) => lt.label === N);
1405
- J && (A.setAttribute("data-tag-type", "todo"), A.setAttribute("data-tag-name", J.label), A.setAttribute("plan_id", J.id));
1406
- }), B.web_content = v.body.innerHTML, B.content = o.content;
1499
+ a.querySelectorAll("span").forEach((o) => {
1500
+ var T, M;
1501
+ if (ot(o) !== "todo") return;
1502
+ const m = o.getAttribute("data-tag-name") || ((M = (T = o.textContent) == null ? void 0 : T.match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : M[1]), v = E.find((R) => R.label === m);
1503
+ v && (o.setAttribute("data-tag-type", "todo"), o.setAttribute("data-tag-name", v.label), o.setAttribute("plan_id", v.id));
1504
+ }), F.web_content = a.body.innerHTML, F.content = s.content;
1407
1505
  }
1408
- return { ok: !0, value: B };
1506
+ return { ok: !0, value: F };
1409
1507
  }
1410
1508
  export {
1411
1509
  _t as LEGACY_BUSINESS_ATTRIBUTES,
1412
- te as agentPromptPreview,
1510
+ ee as agentPromptPreview,
1413
1511
  Ot as isLegacyBusinessAttributeCatalog,
1414
- qt as legacyItemToScene,
1415
- ee as sceneToLegacyItem
1512
+ It as legacyItemToScene,
1513
+ ae as sceneToLegacyItem
1416
1514
  };