@freecallai/pro 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +23 -23
  3. package/dist/FkpKnowledgeTypePicker.vue_vue_type_script_setup_true_lang--MPtqZY_.js +193 -0
  4. package/dist/FkpRichText.vue_vue_type_script_setup_true_lang-bw74hFS9.js +4980 -0
  5. package/dist/KnowledgeArea-CEX1esVZ.js +4 -0
  6. package/dist/KnowledgeArea.vue_vue_type_script_setup_true_lang-Bg1e7xYT.js +1653 -0
  7. package/dist/ToolForm-DA-EFBhw.js +196 -0
  8. package/dist/agent-prompt-editor/index.js +917 -0
  9. package/dist/agent-prompt-editor/legacy-converter/index.js +490 -0
  10. package/dist/{choice-Bt2xhoN_.js → choice-2dbddjJU.js} +1 -1
  11. package/dist/edition-info/index.js +1 -1
  12. package/dist/filters/index.js +1 -1
  13. package/dist/{guard-B7U3S4F1.js → guard-Cr_ny-sR.js} +255 -237
  14. package/dist/index-7x1OTv0m.js +98 -0
  15. package/dist/{index-BF6MRSMb.js → index-BBxrpF3v.js} +1 -1
  16. package/dist/{index-sjDmbR5o.js → index-CgRisH4B.js} +1 -1
  17. package/dist/index-Ck8RYpuE.js +816 -0
  18. package/dist/index-CnjG7Mj4.js +5 -0
  19. package/dist/{index-lNhA3N9x.js → index-DBQsQ1ZK.js} +1 -0
  20. package/dist/index-DCZKt14c.js +5 -0
  21. package/dist/{index-D9yqpH_4.js → index-DiaPY8Db.js} +2 -2
  22. package/dist/{index-trxE5T0w.js → index-DmdrsEvk.js} +1 -1
  23. package/dist/index-DnmCPdCI.js +168 -0
  24. package/dist/{index-B4-2_sJI.js → index-DwDYy2lj.js} +1 -1
  25. package/dist/{index-BBv72oZe.js → index-FQQfN6nm.js} +1 -1
  26. package/dist/{index-DYeJRJY1.js → index-aic1yCBs.js} +1 -1
  27. package/dist/index.js +13 -13
  28. package/dist/{inline-KPGqYMIR.js → inline-8aNfINLF.js} +1 -1
  29. package/dist/knowledge-type-picker/index.js +1 -1
  30. package/dist/{knowledge-CupkY2rK.js → knowledge-y2j0ijgx.js} +1 -1
  31. package/dist/{media-extensions-DhRlLKYM.js → media-extensions-wlcCEdtg.js} +27 -24
  32. package/dist/media-id-b2dgniSy.js +15 -0
  33. package/dist/{media-migration-CbMT2wS0.js → media-migration-Dy_rbdkK.js} +1 -1
  34. package/dist/media-policy-BwKjZPWt.js +158 -0
  35. package/dist/{media-upload-P9WeUHHr.js → media-upload-NzWYyCm3.js} +1 -1
  36. package/dist/model-DvukseoR.js +146 -0
  37. package/dist/navigation/index.js +1 -1
  38. package/dist/rich-text/index.js +75 -73
  39. package/dist/rich-text/legacy-converter/index.js +988 -867
  40. package/dist/style.css +1 -1
  41. package/dist/switcher/index.js +1 -1
  42. package/dist/types/agent-prompt-editor/FkpAgentPromptEditor.vue.d.ts +550 -0
  43. package/dist/types/agent-prompt-editor/agent-size-chart.d.ts +3 -0
  44. package/dist/types/agent-prompt-editor/document-adapter.d.ts +3 -0
  45. package/dist/types/agent-prompt-editor/index.d.ts +6 -0
  46. package/dist/types/agent-prompt-editor/legacy-converter-index.d.ts +2 -0
  47. package/dist/types/agent-prompt-editor/legacy-converter.d.ts +26 -0
  48. package/dist/types/agent-prompt-editor/model.d.ts +21 -0
  49. package/dist/types/agent-prompt-editor/types.d.ts +56 -0
  50. package/dist/types/edition-info/FkpEditionInfo.vue.d.ts +1 -3
  51. package/dist/types/edition-info/presets.d.ts +8 -0
  52. package/dist/types/edition-info/types.d.ts +1 -0
  53. package/dist/types/filters/FkpFilter.vue.d.ts +2 -2
  54. package/dist/types/filters/FkpFilterDateRange.vue.d.ts +2 -2
  55. package/dist/types/filters/FkpFilterPeriod.vue.d.ts +2 -2
  56. package/dist/types/filters/FkpSearchableMultiSelect.vue.d.ts +2 -2
  57. package/dist/types/index.d.ts +4 -1
  58. package/dist/types/navigation/FkpNavigation.vue.d.ts +20 -29
  59. package/dist/types/navigation/NavigationButton.vue.d.ts +26 -0
  60. package/dist/types/navigation/NavigationGroup.vue.d.ts +45 -0
  61. package/dist/types/navigation/NavigationIcon.vue.d.ts +28 -0
  62. package/dist/types/navigation/NavigationNodes.vue.d.ts +40 -0
  63. package/dist/types/navigation/index.d.ts +1 -1
  64. package/dist/types/navigation/types.d.ts +43 -5
  65. package/dist/types/navigation/use-navigation-tree.d.ts +13 -0
  66. package/dist/types/rich-text/FkpRichText.vue.d.ts +28 -8
  67. package/dist/types/rich-text/config/descriptor.d.ts +1 -0
  68. package/dist/types/rich-text/config/resolve.d.ts +1 -1
  69. package/dist/types/rich-text/index.d.ts +4 -1
  70. package/dist/types/rich-text/knowledge-document-adapter.d.ts +2 -0
  71. package/dist/types/rich-text/model/question-text.d.ts +1 -1
  72. package/dist/types/rich-text/plugins/registry.d.ts +2 -1
  73. package/dist/types/rich-text/public/types.d.ts +12 -0
  74. package/dist/types/rich-text/runtime/document-adapter.d.ts +9 -0
  75. package/dist/types/rich-text/runtime/knowledge-clipboard.d.ts +9 -3
  76. package/dist/types/rich-text/runtime/media-sources.d.ts +7 -0
  77. package/dist/types/rich-text/runtime/media-upload-session.d.ts +2 -0
  78. package/dist/types/rich-text/ui/FkpKnowledgeTypePicker.vue.d.ts +3 -3
  79. package/dist/types/rich-text/ui/KnowledgeArea.vue.d.ts +18 -3
  80. package/dist/types/rich-text/ui/MediaSourceControls.vue.d.ts +190 -0
  81. package/dist/types/rich-text/ui/ToolForm.vue.d.ts +2 -2
  82. package/dist/types/rich-text/ui/token-renderer.d.ts +3 -0
  83. package/dist/types/rich-text/ui/useMediaHint.d.ts +6 -0
  84. package/dist/types/switcher/FkpSwitcher.vue.d.ts +2 -2
  85. package/dist/types-PvYB5e85.js +14 -0
  86. package/package.json +13 -5
  87. package/dist/FkpKnowledgeTypePicker.vue_vue_type_script_setup_true_lang-xR8ZhhdJ.js +0 -187
  88. package/dist/FkpRichText.vue_vue_type_script_setup_true_lang-CaHRIHab.js +0 -4864
  89. package/dist/KnowledgeArea-_rsydhnt.js +0 -1438
  90. package/dist/ToolForm-Czg67cDT.js +0 -185
  91. package/dist/index-BQrYBmwR.js +0 -5
  92. package/dist/index-CS2xQQ8W.js +0 -168
  93. package/dist/index-D0bJAQSN.js +0 -327
  94. package/dist/index-DCmHHi07.js +0 -71
  95. package/dist/index-uCVrA6xK.js +0 -5
@@ -0,0 +1,917 @@
1
+ import { defineComponent as kt, ref as p, computed as N, onMounted as It, watch as $, onBeforeUnmount as Mt, openBlock as v, createElementBlock as b, withKeys as Et, withModifiers as ae, normalizeClass as Tt, createElementVNode as y, Fragment as fe, renderList as Ee, createCommentVNode as U, createVNode as K, unref as T, withCtx as ve, createBlock as He, createTextVNode as Te, toDisplayString as q, renderSlot as Lt, normalizeStyle as _t, withDirectives as Je, vModelText as We, nextTick as me } from "vue";
2
+ import { Popover as Ct, Button as Le } from "@freecallai/ui";
3
+ import _e from "@freecallai/icons";
4
+ import { u as wt, c as Xe, _ as St, m as Ce, M as Ge, a as Dt, b as Nt } from "../media-policy-BwKjZPWt.js";
5
+ import { i as Ze } from "../guard-Cr_ny-sR.js";
6
+ import { _ as Pt } from "../KnowledgeArea.vue_vue_type_script_setup_true_lang-Bg1e7xYT.js";
7
+ import { Node as Ot } from "@tiptap/core";
8
+ import { f as ne, a as je, c as zt, e as Vt, v as xt } from "../model-DvukseoR.js";
9
+ const Kt = Ot.create({
10
+ name: "agentSizeChart",
11
+ group: "inline",
12
+ inline: !0,
13
+ atom: !0,
14
+ selectable: !0,
15
+ addAttributes() {
16
+ return { name: { default: "" } };
17
+ },
18
+ parseHTML() {
19
+ return [
20
+ {
21
+ tag: "span[data-agent-size-chart]",
22
+ getAttrs: (L) => ({
23
+ name: L.getAttribute("data-agent-size-chart") || ""
24
+ })
25
+ }
26
+ ];
27
+ },
28
+ renderHTML({ node: L }) {
29
+ return [
30
+ "span",
31
+ {
32
+ "data-agent-size-chart": L.attrs.name,
33
+ class: "fkp-agent-size-chart fkp-knowledge-tag",
34
+ contenteditable: "false"
35
+ },
36
+ `#@${L.attrs.name}@#`
37
+ ];
38
+ },
39
+ renderText({ node: L }) {
40
+ return `#@${L.attrs.name}@#`;
41
+ }
42
+ });
43
+ function Rt(L) {
44
+ return {
45
+ ariaLabel: "Agent 提示词",
46
+ placeholder: "填写提示词",
47
+ extensions: [Kt],
48
+ clipboard: {
49
+ allowBusinessToken: (_, D) => _ !== "tool" || D === "small_payment",
50
+ sanitizeInlineNode(_) {
51
+ if (!_.hasAttribute("data-agent-size-chart")) return;
52
+ const D = _.getAttribute("data-agent-size-chart") || "";
53
+ if (!L() || !D.trim() || /[#@<>\r\n]/u.test(D) || _.textContent !== `#@${D}@#`)
54
+ return null;
55
+ const o = document.createElement("span");
56
+ return o.setAttribute("data-agent-size-chart", D), o.textContent = `#@${D}@#`, o;
57
+ },
58
+ serializeNode(_) {
59
+ if (_.type.name === "agentSizeChart")
60
+ return `#@${_.attrs.name || ""}@#`;
61
+ }
62
+ }
63
+ };
64
+ }
65
+ const Ft = {
66
+ key: 0,
67
+ class: "fkp-toolbar-divider",
68
+ "aria-hidden": "true"
69
+ }, Bt = {
70
+ key: 0,
71
+ class: "fkp-more-wrap"
72
+ }, $t = {
73
+ key: 0,
74
+ class: "fkp-menu fkp-more-menu",
75
+ role: "menu",
76
+ "aria-label": "更多提示词操作"
77
+ }, Ut = { class: "fkp-toolbar-right fkp-agent-prompt-toolbar-right" }, qt = ["aria-label"], Yt = { key: 0 }, Ht = { key: 1 }, Jt = ["disabled", "onClick"], Wt = {
78
+ key: 1,
79
+ class: "fkp-agent-prompt-options"
80
+ }, Xt = {
81
+ key: 2,
82
+ role: "alert",
83
+ class: "fkp-agent-prompt-error"
84
+ }, Gt = { class: "fkp-agent-prompt-footer" }, oa = /* @__PURE__ */ kt({
85
+ name: "FkpAgentPromptEditor",
86
+ __name: "FkpAgentPromptEditor",
87
+ props: {
88
+ promptKey: {},
89
+ modelValue: {},
90
+ ackRevision: { default: 0 },
91
+ ports: {},
92
+ policy: {},
93
+ config: {},
94
+ mediaSources: {},
95
+ capabilities: {},
96
+ readonly: { type: Boolean, default: !1 },
97
+ disabled: { type: Boolean, default: !1 },
98
+ placeholder: { default: "填写提示词" },
99
+ maxLength: { default: 1e4 }
100
+ },
101
+ emits: ["update:modelValue", "change", "diagnostic", "busy-change"],
102
+ setup(L, { expose: _, emit: D }) {
103
+ const o = L, le = D;
104
+ function we(e) {
105
+ return JSON.parse(JSON.stringify(e));
106
+ }
107
+ function Se(e) {
108
+ return ne(e) ? Vt() : we(e);
109
+ }
110
+ const C = p(Se(o.modelValue)), O = p(
111
+ ne(o.modelValue)
112
+ ), Y = p(0), c = p(), oe = p(), ge = p(), H = p(), J = p(Number.POSITIVE_INFINITY), I = p(!1), h = p(null), ie = p([]), W = p(""), re = p(!1), De = p(12), k = p(!1), X = p(null), G = p(0), Z = p(0), ue = p(), w = p(null), P = p(null), { suppressedMediaHint: Qe, suppressMediaHint: et, resumeMediaHintOnHover: tt } = wt(), Ne = p({});
113
+ let S = null;
114
+ const R = /* @__PURE__ */ new Set(), se = /* @__PURE__ */ new Map();
115
+ let A = null, be = null, at = 0;
116
+ const ce = p(Date.now());
117
+ let j;
118
+ const Pe = N(
119
+ () => new Set(o.capabilities || je)
120
+ ), Oe = [
121
+ { id: "variable", label: "变量", icon: "hashtag", group: "reference" },
122
+ { id: "todo", label: "待办", icon: "rte-todo", group: "reference" },
123
+ {
124
+ id: "tableKnowledge",
125
+ label: "表格知识",
126
+ icon: "table-knowledge",
127
+ group: "reference"
128
+ },
129
+ { id: "sizeChart", label: "尺码表", icon: "size-guide", group: "reference" },
130
+ {
131
+ id: "attribute",
132
+ label: "业务属性",
133
+ icon: "prte-reference",
134
+ group: "reference"
135
+ },
136
+ { id: "image", label: "图片", icon: "pic", group: "media" },
137
+ { id: "video", label: "视频", icon: "video3", group: "media" },
138
+ { id: "originalReply", label: "原话复述", icon: "quote", group: "format" },
139
+ { id: "separator", label: "分隔符", icon: "sep", group: "format" },
140
+ { id: "smallPayment", label: "小额打款", icon: "rte-tool", group: "tool" }
141
+ ], nt = N(
142
+ () => {
143
+ var e;
144
+ return new Set(
145
+ ((e = o.config) == null ? void 0 : e.schemaVersion) === 1 && Array.isArray(o.config.rules) ? o.config.rules.filter((t) => (t == null ? void 0 : t.visible) === !1).map((t) => t.id) : []
146
+ );
147
+ }
148
+ ), pe = N(
149
+ () => Oe.filter(
150
+ (e) => Pe.value.has(e.id) && !nt.value.has(e.id)
151
+ )
152
+ ), ze = N(
153
+ () => pe.value.slice(0, J.value)
154
+ ), ye = N(
155
+ () => pe.value.slice(J.value)
156
+ ), Ve = N(
157
+ () => {
158
+ var e;
159
+ return ((e = Oe.find((t) => t.id === h.value)) == null ? void 0 : e.label) || "";
160
+ }
161
+ ), z = N(
162
+ () => o.readonly || o.disabled || !!O.value || !!o.policy && o.policy.expiresAt <= ce.value
163
+ );
164
+ function g(e) {
165
+ return !z.value && je.includes(e) && Pe.value.has(e) && (!o.policy || o.policy.allowed.includes(e));
166
+ }
167
+ const lt = Rt(() => g("sizeChart"));
168
+ function he(e) {
169
+ var t, a;
170
+ return g(e) && (e === "variable" ? !!((t = o.ports) != null && t.listVariables) : !!((a = o.ports) != null && a.listCapabilityOptions));
171
+ }
172
+ function Ae(e) {
173
+ return e === "image" || e === "video" ? g(e) && Ce(o.mediaSources, e).some(
174
+ (t) => {
175
+ var a;
176
+ return t === "online" || !!((a = o.ports) != null && a.uploadMedia);
177
+ }
178
+ ) : [
179
+ "variable",
180
+ "todo",
181
+ "tableKnowledge",
182
+ "sizeChart",
183
+ "attribute"
184
+ ].includes(e) ? he(e) : g(e);
185
+ }
186
+ function F() {
187
+ A == null || A.abort(), h.value = null;
188
+ }
189
+ function xe(e, t) {
190
+ var a;
191
+ if (Ae(e))
192
+ if (I.value = !1, F(), V(), k.value = !1, ["variable", "todo", "tableKnowledge", "sizeChart", "attribute"].includes(
193
+ e
194
+ )) {
195
+ const n = t.currentTarget, l = (a = oe.value) == null ? void 0 : a.getBoundingClientRect();
196
+ l && (De.value = Math.max(
197
+ 12,
198
+ Math.min(
199
+ n.getBoundingClientRect().left - l.left,
200
+ l.width - 332
201
+ )
202
+ )), st(e);
203
+ } else e === "image" || e === "video" ? pt(e, t) : e === "smallPayment" ? vt() : de({ type: "capability", capabilityId: e });
204
+ }
205
+ let Q, Ke = 0;
206
+ async function ee() {
207
+ const e = ++Ke;
208
+ for (J.value = pe.value.length, await me(); e === Ke && H.value && H.value.clientWidth > 0 && H.value.scrollWidth > H.value.clientWidth + 1 && J.value > 0; )
209
+ J.value--, await me();
210
+ ye.value.length || (I.value = !1);
211
+ }
212
+ function Re(e) {
213
+ var t;
214
+ (t = oe.value) != null && t.contains(e.target) || (I.value = !1, F(), P.value || V(), k.value = !1);
215
+ }
216
+ It(() => {
217
+ window.addEventListener("resize", ee), document.addEventListener("click", Re), typeof ResizeObserver < "u" && ge.value && (Q = new ResizeObserver(() => void ee()), Q.observe(ge.value)), ee();
218
+ }), $(pe, (e) => {
219
+ h.value && !e.some((t) => t.id === h.value) && F(), k.value && !e.some((t) => t.id === "smallPayment") && (k.value = !1), ee();
220
+ }), $(z, (e) => {
221
+ e && (F(), V(), k.value = !1, I.value = !1);
222
+ });
223
+ const ot = {
224
+ businessToken: !0,
225
+ originalReply: !0,
226
+ separator: !0,
227
+ mediaBlock: !0
228
+ }, it = N(
229
+ () => [
230
+ "variable",
231
+ "todo",
232
+ "tableKnowledge",
233
+ "attribute",
234
+ "image",
235
+ "video",
236
+ "originalReply",
237
+ "separator",
238
+ "tool"
239
+ ].filter(
240
+ (e) => g(e === "tool" ? "smallPayment" : e)
241
+ ).map((e) => ({
242
+ id: e,
243
+ slot: e === "image" || e === "video" || e === "originalReply" ? "knowledgeBlock" : "knowledgeInline"
244
+ }))
245
+ ), rt = N(() => zt(C.value));
246
+ function Fe() {
247
+ j && clearTimeout(j), ce.value = Date.now(), o.policy && o.policy.expiresAt > ce.value && (j = setTimeout(
248
+ Fe,
249
+ Math.min(o.policy.expiresAt - ce.value + 1, 2147483647)
250
+ ));
251
+ }
252
+ $(() => {
253
+ var e;
254
+ return (e = o.policy) == null ? void 0 : e.expiresAt;
255
+ }, Fe, { immediate: !0 });
256
+ function te() {
257
+ le("busy-change", {
258
+ uploading: G.value,
259
+ requesting: Z.value
260
+ });
261
+ }
262
+ function Be() {
263
+ V();
264
+ for (const e of R) e.abort();
265
+ R.clear(), se.clear(), A = null, h.value = null, I.value = !1, k.value = !1, ie.value = [], re.value = !1, G.value = 0, Z.value = 0, te();
266
+ }
267
+ $(
268
+ () => o.promptKey,
269
+ () => {
270
+ Be(), C.value = Se(o.modelValue), O.value = ne(o.modelValue), Y.value = 0;
271
+ },
272
+ { flush: "sync" }
273
+ ), $(
274
+ () => [o.modelValue, o.ackRevision],
275
+ ([e, t]) => {
276
+ const a = ne(e);
277
+ if (a) {
278
+ O.value = a, m("PROMPT_DOCUMENT_INVALID", "输入的提示词文档无效", a);
279
+ return;
280
+ }
281
+ if (Xe(e) === Xe(C.value)) {
282
+ O.value = null;
283
+ return;
284
+ }
285
+ Y.value > 0 && (t || 0) < Y.value || (O.value = null, C.value = we(e));
286
+ },
287
+ { deep: !0 }
288
+ ), Mt(() => {
289
+ Be(), j && clearTimeout(j), Q == null || Q.disconnect(), window.removeEventListener("resize", ee), document.removeEventListener("click", Re);
290
+ });
291
+ function m(e, t, a = "doc") {
292
+ le("diagnostic", {
293
+ code: e,
294
+ message: t,
295
+ path: a,
296
+ severity: "warning",
297
+ source: "validation"
298
+ });
299
+ }
300
+ function ke(e, t, a) {
301
+ if (z.value) return !1;
302
+ const n = { schemaVersion: 1, doc: e }, l = ne(n);
303
+ if (l)
304
+ return m("PROMPT_DOCUMENT_INVALID", "编辑结果包含无效内容", l), me(() => {
305
+ var i;
306
+ return (i = c.value) == null ? void 0 : i.restoreDoc(C.value.doc);
307
+ }), !1;
308
+ C.value = n;
309
+ const s = ++Y.value;
310
+ return le("change", n, {
311
+ promptKey: o.promptKey,
312
+ revision: s,
313
+ origin: t,
314
+ ...a ? { capabilityId: a } : {}
315
+ }), le("update:modelValue", n), !0;
316
+ }
317
+ function ut(e) {
318
+ const t = be;
319
+ ke(e, (t == null ? void 0 : t.origin) || "user", t == null ? void 0 : t.capabilityId);
320
+ }
321
+ function M(e, t, a) {
322
+ be = { origin: t, capabilityId: a };
323
+ try {
324
+ return e();
325
+ } finally {
326
+ be = null;
327
+ }
328
+ }
329
+ function d(e, t) {
330
+ return m(e, t), { ok: !1, code: e, message: t };
331
+ }
332
+ function B() {
333
+ return { ok: !0, revision: Y.value };
334
+ }
335
+ function $e(e) {
336
+ const t = /* @__PURE__ */ new Set(), a = (n) => {
337
+ var l, s, i, r;
338
+ e === "agentSizeChart" && n.type === e && t.add(String(((l = n.attrs) == null ? void 0 : l.name) || "").trim()), e === "tableKnowledge" && ((s = n.attrs) == null ? void 0 : s.kind) === e && t.add(String(((i = n.attrs) == null ? void 0 : i.label) || "").trim()), (r = n.content) == null || r.forEach(a);
339
+ };
340
+ return a(C.value.doc), t;
341
+ }
342
+ function Ie(e, t) {
343
+ return {
344
+ promptKey: o.promptKey,
345
+ capabilityId: e,
346
+ requestId: `agent-prompt-${++at}`,
347
+ signal: t.signal
348
+ };
349
+ }
350
+ async function de(e) {
351
+ var i, r, x;
352
+ if (z.value) return d("PROMPT_READONLY", "当前提示词不可编辑");
353
+ const t = o.promptKey;
354
+ let a = c.value;
355
+ if (a || (await me(), a = c.value), !a || !await a.whenReady() || t !== o.promptKey)
356
+ return d("EDITOR_UNAVAILABLE", "提示词编辑器尚未就绪");
357
+ if (e.type === "text")
358
+ return e.text ? M(
359
+ () => a.insertText(e.text, e.placement, e.selectInserted),
360
+ "api"
361
+ ) ? B() : d("INSERT_FAILED", "文本插入失败") : d("EMPTY_TEXT", "插入文本不能为空");
362
+ if (e.type === "media") {
363
+ const { asset: u } = e;
364
+ if (!g(u.kind) || !Ze(u.url))
365
+ return d("MEDIA_INVALID", "媒体资源不可用");
366
+ const f = a.captureMediaTarget() || a.captureEndTarget();
367
+ if (!f) return d("INSERT_FAILED", "无法确定媒体插入位置");
368
+ try {
369
+ const E = a.insertMedia(u, e.name || "", f, !0);
370
+ return E && ke(E, "api", u.kind) ? B() : d("INSERT_FAILED", "媒体插入失败");
371
+ } finally {
372
+ f.dispose();
373
+ }
374
+ }
375
+ const n = e.capabilityId;
376
+ if (!g(n)) return d("CAPABILITY_DISABLED", "当前功能不可用");
377
+ const { option: l } = e;
378
+ if (n === "originalReply")
379
+ return M(() => a.insertOriginal(), "api", n) ? B() : d("INSERT_FAILED", "原话复述插入失败");
380
+ if (n === "separator")
381
+ return M(() => a.insertSeparator(), "api", n) ? B() : d("INSERT_FAILED", "分隔符插入失败");
382
+ if (n === "smallPayment") {
383
+ const u = Number((i = l == null ? void 0 : l.params) == null ? void 0 : i.amount);
384
+ return !Number.isInteger(u) || u < 1 || u > 99 ? d("PAYMENT_INVALID", "小额打款金额必须为 1–99 整数元") : M(
385
+ () => a.upsertToken("tool", "small_payment", "小额打款", {
386
+ amount: String(u)
387
+ }),
388
+ "api",
389
+ n
390
+ ) ? B() : d("PAYMENT_INVALID", "小额打款金额必须为 1–99 整数元");
391
+ }
392
+ if (!((r = l == null ? void 0 : l.label) != null && r.trim()) || !((x = l.id) != null && x.trim()))
393
+ return d("OPTION_INVALID", "请选择有效的功能选项");
394
+ if (n === "tableKnowledge" || n === "sizeChart") {
395
+ const u = $e("tableKnowledge"), f = $e("agentSizeChart");
396
+ if (n === "tableKnowledge") {
397
+ if (f.size)
398
+ return d("TABLE_SIZE_CONFLICT", "表格知识与尺码表不能同时引用");
399
+ if (!u.has(l.label) && u.size >= 5)
400
+ return d("TABLE_LIMIT", "最多引用 5 个表格知识");
401
+ } else {
402
+ if (u.size)
403
+ return d("TABLE_SIZE_CONFLICT", "表格知识与尺码表不能同时引用");
404
+ if (!f.has(l.label) && f.size >= 4)
405
+ return d("SIZE_LIMIT", "最多引用 4 个尺码表");
406
+ }
407
+ }
408
+ return M(
409
+ () => n === "sizeChart" ? a.insertInlineNode("agentSizeChart", {
410
+ name: l.label.trim()
411
+ }) : a.insertToken(
412
+ n,
413
+ l.id,
414
+ l.label,
415
+ l.token,
416
+ l.params
417
+ ),
418
+ "api",
419
+ n
420
+ ) ? B() : d("INSERT_FAILED", "功能内容插入失败");
421
+ }
422
+ async function Ue(e) {
423
+ var n, l, s, i;
424
+ if (!he(e)) return;
425
+ A == null || A.abort(), h.value = e, ie.value = [];
426
+ const t = new AbortController();
427
+ A = t, R.add(t), Z.value++, re.value = !0, te();
428
+ const a = o.promptKey;
429
+ try {
430
+ const r = e === "variable" ? await ((l = (n = o.ports) == null ? void 0 : n.listVariables) == null ? void 0 : l.call(
431
+ n,
432
+ { search: W.value, limit: 50 },
433
+ Ie(e, t)
434
+ )) : await ((i = (s = o.ports) == null ? void 0 : s.listCapabilityOptions) == null ? void 0 : i.call(
435
+ s,
436
+ { capabilityId: e, search: W.value, limit: 50 },
437
+ Ie(e, t)
438
+ ));
439
+ if (t.signal.aborted || a !== o.promptKey || h.value !== e)
440
+ return;
441
+ if (!(r != null && r.ok)) {
442
+ m("OPTION_LOAD_FAILED", (r == null ? void 0 : r.error.message) || "选项加载失败");
443
+ return;
444
+ }
445
+ ie.value = r.data.items;
446
+ } catch {
447
+ t.signal.aborted || m("OPTION_LOAD_FAILED", "选项加载失败");
448
+ } finally {
449
+ A === t && (A = null, re.value = !1), R.delete(t) && (Z.value = Math.max(0, Z.value - 1), te());
450
+ }
451
+ }
452
+ function st(e) {
453
+ he(e) && (W.value = "", Ue(e));
454
+ }
455
+ function ct(e) {
456
+ const t = h.value;
457
+ t && (A == null || A.abort(), h.value = null, de({
458
+ type: "capability",
459
+ capabilityId: t,
460
+ option: {
461
+ id: e.id,
462
+ label: e.label,
463
+ ...t === "variable" && "token" in e ? { token: String(e.token) } : {}
464
+ }
465
+ }));
466
+ }
467
+ function V() {
468
+ w.value = null, P.value = null, S == null || S.dispose(), S = null;
469
+ }
470
+ $(() => o.mediaSources, V, { deep: !0 });
471
+ function pt(e, t) {
472
+ var s, i, r;
473
+ const a = Ce(o.mediaSources, e).filter(
474
+ (x) => {
475
+ var u;
476
+ return x === "online" || !!((u = o.ports) != null && u.uploadMedia);
477
+ }
478
+ );
479
+ if (!g(e) || !a.length) return;
480
+ if (et(e), S = ((s = c.value) == null ? void 0 : s.captureMediaTarget()) || ((i = c.value) == null ? void 0 : i.captureEndTarget()) || null, !S) {
481
+ m("EDITOR_UNAVAILABLE", "无法确定媒体插入位置");
482
+ return;
483
+ }
484
+ if (a.length === 1) {
485
+ qe(e, a[0]);
486
+ return;
487
+ }
488
+ const n = t.currentTarget.getBoundingClientRect(), l = (r = oe.value) == null ? void 0 : r.getBoundingClientRect();
489
+ Ne.value = {
490
+ left: `${Math.max(
491
+ 8,
492
+ Math.min(
493
+ n.left - ((l == null ? void 0 : l.left) || 0),
494
+ ((l == null ? void 0 : l.width) || 240) - 116
495
+ )
496
+ )}px`,
497
+ top: `${n.bottom - ((l == null ? void 0 : l.top) || 0) + 4}px`
498
+ }, w.value = e;
499
+ }
500
+ function qe(e, t) {
501
+ if (w.value = null, t === "online") {
502
+ P.value = e;
503
+ return;
504
+ }
505
+ ue.value && (ue.value.accept = e === "image" ? "image/png,image/jpeg" : "video/mp4", ue.value.click());
506
+ }
507
+ function dt(e) {
508
+ const t = w.value;
509
+ t && qe(t, e);
510
+ }
511
+ function ft(e) {
512
+ var n;
513
+ const t = P.value, a = S;
514
+ if (S = null, P.value = null, !(!t || !a))
515
+ try {
516
+ if (!g(t) || a.status() !== "ready") {
517
+ m("INSERT_TARGET_LOST", "媒体插入位置已失效");
518
+ return;
519
+ }
520
+ const l = (n = c.value) == null ? void 0 : n.insertMedia({ kind: t, url: e }, "", a, !0);
521
+ (!l || !ke(l, "api", t)) && m("INSERT_FAILED", "在线媒体插入失败");
522
+ } finally {
523
+ a.dispose();
524
+ }
525
+ }
526
+ function vt() {
527
+ if (!g("smallPayment")) return;
528
+ X.value = null;
529
+ const e = (t) => {
530
+ var a, n, l;
531
+ t.type === "businessToken" && ((a = t.attrs) == null ? void 0 : a.kind) === "tool" && t.attrs.key === "small_payment" && (X.value = Number((n = t.attrs.params) == null ? void 0 : n.amount)), (l = t.content) == null || l.forEach(e);
532
+ };
533
+ e(C.value.doc), k.value = !0, h.value = null;
534
+ }
535
+ async function mt() {
536
+ (await de({
537
+ type: "capability",
538
+ capabilityId: "smallPayment",
539
+ option: {
540
+ id: "small_payment",
541
+ label: "小额打款",
542
+ params: { amount: X.value }
543
+ }
544
+ })).ok && (k.value = !1);
545
+ }
546
+ function Me(e, t) {
547
+ var s;
548
+ if (!e.length || e.length > Ge) {
549
+ t == null || t.dispose(), m("INVALID_MEDIA", `一次最多添加 ${Ge} 个媒体文件`);
550
+ return;
551
+ }
552
+ const a = e.map((i) => {
553
+ var r;
554
+ return {
555
+ file: i,
556
+ kind: (r = Dt(i)) == null ? void 0 : r.kind
557
+ };
558
+ });
559
+ if (a.some(
560
+ ({ file: i, kind: r }) => !r || !g(r) || i.size > Nt[r]
561
+ )) {
562
+ t == null || t.dispose(), m("INVALID_MEDIA", "仅支持符合大小限制的 JPG、PNG、MP4 文件");
563
+ return;
564
+ }
565
+ if (!((s = o.ports) != null && s.uploadMedia) || !t || !c.value) {
566
+ t == null || t.dispose(), m("UPLOAD_UNAVAILABLE", "上传功能不可用");
567
+ return;
568
+ }
569
+ const n = a, l = M(
570
+ () => {
571
+ var i;
572
+ return ((i = c.value) == null ? void 0 : i.insertPendingMediaBatch(n, t)) || null;
573
+ },
574
+ "plugin",
575
+ n[0].kind
576
+ );
577
+ if (t.dispose(), !l || l.length !== n.length) {
578
+ m("INSERT_FAILED", "无法插入待上传的媒体");
579
+ return;
580
+ }
581
+ l.forEach((i, r) => {
582
+ se.set(i, n[r].file), Ye(i, n[r].file, n[r].kind);
583
+ });
584
+ }
585
+ async function Ye(e, t, a) {
586
+ var i, r, x;
587
+ const n = (i = o.ports) == null ? void 0 : i.uploadMedia;
588
+ if (!n) return;
589
+ const l = new AbortController();
590
+ R.add(l), G.value++, te();
591
+ const s = o.promptKey;
592
+ try {
593
+ const u = await n({ file: t, kind: a }, Ie(a, l));
594
+ if (l.signal.aborted || s !== o.promptKey) return;
595
+ const f = (r = c.value) == null ? void 0 : r.getMediaState(e);
596
+ if (!f || f.status !== "uploading") return;
597
+ if (!u.ok || !Ze(u.data.url) || u.data.kind !== a) {
598
+ m(
599
+ "UPLOAD_FAILED",
600
+ u.ok ? "上传资源无效" : u.error.message
601
+ ), M(
602
+ () => {
603
+ var E;
604
+ return (E = c.value) == null ? void 0 : E.failMedia(e, "上传失败", f.nodeVersion);
605
+ },
606
+ "plugin",
607
+ a
608
+ );
609
+ return;
610
+ }
611
+ if (!g(a)) {
612
+ M(
613
+ () => {
614
+ var E;
615
+ return (E = c.value) == null ? void 0 : E.failMedia(e, "当前无媒体权限", f.nodeVersion);
616
+ },
617
+ "plugin",
618
+ a
619
+ );
620
+ return;
621
+ }
622
+ M(
623
+ () => {
624
+ var E;
625
+ return ((E = c.value) == null ? void 0 : E.completeMedia(e, f.nodeVersion, u.data)) || !1;
626
+ },
627
+ "plugin",
628
+ a
629
+ ) && se.delete(e);
630
+ } catch {
631
+ if (!l.signal.aborted) {
632
+ const u = (x = c.value) == null ? void 0 : x.getMediaState(e);
633
+ (u == null ? void 0 : u.status) === "uploading" && M(
634
+ () => {
635
+ var f;
636
+ return (f = c.value) == null ? void 0 : f.failMedia(e, "上传失败", u.nodeVersion);
637
+ },
638
+ "plugin",
639
+ a
640
+ ), m("UPLOAD_FAILED", "媒体上传失败");
641
+ }
642
+ } finally {
643
+ R.delete(l) && (G.value = Math.max(0, G.value - 1), te());
644
+ }
645
+ }
646
+ function gt(e) {
647
+ var n;
648
+ const t = se.get(e), a = (n = c.value) == null ? void 0 : n.getMediaState(e);
649
+ !t || !a || a.status !== "error" || !g(a.kind) || M(
650
+ () => {
651
+ var l;
652
+ return (l = c.value) == null ? void 0 : l.retryMedia(e, a.nodeVersion);
653
+ },
654
+ "plugin",
655
+ a.kind
656
+ ) && Ye(e, t, a.kind);
657
+ }
658
+ async function bt(e) {
659
+ var n, l, s;
660
+ const t = Array.from(e.target.files || []);
661
+ e.target.value = "";
662
+ const a = S;
663
+ if (S = null, t.length) {
664
+ const i = o.promptKey;
665
+ if (!await ((n = c.value) == null ? void 0 : n.whenReady()) || i !== o.promptKey) {
666
+ a == null || a.dispose();
667
+ return;
668
+ }
669
+ const r = a || ((l = c.value) == null ? void 0 : l.captureMediaTarget()) || ((s = c.value) == null ? void 0 : s.captureEndTarget());
670
+ Me(t, r || null);
671
+ } else a == null || a.dispose();
672
+ }
673
+ function yt(e) {
674
+ var n, l, s, i;
675
+ const t = Array.from(((n = e.clipboardData) == null ? void 0 : n.files) || []);
676
+ if (!t.length || z.value) return;
677
+ e.preventDefault();
678
+ const a = ((l = c.value) == null ? void 0 : l.pasteClipboardContent(e)) || ((s = c.value) == null ? void 0 : s.captureMediaTarget()) || ((i = c.value) == null ? void 0 : i.captureEndTarget());
679
+ a && Me(t, a);
680
+ }
681
+ function ht(e) {
682
+ var n, l, s;
683
+ const t = Array.from(((n = e.dataTransfer) == null ? void 0 : n.files) || []);
684
+ if (!t.length || z.value) return;
685
+ e.preventDefault();
686
+ const a = ((l = c.value) == null ? void 0 : l.captureMediaTargetAt(e.clientX, e.clientY)) || ((s = c.value) == null ? void 0 : s.captureEndTarget());
687
+ a && Me(t, a);
688
+ }
689
+ function At() {
690
+ return xt(C.value, o.maxLength);
691
+ }
692
+ return _({
693
+ insertContent: de,
694
+ focus: () => {
695
+ var e;
696
+ return (e = c.value) == null ? void 0 : e.focus();
697
+ },
698
+ validate: At
699
+ }), (e, t) => (v(), b("section", {
700
+ ref_key: "root",
701
+ ref: oe,
702
+ class: Tt(["fkp-rich-text fkp-agent-prompt-editor", {
703
+ "has-open-menu": !!h.value || k.value || I.value || !!w.value
704
+ }]),
705
+ "aria-label": "Agent 提示词编辑器",
706
+ onKeydown: t[10] || (t[10] = Et(ae((a) => {
707
+ F(), k.value = !1, I.value = !1, V();
708
+ }, ["stop"]), ["esc"]))
709
+ }, [
710
+ y("div", {
711
+ ref_key: "toolbar",
712
+ ref: ge,
713
+ class: "fkp-scene-toolbar fkp-agent-prompt-toolbar",
714
+ role: "toolbar",
715
+ "aria-label": "提示词工具栏"
716
+ }, [
717
+ y("div", {
718
+ ref_key: "toolbarLeft",
719
+ ref: H,
720
+ class: "fkp-toolbar-groups fkp-agent-prompt-toolbar-left"
721
+ }, [
722
+ (v(!0), b(fe, null, Ee(ze.value, (a, n) => (v(), b(fe, {
723
+ key: a.id
724
+ }, [
725
+ n > 0 && a.group !== ze.value[n - 1].group ? (v(), b("span", Ft)) : U("", !0),
726
+ K(T(Ct), {
727
+ trigger: "hover",
728
+ position: "bottom",
729
+ content: a.label,
730
+ "popup-visible": T(Qe) === a.id || w.value === a.id || P.value === a.id ? !1 : void 0
731
+ }, {
732
+ default: ve(() => [
733
+ K(T(Le), {
734
+ class: "fkp-tool-button fkp-agent-prompt-tool",
735
+ type: "text",
736
+ "data-fkp-menu-trigger": a.id,
737
+ "aria-label": a.label,
738
+ disabled: !Ae(a.id),
739
+ onMouseenter: (l) => T(tt)(
740
+ a.id,
741
+ !!w.value || !!P.value
742
+ ),
743
+ onMousedown: t[0] || (t[0] = ae(() => {
744
+ }, ["prevent"])),
745
+ onClick: (l) => xe(a.id, l)
746
+ }, {
747
+ default: ve(() => [
748
+ K(T(_e), {
749
+ name: a.icon,
750
+ size: 16
751
+ }, null, 8, ["name"])
752
+ ]),
753
+ _: 2
754
+ }, 1032, ["data-fkp-menu-trigger", "aria-label", "disabled", "onMouseenter", "onClick"])
755
+ ]),
756
+ _: 2
757
+ }, 1032, ["content", "popup-visible"])
758
+ ], 64))), 128))
759
+ ], 512),
760
+ ye.value.length ? (v(), b("div", Bt, [
761
+ K(T(Le), {
762
+ class: "fkp-more-button",
763
+ type: "text",
764
+ "aria-label": "更多操作",
765
+ "aria-haspopup": "menu",
766
+ "aria-expanded": I.value,
767
+ onMousedown: t[1] || (t[1] = ae(() => {
768
+ }, ["prevent"])),
769
+ onClick: t[2] || (t[2] = (a) => I.value = !I.value)
770
+ }, {
771
+ default: ve(() => [
772
+ K(T(_e), {
773
+ name: "more",
774
+ size: 16
775
+ })
776
+ ]),
777
+ _: 1
778
+ }, 8, ["aria-expanded"]),
779
+ I.value ? (v(), b("div", $t, [
780
+ (v(!0), b(fe, null, Ee(ye.value, (a) => (v(), He(T(Le), {
781
+ key: a.id,
782
+ class: "fkp-agent-prompt-more-item",
783
+ type: "text",
784
+ role: "menuitem",
785
+ "data-fkp-menu-trigger": a.id,
786
+ disabled: !Ae(a.id),
787
+ onMousedown: t[3] || (t[3] = ae(() => {
788
+ }, ["prevent"])),
789
+ onClick: (n) => xe(a.id, n)
790
+ }, {
791
+ default: ve(() => [
792
+ K(T(_e), {
793
+ name: a.icon,
794
+ size: 16
795
+ }, null, 8, ["name"]),
796
+ Te(q(a.label), 1)
797
+ ]),
798
+ _: 2
799
+ }, 1032, ["data-fkp-menu-trigger", "disabled", "onClick"]))), 128))
800
+ ])) : U("", !0)
801
+ ])) : U("", !0),
802
+ y("div", Ut, [
803
+ Lt(e.$slots, "toolbar-action")
804
+ ]),
805
+ y("input", {
806
+ ref_key: "fileInput",
807
+ ref: ue,
808
+ type: "file",
809
+ hidden: "",
810
+ onChange: bt
811
+ }, null, 544)
812
+ ], 512),
813
+ K(St, {
814
+ "menu-kind": w.value,
815
+ "dialog-kind": P.value,
816
+ "menu-style": Ne.value,
817
+ sources: w.value ? T(Ce)(e.mediaSources, w.value).filter(
818
+ (a) => {
819
+ var n;
820
+ return a === "online" || !!((n = e.ports) != null && n.uploadMedia);
821
+ }
822
+ ) : [],
823
+ onChoose: dt,
824
+ onSubmit: ft,
825
+ onClose: V
826
+ }, null, 8, ["menu-kind", "dialog-kind", "menu-style", "sources"]),
827
+ h.value ? (v(), b("div", {
828
+ key: 0,
829
+ class: "fkp-agent-prompt-options",
830
+ style: _t({ left: `${De.value}px` })
831
+ }, [
832
+ y("label", null, [
833
+ Te(" 搜索" + q(Ve.value) + " ", 1),
834
+ Je(y("input", {
835
+ "onUpdate:modelValue": t[4] || (t[4] = (a) => W.value = a),
836
+ type: "search",
837
+ "aria-label": `搜索${Ve.value}`,
838
+ onInput: t[5] || (t[5] = (a) => Ue(h.value))
839
+ }, null, 40, qt), [
840
+ [We, W.value]
841
+ ])
842
+ ]),
843
+ y("button", {
844
+ type: "button",
845
+ "aria-label": "关闭选项",
846
+ onClick: F
847
+ }, "×"),
848
+ re.value ? (v(), b("p", Yt, "加载中…")) : (v(), b("ul", Ht, [
849
+ (v(!0), b(fe, null, Ee(ie.value, (a) => (v(), b("li", {
850
+ key: a.id
851
+ }, [
852
+ y("button", {
853
+ type: "button",
854
+ disabled: a.disabled,
855
+ onMousedown: t[6] || (t[6] = ae(() => {
856
+ }, ["prevent"])),
857
+ onClick: (n) => ct(a)
858
+ }, q(a.label), 41, Jt)
859
+ ]))), 128))
860
+ ]))
861
+ ], 4)) : U("", !0),
862
+ k.value ? (v(), b("div", Wt, [
863
+ y("label", null, [
864
+ t[11] || (t[11] = Te(" 小额打款金额(元) ")),
865
+ Je(y("input", {
866
+ "onUpdate:modelValue": t[7] || (t[7] = (a) => X.value = a),
867
+ type: "number",
868
+ min: "1",
869
+ max: "99",
870
+ step: "1"
871
+ }, null, 512), [
872
+ [
873
+ We,
874
+ X.value,
875
+ void 0,
876
+ { number: !0 }
877
+ ]
878
+ ])
879
+ ]),
880
+ y("button", {
881
+ type: "button",
882
+ onClick: t[8] || (t[8] = (a) => k.value = !1)
883
+ }, "取消"),
884
+ y("button", {
885
+ type: "button",
886
+ onClick: mt
887
+ }, "确认")
888
+ ])) : U("", !0),
889
+ O.value ? (v(), b("p", Xt, "提示词文档无效:" + q(O.value), 1)) : U("", !0),
890
+ (v(), He(Pt, {
891
+ key: e.promptKey,
892
+ ref_key: "area",
893
+ ref: c,
894
+ "model-value": C.value.doc,
895
+ editable: !z.value,
896
+ placeholder: e.placeholder,
897
+ "schema-plan": ot,
898
+ "paste-capabilities": it.value,
899
+ "document-adapter": T(lt),
900
+ "onUpdate:modelValue": ut,
901
+ onLoadError: t[9] || (t[9] = (a) => m("EDITOR_LOAD_FAILED", a)),
902
+ onRetryMedia: gt,
903
+ onPasteCapture: yt,
904
+ onDropCapture: ht
905
+ }, null, 8, ["model-value", "editable", "placeholder", "paste-capabilities", "document-adapter"])),
906
+ y("div", Gt, [
907
+ y("span", null, q(rt.value) + "/" + q(e.maxLength), 1)
908
+ ])
909
+ ], 34));
910
+ }
911
+ });
912
+ export {
913
+ oa as FkpAgentPromptEditor,
914
+ oa as default,
915
+ Vt as emptyAgentPrompt,
916
+ xt as validateAgentPrompt
917
+ };