@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
@@ -0,0 +1,4885 @@
1
+ import { ref as ee, shallowRef as Cn, defineComponent as Co, openBlock as A, createElementBlock as L, normalizeClass as we, createElementVNode as R, toDisplayString as ae, createBlock as ce, unref as w, withCtx as j, createVNode as F, createTextVNode as ye, createCommentVNode as oe, computed as ie, watch as Te, Fragment as Ee, renderList as an, getCurrentInstance as La, defineAsyncComponent as gi, nextTick as Qe, onMounted as Ra, onBeforeUnmount as Da, withKeys as ko, withModifiers as Gt, normalizeStyle as yi, createSlots as bo, resolveDynamicComponent as Ka, isRef as qa } from "vue";
2
+ import { Button as ue, Popover as rt, Switch as mi, Input as Va, Drawer as $a, Popconfirm as Ba, Modal as ho, Textarea as Ua, Tooltip as Fa, Message as ki } from "@freecallai/ui";
3
+ import Ne from "@freecallai/icons";
4
+ import { IconExclamationCircleFill as ja, IconClose as za } from "@freecallai/ui/es/icon/index.js";
5
+ import { A as ln, B as xi, f as Mn, D as Mi, E as Ga, F as Li, h as Zt, c as Pt, i as Ja, b as Mt, r as Po, G as Ha, g as Wt, y as Wa, z as Ya, M as Xa, H as Qa, I as Za, p as bi } from "./guard-CXpVx8UR.js";
6
+ import { a as On, _ as el, e as ut } from "./FkpKnowledgeTypePicker.vue_vue_type_script_setup_true_lang-DYwu7oQs.js";
7
+ function xt(t, o) {
8
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
9
+ const a = t;
10
+ return Object.keys(a).some((i) => !["maxBytes", "mimeTypes"].includes(i)) || a.maxBytes !== void 0 && (!Number.isSafeInteger(a.maxBytes) || a.maxBytes <= 0) || a.mimeTypes !== void 0 && (!Array.isArray(a.mimeTypes) || !a.mimeTypes.every(
11
+ (i) => typeof i == "string" && new RegExp(`^${o}/[a-z0-9.+-]+$`, "i").test(i)
12
+ )) ? null : {
13
+ ...a.maxBytes !== void 0 ? { maxBytes: a.maxBytes } : {},
14
+ ...a.mimeTypes !== void 0 ? {
15
+ mimeTypes: [...new Set(a.mimeTypes)].sort()
16
+ } : {}
17
+ };
18
+ }
19
+ function nl(t, o) {
20
+ let a, i;
21
+ for (const r of t)
22
+ if (r && (r.maxBytes !== void 0 && (a !== void 0 && r.maxBytes > a && o(), a = Math.min(a ?? r.maxBytes, r.maxBytes)), r.mimeTypes !== void 0)) {
23
+ const d = i, f = r.mimeTypes;
24
+ d && f.some((p) => !d.includes(p)) && o(), i = d ? d.filter((p) => f.includes(p)) : f;
25
+ }
26
+ return {
27
+ ...a !== void 0 ? { maxBytes: a } : {},
28
+ ...i !== void 0 ? { mimeTypes: i } : {}
29
+ };
30
+ }
31
+ function No(t) {
32
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
33
+ const o = t;
34
+ return Object.keys(o).some((a) => a !== "pageSize") || o.pageSize !== void 0 && (!Number.isSafeInteger(o.pageSize) || o.pageSize < 1 || o.pageSize > 100) ? null : o.pageSize === void 0 ? {} : { pageSize: o.pageSize };
35
+ }
36
+ function tl(t, o) {
37
+ let a;
38
+ for (const i of t)
39
+ (i == null ? void 0 : i.pageSize) !== void 0 && (a !== void 0 && i.pageSize > a && o(), a = Math.min(a ?? i.pageSize, i.pageSize));
40
+ return { pageSize: a ?? 30 };
41
+ }
42
+ const Ie = (t) => `${t.id}:${t.slot}`, Gn = (t, o) => !!t && typeof t == "object" && !Array.isArray(t) && Object.keys(t).every((a) => o.includes(a)), ol = (t) => {
43
+ if (!t || typeof t != "object") return !1;
44
+ const o = t;
45
+ return Gn(o, [
46
+ "id",
47
+ "slot",
48
+ "enabled",
49
+ "visible",
50
+ "label",
51
+ "order",
52
+ "options"
53
+ ]) && typeof o.id == "string" && typeof o.slot == "string" && (o.enabled === void 0 || typeof o.enabled == "boolean") && (o.visible === void 0 || typeof o.visible == "boolean") && (o.label === void 0 || typeof o.label == "string" && !!o.label.trim()) && (o.order === void 0 || typeof o.order == "number" && Number.isFinite(o.order)) && (o.options === void 0 || typeof o.options == "object");
54
+ };
55
+ function ct(t, o, a = Date.now()) {
56
+ var Z, _e, Oe, fe, me, De, xe, pe, Ce, Ke, Ve;
57
+ const i = [], r = ln.filter((E) => E.types.includes(t)), d = (E) => E === void 0 ? null : !E || typeof E != "object" || Array.isArray(E) ? "snapshot" : Mn(E), f = d(o.config), p = f === null && !!o.config && (!Gn(o.config, ["remote", "page"]) || Object.prototype.hasOwnProperty.call(o.config, "page") && !Gn(o.config.page, [
58
+ "schemaVersion",
59
+ "revision",
60
+ "rules"
61
+ ]) || ((Z = o.config.page) == null ? void 0 : Z.revision) !== void 0 && typeof o.config.page.revision != "string" || Object.prototype.hasOwnProperty.call(o.config, "remote") && !Gn(o.config.remote, [
62
+ "status",
63
+ "required",
64
+ "snapshot",
65
+ "expiresAt"
66
+ ]) || ((_e = o.config.remote) == null ? void 0 : _e.status) === "unavailable" && (Object.prototype.hasOwnProperty.call(
67
+ o.config.remote,
68
+ "snapshot"
69
+ ) || Object.prototype.hasOwnProperty.call(
70
+ o.config.remote,
71
+ "expiresAt"
72
+ )) || ((Oe = o.config.remote) == null ? void 0 : Oe.status) === "ready" && !!o.config.remote.snapshot && (!Gn(o.config.remote.snapshot, [
73
+ "schemaVersion",
74
+ "revision",
75
+ "rules"
76
+ ]) || o.config.remote.snapshot.revision !== void 0 && typeof o.config.remote.snapshot.revision != "string")), y = f !== null || p, _ = d(o.policy) !== null;
77
+ if (y || _)
78
+ return y && i.push({
79
+ code: f != null && f.includes("rules") ? "CONFIG_RULES_INVALID" : "CONFIG_INVALID",
80
+ severity: "error",
81
+ source: "config",
82
+ message: "能力配置包含不可安全读取的数据,当前知识只能查看"
83
+ }), _ && i.push({
84
+ code: "POLICY_INVALID",
85
+ severity: "error",
86
+ source: "config",
87
+ message: "权限快照无效,当前知识只能查看"
88
+ }), {
89
+ type: t,
90
+ mode: "readonly",
91
+ capabilities: r.map((E) => ({
92
+ ...E,
93
+ canInsert: !1,
94
+ canInsertProvided: !1,
95
+ visible: !1
96
+ })),
97
+ diagnostics: i,
98
+ fingerprint: hi({
99
+ type: t,
100
+ invalidConfigInput: y,
101
+ invalidPolicyInput: _
102
+ })
103
+ };
104
+ const { remote: v } = o.config || {}, N = new Set(ln.map(Ie)), { policy: b } = o, k = (E) => ln.find(($) => Ie($) === Ie(E)), C = (E) => {
105
+ if (E.options === void 0) return !0;
106
+ const $ = k(E);
107
+ return ($ == null ? void 0 : $.optionKind) === "media" ? xt(E.options, $.id) !== null : ($ == null ? void 0 : $.optionKind) === "selection" ? No(E.options) !== null : !1;
108
+ }, S = !!b && (!Gn(b, ["revision", "expiresAt", "allowed"]) || typeof b.revision != "string" || !b.revision || !Number.isFinite(b.expiresAt) || !Array.isArray(b.allowed) || !b.allowed.every(
109
+ (E) => Gn(E, ["id", "slot", "options"]) && typeof E.id == "string" && typeof E.slot == "string" && N.has(Ie(E)) && C(E)
110
+ ) || new Set(b.allowed.map(Ie)).size !== b.allowed.length), s = b && !S ? b.allowed : [], x = !!v && (v.status !== "ready" && v.status !== "unavailable" || typeof v.required != "boolean" || v.status === "ready" && !Number.isFinite(v.expiresAt)), q = (v == null ? void 0 : v.status) === "ready" && ((fe = v.snapshot) == null ? void 0 : fe.schemaVersion) !== 1, H = !!((me = o.config) != null && me.page) && o.config.page.schemaVersion !== 1, V = (E) => Array.isArray(E) && E.every(
111
+ ($) => ol($) && N.has(Ie($)) && C($)
112
+ ), m = (v == null ? void 0 : v.status) === "ready" && !V((De = v.snapshot) == null ? void 0 : De.rules), Y = !!((xe = o.config) != null && xe.page) && !V(o.config.page.rules), ne = (v == null ? void 0 : v.status) === "ready" && !m && !q ? v.snapshot.rules : [], G = (pe = o.config) != null && pe.page && !Y && !H ? o.config.page.rules : [], z = (E) => new Set(E.map(Ie)).size !== E.length, se = z(ne) || z(G), be = !!o.readonly || !!o.disabled || S || x || !!o.policy && o.policy.expiresAt <= a || q || H || m || Y || se || (v == null ? void 0 : v.status) === "ready" && v.expiresAt <= a || (v == null ? void 0 : v.status) === "unavailable";
113
+ o.policy && o.policy.expiresAt <= a && i.push({
114
+ code: "POLICY_EXPIRED",
115
+ severity: "error",
116
+ source: "config",
117
+ message: "权限已过期,当前知识只能查看"
118
+ }), S && i.push({
119
+ code: "POLICY_INVALID",
120
+ severity: "error",
121
+ source: "config",
122
+ message: "权限快照无效,当前知识只能查看"
123
+ }), x && i.push({
124
+ code: "CONFIG_INVALID",
125
+ severity: "error",
126
+ source: "config",
127
+ message: "远端配置快照无效,当前知识只能查看"
128
+ }), q && i.push({
129
+ code: "CONFIG_VERSION_INVALID",
130
+ severity: "error",
131
+ source: "config",
132
+ message: "配置版本不兼容,当前知识只能查看"
133
+ }), H && i.push({
134
+ code: "CONFIG_VERSION_INVALID",
135
+ severity: "error",
136
+ source: "config",
137
+ message: "页面配置版本不兼容,当前知识只能查看"
138
+ }), (m || Y) && i.push({
139
+ code: "CONFIG_RULES_INVALID",
140
+ severity: "error",
141
+ source: "config",
142
+ message: "能力配置无效,当前知识只能查看"
143
+ }), (v == null ? void 0 : v.status) === "unavailable" && i.push({
144
+ code: "CONFIG_UNAVAILABLE",
145
+ severity: "error",
146
+ source: "config",
147
+ message: "配置不可用,当前知识只能查看"
148
+ }), (v == null ? void 0 : v.status) === "ready" && v.expiresAt <= a && i.push({
149
+ code: "CONFIG_EXPIRED",
150
+ severity: "error",
151
+ source: "config",
152
+ message: "配置已过期,当前知识只能查看"
153
+ });
154
+ for (const [E, $] of [
155
+ ["remote", ne],
156
+ ["page", G]
157
+ ]) {
158
+ const Q = /* @__PURE__ */ new Set();
159
+ for (const Ae of $)
160
+ Q.has(Ie(Ae)) && i.push({
161
+ code: "DUPLICATE_RULE",
162
+ severity: "error",
163
+ source: "config",
164
+ message: `${E} 配置重复:${Ie(Ae)}`,
165
+ capabilityId: Ae.id
166
+ }), Q.add(Ie(Ae));
167
+ }
168
+ const he = (E, $) => E == null ? void 0 : E.find((Q) => Ie(Q) === Ie($)), W = r.map((E) => {
169
+ var Ln;
170
+ const $ = (v == null ? void 0 : v.status) === "ready" && v.expiresAt > a ? he(ne, E) : void 0, Q = he(G, E), Ae = !o.policy || s.some((Le) => Ie(Le) === Ie(E)), je = (Ln = E.actions) == null ? void 0 : Ln.find(
171
+ (Le) => Le.id === E.primaryActionId
172
+ ), qe = [
173
+ ...E.optionKind === "selection" && E.optionSource ? [] : (je == null ? void 0 : je.requiredPorts) || [],
174
+ ...E.optionSource && E.optionSource !== "reasoningTemplates" ? [xi[E.optionSource]] : [],
175
+ ...E.uiPorts || []
176
+ ], pn = (() => {
177
+ if (E.primaryActionId && !je) return !1;
178
+ try {
179
+ return qe.every(
180
+ (Le) => {
181
+ var hn;
182
+ return typeof ((hn = o.ports) == null ? void 0 : hn[Le]) == "function";
183
+ }
184
+ );
185
+ } catch {
186
+ return i.push({
187
+ code: "PORT_INVALID",
188
+ severity: "warning",
189
+ source: "config",
190
+ message: `${E.id} 的宿主接口不可安全读取,该能力已禁用`,
191
+ capabilityId: E.id
192
+ }), !1;
193
+ }
194
+ })(), Me = s.find(
195
+ (Le) => Ie(Le) === Ie(E)
196
+ ), Se = E.optionKind === "media" ? nl(
197
+ [
198
+ xt(
199
+ Me == null ? void 0 : Me.options,
200
+ E.id
201
+ ) || void 0,
202
+ xt(
203
+ $ == null ? void 0 : $.options,
204
+ E.id
205
+ ) || void 0,
206
+ xt(
207
+ Q == null ? void 0 : Q.options,
208
+ E.id
209
+ ) || void 0
210
+ ],
211
+ () => i.push({
212
+ code: "OPTION_WIDEN_ATTEMPT",
213
+ severity: "warning",
214
+ source: "config",
215
+ message: `${E.id} 的后续配置试图放宽媒体限制,已按较严格值处理`,
216
+ capabilityId: E.id
217
+ })
218
+ ) : void 0, Hn = E.optionKind === "selection" ? tl(
219
+ [Me == null ? void 0 : Me.options, $ == null ? void 0 : $.options, Q == null ? void 0 : Q.options].map(
220
+ (Le) => Le === void 0 ? void 0 : No(Le) || void 0
221
+ ),
222
+ () => i.push({
223
+ code: "OPTION_WIDEN_ATTEMPT",
224
+ severity: "warning",
225
+ source: "config",
226
+ message: `${E.id} 的后续配置试图放宽查询分页限制,已按较严格值处理`,
227
+ capabilityId: E.id
228
+ })
229
+ ) : void 0, Wn = Se || Hn, sn = !!(Se != null && Se.mimeTypes) && !Se.mimeTypes.length;
230
+ sn && i.push({
231
+ code: "OPTION_SET_EMPTY",
232
+ severity: "warning",
233
+ source: "config",
234
+ message: `${E.id} 的可用媒体类型交集为空`,
235
+ capabilityId: E.id
236
+ });
237
+ const re = !be && Ae && !sn && ($ == null ? void 0 : $.enabled) !== !1 && (Q == null ? void 0 : Q.enabled) !== !1, rn = re && pn;
238
+ return {
239
+ ...E,
240
+ label: (Q == null ? void 0 : Q.label) || ($ == null ? void 0 : $.label) || E.label,
241
+ order: (Q == null ? void 0 : Q.order) ?? ($ == null ? void 0 : $.order) ?? E.order,
242
+ canInsert: rn,
243
+ canInsertProvided: re,
244
+ options: Wn,
245
+ visible: ($ == null ? void 0 : $.visible) !== !1 && (Q == null ? void 0 : Q.visible) !== !1 && (rn || !pn)
246
+ };
247
+ }).sort(
248
+ (E, $) => E.order - $.order || E.id.localeCompare($.id) || E.slot.localeCompare($.slot)
249
+ );
250
+ return {
251
+ type: t,
252
+ mode: be ? "readonly" : "editable",
253
+ capabilities: W,
254
+ diagnostics: i,
255
+ fingerprint: hi({
256
+ type: t,
257
+ mode: be ? "readonly" : "editable",
258
+ policyRevision: b == null ? void 0 : b.revision,
259
+ remoteRevision: (v == null ? void 0 : v.status) === "ready" ? (Ce = v.snapshot) == null ? void 0 : Ce.revision : v == null ? void 0 : v.status,
260
+ pageRevision: (Ve = (Ke = o.config) == null ? void 0 : Ke.page) == null ? void 0 : Ve.revision,
261
+ policyAllowed: wo(s),
262
+ remoteRules: wo(ne),
263
+ pageRules: wo(G),
264
+ options: W.map((E) => ({
265
+ id: E.id,
266
+ slot: E.slot,
267
+ apiVersion: E.apiVersion,
268
+ dataVersion: E.dataVersion,
269
+ options: E.options
270
+ }))
271
+ })
272
+ };
273
+ }
274
+ function wo(t) {
275
+ return t.map((o) => {
276
+ var a;
277
+ return {
278
+ id: o.id,
279
+ slot: o.slot,
280
+ enabled: o.enabled,
281
+ visible: o.visible,
282
+ label: o.label,
283
+ order: o.order,
284
+ options: o.options === void 0 ? void 0 : o.id === "image" || o.id === "video" ? xt(o.options, o.id) : ((a = ln.find((i) => Ie(i) === Ie(o))) == null ? void 0 : a.optionKind) === "selection" ? No(o.options) : o.options
285
+ };
286
+ }).sort((o, a) => Ie(o).localeCompare(Ie(a)));
287
+ }
288
+ function hi(t) {
289
+ const o = (r) => Array.isArray(r) ? `[${r.map(o).join(",")}]` : r && typeof r == "object" ? `{${Object.entries(r).sort(([d], [f]) => d.localeCompare(f)).map(([d, f]) => `${JSON.stringify(d)}:${o(f)}`).join(",")}}` : JSON.stringify(r) ?? "null", a = o(t);
290
+ let i = 2166136261;
291
+ for (let r = 0; r < a.length; r++)
292
+ i = Math.imul(i ^ a.charCodeAt(r), 16777619);
293
+ return (i >>> 0).toString(16).padStart(8, "0");
294
+ }
295
+ function il(t) {
296
+ const o = t.attrs || {}, a = Mi(t);
297
+ return a ? {
298
+ ...a,
299
+ identity: t.type === "businessToken" ? JSON.stringify([o.key, o.label, o.token]) : t.type === "mediaBlock" ? String(o.id || "") : "block"
300
+ } : null;
301
+ }
302
+ function wi(t) {
303
+ const o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new WeakSet(), i = (r) => {
304
+ if (!r || typeof r != "object") return;
305
+ const d = r;
306
+ if (a.has(d)) return;
307
+ a.add(d);
308
+ const f = il(d);
309
+ if (f) {
310
+ const p = `${f.id}:${f.slot}`, y = o.get(p) || {
311
+ use: { id: f.id, slot: f.slot },
312
+ instances: /* @__PURE__ */ new Map()
313
+ };
314
+ y.instances.set(
315
+ f.identity,
316
+ (y.instances.get(f.identity) || 0) + 1
317
+ ), o.set(p, y);
318
+ }
319
+ Array.isArray(d.content) && d.content.forEach(i);
320
+ };
321
+ return t && i(t), o;
322
+ }
323
+ function Ti(t, o, a) {
324
+ var d;
325
+ const i = wi(t), r = wi(o);
326
+ for (const [f, p] of r) {
327
+ if (a.some(
328
+ (_) => _.id === p.use.id && _.slot === p.use.slot && _.canInsert
329
+ ))
330
+ continue;
331
+ const y = (d = i.get(f)) == null ? void 0 : d.instances;
332
+ for (const [_, v] of p.instances)
333
+ if (v > ((y == null ? void 0 : y.get(_)) || 0)) return p.use;
334
+ }
335
+ return null;
336
+ }
337
+ function al(t, o) {
338
+ const a = JSON.parse(JSON.stringify(t));
339
+ if (t.type === o) return { scene: a, removed: [] };
340
+ const i = /* @__PURE__ */ new Set();
341
+ if (a.extensionState = Object.fromEntries(
342
+ Object.entries(a.extensionState).filter(([f]) => {
343
+ const p = ln.find(
344
+ (y) => y.id === f && y.types.includes(t.type) && y.implementation === "plugin"
345
+ );
346
+ return !p || ln.some(
347
+ (y) => y.id === f && y.slot === p.slot && y.types.includes(o)
348
+ ) ? !0 : (i.add(p.removalLabel || p.label), !1);
349
+ })
350
+ ), t.knowledge.agentRef && i.add("Agent 引用"), o === "agent") {
351
+ const f = a.knowledge.doc || a.knowledge.retainedDoc;
352
+ a.knowledge = {
353
+ doc: null,
354
+ ...f ? {
355
+ retainedDoc: f
356
+ } : {},
357
+ agentRef: null
358
+ };
359
+ } else
360
+ a.knowledge = {
361
+ doc: ll(
362
+ a.knowledge.doc || a.knowledge.agentBody || a.knowledge.retainedDoc || On(),
363
+ o,
364
+ i
365
+ ),
366
+ agentRef: null
367
+ };
368
+ a.type = o;
369
+ const r = new Map(
370
+ ln.map((f) => [f.removalLabel || f.label, f.order])
371
+ ), d = (f) => f === "Agent 引用" ? Number.MAX_SAFE_INTEGER : r.get(f) ?? Number.MAX_SAFE_INTEGER;
372
+ return {
373
+ scene: a,
374
+ removed: [...i].sort((f, p) => d(f) - d(p))
375
+ };
376
+ }
377
+ function ll(t, o, a) {
378
+ const i = (r) => {
379
+ const d = Mi(r), f = o === "agent" ? "normal" : o;
380
+ if (d && !ln.some(
381
+ (p) => p.id === d.id && p.slot === d.slot && p.types.includes(f)
382
+ )) {
383
+ const p = ln.find(
384
+ (y) => y.id === d.id && y.slot === d.slot
385
+ );
386
+ return a.add(
387
+ (p == null ? void 0 : p.removalLabel) || (p == null ? void 0 : p.label) || d.id
388
+ ), null;
389
+ }
390
+ return r.content ? {
391
+ ...r,
392
+ content: r.content.map(i).filter((p) => p !== null)
393
+ } : r;
394
+ };
395
+ return i(t) || On();
396
+ }
397
+ function To(t) {
398
+ const o = [], a = /* @__PURE__ */ new WeakSet();
399
+ let i = 0;
400
+ const r = 2e4, d = (_) => {
401
+ if (i >= r) return;
402
+ const v = _.slice(0, r - i);
403
+ o.push(v), i += v.length;
404
+ }, f = (_, v) => {
405
+ if (!_ || typeof _ != "object" || v > 32) return;
406
+ const N = _;
407
+ if (a.has(N)) return;
408
+ a.add(N);
409
+ const b = typeof N.type == "string" ? N.type : "未知类型", k = N.attrs && typeof N.attrs == "object" ? N.attrs : {};
410
+ if (b === "text") {
411
+ typeof N.text == "string" && d(N.text);
412
+ return;
413
+ }
414
+ if (b === "hardBreak") {
415
+ d(`
416
+ `);
417
+ return;
418
+ }
419
+ if (b === "businessToken") {
420
+ const C = k.token || k.label || k.key;
421
+ d(typeof C == "string" ? C : "[引用]");
422
+ return;
423
+ }
424
+ if (b === "mediaBlock") {
425
+ const C = k.kind === "video" ? "视频" : "图片", S = typeof k.name == "string" && k.name ? `:${k.name}` : "";
426
+ d(`
427
+ [${C}${S}]
428
+ `);
429
+ return;
430
+ }
431
+ if (b === "messageSeparator") {
432
+ d(`
433
+ ────
434
+ `);
435
+ return;
436
+ }
437
+ Ga(b) || d(`
438
+ [未识别内容:${b.slice(0, 80)}]
439
+ `), typeof N.text == "string" && d(N.text), Array.isArray(N.content) && N.content.forEach((C) => f(C, v + 1)), ["paragraph", "listItem", "blockquote", "originalReply"].includes(b) && d(`
440
+ `);
441
+ };
442
+ let p = !1;
443
+ try {
444
+ f(t, 0);
445
+ } catch {
446
+ p = !0;
447
+ }
448
+ const y = o.join("").replace(/\n{3,}/g, `
449
+
450
+ `).trim();
451
+ return p ? y ? `${y}
452
+ 部分内容无法读取,原始数据仍保留。` : "内容无法安全预览;原始数据仍保留。" : y ? `${y}${i >= r ? `
453
+ …内容已截断,原始数据仍保留` : ""}` : "没有可提取的文本;原始数据仍保留。";
454
+ }
455
+ function Jn(t) {
456
+ const o = (a) => Array.isArray(a) ? `[${a.map((i) => o(i)).join(",")}]` : a && typeof a == "object" ? `{${Object.keys(a).filter((i) => a[i] !== void 0).sort().map(
457
+ (i) => `${JSON.stringify(i)}:${o(
458
+ a[i]
459
+ )}`
460
+ ).join(",")}}` : JSON.stringify(a) ?? "null";
461
+ return o(t);
462
+ }
463
+ function Fe(t) {
464
+ return Jn(t);
465
+ }
466
+ const Yt = (t) => Array.from(t.replace(/\s/gu, "")).length;
467
+ function ft(t) {
468
+ let o = "", a = !1, i = !1, r = !1, d = !1, f = 0, p = !1;
469
+ const y = /* @__PURE__ */ new Set(), _ = /* @__PURE__ */ new WeakSet(), v = (N) => {
470
+ var k, C, S, s, x, q, H;
471
+ if (!N || typeof N != "object") return;
472
+ const b = N;
473
+ if (!_.has(b)) {
474
+ if (_.add(b), typeof b.type == "string" && Ja(b.type) && (typeof ((k = b.attrs) == null ? void 0 : k.id) != "string" || !b.attrs.id.trim() || !Number.isSafeInteger(b.attrs.nodeVersion) || b.attrs.nodeVersion < 0) && (d = !0), b.type === "mediaBlock") {
475
+ a = !0, (((C = b.attrs) == null ? void 0 : C.status) === "uploading" || ((S = b.attrs) == null ? void 0 : S.status) === "error") && (i = !0);
476
+ return;
477
+ }
478
+ if (b.type === "businessToken") {
479
+ if (a = !0, ((s = b.attrs) == null ? void 0 : s.kind) === "tool" && (b.attrs.key === "small_payment" && ++f > 1 && (p = !0), b.attrs.key === "order_note")) {
480
+ const V = (x = b.attrs.params) == null ? void 0 : x.id;
481
+ typeof V == "string" && y.has(V) && (p = !0), typeof V == "string" && y.add(V);
482
+ }
483
+ ((q = b.attrs) == null ? void 0 : q.kind) === "tool" && ((H = b.attrs) == null ? void 0 : H.params) == null && (r = !0);
484
+ return;
485
+ }
486
+ if (b.type === "text" && typeof b.text == "string" && (o += b.text, Yt(b.text) > 0 && (a = !0)), Array.isArray(b.content))
487
+ for (const V of b.content) v(V);
488
+ }
489
+ };
490
+ return t && v(t), {
491
+ text: o,
492
+ hasContent: a,
493
+ pendingMedia: i,
494
+ missingToolParams: r,
495
+ incompleteNodeIdentity: d,
496
+ repeatedTool: p
497
+ };
498
+ }
499
+ function Xt(t) {
500
+ return ft(t.knowledge.doc).pendingMedia || ft(t.knowledge.retainedDoc || null).pendingMedia || ft(t.knowledge.agentBody || null).pendingMedia;
501
+ }
502
+ function sl(t) {
503
+ return ft(t).hasContent;
504
+ }
505
+ function Hs(t, o = {}) {
506
+ if (!Array.isArray(t) || t.length === 0)
507
+ return {
508
+ ok: !1,
509
+ characterCount: 0,
510
+ issues: [
511
+ {
512
+ code: Array.isArray(t) ? "EMPTY_CONTENT" : "UNSUPPORTED_CONTENT",
513
+ sceneIndex: null,
514
+ message: Array.isArray(t) ? "请至少添加一条知识场景" : "知识场景列表格式不正确"
515
+ }
516
+ ]
517
+ };
518
+ const a = o.maxCharacters, i = typeof a == "number" && Number.isSafeInteger(a) && a > 0 ? Math.min(a, 2e3) : 2e3, r = [], d = /* @__PURE__ */ new Set();
519
+ let f = 0;
520
+ return t.forEach((p, y) => {
521
+ var V, m, Y, ne;
522
+ let _;
523
+ try {
524
+ if (Mn(p) !== null)
525
+ throw new Error("Non-JSON scene");
526
+ _ = JSON.parse(JSON.stringify(p));
527
+ } catch {
528
+ r.push({
529
+ code: "UNSUPPORTED_CONTENT",
530
+ sceneIndex: y,
531
+ message: "知识包含当前版本不支持的内容"
532
+ });
533
+ return;
534
+ }
535
+ if (!Li(_)) {
536
+ r.push({
537
+ code: "UNSUPPORTED_CONTENT",
538
+ sceneIndex: y,
539
+ message: "知识包含当前版本不支持的内容"
540
+ });
541
+ return;
542
+ }
543
+ _.schemaVersion !== 1 && r.push({
544
+ code: "SCHEMA_VERSION",
545
+ sceneIndex: y,
546
+ message: "知识数据版本不兼容"
547
+ });
548
+ const v = ((V = _.question) == null ? void 0 : V.text) || "", N = ft(
549
+ _.type === "agent" ? _.knowledge.agentBody || null : _.knowledge.doc
550
+ ), b = ft(_.knowledge.retainedDoc || null);
551
+ f += Yt(v) + Yt(N.text);
552
+ const k = Yt(v) > 0;
553
+ Zt(v) && r.push({
554
+ code: "INVALID_INTENT_BRACKET",
555
+ sceneIndex: y,
556
+ message: "意图文字中不可填写方括号或换行,请修改"
557
+ });
558
+ const C = (m = _.knowledge.agentRef) == null ? void 0 : m.name, S = typeof C == "string" && !!C.trim(), s = (Y = _.extensionState.todo) == null ? void 0 : Y.data, x = _.type === "normal" && (s == null ? void 0 : s.enabled) === !0 && typeof ((ne = s.tag) == null ? void 0 : ne.id) == "string" && !!s.tag.id.trim() && typeof s.tag.label == "string" && !!s.tag.label.trim();
559
+ _.type === "agent" && !S ? r.push({
560
+ code: k ? "AGENT_REQUIRED" : "EMPTY_CONTENT_AND_AGENT",
561
+ sceneIndex: y,
562
+ message: k ? "请选择Agent" : "请填写顾客意图或知识内容,并选择Agent"
563
+ }) : _.type !== "agent" && !k && !N.hasContent && !x && r.push({
564
+ code: "EMPTY_CONTENT",
565
+ sceneIndex: y,
566
+ message: "请填写顾客意图或知识内容"
567
+ });
568
+ const q = v.split("/").map((G) => G.trim()).filter(Boolean);
569
+ q.some((G) => d.has(G)) && r.push({
570
+ code: "DUPLICATE_INTENT",
571
+ sceneIndex: y,
572
+ message: "已存在相同意图的知识场景"
573
+ }), q.forEach((G) => d.add(G)), Xt(_) && r.push({
574
+ code: "MEDIA_PENDING",
575
+ sceneIndex: y,
576
+ message: "请等待媒体上传完成或移除失败的媒体"
577
+ }), (N.repeatedTool || b.repeatedTool) && r.push({
578
+ code: "UNSUPPORTED_CONTENT",
579
+ sceneIndex: y,
580
+ message: "工具标签重复"
581
+ }), N.missingToolParams && r.push({
582
+ code: "UNSUPPORTED_CONTENT",
583
+ sceneIndex: y,
584
+ message: "工具配置缺失,请迁移后保存"
585
+ });
586
+ const H = Pt(_);
587
+ !H && (N.incompleteNodeIdentity || b.incompleteNodeIdentity) && r.push({
588
+ code: "UNSUPPORTED_CONTENT",
589
+ sceneIndex: y,
590
+ message: "引用节点缺少稳定 ID 或版本,请迁移后保存"
591
+ }), H && r.push({
592
+ code: "UNSUPPORTED_CONTENT",
593
+ sceneIndex: y,
594
+ message: "知识包含当前版本不支持的内容"
595
+ });
596
+ }), f > i && r.push({
597
+ code: "TOO_LONG",
598
+ sceneIndex: null,
599
+ message: `内容不能超过${i}字`
600
+ }), { ok: r.length === 0, characterCount: f, issues: r };
601
+ }
602
+ const rl = {
603
+ "todo:questionAction": () => import("./question-C7akkjHn.js"),
604
+ "todo:knowledgeInline": () => import("./knowledge-DaTnF2IW.js"),
605
+ "tableKnowledge:knowledgeInline": () => import("./index-Cy4DqT8R.js"),
606
+ "ticket:knowledgeInline": () => import("./index-CZc2Gyjb.js"),
607
+ "originalReply:questionAction": () => import("./question-DXZ8R-34.js"),
608
+ "originalReply:knowledgeBlock": () => import("./knowledge-DzwXQR-q.js"),
609
+ "memory:questionAction": () => import("./index-9NM1SHoR.js"),
610
+ "tagged:questionAction": () => import("./index-Dy2Gy3bL.js"),
611
+ "attribute:knowledgeInline": () => import("./index-bSNw0XAf.js"),
612
+ "tool:knowledgeInline": () => import("./index-BqXNMfLG.js"),
613
+ "variable:knowledgeInline": () => import("./index-CM0MN2DT.js"),
614
+ "separator:knowledgeInline": () => import("./index-DnaEbb6l.js"),
615
+ "image:knowledgeBlock": () => import("./index-DAZ1ulyA.js"),
616
+ "video:knowledgeBlock": () => import("./index-F7lDP1lI.js"),
617
+ "reasoningPolish:sceneAction": () => import("./index-UjI4WA5F.js"),
618
+ "reasoningTemplate:sceneAction": () => import("./index-B8jg37Wj.js")
619
+ };
620
+ function ul(t, o) {
621
+ if (!o || typeof o != "object") return !1;
622
+ const a = o, { actions: i } = t, r = a.actions;
623
+ if (t.implementation !== "plugin" || !(i != null && i.length) || new Set(i.map((f) => f.id)).size !== i.length || !r || typeof r != "object" || Array.isArray(r) || a.validateInsert !== void 0 && typeof a.validateInsert != "function")
624
+ return !1;
625
+ const d = r;
626
+ return Object.keys(d).length !== i.length || i.some((f) => {
627
+ const p = d[f.id];
628
+ return !Object.prototype.hasOwnProperty.call(d, f.id) || !p || typeof p != "object" || typeof p.execute != "function";
629
+ }) ? !1 : a.id === t.id && a.slot === t.slot && a.apiVersion === t.apiVersion && a.dataVersion === t.dataVersion;
630
+ }
631
+ async function Ri(t) {
632
+ if (t.implementation !== "plugin")
633
+ return { ok: !1, reason: "NOT_REGISTERED" };
634
+ const o = rl[`${t.id}:${t.slot}`];
635
+ if (!o) return { ok: !1, reason: "NOT_REGISTERED" };
636
+ const a = await o();
637
+ return ul(t, a.default) ? { ok: !0, module: a.default } : { ok: !1, reason: "VERSION_MISMATCH" };
638
+ }
639
+ function Di(t, o, a = []) {
640
+ if (!Array.isArray(t) || new Set(t).size !== t.length || !Array.isArray(a) || (/* @__PURE__ */ new Set([...t, ...a])).size !== t.length + a.length)
641
+ return null;
642
+ const i = [
643
+ ...t,
644
+ ...a
645
+ ], r = {};
646
+ try {
647
+ for (const d of i) {
648
+ const f = o == null ? void 0 : o[d];
649
+ if (!(f === void 0 && a.includes(d))) {
650
+ if (typeof f != "function") return null;
651
+ r[d] = f;
652
+ }
653
+ }
654
+ } catch {
655
+ return null;
656
+ }
657
+ return r;
658
+ }
659
+ function xo(t, o, a) {
660
+ var r;
661
+ const i = (r = t.actions) == null ? void 0 : r.filter((d) => d.id === o);
662
+ return !i || i.length !== 1 ? null : Di(
663
+ i[0].requiredPorts,
664
+ a,
665
+ i[0].optionalPorts
666
+ );
667
+ }
668
+ function cl(t, o) {
669
+ return Di(t.readPorts, o);
670
+ }
671
+ function dl(t, o) {
672
+ const a = ln.filter(
673
+ (i) => {
674
+ var r;
675
+ return (r = i.actions) == null ? void 0 : r.some((d) => d.id === t);
676
+ }
677
+ );
678
+ return a.length !== 1 ? null : xo(
679
+ a[0],
680
+ t,
681
+ o
682
+ );
683
+ }
684
+ let Ii = 0;
685
+ function Jt(t) {
686
+ var o, a;
687
+ t.target instanceof Element && t.target.closest('input[type="file"]') || (Array.from(((o = t.dataTransfer) == null ? void 0 : o.types) || []).includes("Files") || (a = t.dataTransfer) != null && a.files.length) && t.preventDefault();
688
+ }
689
+ function fl() {
690
+ Ii++ === 0 && (window.addEventListener("dragover", Jt), window.addEventListener("drop", Jt));
691
+ let t = !1;
692
+ return () => {
693
+ t || (t = !0, --Ii === 0 && (window.removeEventListener("dragover", Jt), window.removeEventListener("drop", Jt)));
694
+ };
695
+ }
696
+ const pl = 10, Io = {
697
+ image: 5 * 1024 * 1024,
698
+ video: 100 * 1024 * 1024
699
+ }, Ai = {
700
+ image: ["image/png", "image/jpeg"],
701
+ video: ["video/mp4"]
702
+ }, Si = {
703
+ png: { kind: "image", mime: "image/png" },
704
+ jpg: { kind: "image", mime: "image/jpeg" },
705
+ jpeg: { kind: "image", mime: "image/jpeg" },
706
+ mp4: { kind: "video", mime: "video/mp4" }
707
+ };
708
+ function Qt(t) {
709
+ const o = t.name.lastIndexOf("."), a = o < 0 ? "" : t.name.slice(o + 1).toLowerCase(), i = Object.prototype.hasOwnProperty.call(Si, a) ? Si[a] : void 0;
710
+ return !i || t.type && t.type.toLowerCase() !== i.mime ? null : i;
711
+ }
712
+ const vl = /* @__PURE__ */ new Set([
713
+ "ABORTED",
714
+ "UNAVAILABLE",
715
+ "FORBIDDEN",
716
+ "INVALID_RESPONSE",
717
+ "CONFLICT",
718
+ "TIMEOUT",
719
+ "NETWORK",
720
+ "UNKNOWN"
721
+ ]), _n = () => ({
722
+ ok: !1,
723
+ error: {
724
+ code: "INVALID_RESPONSE",
725
+ message: "宿主接口返回格式不正确",
726
+ retryable: !1
727
+ }
728
+ }), ke = (t) => !!t && typeof t == "object" && !Array.isArray(t), pt = (t) => typeof t == "string" && t.length > 0, Ze = (t) => typeof t == "string" && t.trim().length > 0, Pn = (t, o) => Object.keys(t).every((a) => o.includes(a)), gl = /* @__PURE__ */ new Set([
729
+ "config",
730
+ "plugin",
731
+ "port",
732
+ "validation",
733
+ "migration"
734
+ ]), yl = /* @__PURE__ */ new Set([
735
+ "info",
736
+ "warning",
737
+ "error"
738
+ ]), ml = new Set(ln.map((t) => t.id)), kl = /* @__PURE__ */ new Set([
739
+ "questionAction",
740
+ "knowledgeInline",
741
+ "knowledgeBlock",
742
+ "sceneAction",
743
+ "toolbarOnly"
744
+ ]);
745
+ function bl(t) {
746
+ return ke(t) ? Object.keys(t).every(
747
+ (o) => [
748
+ "code",
749
+ "severity",
750
+ "source",
751
+ "message",
752
+ "sceneKey",
753
+ "capabilityId",
754
+ "slot",
755
+ "path",
756
+ "retryable"
757
+ ].includes(o)
758
+ ) && pt(t.code) && yl.has(t.severity) && gl.has(t.source) && typeof t.message == "string" && (t.sceneKey === void 0 || typeof t.sceneKey == "string") && (t.capabilityId === void 0 || ml.has(t.capabilityId)) && (t.slot === void 0 || kl.has(t.slot)) && (t.path === void 0 || typeof t.path == "string") && (t.retryable === void 0 || typeof t.retryable == "boolean") : !1;
759
+ }
760
+ function xn(t, o) {
761
+ try {
762
+ if (!ke(t)) return _n();
763
+ if (t.ok === !0) {
764
+ const y = t.data;
765
+ if (y !== void 0 && Mn(y) !== null)
766
+ return _n();
767
+ const _ = y === void 0 ? void 0 : JSON.parse(JSON.stringify(y));
768
+ return o(_) ? { ok: !0, data: _ } : _n();
769
+ }
770
+ if (t.ok !== !1 || !ke(t.error)) return _n();
771
+ const { code: a, message: i, retryable: r, traceId: d, issues: f } = t.error;
772
+ let p;
773
+ if (f !== void 0) {
774
+ if (Mn(f) !== null) return _n();
775
+ const y = JSON.parse(JSON.stringify(f));
776
+ if (!Array.isArray(y) || !y.every(bl))
777
+ return _n();
778
+ p = y;
779
+ }
780
+ return vl.has(a) && pt(i) && typeof r == "boolean" && (d === void 0 || typeof d == "string") ? {
781
+ ok: !1,
782
+ error: {
783
+ code: a,
784
+ message: i,
785
+ retryable: r,
786
+ ...typeof d == "string" ? { traceId: d } : {},
787
+ ...p ? { issues: p } : {}
788
+ }
789
+ } : _n();
790
+ } catch {
791
+ return _n();
792
+ }
793
+ }
794
+ function Mo(t, o) {
795
+ if (!ke(t) || !Array.isArray(t.items)) return !1;
796
+ const { items: a } = t;
797
+ return a.every(o) ? new Set(a.map((i) => i.id)).size === a.length && (t.nextCursor === void 0 || pt(t.nextCursor)) : !1;
798
+ }
799
+ const hl = (t) => Mo(
800
+ t,
801
+ (o) => ke(o) && Ze(o.id) && Ze(o.label) && Ze(o.token) && (o.group === void 0 || typeof o.group == "string") && (o.disabled === void 0 || typeof o.disabled == "boolean")
802
+ ), wl = (t) => Mo(
803
+ t,
804
+ (o) => ke(o) && Ze(o.id) && Ze(o.name)
805
+ ), Lo = (t) => Mo(
806
+ t,
807
+ (o) => ke(o) && Ze(o.id) && Ze(o.label) && (o.disabled === void 0 || typeof o.disabled == "boolean") && (o.hasChildren === void 0 || typeof o.hasChildren == "boolean") && (o.preview === void 0 || typeof o.preview == "string")
808
+ ), Tl = (t) => Lo(t) && t.items.every(
809
+ (o) => !!o.label.trim() && !o.hasChildren && !Ha(o.label)
810
+ ), Ei = (t, o) => ke(o) && Pn(o, ["toolId", "permitted", "fields"]) && o.toolId === t && typeof o.permitted == "boolean" && Array.isArray(o.fields) && o.fields.length <= 20 && new Set(
811
+ o.fields.map((a) => ke(a) ? a.id : null)
812
+ ).size === o.fields.length && o.fields.every(
813
+ (a) => ke(a) && Pn(a, [
814
+ "id",
815
+ "label",
816
+ "kind",
817
+ "required",
818
+ "placeholder",
819
+ "min",
820
+ "max",
821
+ "maxLength",
822
+ "options",
823
+ "defaultValue",
824
+ "hideLabel",
825
+ "appearance",
826
+ "visibleWhen"
827
+ ]) && typeof a.id == "string" && /^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(a.id) && !["constructor", "prototype"].includes(a.id) && Ze(a.label) && ["text", "number", "switch", "textarea", "radio", "checkbox"].includes(
828
+ String(a.kind)
829
+ ) && (a.required === void 0 || typeof a.required == "boolean") && (a.placeholder === void 0 || typeof a.placeholder == "string") && (a.hideLabel === void 0 || typeof a.hideLabel == "boolean") && (a.appearance === void 0 || a.kind === "radio" && a.appearance === "flag") && (a.maxLength === void 0 || (a.kind === "text" || a.kind === "textarea") && typeof a.maxLength == "number" && Number.isInteger(a.maxLength) && a.maxLength > 0) && (a.options === void 0 || a.kind === "radio" && Array.isArray(a.options) && a.options.length > 0 && a.options.every(
830
+ (i) => ke(i) && Pn(i, ["value", "label", "color"]) && pt(i.value) && i.value.trim() === i.value && Ze(i.label) && (i.color === void 0 || a.appearance === "flag" && typeof i.color == "string" && /^#[0-9a-fA-F]{6}$/.test(i.color))
831
+ )) && (a.kind !== "radio" || a.options !== void 0) && (a.defaultValue === void 0 || (["switch", "checkbox"].includes(String(a.kind)) ? typeof a.defaultValue == "boolean" : typeof a.defaultValue == "string" && a.defaultValue.trim() === a.defaultValue)) && (a.visibleWhen === void 0 || ke(a.visibleWhen) && Pn(a.visibleWhen, ["fieldId", "equals"]) && pt(a.visibleWhen.fieldId) && (typeof a.visibleWhen.equals == "string" || typeof a.visibleWhen.equals == "boolean")) && (a.min === void 0 || typeof a.min == "number" && Number.isFinite(a.min)) && (a.max === void 0 || typeof a.max == "number" && Number.isFinite(a.max)) && (a.kind === "number" || a.min === void 0 && a.max === void 0) && (a.min === void 0 || a.max === void 0 || a.min <= a.max)
832
+ ) && o.fields.every((a, i) => {
833
+ if (!ke(a)) return !1;
834
+ if (a.kind === "radio") {
835
+ const p = a.options.map((y) => y.value);
836
+ if (new Set(p).size !== p.length || a.defaultValue !== void 0 && !p.includes(a.defaultValue))
837
+ return !1;
838
+ }
839
+ if (a.visibleWhen === void 0) return !0;
840
+ const r = a.visibleWhen, d = o.fields.slice(0, i).find(
841
+ (f) => ke(f) ? f.id === r.fieldId : !1
842
+ );
843
+ return ke(d) ? d.kind === "radio" ? d.options.some(
844
+ (f) => f.value === r.equals
845
+ ) : ["switch", "checkbox"].includes(String(d.kind)) ? typeof r.equals == "boolean" : typeof r.equals == "string" : !1;
846
+ }), Ws = (t) => ke(t) && Object.keys(t).every(
847
+ (o) => ["proposedDoc", "explanation"].includes(o)
848
+ ) && ke(t.proposedDoc) && t.proposedDoc.type === "doc" && !Po(t.proposedDoc) && (t.explanation === void 0 || typeof t.explanation == "string"), Ys = (t) => ke(t) && Object.keys(t).length === 2 && typeof t.question == "string" && !Zt(t.question) && ke(t.doc) && t.doc.type === "doc" && !Po(t.doc), Il = /* @__PURE__ */ new Set([
849
+ "todo",
850
+ "cdp_tag",
851
+ "separator",
852
+ "original_repeat",
853
+ "size_chart",
854
+ "table_knowledge",
855
+ "biz_attribute",
856
+ "variable",
857
+ "custom_agent",
858
+ "reasoning",
859
+ "memory_trigger",
860
+ "no_send_follow_order",
861
+ "small_payment",
862
+ "order_remark",
863
+ "external_method",
864
+ "ticket",
865
+ "tool"
866
+ ]), Al = (t) => ke(t) ? t.type === "break" ? Pn(t, ["type"]) : t.type === "text" ? Pn(t, ["type", "text"]) && typeof t.text == "string" : t.type === "tag" ? Pn(t, ["type", "kind", "label"]) && Il.has(t.kind) && Ze(t.label) : t.type === "media" ? Pn(t, ["type", "kind", "url"]) && (t.kind === "image" || t.kind === "video") && Mt(t.url) : !1 : !1, Sl = (t, o) => ke(o) && Ze(t) && o.id === t && Ze(o.name) && typeof o.prompt == "string" && (o.preview === void 0 || Array.isArray(o.preview) && o.preview.every(Al)) && (o.revision === void 0 || typeof o.revision == "string"), Xs = (t, o) => ke(o) && o.kind === t && Mt(o.url) && (o.id === void 0 || pt(o.id)) && (o.posterUrl === void 0 || Mt(o.posterUrl)), Ki = [
867
+ {
868
+ id: "shipping-time",
869
+ label: "示例 A",
870
+ name: "发货物流与时间",
871
+ question: "询问多久能到货/xx地区几天能到",
872
+ content: `1.当顾客询问到货时长相关问题时,首先判断顾客是否说明了具体省市地区:
873
+ - 如果顾客没有说明具体省市地区,话术:“宝,请问您是要发往什么地方呢?”
874
+ 2.如果顾客说明了具体省市地区,判断该地区是否属于偏远地区(偏远地区指新疆、内蒙古、西藏):
875
+ - 如果不是偏远地区,回复顾客:“宝,发货后同城一般隔天送到,省外的正常2-3天左右。由于运输有些不确定因素,所以具体到货时间快递也不做百分百保证,以物流为准哈。但请您放心,下单后咱家都会按照付款先后尽快安排发出哒。”
876
+ - 如果是偏远地区,则回复顾客:“宝宝距离稍微有一点远哟,预计需要4-5天才能送达,稍有延迟还请耐心等待哦。”`
877
+ },
878
+ {
879
+ id: "shipping-carrier",
880
+ label: "示例 B",
881
+ name: "快递物流",
882
+ question: "发xx快递/能指定快递吗",
883
+ content: `1、当顾客需要指定快递时,先判断聊天记录中说否说过指定发什么快递:
884
+ - 如果没说过指定发什么快递,则回复话术“亲,可以指定快递的哦,请问您是要指定什么快递呢?”。
885
+ 2、在顾客发送指定快递后,进行下一步判断:
886
+ - 如果收到顾客需要指定的快递是顺丰,回复话术:“辛苦您提交订单不付款,联系客服补一下顺丰运费差额哦{待办@默认}”
887
+ - 如果收到顾客需要指定的快递不是顺丰,则回复话术:“好的呢亲爱的,这边为您备注下哦{待办@默认}”`
888
+ },
889
+ {
890
+ id: "refund-rules",
891
+ label: "示例 C",
892
+ name: "退款流程与规则",
893
+ question: "顾客要求退款/退货",
894
+ content: `1.当顾客反馈需要申请退款/退货时,先判断顾客是否在聊天记录中说明过退款/退货原因:
895
+ -如果没说过退款/退货原因,需进行询问:“您好~抱歉呢,具体是什么问题呢。”
896
+ -如果顾客已说明退款/退货原因,回复话术:“亲,可能产品没有达到您的预期效果,您再考虑下呢,退回来也是比较麻烦,希望您有一个愉快的购物体验呢;但是您实在不想要的话,这边可以给您处理退货退款”,
897
+ 2、接着判断顾客是否愿意接受留下不退款的方案:
898
+ - 如果顾客愿意接受留下不退货方案,回复:“感谢理解哦,马上给您申请打折{待办@默认}”
899
+ - 如果顾客还是坚持要退款/退货,则回复:“实在抱歉给您带来不好的购物体验了,这边马上给您处理哦{待办@默认}”`
900
+ },
901
+ {
902
+ id: "damaged-product",
903
+ label: "示例 D",
904
+ name: "质量相关",
905
+ question: "顾客反馈商品有破损",
906
+ content: `1. 当顾客反馈商品有破损等相关问题时,接着判断顾客在聊天上文中有没有发送图片或者视频:
907
+ - 如果顾客在聊天记录中没有发送过破损相关图片或者视频,发送话术:“非常抱歉,辛苦您拍破损处的清晰照片+快递面单+外包装,方便我们判断破损情况;如果是快递暴力运输导致的问题,我们会根据破损严重程度为您安排方案。”
908
+ - 如果顾客在聊天记录中有发送破损相关图片或者视频,发送话术:“给您带来极大的不便了!这边收到您的信息啦,这边马上看看什么情况,一定努力为您解决好问题哈,不会让您受委屈哦{待办@默认}”`
909
+ },
910
+ {
911
+ id: "product-instructions",
912
+ label: "示例 E",
913
+ name: "商品使用教学",
914
+ question: "顾客询问教学视频/使用方法",
915
+ content: `1.当顾客进线咨询使用方法或使用视频时,首先需要判断顾客提到的商品类型:
916
+ -如果聊天记录中客户尚未说明机型,发送话术:“亲亲,您的商品是A类的还是B类的呢。”
917
+ 2.根据客户回复的关于机型的话术,进一步做出判断:
918
+ -如果客户回复是“特征1、特征2”,则视为A类商品,回复话术:“您提到的这款商品使用步骤如下:先进行操作...然后再...。下面我们的使用教学,您参考一下噢~<此处放A类视频教学链接>”
919
+ -如果客户回复是“特征3、特征4”,则视为B类商品,回复话术:“您提到的这款商品使用步骤如下:先进行操作...然后再...。下面我们的使用教学,您参考一下噢~<此处放B类视频教学链接>”
920
+ -如果客户回复的机型描述不是“特征1、特征2、特征3、特征4”其中之一,则回复:“宝子请稍等,我们这边帮您看下哦。{待办@默认}”`
921
+ },
922
+ {
923
+ id: "exchange-rules",
924
+ label: "示例 F",
925
+ name: "换货流程与规则",
926
+ question: "顾客反馈买错了要换货/申请换货",
927
+ content: `1、当顾客反馈买错换货/申请换货等问题时,首先需要确认顾客对应产品是否已拆封:“宝,您这边是否已拆封了呢?没拆封的话是可以换货的”
928
+ 2、当顾客给出拆封情况回复后,根据是否拆封进行对应处理:
929
+ 2.1、如果顾客回复已拆封,回复顾客:“宝,产品拆封影响二次销售,不支持退货退款哦。”
930
+ 2.2、如果顾客回复未拆封,接着判断聊天记录中顾客是否提供过需要更换的货品型号:
931
+ -如果聊天记录中顾客未提供过需要更换的货品型号,回复顾客:“宝,麻烦提供下换货的型号,这边给您确认是否有货呦。”
932
+ -如果聊天记录中顾客提供过需要更换的货品型号,回复顾客:“宝,稍等,这边马上为您处理换货事宜{待办@默认}”`
933
+ }
934
+ ], _o = "builtin:reasoning:", Oo = "builtin:reasoning:page:", Ht = (t) => ({
935
+ ok: !1,
936
+ error: { code: "UNAVAILABLE", message: t, retryable: !1 }
937
+ });
938
+ function qi(t) {
939
+ return !!(t != null && t.startsWith(Oo));
940
+ }
941
+ function Ni(t) {
942
+ var d;
943
+ const o = t.cursor ? Number(t.cursor.slice(Oo.length)) : 0;
944
+ if (t.cursor && !qi(t.cursor) || !Number.isSafeInteger(o) || o < 0)
945
+ return {
946
+ ok: !1,
947
+ error: {
948
+ code: "INVALID_RESPONSE",
949
+ message: "默认模板分页位置无效",
950
+ retryable: !1
951
+ }
952
+ };
953
+ const a = ((d = t.search) == null ? void 0 : d.trim()) || "", i = Ki.filter(
954
+ (f) => `${f.label} ${f.name} ${f.question}`.includes(a)
955
+ ), r = o + t.limit;
956
+ return {
957
+ ok: !0,
958
+ data: {
959
+ items: i.slice(o, r).map((f) => ({
960
+ id: _o + f.id,
961
+ label: f.label,
962
+ preview: `[${f.question}]
963
+ ${f.content}`
964
+ })),
965
+ ...r < i.length ? { nextCursor: Oo + r } : {}
966
+ }
967
+ };
968
+ }
969
+ async function Qs(t, o) {
970
+ if (!t.startsWith(_o)) return null;
971
+ const a = Ki.find(
972
+ (d) => _o + d.id === t
973
+ );
974
+ if (!a) return Ht("默认推理模板不存在");
975
+ let i;
976
+ if (a.content.includes("{待办@默认}")) {
977
+ const d = o.ports.listCapabilityOptions;
978
+ if (!d) return Ht("此模板需要默认待办方案,请先接入待办选项");
979
+ const f = /* @__PURE__ */ new Set();
980
+ let p;
981
+ do {
982
+ const y = await d(
983
+ {
984
+ capabilityId: "todo",
985
+ search: "默认",
986
+ limit: 100,
987
+ ...p ? { cursor: p } : {}
988
+ },
989
+ o.request
990
+ ), _ = xn(y, Lo);
991
+ if (!_.ok) return _;
992
+ if (_.data.items.length > 100)
993
+ return {
994
+ ok: !1,
995
+ error: {
996
+ code: "INVALID_RESPONSE",
997
+ message: "待办选项超过请求上限",
998
+ retryable: !1
999
+ }
1000
+ };
1001
+ const v = _.data.items.find(
1002
+ (N) => N.label === "默认" && !N.disabled && !N.hasChildren
1003
+ );
1004
+ if (v) {
1005
+ i = { id: v.id, label: v.label };
1006
+ break;
1007
+ }
1008
+ if (p = _.data.nextCursor, p && f.has(p))
1009
+ return Ht("待办目录分页游标重复");
1010
+ p && f.add(p);
1011
+ } while (p && !o.request.signal.aborted);
1012
+ if (!i) return Ht("没有可用的默认待办方案,请先配置默认待办");
1013
+ }
1014
+ const r = a.content.split(`
1015
+ `).map((d) => {
1016
+ const f = [];
1017
+ return d.split("{待办@默认}").forEach((p, y) => {
1018
+ y && i && f.push({
1019
+ type: "businessToken",
1020
+ attrs: { kind: "todo", key: i.id, label: i.label }
1021
+ }), p && f.push({ type: "text", text: p });
1022
+ }), { type: "paragraph", content: f };
1023
+ });
1024
+ return {
1025
+ ok: !0,
1026
+ data: { question: a.question, doc: { type: "doc", content: r } }
1027
+ };
1028
+ }
1029
+ const Vi = () => ({
1030
+ ok: !1,
1031
+ error: {
1032
+ code: "INVALID_RESPONSE",
1033
+ message: "选项页数量超过请求上限",
1034
+ retryable: !1
1035
+ }
1036
+ });
1037
+ function El(t, o) {
1038
+ if (!t || typeof t != "object") return !1;
1039
+ try {
1040
+ const a = Object.getOwnPropertyDescriptor(t, "ok"), i = Object.getOwnPropertyDescriptor(t, "data");
1041
+ if ((a == null ? void 0 : a.value) !== !0 || !i || !("value" in i) || !i.value || typeof i.value != "object")
1042
+ return !1;
1043
+ const r = Object.getOwnPropertyDescriptor(i.value, "items");
1044
+ return !!r && "value" in r && Array.isArray(r.value) && r.value.length > o;
1045
+ } catch {
1046
+ return !1;
1047
+ }
1048
+ }
1049
+ function Nl(t, o) {
1050
+ return !t.ok || t.data.items.length <= o ? t : Vi();
1051
+ }
1052
+ function Ao(t, o, a) {
1053
+ return El(t, a) ? Vi() : Nl(xn(t, o), a);
1054
+ }
1055
+ async function _l(t, o, a, i) {
1056
+ const { search: r, cursor: d, parentId: f, limit: p } = o;
1057
+ if (t.optionKind !== "selection") return null;
1058
+ if (t.optionSource === "agents") {
1059
+ const y = a == null ? void 0 : a.searchAgents;
1060
+ if (typeof y != "function") return null;
1061
+ const _ = Ao(
1062
+ await y(
1063
+ {
1064
+ ...r !== void 0 ? { search: r } : {},
1065
+ ...d !== void 0 ? { cursor: d } : {},
1066
+ limit: p
1067
+ },
1068
+ i
1069
+ ),
1070
+ wl,
1071
+ p
1072
+ );
1073
+ return _.ok ? {
1074
+ ok: !0,
1075
+ data: {
1076
+ ..._.data,
1077
+ items: _.data.items.map(({ id: v, name: N }) => ({ id: v, label: N }))
1078
+ }
1079
+ } : _;
1080
+ }
1081
+ if (t.optionSource === "variables") {
1082
+ const y = a == null ? void 0 : a.listVariables;
1083
+ return typeof y != "function" ? null : Ao(
1084
+ await y(
1085
+ {
1086
+ ...r !== void 0 ? { search: r } : {},
1087
+ ...d !== void 0 ? { cursor: d } : {},
1088
+ limit: p
1089
+ },
1090
+ i
1091
+ ),
1092
+ hl,
1093
+ p
1094
+ );
1095
+ }
1096
+ if (t.optionSource === "flatTags" || t.optionSource === "capabilities" || t.optionSource === "reasoningTemplates") {
1097
+ const y = a == null ? void 0 : a.listCapabilityOptions, _ = t.optionSource === "reasoningTemplates";
1098
+ if (_ && (typeof y != "function" || qi(d)))
1099
+ return Ni(o);
1100
+ if (typeof y != "function") return null;
1101
+ const v = await y(
1102
+ {
1103
+ capabilityId: t.id,
1104
+ ...f !== void 0 ? { parentId: f } : {},
1105
+ ...r !== void 0 ? { search: r } : {},
1106
+ ...d !== void 0 ? { cursor: d } : {},
1107
+ limit: p
1108
+ },
1109
+ i
1110
+ ), N = Ao(
1111
+ v,
1112
+ t.optionSource === "flatTags" ? Tl : Lo,
1113
+ p
1114
+ );
1115
+ return _ && !d && (!N.ok && N.error.code === "UNAVAILABLE" || N.ok && !N.data.items.length && !N.data.nextCursor) ? Ni(o) : N.ok && t.optionHierarchy !== "tree" && N.data.items.some((b) => b.hasChildren) ? {
1116
+ ok: !1,
1117
+ error: {
1118
+ code: "INVALID_RESPONSE",
1119
+ message: "当前能力不支持分类选项",
1120
+ retryable: !1
1121
+ }
1122
+ } : N;
1123
+ }
1124
+ return null;
1125
+ }
1126
+ function Ol(t) {
1127
+ const o = ee(""), a = Cn([]), i = Cn([]), r = ee(null), d = ee(!1), f = /* @__PURE__ */ new Set();
1128
+ let p = null, y = 0;
1129
+ function _() {
1130
+ if (!p) return;
1131
+ const C = p;
1132
+ p = null, C.abort(), t.track(C, !1), d.value = !1;
1133
+ }
1134
+ function v() {
1135
+ _(), o.value = "", a.value = [], i.value = [], r.value = null, f.clear();
1136
+ }
1137
+ function N(C) {
1138
+ _(), i.value = [...i.value, C], o.value = "", a.value = [], r.value = null, f.clear();
1139
+ }
1140
+ function b() {
1141
+ return i.value.length ? (_(), i.value = i.value.slice(0, -1), o.value = "", a.value = [], r.value = null, f.clear(), !0) : !1;
1142
+ }
1143
+ async function k(C, S = !1) {
1144
+ var G;
1145
+ const s = S ? r.value : null;
1146
+ if (S && !s) return;
1147
+ S || (a.value = [], r.value = null, f.clear()), _();
1148
+ const x = new AbortController();
1149
+ p = x;
1150
+ const q = ++y, H = o.value, V = (G = i.value.at(-1)) == null ? void 0 : G.id, m = t.descriptor(C), Y = m == null ? void 0 : m.options, ne = Y && "pageSize" in Y ? Y.pageSize ?? 30 : 30;
1151
+ t.track(x, !0), d.value = !0;
1152
+ try {
1153
+ const z = m ? await _l(
1154
+ m,
1155
+ {
1156
+ search: H,
1157
+ ...V ? { parentId: V } : {},
1158
+ ...s ? { cursor: s } : {},
1159
+ limit: ne
1160
+ },
1161
+ t.ports(),
1162
+ t.context(C, x)
1163
+ ) : null;
1164
+ if (x.signal.aborted || q !== y || !t.isCurrent(C))
1165
+ return;
1166
+ if (!z) {
1167
+ t.diagnostic("PORT_MISSING", "宿主未提供所需的数据接口", C);
1168
+ return;
1169
+ }
1170
+ if (!z.ok) {
1171
+ t.portDiagnostic(z.error, C);
1172
+ return;
1173
+ }
1174
+ const se = z.data.items, be = S ? a.value : [], he = new Set(be.map((Z) => Z.id));
1175
+ if (se.some((Z) => he.has(Z.id))) {
1176
+ r.value = null, t.diagnostic("INVALID_RESPONSE", "选项分页返回了重复的 ID", C);
1177
+ return;
1178
+ }
1179
+ const W = z.data.nextCursor || null;
1180
+ if (W && (W === s || f.has(W))) {
1181
+ r.value = null, t.diagnostic("INVALID_RESPONSE", "选项分页游标未前进", C);
1182
+ return;
1183
+ }
1184
+ s && f.add(s), a.value = [...be, ...se], r.value = W;
1185
+ } catch (z) {
1186
+ x.signal.aborted || t.diagnostic(
1187
+ "PORT_FAILED",
1188
+ z instanceof Error ? z.message : "请求失败",
1189
+ C
1190
+ );
1191
+ } finally {
1192
+ t.track(x, !1), p === x && (p = null, d.value = !1);
1193
+ }
1194
+ }
1195
+ return {
1196
+ query: o,
1197
+ options: a,
1198
+ path: i,
1199
+ nextCursor: r,
1200
+ loading: d,
1201
+ abort: _,
1202
+ reset: v,
1203
+ enter: N,
1204
+ back: b,
1205
+ fetch: k
1206
+ };
1207
+ }
1208
+ const _i = 3;
1209
+ function Cl() {
1210
+ let t = 0;
1211
+ const o = /* @__PURE__ */ new Set();
1212
+ function a() {
1213
+ var i, r;
1214
+ for (; t < _i && o.size; )
1215
+ (r = (i = o.values().next()).value) == null || r.call(i);
1216
+ }
1217
+ return {
1218
+ acquire(i) {
1219
+ return new Promise((r) => {
1220
+ let d = !1;
1221
+ function f() {
1222
+ d && (d = !1, i.removeEventListener("abort", p), t--, a());
1223
+ }
1224
+ function p() {
1225
+ d ? f() : (o.delete(y), i.removeEventListener("abort", p), r(null));
1226
+ }
1227
+ function y() {
1228
+ if (i.aborted) {
1229
+ p();
1230
+ return;
1231
+ }
1232
+ t >= _i || (o.delete(y), t++, d = !0, r(f));
1233
+ }
1234
+ i.addEventListener("abort", p, { once: !0 }), o.add(y), y();
1235
+ });
1236
+ }
1237
+ };
1238
+ }
1239
+ function Oi(t) {
1240
+ return Number.isSafeInteger(t) && t >= 0 && t < Number.MAX_SAFE_INTEGER;
1241
+ }
1242
+ function Pl(t) {
1243
+ const o = {
1244
+ type: "doc",
1245
+ content: t.type === "businessToken" ? [{ type: "paragraph", content: [t] }] : [t]
1246
+ };
1247
+ return !Po(o);
1248
+ }
1249
+ function xl(t, o) {
1250
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
1251
+ try {
1252
+ if (Mn(t) !== null) return null;
1253
+ const a = JSON.parse(JSON.stringify(t));
1254
+ return !o || typeof a.enabled == "boolean" ? a : null;
1255
+ } catch {
1256
+ return null;
1257
+ }
1258
+ }
1259
+ function dt(t, o) {
1260
+ return Object.keys(t).some((a) => !o.includes(a));
1261
+ }
1262
+ function $i(t, o) {
1263
+ var _, v, N, b;
1264
+ if (!Array.isArray(o))
1265
+ return { ok: !1, reason: "扩展返回值不是操作列表" };
1266
+ if (!o.length) return { ok: !0, kind: "none" };
1267
+ if (Mn(o) !== null)
1268
+ return { ok: !1, reason: "扩展操作包含不可序列化参数" };
1269
+ const a = [];
1270
+ let i = null, r = null, d;
1271
+ const f = [];
1272
+ let p = "";
1273
+ for (const k of o) {
1274
+ if (!k || k.capabilityId !== t.id)
1275
+ return { ok: !1, reason: "操作能力与扩展不匹配" };
1276
+ if (k.kind === "setOwnState") {
1277
+ if (t.implementation !== "plugin" || i || dt(k, ["kind", "capabilityId", "data"]))
1278
+ return { ok: !1, reason: "扩展状态操作无效" };
1279
+ const C = xl(
1280
+ k.data,
1281
+ t.slot === "questionAction"
1282
+ );
1283
+ if (!C) return { ok: !1, reason: "扩展状态操作无效" };
1284
+ i = C;
1285
+ } else if (k.kind === "insertOwnToken") {
1286
+ const C = Wt(t.id);
1287
+ if (!C || t.slot !== "knowledgeInline" || f.length || r || dt(k, [
1288
+ "kind",
1289
+ "capabilityId",
1290
+ "key",
1291
+ "label",
1292
+ "token",
1293
+ "params"
1294
+ ]) || typeof k.key != "string" || !k.key || typeof k.label != "string" || (_ = C.validate) != null && _.call(C, {
1295
+ kind: t.id,
1296
+ key: k.key,
1297
+ label: k.label,
1298
+ params: k.params
1299
+ }) || k.token !== void 0 && (typeof k.token != "string" || !k.token.trim()) || k.params !== void 0 && (!C.allowsParams || !k.params || typeof k.params != "object" || Array.isArray(k.params) || JSON.stringify(k.params).length > 8192) || C.requiresInsertToken && (typeof k.token != "string" || !k.token.trim()))
1300
+ return { ok: !1, reason: "扩展引用操作无效" };
1301
+ a.push(
1302
+ {
1303
+ type: "businessToken",
1304
+ attrs: {
1305
+ kind: t.id,
1306
+ key: k.key,
1307
+ label: k.label,
1308
+ ...k.token ? { token: k.token } : {},
1309
+ ...k.params ? { params: k.params } : {}
1310
+ }
1311
+ },
1312
+ { type: "text", text: " " }
1313
+ );
1314
+ } else if (k.kind === "insertOwnBlock") {
1315
+ if (t.slot !== "knowledgeBlock" || k.block !== "originalReply" || f.length || r || dt(k, ["kind", "capabilityId", "block"]) || k.block !== t.id)
1316
+ return { ok: !1, reason: "扩展块操作无效" };
1317
+ a.push({
1318
+ type: "originalReply",
1319
+ content: [{ type: "paragraph" }]
1320
+ });
1321
+ } else if (k.kind === "replaceSceneDoc") {
1322
+ if (t.slot !== "sceneAction" || t.implementation !== "plugin" || a.length || f.length || r || dt(k, [
1323
+ "kind",
1324
+ "capabilityId",
1325
+ "doc",
1326
+ "question",
1327
+ "confirmation"
1328
+ ]) || k.question !== void 0 && (typeof k.question != "string" || Zt(k.question)) || typeof k.confirmation != "string" || !k.confirmation.trim() || k.confirmation.length > 160 || !k.doc || typeof k.doc != "object" || Array.isArray(k.doc) || k.doc.type !== "doc")
1329
+ return { ok: !1, reason: "扩展正文替换操作无效" };
1330
+ r = JSON.parse(JSON.stringify(k.doc)), d = k.question, p = k.confirmation;
1331
+ } else if (k.kind === "updateOwnNode") {
1332
+ const { node: C, nodeId: S, expectedNodeVersion: s } = k;
1333
+ if (!["knowledgeInline", "knowledgeBlock"].includes(t.slot) || ["image", "video"].includes(t.id) && o.length !== 1 || a.length || r || f.some((x) => x.nodeId === S) || dt(k, [
1334
+ "kind",
1335
+ "capabilityId",
1336
+ "nodeId",
1337
+ "expectedNodeVersion",
1338
+ "node"
1339
+ ]) || typeof S != "string" || !S || !Oi(s) || !C || typeof C != "object" || Array.isArray(C) || C.type !== "originalReply" && Object.keys(C).some((x) => !["type", "attrs"].includes(x)) || C.type === "originalReply" && Object.keys(C).some(
1340
+ (x) => !["type", "attrs", "content"].includes(x)
1341
+ ) || Wa(C.type || "", C.attrs) !== t.id || t.slot === "knowledgeInline" != (C.type === "businessToken") || ((v = C.attrs) == null ? void 0 : v.id) !== S || ((N = C.attrs) == null ? void 0 : N.nodeVersion) !== s + 1 || C.type === "mediaBlock" && ((b = C.attrs) == null ? void 0 : b.status) !== "ready" || C.type === "originalReply" && Ya(C) || !Pl(C))
1342
+ return { ok: !1, reason: "扩展节点更新操作无效" };
1343
+ f.push({
1344
+ ok: !0,
1345
+ kind: "updateNode",
1346
+ nodeId: S,
1347
+ expectedNodeVersion: s,
1348
+ node: JSON.parse(JSON.stringify(C))
1349
+ });
1350
+ } else if (k.kind === "removeOwnNode") {
1351
+ const { nodeId: C, expectedNodeVersion: S } = k;
1352
+ if (!["knowledgeInline", "knowledgeBlock"].includes(t.slot) || ["image", "video"].includes(t.id) && o.length !== 1 || a.length || r || f.some((s) => s.nodeId === C) || dt(k, [
1353
+ "kind",
1354
+ "capabilityId",
1355
+ "nodeId",
1356
+ "expectedNodeVersion"
1357
+ ]) || typeof C != "string" || !C || !Oi(S))
1358
+ return { ok: !1, reason: "扩展节点删除操作无效" };
1359
+ f.push({
1360
+ ok: !0,
1361
+ kind: "removeNode",
1362
+ nodeId: C,
1363
+ expectedNodeVersion: S
1364
+ });
1365
+ } else
1366
+ return { ok: !1, reason: "扩展操作类型无效" };
1367
+ }
1368
+ let y = null;
1369
+ if (f.length === 1) {
1370
+ const [k] = f;
1371
+ y = k;
1372
+ } else f.length > 1 ? y = { ok: !0, kind: "batchNodes", operations: f } : r ? y = {
1373
+ ok: !0,
1374
+ kind: "replaceDoc",
1375
+ doc: r,
1376
+ ...d !== void 0 ? { question: d } : {},
1377
+ confirmation: p
1378
+ } : a.length && (y = { ok: !0, kind: "doc", content: a });
1379
+ return i && y ? { ok: !0, kind: "compound", data: i, document: y } : i ? { ok: !0, kind: "state", data: i } : y || { ok: !0, kind: "none" };
1380
+ }
1381
+ function So(t, o, a, i) {
1382
+ const r = a == null ? void 0 : a.options, d = Qt(t);
1383
+ if (i !== "size" && (!d || d.kind !== o))
1384
+ return {
1385
+ code: "INVALID_MEDIA",
1386
+ message: "仅支持添加 jpg,jpeg,png,mp4 格式的文件"
1387
+ };
1388
+ if (i !== "size" && r && "mimeTypes" in r && r.mimeTypes && !r.mimeTypes.includes((d == null ? void 0 : d.mime) || t.type))
1389
+ return {
1390
+ code: "INVALID_MEDIA",
1391
+ message: `文件类型不符合${o === "image" ? "图片" : "视频"}配置`
1392
+ };
1393
+ const f = r && "maxBytes" in r ? r.maxBytes : void 0, p = Math.min(
1394
+ Io[o],
1395
+ f ?? Io[o]
1396
+ );
1397
+ return i !== "format" && t.size > p ? {
1398
+ code: "MEDIA_TOO_LARGE",
1399
+ message: p === Io[o] ? `${o === "image" ? "图片不能超过 5MB" : "视频不能超过 100MB"}` : `文件不能超过 ${p} 字节`
1400
+ } : null;
1401
+ }
1402
+ function Ml(t) {
1403
+ const o = /* @__PURE__ */ new Map(), a = Cl();
1404
+ let i = null;
1405
+ function r(S) {
1406
+ i == null || i.dispose(), i = S;
1407
+ }
1408
+ function d() {
1409
+ const S = i;
1410
+ return i = null, S;
1411
+ }
1412
+ function f() {
1413
+ r(null);
1414
+ }
1415
+ function p(S) {
1416
+ return o.has(S);
1417
+ }
1418
+ function y(S) {
1419
+ var s;
1420
+ for (const [x, q] of o)
1421
+ S.has(x) || ((s = q.controller) == null || s.abort(), o.delete(x));
1422
+ }
1423
+ function _(S, s) {
1424
+ var Y, ne, G;
1425
+ const x = {
1426
+ active: /* @__PURE__ */ new Set(),
1427
+ files: /* @__PURE__ */ new Set(),
1428
+ markFailed: []
1429
+ };
1430
+ if (s.id !== S.id) return x;
1431
+ const q = new Set(o.keys()), H = (z) => {
1432
+ const se = /* @__PURE__ */ new Map(), be = /* @__PURE__ */ new Set(), he = (W) => {
1433
+ var _e, Oe;
1434
+ const Z = (_e = W.attrs) == null ? void 0 : _e.id;
1435
+ W.type === "mediaBlock" && typeof Z == "string" && q.has(Z) && (se.has(Z) ? be.add(Z) : se.set(Z, W)), (Oe = W.content) == null || Oe.forEach(he);
1436
+ };
1437
+ return z && he(z), be.forEach((W) => se.delete(W)), se;
1438
+ }, V = H(S.knowledge.doc), m = H(s.knowledge.doc);
1439
+ for (const [z, se] of o) {
1440
+ const be = (Y = t.editor()) == null ? void 0 : Y.getMediaState(z), he = V.get(z), W = m.get(z);
1441
+ !be || !he || !W || be.kind !== se.kind || ((ne = W.attrs) == null ? void 0 : ne.kind) !== se.kind || !Number.isSafeInteger((G = W.attrs) == null ? void 0 : G.nodeVersion) || W.attrs.nodeVersion < 0 || W.attrs.status !== "uploading" && W.attrs.status !== "error" || (x.files.add(z), be.status === W.attrs.status && Jn(he) === Jn(W) ? x.active.add(z) : W.attrs.status === "uploading" && x.markFailed.push({
1442
+ id: z,
1443
+ nodeVersion: W.attrs.nodeVersion
1444
+ }));
1445
+ }
1446
+ return x;
1447
+ }
1448
+ function v(S) {
1449
+ return new Set(
1450
+ [...o].filter(([s]) => S.has(s)).map(([, s]) => s.controller).filter((s) => !!s)
1451
+ );
1452
+ }
1453
+ function N(S) {
1454
+ for (const [s, x] of o)
1455
+ S != null && S.files.has(s) ? S.active.has(s) || (x.controller = void 0) : o.delete(s);
1456
+ }
1457
+ async function b(S, s, x, q = !1) {
1458
+ var G, z, se, be, he, W;
1459
+ const H = [];
1460
+ try {
1461
+ if (!S.length) return;
1462
+ const Z = (fe, me, De) => {
1463
+ var xe;
1464
+ t.diagnostic(fe, me, "validation", De), (xe = t.notify) == null || xe.call(t, "warning", me);
1465
+ };
1466
+ if (S.length > pl) {
1467
+ Z("TOO_MANY_MEDIA", "每次最多仅支持添加10个图片或视频文件");
1468
+ return;
1469
+ }
1470
+ for (const fe of ["format", "size"])
1471
+ for (const me of S) {
1472
+ const De = (G = Qt(me)) == null ? void 0 : G.kind;
1473
+ if (!De || x && De !== x) {
1474
+ Z(
1475
+ "INVALID_MEDIA",
1476
+ "仅支持添加 jpg,jpeg,png,mp4 格式的文件",
1477
+ x
1478
+ );
1479
+ return;
1480
+ }
1481
+ const xe = So(
1482
+ me,
1483
+ De,
1484
+ t.capability(De),
1485
+ fe
1486
+ );
1487
+ if (xe) {
1488
+ Z(
1489
+ xe.code,
1490
+ fe === "size" && S.length > 1 ? "仅支持添加 5MB 以内图片或 100MB 以内视频" : xe.message,
1491
+ De
1492
+ );
1493
+ return;
1494
+ }
1495
+ }
1496
+ for (const fe of S) {
1497
+ const { kind: me } = Qt(fe);
1498
+ if (!t.canUse(me)) {
1499
+ Z("CAPABILITY_REVOKED", "此媒体能力当前不可用", me);
1500
+ return;
1501
+ }
1502
+ }
1503
+ const _e = S.map((fe) => ({
1504
+ file: fe,
1505
+ kind: Qt(fe).kind
1506
+ })), Oe = (z = t.editor()) == null ? void 0 : z.insertPendingMediaBatch(_e, s);
1507
+ if (!Oe) {
1508
+ const fe = s.status() !== "ready";
1509
+ Z(
1510
+ fe ? "INSERT_TARGET_LOST" : "INSERT_FAILED",
1511
+ fe ? "原始插入位置已失效,媒体未写入" : "媒体未能插入知识区"
1512
+ );
1513
+ return;
1514
+ }
1515
+ Oe.forEach((fe, me) => {
1516
+ o.set(fe, _e[me]), H.push(fe);
1517
+ });
1518
+ } finally {
1519
+ s.dispose();
1520
+ }
1521
+ if (H.length && q && ((se = t.editor()) == null || se.focus()), !H.length) return;
1522
+ const V = t.sceneKey();
1523
+ if ((be = t.notify) == null || be.call(t, "info", `正在上传 ${H.length} 个文件`), await Promise.all(H.map(k)), V !== t.sceneKey()) return;
1524
+ const m = H.map((Z) => {
1525
+ var _e;
1526
+ return (_e = t.editor()) == null ? void 0 : _e.getMediaState(Z);
1527
+ }), Y = m.filter((Z) => (Z == null ? void 0 : Z.status) === "error").length, ne = m.filter((Z) => (Z == null ? void 0 : Z.status) === "ready").length;
1528
+ Y ? (he = t.notify) == null || he.call(
1529
+ t,
1530
+ "error",
1531
+ `${ne} 个文件上传成功,${Y} 个上传失败,可在失败项重试`
1532
+ ) : ne && ((W = t.notify) == null || W.call(t, "success", "操作成功"));
1533
+ }
1534
+ async function k(S) {
1535
+ var be, he, W, Z, _e, Oe, fe, me, De;
1536
+ const s = o.get(S), x = t.editor(), q = x == null ? void 0 : x.getMediaState(S);
1537
+ if (!s || s.controller || (q == null ? void 0 : q.status) !== "uploading" || q.kind !== s.kind)
1538
+ return;
1539
+ const { file: H, kind: V } = s, m = t.capability(V), Y = m == null ? void 0 : m.primaryActionId, ne = q.nodeVersion;
1540
+ if (!m || !Y) {
1541
+ x != null && x.failMedia(S, "宿主未提供媒体上传接口", ne) && t.diagnostic("PORT_MISSING", "宿主未提供媒体上传接口", "port", V);
1542
+ return;
1543
+ }
1544
+ const G = t.sceneKey(), z = new AbortController();
1545
+ s.controller = z, t.track(z, !0);
1546
+ let se = null;
1547
+ try {
1548
+ if (se = await a.acquire(z.signal), !se || z.signal.aborted) return;
1549
+ const xe = await Ri(m);
1550
+ if (z.signal.aborted || G !== t.sceneKey() || o.get(S) !== s)
1551
+ return;
1552
+ if (!t.canUse(V)) {
1553
+ (be = t.editor()) == null || be.failMedia(S, "媒体能力已失效,请删除后重试", ne);
1554
+ return;
1555
+ }
1556
+ const pe = t.capability(V), Ce = So(H, V, pe);
1557
+ if (Ce) {
1558
+ (he = t.editor()) != null && he.failMedia(S, Ce.message, ne) && t.diagnostic(
1559
+ Ce.code,
1560
+ Ce.message,
1561
+ "validation",
1562
+ V
1563
+ );
1564
+ return;
1565
+ }
1566
+ const Ke = pe ? xo(pe, Y, t.ports()) : null;
1567
+ if (!Ke) {
1568
+ (W = t.editor()) != null && W.failMedia(S, "宿主未提供媒体上传接口", ne) && t.diagnostic(
1569
+ "PORT_MISSING",
1570
+ "宿主未提供媒体上传接口",
1571
+ "port",
1572
+ V
1573
+ );
1574
+ return;
1575
+ }
1576
+ const Ve = xe.ok ? xe.module.actions[Y] : null;
1577
+ if (!Ve) {
1578
+ (Z = t.editor()) != null && Z.failMedia(S, "媒体上传扩展不可用", ne) && t.diagnostic(
1579
+ "PLUGIN_UNAVAILABLE",
1580
+ "媒体上传扩展不可用",
1581
+ "plugin",
1582
+ V
1583
+ );
1584
+ return;
1585
+ }
1586
+ const E = t.context(V, z);
1587
+ E.reportProgress = (pn) => {
1588
+ var Me;
1589
+ !z.signal.aborted && G === t.sceneKey() && o.get(S) === s && t.canUse(V) && ((Me = t.editor()) == null || Me.reportMediaProgress(S, ne, pn));
1590
+ };
1591
+ const $ = t.scene(), Q = await Ve.execute(
1592
+ { upload: { file: H, nodeId: S, expectedNodeVersion: ne } },
1593
+ {
1594
+ scene: JSON.parse(JSON.stringify($.scene)),
1595
+ sceneKey: G,
1596
+ revision: $.revision,
1597
+ options: pe == null ? void 0 : pe.options,
1598
+ request: E,
1599
+ ports: Ke
1600
+ }
1601
+ );
1602
+ if (z.signal.aborted || G !== t.sceneKey() || o.get(S) !== s)
1603
+ return;
1604
+ if (!t.canUse(V)) {
1605
+ (_e = t.editor()) == null || _e.failMedia(S, "媒体能力已失效,请删除后重试", ne);
1606
+ return;
1607
+ }
1608
+ const Ae = So(
1609
+ H,
1610
+ V,
1611
+ t.capability(V)
1612
+ );
1613
+ if (Ae) {
1614
+ (Oe = t.editor()) != null && Oe.failMedia(S, Ae.message, ne) && t.diagnostic(
1615
+ Ae.code,
1616
+ Ae.message,
1617
+ "validation",
1618
+ V
1619
+ );
1620
+ return;
1621
+ }
1622
+ const je = xn(
1623
+ Q,
1624
+ (pn) => Array.isArray(pn)
1625
+ );
1626
+ if (!je.ok) {
1627
+ (fe = t.editor()) != null && fe.failMedia(S, je.error.message, ne) && t.portDiagnostic(je.error, V);
1628
+ return;
1629
+ }
1630
+ const qe = $i(m, je.data);
1631
+ if (!qe.ok || qe.kind !== "updateNode") {
1632
+ (me = t.editor()) != null && me.failMedia(S, "媒体扩展返回的节点更新无效", ne) && t.diagnostic(
1633
+ "PLUGIN_OPERATION_REJECTED",
1634
+ qe.ok ? "媒体扩展未返回节点更新" : qe.reason,
1635
+ "plugin",
1636
+ V
1637
+ );
1638
+ return;
1639
+ }
1640
+ t.applyNodeUpdate(qe, V) && o.delete(S);
1641
+ } catch (xe) {
1642
+ if (!z.signal.aborted) {
1643
+ const pe = xe instanceof Error ? xe.message : "上传失败";
1644
+ (De = t.editor()) != null && De.failMedia(S, pe, ne) && t.diagnostic("PORT_FAILED", pe, "port", V);
1645
+ }
1646
+ } finally {
1647
+ se == null || se(), s.controller === z && (s.controller = void 0), t.track(z, !1);
1648
+ }
1649
+ }
1650
+ function C(S) {
1651
+ var q, H;
1652
+ const s = o.get(S), x = (q = t.editor()) == null ? void 0 : q.getMediaState(S);
1653
+ !s || s.controller || (x == null ? void 0 : x.status) !== "error" || x.kind !== s.kind || !t.canUse(s.kind) || (H = t.editor()) != null && H.retryMedia(S, x.nodeVersion) && k(S);
1654
+ }
1655
+ return {
1656
+ selectTarget: r,
1657
+ takeTarget: d,
1658
+ clearTarget: f,
1659
+ has: p,
1660
+ removeAbsent: y,
1661
+ classify: _,
1662
+ activeControllers: v,
1663
+ retain: N,
1664
+ enqueue: b,
1665
+ retry: C
1666
+ };
1667
+ }
1668
+ function Ll(t, o) {
1669
+ var i, r, d;
1670
+ const a = Object.prototype.hasOwnProperty.call(o, t.id) ? o[t.id] : t.defaultValue;
1671
+ if (t.kind === "switch" || t.kind === "checkbox")
1672
+ return a === !0;
1673
+ if (t.kind === "radio") {
1674
+ const f = String(a ?? "");
1675
+ return (i = t.options) != null && i.some((p) => p.value === f) ? f : ((d = (r = t.options) == null ? void 0 : r[0]) == null ? void 0 : d.value) || "";
1676
+ }
1677
+ return String(a ?? "");
1678
+ }
1679
+ function Rl(t, o) {
1680
+ var i;
1681
+ const a = new Map(o.fields.map((r) => [r.id, r]));
1682
+ for (const [r, d] of Object.entries(t)) {
1683
+ if (o.toolId === "order_note" && r === "id" && typeof d == "string" && /^rmk_[a-z0-9]{8}$/.test(d))
1684
+ continue;
1685
+ const f = a.get(r);
1686
+ if (!f) return r;
1687
+ if (f.visibleWhen) {
1688
+ const p = a.get(f.visibleWhen.fieldId);
1689
+ if (!p || Ll(p, t) !== f.visibleWhen.equals)
1690
+ return r;
1691
+ }
1692
+ if (f.kind === "switch" || f.kind === "checkbox") {
1693
+ if (typeof d != "boolean") return r;
1694
+ continue;
1695
+ }
1696
+ if (typeof d != "string" || d.trim() !== d || f.kind === "radio" && !((i = f.options) != null && i.some((p) => p.value === d)))
1697
+ return r;
1698
+ }
1699
+ return null;
1700
+ }
1701
+ function Dl(t) {
1702
+ const o = Cn(null), a = Cn(null);
1703
+ let i = null;
1704
+ function r() {
1705
+ if (!i) return;
1706
+ const v = i;
1707
+ i = null, v.abort(), t.track(v, !1);
1708
+ }
1709
+ function d() {
1710
+ var v, N;
1711
+ r(), (N = (v = o.value) == null ? void 0 : v.target) == null || N.dispose(), o.value = null, a.value = null;
1712
+ }
1713
+ function f(v, N) {
1714
+ v === N || !o.value || (d(), t.diagnostic(
1715
+ "TOOL_FORM_CHANGED",
1716
+ "工具配置接口已更新,请重新打开",
1717
+ "port"
1718
+ ));
1719
+ }
1720
+ async function p(v) {
1721
+ var k, C;
1722
+ if (d(), !t.canUse()) {
1723
+ (k = v.target) == null || k.dispose();
1724
+ return;
1725
+ }
1726
+ const N = t.getPort();
1727
+ if (typeof N != "function") {
1728
+ (C = v.target) == null || C.dispose(), t.diagnostic("PORT_MISSING", "宿主未提供工具配置接口", "port");
1729
+ return;
1730
+ }
1731
+ o.value = v;
1732
+ const b = new AbortController();
1733
+ i = b, t.track(b, !0);
1734
+ try {
1735
+ const S = await N({ toolId: v.key }, t.context(b)), s = t.getScene();
1736
+ if (b.signal.aborted || i !== b || v.sceneKey !== s.sceneKey || v.type !== s.type)
1737
+ return;
1738
+ const x = xn(
1739
+ S,
1740
+ (q) => Ei(v.key, q)
1741
+ );
1742
+ if (!x.ok) {
1743
+ t.portDiagnostic(x.error), d();
1744
+ return;
1745
+ }
1746
+ if (!x.data.permitted) {
1747
+ t.diagnostic("CAPABILITY_REVOKED", "当前无权使用此工具", "config"), d();
1748
+ return;
1749
+ }
1750
+ if (v.nodeId) {
1751
+ const q = Rl(
1752
+ v.params,
1753
+ x.data
1754
+ );
1755
+ if (q !== null) {
1756
+ t.diagnostic(
1757
+ "TOOL_PARAMS_UNSUPPORTED",
1758
+ `当前工具表单无法编辑旧参数:${q}`,
1759
+ "validation"
1760
+ ), d();
1761
+ return;
1762
+ }
1763
+ }
1764
+ a.value = x.data;
1765
+ } catch (S) {
1766
+ b.signal.aborted || (t.diagnostic(
1767
+ "PORT_FAILED",
1768
+ S instanceof Error ? S.message : "工具配置读取失败",
1769
+ "port"
1770
+ ), d());
1771
+ } finally {
1772
+ t.track(b, !1), i === b && (i = null);
1773
+ }
1774
+ }
1775
+ async function y(v, N) {
1776
+ if (i || o.value !== v || a.value !== N)
1777
+ return !1;
1778
+ const b = t.getPort();
1779
+ if (typeof b != "function")
1780
+ return t.diagnostic("PORT_MISSING", "宿主未提供工具配置接口", "port"), d(), !1;
1781
+ const k = new AbortController();
1782
+ i = k, t.track(k, !0);
1783
+ try {
1784
+ const C = await b({ toolId: v.key }, t.context(k));
1785
+ if (k.signal.aborted || i !== k || o.value !== v || a.value !== N)
1786
+ return !1;
1787
+ const S = t.getScene();
1788
+ if (v.sceneKey !== S.sceneKey || v.type !== S.type || !t.canUse())
1789
+ return d(), !1;
1790
+ if (t.getPort() !== b)
1791
+ return t.diagnostic(
1792
+ "TOOL_FORM_CHANGED",
1793
+ "工具配置接口已更新,请重新打开",
1794
+ "port"
1795
+ ), d(), !1;
1796
+ const s = xn(
1797
+ C,
1798
+ (x) => Ei(v.key, x)
1799
+ );
1800
+ return s.ok ? s.data.permitted ? Jn(s.data.fields) !== Jn(N.fields) ? (t.diagnostic(
1801
+ "TOOL_FORM_CHANGED",
1802
+ "工具配置已更新,请重新打开",
1803
+ "port"
1804
+ ), d(), !1) : !0 : (t.diagnostic("CAPABILITY_REVOKED", "当前无权使用此工具", "config"), d(), !1) : (t.portDiagnostic(s.error), !1);
1805
+ } catch (C) {
1806
+ return k.signal.aborted || t.diagnostic(
1807
+ "PORT_FAILED",
1808
+ C instanceof Error ? C.message : "工具配置读取失败",
1809
+ "port"
1810
+ ), !1;
1811
+ } finally {
1812
+ t.track(k, !1), i === k && (i = null);
1813
+ }
1814
+ }
1815
+ function _() {
1816
+ o.value = null, a.value = null;
1817
+ }
1818
+ return {
1819
+ edit: o,
1820
+ definition: a,
1821
+ cancel: d,
1822
+ portChanged: f,
1823
+ open: p,
1824
+ recheck: y,
1825
+ releaseForInsert: _
1826
+ };
1827
+ }
1828
+ function Ci(t, o) {
1829
+ const a = (p, y) => t.some(
1830
+ (_) => _.slot === y && (_.canInsert || _.canInsertProvided) && p.includes(_.id)
1831
+ ), i = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new WeakSet(), d = (p) => {
1832
+ if (!p || typeof p != "object") return;
1833
+ const y = p;
1834
+ r.has(y) || (r.add(y), typeof y.type == "string" && i.add(y.type), Array.isArray(y.content) && y.content.forEach(d));
1835
+ };
1836
+ d(o);
1837
+ const f = a(["originalReply"], "knowledgeBlock") || i.has("originalReply");
1838
+ return {
1839
+ businessToken: a(Qa, "knowledgeInline") || i.has("businessToken"),
1840
+ originalReply: f,
1841
+ // OriginalReply's content expression references both node types.
1842
+ separator: f || i.has("messageSeparator"),
1843
+ mediaBlock: f || a(Xa, "knowledgeBlock") || i.has("mediaBlock")
1844
+ };
1845
+ }
1846
+ function Pi(t) {
1847
+ return [
1848
+ t.businessToken,
1849
+ t.originalReply,
1850
+ t.separator,
1851
+ t.mediaBlock
1852
+ ].map((o) => o ? "1" : "0").join("");
1853
+ }
1854
+ const Kl = { class: "fkp-capability-help-head" }, Eo = /* @__PURE__ */ Co({
1855
+ __name: "CapabilityHelp",
1856
+ props: {
1857
+ capabilityId: {}
1858
+ },
1859
+ emits: ["help"],
1860
+ setup(t, { emit: o }) {
1861
+ const a = t, i = o, r = {
1862
+ originalReply: {
1863
+ title: "原话复述",
1864
+ description: `常规知识可直接开启原话复述标签;
1865
+ 推理知识需在回复话术末尾双引号前添加该标签;
1866
+ 触发后,各模式 AI 均会直接使用原话进行自动回复;
1867
+ 多次重复发送相同原话可能引发平台风控,请谨慎使用`
1868
+ },
1869
+ memory: {
1870
+ title: "记忆触发点",
1871
+ description: "顾客消息命中此场景后,系统将刷新记忆画像,供后续 AI 回复参考"
1872
+ },
1873
+ separator: {
1874
+ title: "分隔符",
1875
+ description: "分隔符前后内容将被分成两条消息发出"
1876
+ }
1877
+ };
1878
+ return (d, f) => (A(), L("div", {
1879
+ class: we(["fkp-capability-help", {
1880
+ "fkp-memory-help": a.capabilityId === "memory",
1881
+ "fkp-original-help": a.capabilityId === "originalReply",
1882
+ "fkp-separator-help": a.capabilityId === "separator"
1883
+ }])
1884
+ }, [
1885
+ R("div", Kl, [
1886
+ R("strong", null, ae(r[a.capabilityId].title), 1),
1887
+ a.capabilityId !== "separator" ? (A(), ce(w(ue), {
1888
+ key: 0,
1889
+ class: "fkp-capability-help-link",
1890
+ type: "text",
1891
+ onClick: f[0] || (f[0] = (p) => i("help"))
1892
+ }, {
1893
+ default: j(() => [
1894
+ F(w(Ne), {
1895
+ name: "rte-help",
1896
+ size: 14
1897
+ }),
1898
+ f[1] || (f[1] = ye("我该怎么配? "))
1899
+ ]),
1900
+ _: 1
1901
+ })) : oe("", !0)
1902
+ ]),
1903
+ R("p", null, ae(r[a.capabilityId].description), 1)
1904
+ ], 2));
1905
+ }
1906
+ }), ql = { class: "fkp-variable-columns" }, Vl = {
1907
+ class: "fkp-variable-root",
1908
+ "aria-label": "变量分类"
1909
+ }, $l = {
1910
+ key: 0,
1911
+ class: "fkp-menu-empty"
1912
+ }, Bl = {
1913
+ key: 1,
1914
+ class: "fkp-menu-empty"
1915
+ }, Ul = { class: "fkp-variable-label" }, Fl = { class: "fkp-variable-label" }, jl = {
1916
+ class: "fkp-variable-children",
1917
+ "aria-label": "分组变量"
1918
+ }, zl = { class: "fkp-variable-label" }, Gl = /* @__PURE__ */ Co({
1919
+ __name: "VariableOptionList",
1920
+ props: {
1921
+ options: {},
1922
+ loading: { type: Boolean },
1923
+ nextCursor: {},
1924
+ query: {}
1925
+ },
1926
+ emits: ["choose", "loadMore"],
1927
+ setup(t, { emit: o }) {
1928
+ const a = t, i = o;
1929
+ function r(v) {
1930
+ return "group" in v && typeof v.group == "string" ? v.group.trim() : "";
1931
+ }
1932
+ const d = ie(() => {
1933
+ const v = [], N = /* @__PURE__ */ new Set();
1934
+ for (const b of a.options) {
1935
+ const k = r(b);
1936
+ k ? N.has(k) || (v.push({ kind: "group", label: k }), N.add(k)) : v.push({ kind: "option", option: b });
1937
+ }
1938
+ return v;
1939
+ }), f = ee(""), p = ie(
1940
+ () => d.value.flatMap(
1941
+ (v) => v.kind === "group" ? [v.label] : []
1942
+ )
1943
+ ), y = ie(
1944
+ () => p.value.includes(f.value) ? f.value : p.value[0] || ""
1945
+ ), _ = ie(
1946
+ () => y.value ? a.options.filter((v) => r(v) === y.value) : []
1947
+ );
1948
+ return Te(
1949
+ () => a.query,
1950
+ () => {
1951
+ f.value = "";
1952
+ }
1953
+ ), (v, N) => (A(), L("div", ql, [
1954
+ R("div", Vl, [
1955
+ v.loading && !d.value.length ? (A(), L("p", $l, [
1956
+ F(w(Ne), {
1957
+ name: "sync",
1958
+ size: 15,
1959
+ class: "fkp-spin"
1960
+ }),
1961
+ N[1] || (N[1] = ye("加载中… "))
1962
+ ])) : !v.loading && !d.value.length ? (A(), L("p", Bl, " 暂无可选项 ")) : oe("", !0),
1963
+ (A(!0), L(Ee, null, an(d.value, (b) => (A(), L(Ee, {
1964
+ key: b.kind === "group" ? `group:${b.label}` : `option:${b.option.id}`
1965
+ }, [
1966
+ b.kind === "group" ? (A(), ce(w(ue), {
1967
+ key: 0,
1968
+ class: "fkp-variable-group",
1969
+ type: "text",
1970
+ "aria-label": b.label,
1971
+ title: b.label,
1972
+ "aria-pressed": y.value === b.label,
1973
+ onMouseenter: (k) => f.value = b.label,
1974
+ onFocus: (k) => f.value = b.label,
1975
+ onClick: (k) => f.value = b.label
1976
+ }, {
1977
+ default: j(() => [
1978
+ R("span", Ul, ae(b.label), 1),
1979
+ F(w(Ne), {
1980
+ class: "fkp-variable-group-arrow",
1981
+ name: "arrow-down",
1982
+ size: 14
1983
+ })
1984
+ ]),
1985
+ _: 2
1986
+ }, 1032, ["aria-label", "title", "aria-pressed", "onMouseenter", "onFocus", "onClick"])) : (A(), ce(w(ue), {
1987
+ key: 1,
1988
+ type: "text",
1989
+ "aria-label": b.option.label,
1990
+ title: b.option.label,
1991
+ disabled: b.option.disabled,
1992
+ onClick: (k) => i("choose", b.option, k)
1993
+ }, {
1994
+ default: j(() => [
1995
+ R("span", Fl, ae(b.option.label), 1)
1996
+ ]),
1997
+ _: 2
1998
+ }, 1032, ["aria-label", "title", "disabled", "onClick"]))
1999
+ ], 64))), 128)),
2000
+ v.nextCursor ? (A(), ce(w(ue), {
2001
+ key: 2,
2002
+ class: "fkp-menu-more",
2003
+ type: "text",
2004
+ disabled: v.loading,
2005
+ onClick: N[0] || (N[0] = (b) => i("loadMore"))
2006
+ }, {
2007
+ default: j(() => N[2] || (N[2] = [
2008
+ ye("加载更多")
2009
+ ])),
2010
+ _: 1
2011
+ }, 8, ["disabled"])) : oe("", !0)
2012
+ ]),
2013
+ R("div", jl, [
2014
+ (A(!0), L(Ee, null, an(_.value, (b) => (A(), ce(w(ue), {
2015
+ key: b.id,
2016
+ type: "text",
2017
+ "aria-label": b.label,
2018
+ title: b.label,
2019
+ disabled: b.disabled,
2020
+ onClick: (k) => i("choose", b, k)
2021
+ }, {
2022
+ default: j(() => [
2023
+ R("span", zl, ae(b.label), 1)
2024
+ ]),
2025
+ _: 2
2026
+ }, 1032, ["aria-label", "title", "disabled", "onClick"]))), 128))
2027
+ ])
2028
+ ]));
2029
+ }
2030
+ }), Jl = { class: "fkp-type-confirm-message" }, Hl = { key: 0 }, Wl = { key: 1 }, Yl = { class: "fkp-type-confirm-actions" }, Xl = {
2031
+ key: 0,
2032
+ class: "fkp-toolbar-divider"
2033
+ }, Ql = { class: "fkp-toolbar-group" }, Zl = ["data-fkp-menu-trigger", "onMouseenter", "onPointerdownCapture"], es = { key: 0 }, ns = ["data-fkp-menu-trigger", "onMouseenter", "onPointerdownCapture"], ts = {
2034
+ key: 1,
2035
+ class: "fkp-toolbar-right"
2036
+ }, os = {
2037
+ key: 0,
2038
+ class: "fkp-agent-menu-arrow",
2039
+ "aria-hidden": "true"
2040
+ }, is = { class: "fkp-menu-head" }, as = { key: 1 }, ls = {
2041
+ key: 2,
2042
+ class: "fkp-menu-path"
2043
+ }, ss = {
2044
+ key: 4,
2045
+ class: "fkp-option-list"
2046
+ }, rs = {
2047
+ key: 0,
2048
+ class: "fkp-menu-empty"
2049
+ }, us = {
2050
+ key: 1,
2051
+ class: "fkp-menu-empty"
2052
+ }, cs = { class: "fkp-template-drawer" }, ds = {
2053
+ key: 0,
2054
+ class: "fkp-menu-empty"
2055
+ }, fs = {
2056
+ key: 1,
2057
+ class: "fkp-menu-empty"
2058
+ }, ps = {
2059
+ key: 0,
2060
+ class: "fkp-template-example"
2061
+ }, vs = {
2062
+ key: 0,
2063
+ class: "fkp-template-preview"
2064
+ }, gs = {
2065
+ key: 0,
2066
+ class: "fkp-polish-wait",
2067
+ role: "status"
2068
+ }, ys = {
2069
+ key: 1,
2070
+ class: "fkp-polish-compare"
2071
+ }, ms = { class: "fkp-polish-panel fkp-polish-panel--original" }, ks = { class: "fkp-polish-text" }, bs = { class: "fkp-polish-panel fkp-polish-panel--proposed" }, hs = { class: "fkp-polish-text" }, ws = {
2072
+ key: 2,
2073
+ class: "fkp-polish-wait fkp-polish-error",
2074
+ role: "alert"
2075
+ }, Ts = { class: "fkp-question-row" }, Is = {
2076
+ "aria-hidden": "true",
2077
+ class: "fkp-question-measure"
2078
+ }, As = {
2079
+ key: 0,
2080
+ class: "fkp-question-tags"
2081
+ }, Ss = { class: "fkp-question-tag-label" }, Es = { class: "fkp-knowledge-row" }, Ns = {
2082
+ key: 0,
2083
+ class: "fkp-unsupported"
2084
+ }, _s = { class: "fkp-safe-preview" }, Os = { class: "fkp-safe-preview fkp-safe-state" }, Cs = {
2085
+ key: 2,
2086
+ class: "fkp-agent-preview"
2087
+ }, Ps = {
2088
+ key: 2,
2089
+ class: "fkp-agent-prompt-content"
2090
+ }, xs = { key: 0 }, Ms = { key: 1 }, Ls = ["data-agent-tag"], Rs = ["src"], Ds = ["src"], Ks = ["accept"], qs = "https://freecallai.feishu.cn/wiki/OSb9wD18FizxYfkCXATcXIpAnSg?from=from_copylink", Vs = `填写不同情况的判断条件和处理规则,例如:
2091
+ 1、如果顾客询问要求换货,判断顾客是否提供了要更换的商品信息(例如换成XX):
2092
+ -如果顾客提供了要更换的商品信息,回复:“好的稍等,这边为您备注哦”
2093
+ -如果顾客没有提供要更换的商品信息,回复:“亲,请您提供下需要更换的商品信息” ……`, $s = 2147483647, Zs = /* @__PURE__ */ Co({
2094
+ name: "FkpRichText",
2095
+ __name: "FkpRichText",
2096
+ props: {
2097
+ sceneKey: { default: "default" },
2098
+ modelValue: { default: () => ut() },
2099
+ config: {},
2100
+ policy: {},
2101
+ ports: {},
2102
+ ackRevision: { default: 0 },
2103
+ readonly: { type: Boolean, default: !1 },
2104
+ disabled: { type: Boolean, default: !1 },
2105
+ typeSelectionMode: { default: "switch" }
2106
+ },
2107
+ emits: ["change", "update:modelValue", "diagnostic", "busy-change", "help", "configure", "add-scene"],
2108
+ setup(t, { expose: o, emit: a }) {
2109
+ const i = t, r = (e) => JSON.parse(JSON.stringify(e));
2110
+ function d(e) {
2111
+ const n = Mn(e);
2112
+ if (n !== null)
2113
+ return {
2114
+ scene: ut(),
2115
+ invalid: { path: n || "modelValue", raw: e }
2116
+ };
2117
+ try {
2118
+ const l = JSON.parse(JSON.stringify(e));
2119
+ if (Li(l)) return { scene: l, invalid: null };
2120
+ const c = Pt(l) || "modelValue";
2121
+ return { scene: ut(), invalid: { path: c, raw: l } };
2122
+ } catch {
2123
+ return { scene: ut(), invalid: { path: "modelValue", raw: e } };
2124
+ }
2125
+ }
2126
+ function f(e) {
2127
+ if (!e || typeof e != "object" || Array.isArray(e)) return e;
2128
+ try {
2129
+ const { knowledge: n } = e;
2130
+ if (!n || typeof n != "object" || Array.isArray(n))
2131
+ return e;
2132
+ const l = n;
2133
+ return l.doc ?? l.agentBody ?? l.retainedDoc ?? e;
2134
+ } catch {
2135
+ return e;
2136
+ }
2137
+ }
2138
+ const p = a, y = La();
2139
+ function _(e) {
2140
+ var n;
2141
+ p("help", { capabilityId: e }), (n = y == null ? void 0 : y.vnode.props) != null && n.onHelp || window.open(qs, "_blank", "noopener,noreferrer");
2142
+ }
2143
+ function v(e) {
2144
+ var l;
2145
+ if (p("configure", { capabilityId: e }), (l = y == null ? void 0 : y.vnode.props) != null && l.onConfigure) return;
2146
+ const n = e === "agentSelect" ? "customAgent" : "customerTag";
2147
+ window.open(
2148
+ `${window.location.origin}/#/${n}`,
2149
+ "_blank",
2150
+ "noopener,noreferrer"
2151
+ );
2152
+ }
2153
+ const N = (e) => e === "originalReply" || e === "memory" || e === "separator", b = () => import("./KnowledgeArea-BH-_uF6R.js"), k = gi(b), C = gi(() => import("./ToolForm-C6XW31Y7.js")), S = d(i.modelValue), s = ee(S.scene), x = Cn(S.invalid), q = ee(0), H = ee([]), V = /* @__PURE__ */ new Map(), m = ee(null), Y = Cn(null), ne = ee(0), G = ee(null), z = ee(null), se = ee(null), be = Ol({
2154
+ descriptor: (e) => le.value.capabilities.find(
2155
+ (n) => n.id === e && n.optionKind === "selection"
2156
+ ),
2157
+ ports: () => i.ports,
2158
+ context: it,
2159
+ isCurrent: (e) => m.value === e && Je(e, zn(e)),
2160
+ track: (e, n) => {
2161
+ (n || ze.has(e)) && fn(e, "requesting", n);
2162
+ },
2163
+ diagnostic: (e, n, l) => X(e, n, "port", l),
2164
+ portDiagnostic: (e, n) => tt(e, n)
2165
+ }), {
2166
+ query: he,
2167
+ options: W,
2168
+ path: Z,
2169
+ nextCursor: _e,
2170
+ loading: Oe,
2171
+ abort: fe,
2172
+ reset: me,
2173
+ enter: De,
2174
+ back: xe,
2175
+ fetch: pe
2176
+ } = be, Ce = ee(!1);
2177
+ let Ke = null, Ve = null;
2178
+ const E = ee(""), $ = ee([]), Q = ee("idle");
2179
+ function Ae() {
2180
+ E.value = "", $.value = [], Q.value = "idle";
2181
+ }
2182
+ const je = ee(!1), qe = ee({ uploading: 0, requesting: 0 }), pn = ee(), Me = ee(), Se = ee(), Hn = ee(), Wn = ee(), sn = ee(Number.MAX_SAFE_INTEGER), re = ee(!1);
2183
+ let rn = !1, Ln = !1, Le;
2184
+ const hn = /* @__PURE__ */ new Set(), wn = ee(null);
2185
+ let Lt = !1;
2186
+ Te([m, W], ([e, n], [l]) => {
2187
+ var c;
2188
+ if (e !== "reasoningTemplate") {
2189
+ Lt = !1, wn.value = null;
2190
+ return;
2191
+ }
2192
+ l !== e && (Lt = !1), !Lt && n.length && (wn.value = ((c = n.find((g) => !g.disabled)) == null ? void 0 : c.id) ?? null, Lt = !0);
2193
+ });
2194
+ const Yn = Dl({
2195
+ getPort: () => {
2196
+ var e;
2197
+ return (e = i.ports) == null ? void 0 : e.getToolForm;
2198
+ },
2199
+ getScene: () => ({ sceneKey: i.sceneKey, type: s.value.type }),
2200
+ canUse: () => Je("tool", "knowledgeInline"),
2201
+ context: (e) => it("tool", e),
2202
+ track: (e, n) => {
2203
+ (n || ze.has(e)) && fn(e, "requesting", n);
2204
+ },
2205
+ diagnostic: (e, n, l) => X(e, n, l, "tool"),
2206
+ portDiagnostic: (e) => tt(e, "tool")
2207
+ }), { edit: Rn, definition: Rt } = Yn, Dn = Yn.cancel, Ro = Yn.open, vt = ee("image"), J = ee(), eo = /* @__PURE__ */ new Set();
2208
+ let no = !1;
2209
+ const ze = /* @__PURE__ */ new Map(), gt = /* @__PURE__ */ new Set(), Kn = Cn(null), en = ee(!1), Tn = ee("loading"), Xn = ee(""), Do = ee(""), to = ee(""), Qn = Cn(null);
2210
+ function un() {
2211
+ var e;
2212
+ (e = Vn.get("reasoningPolish:sceneAction")) == null || e.abort(), en.value = !1, Xn.value = "", to.value = "", Qn.value = null;
2213
+ }
2214
+ function Bi() {
2215
+ const e = Qn.value;
2216
+ if (!en.value || Tn.value !== "ready" || !e || e.sceneKey !== i.sceneKey || e.snapshot !== Fe(s.value) || te.value || !nt.value) {
2217
+ un();
2218
+ return;
2219
+ }
2220
+ e.apply(), un();
2221
+ }
2222
+ Te(
2223
+ () => en.value ? [i.sceneKey, Fe(s.value), te.value] : null,
2224
+ () => {
2225
+ en.value && (to.value !== Fe(s.value) || te.value) && un();
2226
+ },
2227
+ { flush: "sync" }
2228
+ ), Te(m, (e) => {
2229
+ e !== "reasoningTemplate" && (Kn.value = null);
2230
+ });
2231
+ const $e = Ml({
2232
+ editor: () => J.value,
2233
+ capability: (e) => le.value.capabilities.find(
2234
+ (n) => n.id === e && n.slot === "knowledgeBlock"
2235
+ ),
2236
+ canUse: (e) => Je(e, "knowledgeBlock"),
2237
+ scene: () => ({
2238
+ scene: s.value,
2239
+ sceneKey: i.sceneKey,
2240
+ revision: q.value
2241
+ }),
2242
+ sceneKey: () => i.sceneKey,
2243
+ ports: () => i.ports,
2244
+ context: it,
2245
+ track: (e, n) => {
2246
+ (n || ze.has(e)) && fn(e, "uploading", n);
2247
+ },
2248
+ diagnostic: X,
2249
+ portDiagnostic: tt,
2250
+ notify: (e, n) => {
2251
+ ki[e]({ content: n, position: "top" });
2252
+ },
2253
+ applyNodeUpdate: (e, n) => {
2254
+ var l;
2255
+ ot = n;
2256
+ try {
2257
+ return ((l = J.value) == null ? void 0 : l.applyNodeUpdate(e, n)) || !1;
2258
+ } finally {
2259
+ ot = null;
2260
+ }
2261
+ }
2262
+ });
2263
+ let vn = null, Zn = null, In = null;
2264
+ const qn = /* @__PURE__ */ new Set(), et = /* @__PURE__ */ new Set(), Vn = /* @__PURE__ */ new Map();
2265
+ let Ui = 0, $n = null, cn, ve = !1, gn = null, Be = null, yn = null;
2266
+ const Dt = ee(Date.now());
2267
+ let yt;
2268
+ function Ko() {
2269
+ var n, l, c;
2270
+ yt && clearTimeout(yt), Dt.value = Date.now();
2271
+ const e = [
2272
+ (n = i.policy) == null ? void 0 : n.expiresAt,
2273
+ ((c = (l = i.config) == null ? void 0 : l.remote) == null ? void 0 : c.status) === "ready" ? i.config.remote.expiresAt : void 0
2274
+ ].filter(
2275
+ (g) => typeof g == "number" && g > Dt.value
2276
+ );
2277
+ e.length && (yt = setTimeout(
2278
+ Ko,
2279
+ Math.min(Math.min(...e) - Dt.value + 1, $s)
2280
+ ));
2281
+ }
2282
+ Te(
2283
+ () => {
2284
+ var e, n, l;
2285
+ return [
2286
+ (e = i.policy) == null ? void 0 : e.expiresAt,
2287
+ ((l = (n = i.config) == null ? void 0 : n.remote) == null ? void 0 : l.status) === "ready" ? i.config.remote.expiresAt : void 0
2288
+ ];
2289
+ },
2290
+ Ko,
2291
+ { immediate: !0 }
2292
+ );
2293
+ const le = ie(
2294
+ () => ct(s.value.type, i, Dt.value)
2295
+ ), qo = ie(
2296
+ () => Ci(le.value.capabilities, s.value.knowledge.doc)
2297
+ ), Vo = ie(
2298
+ () => Pi(qo.value)
2299
+ );
2300
+ Te(
2301
+ () => [i.sceneKey, s.value.type, Vo.value],
2302
+ (e, n) => {
2303
+ var c;
2304
+ if (je.value = !1, !n || e[0] !== n[0] || e[1] !== n[1] || e[2] === n[2])
2305
+ return;
2306
+ const l = (c = J.value) == null ? void 0 : c.captureSelection();
2307
+ Tt(), Ut(), $e.clearTarget(), qn.forEach((g) => g.dispose()), qn.clear(), et.forEach((g) => g.abort()), et.clear(), Vn.clear(), l && Qe(() => {
2308
+ var g;
2309
+ return (g = J.value) == null ? void 0 : g.restoreSelection(l);
2310
+ });
2311
+ }
2312
+ );
2313
+ const Bn = ie(
2314
+ () => {
2315
+ var e;
2316
+ return ((e = x.value) == null ? void 0 : e.path) || Pt(s.value);
2317
+ }
2318
+ ), Fi = ie(
2319
+ () => To(
2320
+ x.value ? f(x.value.raw) : s.value.knowledge.doc || s.value.knowledge.agentBody || s.value.knowledge.retainedDoc
2321
+ )
2322
+ ), $o = ie(() => {
2323
+ var e;
2324
+ if (x.value || !((e = Bn.value) != null && e.startsWith("extensionState")))
2325
+ return null;
2326
+ try {
2327
+ return JSON.stringify(s.value.extensionState, null, 2);
2328
+ } catch {
2329
+ return "扩展状态无法安全预览;原始数据仍保留。";
2330
+ }
2331
+ }), te = ie(
2332
+ () => le.value.mode === "readonly" || !!Bn.value || je.value
2333
+ ), oo = ie(
2334
+ () => le.value.capabilities.filter(
2335
+ (e) => e.slot === "questionAction" && e.visible
2336
+ )
2337
+ ), io = ie(
2338
+ () => le.value.capabilities.filter(
2339
+ (e) => (e.slot === "knowledgeInline" || e.slot === "knowledgeBlock") && e.visible
2340
+ )
2341
+ ), Kt = ie(
2342
+ () => le.value.capabilities.filter(
2343
+ (e) => e.slot === "sceneAction" && e.visible
2344
+ )
2345
+ ), Bo = ie(() => {
2346
+ const e = [];
2347
+ let n = 0;
2348
+ const l = (c, g, T, M = !1) => {
2349
+ T.length && e.push({
2350
+ key: c,
2351
+ actions: T.map((h) => ({
2352
+ key: `${h.id}:${h.slot}`,
2353
+ kind: g,
2354
+ index: n++,
2355
+ item: h,
2356
+ showLabel: M
2357
+ }))
2358
+ });
2359
+ };
2360
+ return s.value.type === "normal" ? (l("questions", "question", oo.value), l("insert", "knowledge", io.value)) : (s.value.type === "reasoning" && (l(
2361
+ "references",
2362
+ "knowledge",
2363
+ io.value.filter((c) => c.order <= 40),
2364
+ !0
2365
+ ), l(
2366
+ "media",
2367
+ "knowledge",
2368
+ io.value.filter((c) => c.order > 40)
2369
+ )), l("questions", "question", oo.value)), e;
2370
+ }), ao = ie(() => s.value.type === "reasoning" ? Kt.value.map((e, n) => ({
2371
+ key: `${e.id}:${e.slot}`,
2372
+ kind: "scene",
2373
+ index: n,
2374
+ item: e
2375
+ })) : s.value.type === "agent" ? [{ key: "agentOpen", kind: "agentOpen", index: 0 }] : []), lo = ie(
2376
+ () => Bo.value.flatMap((e) => e.actions)
2377
+ ), so = ie(
2378
+ () => lo.value.slice(sn.value)
2379
+ );
2380
+ let mt, Uo = 0;
2381
+ function Fo() {
2382
+ qt(), jo();
2383
+ }
2384
+ function jo() {
2385
+ var l;
2386
+ const e = (l = Me.value) == null ? void 0 : l.getBoundingClientRect();
2387
+ if (!e) return;
2388
+ const n = Math.min(320, window.innerWidth - 24);
2389
+ ne.value = Math.max(
2390
+ 12 - e.left,
2391
+ Math.min(0, window.innerWidth - 12 - e.left - n)
2392
+ );
2393
+ }
2394
+ async function qt() {
2395
+ const e = ++Uo;
2396
+ sn.value = lo.value.length, await Qe();
2397
+ const n = Hn.value;
2398
+ if (n) {
2399
+ for (; e === Uo && (n.scrollWidth > n.clientWidth || Wn.value !== void 0 && Wn.value.scrollWidth > Wn.value.clientWidth) && sn.value > 0; )
2400
+ sn.value--, await Qe();
2401
+ so.value.length || (re.value = !1);
2402
+ }
2403
+ }
2404
+ let Vt;
2405
+ Ra(() => {
2406
+ Vt = fl(), window.addEventListener("resize", Fo), document.addEventListener("click", ai), typeof ResizeObserver < "u" && (mt = new ResizeObserver(() => void qt()), Hn.value && mt.observe(Hn.value)), qt();
2407
+ }), Te(
2408
+ () => {
2409
+ var e;
2410
+ return [...lo.value, ...ao.value].map((n) => {
2411
+ var l;
2412
+ return `${n.key}:${((l = n.item) == null ? void 0 : l.label) || ""}`;
2413
+ }).concat(((e = s.value.knowledge.agentRef) == null ? void 0 : e.name) || "").join("|");
2414
+ },
2415
+ () => void qt()
2416
+ );
2417
+ function kt(e, n) {
2418
+ e.kind === "knowledge" && e.item && (n == null ? void 0 : n.currentTarget) instanceof Element && n.currentTarget.closest(".fkp-more-menu") && Ft(e.item), re.value = !1, e.kind === "agentOpen" ? Oa() : e.item && (e.kind === "question" ? Fn(e.item.id) ? It(e.item, n) : fo(e.item) : It(e.item, n));
2419
+ }
2420
+ function zo(e) {
2421
+ We(e) && Ft(e);
2422
+ }
2423
+ function ji(e, n) {
2424
+ e.item && (e.kind === "question" ? uo(e.item, n) : e.kind === "knowledge" && zo(e.item));
2425
+ }
2426
+ function Go(e, n, l) {
2427
+ const c = le.value.capabilities.find(
2428
+ (g) => g.id === e && g.slot === "questionAction"
2429
+ );
2430
+ c && (l ? At(c, n) : It(c, n));
2431
+ }
2432
+ function zi(e, n) {
2433
+ const l = le.value.capabilities.find(
2434
+ (c) => c.id === e && c.slot === "questionAction"
2435
+ );
2436
+ l && uo(l, n);
2437
+ }
2438
+ const Ge = ie(() => s.value.knowledge.agentRef), Jo = ie(
2439
+ () => Ge.value ? `${Ge.value.name}${Ge.value.invalid ? "(已失效)" : ""}` : ""
2440
+ ), Un = ie(
2441
+ () => {
2442
+ var e, n;
2443
+ return !((e = Ge.value) != null && e.invalid) && typeof ((n = Ge.value) == null ? void 0 : n.id) == "string" ? Ge.value.id.trim() : "";
2444
+ }
2445
+ ), Ho = ie(
2446
+ () => Ci([], s.value.knowledge.agentBody || null)
2447
+ ), nt = ie(
2448
+ () => sl(s.value.knowledge.doc)
2449
+ );
2450
+ function Fn(e) {
2451
+ return le.value.capabilities.some(
2452
+ (n) => n.id === e && n.slot === "questionAction" && !!n.questionTag
2453
+ );
2454
+ }
2455
+ function bt(e) {
2456
+ return le.value.capabilities.some(
2457
+ (n) => n.id === e && n.optionKind === "selection" && n.optionTrigger === "hover"
2458
+ );
2459
+ }
2460
+ const ro = (e) => Za(s.value, e), Wo = ie(() => {
2461
+ const e = [], n = le.value.capabilities.filter((l) => l.slot === "questionAction").sort((l, c) => l.order - c.order);
2462
+ for (const l of n) {
2463
+ const c = l.questionTag;
2464
+ if (!c || !jn(l.id) || !Fn(l.id)) continue;
2465
+ const g = ro(l.id);
2466
+ g && e.push({
2467
+ id: l.id,
2468
+ kind: c.kind,
2469
+ protocolLabel: c.protocolLabel,
2470
+ label: g.label,
2471
+ icon: l.icon
2472
+ });
2473
+ }
2474
+ return e;
2475
+ }), ht = ie(
2476
+ () => le.value.capabilities.find(
2477
+ (e) => e.id === m.value && e.optionKind === "selection"
2478
+ )
2479
+ ), Re = ie(() => {
2480
+ var e;
2481
+ return (e = ht.value) == null ? void 0 : e.menu;
2482
+ }), Yo = ie(
2483
+ () => !!ht.value && ht.value.optionSource !== "agents"
2484
+ ), Xo = ie(
2485
+ () => {
2486
+ var e;
2487
+ return ((e = Re.value) == null ? void 0 : e.searchLabel) || "搜索选项";
2488
+ }
2489
+ ), Qo = ie(
2490
+ () => {
2491
+ var e, n;
2492
+ return ((e = Re.value) == null ? void 0 : e.title) || ((n = ht.value) == null ? void 0 : n.label) || "选择内容";
2493
+ }
2494
+ ), Zo = ie(() => {
2495
+ var n, l;
2496
+ const e = (n = le.value.capabilities.find(
2497
+ (c) => c.id === vt.value && c.slot === "knowledgeBlock"
2498
+ )) == null ? void 0 : n.options;
2499
+ return e && "mimeTypes" in e && ((l = e.mimeTypes) != null && l.length) ? e.mimeTypes.filter(
2500
+ (c) => Ai[vt.value].includes(c)
2501
+ ).join(",") : Ai[vt.value].join(",");
2502
+ });
2503
+ Te(
2504
+ () => i.sceneKey,
2505
+ () => {
2506
+ un(), Y.value = null, An();
2507
+ const e = d(i.modelValue);
2508
+ s.value = e.scene, x.value = e.invalid, q.value = 0, V.clear(), H.value = [], Ae(), Ce.value = !1, Ke = null, Ve = null;
2509
+ }
2510
+ ), Te(
2511
+ () => d(i.modelValue),
2512
+ (e) => {
2513
+ if (e.invalid) {
2514
+ un(), Y.value = null, An(), x.value = e.invalid, V.clear(), H.value = [];
2515
+ return;
2516
+ }
2517
+ const n = Fe(e.scene);
2518
+ if (x.value) {
2519
+ un(), An(), s.value = e.scene, x.value = null, V.clear(), H.value = [], Ae(), Ce.value = !1, Ke = null, Ve = null;
2520
+ return;
2521
+ }
2522
+ if (n === Fe(s.value) || i.ackRevision > 0 && V.get(i.ackRevision) === n)
2523
+ return;
2524
+ if (i.ackRevision < q.value && q.value > 0) {
2525
+ X(
2526
+ "STALE_EXTERNAL_VALUE",
2527
+ "外部更新与当前编辑冲突,已保留当前草稿",
2528
+ "validation"
2529
+ );
2530
+ return;
2531
+ }
2532
+ const l = s.value.type !== e.scene.type, c = l ? void 0 : ga(e.scene);
2533
+ if (An(c), un(), Y.value = null, s.value = e.scene, V.clear(), H.value = [], Ae(), l && (Ce.value = !1), Ke = null, Ve = null, c != null && c.markFailed.length) {
2534
+ const { sceneKey: g } = i;
2535
+ Qe(() => {
2536
+ var T, M, h;
2537
+ if (!(g !== i.sceneKey || s.value.id !== e.scene.id || s.value.type !== e.scene.type))
2538
+ for (const { id: O, nodeVersion: B } of c.markFailed)
2539
+ $e.has(O) && ((M = (T = J.value) == null ? void 0 : T.getMediaState(O)) == null ? void 0 : M.status) === "uploading" && ((h = J.value) == null || h.failMedia(
2540
+ O,
2541
+ "媒体占位已被外部更新,请重试上传",
2542
+ B
2543
+ ));
2544
+ });
2545
+ }
2546
+ }
2547
+ ), Te(
2548
+ () => le.value.diagnostics,
2549
+ (e) => e.forEach(
2550
+ (n) => p("diagnostic", { ...n, sceneKey: i.sceneKey })
2551
+ ),
2552
+ { immediate: !0 }
2553
+ ), Te(
2554
+ Bn,
2555
+ (e) => {
2556
+ e && p("diagnostic", {
2557
+ code: "UNSUPPORTED_CONTENT",
2558
+ severity: "error",
2559
+ source: "migration",
2560
+ message: "文档包含当前版本不认识的内容,已进入只读保护",
2561
+ sceneKey: i.sceneKey,
2562
+ path: e
2563
+ });
2564
+ },
2565
+ { immediate: !0 }
2566
+ );
2567
+ function X(e, n, l, c) {
2568
+ c === "reasoningPolish" && en.value && (Xn.value = n), p("diagnostic", {
2569
+ code: e,
2570
+ message: n,
2571
+ source: l,
2572
+ capabilityId: c,
2573
+ sceneKey: i.sceneKey,
2574
+ severity: "warning"
2575
+ });
2576
+ }
2577
+ function tt(e, n, l = "port") {
2578
+ if (e.code !== "ABORTED") {
2579
+ n === "reasoningPolish" && en.value && (Xn.value = e.message), p("diagnostic", {
2580
+ code: e.code,
2581
+ message: e.message,
2582
+ source: l,
2583
+ severity: "warning",
2584
+ capabilityId: n,
2585
+ sceneKey: i.sceneKey,
2586
+ retryable: e.retryable
2587
+ });
2588
+ for (const c of e.issues || [])
2589
+ p("diagnostic", {
2590
+ ...c,
2591
+ sceneKey: i.sceneKey,
2592
+ capabilityId: c.capabilityId || n,
2593
+ retryable: c.retryable ?? e.retryable
2594
+ });
2595
+ }
2596
+ }
2597
+ function nn(e, n, l) {
2598
+ if (te.value || ct(s.value.type, i).mode === "readonly" || Pt(e))
2599
+ return !1;
2600
+ Y.value = null;
2601
+ const c = n === "typeSwitch" ? r(s.value) : null;
2602
+ s.value = e, c ? H.value = [
2603
+ ...H.value.slice(-19),
2604
+ c
2605
+ ] : n !== "undo" && (H.value = []);
2606
+ const g = {
2607
+ sceneKey: i.sceneKey,
2608
+ revision: ++q.value,
2609
+ origin: n,
2610
+ capabilityId: l
2611
+ };
2612
+ return V.set(g.revision, Fe(e)), V.size > 32 && V.delete(V.keys().next().value), p("change", e, g), p("update:modelValue", e), !0;
2613
+ }
2614
+ function ei(e, n) {
2615
+ const { sceneKey: l } = i, c = Fe(s.value), g = ho.confirm({
2616
+ title: "确认操作",
2617
+ content: e,
2618
+ onOk: () => {
2619
+ gt.delete(g), !(i.sceneKey !== l || Fe(s.value) !== c || te.value) && n();
2620
+ },
2621
+ onClose: () => gt.delete(g)
2622
+ });
2623
+ gt.add(g);
2624
+ }
2625
+ function ni(e, n, l) {
2626
+ Kn.value = {
2627
+ optionId: e,
2628
+ sceneKey: i.sceneKey,
2629
+ snapshot: Fe(s.value),
2630
+ content: n,
2631
+ apply: l
2632
+ };
2633
+ }
2634
+ function $t() {
2635
+ Kn.value = null;
2636
+ }
2637
+ function Gi() {
2638
+ const e = Kn.value;
2639
+ Kn.value = null, !(!e || m.value !== "reasoningTemplate" || i.sceneKey !== e.sceneKey || Fe(s.value) !== e.snapshot || te.value) && e.apply();
2640
+ }
2641
+ function Ji(e) {
2642
+ nn(
2643
+ { ...s.value, question: { text: e.replace(/[\r\n]+/g, " ") } },
2644
+ "user"
2645
+ );
2646
+ }
2647
+ function Hi() {
2648
+ Ce.value = !1, Ke = "question", ii(), gn = null, yn = null;
2649
+ }
2650
+ function Wi(e) {
2651
+ var c;
2652
+ if (te.value || e.target instanceof HTMLTextAreaElement) return;
2653
+ const n = (c = Se.value) == null ? void 0 : c.querySelector(
2654
+ '[aria-label="顾客问法"]'
2655
+ );
2656
+ if (!n) return;
2657
+ n.focus();
2658
+ const l = n.value.length;
2659
+ n.setSelectionRange(l, l);
2660
+ }
2661
+ function Yi(e) {
2662
+ const n = e.target;
2663
+ n instanceof HTMLTextAreaElement && (gn = {
2664
+ sceneKey: i.sceneKey,
2665
+ from: n.selectionStart,
2666
+ to: n.selectionEnd,
2667
+ next: e.relatedTarget
2668
+ }, Ve = {
2669
+ sceneKey: i.sceneKey,
2670
+ from: n.selectionStart,
2671
+ to: n.selectionEnd,
2672
+ text: s.value.question.text
2673
+ });
2674
+ }
2675
+ function uo(e, n) {
2676
+ var c;
2677
+ const l = (c = Se.value) == null ? void 0 : c.querySelector(
2678
+ '[aria-label="顾客问法"]'
2679
+ );
2680
+ l && document.activeElement === l && co(e, n);
2681
+ }
2682
+ function ti() {
2683
+ var n, l;
2684
+ Ut(), Ce.value && (In = ((n = J.value) == null ? void 0 : n.captureMediaTarget()) || null);
2685
+ const e = (l = Se.value) == null ? void 0 : l.querySelector(
2686
+ '[aria-label="顾客问法"]'
2687
+ );
2688
+ e && document.activeElement === e && (yn = {
2689
+ sceneKey: i.sceneKey,
2690
+ from: e.selectionStart,
2691
+ to: e.selectionEnd
2692
+ });
2693
+ }
2694
+ function co(e, n) {
2695
+ var T;
2696
+ if (e.slot !== "questionAction" || !Fn(e.id)) {
2697
+ Be = null;
2698
+ return;
2699
+ }
2700
+ const l = (T = Se.value) == null ? void 0 : T.querySelector(
2701
+ '[aria-label="顾客问法"]'
2702
+ ), c = (n == null ? void 0 : n.currentTarget) instanceof Element ? !!n.currentTarget.closest(".fkp-more-menu") : !!(Be != null && Be.fromMore);
2703
+ let g = null;
2704
+ if (l && document.activeElement === l)
2705
+ g = {
2706
+ sceneKey: i.sceneKey,
2707
+ from: l.selectionStart,
2708
+ to: l.selectionEnd
2709
+ };
2710
+ else if ((gn == null ? void 0 : gn.sceneKey) === i.sceneKey) {
2711
+ const { next: M } = gn, h = n == null ? void 0 : n.currentTarget;
2712
+ M instanceof Element && (h instanceof Node ? h === M || h.contains(M) || M.contains(h) || c && M.closest('[data-fkp-menu-trigger="more"]') : M.closest(`[data-fkp-menu-trigger="${e.id}"]`)) && (g = gn);
2713
+ }
2714
+ !g && (n == null ? void 0 : n.currentTarget) instanceof Element && n.currentTarget.closest(".fkp-more-menu") && (yn == null ? void 0 : yn.sceneKey) === i.sceneKey && (g = yn), !g && (Be == null ? void 0 : Be.sceneKey) === i.sceneKey && Be.capabilityId === e.id && (g = Be), Be = g ? { ...g, capabilityId: e.id, fromMore: c } : null, gn = null, yn = null;
2715
+ }
2716
+ Te(m, (e) => {
2717
+ var n;
2718
+ e || (Be = null), e !== ((n = G.value) == null ? void 0 : n.kind) && (G.value = null), !e && se.value && re.value && Bt();
2719
+ }), Te(re, (e) => {
2720
+ e || (dn(), hn.clear(), rn = !1, Ln = !1, yn = null, Ut());
2721
+ });
2722
+ function dn() {
2723
+ Le && clearTimeout(Le), Le = void 0;
2724
+ }
2725
+ function Xi() {
2726
+ Ln = !0, dn();
2727
+ }
2728
+ function Qi() {
2729
+ Ln = !1, Bt();
2730
+ }
2731
+ function Zi() {
2732
+ dn(), !re.value && (ti(), rn = !0, re.value = !0, m.value = null);
2733
+ }
2734
+ function ea() {
2735
+ if (dn(), re.value && rn) {
2736
+ rn = !1;
2737
+ return;
2738
+ }
2739
+ rn = !1, re.value = !re.value, m.value = null;
2740
+ }
2741
+ function Bt() {
2742
+ !rn || Ln || (dn(), Le = setTimeout(() => {
2743
+ Le = void 0, rn && !hn.size && (re.value = !1);
2744
+ }, 240));
2745
+ }
2746
+ function na(e, n) {
2747
+ n ? (hn.add(e), dn()) : (hn.delete(e), hn.size || Bt());
2748
+ }
2749
+ async function ta(e, n) {
2750
+ var g;
2751
+ if (!e || e.capabilityId !== n || e.sceneKey !== i.sceneKey)
2752
+ return;
2753
+ await Qe();
2754
+ const l = (g = Se.value) == null ? void 0 : g.querySelector(
2755
+ '[aria-label="顾客问法"]'
2756
+ );
2757
+ if (!l || l.disabled) return;
2758
+ const c = document.activeElement;
2759
+ c !== l && c !== document.body && !(c instanceof Element && (c.closest(".fkp-option-menu") || c.closest(`[data-fkp-menu-trigger="${n}"]`) || e.fromMore && c.closest('[data-fkp-menu-trigger="more"]'))) || (l.focus(), l.setSelectionRange(e.from, e.to));
2760
+ }
2761
+ function wt(e, n = "user", l, c = s.value.extensionState, g) {
2762
+ var B, U;
2763
+ const T = Ti(
2764
+ s.value.knowledge.doc,
2765
+ e,
2766
+ le.value.capabilities
2767
+ );
2768
+ if (T) {
2769
+ X(
2770
+ "CAPABILITY_REVOKED",
2771
+ "此能力当前不可插入新内容",
2772
+ "config",
2773
+ T.id
2774
+ ), (B = J.value) == null || B.restoreDoc(s.value.knowledge.doc || On());
2775
+ return;
2776
+ }
2777
+ if (!nn(
2778
+ {
2779
+ ...s.value,
2780
+ question: g === void 0 ? s.value.question : { text: g },
2781
+ knowledge: { ...s.value.knowledge, doc: e },
2782
+ extensionState: c
2783
+ },
2784
+ n,
2785
+ l
2786
+ )) {
2787
+ (U = J.value) == null || U.restoreDoc(s.value.knowledge.doc || On());
2788
+ return;
2789
+ }
2790
+ const h = /* @__PURE__ */ new Set(), O = (K) => {
2791
+ var u, P;
2792
+ K.type === "mediaBlock" && typeof ((u = K.attrs) == null ? void 0 : u.id) == "string" && h.add(K.attrs.id), (P = K.content) == null || P.forEach(O);
2793
+ };
2794
+ O(e), $e.removeAbsent(h);
2795
+ }
2796
+ let ot = null;
2797
+ function oa(e) {
2798
+ wt(
2799
+ e,
2800
+ ot ? "plugin" : "user",
2801
+ ot || void 0
2802
+ );
2803
+ }
2804
+ function oi(e, n, l = s.value.extensionState, c) {
2805
+ const g = {
2806
+ ...s.value,
2807
+ question: c === void 0 ? s.value.question : { text: c },
2808
+ knowledge: { ...s.value.knowledge, doc: e },
2809
+ extensionState: l
2810
+ };
2811
+ return Pt(g) || Ti(
2812
+ s.value.knowledge.doc,
2813
+ e,
2814
+ le.value.capabilities
2815
+ ) ? (X(
2816
+ "INVALID_RESPONSE",
2817
+ "接口返回的文档包含当前场景不可用的内容",
2818
+ "port",
2819
+ n
2820
+ ), !1) : !0;
2821
+ }
2822
+ function jn(e) {
2823
+ var n, l;
2824
+ return !!((l = (n = s.value.extensionState[e]) == null ? void 0 : n.data) != null && l.enabled);
2825
+ }
2826
+ function fo(e) {
2827
+ if (Fn(e.id) && !jn(e.id) && !ro(e.id)) {
2828
+ It(e);
2829
+ return;
2830
+ }
2831
+ mn(e);
2832
+ }
2833
+ function zn(e) {
2834
+ const n = le.value.capabilities.find(
2835
+ (l) => l.id === e && l.optionKind === "selection"
2836
+ );
2837
+ return n ? n.slot : "knowledgeInline";
2838
+ }
2839
+ function Je(e, n) {
2840
+ return !te.value && ct(s.value.type, i).capabilities.some(
2841
+ (l) => l.id === e && l.slot === n && l.canInsert
2842
+ );
2843
+ }
2844
+ function po(e, n) {
2845
+ return !te.value && ct(s.value.type, i).capabilities.some(
2846
+ (l) => l.id === e && l.slot === n && l.canInsertProvided
2847
+ );
2848
+ }
2849
+ Te(
2850
+ () => Je("tool", "knowledgeInline"),
2851
+ (e) => {
2852
+ !e && Rn.value && Dn();
2853
+ }
2854
+ ), Te(
2855
+ () => {
2856
+ const e = m.value;
2857
+ return {
2858
+ opened: e,
2859
+ locked: te.value,
2860
+ usable: !e || e === "type" || le.value.capabilities.some(
2861
+ (n) => n.id === e && n.slot === zn(e) && n.canInsert
2862
+ )
2863
+ };
2864
+ },
2865
+ ({ opened: e, locked: n, usable: l }) => {
2866
+ !e || !n && l || (ve = !1, Ye(), m.value = null);
2867
+ },
2868
+ { flush: "sync" }
2869
+ );
2870
+ function We(e) {
2871
+ var n, l;
2872
+ return !te.value && e.canInsert && (e.id !== "reasoningPolish" || nt.value) && (((n = Wt(e.id)) == null ? void 0 : n.allowInOriginalReply) !== !1 || !((l = J.value) != null && l.isSelectionInsideOriginalReply())) && (e.slot !== "knowledgeInline" && e.slot !== "knowledgeBlock" || Ce.value && !!J.value);
2873
+ }
2874
+ function ia(e) {
2875
+ const { target: n } = e;
2876
+ n instanceof Element && n.closest('.fkp-knowledge-document[contenteditable="true"]') && (Ce.value = !0, Ke = "knowledge");
2877
+ }
2878
+ function aa(e) {
2879
+ je.value = !0, X("MEDIA_EXTENSION_UNAVAILABLE", e, "plugin");
2880
+ }
2881
+ function la(e) {
2882
+ const n = e.relatedTarget;
2883
+ (!(n instanceof Node) || !e.currentTarget.contains(n)) && (Ce.value = !1, n instanceof HTMLElement && n !== document.body && ii());
2884
+ }
2885
+ function ii() {
2886
+ if (!m.value) return;
2887
+ const e = m.value;
2888
+ le.value.capabilities.some(
2889
+ (n) => n.id === e && (n.slot === "knowledgeInline" || n.slot === "knowledgeBlock")
2890
+ ) && (Ye(), ve = !1, m.value = null);
2891
+ }
2892
+ async function mn(e, n = {}, l, c, g, T = !1, M) {
2893
+ var lt, St, Et, st, Nt, zt, _t, ri, ui, ci, di, fi;
2894
+ const h = (de, Xe) => (M == null || M({ ok: !1, code: de, message: Xe }), !1), O = !!n.edit, B = T ? po : Je;
2895
+ let U = We(e);
2896
+ if (O ? U = B(e.id, e.slot) : l && (U = B(e.id, e.slot) && (((lt = Wt(e.id)) == null ? void 0 : lt.allowInOriginalReply) !== !1 || !((St = J.value) != null && St.isSelectionInsideOriginalReply()))), !U || te.value || !ct(s.value.type, i).capabilities.some(
2897
+ (de) => de.id === e.id && de.slot === e.slot && (T ? de.canInsertProvided : de.canInsert)
2898
+ ))
2899
+ return l == null || l.dispose(), h("CAPABILITY_REVOKED", "该扩展当前不可插入");
2900
+ const K = e.slot === "knowledgeInline" || e.slot === "knowledgeBlock", u = K && !O, P = u ? l || ((Et = J.value) == null ? void 0 : Et.captureMediaTarget()) : null;
2901
+ if (u && !P)
2902
+ return X(
2903
+ "INSERT_TARGET_LOST",
2904
+ "原始插入位置已失效,扩展内容未写入",
2905
+ "plugin",
2906
+ e.id
2907
+ ), h("INSERT_TARGET_LOST", "原始插入位置已失效");
2908
+ P && qn.add(P);
2909
+ const I = K ? null : `${e.id}:${e.slot}`;
2910
+ I && ((st = Vn.get(I)) == null || st.abort());
2911
+ const D = new AbortController();
2912
+ et.add(D), I && Vn.set(I, D);
2913
+ const tn = q.value, kn = i.sceneKey, { type: at } = s.value, on = r(s.value), En = document.activeElement, He = c instanceof HTMLElement ? c : En;
2914
+ let Pe = !1;
2915
+ const Nn = () => !D.signal.aborted && (!g || g()) && kn === i.sceneKey && at === s.value.type && (!P || qn.has(P)) && (K || tn === q.value) && le.value.capabilities.some(
2916
+ (de) => de.id === e.id && de.slot === e.slot && (T ? de.canInsertProvided : de.canInsert)
2917
+ ) && ct(s.value.type, i).capabilities.some(
2918
+ (de) => de.id === e.id && de.slot === e.slot && (T ? de.canInsertProvided : de.canInsert)
2919
+ );
2920
+ try {
2921
+ const de = await Ri(e);
2922
+ if (!Nn())
2923
+ return h("INSERT_CANCELLED", "场景、权限或光标已变化");
2924
+ if (!de.ok) {
2925
+ const Ue = de.reason === "VERSION_MISMATCH" ? "扩展身份或版本不匹配" : "扩展未安装";
2926
+ return X("PLUGIN_UNAVAILABLE", Ue, "plugin", e.id), h("PLUGIN_UNAVAILABLE", Ue);
2927
+ }
2928
+ const Xe = (Nt = e.actions) == null ? void 0 : Nt.find(
2929
+ (Ue) => Ue.id === (e.primaryActionId || `${e.id}.${e.slot}.apply`)
2930
+ ), Ot = Xe && de.module.actions[Xe.id];
2931
+ if (!Xe || !Ot)
2932
+ return X("PLUGIN_UNAVAILABLE", "扩展动作不可用", "plugin", e.id), h("PLUGIN_UNAVAILABLE", "扩展动作不可用");
2933
+ const pi = xo(e, Xe.id, i.ports);
2934
+ if (!pi)
2935
+ return X("PORT_MISSING", "宿主未提供扩展所需的接口", "port", e.id), h("PORT_MISSING", "宿主未提供扩展所需的接口");
2936
+ (Xe.requiredPorts.length || (zt = Xe.optionalPorts) != null && zt.length) && (fn(D, "requesting", !0), Pe = !0);
2937
+ const Pa = await Ot.execute(n, {
2938
+ scene: on,
2939
+ sceneKey: kn,
2940
+ revision: tn,
2941
+ options: e.options,
2942
+ request: it(e.id, D),
2943
+ ports: pi
2944
+ });
2945
+ if (!Nn())
2946
+ return h("INSERT_CANCELLED", "场景、权限或光标已变化");
2947
+ const Ct = xn(
2948
+ Pa,
2949
+ (Ue) => Array.isArray(Ue)
2950
+ );
2951
+ if (!Ct.ok)
2952
+ return tt(
2953
+ Ct.error,
2954
+ e.id,
2955
+ Xe.requiredPorts.length ? "port" : "plugin"
2956
+ ), h(Ct.error.code, Ct.error.message);
2957
+ const bn = $i(e, Ct.data);
2958
+ if (T && (!bn.ok || bn.kind !== "doc" || !bn.content.length)) {
2959
+ const Ue = bn.ok ? "该扩展未返回可插入的知识区内容" : bn.reason;
2960
+ return X("PLUGIN_OPERATION_REJECTED", Ue, "plugin", e.id), h("PLUGIN_OPERATION_REJECTED", Ue);
2961
+ }
2962
+ if (T && bn.ok && bn.kind === "doc") {
2963
+ const Ue = (ri = (_t = de.module).validateInsert) == null ? void 0 : ri.call(
2964
+ _t,
2965
+ n,
2966
+ r(s.value)
2967
+ );
2968
+ if (Ue && !Ue.ok)
2969
+ return h(Ue.code, Ue.message);
2970
+ const Ma = s.value.knowledge.doc || On(), vi = P ? (ui = J.value) == null ? void 0 : ui.insertBatch(
2971
+ bn.content,
2972
+ P,
2973
+ document.activeElement === En
2974
+ ) : null;
2975
+ return vi ? nn(
2976
+ { ...s.value, knowledge: { ...s.value.knowledge, doc: vi } },
2977
+ "api",
2978
+ e.id
2979
+ ) ? !0 : ((ci = J.value) == null || ci.restoreDoc(Ma), X(
2980
+ "INSERT_FAILED",
2981
+ "扩展内容未能通过场景校验",
2982
+ "plugin",
2983
+ e.id
2984
+ ), h("INSERT_FAILED", "扩展内容未能通过场景校验")) : (X(
2985
+ "INSERT_FAILED",
2986
+ "扩展内容未能插入知识区",
2987
+ "plugin",
2988
+ e.id
2989
+ ), h("INSERT_FAILED", "扩展内容未能插入知识区"));
2990
+ }
2991
+ const xa = q.value;
2992
+ return sa(
2993
+ e,
2994
+ bn,
2995
+ P,
2996
+ !O && He instanceof HTMLElement && (document.activeElement === He || document.activeElement instanceof Element && !!((di = Se.value) != null && di.contains(document.activeElement)) && !!document.activeElement.closest('[role="toolbar"]') || document.activeElement === document.body),
2997
+ on.extensionState[e.id],
2998
+ (fi = n.option) == null ? void 0 : fi.id
2999
+ ), q.value !== xa;
3000
+ } catch (de) {
3001
+ if (Nn()) {
3002
+ const Xe = Pe ? "PORT_FAILED" : "PLUGIN_FAILED", Ot = de instanceof Error ? de.message : "扩展执行失败";
3003
+ return X(
3004
+ Xe,
3005
+ Ot,
3006
+ Pe ? "port" : "plugin",
3007
+ e.id
3008
+ ), h(Xe, Ot);
3009
+ }
3010
+ return h("INSERT_CANCELLED", "场景、权限或光标已变化");
3011
+ } finally {
3012
+ e.id === "reasoningPolish" && en.value && Tn.value === "loading" && (Tn.value = "error"), Pe && ze.has(D) && fn(D, "requesting", !1), D.abort(), et.delete(D), I && Vn.get(I) === D && Vn.delete(I), P == null || P.dispose(), P && qn.delete(P);
3013
+ }
3014
+ }
3015
+ function sa(e, n, l, c, g, T) {
3016
+ var M, h, O, B, U;
3017
+ if (!n.ok) {
3018
+ X("PLUGIN_OPERATION_REJECTED", n.reason, "plugin", e.id);
3019
+ return;
3020
+ }
3021
+ if (n.kind !== "none") {
3022
+ if (!Je(e.id, e.slot)) {
3023
+ X(
3024
+ "PLUGIN_OPERATION_REJECTED",
3025
+ "扩展操作未通过权限校验",
3026
+ "plugin",
3027
+ e.id
3028
+ );
3029
+ return;
3030
+ }
3031
+ if ((n.kind === "state" || n.kind === "compound") && Jn(g ?? null) !== Jn(s.value.extensionState[e.id] ?? null)) {
3032
+ X(
3033
+ "PLUGIN_OPERATION_REJECTED",
3034
+ "扩展状态已变化,本次过期操作未写入",
3035
+ "plugin",
3036
+ e.id
3037
+ );
3038
+ return;
3039
+ }
3040
+ if (n.kind === "compound") {
3041
+ const K = {
3042
+ ...s.value.extensionState,
3043
+ [e.id]: { version: e.dataVersion, data: n.data }
3044
+ }, { document: u } = n;
3045
+ if (u.kind === "replaceDoc") {
3046
+ if (!oi(
3047
+ u.doc,
3048
+ e.id,
3049
+ K,
3050
+ u.question
3051
+ ))
3052
+ return;
3053
+ const D = () => {
3054
+ if (Je(e.id, e.slot)) {
3055
+ const tn = q.value;
3056
+ wt(
3057
+ u.doc,
3058
+ "plugin",
3059
+ e.id,
3060
+ K,
3061
+ u.question
3062
+ ), e.id === "reasoningTemplate" && q.value !== tn && (m.value = null);
3063
+ }
3064
+ };
3065
+ e.id === "reasoningTemplate" && !s.value.question.text.trim() && !nt.value ? D() : e.id === "reasoningTemplate" && T ? ni(T, u.confirmation, D) : ei(u.confirmation, D);
3066
+ return;
3067
+ }
3068
+ if (u.kind === "doc") {
3069
+ const D = l ? (M = J.value) == null ? void 0 : M.insertBatch(u.content, l, c) : null;
3070
+ if (!D) {
3071
+ X(
3072
+ l && l.status() !== "ready" ? "INSERT_TARGET_LOST" : "INSERT_FAILED",
3073
+ "扩展内容未能插入知识区",
3074
+ "plugin",
3075
+ e.id
3076
+ );
3077
+ return;
3078
+ }
3079
+ wt(D, "plugin", e.id, K);
3080
+ return;
3081
+ }
3082
+ const P = u.kind === "batchNodes" ? u.operations : [u], I = (h = J.value) == null ? void 0 : h.previewPluginNodeOperations(P, e.id);
3083
+ if (!I) {
3084
+ X(
3085
+ "PLUGIN_OPERATION_REJECTED",
3086
+ "目标节点不存在、归属不符或版本已变化",
3087
+ "plugin",
3088
+ e.id
3089
+ );
3090
+ return;
3091
+ }
3092
+ wt(I, "plugin", e.id, K);
3093
+ return;
3094
+ }
3095
+ if (n.kind === "replaceDoc") {
3096
+ if (!oi(
3097
+ n.doc,
3098
+ e.id,
3099
+ s.value.extensionState,
3100
+ n.question
3101
+ ))
3102
+ return;
3103
+ const K = () => {
3104
+ if (Je(e.id, e.slot)) {
3105
+ const u = q.value;
3106
+ wt(
3107
+ n.doc,
3108
+ "plugin",
3109
+ e.id,
3110
+ s.value.extensionState,
3111
+ n.question
3112
+ ), e.id === "reasoningTemplate" && q.value !== u && (m.value = null);
3113
+ }
3114
+ };
3115
+ e.id === "reasoningPolish" ? (Qn.value = {
3116
+ sceneKey: i.sceneKey,
3117
+ snapshot: Fe(s.value),
3118
+ proposed: To(n.doc),
3119
+ apply: K
3120
+ }, Tn.value = "ready") : e.id === "reasoningTemplate" && !s.value.question.text.trim() && !nt.value ? K() : e.id === "reasoningTemplate" && T ? ni(T, n.confirmation, K) : ei(n.confirmation, K);
3121
+ return;
3122
+ }
3123
+ if (n.kind === "updateNode" || n.kind === "removeNode" || n.kind === "batchNodes") {
3124
+ const K = n.kind === "batchNodes" ? n.operations : [n];
3125
+ if (["image", "video"].includes(e.id) && K.some((P) => P.kind === "updateNode")) {
3126
+ X(
3127
+ "PLUGIN_OPERATION_REJECTED",
3128
+ "媒体节点更新只能由对应节点的异步生命周期提交",
3129
+ "plugin",
3130
+ e.id
3131
+ );
3132
+ return;
3133
+ }
3134
+ ot = e.id;
3135
+ let u = !1;
3136
+ try {
3137
+ u = ((O = J.value) == null ? void 0 : O.applyPluginNodeOperations(K, e.id)) || !1;
3138
+ } finally {
3139
+ ot = null;
3140
+ }
3141
+ u || X(
3142
+ "PLUGIN_OPERATION_REJECTED",
3143
+ "目标节点不存在、归属不符或版本已变化",
3144
+ "plugin",
3145
+ e.id
3146
+ );
3147
+ return;
3148
+ }
3149
+ if (n.kind === "state")
3150
+ nn(
3151
+ {
3152
+ ...s.value,
3153
+ extensionState: {
3154
+ ...s.value.extensionState,
3155
+ [e.id]: { version: e.dataVersion, data: n.data }
3156
+ }
3157
+ },
3158
+ "plugin",
3159
+ e.id
3160
+ );
3161
+ else {
3162
+ const K = l ? (B = J.value) == null ? void 0 : B.insertBatch(n.content, l, c) : null;
3163
+ if (!K) {
3164
+ const P = !!l && l.status() !== "ready";
3165
+ X(
3166
+ P ? "INSERT_TARGET_LOST" : "INSERT_FAILED",
3167
+ P ? "原始插入位置已失效,扩展内容未写入" : "扩展内容未能插入知识区",
3168
+ "plugin",
3169
+ e.id
3170
+ );
3171
+ return;
3172
+ }
3173
+ nn(
3174
+ { ...s.value, knowledge: { ...s.value.knowledge, doc: K } },
3175
+ "plugin",
3176
+ e.id
3177
+ ) || (U = J.value) == null || U.restoreDoc(s.value.knowledge.doc || On());
3178
+ }
3179
+ }
3180
+ }
3181
+ function ra(e) {
3182
+ if (m.value = null, ve = !1, Ye(), te.value) return;
3183
+ if (i.typeSelectionMode === "add") {
3184
+ p("add-scene", { type: e, scene: ut(e), position: "start" });
3185
+ return;
3186
+ }
3187
+ if (e === s.value.type) return;
3188
+ if (qe.value.uploading > 0 || Xt(s.value)) {
3189
+ X(
3190
+ "UPLOAD_PENDING",
3191
+ "请先完成或移除未成功的媒体后切换知识类型",
3192
+ "validation"
3193
+ );
3194
+ return;
3195
+ }
3196
+ const { scene: n } = al(s.value, e);
3197
+ Y.value = {
3198
+ sceneKey: i.sceneKey,
3199
+ snapshot: Fe(s.value),
3200
+ scene: n
3201
+ }, jo(), Qe(
3202
+ () => {
3203
+ var l, c;
3204
+ return (c = (l = Me.value) == null ? void 0 : l.querySelector(".fkp-type-confirm-cancel")) == null ? void 0 : c.focus();
3205
+ }
3206
+ );
3207
+ }
3208
+ function ua(e) {
3209
+ An(), Ae(), Ce.value = !1, Ke = null, Ve = null, nn(e, "typeSwitch") && Qe(() => {
3210
+ var n, l;
3211
+ return (l = (n = Me.value) == null ? void 0 : n.querySelector("button")) == null ? void 0 : l.focus();
3212
+ });
3213
+ }
3214
+ function vo(e = !1) {
3215
+ Y.value = null, e && Qe(() => {
3216
+ var n, l;
3217
+ return (l = (n = Me.value) == null ? void 0 : n.querySelector("button")) == null ? void 0 : l.focus();
3218
+ });
3219
+ }
3220
+ function ca() {
3221
+ const e = Y.value;
3222
+ Y.value = null, !(!e || e.sceneKey !== i.sceneKey || e.snapshot !== Fe(s.value) || te.value || qe.value.uploading > 0 || Xt(s.value)) && ua(e.scene);
3223
+ }
3224
+ function da(e, n) {
3225
+ if (!e) {
3226
+ m.value === "type" && (m.value = null);
3227
+ return;
3228
+ }
3229
+ te.value || Y.value && n === "hover" || (Y.value = null, re.value = !1, Ye(), ve = n === "hover", m.value = "type");
3230
+ }
3231
+ function ai(e) {
3232
+ const n = Se.value;
3233
+ if (!n || !m.value && !re.value && !Y.value)
3234
+ return;
3235
+ const l = e.composedPath(), c = l.includes(n), g = (M) => c && l.some((h) => h instanceof Element && h.matches(M)), T = c ? l.find(
3236
+ (M) => M instanceof HTMLElement && M.hasAttribute("data-fkp-menu-trigger")
3237
+ ) : void 0;
3238
+ m.value && m.value !== "reasoningTemplate" && !g(".fkp-type-menu, .fkp-option-menu") && (T == null ? void 0 : T.dataset.fkpMenuTrigger) !== m.value && (m.value = null, ve = !1, Ye()), re.value && !g(".fkp-more-menu") && (T == null ? void 0 : T.dataset.fkpMenuTrigger) !== "more" && (re.value = !1), Y.value && !g(".fkp-type-menu, .fkp-type-confirm") && (T == null ? void 0 : T.dataset.fkpMenuTrigger) !== "type" && vo();
3239
+ }
3240
+ function li() {
3241
+ const e = H.value.at(-1);
3242
+ return !e || te.value || qe.value.uploading > 0 || Xt(s.value) || !nn(r(e), "undo") ? !1 : (H.value = H.value.slice(0, -1), An(), Ae(), Ce.value = !1, Ke = null, Ve = null, m.value = null, Qe(() => {
3243
+ var n, l;
3244
+ return (l = (n = Me.value) == null ? void 0 : n.querySelector("button")) == null ? void 0 : l.focus();
3245
+ }), !0);
3246
+ }
3247
+ function ge(e, n, l) {
3248
+ return X(e, n, "validation", l), { ok: !1, code: e, message: n };
3249
+ }
3250
+ function fa(e, n) {
3251
+ return no ? Promise.resolve(null) : J.value ? Promise.resolve(J.value) : new Promise((l) => {
3252
+ let c = !1;
3253
+ const g = Te(
3254
+ [J, () => i.sceneKey, () => s.value.type, Bn],
3255
+ ([O, B, U, K]) => {
3256
+ B !== e || U !== n || K ? h(null) : O && h(O);
3257
+ },
3258
+ { flush: "post" }
3259
+ ), T = setTimeout(() => h(null), 5e3), M = () => h(null);
3260
+ eo.add(M);
3261
+ function h(O) {
3262
+ c || (c = !0, g(), clearTimeout(T), eo.delete(M), l(O));
3263
+ }
3264
+ J.value && h(J.value);
3265
+ });
3266
+ }
3267
+ async function pa(e) {
3268
+ var M;
3269
+ if (te.value) return ge("EDITOR_READONLY", "当前知识不可编辑");
3270
+ if (!e || typeof e != "object" || !("type" in e))
3271
+ return ge("INVALID_INPUT", "插入内容无效");
3272
+ const n = (M = Se.value) == null ? void 0 : M.querySelector(
3273
+ '[aria-label="顾客问法"]'
3274
+ );
3275
+ if (e.type === "text") {
3276
+ if (typeof e.text != "string" || !e.text)
3277
+ return ge("INVALID_INPUT", "插入文字不能为空");
3278
+ if (Ke === "question") {
3279
+ const h = n && document.activeElement === n ? {
3280
+ sceneKey: i.sceneKey,
3281
+ from: n.selectionStart,
3282
+ to: n.selectionEnd,
3283
+ text: s.value.question.text
3284
+ } : Ve;
3285
+ if (!n || !h || h.sceneKey !== i.sceneKey || h.text !== s.value.question.text)
3286
+ return ge("INSERT_TARGET_LOST", "问法光标位置已失效");
3287
+ const O = s.value.question.text, B = O.slice(0, h.from) + e.text + O.slice(h.to);
3288
+ if (Zt(B))
3289
+ return ge("INVALID_INPUT", "问法不能包含方括号或换行");
3290
+ const U = document.activeElement;
3291
+ if (!nn({ ...s.value, question: { text: B } }, "api"))
3292
+ return ge("INSERT_FAILED", "文字未能插入问法区");
3293
+ const K = h.from + e.text.length;
3294
+ Ve = {
3295
+ sceneKey: i.sceneKey,
3296
+ from: K,
3297
+ to: K,
3298
+ text: B
3299
+ };
3300
+ const u = q.value;
3301
+ return await Qe(), n.isConnected && i.sceneKey === h.sceneKey && s.value.question.text === B && document.activeElement === U && (n.focus(), n.setSelectionRange(K, K)), { ok: !0, revision: u };
3302
+ }
3303
+ }
3304
+ const { sceneKey: l } = i, { type: c } = s.value;
3305
+ if (!J.value && !Bn.value && c !== "agent")
3306
+ try {
3307
+ if (await b(), no)
3308
+ return ge("INSERT_CANCELLED", "编辑器已关闭,插入已取消");
3309
+ await fa(l, c);
3310
+ } catch {
3311
+ return ge("INSERT_TARGET_LOST", "知识区尚未就绪");
3312
+ }
3313
+ if (l !== i.sceneKey || c !== s.value.type)
3314
+ return ge("INSERT_CANCELLED", "知识区已变化,插入已取消");
3315
+ if (!J.value) return ge("INSERT_TARGET_LOST", "知识区尚未就绪");
3316
+ const g = J.value;
3317
+ if (!g.getJSON()) {
3318
+ if (!await g.whenReady())
3319
+ return ge("INSERT_TARGET_LOST", "知识区尚未就绪");
3320
+ if (l !== i.sceneKey || c !== s.value.type || J.value !== g)
3321
+ return ge("INSERT_CANCELLED", "知识区已变化,插入已取消");
3322
+ }
3323
+ if (te.value) return ge("EDITOR_READONLY", "当前知识不可编辑");
3324
+ const T = Ke === "knowledge" ? J.value.captureMediaTarget() : J.value.captureEndTarget();
3325
+ if (!T || T.status() !== "ready")
3326
+ return T == null || T.dispose(), ge("INSERT_TARGET_LOST", "知识区光标位置已失效");
3327
+ if (e.type === "capability") {
3328
+ const h = le.value.capabilities.find(
3329
+ (P) => P.id === e.capabilityId && (P.slot === "knowledgeInline" || P.slot === "knowledgeBlock") && P.implementation === "plugin"
3330
+ );
3331
+ if (!h || !po(h.id, h.slot) || h.optionKind === "media")
3332
+ return T.dispose(), ge(
3333
+ "CAPABILITY_REVOKED",
3334
+ "该知识类型当前不支持插入此扩展",
3335
+ e.capabilityId
3336
+ );
3337
+ const { option: O } = e, B = Wt(h.id);
3338
+ if (!!O != (h.optionKind === "selection") || O && (Mn(O) !== null || Object.keys(O).some(
3339
+ (P) => !["id", "label", "token", "params"].includes(P)
3340
+ ) || typeof O.id != "string" || !O.id.trim() || typeof O.label != "string" || !O.label.trim() || O.token !== void 0 && (!(B != null && B.requiresInsertToken) || typeof O.token != "string" || !O.token.trim()) || B != null && B.requiresInsertToken && (!O.token || !O.token.trim()) || O.params !== void 0 && (!(B != null && B.allowsParams) || !O.params || typeof O.params != "object" || Array.isArray(O.params))))
3341
+ return T.dispose(), ge("INVALID_INPUT", "扩展选项数据无效", h.id);
3342
+ const U = O ? JSON.parse(JSON.stringify(O)) : void 0;
3343
+ if (h.id === "tool" && U && ["small_payment", "order_note"].includes(U.id)) {
3344
+ const { params: P } = U;
3345
+ if (!P || Object.values(P).some(
3346
+ (D) => typeof D != "string" && typeof D != "boolean"
3347
+ ))
3348
+ return T.dispose(), ge("TOOL_PARAMS_INVALID", "工具参数无效", h.id);
3349
+ const I = bi(
3350
+ U.id,
3351
+ P,
3352
+ P,
3353
+ s.value.knowledge.doc
3354
+ );
3355
+ if (!I.ok)
3356
+ return T.dispose(), ge(I.code, I.message, h.id);
3357
+ U.params = I.params;
3358
+ }
3359
+ let K = null;
3360
+ return await mn(
3361
+ h,
3362
+ U ? { option: U } : {},
3363
+ T,
3364
+ void 0,
3365
+ void 0,
3366
+ !0,
3367
+ (P) => {
3368
+ K = P;
3369
+ }
3370
+ ) ? { ok: !0, revision: q.value } : K || {
3371
+ ok: !1,
3372
+ code: "PLUGIN_REJECTED",
3373
+ message: "扩展内容未能插入知识区"
3374
+ };
3375
+ }
3376
+ if (e.type === "text" || e.type === "media") {
3377
+ if (e.type === "media") {
3378
+ const { asset: U } = e;
3379
+ if (!U || Object.keys(U).some(
3380
+ (K) => !["kind", "url", "id", "posterUrl"].includes(K)
3381
+ ) || U.kind !== "image" && U.kind !== "video" || !Mt(U.url) || U.posterUrl !== void 0 && !Mt(U.posterUrl) || U.id !== void 0 && (typeof U.id != "string" || !U.id.trim()) || e.name !== void 0 && typeof e.name != "string")
3382
+ return T.dispose(), ge("INVALID_INPUT", "媒体资源数据无效");
3383
+ if (!po(U.kind, "knowledgeBlock"))
3384
+ return T.dispose(), ge(
3385
+ "CAPABILITY_REVOKED",
3386
+ "该知识类型当前不支持插入此媒体",
3387
+ U.kind
3388
+ );
3389
+ }
3390
+ const h = s.value.knowledge.doc || On(), O = e.type === "text" ? J.value.insertBatch(
3391
+ e.text.replace(/\r\n?/gu, `
3392
+ `).split(`
3393
+ `).flatMap((U, K) => [
3394
+ ...K ? [{ type: "hardBreak" }] : [],
3395
+ ...U ? [{ type: "text", text: U }] : []
3396
+ ]),
3397
+ T,
3398
+ !0
3399
+ ) : J.value.insertMedia(e.asset, e.name || "", T, !0);
3400
+ if (T.dispose(), !O) return ge("INSERT_FAILED", "内容未能插入知识区");
3401
+ const B = e.type === "media" ? e.asset.kind : void 0;
3402
+ return nn(
3403
+ { ...s.value, knowledge: { ...s.value.knowledge, doc: O } },
3404
+ "api",
3405
+ B
3406
+ ) ? { ok: !0, revision: q.value } : (J.value.restoreDoc(h), ge("INSERT_FAILED", "内容未能通过场景校验"));
3407
+ }
3408
+ return T.dispose(), ge("INVALID_INPUT", "插入内容类型无效");
3409
+ }
3410
+ function va(e) {
3411
+ e.key.toLowerCase() !== "z" || !(e.ctrlKey || e.metaKey) || e.altKey || e.shiftKey || e.target instanceof Element && e.target.closest('input, textarea, [contenteditable="true"]') || li() && e.preventDefault();
3412
+ }
3413
+ o({ undoTypeSwitch: li, insertContent: pa });
3414
+ function it(e, n) {
3415
+ return {
3416
+ sceneKey: i.sceneKey,
3417
+ capabilityId: e,
3418
+ requestId: `${i.sceneKey}:${++Ui}`,
3419
+ signal: n.signal
3420
+ };
3421
+ }
3422
+ function fn(e, n, l) {
3423
+ l ? ze.set(e, n) : ze.delete(e), qe.value = {
3424
+ requesting: [...ze.values()].filter(
3425
+ (c) => c === "requesting"
3426
+ ).length,
3427
+ uploading: [...ze.values()].filter(
3428
+ (c) => c === "uploading"
3429
+ ).length
3430
+ }, p("busy-change", qe.value);
3431
+ }
3432
+ Te(
3433
+ m,
3434
+ (e, n) => {
3435
+ e !== n && n && n !== "type" && fe();
3436
+ },
3437
+ { flush: "sync" }
3438
+ );
3439
+ function ga(e) {
3440
+ return $e.classify(s.value, e);
3441
+ }
3442
+ function An(e) {
3443
+ Dn(), Tt(), Ut(), cn && clearTimeout(cn), ve = !1, et.forEach((l) => l.abort()), et.clear(), Vn.clear();
3444
+ const n = $e.activeControllers(
3445
+ (e == null ? void 0 : e.active) || /* @__PURE__ */ new Set()
3446
+ );
3447
+ ze.forEach((l, c) => {
3448
+ l === "uploading" && n.has(c) || (c.abort(), ze.delete(c));
3449
+ }), qe.value = {
3450
+ requesting: 0,
3451
+ uploading: [...ze.values()].filter((l) => l === "uploading").length
3452
+ }, p("busy-change", qe.value), $e.clearTarget(), qn.forEach((l) => l.dispose()), qn.clear(), $e.retain(e), m.value = null, me(), $n = null;
3453
+ }
3454
+ function go(e, n = "start", l, c = "scene") {
3455
+ var on, En;
3456
+ if (se.value = null, !(e instanceof HTMLElement) || !Se.value)
3457
+ return z.value = null, !1;
3458
+ const g = le.value.capabilities.find(
3459
+ (He) => He.id === l && He.optionKind === "selection"
3460
+ ), T = (g == null ? void 0 : g.slot) === "questionAction" && g.questionTag ? e.closest(".fkp-action-toggle") : null, M = e.closest(".fkp-more-menu"), h = M ? Se.value.querySelector(".fkp-more-button") || e : T || e, O = Se.value.getBoundingClientRect(), B = ((on = g == null ? void 0 : g.menu) == null ? void 0 : on.width) || (n === "center" ? 320 : 296);
3461
+ if (M && re.value) {
3462
+ const He = M.getBoundingClientRect(), Pe = e.getBoundingClientRect(), Nn = 6, lt = window.innerWidth - He.right - Nn - 8, St = He.left - Nn - 8, Et = Math.max(St, lt);
3463
+ if (Et >= 240) {
3464
+ const st = Math.min(
3465
+ B,
3466
+ Math.max(0, O.width - 32),
3467
+ Et
3468
+ ), Nt = lt >= st || lt >= St ? "right" : "left", zt = Nt === "right" ? He.right + Nn : He.left - Nn - st, _t = Math.max(
3469
+ 8,
3470
+ Math.min(Pe.top - 8, window.innerHeight - 328)
3471
+ );
3472
+ return se.value = Nt, z.value = {
3473
+ left: `${zt - O.left}px`,
3474
+ top: `${_t - O.top}px`,
3475
+ width: `${st}px`,
3476
+ "--fkp-more-arrow-top": `${Math.max(
3477
+ 16,
3478
+ Math.min(Pe.top + Pe.height / 2 - _t, 304)
3479
+ )}px`
3480
+ }, !0;
3481
+ }
3482
+ }
3483
+ const U = h.getBoundingClientRect(), K = M ? "viewport" : c, u = K === "viewport" ? Math.min(
3484
+ B,
3485
+ Math.max(0, O.width - 32),
3486
+ Math.max(0, window.innerWidth - 32)
3487
+ ) : B, P = U.left - O.left + U.width / 2, I = n === "center" ? P - u / 2 : U.left - O.left, D = K === "viewport" ? 8 - O.left : 8, tn = K === "viewport" ? window.innerWidth - O.left - u - 8 : O.width - u - 8, kn = Math.max(
3488
+ D,
3489
+ Math.min(I, Math.max(D, tn))
3490
+ ), at = (En = h.closest(".fkp-scene-toolbar")) == null ? void 0 : En.getBoundingClientRect().bottom;
3491
+ return z.value = {
3492
+ left: `${kn}px`,
3493
+ top: `${Math.max(U.bottom, at ?? U.bottom) - O.top + 4}px`,
3494
+ ...n === "center" ? { "--fkp-agent-arrow-left": `${P - kn}px` } : {},
3495
+ ...g && g.optionSource !== "agents" ? { "--fkp-choice-arrow-left": `${P - kn}px` } : {}
3496
+ }, !1;
3497
+ }
3498
+ function Tt() {
3499
+ vn == null || vn.dispose(), vn = null, Zn = null;
3500
+ }
3501
+ function Ut() {
3502
+ In == null || In.dispose(), In = null;
3503
+ }
3504
+ function Ft(e) {
3505
+ var n;
3506
+ e.slot !== "knowledgeInline" && e.slot !== "knowledgeBlock" || Zn === e.id && vn || (Tt(), vn = re.value && In || ((n = J.value) == null ? void 0 : n.captureMediaTarget()) || null, vn === In && (In = null), Zn = e.id);
3507
+ }
3508
+ function jt(e) {
3509
+ if (Zn !== e) return null;
3510
+ const n = vn;
3511
+ return vn = null, Zn = null, n;
3512
+ }
3513
+ Te(
3514
+ m,
3515
+ (e) => {
3516
+ e !== Zn && Tt();
3517
+ },
3518
+ { flush: "sync" }
3519
+ );
3520
+ async function It(e, n) {
3521
+ var l, c;
3522
+ if (e.id === ((l = G.value) == null ? void 0 : l.kind) && (G.value = null, m.value = null, ve = !1), !!We(e)) {
3523
+ if (m.value !== e.id && co(e, n), e.id === "image" || e.id === "video") {
3524
+ $e.clearTarget();
3525
+ const g = jt(e.id) || ((c = J.value) == null ? void 0 : c.captureMediaTarget()) || null;
3526
+ if (!g) {
3527
+ X(
3528
+ "EDITOR_UNAVAILABLE",
3529
+ "知识区尚未就绪,无法选择媒体",
3530
+ "validation",
3531
+ e.id
3532
+ );
3533
+ return;
3534
+ }
3535
+ $e.selectTarget(g), vt.value = e.id;
3536
+ const T = pn.value;
3537
+ T && (T.accept = Zo.value, T.click());
3538
+ return;
3539
+ }
3540
+ if (e.implementation === "plugin" && !e.optionKind && e.slot !== "sceneAction") {
3541
+ await mn(
3542
+ e,
3543
+ {},
3544
+ jt(e.id) || void 0,
3545
+ n == null ? void 0 : n.currentTarget
3546
+ );
3547
+ return;
3548
+ }
3549
+ if (e.id === "reasoningPolish") {
3550
+ if (en.value || !nt.value) return;
3551
+ Do.value = To(s.value.knowledge.doc), Qn.value = null, Tn.value = "loading", Xn.value = "", to.value = Fe(s.value), en.value = !0, await mn(e, {}, void 0, void 0, () => en.value);
3552
+ return;
3553
+ }
3554
+ if (m.value !== e.id && Ft(e), cn && clearTimeout(cn), e.optionKind === "selection" ? n != null && n.currentTarget ? go(n.currentTarget, "center", e.id) : (m.value !== e.id || !ve) && (z.value = null) : z.value = null, m.value === e.id && ve) {
3555
+ ve = !1;
3556
+ return;
3557
+ }
3558
+ ve = !1, m.value = m.value === e.id ? null : e.id, wn.value = null, me(), m.value && await pe(e.id);
3559
+ }
3560
+ }
3561
+ function At(e, n) {
3562
+ var g;
3563
+ const l = n.currentTarget instanceof Element && !!n.currentTarget.closest(".fkp-more-menu");
3564
+ if (l && ve && m.value !== e.id && (m.value = null, ve = !1), e.id === ((g = G.value) == null ? void 0 : g.kind) && (G.value = null, m.value = null, ve = !1), !bt(e.id) || !We(e) || m.value === e.id)
3565
+ return;
3566
+ co(e, n), Ft(e), cn && clearTimeout(cn);
3567
+ const c = go(n.currentTarget, "center", e.id);
3568
+ (!l || !c) && (re.value = !1), ve = !0, m.value = e.id, me(), pe(e.id);
3569
+ }
3570
+ function ya(e, n) {
3571
+ dn(), e.item ? At(e.item, n) : ve && (Ye(), ve = !1, m.value = null);
3572
+ }
3573
+ function ma(e) {
3574
+ var l;
3575
+ if (te.value || !Je(e.kind, "knowledgeInline"))
3576
+ return;
3577
+ const n = m.value === e.kind && ((l = G.value) == null ? void 0 : l.nodeId) === e.nodeId && G.value.sceneKey === i.sceneKey;
3578
+ Ye(), Tt(), re.value = !1, go(e.anchor, "center", e.kind, "viewport"), ve = !0, !n && (G.value = {
3579
+ nodeId: e.nodeId,
3580
+ nodeVersion: e.nodeVersion,
3581
+ key: e.key,
3582
+ kind: e.kind,
3583
+ sceneKey: i.sceneKey,
3584
+ type: s.value.type
3585
+ }, m.value = e.kind, me(), pe(e.kind));
3586
+ }
3587
+ function Ye() {
3588
+ cn && clearTimeout(cn), cn = void 0;
3589
+ }
3590
+ function Sn() {
3591
+ ve && (Ye(), cn = setTimeout(() => {
3592
+ ve && (m.value === "type" || bt(m.value)) && (m.value = null), ve = !1;
3593
+ }, 180));
3594
+ }
3595
+ Te(
3596
+ () => {
3597
+ var g, T;
3598
+ const e = m.value, n = le.value, l = (g = n.capabilities.find(
3599
+ (M) => M.id === e && M.optionKind === "selection"
3600
+ )) == null ? void 0 : g.optionSource, c = l ? (T = i.ports) == null ? void 0 : T[xi[l]] : void 0;
3601
+ return [e, c, n.fingerprint];
3602
+ },
3603
+ ([e, n, l], [c, g, T]) => {
3604
+ !e || e === "type" || e !== c || n === g && l === T || (me(), Je(e, zn(e)) && pe(e));
3605
+ },
3606
+ { flush: "sync" }
3607
+ );
3608
+ function ka(e) {
3609
+ xe() && pe(e);
3610
+ }
3611
+ async function yo(e, n, l) {
3612
+ var M;
3613
+ if (n.disabled) return;
3614
+ if (!Je(e, zn(e))) {
3615
+ X("CAPABILITY_REVOKED", "此能力当前不可用", "config", e);
3616
+ return;
3617
+ }
3618
+ const c = le.value.capabilities.find(
3619
+ (h) => h.id === e && h.optionKind === "selection"
3620
+ );
3621
+ if ((c == null ? void 0 : c.optionHierarchy) === "tree" && n.hasChildren) {
3622
+ De(n), await pe(e);
3623
+ return;
3624
+ }
3625
+ if (e === "tool") {
3626
+ const h = jt(e);
3627
+ if (!h) {
3628
+ X("INSERT_TARGET_LOST", "工具插入位置已失效", "plugin", "tool");
3629
+ return;
3630
+ }
3631
+ m.value = null, await Ro({
3632
+ key: n.id,
3633
+ label: n.label,
3634
+ params: {},
3635
+ target: h,
3636
+ sceneKey: i.sceneKey,
3637
+ type: s.value.type
3638
+ });
3639
+ return;
3640
+ }
3641
+ if (e === ((M = G.value) == null ? void 0 : M.kind)) {
3642
+ const h = G.value;
3643
+ if (m.value = null, G.value = null, ve = !1, Ye(), h.sceneKey !== i.sceneKey || h.type !== s.value.type) {
3644
+ X("INSERT_TARGET_LOST", "引用标签所属场景已变化", "plugin", e);
3645
+ return;
3646
+ }
3647
+ const O = le.value.capabilities.find(
3648
+ (B) => B.id === e && B.slot === "knowledgeInline"
3649
+ );
3650
+ if (!O) return;
3651
+ await mn(O, {
3652
+ option: n,
3653
+ edit: { nodeId: h.nodeId, nodeVersion: h.nodeVersion }
3654
+ });
3655
+ return;
3656
+ }
3657
+ const g = zn(e) === "knowledgeInline" ? jt(e) : null;
3658
+ e === "reasoningTemplate" ? $t() : m.value = null, ve = !1, Ye();
3659
+ const T = Be;
3660
+ if (Be = null, Fn(e) && zn(e) === "questionAction") {
3661
+ const h = le.value.capabilities.find(
3662
+ (O) => O.id === e && O.slot === "questionAction"
3663
+ );
3664
+ h && await mn(h, { option: n }), await ta(T, e);
3665
+ } else if (e === "agentSelect")
3666
+ nn(
3667
+ {
3668
+ ...s.value,
3669
+ knowledge: {
3670
+ ...s.value.knowledge,
3671
+ agentBody: null,
3672
+ agentRef: { id: n.id, name: n.label }
3673
+ }
3674
+ },
3675
+ "plugin",
3676
+ e
3677
+ );
3678
+ else {
3679
+ const h = le.value.capabilities.find(
3680
+ (O) => O.id === e && (O.slot === "knowledgeInline" || O.slot === "sceneAction")
3681
+ );
3682
+ if (h) {
3683
+ if (h.slot === "knowledgeInline" && !g) {
3684
+ X("INSERT_TARGET_LOST", "原始插入位置已失效", "plugin", e);
3685
+ return;
3686
+ }
3687
+ h.slot !== "knowledgeInline" && (g == null || g.dispose()), await mn(
3688
+ h,
3689
+ { option: n },
3690
+ g || void 0,
3691
+ l == null ? void 0 : l.currentTarget,
3692
+ e === "reasoningTemplate" ? () => m.value === "reasoningTemplate" : void 0
3693
+ );
3694
+ } else g == null || g.dispose();
3695
+ }
3696
+ }
3697
+ Te(
3698
+ () => {
3699
+ var e;
3700
+ try {
3701
+ return (e = i.ports) == null ? void 0 : e.getToolForm;
3702
+ } catch {
3703
+ return;
3704
+ }
3705
+ },
3706
+ (e, n) => Yn.portChanged(e, n),
3707
+ { flush: "sync" }
3708
+ );
3709
+ function ba(e) {
3710
+ if (!Je("tool", "knowledgeInline")) return;
3711
+ const { params: n } = e;
3712
+ if (n === null) {
3713
+ X(
3714
+ "TOOL_PARAMS_UNSUPPORTED",
3715
+ "当前工具标签缺少配置参数,请先迁移旧数据",
3716
+ "validation",
3717
+ "tool"
3718
+ );
3719
+ return;
3720
+ }
3721
+ Ro({
3722
+ ...e,
3723
+ params: n,
3724
+ sceneKey: i.sceneKey,
3725
+ type: s.value.type
3726
+ });
3727
+ }
3728
+ async function ha(e, n) {
3729
+ var O;
3730
+ const l = document.activeElement, c = Rn.value, g = Rt.value;
3731
+ if (!c || !g || !Je("tool", "knowledgeInline"))
3732
+ return;
3733
+ if (c.sceneKey !== i.sceneKey || c.type !== s.value.type) {
3734
+ Dn();
3735
+ return;
3736
+ }
3737
+ if (!await Yn.recheck(c, g)) return;
3738
+ const T = bi(
3739
+ c.key,
3740
+ e,
3741
+ c.params,
3742
+ s.value.knowledge.doc,
3743
+ c.nodeId
3744
+ );
3745
+ if (!T.ok) {
3746
+ X(T.code, T.message, "validation", "tool");
3747
+ return;
3748
+ }
3749
+ e = T.params;
3750
+ const M = le.value.capabilities.find(
3751
+ (B) => B.id === "tool" && B.slot === "knowledgeInline"
3752
+ );
3753
+ if (!M) return;
3754
+ if (c.nodeId !== void 0 && c.nodeVersion !== void 0) {
3755
+ const B = document.activeElement, U = B === document.body || B instanceof Element && !!B.closest(".fkp-tool-modal") && (B === l || B === n);
3756
+ if (await mn(
3757
+ M,
3758
+ {
3759
+ option: { id: c.key, label: c.label, params: e },
3760
+ edit: { nodeId: c.nodeId, nodeVersion: c.nodeVersion }
3761
+ },
3762
+ void 0,
3763
+ n,
3764
+ () => Rn.value === c && Rt.value === g
3765
+ ), Rn.value !== c) return;
3766
+ Dn(), await Qe();
3767
+ const K = document.activeElement;
3768
+ U && c.sceneKey === i.sceneKey && c.type === s.value.type && (K === document.body || K === l || K === n) && ((O = J.value) == null || O.focus());
3769
+ return;
3770
+ }
3771
+ const { target: h } = c;
3772
+ if (!h || h.status() !== "ready") {
3773
+ X("INSERT_TARGET_LOST", "工具插入位置已失效", "plugin", "tool"), Dn();
3774
+ return;
3775
+ }
3776
+ Yn.releaseForInsert(), await mn(
3777
+ M,
3778
+ { option: { id: c.key, label: c.label, params: e } },
3779
+ h,
3780
+ n
3781
+ );
3782
+ }
3783
+ function wa() {
3784
+ const e = $n;
3785
+ e && ($n = null, e.abort(), ze.has(e) && fn(e, "requesting", !1));
3786
+ }
3787
+ async function Ta(e) {
3788
+ const n = mo.value;
3789
+ if (!n) return;
3790
+ const l = new AbortController();
3791
+ $n = l;
3792
+ const { sceneKey: c } = i, g = () => !l.signal.aborted && $n === l && c === i.sceneKey && Un.value === e;
3793
+ Q.value = "loading", fn(l, "requesting", !0);
3794
+ try {
3795
+ const T = await n({ agentId: e }, it("agentSelect", l));
3796
+ if (!g()) return;
3797
+ const M = xn(
3798
+ T,
3799
+ (h) => Sl(e, h)
3800
+ );
3801
+ M.ok ? (E.value = M.data.prompt, $.value = M.data.preview || [], Q.value = "ready") : (Q.value = "error", tt(M.error, "agentSelect"));
3802
+ } catch (T) {
3803
+ g() && (Q.value = "error", X(
3804
+ "PORT_FAILED",
3805
+ T instanceof Error ? T.message : "读取 Agent 失败",
3806
+ "port",
3807
+ "agentSelect"
3808
+ ));
3809
+ } finally {
3810
+ $n === l && ($n = null), ze.has(l) && fn(l, "requesting", !1);
3811
+ }
3812
+ }
3813
+ const mo = ie(() => {
3814
+ var n;
3815
+ const e = le.value.capabilities.find(
3816
+ (l) => l.id === "agentSelect" && l.slot === "sceneAction"
3817
+ );
3818
+ return e ? (n = cl(e, i.ports)) == null ? void 0 : n.getAgentPrompt : void 0;
3819
+ }), si = ie(() => Ge.value ? Un.value ? mo.value ? Q.value === "error" ? "Agent 提示词读取失败" : Q.value === "ready" ? E.value || "Agent 提示词为空" : "正在读取 Agent 提示词…" : "" : Ge.value.invalid ? "Agent 已失效" : "Agent 尚未匹配 ID" : "选择 Agent 后,将在此处显示 Agent 提示词内容"), Ia = (e) => ({
3820
+ todo: "rte-todo",
3821
+ cdp_tag: "rte-tag",
3822
+ separator: "sep",
3823
+ original_repeat: "quote",
3824
+ size_chart: "size-guide",
3825
+ table_knowledge: "table-knowledge",
3826
+ biz_attribute: "prte-reference",
3827
+ variable: "hashtag",
3828
+ custom_agent: "rte-agent",
3829
+ reasoning: "thinking",
3830
+ memory_trigger: "memory",
3831
+ no_send_follow_order: "non-follow-up",
3832
+ small_payment: "rte-tool",
3833
+ order_remark: "pen",
3834
+ external_method: "rte-tool",
3835
+ ticket: "AI-ticket",
3836
+ tool: "rte-tool"
3837
+ })[e] || "rte-tag";
3838
+ Te(
3839
+ () => [
3840
+ i.sceneKey,
3841
+ Un.value,
3842
+ mo.value,
3843
+ Ge.value
3844
+ ],
3845
+ ([, e]) => {
3846
+ wa(), Ae(), e && !s.value.knowledge.agentBody && Ta(e);
3847
+ },
3848
+ { immediate: !0 }
3849
+ );
3850
+ async function Aa(e) {
3851
+ const n = e.target, l = Array.from(n.files || []);
3852
+ n.value = "";
3853
+ const c = $e.takeTarget(), g = document.activeElement, T = g === document.body || g === n || g instanceof Element && !!g.closest(
3854
+ '[data-fkp-menu-trigger="image"], [data-fkp-menu-trigger="video"]'
3855
+ );
3856
+ c && await $e.enqueue(
3857
+ l,
3858
+ c,
3859
+ vt.value,
3860
+ T
3861
+ );
3862
+ }
3863
+ function Sa(e) {
3864
+ var c, g, T;
3865
+ const n = Array.from(((c = e.clipboardData) == null ? void 0 : c.files) || []);
3866
+ if (!n.length || (e.preventDefault(), e.stopPropagation(), te.value)) return;
3867
+ const l = ((g = J.value) == null ? void 0 : g.pasteClipboardContent(e)) || ((T = J.value) == null ? void 0 : T.captureMediaTarget());
3868
+ if (!l) {
3869
+ X(
3870
+ "EDITOR_UNAVAILABLE",
3871
+ "知识区尚未就绪,无法粘贴媒体",
3872
+ "validation"
3873
+ );
3874
+ return;
3875
+ }
3876
+ $e.enqueue(n, l);
3877
+ }
3878
+ function Ea(e) {
3879
+ var n;
3880
+ Array.from(((n = e.dataTransfer) == null ? void 0 : n.types) || []).includes("Files") && (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = te.value ? "none" : "copy"));
3881
+ }
3882
+ function Na(e) {
3883
+ var c, g, T;
3884
+ if (Array.from(((c = e.dataTransfer) == null ? void 0 : c.items) || []).some(
3885
+ (M) => {
3886
+ var h, O;
3887
+ return (O = (h = M.webkitGetAsEntry) == null ? void 0 : h.call(M)) == null ? void 0 : O.isDirectory;
3888
+ }
3889
+ )) {
3890
+ e.preventDefault(), ki.error({
3891
+ content: "不支持上传文件夹,请选择图片或视频文件",
3892
+ position: "top"
3893
+ });
3894
+ return;
3895
+ }
3896
+ const n = Array.from(((g = e.dataTransfer) == null ? void 0 : g.files) || []);
3897
+ if (!n.length || (e.preventDefault(), te.value)) return;
3898
+ const l = (T = J.value) == null ? void 0 : T.captureMediaTargetAt(e.clientX, e.clientY);
3899
+ if (!l) {
3900
+ X("INSERT_TARGET_LOST", "拖放位置无效,媒体未写入", "validation");
3901
+ return;
3902
+ }
3903
+ $e.enqueue(n, l);
3904
+ }
3905
+ const _a = $e.retry;
3906
+ async function Oa() {
3907
+ var T;
3908
+ const e = Un.value, n = (T = dl(
3909
+ "agentSelect.openConfig",
3910
+ i.ports
3911
+ )) == null ? void 0 : T.openAgentConfig;
3912
+ if (!e || !n) return;
3913
+ const l = new AbortController(), { sceneKey: c } = i, g = () => !l.signal.aborted && c === i.sceneKey && Un.value === e;
3914
+ fn(l, "requesting", !0);
3915
+ try {
3916
+ const M = await n(
3917
+ { agentId: e, target: "_blank" },
3918
+ it("agentSelect", l)
3919
+ );
3920
+ if (!g()) return;
3921
+ const h = xn(
3922
+ M,
3923
+ (O) => O === void 0
3924
+ );
3925
+ h.ok || tt(h.error, "agentSelect");
3926
+ } catch (M) {
3927
+ g() && X(
3928
+ "PORT_FAILED",
3929
+ M instanceof Error ? M.message : "打开 Agent 失败",
3930
+ "port",
3931
+ "agentSelect"
3932
+ );
3933
+ } finally {
3934
+ fn(l, "requesting", !1);
3935
+ }
3936
+ }
3937
+ function Ca() {
3938
+ if (te.value) return;
3939
+ const { sceneKey: e } = i, n = ut(s.value.type);
3940
+ An(), Ae(), re.value = !1, G.value = null, wn.value = null, gn = null, Be = null, yn = null, nn(
3941
+ {
3942
+ ...s.value,
3943
+ question: n.question,
3944
+ knowledge: n.knowledge,
3945
+ extensionState: n.extensionState
3946
+ },
3947
+ "user"
3948
+ ) && Qe(() => {
3949
+ var g;
3950
+ if (e !== i.sceneKey || te.value) return;
3951
+ const c = (g = Se.value) == null ? void 0 : g.querySelector(
3952
+ '[aria-label="顾客问法"]'
3953
+ );
3954
+ !c || c.disabled || (c.focus(), c.setSelectionRange(0, 0));
3955
+ });
3956
+ }
3957
+ return Da(() => {
3958
+ no = !0, eo.forEach((e) => e()), dn(), un(), Vt == null || Vt(), mt == null || mt.disconnect(), window.removeEventListener("resize", Fo), document.removeEventListener("click", ai), gt.forEach((e) => e.close()), gt.clear(), An(), yt && clearTimeout(yt);
3959
+ }), (e, n) => {
3960
+ var l, c, g, T, M, h, O, B, U, K;
3961
+ return A(), L("section", {
3962
+ ref_key: "sceneRoot",
3963
+ ref: Se,
3964
+ class: we(["fkp-rich-text", [
3965
+ `fkp-type-${s.value.type}`,
3966
+ {
3967
+ "is-readonly": te.value,
3968
+ "has-open-menu": !!m.value || re.value || !!Y.value
3969
+ }
3970
+ ]]),
3971
+ onKeydown: [
3972
+ n[21] || (n[21] = ko((u) => {
3973
+ m.value = null, re.value = !1, Y.value = null;
3974
+ }, ["esc"])),
3975
+ va
3976
+ ],
3977
+ onFocusout: la
3978
+ }, [
3979
+ R("div", {
3980
+ ref_key: "toolbar",
3981
+ ref: Hn,
3982
+ class: "fkp-scene-toolbar",
3983
+ role: "toolbar",
3984
+ "aria-label": "知识编辑工具栏"
3985
+ }, [
3986
+ R("div", {
3987
+ ref_key: "typeWrap",
3988
+ ref: Me,
3989
+ class: "fkp-type-wrap fkp-type-host",
3990
+ onMouseenter: Ye,
3991
+ onMouseleave: Sn
3992
+ }, [
3993
+ F(el, {
3994
+ "current-type": s.value.type,
3995
+ mode: e.typeSelectionMode,
3996
+ trigger: "toolbar",
3997
+ disabled: te.value,
3998
+ open: m.value === "type",
3999
+ "aria-keyshortcuts": H.value.length ? "Control+Z Meta+Z" : void 0,
4000
+ "onUpdate:open": da,
4001
+ onSelect: ra
4002
+ }, {
4003
+ default: j(() => [
4004
+ Y.value ? (A(), L("div", {
4005
+ key: 0,
4006
+ class: "fkp-type-confirm",
4007
+ role: "alertdialog",
4008
+ "aria-label": "确认切换知识类型",
4009
+ style: yi({
4010
+ left: `${ne.value}px`,
4011
+ "--fkp-type-confirm-arrow-left": `${48 - ne.value}px`
4012
+ }),
4013
+ onKeydown: n[1] || (n[1] = ko(Gt((u) => vo(!0), ["stop", "prevent"]), ["esc"]))
4014
+ }, [
4015
+ n[24] || (n[24] = R("span", {
4016
+ class: "fkp-type-confirm-arrow",
4017
+ "aria-hidden": "true"
4018
+ }, null, -1)),
4019
+ R("div", Jl, [
4020
+ F(w(ja), { "aria-hidden": "true" }),
4021
+ Y.value.scene.type === "agent" ? (A(), L("span", Hl, "切换后原知识内容和标签将保留,供切回其他知识类型时恢复。确认切换吗?")) : (A(), L("span", Wl, "切换后将移除不适配标签,其余知识内容不变,是否确认切换?"))
4022
+ ]),
4023
+ R("div", Yl, [
4024
+ F(w(ue), {
4025
+ class: "fkp-type-confirm-cancel",
4026
+ onClick: n[0] || (n[0] = (u) => vo(!0))
4027
+ }, {
4028
+ default: j(() => n[22] || (n[22] = [
4029
+ ye("取消")
4030
+ ])),
4031
+ _: 1
4032
+ }),
4033
+ F(w(ue), {
4034
+ type: "primary",
4035
+ onClick: ca
4036
+ }, {
4037
+ default: j(() => n[23] || (n[23] = [
4038
+ ye("确认")
4039
+ ])),
4040
+ _: 1
4041
+ })
4042
+ ])
4043
+ ], 36)) : oe("", !0)
4044
+ ]),
4045
+ _: 1
4046
+ }, 8, ["current-type", "mode", "disabled", "open", "aria-keyshortcuts"])
4047
+ ], 544),
4048
+ n[27] || (n[27] = R("span", { class: "fkp-toolbar-divider" }, null, -1)),
4049
+ s.value.type === "agent" ? (A(), ce(w(rt), {
4050
+ key: 0,
4051
+ trigger: "hover",
4052
+ position: "bottom",
4053
+ content: "选择 Agent",
4054
+ "popup-visible": !1
4055
+ }, {
4056
+ default: j(() => {
4057
+ var u, P;
4058
+ return [
4059
+ F(w(ue), {
4060
+ class: we(["fkp-agent-picker", { "is-invalid": (u = Ge.value) == null ? void 0 : u.invalid }]),
4061
+ type: "text",
4062
+ "data-fkp-menu-trigger": "agentSelect",
4063
+ disabled: te.value || !((P = Kt.value.find((I) => I.id === "agentSelect")) != null && P.canInsert),
4064
+ onMouseenter: n[2] || (n[2] = (I) => At(
4065
+ Kt.value.find((D) => D.id === "agentSelect"),
4066
+ I
4067
+ )),
4068
+ onMouseleave: Sn,
4069
+ onClick: n[3] || (n[3] = (I) => It(
4070
+ Kt.value.find((D) => D.id === "agentSelect"),
4071
+ I
4072
+ ))
4073
+ }, {
4074
+ default: j(() => [
4075
+ ye(ae(Jo.value || "选择 Agent") + " ", 1),
4076
+ F(w(Ne), {
4077
+ name: "arrow-down",
4078
+ size: 12
4079
+ })
4080
+ ]),
4081
+ _: 1
4082
+ }, 8, ["class", "disabled"])
4083
+ ];
4084
+ }),
4085
+ _: 1
4086
+ })) : oe("", !0),
4087
+ R("div", {
4088
+ ref_key: "toolbarLeft",
4089
+ ref: Wn,
4090
+ class: "fkp-toolbar-groups"
4091
+ }, [
4092
+ (A(!0), L(Ee, null, an(Bo.value, (u, P) => (A(), L(Ee, {
4093
+ key: u.key
4094
+ }, [
4095
+ u.actions.some((I) => I.index < sn.value) ? (A(), L(Ee, { key: 0 }, [
4096
+ P > 0 || s.value.type === "agent" ? (A(), L("span", Xl)) : oe("", !0),
4097
+ R("div", Ql, [
4098
+ (A(!0), L(Ee, null, an(u.actions, (I) => (A(), L(Ee, {
4099
+ key: I.key
4100
+ }, [
4101
+ I.index < sn.value && I.kind === "question" && I.item ? (A(), ce(w(rt), {
4102
+ key: 0,
4103
+ trigger: "hover",
4104
+ position: "bottom",
4105
+ content: N(I.item.id) ? void 0 : `${I.item.label}开关`,
4106
+ "content-class": N(I.item.id) ? "fkp-capability-help-popover" : void 0,
4107
+ "popup-visible": Fn(I.item.id) ? !1 : void 0
4108
+ }, bo({
4109
+ default: j(() => [
4110
+ R("div", {
4111
+ class: we(["fkp-action-toggle", {
4112
+ "is-disabled": !We(I.item),
4113
+ "is-todo-active": I.item.id === "todo" && jn("todo"),
4114
+ "is-question-active": I.item.id !== "todo" && jn(I.item.id)
4115
+ }]),
4116
+ "data-fkp-menu-trigger": Fn(I.item.id) ? I.item.id : void 0,
4117
+ onMouseenter: (D) => At(I.item, D),
4118
+ onPointerdownCapture: (D) => uo(I.item, D),
4119
+ onMouseleave: Sn
4120
+ }, [
4121
+ F(w(ue), {
4122
+ class: "fkp-action-label",
4123
+ type: "text",
4124
+ disabled: !We(I.item),
4125
+ "aria-label": I.item.label,
4126
+ "aria-pressed": jn(I.item.id),
4127
+ onClick: (D) => kt(I, D)
4128
+ }, {
4129
+ default: j(() => [
4130
+ F(w(Ne), {
4131
+ name: I.item.icon,
4132
+ size: 16
4133
+ }, null, 8, ["name"]),
4134
+ ye(ae(I.item.label), 1)
4135
+ ]),
4136
+ _: 2
4137
+ }, 1032, ["disabled", "aria-label", "aria-pressed", "onClick"]),
4138
+ F(w(mi), {
4139
+ class: "fkp-action-switch",
4140
+ size: "small",
4141
+ "model-value": jn(I.item.id),
4142
+ disabled: !We(I.item),
4143
+ "aria-label": `${I.item.label}开关`,
4144
+ onMousedown: n[4] || (n[4] = Gt(() => {
4145
+ }, ["prevent"])),
4146
+ onChange: (D) => fo(I.item)
4147
+ }, null, 8, ["model-value", "disabled", "aria-label", "onChange"])
4148
+ ], 42, Zl)
4149
+ ]),
4150
+ _: 2
4151
+ }, [
4152
+ N(I.item.id) ? {
4153
+ name: "content",
4154
+ fn: j(() => [
4155
+ F(Eo, {
4156
+ "capability-id": I.item.id,
4157
+ onHelp: (D) => _(I.item.id)
4158
+ }, null, 8, ["capability-id", "onHelp"])
4159
+ ]),
4160
+ key: "0"
4161
+ } : void 0
4162
+ ]), 1032, ["content", "content-class", "popup-visible"])) : I.index < sn.value && I.kind === "knowledge" && I.item ? (A(), ce(w(rt), {
4163
+ key: 1,
4164
+ trigger: "hover",
4165
+ position: "bottom",
4166
+ content: N(I.item.id) ? void 0 : `${I.item.label}:在知识区光标处插入`,
4167
+ "content-class": N(I.item.id) ? "fkp-capability-help-popover" : void 0,
4168
+ "popup-visible": bt(I.item.id) || m.value === I.item.id ? !1 : void 0
4169
+ }, bo({
4170
+ default: j(() => [
4171
+ F(w(ue), {
4172
+ class: "fkp-tool-button",
4173
+ type: "text",
4174
+ "data-fkp-menu-trigger": I.item.id,
4175
+ disabled: !We(I.item),
4176
+ "aria-label": I.item.label,
4177
+ onMouseenter: (D) => At(I.item, D),
4178
+ onPointerdownCapture: (D) => zo(I.item),
4179
+ onMouseleave: Sn,
4180
+ onClick: (D) => kt(I, D)
4181
+ }, {
4182
+ default: j(() => [
4183
+ F(w(Ne), {
4184
+ name: I.item.icon,
4185
+ size: 16
4186
+ }, null, 8, ["name"]),
4187
+ I.showLabel ? (A(), L("span", es, ae(I.item.label), 1)) : oe("", !0)
4188
+ ]),
4189
+ _: 2
4190
+ }, 1032, ["data-fkp-menu-trigger", "disabled", "aria-label", "onMouseenter", "onPointerdownCapture", "onClick"])
4191
+ ]),
4192
+ _: 2
4193
+ }, [
4194
+ N(I.item.id) ? {
4195
+ name: "content",
4196
+ fn: j(() => [
4197
+ F(Eo, {
4198
+ "capability-id": I.item.id,
4199
+ onHelp: (D) => _(I.item.id)
4200
+ }, null, 8, ["capability-id", "onHelp"])
4201
+ ]),
4202
+ key: "0"
4203
+ } : void 0
4204
+ ]), 1032, ["content", "content-class", "popup-visible"])) : oe("", !0)
4205
+ ], 64))), 128))
4206
+ ])
4207
+ ], 64)) : oe("", !0)
4208
+ ], 64))), 128)),
4209
+ so.value.length ? (A(), L("div", {
4210
+ key: 0,
4211
+ class: we(["fkp-more-wrap", { "is-open": re.value }]),
4212
+ onMouseenter: Xi,
4213
+ onMouseleave: Qi
4214
+ }, [
4215
+ F(w(ue), {
4216
+ class: "fkp-more-button",
4217
+ type: "text",
4218
+ "data-fkp-menu-trigger": "more",
4219
+ "aria-label": "更多操作",
4220
+ "aria-expanded": re.value,
4221
+ onMouseenter: Zi,
4222
+ onPointerdownCapture: ti,
4223
+ onClick: ea
4224
+ }, {
4225
+ default: j(() => [
4226
+ F(w(Ne), {
4227
+ name: "more",
4228
+ size: 16
4229
+ })
4230
+ ]),
4231
+ _: 1
4232
+ }, 8, ["aria-expanded"]),
4233
+ re.value ? (A(), L("div", {
4234
+ key: 0,
4235
+ class: "fkp-menu fkp-more-menu",
4236
+ onMouseenter: dn
4237
+ }, [
4238
+ (A(!0), L(Ee, null, an(so.value, (u) => {
4239
+ var P, I, D, tn, kn, at;
4240
+ return A(), ce(w(rt), {
4241
+ key: u.key,
4242
+ class: "fkp-more-popover",
4243
+ trigger: "hover",
4244
+ position: "right",
4245
+ content: N((P = u.item) == null ? void 0 : P.id) ? void 0 : u.kind === "knowledge" ? `${(I = u.item) == null ? void 0 : I.label}:在知识区光标处插入` : u.kind === "question" ? `${(D = u.item) == null ? void 0 : D.label}开关` : ((tn = u.item) == null ? void 0 : tn.label) || "前往编辑 Agent",
4246
+ "content-class": N((kn = u.item) == null ? void 0 : kn.id) ? "fkp-capability-help-popover fkp-capability-help-popover--more" : void 0,
4247
+ "popup-visible": u.item && bt(u.item.id) ? !1 : void 0,
4248
+ onPopupVisibleChange: (on) => !(u.item && bt(u.item.id)) && na(u.key, on)
4249
+ }, bo({
4250
+ default: j(() => {
4251
+ var on, En, He;
4252
+ return [
4253
+ R("div", {
4254
+ class: we(["fkp-more-row", {
4255
+ "fkp-more-row--question": u.kind === "question",
4256
+ "is-disabled": u.item && !We(u.item)
4257
+ }]),
4258
+ "data-fkp-menu-trigger": (on = u.item) == null ? void 0 : on.id,
4259
+ onMouseenter: (Pe) => ya(u, Pe),
4260
+ onPointerdownCapture: (Pe) => ji(u, Pe),
4261
+ onMouseleave: Sn
4262
+ }, [
4263
+ F(w(ue), {
4264
+ type: "text",
4265
+ class: we({
4266
+ "fkp-polish-action": ((En = u.item) == null ? void 0 : En.id) === "reasoningPolish"
4267
+ }),
4268
+ disabled: u.kind === "agentOpen" ? !Un.value || !((He = e.ports) != null && He.openAgentConfig) : !u.item || !We(u.item),
4269
+ onClick: (Pe) => kt(u, Pe)
4270
+ }, {
4271
+ default: j(() => {
4272
+ var Pe;
4273
+ return [
4274
+ F(w(Ne), {
4275
+ name: u.item ? u.item.icon : "open",
4276
+ size: 16
4277
+ }, null, 8, ["name"]),
4278
+ ye(ae(((Pe = u.item) == null ? void 0 : Pe.label) || "前往编辑 Agent"), 1)
4279
+ ];
4280
+ }),
4281
+ _: 2
4282
+ }, 1032, ["class", "disabled", "onClick"]),
4283
+ u.kind === "question" && u.item ? (A(), ce(w(mi), {
4284
+ key: 0,
4285
+ class: "fkp-action-switch",
4286
+ size: "small",
4287
+ "model-value": jn(u.item.id),
4288
+ disabled: !We(u.item),
4289
+ "aria-label": `${u.item.label}开关`,
4290
+ onMousedown: n[5] || (n[5] = Gt(() => {
4291
+ }, ["prevent"])),
4292
+ onChange: (Pe) => fo(u.item)
4293
+ }, null, 8, ["model-value", "disabled", "aria-label", "onChange"])) : oe("", !0)
4294
+ ], 42, ns)
4295
+ ];
4296
+ }),
4297
+ _: 2
4298
+ }, [
4299
+ N((at = u.item) == null ? void 0 : at.id) ? {
4300
+ name: "content",
4301
+ fn: j(() => [
4302
+ F(Eo, {
4303
+ "capability-id": u.item.id,
4304
+ onHelp: (on) => _(u.item.id)
4305
+ }, null, 8, ["capability-id", "onHelp"])
4306
+ ]),
4307
+ key: "0"
4308
+ } : void 0
4309
+ ]), 1032, ["content", "content-class", "popup-visible", "onPopupVisibleChange"]);
4310
+ }), 128))
4311
+ ], 32)) : oe("", !0)
4312
+ ], 34)) : oe("", !0)
4313
+ ], 512),
4314
+ ao.value.length ? (A(), L("div", ts, [
4315
+ n[26] || (n[26] = R("span", { class: "fkp-toolbar-divider" }, null, -1)),
4316
+ (A(!0), L(Ee, null, an(ao.value, (u) => (A(), L(Ee, {
4317
+ key: u.key
4318
+ }, [
4319
+ u.kind === "scene" && u.item ? (A(), ce(w(rt), {
4320
+ key: 0,
4321
+ trigger: "hover",
4322
+ position: "bottom",
4323
+ content: u.item.label
4324
+ }, {
4325
+ default: j(() => [
4326
+ F(w(ue), {
4327
+ class: we(["fkp-scene-action", {
4328
+ "fkp-polish-action": u.item.id === "reasoningPolish"
4329
+ }]),
4330
+ type: "text",
4331
+ "data-fkp-menu-trigger": u.item.id === "reasoningTemplate" ? "reasoningTemplate" : void 0,
4332
+ disabled: !We(u.item),
4333
+ onClick: (P) => kt(u)
4334
+ }, {
4335
+ default: j(() => [
4336
+ F(w(Ne), {
4337
+ name: u.item.icon,
4338
+ size: 12
4339
+ }, null, 8, ["name"]),
4340
+ ye(ae(u.item.label), 1)
4341
+ ]),
4342
+ _: 2
4343
+ }, 1032, ["class", "data-fkp-menu-trigger", "disabled", "onClick"])
4344
+ ]),
4345
+ _: 2
4346
+ }, 1032, ["content"])) : u.kind === "agentOpen" ? (A(), ce(w(rt), {
4347
+ key: 1,
4348
+ trigger: "hover",
4349
+ position: "bottom",
4350
+ content: "前往编辑 Agent"
4351
+ }, {
4352
+ default: j(() => {
4353
+ var P;
4354
+ return [
4355
+ F(w(ue), {
4356
+ class: "fkp-open-agent",
4357
+ type: "text",
4358
+ disabled: !Un.value || !((P = e.ports) != null && P.openAgentConfig),
4359
+ onClick: (I) => kt(u)
4360
+ }, {
4361
+ default: j(() => [
4362
+ F(w(Ne), {
4363
+ name: "rte-open",
4364
+ size: 12
4365
+ }),
4366
+ n[25] || (n[25] = ye("前往编辑 Agent "))
4367
+ ]),
4368
+ _: 2
4369
+ }, 1032, ["disabled", "onClick"])
4370
+ ];
4371
+ }),
4372
+ _: 2
4373
+ }, 1024)) : oe("", !0)
4374
+ ], 64))), 128))
4375
+ ])) : oe("", !0)
4376
+ ], 512),
4377
+ m.value && m.value !== "type" && m.value !== "reasoningTemplate" ? (A(), L("div", {
4378
+ key: 0,
4379
+ class: we(["fkp-menu fkp-option-menu", [
4380
+ (l = Re.value) == null ? void 0 : l.classes,
4381
+ {
4382
+ "is-choice-menu": Yo.value,
4383
+ "is-more-submenu": !!se.value,
4384
+ "is-more-submenu--left": se.value === "left",
4385
+ "is-more-submenu--right": se.value === "right"
4386
+ }
4387
+ ]]),
4388
+ style: yi(z.value || void 0),
4389
+ onMouseenter: n[15] || (n[15] = (u) => {
4390
+ Ye(), dn();
4391
+ }),
4392
+ onMouseleave: n[16] || (n[16] = (u) => {
4393
+ Sn(), Bt();
4394
+ })
4395
+ }, [
4396
+ m.value === "agentSelect" ? (A(), L("span", os)) : oe("", !0),
4397
+ R("div", is, [
4398
+ (c = Re.value) != null && c.badge ? (A(), L("span", {
4399
+ key: 0,
4400
+ class: we(Re.value.headingClass)
4401
+ }, [
4402
+ R("strong", null, ae(Qo.value), 1),
4403
+ R("span", {
4404
+ class: we(Re.value.badge.className)
4405
+ }, ae(Re.value.badge.text), 3),
4406
+ R("span", {
4407
+ class: we(Re.value.badge.dotClass),
4408
+ "aria-hidden": "true"
4409
+ }, null, 2)
4410
+ ], 2)) : (A(), L("strong", as, ae(Qo.value), 1)),
4411
+ Re.value ? (A(), ce(w(ue), {
4412
+ key: 2,
4413
+ class: we(Re.value.helpClass),
4414
+ type: "text",
4415
+ onClick: n[6] || (n[6] = (u) => _(m.value))
4416
+ }, {
4417
+ default: j(() => [
4418
+ F(w(Ne), {
4419
+ name: "rte-help",
4420
+ size: 14
4421
+ }),
4422
+ n[28] || (n[28] = ye("我该怎么配? "))
4423
+ ]),
4424
+ _: 1
4425
+ }, 8, ["class"])) : (A(), ce(w(ue), {
4426
+ key: 3,
4427
+ type: "text",
4428
+ "aria-label": "关闭菜单",
4429
+ onClick: n[7] || (n[7] = (u) => m.value = null)
4430
+ }, {
4431
+ default: j(() => [
4432
+ F(w(za), { size: 15 })
4433
+ ]),
4434
+ _: 1
4435
+ }))
4436
+ ]),
4437
+ (T = (g = Re.value) == null ? void 0 : g.guidance) != null && T.length ? (A(), ce(Ka(((h = (M = Re.value) == null ? void 0 : M.guidance) == null ? void 0 : h.length) === 1 ? "p" : "div"), {
4438
+ key: 1,
4439
+ class: we(Re.value.guidanceClass)
4440
+ }, {
4441
+ default: j(() => [
4442
+ Re.value.guidance.length === 1 ? (A(), L(Ee, { key: 0 }, [
4443
+ ye(ae(Re.value.guidance[0]), 1)
4444
+ ], 64)) : (A(!0), L(Ee, { key: 1 }, an(Re.value.guidance, (u) => (A(), L("p", { key: u }, ae(u), 1))), 128))
4445
+ ]),
4446
+ _: 1
4447
+ }, 8, ["class"])) : oe("", !0),
4448
+ w(Z).length && m.value !== "variable" ? (A(), L("div", ls, [
4449
+ F(w(ue), {
4450
+ type: "text",
4451
+ onClick: n[8] || (n[8] = (u) => ka(m.value))
4452
+ }, {
4453
+ default: j(() => n[29] || (n[29] = [
4454
+ ye("返回")
4455
+ ])),
4456
+ _: 1
4457
+ }),
4458
+ R("span", null, ae(w(Z).map((u) => u.label).join(" / ")), 1)
4459
+ ])) : oe("", !0),
4460
+ R("div", {
4461
+ class: we(["fkp-menu-search", {
4462
+ "is-todo-search": Yo.value,
4463
+ "is-agent-search": ((O = ht.value) == null ? void 0 : O.optionSource) === "agents"
4464
+ }])
4465
+ }, [
4466
+ F(w(Ne), {
4467
+ name: "search",
4468
+ size: 15
4469
+ }),
4470
+ F(w(Va), {
4471
+ modelValue: w(he),
4472
+ "onUpdate:modelValue": n[9] || (n[9] = (u) => qa(he) ? he.value = u : null),
4473
+ "input-attrs": { "aria-label": Xo.value },
4474
+ placeholder: Xo.value,
4475
+ onInput: n[10] || (n[10] = (u) => w(pe)(m.value))
4476
+ }, null, 8, ["modelValue", "input-attrs", "placeholder"])
4477
+ ], 2),
4478
+ m.value === "variable" ? (A(), ce(Gl, {
4479
+ key: 3,
4480
+ options: w(W),
4481
+ loading: w(Oe),
4482
+ "next-cursor": w(_e),
4483
+ query: w(he),
4484
+ onChoose: n[11] || (n[11] = (u, P) => yo("variable", u, P)),
4485
+ onLoadMore: n[12] || (n[12] = (u) => w(pe)("variable", !0))
4486
+ }, null, 8, ["options", "loading", "next-cursor", "query"])) : (A(), L("div", ss, [
4487
+ w(Oe) && !w(W).length ? (A(), L("p", rs, [
4488
+ F(w(Ne), {
4489
+ name: "sync",
4490
+ size: 15,
4491
+ class: "fkp-spin"
4492
+ }),
4493
+ n[30] || (n[30] = ye("加载中…"))
4494
+ ])) : !w(Oe) && !w(W).length ? (A(), L("p", us, ae(m.value === "ticket" ? "暂无可用工单场景" : "暂无可选项"), 1)) : oe("", !0),
4495
+ (A(!0), L(Ee, null, an(w(W), (u) => {
4496
+ var P, I, D;
4497
+ return A(), ce(w(ue), {
4498
+ key: u.id,
4499
+ type: "text",
4500
+ "aria-label": u.label,
4501
+ "aria-pressed": m.value === ((P = G.value) == null ? void 0 : P.kind) ? G.value.key === u.id : m.value === "agentSelect" ? ((I = Ge.value) == null ? void 0 : I.id) === u.id : (m.value === "todo" || m.value === "tagged") && zn(m.value) === "questionAction" ? ((D = ro(m.value)) == null ? void 0 : D.id) === u.id : void 0,
4502
+ disabled: u.disabled,
4503
+ onClick: (tn) => yo(m.value, u, tn)
4504
+ }, {
4505
+ default: j(() => [
4506
+ ye(ae(u.label), 1),
4507
+ u.hasChildren ? (A(), ce(w(Ne), {
4508
+ key: 0,
4509
+ class: "fkp-option-child-icon",
4510
+ name: "arrow-down",
4511
+ size: 14
4512
+ })) : oe("", !0)
4513
+ ]),
4514
+ _: 2
4515
+ }, 1032, ["aria-label", "aria-pressed", "disabled", "onClick"]);
4516
+ }), 128)),
4517
+ w(_e) ? (A(), ce(w(ue), {
4518
+ key: 2,
4519
+ type: "text",
4520
+ class: "fkp-menu-more",
4521
+ disabled: w(Oe),
4522
+ onClick: n[13] || (n[13] = (u) => w(pe)(m.value, !0))
4523
+ }, {
4524
+ default: j(() => n[31] || (n[31] = [
4525
+ ye("加载更多")
4526
+ ])),
4527
+ _: 1
4528
+ }, 8, ["disabled"])) : oe("", !0)
4529
+ ])),
4530
+ m.value === "agentSelect" || m.value === "tagged" ? (A(), ce(w(ue), {
4531
+ key: 5,
4532
+ class: "fkp-menu-config",
4533
+ type: "text",
4534
+ onClick: n[14] || (n[14] = (u) => v(m.value))
4535
+ }, {
4536
+ default: j(() => n[32] || (n[32] = [
4537
+ ye("去配置")
4538
+ ])),
4539
+ _: 1
4540
+ })) : oe("", !0)
4541
+ ], 38)) : oe("", !0),
4542
+ F(w($a), {
4543
+ visible: m.value === "reasoningTemplate",
4544
+ title: "推理模板",
4545
+ width: 600,
4546
+ footer: !1,
4547
+ onCancel: n[19] || (n[19] = (u) => {
4548
+ $t(), m.value = null;
4549
+ })
4550
+ }, {
4551
+ default: j(() => [
4552
+ R("div", cs, [
4553
+ n[35] || (n[35] = R("div", { class: "fkp-template-intro" }, [
4554
+ R("h3", null, "说明"),
4555
+ R("p", null, " 推理适用于需要根据不同情况判断条件和对应处理规则的业务场景,AI 命中知识后会选择对应流程并结合实际信息进行回复或执行动作。 "),
4556
+ R("p", null, "您可以参考以下示例进行推理内容的配置:")
4557
+ ], -1)),
4558
+ w(Oe) ? (A(), L("p", ds, "加载中…")) : w(W).length ? oe("", !0) : (A(), L("p", fs, "暂无可用模板")),
4559
+ (A(!0), L(Ee, null, an(w(W), (u) => {
4560
+ var P, I;
4561
+ return A(), L("div", {
4562
+ key: u.id,
4563
+ class: "fkp-template-card"
4564
+ }, [
4565
+ F(w(ue), {
4566
+ type: "text",
4567
+ class: "fkp-template-title",
4568
+ "aria-label": u.label,
4569
+ "aria-expanded": wn.value === u.id,
4570
+ disabled: u.disabled,
4571
+ onClick: (D) => wn.value = wn.value === u.id ? null : u.id
4572
+ }, {
4573
+ default: j(() => [
4574
+ ye(ae(u.label), 1),
4575
+ F(w(Ne), {
4576
+ class: "fkp-template-title-arrow",
4577
+ name: "arrow-down",
4578
+ size: 14
4579
+ })
4580
+ ]),
4581
+ _: 2
4582
+ }, 1032, ["aria-label", "aria-expanded", "disabled", "onClick"]),
4583
+ wn.value === u.id ? (A(), L("div", ps, [
4584
+ u.preview ? (A(), L("p", vs, ae(u.preview), 1)) : oe("", !0),
4585
+ F(w(Ba), {
4586
+ type: "warning",
4587
+ position: "bottom",
4588
+ content: (P = Kn.value) == null ? void 0 : P.content,
4589
+ "popup-visible": ((I = Kn.value) == null ? void 0 : I.optionId) === u.id,
4590
+ "content-class": "fkp-template-confirm",
4591
+ onPopupVisibleChange: n[17] || (n[17] = (D) => {
4592
+ D || $t();
4593
+ }),
4594
+ onOk: Gi,
4595
+ onCancel: $t
4596
+ }, {
4597
+ default: j(() => [
4598
+ F(w(ue), {
4599
+ type: "primary",
4600
+ disabled: u.disabled,
4601
+ onClick: (D) => yo("reasoningTemplate", u, D)
4602
+ }, {
4603
+ default: j(() => n[33] || (n[33] = [
4604
+ ye("使用模板")
4605
+ ])),
4606
+ _: 2
4607
+ }, 1032, ["disabled", "onClick"])
4608
+ ]),
4609
+ _: 2
4610
+ }, 1032, ["content", "popup-visible"])
4611
+ ])) : oe("", !0)
4612
+ ]);
4613
+ }), 128)),
4614
+ w(_e) ? (A(), ce(w(ue), {
4615
+ key: 2,
4616
+ type: "text",
4617
+ disabled: w(Oe),
4618
+ onClick: n[18] || (n[18] = (u) => w(pe)("reasoningTemplate", !0))
4619
+ }, {
4620
+ default: j(() => n[34] || (n[34] = [
4621
+ ye("加载更多")
4622
+ ])),
4623
+ _: 1
4624
+ }, 8, ["disabled"])) : oe("", !0)
4625
+ ])
4626
+ ]),
4627
+ _: 1
4628
+ }, 8, ["visible"]),
4629
+ F(w(ho), {
4630
+ visible: en.value,
4631
+ title: "话术润色",
4632
+ width: 1200,
4633
+ "modal-class": "fkp-polish-modal",
4634
+ "mask-closable": !1,
4635
+ "unmount-on-close": !0,
4636
+ onCancel: un
4637
+ }, {
4638
+ footer: j(() => [
4639
+ F(w(ue), { onClick: un }, {
4640
+ default: j(() => n[39] || (n[39] = [
4641
+ ye("取消")
4642
+ ])),
4643
+ _: 1
4644
+ }),
4645
+ F(w(ue), {
4646
+ type: "primary",
4647
+ disabled: Tn.value !== "ready",
4648
+ onClick: Bi
4649
+ }, {
4650
+ default: j(() => n[40] || (n[40] = [
4651
+ ye("采用")
4652
+ ])),
4653
+ _: 1
4654
+ }, 8, ["disabled"])
4655
+ ]),
4656
+ default: j(() => [
4657
+ Tn.value === "loading" ? (A(), L("div", gs, n[36] || (n[36] = [
4658
+ R("span", {
4659
+ class: "fkp-polish-dot",
4660
+ "aria-hidden": "true"
4661
+ }, null, -1),
4662
+ R("strong", null, "话术润色中...", -1),
4663
+ R("p", null, "系统将分析话术内容,可能需要几十秒时间", -1)
4664
+ ]))) : Tn.value === "ready" && Qn.value ? (A(), L("div", ys, [
4665
+ R("section", ms, [
4666
+ n[37] || (n[37] = R("h3", null, "原文", -1)),
4667
+ R("div", ks, ae(Do.value), 1)
4668
+ ]),
4669
+ R("section", bs, [
4670
+ n[38] || (n[38] = R("h3", null, "润色后", -1)),
4671
+ R("div", hs, ae(Qn.value.proposed), 1)
4672
+ ])
4673
+ ])) : (A(), L("div", ws, ae(Xn.value ? `润色失败:${Xn.value}` : "润色失败,请稍后重试"), 1))
4674
+ ]),
4675
+ _: 1
4676
+ }, 8, ["visible"]),
4677
+ w(Rt) ? (A(), ce(w(ho), {
4678
+ key: 1,
4679
+ visible: !0,
4680
+ title: ((B = w(Rn)) == null ? void 0 : B.label) || "工具配置",
4681
+ width: 500,
4682
+ "modal-class": "fkp-tool-modal",
4683
+ footer: !1,
4684
+ onCancel: w(Dn)
4685
+ }, {
4686
+ default: j(() => {
4687
+ var u, P;
4688
+ return [
4689
+ F(w(C), {
4690
+ definition: w(Rt),
4691
+ "initial-params": ((u = w(Rn)) == null ? void 0 : u.params) || {},
4692
+ "submit-label": (P = w(Rn)) != null && P.nodeId ? "保存" : "插入",
4693
+ onSubmit: ha,
4694
+ onCancel: w(Dn)
4695
+ }, null, 8, ["definition", "initial-params", "submit-label", "onCancel"])
4696
+ ];
4697
+ }),
4698
+ _: 1
4699
+ }, 8, ["title", "onCancel"])) : oe("", !0),
4700
+ R("div", {
4701
+ class: we(["fkp-scene-body", { "has-knowledge-content": nt.value }])
4702
+ }, [
4703
+ R("div", Ts, [
4704
+ R("span", {
4705
+ class: "fkp-question-prompt",
4706
+ onClick: Wi
4707
+ }, [
4708
+ n[41] || (n[41] = R("span", { "aria-hidden": "true" }, "[", -1)),
4709
+ R("span", {
4710
+ class: we(["fkp-question-field", { "is-filled": !!s.value.question.text }])
4711
+ }, [
4712
+ R("span", Is, ae(s.value.question.text || "填写顾客咨询意图,多种意图使用 / 分隔"), 1),
4713
+ F(w(Ua), {
4714
+ "model-value": s.value.question.text,
4715
+ disabled: te.value,
4716
+ "textarea-attrs": { "aria-label": "顾客问法", rows: 1 },
4717
+ placeholder: "填写顾客咨询意图,多种意图使用 / 分隔",
4718
+ onFocus: Hi,
4719
+ onBlur: Yi,
4720
+ onKeydown: n[20] || (n[20] = ko(Gt(() => {
4721
+ }, ["prevent"]), ["enter"])),
4722
+ onInput: Ji
4723
+ }, null, 8, ["model-value", "disabled"])
4724
+ ], 2),
4725
+ n[42] || (n[42] = R("span", {
4726
+ "aria-hidden": "true",
4727
+ class: "fkp-question-close"
4728
+ }, "]", -1))
4729
+ ]),
4730
+ Wo.value.length ? (A(), L("span", As, [
4731
+ (A(!0), L(Ee, null, an(Wo.value, (u) => (A(), ce(w(ue), {
4732
+ key: u.id,
4733
+ class: we(["fkp-question-tag", `fkp-question-tag--${u.kind}`]),
4734
+ "data-fkp-menu-trigger": u.id,
4735
+ type: "text",
4736
+ disabled: te.value,
4737
+ "aria-label": `${u.protocolLabel}方案:${u.label}`,
4738
+ "aria-expanded": m.value === u.id,
4739
+ onMouseenter: (P) => Go(u.id, P, !0),
4740
+ onPointerdownCapture: (P) => zi(u.id, P),
4741
+ onMouseleave: Sn,
4742
+ onClick: (P) => Go(u.id, P, !1)
4743
+ }, {
4744
+ default: j(() => [
4745
+ F(w(Ne), {
4746
+ class: "fkp-question-tag-icon",
4747
+ name: u.icon,
4748
+ size: 16
4749
+ }, null, 8, ["name"]),
4750
+ R("span", Ss, ae(u.label), 1),
4751
+ F(w(Ne), {
4752
+ class: "fkp-question-tag-arrow",
4753
+ name: "arrow-down",
4754
+ size: 12
4755
+ })
4756
+ ]),
4757
+ _: 2
4758
+ }, 1032, ["data-fkp-menu-trigger", "class", "disabled", "aria-label", "aria-expanded", "onMouseenter", "onPointerdownCapture", "onClick"]))), 128))
4759
+ ])) : oe("", !0)
4760
+ ]),
4761
+ R("div", Es, [
4762
+ Bn.value ? (A(), L("div", Ns, [
4763
+ R("p", null, "此知识包含当前版本无法编辑的内容:" + ae(Bn.value) + "。请升级扩展后编辑。", 1),
4764
+ R("pre", _s, ae(Fi.value), 1),
4765
+ $o.value ? (A(), L(Ee, { key: 0 }, [
4766
+ n[43] || (n[43] = R("p", null, "扩展状态(只读)", -1)),
4767
+ R("pre", Os, ae($o.value), 1)
4768
+ ], 64)) : oe("", !0)
4769
+ ])) : s.value.type !== "agent" ? (A(), ce(w(k), {
4770
+ ref_key: "area",
4771
+ ref: J,
4772
+ key: e.sceneKey + ":" + s.value.type + ":" + Vo.value,
4773
+ "model-value": s.value.knowledge.doc || w(On)(),
4774
+ editable: !te.value,
4775
+ "schema-plan": qo.value,
4776
+ "paste-capabilities": le.value.capabilities.filter((u) => u.canInsert),
4777
+ "active-choice-id": m.value === ((U = G.value) == null ? void 0 : U.kind) ? (K = G.value) == null ? void 0 : K.nodeId : null,
4778
+ placeholder: s.value.type === "reasoning" ? Vs : "填写知识内容",
4779
+ onFocusin: ia,
4780
+ onPasteCapture: Sa,
4781
+ onDragoverCapture: Ea,
4782
+ onDropCapture: Na,
4783
+ "onUpdate:modelValue": oa,
4784
+ onRetryMedia: w(_a),
4785
+ onLoadError: aa,
4786
+ onEditTool: ba,
4787
+ onChoiceMenu: ma,
4788
+ onLeaveChoice: Sn
4789
+ }, null, 8, ["model-value", "editable", "schema-plan", "paste-capabilities", "active-choice-id", "placeholder", "onRetryMedia"])) : (A(), L("div", Cs, [
4790
+ Ge.value ? (A(), L("div", {
4791
+ key: 0,
4792
+ class: we(["fkp-agent-preview-name", { "is-invalid": Ge.value.invalid }])
4793
+ }, ae(Jo.value), 3)) : oe("", !0),
4794
+ s.value.knowledge.agentBody ? (A(), ce(w(k), {
4795
+ key: e.sceneKey + ":agent-body:" + w(Pi)(Ho.value),
4796
+ "model-value": s.value.knowledge.agentBody,
4797
+ editable: !1,
4798
+ "schema-plan": Ho.value
4799
+ }, null, 8, ["model-value", "schema-plan"])) : oe("", !0),
4800
+ Q.value === "ready" && $.value.length ? (A(), L("div", Ps, [
4801
+ (A(!0), L(Ee, null, an($.value, (u, P) => (A(), L(Ee, { key: P }, [
4802
+ u.type === "text" ? (A(), L("span", xs, ae(u.text), 1)) : u.type === "break" ? (A(), L("br", Ms)) : u.type === "tag" ? (A(), L("span", {
4803
+ key: 2,
4804
+ class: we(["fkp-knowledge-tag fkp-agent-prompt-tag", `fkp-agent-prompt-tag--${u.kind}`]),
4805
+ "data-agent-tag": u.kind
4806
+ }, [
4807
+ F(w(Ne), {
4808
+ name: Ia(u.kind),
4809
+ size: 12
4810
+ }, null, 8, ["name"]),
4811
+ ye(ae(u.label), 1)
4812
+ ], 10, Ls)) : u.kind === "image" ? (A(), L("img", {
4813
+ key: 3,
4814
+ class: "fkp-agent-prompt-media",
4815
+ src: u.url,
4816
+ alt: "Agent 提示词图片"
4817
+ }, null, 8, Rs)) : (A(), L("video", {
4818
+ key: 4,
4819
+ class: "fkp-agent-prompt-media",
4820
+ src: u.url,
4821
+ controls: ""
4822
+ }, null, 8, Ds))
4823
+ ], 64))), 128))
4824
+ ])) : si.value ? (A(), L("div", {
4825
+ key: 3,
4826
+ class: we({
4827
+ placeholder: !s.value.knowledge.agentBody && (Q.value !== "ready" || !E.value)
4828
+ })
4829
+ }, ae(si.value), 3)) : oe("", !0)
4830
+ ]))
4831
+ ]),
4832
+ F(w(Fa), {
4833
+ content: "删除",
4834
+ position: "top",
4835
+ disabled: te.value
4836
+ }, {
4837
+ default: j(() => [
4838
+ F(w(ue), {
4839
+ class: "fkp-delete",
4840
+ type: "text",
4841
+ "aria-label": "清空行为与知识",
4842
+ disabled: te.value,
4843
+ onClick: Ca
4844
+ }, {
4845
+ default: j(() => [
4846
+ F(w(Ne), {
4847
+ name: "rte-del",
4848
+ size: 19
4849
+ })
4850
+ ]),
4851
+ _: 1
4852
+ }, 8, ["disabled"])
4853
+ ]),
4854
+ _: 1
4855
+ }, 8, ["disabled"])
4856
+ ], 2),
4857
+ R("input", {
4858
+ ref_key: "fileInput",
4859
+ ref: pn,
4860
+ type: "file",
4861
+ accept: Zo.value,
4862
+ multiple: "",
4863
+ hidden: "",
4864
+ "aria-label": "选择媒体文件",
4865
+ onChange: Aa
4866
+ }, null, 40, Ks)
4867
+ ], 34);
4868
+ };
4869
+ }
4870
+ });
4871
+ export {
4872
+ Zs as _,
4873
+ Ws as a,
4874
+ Ys as b,
4875
+ Ll as c,
4876
+ Fe as d,
4877
+ bl as e,
4878
+ Jn as f,
4879
+ Xs as i,
4880
+ Qs as l,
4881
+ Qt as m,
4882
+ xn as p,
4883
+ ct as r,
4884
+ Hs as v
4885
+ };