@freecallai/pro 0.0.2 → 0.0.4

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