@freecallai/pro 0.0.3 → 0.0.5

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