@freecallai/pro 0.0.2 → 0.0.3

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 (116) hide show
  1. package/README.md +23 -17
  2. package/dist/FkpKnowledgeTypePicker.vue_vue_type_script_setup_true_lang-xR8ZhhdJ.js +187 -0
  3. package/dist/FkpRichText.vue_vue_type_script_setup_true_lang-CaHRIHab.js +4864 -0
  4. package/dist/KnowledgeArea-_rsydhnt.js +1438 -0
  5. package/dist/{ToolForm-BSJxTJ7U.js → ToolForm-Czg67cDT.js} +1 -1
  6. package/dist/{choice-DDg5gNtS.js → choice-Bt2xhoN_.js} +1 -1
  7. package/dist/edition-info/index.js +4 -0
  8. package/dist/filters/index.js +7 -0
  9. package/dist/guard-B7U3S4F1.js +1163 -0
  10. package/dist/{index-D8bcFtWR.js → index-9NM1SHoR.js} +1 -1
  11. package/dist/index-B4-2_sJI.js +10 -0
  12. package/dist/{index-BnFTr8u9.js → index-BBv72oZe.js} +10 -10
  13. package/dist/index-BF6MRSMb.js +6 -0
  14. package/dist/index-BQrYBmwR.js +5 -0
  15. package/dist/index-CS2xQQ8W.js +168 -0
  16. package/dist/index-D0bJAQSN.js +327 -0
  17. package/dist/index-D9yqpH_4.js +57 -0
  18. package/dist/index-DCmHHi07.js +71 -0
  19. package/dist/index-DYeJRJY1.js +6 -0
  20. package/dist/{index-CJlAseSN.js → index-DnaEbb6l.js} +1 -1
  21. package/dist/{index-DSgEWJGP.js → index-Dy2Gy3bL.js} +1 -1
  22. package/dist/index-lNhA3N9x.js +379 -0
  23. package/dist/{index-CG2j9Znw.js → index-sjDmbR5o.js} +1 -1
  24. package/dist/index-trxE5T0w.js +6 -0
  25. package/dist/index-uCVrA6xK.js +5 -0
  26. package/dist/index.js +36 -11
  27. package/dist/inline-KPGqYMIR.js +19 -0
  28. package/dist/knowledge-CupkY2rK.js +6 -0
  29. package/dist/{knowledge-DnYGicjn.js → knowledge-DzwXQR-q.js} +1 -1
  30. package/dist/knowledge-type-picker/index.js +5 -0
  31. package/dist/media-extensions-DhRlLKYM.js +321 -0
  32. package/dist/{media-migration-Cj-3xrxd.js → media-migration-CbMT2wS0.js} +1 -1
  33. package/dist/{media-upload-D7DpMJYx.js → media-upload-P9WeUHHr.js} +1 -1
  34. package/dist/navigation/index.js +4 -0
  35. package/dist/operations-D8pn-_iW.js +20 -0
  36. package/dist/{question-DGC6JHy5.js → question-C7akkjHn.js} +1 -1
  37. package/dist/{question-D1--acV8.js → question-DXZ8R-34.js} +1 -1
  38. package/dist/rich-text/index.js +57 -53
  39. package/dist/rich-text/legacy-converter/index.js +1129 -643
  40. package/dist/style.css +1 -1
  41. package/dist/switcher/index.js +4 -0
  42. package/dist/types/edition-info/FkpEditionInfo.vue.d.ts +5 -0
  43. package/dist/types/edition-info/index.d.ts +2 -0
  44. package/dist/types/edition-info/types.d.ts +5 -0
  45. package/dist/types/filters/FkpFilter.vue.d.ts +20 -0
  46. package/dist/types/filters/FkpFilterDateRange.vue.d.ts +13 -0
  47. package/dist/types/filters/FkpFilterPeriod.vue.d.ts +17 -0
  48. package/dist/types/filters/FkpSearchableMultiSelect.vue.d.ts +44 -0
  49. package/dist/types/filters/index.d.ts +5 -0
  50. package/dist/types/filters/selection.d.ts +5 -0
  51. package/dist/types/filters/types.d.ts +30 -0
  52. package/dist/types/index.d.ts +7 -1
  53. package/dist/types/knowledge-type-picker/index.d.ts +3 -0
  54. package/dist/types/navigation/FkpNavigation.vue.d.ts +51 -0
  55. package/dist/types/navigation/index.d.ts +2 -0
  56. package/dist/types/navigation/types.d.ts +15 -0
  57. package/dist/types/rich-text/FkpRichText.vue.d.ts +18 -5
  58. package/dist/types/rich-text/__demo__/conversion-fixtures.d.ts +2 -2
  59. package/dist/types/rich-text/__demo__/reasoning-template-examples.d.ts +2 -3
  60. package/dist/types/rich-text/config/descriptor.d.ts +25 -2
  61. package/dist/types/rich-text/config/resolve.d.ts +2 -0
  62. package/dist/types/rich-text/index.d.ts +3 -1
  63. package/dist/types/rich-text/legacy-converter/agent-prompt-preview.d.ts +2 -0
  64. package/dist/types/rich-text/legacy-converter/business-attribute.d.ts +9 -29
  65. package/dist/types/rich-text/legacy-converter/index.d.ts +8 -1
  66. package/dist/types/rich-text/legacy-converter/tool-contract.d.ts +1 -5
  67. package/dist/types/rich-text/model/guard.d.ts +2 -1
  68. package/dist/types/rich-text/model/node-contract.d.ts +3 -5
  69. package/dist/types/rich-text/model/node-identity.d.ts +7 -1
  70. package/dist/types/rich-text/model/question-text.d.ts +2 -4
  71. package/dist/types/rich-text/plugins/attribute/token.d.ts +9 -0
  72. package/dist/types/rich-text/plugins/operations.d.ts +9 -0
  73. package/dist/types/rich-text/plugins/reasoningTemplate/defaults.d.ts +14 -0
  74. package/dist/types/rich-text/plugins/reasoningTemplate/examples.d.ts +9 -0
  75. package/dist/types/rich-text/plugins/separator/token.d.ts +2 -0
  76. package/dist/types/rich-text/plugins/tableKnowledge/descriptor.d.ts +2 -0
  77. package/dist/types/rich-text/plugins/tableKnowledge/index.d.ts +2 -0
  78. package/dist/types/rich-text/plugins/tableKnowledge/token.d.ts +9 -0
  79. package/dist/types/rich-text/plugins/ticket/protocol.d.ts +8 -0
  80. package/dist/types/rich-text/plugins/ticket/token.d.ts +9 -0
  81. package/dist/types/rich-text/plugins/todo/token.d.ts +3 -0
  82. package/dist/types/rich-text/plugins/token-catalog.d.ts +46 -0
  83. package/dist/types/rich-text/plugins/token-definition.d.ts +24 -0
  84. package/dist/types/rich-text/plugins/tool/presentation.d.ts +2 -1
  85. package/dist/types/rich-text/plugins/tool/protocol.d.ts +5 -0
  86. package/dist/types/rich-text/plugins/tool/rules.d.ts +1 -0
  87. package/dist/types/rich-text/plugins/tool/token.d.ts +2 -0
  88. package/dist/types/rich-text/plugins/variable/token.d.ts +2 -0
  89. package/dist/types/rich-text/public/types.d.ts +63 -6
  90. package/dist/types/rich-text/runtime/action-ports.d.ts +6 -1
  91. package/dist/types/rich-text/runtime/knowledge-clipboard.d.ts +16 -0
  92. package/dist/types/rich-text/runtime/media-target.d.ts +2 -0
  93. package/dist/types/rich-text/runtime/media-upload-session.d.ts +1 -1
  94. package/dist/types/rich-text/runtime/schema-plan.d.ts +1 -0
  95. package/dist/types/rich-text/types.d.ts +3 -40
  96. package/dist/types/rich-text/ui/FkpKnowledgeTypePicker.vue.d.ts +38 -0
  97. package/dist/types/rich-text/ui/KnowledgeArea.vue.d.ts +7 -3
  98. package/dist/types/rich-text/ui/knowledge-type-picker-types.d.ts +14 -0
  99. package/dist/types/rich-text/ui/token-renderer.d.ts +5 -0
  100. package/dist/types/switcher/FkpSwitcher.vue.d.ts +52 -0
  101. package/dist/types/switcher/index.d.ts +2 -0
  102. package/dist/types/switcher/types.d.ts +7 -0
  103. package/package.json +26 -6
  104. package/dist/FkpRichText.vue_vue_type_script_setup_true_lang-BuMz8Tyy.js +0 -4416
  105. package/dist/KnowledgeArea-BkRVWFrg.js +0 -1224
  106. package/dist/index-BVHYCLDv.js +0 -5
  107. package/dist/index-CzpY61Qj.js +0 -6
  108. package/dist/index-DxxX09iY.js +0 -6
  109. package/dist/index-kOPLn4DD.js +0 -5
  110. package/dist/index-nnvfy5q0.js +0 -31
  111. package/dist/index-urNonkMH.js +0 -6
  112. package/dist/inline-TT_dl8Y3.js +0 -17
  113. package/dist/knowledge-BZCmalF_.js +0 -6
  114. package/dist/media-extensions-ZoxmhIhH.js +0 -276
  115. package/dist/operations-JgnjGx3H.js +0 -19
  116. package/dist/rules-CC6NoltX.js +0 -811
@@ -1,254 +1,368 @@
1
- import { q as $t, r as dt, t as ut, h as vt, b as ft, j as xt } from "../../rules-CC6NoltX.js";
2
- import { a as At } from "../../media-migration-Cj-3xrxd.js";
3
- function mt(t) {
4
- const r = /^\$\$小额打款@([1-9]\d*)\$\$$/u.exec(t);
5
- if (r) {
6
- const p = Number(r[1]);
7
- return p < 100 || p > 9900 || p % 100 !== 0 ? null : {
8
- type: "businessToken",
9
- attrs: {
10
- kind: "tool",
11
- key: "small_payment",
12
- label: "小额打款",
13
- params: { amount: String(p / 100) }
14
- }
15
- };
16
- }
17
- const c = /^\^\^订单备注-(固定话术|智能提取)@编号=(rmk_[a-z0-9]{8});插旗=([^;]+);保留已有旗帜=(是|否);位置=(最前|最后);内容=([\s\S]+)\^\^$/u.exec(
18
- t
19
- );
20
- if (!c) return null;
21
- const m = Object.keys(ut).find(
22
- (p) => ut[p] === c[3]
23
- );
24
- if (!m) return null;
25
- const s = {
26
- id: c[2],
27
- contentMode: c[1] === "固定话术" ? "fixed" : "smart",
28
- content: c[6],
29
- flag: m,
30
- preserveFlag: c[4] === "是",
31
- position: c[5] === "最前" ? "first" : "last"
32
- };
33
- return dt(s) ? {
34
- type: "businessToken",
35
- attrs: { kind: "tool", key: "order_note", label: "订单备注", params: s }
36
- } : null;
37
- }
38
- function yt(t) {
39
- var c;
40
- if (t.type !== "businessToken" || ((c = t.attrs) == null ? void 0 : c.kind) !== "tool") return null;
41
- const { params: r } = t.attrs;
42
- return t.attrs.key === "small_payment" ? $t(r == null ? void 0 : r.amount) ? `$$小额打款@${Number(r.amount) * 100}$$` : null : t.attrs.key !== "order_note" || !dt(r) ? null : `^^订单备注-${r.contentMode === "fixed" ? "固定话术" : "智能提取"}@编号=${r.id};插旗=${ut[r.flag]};保留已有旗帜=${r.preserveFlag ? "是" : "否"};位置=${r.position === "first" ? "最前" : "最后"};内容=${r.content}^^`;
43
- }
44
- function St(t) {
45
- try {
46
- const r = JSON.parse(decodeURIComponent(t)), c = {
47
- id: String(r.id || ""),
48
- contentMode: r.content_type === "extract" ? "smart" : "fixed",
49
- content: String(r.content || ""),
50
- flag: r.flag,
51
- preserveFlag: r.keep_flag_if_exists,
52
- position: r.remark_position === "after" ? "last" : "first"
53
- };
54
- return !["fixed", "extract"].includes(String(r.content_type)) || !["before", "after"].includes(String(r.remark_position)) || !dt(c) ? null : {
55
- type: "businessToken",
56
- attrs: { kind: "tool", key: "order_note", label: "订单备注", params: c }
57
- };
58
- } catch {
59
- return null;
60
- }
61
- }
62
- const wt = [
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 = [
63
4
  { id: 1, key: "focus_goods_name", name: "焦点商品名称" },
64
5
  { id: 2, key: "focus_goods_info", name: "焦点商品信息" },
65
6
  { id: 3, key: "focus_goods_sku", name: "焦点商品sku信息" },
66
7
  { id: 4, key: "focus_order_amount", name: "焦点订单实付金额" },
67
8
  { id: 5, key: "focus_order_status", name: "焦点订单状态" },
68
9
  { id: 6, key: "shop_name", name: "店铺名称" }
69
- ], kt = Object.freeze(wt.map((t) => Object.freeze({ ...t })));
70
- function bt(t) {
71
- return kt.find((r) => r.name === t);
10
+ ];
11
+ function Ot(t) {
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));
72
15
  }
73
- function Tt(t) {
74
- return kt.find((r) => r.key === t);
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);
75
19
  }
76
- function gt(t) {
20
+ function Kt(t, o = _t) {
21
+ return o.find((d) => d.key === t);
22
+ }
23
+ function Lt(t) {
77
24
  return `{业务属性@${t}}`;
78
25
  }
79
- function o(t, r, c) {
80
- return { ok: !1, issues: [{ path: r, message: c }], raw: t };
26
+ const Ft = /* @__PURE__ */ new Set([
27
+ "todo",
28
+ "cdp_tag",
29
+ "separator",
30
+ "original_repeat",
31
+ "size_chart",
32
+ "table_knowledge",
33
+ "biz_attribute",
34
+ "variable",
35
+ "custom_agent",
36
+ "reasoning",
37
+ "memory_trigger",
38
+ "no_send_follow_order",
39
+ "small_payment",
40
+ "order_remark",
41
+ "external_method",
42
+ "ticket",
43
+ "tool"
44
+ ]), Jt = /#@[^#\n]+?@#|##[^#\n]+?##|\$\$小额打款@[^$\n]+?\$\$|\^\^订单备注[^\n]+?\^\^|\{自定义Agent\}@[^^\s\n{}]+|\{(?:业务属性|属性|外部方法|智能建单|智能工单|待办|记忆触发点|分隔符|原话复述|顾客标签|意图标签|工具|推理)@?[^}\n]*\}|#[^#\n]+?#/gu;
45
+ function Ut(t) {
46
+ return t.replace(
47
+ /<video\b((?:[^"'<>]|"[^"]*"|'[^']*')*)\/>/giu,
48
+ "<video$1></video>"
49
+ );
50
+ }
51
+ function Vt(t) {
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
+ }
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) });
63
+ };
64
+ if (t != null && t.trim() && typeof DOMParser < "u") {
65
+ const g = new DOMParser().parseFromString(
66
+ Ut(t),
67
+ "text/html"
68
+ ), f = (p) => {
69
+ var n, r;
70
+ if (p.nodeType === Node.TEXT_NODE) {
71
+ a(p.textContent || "");
72
+ return;
73
+ }
74
+ if (!(p instanceof Element)) return;
75
+ const y = p.tagName.toLowerCase();
76
+ if (["script", "style", "svg", "iframe", "object"].includes(y))
77
+ return;
78
+ if (y === "br") {
79
+ S();
80
+ return;
81
+ }
82
+ if (y === "img" && p.getAttribute("data-tag-icon") === "true")
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({
87
+ type: "media",
88
+ kind: y === "img" ? "image" : "video",
89
+ url: u
90
+ });
91
+ return;
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 });
97
+ return;
98
+ }
99
+ const s = [
100
+ "div",
101
+ "p",
102
+ "li",
103
+ "h1",
104
+ "h2",
105
+ "h3",
106
+ "blockquote",
107
+ "pre"
108
+ ].includes(y);
109
+ s && d.length && S(), p.childNodes.forEach(f), s && S();
110
+ };
111
+ for (g.body.childNodes.forEach(f); ((i = d[d.length - 1]) == null ? void 0 : i.type) === "break"; ) d.pop();
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;
116
+ }
117
+ function c(t, o, d) {
118
+ return { ok: !1, issues: [{ path: o, message: d }], raw: t };
81
119
  }
82
- function N(t) {
120
+ function w(t) {
83
121
  return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
84
122
  }
85
- function st(t) {
86
- 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" : "") || (t.getAttribute("data-tag") === "true" ? "todo" : "");
123
+ function pt(t) {
124
+ return t.getAttribute("data-tag-type") || (t.getAttribute("data-tag") === "no_send_follow_order" ? "no_send_follow_order" : "") || (t.getAttribute("data-divider") === "true" ? "separator" : "") || (t.getAttribute("data-retelling") === "true" ? "original_repeat" : "") || (t.getAttribute("data-size") === "true" ? "size_chart" : "") || (t.getAttribute("data-tableKnowledge") === "true" ? "table_knowledge" : "") || (t.getAttribute("data-variable") === "true" ? "variable" : "") || (t.getAttribute("data-agent") === "true" ? "custom_agent" : "") || (t.getAttribute("data-reasoning") === "true" ? "reasoning" : "") || (t.getAttribute("data-memory-trigger") === "true" ? "memory_trigger" : "") || (/^\{(?:智能建单|智能工单)@/u.test((t.textContent || "").trim()) ? "ticket" : "") || ((t.textContent || "").trim().startsWith("{外部方法@") ? "external_method" : "") || (t.getAttribute("data-tag") === "true" ? "todo" : "");
125
+ }
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;
134
+ }
135
+ return d + w(t.slice(S));
87
136
  }
88
- function pt(t, r = !1) {
137
+ function ht(t, o = !1, d = _t) {
89
138
  if (typeof DOMParser > "u")
90
- return o(t, "web_content", "当前环境不支持 HTML 解析");
91
- const c = new DOMParser().parseFromString(t, "text/html"), m = [[]];
92
- let s = null;
93
- const p = (l) => m[m.length - 1].push(l), k = (l = !1) => {
94
- (l || m[m.length - 1].length) && m.push([]);
95
- }, $ = (l, i) => {
96
- var M, C, B, R, T, U, z, W, H, J, L, F;
97
- if (s) return;
98
- if (l.nodeType === 3) {
99
- (l.textContent || "").replace(/\r\n?/g, `
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, `
100
151
  `).replace(
101
- /\^\^订单备注-[\s\S]*?\^\^/gu,
102
- (S) => S.replace(/\n/g, "")
152
+ /\^\^订单备注-[\s\S]*?\^\^|<\{原话复述\}[^<>]*>/gu,
153
+ (j) => j.replace(/\n/g, "")
103
154
  ).split(`
104
- `).forEach((S, x) => {
105
- x && k(!0), S = S.replace(/\uE000/g, `
155
+ `).forEach((j, U) => {
156
+ U && p(!0), j = j.replace(/\uE000/g, `
106
157
  `);
107
- let v = 0;
108
- for (const b of S.matchAll(
109
- /<\{原话复述\}([^<>]*)>|\{待办@([^{}]+)\}/gu
158
+ let $ = 0;
159
+ for (const b of j.matchAll(
160
+ /<\{原话复述\}([^<>]*)>|\{待办(?:@([^{}]+))?\}/gu
110
161
  )) {
111
- if (b[1] === void 0 && !r) continue;
112
- const y = b.index || 0;
113
- y > v && p({ kind: "text", value: S.slice(v, y) }), p(
114
- b[1] !== void 0 ? { kind: "originalReply", html: N(b[1]) } : { kind: "todo", value: b[0] }
115
- ), v = y + b[0].length;
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;
116
167
  }
117
- v < S.length && p({ kind: "text", value: S.slice(v) });
168
+ $ < j.length && f({ kind: "text", value: j.slice($) });
118
169
  });
119
170
  return;
120
171
  }
121
- if (l.nodeType !== 1) return;
122
- const a = l, g = a.tagName.toLowerCase(), d = st(a);
123
- if (g === "span" && d === "original_repeat" && a.getAttribute("data-original-repeat-template") === "true") {
124
- const _ = a.querySelectorAll('[data-original-repeat-input="true"]');
125
- if (_.length !== 1) {
126
- s = { path: i, message: "原话模板缺少唯一的回复输入区" };
172
+ if (m.nodeType !== 1) return;
173
+ const n = m, r = n.tagName.toLowerCase(), u = pt(n);
174
+ if (r === "span" && u === "original_repeat" && n.getAttribute("data-original-repeat-template") === "true") {
175
+ const L = n.querySelectorAll('[data-original-repeat-input="true"]');
176
+ if (L.length !== 1) {
177
+ i = { path: s, message: "原话模板缺少唯一的回复输入区" };
127
178
  return;
128
179
  }
129
- p({ kind: "originalReply", html: _[0].innerHTML });
180
+ f({ kind: "originalReply", html: L[0].innerHTML });
130
181
  return;
131
182
  }
132
- if (g === "span" && d) {
133
- if (d === "no_send_follow_order") {
134
- s = { path: i, message: "旧不发送跟单标签尚无新知识节点承载" };
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,
188
+ message: "工单标签格式无效、引用已失效或属性与内容不一致"
189
+ } : f({ kind: "text", value: $ });
190
+ return;
191
+ }
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: $ });
195
+ return;
196
+ }
197
+ if (u === "no_send_follow_order") {
198
+ i = { path: s, message: "旧不发送跟单标签尚无新知识节点承载" };
199
+ return;
200
+ }
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,
205
+ message: "表格知识名称无效、与标签不一致或引用已失效"
206
+ } : f({
207
+ kind: "tableKnowledge",
208
+ name: b,
209
+ key: n.getAttribute("data-table-id") || b
210
+ });
135
211
  return;
136
212
  }
137
- if (d === "size_chart" || d === "table_knowledge") {
138
- s = { path: i, message: `旧${d}标签尚无新知识节点承载` };
213
+ if (u === "size_chart") {
214
+ i = { path: s, message: `旧${u}标签尚无新知识节点承载` };
139
215
  return;
140
216
  }
141
- if (d === "biz_attribute") {
142
- const v = (a.textContent || "").trim(), b = (M = v.match(
217
+ if (u === "biz_attribute") {
218
+ const $ = (n.textContent || "").trim(), b = (_ = $.match(
143
219
  /^\{业务属性@([^{}<>\r\n]+)\}$/u
144
- )) == null ? void 0 : M[1], y = ((C = a.getAttribute("data-attr-name")) == null ? void 0 : C.trim()) || b, j = y && bt(y);
145
- !j || v !== y && v !== gt(y) || a.hasAttribute("data-attr-key") && a.getAttribute("data-attr-key") !== j.key || a.hasAttribute("data-attr-id") && a.getAttribute("data-attr-id") !== String(j.id) ? s = { path: i, message: "业务属性标签名称、ID 或 key 无效" } : p({ kind: "attribute", name: y, key: j.key });
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 });
146
222
  return;
147
223
  }
148
- if (d === "small_payment" || d === "order_remark") {
149
- if (d === "order_remark" && a.hasAttribute("data-order-remark")) {
150
- const E = St(
151
- a.getAttribute("data-order-remark") || ""
152
- ), P = E && yt(E);
153
- P ? p({ kind: "text", value: P }) : s = { path: i, message: "旧订单备注数据无效" };
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: "旧订单备注数据无效" };
154
230
  return;
155
231
  }
156
- const v = a.textContent || "", b = mt(v), y = (B = b == null ? void 0 : b.attrs) == null ? void 0 : B.params;
157
- (d === "small_payment" ? ((R = b == null ? void 0 : b.attrs) == null ? void 0 : R.key) === "small_payment" && a.getAttribute("data-max-amount-cent") === String(Number(y == null ? void 0 : y.amount) * 100) : ((T = b == null ? void 0 : b.attrs) == null ? void 0 : T.key) === "order_note" && a.getAttribute("data-remark-id") === (y == null ? void 0 : y.id) && a.getAttribute("data-remark-mode") === ((y == null ? void 0 : y.contentMode) === "fixed" ? "fixed" : "extract") && a.getAttribute("data-remark-flag") === (y == null ? void 0 : y.flag) && a.getAttribute("data-remark-keep-flag") === (y != null && y.preserveFlag ? "1" : "0") && a.getAttribute("data-remark-position") === (y == null ? void 0 : y.position) && a.getAttribute("data-remark-content") === (y == null ? void 0 : y.content)) ? p({ kind: "text", value: v }) : s = { path: i, message: `${d} 标签属性与内容不一致` };
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} 标签属性与内容不一致` };
158
234
  return;
159
235
  }
160
- if (d === "variable") {
161
- const v = (a.textContent || "").trim(), b = (z = (U = v.match(/^#([^#\r\n]+)#$/u)) == null ? void 0 : U[1]) == null ? void 0 : z.trim(), j = ((W = a.getAttribute("data-variable-name")) == null ? void 0 : W.trim()) || b;
162
- !j || !b || b !== j ? s = { path: i, message: "变量标签名称与显示内容不一致" } : p({
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({
163
239
  kind: "text",
164
- value: j === "订单链接" ? "{订单链接}" : v
240
+ value: V === "订单链接" ? "{订单链接}" : $
165
241
  });
166
242
  return;
167
243
  }
168
- const _ = a.getAttribute("data-tag-name") || a.getAttribute("data-variable-name") || a.getAttribute("data-agent-name") || "", S = a.textContent || "";
169
- if (d === "cdp_tag" && (!a.getAttribute("data-tag-id") || /已失效/u.test(S))) {
170
- s = { path: i, message: "失效顾客标签需要只读保全" };
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: "失效顾客标签需要只读保全" };
171
247
  return;
172
248
  }
173
- if (d === "todo" || d === "cdp_tag") {
174
- const v = (H = S.match(
175
- d === "todo" ? /\{待办@([^{}]+)\}/u : /\{(?:顾客标签|意图标签)@([^{}]+)\}/u
176
- )) == null ? void 0 : H[1], b = a.getAttribute("data-tag-name");
177
- if (v && b && v !== b) {
178
- s = { path: i, message: `${d} 标签名称与显示内容不一致` };
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} 标签名称与显示内容不一致` };
179
255
  return;
180
256
  }
181
257
  }
182
- const x = {
183
- todo: ((J = S.match(/\{待办(?:@[^{}]+)?\}/u)) == null ? void 0 : J[0]) || (_ ? `{待办@${_}}` : ""),
184
- cdp_tag: ((L = S.match(/\{(?:顾客标签|意图标签)@[^{}]+\}/u)) == null ? void 0 : L[0]) || (_ ? `{顾客标签@${_}}` : ""),
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}}` : ""),
185
261
  separator: "{分隔符}",
186
262
  original_repeat: "{原话复述}",
187
- custom_agent: ((F = S.match(/\{自定义Agent\}@[\s\S]+/u)) == null ? void 0 : F[0]) || (_ ? `{自定义Agent}@${_}` : ""),
263
+ custom_agent: ((it = j.match(/\{自定义Agent\}@[\s\S]+/u)) == null ? void 0 : it[0]) || (L ? `{自定义Agent}@${L}` : ""),
188
264
  reasoning: "{推理}",
189
265
  memory_trigger: "{记忆触发点}"
190
266
  };
191
- x[d] ? p({
192
- kind: d === "todo" ? "todo" : "text",
193
- value: x[d]
194
- }) : s = { path: i, message: `旧标签 ${d} 无法映射到新模型` };
267
+ U[u] ? f({
268
+ kind: u === "todo" ? "todo" : "text",
269
+ value: U[u]
270
+ }) : i = { path: s, message: `旧标签 ${u} 无法映射到新模型` };
195
271
  return;
196
272
  }
197
- if (g === "img" && a.getAttribute("data-tag-icon") === "true") return;
198
- if (g === "img" || g === "video") {
199
- const _ = a.getAttribute("src") || "";
200
- xt(_) ? p({
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({
201
277
  kind: "media",
202
- media: g === "img" ? "image" : "video",
203
- src: _,
204
- path: i
205
- }) : s = { path: i, message: "媒体地址无效" };
278
+ media: r === "img" ? "image" : "video",
279
+ src: L,
280
+ path: s
281
+ }) : i = { path: s, message: "媒体地址无效" };
206
282
  return;
207
283
  }
208
- if (g === "br") {
209
- k(!0);
284
+ const q = {
285
+ b: "bold",
286
+ strong: "bold",
287
+ i: "italic",
288
+ em: "italic",
289
+ u: "underline",
290
+ s: "strike",
291
+ strike: "strike",
292
+ del: "strike",
293
+ 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: "链接地址无效" };
299
+ return;
300
+ }
301
+ const U = q ? { type: q } : j ? {
302
+ type: "link",
303
+ attrs: Object.fromEntries(
304
+ ["href", "target", "rel", "title", "class"].filter(($) => n.hasAttribute($)).map(($) => [$, n.getAttribute($)])
305
+ )
306
+ } : 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;
310
+ return;
311
+ }
312
+ if (["ul", "ol", "blockquote", "pre"].includes(r)) {
313
+ p(), f({ kind: "block", tag: r, html: n.outerHTML }), p(!0);
314
+ return;
315
+ }
316
+ if (r === "br") {
317
+ p(!0);
210
318
  return;
211
319
  }
212
- if (!["p", "div", "span"].includes(g) || g === "span" && a.attributes.length > 0) {
213
- s = { path: i, message: `HTML 标签 ${g} 无法无损转换` };
320
+ if (!["p", "div", "span"].includes(r) || r === "span" && n.attributes.length > 0) {
321
+ i = { path: s, message: `HTML 标签 ${r} 无法无损转换` };
214
322
  return;
215
323
  }
216
- (g === "p" || g === "div") && k();
217
- const G = m.length;
218
- Array.from(a.childNodes).forEach(
219
- (_, S) => $(_, `${i}.childNodes[${S}]`)
220
- ), (g === "p" || g === "div") && (m.length === G || m[m.length - 1].length) && k(!0);
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);
221
329
  };
222
- return Array.from(c.body.childNodes).forEach(
223
- (l, i) => $(l, `web_content.childNodes[${i}]`)
224
- ), s ? { ok: !1, issues: [s], raw: t } : (m.length > 1 && !m[m.length - 1].length && m.pop(), { ok: !0, value: m });
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 });
225
333
  }
226
- function rt(t) {
334
+ function bt(t) {
227
335
  return t.every(
228
- (r) => r.kind === "text" || r.kind === "todo" || r.kind === "attribute"
336
+ (o) => o.kind === "text" || o.kind === "todo" || o.kind === "attribute" || o.kind === "tableKnowledge"
229
337
  ) ? t.map(
230
- (r) => r.kind === "attribute" ? gt(r.name) : r.value
338
+ (o) => o.kind === "tableKnowledge" ? `##${o.name}##` : o.kind === "attribute" ? Lt(o.name) : o.value
231
339
  ).join("") : null;
232
340
  }
233
- function It(t, r, c) {
234
- var k, $;
235
- const m = [], s = /(#@[^#]+@#|##[^#]+##|#[^#\r\n]+#|\{[^{}]+\}|\[sep\]|\$\$小额打款@[^$\r\n]*\$\$|\^\^订单备注-[\s\S]*?\^\^)/gu;
236
- let p = 0;
237
- for (const l of t.matchAll(s)) {
238
- const i = l.index || 0;
239
- if (i > p) {
240
- const g = t.slice(p, i);
241
- if (/\$\$小额打款|\^\^订单备注-|\{业务属性@|<不发送跟单>/u.test(g))
242
- return o(t, r, "工具、业务属性或不发送跟单标记格式错误");
243
- m.push({ type: "text", text: g });
244
- }
245
- const a = l[0];
246
- if (a.startsWith("$$小额打款@") || a.startsWith("^^订单备注-")) {
247
- const g = mt(a);
248
- if (!g) return o(t, r, `工具标记 ${a} 格式错误`);
249
- m.push(g);
250
- } else if (a === "{分隔符}" || a === "[sep]")
251
- m.push({
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);
349
+ if (/\$\$小额打款|\^\^订单备注-|\{业务属性@|\{(?:智能建单|智能工单|外部方法)@|<不发送跟单>/u.test(
350
+ n
351
+ ))
352
+ return c(t, o, "工具、业务属性或不发送跟单标记格式错误");
353
+ a.push({ type: "text", text: n });
354
+ }
355
+ const s = y[0];
356
+ if (/^\{智能(?:建单|工单)/u.test(s)) {
357
+ const n = Nt(s);
358
+ if (!n) return c(t, o, `工单标记 ${s} 格式错误`);
359
+ a.push({ type: "businessToken", attrs: { kind: "ticket", ...n } });
360
+ } else if (s.startsWith("$$小额打款@") || s.startsWith("^^订单备注-") || s.startsWith("{外部方法")) {
361
+ const n = St(s);
362
+ if (!n) return c(t, o, `工具标记 ${s} 格式错误`);
363
+ a.push(n);
364
+ } else if (s === "{分隔符}" || s === "[sep]")
365
+ a.push({
252
366
  type: "businessToken",
253
367
  attrs: {
254
368
  kind: "separator",
@@ -257,122 +371,149 @@ function It(t, r, c) {
257
371
  token: "{分隔符}"
258
372
  }
259
373
  });
260
- else if (a === "{订单链接}" || /^#[^#\r\n]+#$/u.test(a)) {
261
- const g = a === "{订单链接}" ? "订单链接" : a.slice(1, -1).trim(), d = (k = c.variable) == null ? void 0 : k.call(c, g);
262
- if (!g || !(d != null && d.key) || d.label !== g)
263
- return o(t, r, `变量 ${g} 缺少可解析的引用`);
264
- m.push({
374
+ else if (/^##[^#\r\n]+##$/u.test(s)) {
375
+ const n = s.slice(2, -2);
376
+ if (!n.trim()) return c(t, o, "表格知识名称不能为空");
377
+ a.push({
378
+ type: "businessToken",
379
+ attrs: { kind: "tableKnowledge", key: n, label: n }
380
+ });
381
+ } else if (s === "{订单链接}" || /^#[^#\r\n]+#$/u.test(s)) {
382
+ const n = s === "{订单链接}" ? "订单链接" : s.slice(1, -1).trim(), r = (f = d.variable) == null ? void 0 : f.call(d, n);
383
+ if (!n || !(r != null && r.key) || r.label !== n)
384
+ return c(t, o, `变量 ${n} 缺少可解析的引用`);
385
+ a.push({
265
386
  type: "businessToken",
266
- attrs: { kind: "variable", key: d.key, label: d.label, token: a }
387
+ attrs: { kind: "variable", key: r.key, label: r.label, token: s }
267
388
  });
268
- } else if (a.startsWith("{业务属性@")) {
269
- const g = ($ = a.match(/^\{业务属性@([^{}<>\r\n]+)\}$/u)) == null ? void 0 : $[1], d = g && bt(g);
270
- if (!d)
271
- return o(t, r, `业务属性 ${g || a} 不在旧目录中`);
272
- m.push({
389
+ } else if (s.startsWith("{业务属性@")) {
390
+ const n = (p = s.match(/^\{业务属性@([^{}<>\r\n]+)\}$/u)) == null ? void 0 : p[1], r = n && Dt(n, S);
391
+ if (!r)
392
+ return c(t, o, `业务属性 ${n || s} 不在旧目录中`);
393
+ a.push({
273
394
  type: "businessToken",
274
- attrs: { kind: "attribute", key: d.key, label: d.name }
395
+ attrs: { kind: "attribute", key: r.key, label: r.name }
275
396
  });
276
- } else return o(t, r, `正文标记 ${a} 无法在当前位置转换`);
277
- p = i + a.length;
397
+ } else {
398
+ if (/^\{(?:待办|原话复述|推理|记忆触发点|顾客标签|意图标签|自定义Agent)/u.test(
399
+ s
400
+ ) || s.startsWith("#@"))
401
+ return c(t, o, `正文标记 ${s} 无法在当前位置转换`);
402
+ a.push({ type: "text", text: s });
403
+ }
404
+ g = m + s.length;
278
405
  }
279
- if (p < t.length) {
280
- const l = t.slice(p);
281
- if (/\$\$小额打款|\^\^订单备注-|\{业务属性@|<不发送跟单>/u.test(l))
282
- return o(t, r, "工具、业务属性或不发送跟单标记格式错误");
283
- m.push({ type: "text", text: l });
406
+ if (g < t.length) {
407
+ const y = t.slice(g);
408
+ if (/\$\$小额打款|\^\^订单备注-|\{业务属性@|\{(?:智能建单|智能工单|外部方法)@|<不发送跟单>/u.test(
409
+ y
410
+ ))
411
+ return c(t, o, "工具、业务属性或不发送跟单标记格式错误");
412
+ a.push({ type: "text", text: y });
284
413
  }
285
- return { ok: !0, value: m };
414
+ return { ok: !0, value: a };
286
415
  }
287
- function _t(t, r) {
288
- const c = /* @__PURE__ */ new Set();
289
- let m = 0, s = null;
290
- const p = (k, $) => {
291
- var l, i, a;
292
- if (k.type === "businessToken" && ((l = k.attrs) == null ? void 0 : l.kind) === "tool" && (k.attrs.key === "small_payment" && ++m > 1 && (s = $), k.attrs.key === "order_note")) {
293
- const g = String(((i = k.attrs.params) == null ? void 0 : i.id) || "");
294
- c.has(g) && (s = $), c.add(g);
295
- }
296
- (a = k.content) == null || a.forEach(
297
- (g, d) => p(g, `${$}.content[${d}]`)
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);
424
+ }
425
+ (m = g.content) == null || m.forEach(
426
+ (s, n) => i(s, `${f}.content[${n}]`)
298
427
  );
299
428
  };
300
- return t.forEach((k, $) => p(k, `${r}[${$}]`)), s;
429
+ return t.forEach((g, f) => i(g, `${o}[${f}]`)), a;
301
430
  }
302
- function Nt(t) {
303
- var r, c, m, s, p;
304
- for (let k = 0; k < t.length; k++) {
305
- const $ = t[k], l = (r = $.content) == null ? void 0 : r[0];
306
- if ($.type !== "paragraph" || ((c = $.content) == null ? void 0 : c.length) !== 1 || (l == null ? void 0 : l.type) !== "businessToken" || ((m = l.attrs) == null ? void 0 : m.kind) !== "separator")
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")
307
436
  continue;
308
- const i = t[k - 1], a = t[k + 1];
309
- if ((i == null ? void 0 : i.type) === "paragraph" && ((s = i.content) != null && s.length))
310
- i.content.push(l);
311
- else if ((a == null ? void 0 : a.type) === "paragraph" && ((p = a.content) != null && p.length))
312
- a.content.unshift(l);
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);
313
442
  else continue;
314
- t.splice(k--, 1);
443
+ t.splice(g--, 1);
315
444
  }
316
445
  }
317
- function Et(t, r, c = {}, m = {}) {
318
- var X, Z, K, tt, et, nt, at, h;
446
+ function qt(t, o, d = {}, S = {}) {
447
+ var yt, v, A, N, J, G, nt, lt, kt;
319
448
  if (!t || typeof t != "object" || Array.isArray(t))
320
- return o(t, "item", "旧知识记录格式不正确");
321
- if (!(r != null && r.trim()))
322
- return o(t, "sourceRecordKey", "需要稳定的来源记录键");
323
- const s = typeof t.web_content == "string" && t.web_content ? "web_content" : "content", p = t[s];
324
- if (typeof p != "string") return o(t, s, "旧知识缺少内容");
325
- const k = s === "content" && (!!String(t.todo_plan_id || "").trim() || !!t.todo_tag_metas), $ = pt(p, k);
326
- if (!$.ok) return { ...$, raw: t };
327
- const l = $.value, i = l[0] || [], a = i.findIndex(
328
- (e) => e.kind === "originalReply" || e.kind === "media"
329
- ), g = rt(
330
- a >= 0 ? i.slice(0, a) : i
331
- ), d = g == null ? void 0 : g.match(/^\s*【([^【】\r\n]+)】([\s\S]*)$/u), G = d ? d[1] : m.questionText ?? "";
332
- if (vt(G))
333
- return o(t, "questionText", "顾客问法包含保留分隔符");
334
- const M = new DOMParser().parseFromString(p, "text/html"), C = Array.from(
335
- M.querySelectorAll('span[data-tag-type="todo"], span[data-tag="true"]')
336
- ).filter((e) => st(e) === "todo").map(
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(
455
+ t,
456
+ "businessAttributes",
457
+ "业务属性目录格式无效或存在重复引用"
458
+ );
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(
337
473
  (e) => {
338
- var n;
339
- return ((n = (e.textContent || "").match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : n[1]) || e.getAttribute("data-tag-name") || "";
474
+ var l;
475
+ return ((l = (e.textContent || "").match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : l[1]) || e.getAttribute("data-tag-name") || "";
340
476
  }
341
477
  );
342
- k && C.push(
343
- ...Array.from(p.matchAll(/\{待办@([^{}]+)\}/gu), (e) => e[1])
478
+ f && O.push(
479
+ ...Array.from(g.matchAll(/\{待办@([^{}]+)\}/gu), (e) => e[1])
344
480
  );
345
- const B = Array.from(
346
- M.querySelectorAll('span[data-tag-type="cdp_tag"]')
481
+ const P = Array.from(
482
+ z.querySelectorAll('span[data-tag-type="cdp_tag"]')
347
483
  ).map((e) => {
348
- var n;
484
+ var l;
349
485
  return {
350
- name: ((n = (e.textContent || "").match(
486
+ name: ((l = (e.textContent || "").match(
351
487
  /\{(?:顾客标签|意图标签)@([^{}]+)\}/u
352
- )) == null ? void 0 : n[1]) || e.getAttribute("data-tag-name") || "",
488
+ )) == null ? void 0 : l[1]) || e.getAttribute("data-tag-name") || "",
353
489
  id: e.getAttribute("data-tag-id") || ""
354
490
  };
355
491
  });
356
- if (B.length > 1)
357
- return o(t, s, "新模型每条问法只能选择一个顾客标签");
358
- const R = /* @__PURE__ */ new Map();
359
- for (const [e, n] of Array.from(
360
- M.querySelectorAll('span[data-tag-type="todo"], span[data-tag="true"]')
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 || "") });
496
+ }
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"]')
361
502
  ).entries()) {
362
- if (st(n) !== "todo") continue;
363
- const u = (X = n.getAttribute("plan_id")) == null ? void 0 : X.trim();
364
- if (!u) continue;
365
- const I = ((Z = (n.textContent || "").match(/\{待办@([^{}]+)\}/u)) == null ? void 0 : Z[1]) || n.getAttribute("data-tag-name") || "";
366
- if (!I)
367
- return o(t, `${s}.todo[${e}]`, "待办标签缺少方案名称");
368
- const f = R.get(I);
369
- if (f && f.id !== u)
370
- return o(
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(
371
512
  t,
372
- `${s}.todo[${e}]`,
513
+ `${i}.todo[${e}]`,
373
514
  "同名待办对应多个方案 ID"
374
515
  );
375
- R.set(I, { id: u, label: I });
516
+ M.set(h, { id: k, label: h });
376
517
  }
377
518
  if (t.todo_tag_metas !== void 0 && t.todo_tag_metas !== "") {
378
519
  let e = t.todo_tag_metas;
@@ -380,93 +521,106 @@ function Et(t, r, c = {}, m = {}) {
380
521
  try {
381
522
  e = JSON.parse(e);
382
523
  } catch {
383
- return o(t, "todo_tag_metas", "待办方案元数据不是有效 JSON");
524
+ return c(t, "todo_tag_metas", "待办方案元数据不是有效 JSON");
384
525
  }
385
526
  if (!Array.isArray(e))
386
- return o(t, "todo_tag_metas", "待办方案元数据必须为数组");
387
- for (const [n, u] of e.entries()) {
388
- if (!u || typeof u != "object" || typeof u.plan_id != "string" || !u.plan_id.trim() || typeof u.plan_name != "string" || !u.plan_name.trim() || u.tag_type !== void 0 && u.tag_type !== 2)
389
- return o(
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(
390
531
  t,
391
- `todo_tag_metas[${n}]`,
532
+ `todo_tag_metas[${l}]`,
392
533
  "待办方案缺少有效 ID、名称或已失效"
393
534
  );
394
- const I = R.get(u.plan_name);
395
- if (I && I.id !== u.plan_id)
396
- return o(
535
+ const h = M.get(k.plan_name);
536
+ if (h && h.id !== k.plan_id)
537
+ return c(
397
538
  t,
398
- `todo_tag_metas[${n}]`,
539
+ `todo_tag_metas[${l}]`,
399
540
  "待办方案元数据与富文本标签的 plan_id 不一致"
400
541
  );
401
- R.set(u.plan_name, {
402
- id: u.plan_id,
403
- label: u.plan_name
542
+ M.set(k.plan_name, {
543
+ id: k.plan_id,
544
+ label: k.plan_name
404
545
  });
405
546
  }
406
547
  }
407
548
  if (String(t.todo_plan_id || "").trim() && typeof t.todo_plan_name == "string") {
408
- const e = R.get(t.todo_plan_name);
549
+ const e = M.get(t.todo_plan_name);
409
550
  if (e && e.id !== String(t.todo_plan_id))
410
- return o(t, "todo_plan_id", "待办方案字段与多方案元数据不一致");
411
- R.set(t.todo_plan_name, {
551
+ return c(t, "todo_plan_id", "待办方案字段与多方案元数据不一致");
552
+ M.set(t.todo_plan_name, {
412
553
  id: String(t.todo_plan_id),
413
554
  label: t.todo_plan_name
414
555
  });
415
556
  }
416
- const T = {}, U = !d && g && /^(?:\{(?:待办|顾客标签|意图标签)@[^{}]+\}|\{(?:原话复述|记忆触发点|推理)\})+$/u.test(
417
- g.trim()
418
- ), z = [];
419
- let W = !1, H = "", J = "", L = (d == null ? void 0 : d[2].trim()) || (U ? g.trim() : "");
420
- for (; L; ) {
421
- if (L.startsWith("{自定义Agent}@")) {
422
- J = L;
557
+ const _ = {}, B = !u && r && /^(?:\{(?:待办|顾客标签|意图标签)@[^{}]+\}|\{(?:原话复述|记忆触发点|推理)\})+$/u.test(
558
+ r.trim()
559
+ ), 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();
564
+ continue;
565
+ }
566
+ if (/^\{(?:智能建单|智能工单|外部方法)@/u.test(D)) {
567
+ at = D;
423
568
  break;
424
569
  }
425
- const e = L.match(
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();
577
+ continue;
578
+ }
579
+ const e = D.match(
426
580
  /^\{(待办|顾客标签|意图标签)@([^{}]+)\}|^\{(原话复述|记忆触发点|推理)\}/u
427
581
  );
428
582
  if (!e) {
429
- if (L.startsWith("{"))
430
- return o(t, s, `问法后的标记无法转换:${L}`);
431
- H = L;
583
+ if (D.startsWith("{"))
584
+ return c(t, i, `问法后的标记无法转换:${D}`);
585
+ at = D;
432
586
  break;
433
587
  }
434
588
  if (e[1]) {
435
- const n = e[1] === "待办" ? "todo" : "tagged", u = n === "todo" ? C.find((D) => D === e[2]) : B.find((D) => D.name === e[2]);
436
- if (!u)
437
- return o(
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(
438
592
  t,
439
- s,
593
+ i,
440
594
  `${e[1]} ${e[2]} 不是有效的旧版富文本标签`
441
595
  );
442
- const I = n === "todo" && t.todo_plan_name === e[2] ? String(t.todo_plan_id || "") : n === "tagged" ? u.id : "", f = n === "todo" && R.has(e[2]) ? R.get(e[2]) : I ? { id: I, label: e[2] } : (K = c.selection) == null ? void 0 : K.call(c, n, e[2]);
443
- if (!(f != null && f.id) || !f.label || f.label !== e[2])
444
- return o(
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(
445
599
  t,
446
- s,
600
+ i,
447
601
  `${e[1]} ${e[2]} 缺少匹配的方案 ID`
448
602
  );
449
- if (n === "todo")
450
- z.push({ kind: "todo", value: e[0] });
603
+ if (l === "todo")
604
+ K.push({ kind: "todo", value: e[0] });
451
605
  else {
452
- if (T[n]) return o(t, s, `${e[1]}重复`);
453
- T[n] = { version: 1, data: { enabled: !0, tag: f } };
606
+ if (_[l]) return c(t, i, `${e[1]}重复`);
607
+ _[l] = { version: 1, data: { enabled: !0, tag: T } };
454
608
  }
455
609
  } else if (e[3] === "推理") {
456
- if (W) return o(t, s, "推理标记重复");
457
- W = !0;
610
+ if (Y) return c(t, i, "推理标记重复");
611
+ Y = !0;
458
612
  } else {
459
- const n = e[3] === "原话复述" ? "originalReply" : "memory";
460
- if (T[n]) return o(t, s, `${e[3]}重复`);
461
- T[n] = { version: 1, data: { enabled: !0 } };
613
+ const l = e[3] === "原话复述" ? "originalReply" : "memory";
614
+ if (_[l]) return c(t, i, `${e[3]}重复`);
615
+ _[l] = { version: 1, data: { enabled: !0 } };
462
616
  }
463
- L = L.slice(e[0].length).trimStart();
617
+ D = D.slice(e[0].length).trimStart();
464
618
  }
465
619
  if (Array.isArray(t.tag_meta))
466
- for (const [e, n] of t.tag_meta.entries()) {
467
- if (!n || typeof n != "object")
468
- return o(t, `tag_meta[${e}]`, "标签元数据格式错误");
469
- const u = n;
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;
470
624
  if (![
471
625
  "cdp_tag",
472
626
  "todo",
@@ -475,88 +629,104 @@ function Et(t, r, c = {}, m = {}) {
475
629
  "original_repeat",
476
630
  "custom_agent",
477
631
  "memory",
478
- "separator"
479
- ].includes(String(u.type)))
480
- return o(
632
+ "separator",
633
+ "table_knowledge"
634
+ ].includes(String(k.type)))
635
+ return c(
481
636
  t,
482
637
  `tag_meta[${e}]`,
483
638
  "旧标签元数据无法映射到新模型"
484
639
  );
485
- if (u.invalid)
486
- return o(t, `tag_meta[${e}]`, "失效标签需要只读保全");
487
- if (u.type === "cdp_tag" && (!T.tagged || T.tagged.data.tag.id !== String(u.value || "") || T.tagged.data.tag.label !== String(u.name || "")))
488
- return o(
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(
489
644
  t,
490
645
  `tag_meta[${e}]`,
491
646
  "顾客标签 ID 与富文本标签不一致"
492
647
  );
493
648
  }
494
- const F = t.todo_plan_id;
495
- if (F != null && String(F).trim()) {
649
+ const et = t.todo_plan_id;
650
+ if (et != null && String(et).trim()) {
496
651
  const e = t.todo_plan_name;
497
652
  if (typeof e != "string" || !e.trim())
498
- return o(t, "todo_plan_name", "待办方案 ID 存在但名称缺失");
499
- if (!C.includes(e))
500
- return o(t, "web_content", "待办方案字段缺少对应的富文本标签");
653
+ return c(t, "todo_plan_name", "待办方案 ID 存在但名称缺失");
654
+ if (!O.includes(e))
655
+ return c(t, "web_content", "待办方案字段缺少对应的富文本标签");
501
656
  }
502
- const _ = d || U ? l.slice(1) : [...l];
503
- d && a >= 0 && _.unshift(i.slice(a)), J && _.unshift([{ kind: "text", value: J }]);
504
- const S = Number(t.knowledge_type || 0);
505
- let x = S === 2 ? "reasoning" : S === 3 ? "agent" : "normal";
506
- if (t.knowledge_type !== void 0 && ![0, 1, 2, 3].includes(S))
507
- return o(t, "knowledge_type", "未知的旧知识类型");
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", "未知的旧知识类型");
508
663
  if (Array.isArray(t.tag_meta)) {
509
664
  if (t.tag_meta.some(
510
665
  (e) => e && typeof e == "object" && e.type === "reasoning"
511
- ) && S === 1)
512
- return o(t, "tag_meta", "推理标签与知识类型不一致");
666
+ ) && Z === 1)
667
+ return c(t, "tag_meta", "推理标签与知识类型不一致");
513
668
  if (t.tag_meta.some(
514
669
  (e) => e && typeof e == "object" && e.type === "custom_agent"
515
- ) && (S === 1 || S === 2))
516
- return o(t, "tag_meta", "Agent 标签与知识类型不一致");
670
+ ) && (Z === 1 || Z === 2))
671
+ return c(t, "tag_meta", "Agent 标签与知识类型不一致");
517
672
  }
518
- let v = null;
519
- const b = (tt = _[0]) == null ? void 0 : tt[0], y = (b == null ? void 0 : b.kind) === "text" && /^\s*\{推理\}/u.test(b.value);
520
- if (W || y) {
521
- if (x === "agent")
522
- return o(t, s, "推理标记与 Agent 类型冲突");
523
- if (x = "reasoning", y && (b == null ? void 0 : b.kind) === "text") {
524
- const e = b.value.replace(/^\s*\{推理\}\s*/u, ""), n = _[0].slice(1);
525
- for (e && n.unshift({ kind: "text", value: e }); ((et = n[0]) == null ? void 0 : et.kind) === "text" && !n[0].value.trim(); )
526
- n.shift();
527
- n.length ? _[0] = n : _.shift();
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();
528
683
  }
529
684
  }
530
- if (_.length && ((nt = rt(_[0])) != null && nt.trim().startsWith("{自定义Agent}@"))) {
531
- if (x === "reasoning")
532
- return o(t, s, "Agent 标记与推理类型冲突");
533
- x = "agent";
534
- const e = rt(_[0]).trim().slice(11), n = Array.isArray(t.tag_meta) ? t.tag_meta.find(
535
- (f) => f && typeof f == "object" && f.type === "custom_agent" && f.agent_name === e
536
- ) : void 0, u = Array.from(
537
- M.querySelectorAll("span[data-agent-id]")
538
- ).find(
539
- (f) => st(f) === "custom_agent" && ((f.textContent || "").trim() === `{自定义Agent}@${e}` || f.getAttribute("data-agent-name") === e || f.getAttribute("data-tag-name") === e)
540
- ), I = (u == null ? void 0 : u.getAttribute("data-agent-id")) || "";
541
- if (I && (n != null && n.agent_id) && I !== n.agent_id)
542
- return o(t, "tag_meta", "Agent ID 与富文本标签不一致");
543
- if (v = typeof (n == null ? void 0 : n.agent_id) == "string" && n.agent_id ? { id: n.agent_id, name: e } : I.trim() ? { id: I, name: e } : ((at = c.agent) == null ? void 0 : at.call(c, e)) || null, !(v != null && v.id) || v.name !== e)
544
- return o(t, s, `Agent ${e} 缺少匹配的 ID`);
545
- _.shift();
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();
546
706
  }
547
- if (x === "agent" && !v)
548
- return o(t, s, "Agent 知识缺少可解析的 Agent 标记");
549
- H && _.unshift([{ kind: "text", value: H }]);
550
- const j = (e, n, u = !1, I = !1) => {
551
- var w;
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;
552
712
  if (e.kind === "originalReply")
553
- return o(t, n, "原话块不可嵌套原话模板");
554
- if (e.kind === "media")
555
- return o(t, n, "原话块包含无法转换的媒体");
713
+ return c(t, l, "原话块不可嵌套原话模板");
714
+ if (e.kind === "media" || e.kind === "block")
715
+ return c(t, l, "块级内容不能作为行内标签转换");
716
+ if (e.kind === "tableKnowledge")
717
+ return {
718
+ ok: !0,
719
+ value: [
720
+ {
721
+ type: "businessToken",
722
+ attrs: { kind: "tableKnowledge", key: e.key, label: e.name }
723
+ }
724
+ ]
725
+ };
556
726
  if (e.kind === "attribute")
557
- return x !== "reasoning" || I ? o(
727
+ return W !== "agent" && (W !== "reasoning" || h) ? c(
558
728
  t,
559
- n,
729
+ l,
560
730
  "业务属性只能位于推理知识正文,不能放入原话"
561
731
  ) : {
562
732
  ok: !0,
@@ -568,185 +738,294 @@ function Et(t, r, c = {}, m = {}) {
568
738
  ]
569
739
  };
570
740
  if (e.kind !== "todo") {
571
- const A = It(
572
- x === "normal" ? e.value.replace(/\{(?:待办(?:@[^{}]+)?|原话复述)\}/gu, "") : e.value,
573
- n,
574
- c
741
+ const I = Qt(
742
+ W === "normal" ? e.value.replace(/\{(?:待办(?:@[^{}]+)?|原话复述)\}/gu, "") : e.value,
743
+ l,
744
+ d,
745
+ a
575
746
  );
576
- return A.ok && (x !== "reasoning" || I) && A.value.some(
577
- (q) => {
578
- var O;
579
- return q.type === "businessToken" && ((O = q.attrs) == null ? void 0 : O.kind) === "attribute";
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";
580
751
  }
581
- ) ? o(
752
+ ) ? c(
582
753
  t,
583
- n,
754
+ l,
584
755
  "业务属性只能位于推理知识正文,不能放入原话"
585
- ) : A;
586
- }
587
- if (x === "normal" && !u) return { ok: !0, value: [] };
588
- if (x === "agent")
589
- return o(t, n, "Agent 知识当前没有可保存的待办正文");
590
- if (e.value === "{待办}")
591
- return o(t, n, "知识区待办缺少可解析的方案名称和 ID");
592
- const f = e.value.slice(4, -1), D = R.get(f) || ((w = c.selection) == null ? void 0 : w.call(c, "todo", f));
593
- return !(D != null && D.id) || D.label !== f ? o(t, n, `待办 ${f} 缺少匹配的方案 ID`) : x === "normal" && T.todo ? o(t, s, "待办重复") : x === "normal" ? (T.todo = { version: 1, data: { enabled: !0, tag: D } }, { ok: !0, value: [] }) : {
756
+ ) : I.ok && ((tt = e.marks) != null && tt.length) ? {
757
+ ok: !0,
758
+ value: I.value.map((Q) => ({
759
+ ...Q,
760
+ marks: e.marks
761
+ }))
762
+ } : I : I;
763
+ }
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: [] }) : {
594
767
  ok: !0,
595
768
  value: [
596
769
  {
597
770
  type: "businessToken",
598
- attrs: { kind: "todo", key: D.id, label: D.label }
771
+ attrs: {
772
+ kind: "todo",
773
+ key: E.id,
774
+ label: E.label,
775
+ ...e.value === "{待办}" ? { token: "{待办}" } : {}
776
+ }
599
777
  }
600
778
  ]
601
779
  };
602
780
  };
603
- if (x === "normal") {
604
- !z.length && String(F || "").trim() && typeof t.todo_plan_name == "string" && (T.todo = {
781
+ if (W === "normal") {
782
+ !K.length && String(et || "").trim() && typeof t.todo_plan_name == "string" && (_.todo = {
605
783
  version: 1,
606
784
  data: {
607
785
  enabled: !0,
608
- tag: { id: String(F), label: t.todo_plan_name }
786
+ tag: { id: String(et), label: t.todo_plan_name }
609
787
  }
610
788
  });
611
- for (const e of z) {
612
- const n = j(e, s, !0);
613
- if (!n.ok) return { ...n, raw: t };
614
- }
615
- } else z.length && _.unshift(z);
616
- x !== "normal" && T.originalReply && (delete T.originalReply, _.unshift([{ kind: "text", value: "{原话复述}" }]));
617
- const E = [];
618
- for (let e = 0; e < _.length; e++) {
619
- const n = _[e], u = `${s}.line[${e + 2}]`;
620
- if (((h = rt(n)) == null ? void 0 : h.trim()) === "{原话复述}" && x === "reasoning") {
621
- const w = _[++e];
622
- if (!w) return o(t, u, "原话块缺少内容");
623
- if (rt(w) === null) return o(t, u, "原话块包含无法转换的媒体");
624
- const q = [];
625
- for (const O of w) {
626
- const Y = j(O, u, !1, !0);
627
- if (!Y.ok) return { ...Y, raw: t };
628
- q.push(...Y.value);
629
- }
630
- E.push({
631
- type: "originalReply",
632
- content: [{ type: "paragraph", content: q }]
633
- });
634
- continue;
635
- }
636
- if (x === "agent") {
637
- if (n.some(
638
- (w) => w.kind === "text" || w.kind === "todo" ? !!w.value.trim() : !0
639
- ))
640
- return o(t, u, "Agent 知识不能包含正文");
641
- continue;
789
+ for (const e of K) {
790
+ const l = U(e, i, !0);
791
+ if (!l.ok) return { ...l, raw: t };
642
792
  }
643
- let f = [];
644
- const D = () => {
645
- f.length && (E.push({ type: "paragraph", content: f }), f = []);
646
- };
647
- for (const w of n)
648
- if (w.kind === "originalReply") {
649
- f.every((O) => {
650
- var Y;
651
- return O.type === "text" && !((Y = O.text) != null && Y.trim());
652
- }) && (f = []), D();
653
- const A = pt(w.html, k);
654
- if (!A.ok) return { ...A, raw: t };
655
- const q = [];
656
- for (const [O, Y] of A.value.entries()) {
657
- const ct = [];
658
- for (const ht of Y) {
659
- const lt = j(
660
- ht,
661
- `${u}.originalReply[${O}]`,
662
- !1,
663
- !0
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);
812
+ }
813
+ h.push({
814
+ type: "originalReply",
815
+ content: [{ type: "paragraph", content: dt }]
816
+ });
817
+ continue;
818
+ }
819
+ let Q = [];
820
+ const ct = () => {
821
+ Q.length && (h.push({ type: "paragraph", content: Q }), Q = []);
822
+ };
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`,
835
+ !0
836
+ );
837
+ if (!X.ok) return X;
838
+ W === "normal" ? h.push(...X.value) : h.push({
839
+ type: "originalReply",
840
+ content: X.value.length ? X.value : [{ type: "paragraph" }]
841
+ });
842
+ } else if (R.kind === "media")
843
+ ct(), h.push({
844
+ type: "mediaBlock",
845
+ attrs: { kind: R.media, src: R.src, status: "ready" }
846
+ });
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({
853
+ type: "codeBlock",
854
+ ...C.hasAttribute("data-language") ? { attrs: { language: C.getAttribute("data-language") } } : {},
855
+ content: C.textContent ? [{ type: "text", text: C.textContent }] : []
856
+ });
857
+ continue;
858
+ }
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,
866
+ a
664
867
  );
665
- if (!lt.ok) return { ...lt, raw: t };
666
- ct.push(...lt.value);
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);
667
873
  }
668
- q.push({ type: "paragraph", content: ct });
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
878
+ });
879
+ } else {
880
+ const C = U(R, F, !1, k);
881
+ if (!C.ok) return { ...C, raw: t };
882
+ Q.push(...C.value);
669
883
  }
670
- x === "normal" ? E.push(...q) : E.push({ type: "originalReply", content: q });
671
- } else if (w.kind === "media")
672
- D(), E.push({
673
- type: "mediaBlock",
674
- attrs: { kind: w.media, src: w.src, status: "ready" }
675
- });
676
- else {
677
- const A = j(w, u);
678
- if (!A.ok) return { ...A, raw: t };
679
- f.push(...A.value);
680
- }
681
- n.some((w) => w.kind === "originalReply") && f.every((w) => {
682
- var A;
683
- return w.type === "text" && !((A = w.text) != null && A.trim());
684
- }) && (f = []), (f.length || !n.length) && E.push({ type: "paragraph", content: f });
685
- }
686
- Nt(E);
687
- const P = _t(E, `${s}.block`);
688
- if (P) return o(t, P, "工具标签重复");
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 });
888
+ }
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, "工具标签重复");
689
896
  const ot = {
690
897
  type: "doc",
691
- content: E.length ? E : [{ type: "paragraph" }]
692
- }, it = x === "agent" ? null : At(ot, r).doc, Q = {
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());
906
+ }
907
+ ));
908
+ }
909
+ ), ft = {
693
910
  schemaVersion: 1,
694
- type: x,
695
- question: { text: G },
696
- knowledge: { doc: it, agentRef: v },
697
- extensionState: T
698
- }, V = ft(Q);
699
- return V ? o(t, V, "转换后的场景未通过新模型校验") : { ok: !0, value: Q };
911
+ type: W,
912
+ question: { text: q },
913
+ knowledge: {
914
+ doc: st,
915
+ agentRef: it,
916
+ ...W === "agent" && vt ? {
917
+ agentBody: jt(ot, o).doc
918
+ } : {}
919
+ },
920
+ extensionState: _
921
+ }, mt = Et(ft);
922
+ return mt ? c(t, mt, "转换后的场景未通过新模型校验") : { ok: !0, value: ft };
700
923
  }
701
- function Rt(t, r) {
702
- var c, m, s, p, k, $;
703
- if (t.type === "text" && !((c = t.marks) != null && c.length))
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(
928
+ { ...t, marks: void 0 },
929
+ o,
930
+ d
931
+ );
932
+ if (!r.ok) return r;
933
+ let { html: u } = r.value;
934
+ for (const q of [...t.marks].reverse()) {
935
+ const z = {
936
+ bold: "b",
937
+ italic: "i",
938
+ underline: "u",
939
+ strike: "s",
940
+ code: "code",
941
+ 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}>`;
948
+ }
949
+ return { ok: !0, value: { html: u, text: r.value.text } };
950
+ }
951
+ if (t.type === "text" && !((a = t.marks) != null && a.length))
952
+ return {
953
+ ok: !0,
954
+ value: { html: w(t.text || ""), text: t.text || "" }
955
+ };
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) ? {
959
+ ok: !0,
960
+ 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
965
+ }
966
+ } : c(t, o, "工单引用无法映射到旧格式");
967
+ }
968
+ if (t.type === "businessToken" && ((f = t.attrs) == null ? void 0 : f.kind) === "tableKnowledge") {
969
+ const r = String(t.attrs.label);
704
970
  return {
705
971
  ok: !0,
706
- value: { html: N(t.text || ""), text: t.text || "" }
972
+ 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(
976
+ String(t.attrs.key)
977
+ )}">##${w(r)}##</span>`,
978
+ text: `##${r}##`
979
+ }
707
980
  };
708
- if (t.type === "businessToken" && ((m = t.attrs) == null ? void 0 : m.kind) === "todo") {
709
- const l = String(t.attrs.label), i = `{待办@${l}}`;
981
+ }
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}}`;
710
984
  return {
711
985
  ok: !0,
712
986
  value: {
713
- html: `<span contenteditable="false" data-tag="true" data-tag-type="todo" data-tag-name="${N(
714
- l
715
- )}" plan_id="${N(String(t.attrs.key))}">${N(
716
- i
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
717
991
  )}</span>`,
718
- text: i
992
+ text: u
719
993
  }
720
994
  };
721
995
  }
722
- if (t.type === "businessToken" && ((s = t.attrs) == null ? void 0 : s.kind) === "variable") {
723
- const l = String(t.attrs.label || t.attrs.key), i = l === "订单链接" ? "{订单链接}" : `#${l}#`, a = `#${l}#`;
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}#`;
724
998
  return {
725
999
  ok: !0,
726
1000
  value: {
727
- html: `<span contenteditable="false" data-tag-type="variable" data-variable="true" data-variable-name="${N(
728
- l
729
- )}"${l === "客服昵称" ? ' data-customer="true"' : ""}>${N(
730
- a
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
731
1005
  )}</span>`,
732
- text: i
1006
+ text: u
733
1007
  }
734
1008
  };
735
1009
  }
736
- if (t.type === "businessToken" && ((p = t.attrs) == null ? void 0 : p.kind) === "attribute") {
737
- const l = Tt(String(t.attrs.key));
738
- if (!l || t.attrs.label !== l.name)
739
- return o(t, r, "业务属性不在旧目录中或名称与 key 不一致");
740
- const i = N(l.name);
1010
+ if (t.type === "businessToken" && ((m = t.attrs) == null ? void 0 : m.kind) === "attribute") {
1011
+ const r = Kt(
1012
+ String(t.attrs.key),
1013
+ d
1014
+ );
1015
+ if (!r || t.attrs.label !== r.name)
1016
+ return c(t, o, "业务属性不在旧目录中或名称与 key 不一致");
1017
+ const u = w(r.name);
741
1018
  return {
742
1019
  ok: !0,
743
1020
  value: {
744
- html: `<span contenteditable="false" data-tag="true" data-tag-type="biz_attribute" data-attr-name="${i}" data-attr-key="${l.key}" data-attr-id="${l.id}">${i}</span>`,
745
- text: gt(l.name)
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)
746
1025
  }
747
1026
  };
748
1027
  }
749
- if (t.type === "businessToken" && ((k = t.attrs) == null ? void 0 : k.kind) === "separator")
1028
+ if (t.type === "businessToken" && ((s = t.attrs) == null ? void 0 : s.kind) === "separator")
750
1029
  return {
751
1030
  ok: !0,
752
1031
  value: {
@@ -754,177 +1033,384 @@ function Rt(t, r) {
754
1033
  text: "[sep]"
755
1034
  }
756
1035
  };
757
- if (t.type === "businessToken" && (($ = t.attrs) == null ? void 0 : $.kind) === "tool") {
758
- const l = yt(t);
759
- if (!l) return o(t, r, "工具参数无法映射到旧格式");
760
- const { params: i } = t.attrs;
761
- return { ok: !0, value: { html: t.attrs.key === "small_payment" ? `<span contenteditable="false" data-tag="true" data-tag-type="small_payment" data-max-amount-cent="${Number(i.amount) * 100}">${N(l)}</span>` : `<span contenteditable="false" data-tag="true" data-tag-type="order_remark" data-remark-id="${N(
762
- i.id
763
- )}" data-remark-mode="${i.contentMode === "fixed" ? "fixed" : "extract"}" data-remark-flag="${N(
764
- i.flag
765
- )}" data-remark-keep-flag="${i.preserveFlag ? "1" : "0"}" data-remark-position="${i.position}" data-remark-content="${N(i.content)}">${N(
766
- l
767
- )}</span>`, text: l } };
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 } };
768
1051
  }
769
- return o(t, r, `节点 ${t.type} 无法映射到旧格式`);
1052
+ return c(t, o, `节点 ${t.type} 无法映射到旧格式`);
770
1053
  }
771
- function Lt(t, r = {}, c = {}) {
772
- var U, z, W, H, J, L, F, _, S, x, v, b, y, j, E, P, ot, it, Q, V, X, Z, K, tt, et, nt, at;
773
- const m = ft(t);
774
- if (m) return o(t, m, "场景未通过新模型校验");
775
- const s = _t(
776
- ((U = t.knowledge.doc) == null ? void 0 : U.content) || [],
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));
1058
+ return {
1059
+ ok: !0,
1060
+ value: {
1061
+ html: `<${y} src="${m}"${y === "video" ? "></video>" : ">"}`,
1062
+ text: `<${y} src="${m}"${y === "video" ? ' width="240" controls/>' : ' width="120"/>'}`
1063
+ }
1064
+ };
1065
+ }
1066
+ const a = {
1067
+ paragraph: "p",
1068
+ bulletList: "ul",
1069
+ orderedList: "ol",
1070
+ listItem: "li",
1071
+ blockquote: "blockquote",
1072
+ codeBlock: "pre"
1073
+ }[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);
1080
+ }
1081
+ return {
1082
+ ok: !0,
1083
+ 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(
1086
+ ["paragraph", "codeBlock"].includes(t.type || "") ? "" : `
1087
+ `
1088
+ )
1089
+ }
1090
+ };
1091
+ }
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");
1101
+ }
1102
+ ) : a.content;
1103
+ return {
1104
+ ...a,
1105
+ ...o ? {
1106
+ marks: void 0,
1107
+ ...a.type === "text" ? { text: (p = a.text) == null ? void 0 : p.replace(/\u00a0/g, " ") } : {}
1108
+ } : {},
1109
+ attrs: Object.keys(i).length ? i : void 0,
1110
+ content: g != null && g.length ? g.map(d) : void 0
1111
+ };
1112
+ }, S = (a) => Array.isArray(a) ? a.map(S) : a && typeof a == "object" ? Object.fromEntries(
1113
+ Object.entries(a).sort(([i], [g]) => i.localeCompare(g)).map(([i, g]) => [i, S(g)])
1114
+ ) : a;
1115
+ return JSON.stringify(
1116
+ S({
1117
+ type: t.type,
1118
+ question: t.question.text,
1119
+ doc: t.knowledge.doc ? d(t.knowledge.doc) : null,
1120
+ 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,
1123
+ extensionState: t.extensionState
1124
+ })
1125
+ );
1126
+ }
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),
1132
+ "text/html"
1133
+ );
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)
1137
+ )
1138
+ ))
1139
+ 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);
1151
+ };
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 },
1160
+ "layout-proof",
1161
+ s,
1162
+ {
1163
+ questionText: t.question.text,
1164
+ businessAttributes: a
1165
+ }
1166
+ ), r = xt(t);
1167
+ if (!n.ok || xt(n.value) !== r)
1168
+ return !1;
1169
+ if (t.type === "normal") {
1170
+ const _ = ht(
1171
+ String(o.web_content || Ct(o.content))
1172
+ );
1173
+ if (!_.ok || _.value.slice(g ? 1 : 0).some(
1174
+ (B) => B.some(
1175
+ (K) => K.kind === "todo" || K.kind === "text" && /\{(?:待办(?:@[^{}]*)?|原话复述)\}/u.test(K.value)
1176
+ )
1177
+ ))
1178
+ return !1;
1179
+ }
1180
+ const u = qt(
1181
+ { ...d, web_content: "", content: o.content },
1182
+ "layout-proof",
1183
+ {
1184
+ ...s,
1185
+ agent: (_) => {
1186
+ var B;
1187
+ return ((B = t.knowledge.agentRef) == null ? void 0 : B.name) === _ ? t.knowledge.agentRef : null;
1188
+ }
1189
+ },
1190
+ { questionText: t.question.text, businessAttributes: a }
1191
+ );
1192
+ return u.ok && xt(u.value, !0) === xt(t, !0);
1193
+ }
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(
1199
+ t,
1200
+ "businessAttributes",
1201
+ "业务属性目录格式无效或存在重复引用"
1202
+ );
1203
+ const a = Et(t);
1204
+ if (a) return c(t, a, "场景未通过新模型校验");
1205
+ const i = Rt(
1206
+ ((K = t.knowledge.doc) == null ? void 0 : K.content) || [],
777
1207
  "knowledge.doc.content"
778
1208
  );
779
- if (s) return o(t, s, "工具标签重复");
780
- const p = `【${t.question.text}】`, k = [], $ = [];
781
- for (const [h, e] of [
1209
+ if (i) return c(t, i, "工具标签重复");
1210
+ const g = `【${t.question.text}】`, f = [], p = [];
1211
+ for (const [v, A] of [
782
1212
  ["todo", "待办"],
783
1213
  ["tagged", "顾客标签"]
784
1214
  ]) {
785
- const n = (z = t.extensionState[h]) == null ? void 0 : z.data;
786
- if (n != null && n.enabled) {
787
- const u = `{${e}@${(W = n.tag) == null ? void 0 : W.label}}`;
788
- k.push(u), $.push(
789
- h === "todo" ? `<span contenteditable="false" data-tag="true" data-tag-type="todo" data-tag-name="${N(
790
- ((H = n.tag) == null ? void 0 : H.label) || ""
791
- )}" plan_id="${N(((J = n.tag) == null ? void 0 : J.id) || "")}">${N(
792
- u
793
- )}</span>` : `<span contenteditable="false" data-tag="true" data-tag-type="cdp_tag" data-tag-name="${N(
794
- ((L = n.tag) == null ? void 0 : L.label) || ""
795
- )}" data-tag-id="${N(((F = n.tag) == null ? void 0 : F.id) || "")}">${N(
796
- u
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
797
1227
  )}</span>`
798
1228
  );
799
1229
  }
800
1230
  }
801
- (S = (_ = t.extensionState.originalReply) == null ? void 0 : _.data) != null && S.enabled && (k.push("{原话复述}"), $.push(
1231
+ (W = (Z = t.extensionState.originalReply) == null ? void 0 : Z.data) != null && W.enabled && (f.push("{原话复述}"), p.push(
802
1232
  '<span data-tag-type="original_repeat" data-retelling="true">{原话复述}</span>'
803
- )), (v = (x = t.extensionState.memory) == null ? void 0 : x.data) != null && v.enabled && (k.push("{记忆触发点}"), $.push(
1233
+ )), (L = (it = t.extensionState.memory) == null ? void 0 : it.data) != null && L.enabled && (f.push("{记忆触发点}"), p.push(
804
1234
  '<span data-tag-type="memory_trigger" data-memory-trigger="true">{记忆触发点}</span>'
805
1235
  ));
806
- for (const h of Object.keys(t.extensionState))
807
- if (!["todo", "tagged", "originalReply", "memory"].includes(h))
808
- return o(
1236
+ for (const v of Object.keys(t.extensionState))
1237
+ if (!["todo", "tagged", "originalReply", "memory"].includes(v))
1238
+ return c(
809
1239
  t,
810
- `extensionState.${h}`,
1240
+ `extensionState.${v}`,
811
1241
  "旧格式无法表示此插件状态"
812
1242
  );
813
- const l = c.questionStorage || (/^\s*(?:<(?:div|p)>\s*)?【[^【】]+】/u.test(
814
- String(r.web_content || "")
815
- ) ? "inline" : "external"), i = l === "inline" ? [`<div>${N(p)}${$.join("")}</div>`] : $.length ? [`<div>${$.join("")}</div>`] : [], a = l === "inline" ? [p + k.join("")] : k.length ? [k.join("")] : [];
816
- if (t.type === "reasoning" && (i.push("<div>{推理}</div>"), a.push("{推理}")), t.type === "agent") {
817
- if ((y = (b = t.extensionState.tagged) == null ? void 0 : b.data) != null && y.enabled)
818
- return o(
819
- t,
820
- "extensionState.tagged",
821
- "旧系统的 Agent 与顾客标签不能组合"
822
- );
823
- if (t.knowledge.retainedDoc)
824
- return o(
825
- t,
826
- "knowledge.retainedDoc",
827
- "旧格式不能保留 Agent 切换前的正文"
828
- );
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") {
829
1247
  if (!t.knowledge.agentRef)
830
- return o(t, "knowledge.agentRef", "旧格式需要 Agent 引用");
831
- const h = `{自定义Agent}@${t.knowledge.agentRef.name}`;
832
- i.push(
833
- `<div><span data-tag-type="custom_agent" data-agent="true" data-agent-id="${N(
834
- t.knowledge.agentRef.id
835
- )}">${N(h)}</span></div>`
836
- ), a.push(h);
837
- } else
838
- for (const [h, e] of (((j = t.knowledge.doc) == null ? void 0 : j.content) || []).entries()) {
839
- const n = `knowledge.doc.content[${h}]`;
840
- if (e.type === "messageSeparator") {
841
- i.push(
842
- '<div><span data-tag-type="separator" data-divider="true">{分隔符}</span></div>'
843
- ), a.push("[sep]");
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);
1255
+ }
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]");
1263
+ 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
+ );
1272
+ continue;
1273
+ }
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);
1280
+ continue;
1281
+ }
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 || ""
1286
+ )
1287
+ ))
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);
844
1295
  continue;
845
1296
  }
846
- if (e.type === "mediaBlock" && ((E = e.attrs) == null ? void 0 : E.status) === "ready") {
847
- const A = e.attrs.kind === "image" ? "img" : "video", q = N(String(e.attrs.src));
848
- i.push(
849
- `<div><${A} src="${q}"${A === "video" ? "></video>" : ">"}</div>`
850
- ), a.push(
851
- `<${A} src="${q}"${A === "video" ? ' width="240" controls/>' : ' width="120"/>'}`
852
- );
1297
+ if (l.type === "messageSeparator") {
1298
+ nt.push({
1299
+ html: '<span data-tag-type="separator" data-divider="true">分隔符</span>',
1300
+ text: "[sep]"
1301
+ });
853
1302
  continue;
854
1303
  }
855
- const u = e.type === "originalReply", I = u ? (P = e.content) == null ? void 0 : P[0] : e;
856
- if (!I || I.type !== "paragraph" || u && ((ot = e.content) == null ? void 0 : ot.length) !== 1)
857
- return o(t, n, `节点 ${e.type} 无法映射到旧格式`);
858
- const f = [];
859
- for (const [A, q] of (I.content || []).entries()) {
860
- const O = Rt(q, `${n}.content[${A}]`);
861
- if (!O.ok) return { ...O, raw: t };
862
- f.push(O.value);
863
- }
864
- const D = f.map((A) => A.html).join(""), w = f.map((A) => A.text).join("");
865
- u ? (i.push(
866
- `<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">${D}</span><span>&gt;</span></span></div>`
867
- ), a.push(`<{原话复述}${w}>`)) : (i.push(`<div>${D}</div>`), a.push(w));
868
- }
869
- const g = (it = t.extensionState.todo) == null ? void 0 : it.data, d = [], G = (h) => {
870
- var e, n;
871
- h.type === "businessToken" && ((e = h.attrs) == null ? void 0 : e.kind) === "todo" && d.push({
872
- id: String(h.attrs.key),
873
- label: String(h.attrs.label)
874
- }), (n = h.content) == null || n.forEach(G);
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
1310
+ );
1311
+ if (!E.ok) return { ...E, raw: t };
1312
+ k.push(E.value);
1313
+ }
1314
+ nt.push({
1315
+ html: k.map((h) => h.html).join(""),
1316
+ text: k.map((h) => h.text).join("")
1317
+ });
1318
+ }
1319
+ const lt = nt.map((e) => e.html).join("<br>"), kt = nt.map((e) => e.text).join(`
1320
+ `);
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));
1324
+ }
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);
875
1331
  };
876
- (V = (Q = t.knowledge.doc) == null ? void 0 : Q.content) == null || V.forEach(G);
877
- const M = g != null && g.enabled && g.tag ? [g.tag, ...d] : d, C = [
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 = [
878
1334
  ...new Map(
879
- M.map((h) => [JSON.stringify([h.id, h.label]), h])
1335
+ z.map((v) => [JSON.stringify([v.id, v.label]), v])
880
1336
  ).values()
881
1337
  ];
882
- if (new Set(C.map((h) => h.label)).size !== C.length)
883
- return o(
1338
+ if (new Set(O.map((v) => v.label)).size !== O.length)
1339
+ return c(
884
1340
  t,
885
1341
  "knowledge.doc",
886
1342
  "同名待办对应多个方案 ID,旧格式无法无损保存"
887
1343
  );
888
- const B = C.length === 1 ? C[0] : void 0, R = (X = t.extensionState.tagged) == null ? void 0 : X.data, T = [];
889
- if (R != null && R.enabled) {
890
- T.push({
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({
891
1347
  type: "cdp_tag",
892
- name: (Z = R.tag) == null ? void 0 : Z.label,
893
- value: (K = R.tag) == null ? void 0 : K.id
894
- }), C.forEach((e) => T.push({ type: "todo", name: e.label })), t.type === "reasoning" && T.push({ type: "reasoning", name: "推理" }), (et = (tt = t.extensionState.originalReply) == null ? void 0 : tt.data) != null && et.enabled && T.push({ type: "original_repeat", name: "原话复述" });
895
- const h = (e) => {
896
- var n, u;
897
- e.type === "businessToken" && ((n = e.attrs) == null ? void 0 : n.kind) === "variable" && T.push({
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({
898
1354
  type: "variable",
899
- variable_name: e.attrs.label || e.attrs.key
900
- }), e.type === "originalReply" && T.push({ type: "original_repeat", name: "原话复述" }), (u = e.content) == null || u.forEach(h);
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);
901
1357
  };
902
- (at = (nt = t.knowledge.doc) == null ? void 0 : nt.content) == null || at.forEach(h);
1358
+ (yt = (mt = t.knowledge[n]) == null ? void 0 : mt.content) == null || yt.forEach(v);
903
1359
  }
904
- return {
905
- ok: !0,
906
- value: {
907
- ...r,
908
- knowledge_type: t.type === "reasoning" ? 2 : t.type === "agent" ? 3 : 1,
909
- todo_plan_id: (B == null ? void 0 : B.id) || "",
910
- todo_tag_type: C.length ? 2 : 0,
911
- todo_tag_metas: M.length ? JSON.stringify(
912
- M.map((h) => ({
913
- plan_id: h.id,
914
- plan_name: h.label,
1360
+ const B = {
1361
+ ...o,
1362
+ knowledge_type: t.type === "reasoning" ? 2 : t.type === "agent" ? 3 : 1,
1363
+ todo_plan_id: (P == null ? void 0 : P.id) || "",
1364
+ todo_tag_type: O.length ? 2 : 0,
1365
+ ...z.length || Object.hasOwn(o, "todo_tag_metas") ? {
1366
+ todo_tag_metas: z.length ? JSON.stringify(
1367
+ z.map((v) => ({
1368
+ plan_id: v.id,
1369
+ plan_name: v.label,
915
1370
  tag_type: 2
916
1371
  }))
917
- ) : "",
918
- todo_plan_name: (B == null ? void 0 : B.label) || "",
919
- tag_meta: T,
920
- web_content: i.join(""),
921
- content: a.join(`
922
- `)
923
- }
1372
+ ) : ""
1373
+ } : {},
1374
+ todo_plan_name: (P == null ? void 0 : P.label) || "",
1375
+ tag_meta: [
1376
+ ...new Map(
1377
+ _.map((v) => [
1378
+ JSON.stringify([
1379
+ v.type,
1380
+ v.name || "",
1381
+ v.value || "",
1382
+ v.variable_name || ""
1383
+ ]),
1384
+ v
1385
+ ])
1386
+ ).values()
1387
+ ],
1388
+ web_content: m.join(""),
1389
+ content: s.join(`
1390
+ `).replace(/^\n+|\n+$/gu, "")
924
1391
  };
1392
+ if (Yt(t, o, B, y, S)) {
1393
+ const v = new DOMParser().parseFromString(
1394
+ String(o.web_content || B.web_content),
1395
+ "text/html"
1396
+ );
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());
1400
+ }
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;
1407
+ }
1408
+ return { ok: !0, value: B };
925
1409
  }
926
1410
  export {
927
- kt as LEGACY_BUSINESS_ATTRIBUTES,
928
- Et as legacyItemToScene,
929
- Lt as sceneToLegacyItem
1411
+ _t as LEGACY_BUSINESS_ATTRIBUTES,
1412
+ te as agentPromptPreview,
1413
+ Ot as isLegacyBusinessAttributeCatalog,
1414
+ qt as legacyItemToScene,
1415
+ ee as sceneToLegacyItem
930
1416
  };