@freecallai/pro 0.0.2 → 0.0.3

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