yc-component 0.1.0

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 (80) hide show
  1. package/README.en.md +36 -0
  2. package/README.md +216 -0
  3. package/dist/_virtual/_plugin-vue_export-helper.js +9 -0
  4. package/dist/ai-task/api/http.d.ts +6 -0
  5. package/dist/ai-task/api/http.d.ts.map +1 -0
  6. package/dist/ai-task/api/http.js +40 -0
  7. package/dist/ai-task/api/prompt.d.ts +11 -0
  8. package/dist/ai-task/api/prompt.d.ts.map +1 -0
  9. package/dist/ai-task/api/prompt.js +9 -0
  10. package/dist/ai-task/api/workflow.d.ts +51 -0
  11. package/dist/ai-task/api/workflow.d.ts.map +1 -0
  12. package/dist/ai-task/api/workflow.js +15 -0
  13. package/dist/ai-task/components/AiTaskPanel.css +1 -0
  14. package/dist/ai-task/components/AiTaskPanel.d.ts +4 -0
  15. package/dist/ai-task/components/AiTaskPanel.d.ts.map +1 -0
  16. package/dist/ai-task/components/AiTaskPanel.vue.js +7 -0
  17. package/dist/ai-task/components/AiTaskPanel.vue2.js +251 -0
  18. package/dist/ai-task/components/AiTaskProvider.d.ts +26 -0
  19. package/dist/ai-task/components/AiTaskProvider.d.ts.map +1 -0
  20. package/dist/ai-task/components/AiTaskProvider.vue.js +60 -0
  21. package/dist/ai-task/components/AiTaskProvider.vue2.js +4 -0
  22. package/dist/ai-task/components/AiUseDialog.css +1 -0
  23. package/dist/ai-task/components/AiUseDialog.d.ts +22 -0
  24. package/dist/ai-task/components/AiUseDialog.d.ts.map +1 -0
  25. package/dist/ai-task/components/AiUseDialog.vue.js +7 -0
  26. package/dist/ai-task/components/AiUseDialog.vue2.js +224 -0
  27. package/dist/ai-task/composables/useAiTask.d.ts +62 -0
  28. package/dist/ai-task/composables/useAiTask.d.ts.map +1 -0
  29. package/dist/ai-task/composables/useAiTask.js +11 -0
  30. package/dist/ai-task/config.d.ts +23 -0
  31. package/dist/ai-task/config.d.ts.map +1 -0
  32. package/dist/ai-task/config.js +23 -0
  33. package/dist/ai-task/context.d.ts +59 -0
  34. package/dist/ai-task/context.d.ts.map +1 -0
  35. package/dist/ai-task/context.js +42 -0
  36. package/dist/ai-task/dialog-state.d.ts +28 -0
  37. package/dist/ai-task/dialog-state.d.ts.map +1 -0
  38. package/dist/ai-task/dialog-state.js +28 -0
  39. package/dist/ai-task/index.d.ts +15 -0
  40. package/dist/ai-task/index.d.ts.map +1 -0
  41. package/dist/ai-task/index.js +24 -0
  42. package/dist/ai-task/inject.d.ts +307 -0
  43. package/dist/ai-task/inject.d.ts.map +1 -0
  44. package/dist/ai-task/inject.js +10 -0
  45. package/dist/ai-task/services/taskRunner.d.ts +11 -0
  46. package/dist/ai-task/services/taskRunner.d.ts.map +1 -0
  47. package/dist/ai-task/services/taskRunner.js +60 -0
  48. package/dist/ai-task/store/useAiTaskStore.d.ts +255 -0
  49. package/dist/ai-task/store/useAiTaskStore.d.ts.map +1 -0
  50. package/dist/ai-task/store/useAiTaskStore.js +230 -0
  51. package/dist/ai-task/style.css +3 -0
  52. package/dist/ai-task/types/index.d.ts +105 -0
  53. package/dist/ai-task/types/index.d.ts.map +1 -0
  54. package/dist/ai-task/useScopedStore.d.ts +255 -0
  55. package/dist/ai-task/useScopedStore.d.ts.map +1 -0
  56. package/dist/ai-task/useScopedStore.js +10 -0
  57. package/dist/ai-task/utils/runClientScript.d.ts +5 -0
  58. package/dist/ai-task/utils/runClientScript.d.ts.map +1 -0
  59. package/dist/ai-task/utils/runClientScript.js +26 -0
  60. package/dist/ai-task/utils/storage.d.ts +20 -0
  61. package/dist/ai-task/utils/storage.d.ts.map +1 -0
  62. package/dist/ai-task/utils/storage.js +45 -0
  63. package/dist/index.d.ts +6 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +31 -0
  66. package/dist/page-window/YcPageWindow.css +1 -0
  67. package/dist/page-window/YcPageWindow.d.ts +58 -0
  68. package/dist/page-window/YcPageWindow.d.ts.map +1 -0
  69. package/dist/page-window/YcPageWindow.vue.js +7 -0
  70. package/dist/page-window/YcPageWindow.vue2.js +230 -0
  71. package/dist/page-window/index.d.ts +5 -0
  72. package/dist/page-window/index.d.ts.map +1 -0
  73. package/dist/page-window/index.js +5 -0
  74. package/dist/page-window/style.css +1 -0
  75. package/dist/page-window/types.d.ts +32 -0
  76. package/dist/page-window/types.d.ts.map +1 -0
  77. package/dist/plugin.d.ts +14 -0
  78. package/dist/plugin.d.ts.map +1 -0
  79. package/dist/plugin.js +19 -0
  80. package/package.json +84 -0
@@ -0,0 +1,251 @@
1
+ import { defineComponent as N, ref as f, resolveComponent as m, openBlock as s, createBlock as d, Teleport as R, createVNode as a, Transition as B, withCtx as o, withDirectives as b, createElementVNode as i, normalizeClass as L, unref as t, toDisplayString as _, createTextVNode as k, createCommentVNode as u, createElementBlock as v, Fragment as M, renderList as D, vShow as h } from "vue";
2
+ import { Refresh as T, ArrowDown as E, Close as P, CircleCheck as F, CircleClose as U, Remove as J } from "@element-plus/icons-vue";
3
+ import { useScopedAiTaskStore as O } from "../useScopedStore.js";
4
+ const j = { class: "ai-task-panel" }, q = { class: "ai-task-panel__header" }, G = { class: "ai-task-panel__header-left" }, H = { class: "ai-task-panel__titles" }, K = { class: "ai-task-panel__subtitle" }, Q = { class: "ai-task-panel__title" }, W = { class: "ai-task-panel__header-actions" }, X = { class: "ai-task-panel__body" }, Y = {
5
+ key: 1,
6
+ class: "ai-task-list"
7
+ }, Z = { class: "ai-task-row__icon" }, ee = { class: "ai-task-row__main" }, te = { class: "ai-task-row__title" }, ne = { class: "ai-task-row__meta" }, le = { key: 0 }, se = {
8
+ key: 0,
9
+ class: "ai-task-row__summary"
10
+ }, ie = { class: "ai-task-row__ops" }, oe = {
11
+ key: 0,
12
+ class: "ai-task-panel__footer"
13
+ }, ae = { class: "result-pre" }, ce = /* @__PURE__ */ N({
14
+ __name: "AiTaskPanel",
15
+ setup(de) {
16
+ const l = O(), g = f(!1), C = f(""), y = f(null), S = {
17
+ pending: "等待中",
18
+ running: "执行中",
19
+ succeeded: "已完成",
20
+ failed: "失败",
21
+ cancelled: "已取消"
22
+ };
23
+ function V(r) {
24
+ return S[r] ?? r;
25
+ }
26
+ async function z(r) {
27
+ y.value = r.id;
28
+ try {
29
+ const n = r.result ?? await l.loadTaskResult(r.id);
30
+ C.value = JSON.stringify({ result: n, runId: r.runId }, null, 2), g.value = !0;
31
+ } finally {
32
+ y.value = null;
33
+ }
34
+ }
35
+ return (r, n) => {
36
+ const c = m("el-icon"), p = m("el-button"), $ = m("el-empty"), A = m("el-progress"), I = m("el-badge"), x = m("el-dialog");
37
+ return s(), d(R, { to: "body" }, [
38
+ a(B, { name: "ai-panel-slide" }, {
39
+ default: o(() => [
40
+ b(i("div", j, [
41
+ i("div", q, [
42
+ i("div", G, [
43
+ i("div", {
44
+ class: L(["ai-task-panel__icon", { spinning: t(l).activeCount > 0 }])
45
+ }, [
46
+ a(c, null, {
47
+ default: o(() => [
48
+ a(t(T))
49
+ ]),
50
+ _: 1
51
+ })
52
+ ], 2),
53
+ i("div", H, [
54
+ i("div", K, _(t(l).panelSubtitle), 1),
55
+ i("div", Q, _(t(l).panelTitle), 1)
56
+ ])
57
+ ]),
58
+ i("div", W, [
59
+ t(l).runningCount > 0 ? (s(), d(p, {
60
+ key: 0,
61
+ link: "",
62
+ type: "primary",
63
+ onClick: n[0] || (n[0] = (e) => t(l).cancelAll())
64
+ }, {
65
+ default: o(() => [...n[6] || (n[6] = [
66
+ k(" 取消全部 ", -1)
67
+ ])]),
68
+ _: 1
69
+ })) : u("", !0),
70
+ a(p, {
71
+ link: "",
72
+ onClick: n[1] || (n[1] = (e) => t(l).toggleMinimize())
73
+ }, {
74
+ default: o(() => [
75
+ a(c, null, {
76
+ default: o(() => [
77
+ a(t(E))
78
+ ]),
79
+ _: 1
80
+ })
81
+ ]),
82
+ _: 1
83
+ }),
84
+ a(p, {
85
+ link: "",
86
+ onClick: n[2] || (n[2] = (e) => t(l).hidePanel())
87
+ }, {
88
+ default: o(() => [
89
+ a(c, null, {
90
+ default: o(() => [
91
+ a(t(P))
92
+ ]),
93
+ _: 1
94
+ })
95
+ ]),
96
+ _: 1
97
+ })
98
+ ])
99
+ ]),
100
+ i("div", X, [
101
+ t(l).tasks.length ? (s(), v("div", Y, [
102
+ (s(!0), v(M, null, D(t(l).tasks, (e) => (s(), v("div", {
103
+ key: e.id,
104
+ class: "ai-task-row"
105
+ }, [
106
+ i("div", Z, [
107
+ e.status === "succeeded" ? (s(), d(c, {
108
+ key: 0,
109
+ class: "ok"
110
+ }, {
111
+ default: o(() => [
112
+ a(t(F))
113
+ ]),
114
+ _: 1
115
+ })) : e.status === "failed" ? (s(), d(c, {
116
+ key: 1,
117
+ class: "err"
118
+ }, {
119
+ default: o(() => [
120
+ a(t(U))
121
+ ]),
122
+ _: 1
123
+ })) : e.status === "running" || e.status === "pending" ? (s(), d(A, {
124
+ key: 2,
125
+ type: "circle",
126
+ percentage: e.progress,
127
+ width: 36,
128
+ "stroke-width": 3
129
+ }, null, 8, ["percentage"])) : (s(), d(c, {
130
+ key: 3,
131
+ class: "muted"
132
+ }, {
133
+ default: o(() => [
134
+ a(t(J))
135
+ ]),
136
+ _: 1
137
+ }))
138
+ ]),
139
+ i("div", ee, [
140
+ i("div", te, _(e.title), 1),
141
+ i("div", ne, [
142
+ i("span", null, _(V(e.status)), 1),
143
+ e.runId ? (s(), v("span", le, " · #" + _(e.runId), 1)) : u("", !0)
144
+ ]),
145
+ e.summary ? (s(), v("div", se, _(e.summary), 1)) : u("", !0)
146
+ ]),
147
+ i("div", ie, [
148
+ e.status === "running" || e.status === "pending" ? (s(), d(p, {
149
+ key: 0,
150
+ link: "",
151
+ type: "danger",
152
+ size: "small",
153
+ onClick: (w) => t(l).cancelTask(e.id)
154
+ }, {
155
+ default: o(() => [...n[7] || (n[7] = [
156
+ k(" 取消 ", -1)
157
+ ])]),
158
+ _: 1
159
+ }, 8, ["onClick"])) : u("", !0),
160
+ e.status === "succeeded" && e.runId ? (s(), d(p, {
161
+ key: 1,
162
+ link: "",
163
+ type: "primary",
164
+ size: "small",
165
+ loading: y.value === e.id,
166
+ onClick: (w) => z(e)
167
+ }, {
168
+ default: o(() => [...n[8] || (n[8] = [
169
+ k(" 结果 ", -1)
170
+ ])]),
171
+ _: 1
172
+ }, 8, ["loading", "onClick"])) : u("", !0),
173
+ e.status !== "running" && e.status !== "pending" ? (s(), d(p, {
174
+ key: 2,
175
+ link: "",
176
+ size: "small",
177
+ onClick: (w) => t(l).removeTask(e.id)
178
+ }, {
179
+ default: o(() => [...n[9] || (n[9] = [
180
+ k(" 移除 ", -1)
181
+ ])]),
182
+ _: 1
183
+ }, 8, ["onClick"])) : u("", !0)
184
+ ])
185
+ ]))), 128))
186
+ ])) : (s(), d($, {
187
+ key: 0,
188
+ description: "暂无 AI 任务",
189
+ "image-size": 64
190
+ }))
191
+ ]),
192
+ t(l).tasks.some((e) => e.status !== "running" && e.status !== "pending") ? (s(), v("div", oe, [
193
+ a(p, {
194
+ link: "",
195
+ type: "info",
196
+ onClick: n[3] || (n[3] = (e) => t(l).clearFinished())
197
+ }, {
198
+ default: o(() => [...n[10] || (n[10] = [
199
+ k("清除已完成", -1)
200
+ ])]),
201
+ _: 1
202
+ })
203
+ ])) : u("", !0)
204
+ ], 512), [
205
+ [h, t(l).panelVisible && !t(l).panelMinimized]
206
+ ])
207
+ ]),
208
+ _: 1
209
+ }),
210
+ b(i("div", {
211
+ class: "ai-task-panel-mini",
212
+ onClick: n[4] || (n[4] = (e) => t(l).toggleMinimize())
213
+ }, [
214
+ t(l).activeCount > 0 ? (s(), d(c, {
215
+ key: 0,
216
+ class: "spinning"
217
+ }, {
218
+ default: o(() => [
219
+ a(t(T))
220
+ ]),
221
+ _: 1
222
+ })) : u("", !0),
223
+ i("span", null, _(t(l).panelSubtitle), 1),
224
+ t(l).runningCount > 0 ? (s(), d(I, {
225
+ key: 1,
226
+ value: t(l).runningCount,
227
+ class: "m-l-8"
228
+ }, null, 8, ["value"])) : u("", !0)
229
+ ], 512), [
230
+ [h, t(l).panelVisible && t(l).panelMinimized]
231
+ ]),
232
+ a(x, {
233
+ modelValue: g.value,
234
+ "onUpdate:modelValue": n[5] || (n[5] = (e) => g.value = e),
235
+ title: "任务结果",
236
+ width: "640px",
237
+ "append-to-body": "",
238
+ "destroy-on-close": ""
239
+ }, {
240
+ default: o(() => [
241
+ i("pre", ae, _(C.value), 1)
242
+ ]),
243
+ _: 1
244
+ }, 8, ["modelValue"])
245
+ ]);
246
+ };
247
+ }
248
+ });
249
+ export {
250
+ ce as default
251
+ };
@@ -0,0 +1,26 @@
1
+ import { AiTaskFinishPayload, AiUseDialogProps } from '../types';
2
+ import { DefineComponent, ComponentOptionsMixin, PublicProps, ComponentProvideOptions } from 'vue';
3
+ declare function __VLS_template(): {
4
+ attrs: Partial<{}>;
5
+ slots: {
6
+ default?(_: {}): any;
7
+ };
8
+ refs: {};
9
+ rootEl: any;
10
+ };
11
+ type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
12
+ declare const __VLS_component: DefineComponent<AiUseDialogProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
13
+ finish: (data: AiTaskFinishPayload) => any;
14
+ }, string, PublicProps, Readonly<AiUseDialogProps> & Readonly<{
15
+ onFinish?: ((data: AiTaskFinishPayload) => any) | undefined;
16
+ }>, {
17
+ showDialog: boolean;
18
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
19
+ declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
20
+ export default _default;
21
+ type __VLS_WithTemplateSlots<T, S> = T & {
22
+ new (): {
23
+ $slots: S;
24
+ };
25
+ };
26
+ //# sourceMappingURL=AiTaskProvider.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AiTaskProvider.vue.d.ts","sourceRoot":"","sources":["../../../src/ai-task/components/AiTaskProvider.vue"],"names":[],"mappings":";AAKA;AAiEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAuDrE,iBAAS,cAAc;WAsCT,OAAO,IAA6B;;yBAVpB,GAAG;;;;EAehC;AAaD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe;;;;;;6EAQnB,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAapG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { defineComponent as n, provide as l, computed as u, onMounted as c, onUnmounted as d, openBlock as m, createElementBlock as h, Fragment as f, createBlock as T, normalizeProps as b, mergeProps as x, createCommentVNode as A, createVNode as M, renderSlot as k } from "vue";
2
+ import { createAiTaskApi as L } from "../context.js";
3
+ import { AI_TASK_STORE_KEY as _, AI_TASK_INJECT_KEY as w } from "../inject.js";
4
+ import { useAiTaskStore as P } from "../store/useAiTaskStore.js";
5
+ import B from "./AiUseDialog.vue.js";
6
+ import g from "./AiTaskPanel.vue.js";
7
+ const C = /* @__PURE__ */ n({
8
+ __name: "AiTaskProvider",
9
+ props: {
10
+ title: {},
11
+ freeText: {},
12
+ promptId: {},
13
+ autoMatch: { type: Boolean },
14
+ prompts: {},
15
+ showAutoMatch: { type: Boolean },
16
+ autoMatchLabel: {},
17
+ promptLabel: {},
18
+ freeTextLabel: {},
19
+ freeTextPlaceholder: {},
20
+ submitText: {},
21
+ width: {},
22
+ modelValue: { type: Boolean },
23
+ showDialog: { type: Boolean, default: !0 }
24
+ },
25
+ emits: ["finish"],
26
+ setup(r, { emit: i }) {
27
+ const e = r, p = i, o = P();
28
+ l(_, o), l(w, L(o));
29
+ const s = u(() => {
30
+ const t = {
31
+ title: e.title,
32
+ freeText: e.freeText,
33
+ promptId: e.promptId,
34
+ autoMatch: e.autoMatch,
35
+ prompts: e.prompts,
36
+ showAutoMatch: e.showAutoMatch,
37
+ autoMatchLabel: e.autoMatchLabel,
38
+ promptLabel: e.promptLabel,
39
+ freeTextLabel: e.freeTextLabel,
40
+ freeTextPlaceholder: e.freeTextPlaceholder,
41
+ submitText: e.submitText,
42
+ width: e.width
43
+ };
44
+ return e.modelValue !== void 0 && (t.modelValue = e.modelValue), t;
45
+ });
46
+ let a;
47
+ return c(() => {
48
+ o.hydrate(), a = o.onTaskFinish((t) => p("finish", t));
49
+ }), d(() => {
50
+ a == null || a();
51
+ }), (t, y) => (m(), h(f, null, [
52
+ r.showDialog !== !1 ? (m(), T(B, b(x({ key: 0 }, s.value)), null, 16)) : A("", !0),
53
+ M(g),
54
+ k(t.$slots, "default")
55
+ ], 64));
56
+ }
57
+ });
58
+ export {
59
+ C as default
60
+ };
@@ -0,0 +1,4 @@
1
+ import f from "./AiTaskProvider.vue.js";
2
+ export {
3
+ f as default
4
+ };
@@ -0,0 +1 @@
1
+ .ai-use-dialog[data-v-ba49baf7] .el-overlay{z-index:4000}.ai-use-dialog[data-v-ba49baf7] .el-dialog{z-index:4001}.ai-use-dialog[data-v-ba49baf7] .el-dialog__body{padding-top:8px}
@@ -0,0 +1,22 @@
1
+ import { AiUseDialogProps } from '../types';
2
+ import { DefineComponent, ComponentOptionsMixin, PublicProps, ComponentProvideOptions } from 'vue';
3
+ declare const _default: DefineComponent<AiUseDialogProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
4
+ "update:modelValue": (visible: boolean) => any;
5
+ submitted: (taskId: string) => any;
6
+ }, string, PublicProps, Readonly<AiUseDialogProps> & Readonly<{
7
+ "onUpdate:modelValue"?: ((visible: boolean) => any) | undefined;
8
+ onSubmitted?: ((taskId: string) => any) | undefined;
9
+ }>, {
10
+ title: string;
11
+ freeText: string;
12
+ autoMatch: boolean;
13
+ showAutoMatch: boolean;
14
+ autoMatchLabel: string;
15
+ promptLabel: string;
16
+ freeTextLabel: string;
17
+ freeTextPlaceholder: string;
18
+ submitText: string;
19
+ width: string | number;
20
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
21
+ export default _default;
22
+ //# sourceMappingURL=AiUseDialog.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AiUseDialog.vue.d.ts","sourceRoot":"","sources":["../../../src/ai-task/components/AiUseDialog.vue"],"names":[],"mappings":";AAgDA;AAgRA,OAAO,KAAK,EAAsC,gBAAgB,EAAE,MAAM,UAAU,CAAA;;;;;;;;;;;;;;;;;;;AAmcpF,wBASG"}
@@ -0,0 +1,7 @@
1
+ import o from "./AiUseDialog.vue2.js";
2
+ /* empty css */
3
+ import a from "../../_virtual/_plugin-vue_export-helper.js";
4
+ const i = /* @__PURE__ */ a(o, [["__scopeId", "data-v-ba49baf7"]]);
5
+ export {
6
+ i as default
7
+ };
@@ -0,0 +1,224 @@
1
+ import { defineComponent as $, computed as A, ref as v, watch as h, onMounted as j, onUnmounted as z, resolveComponent as m, openBlock as g, createBlock as V, withCtx as r, createVNode as p, createCommentVNode as H, createElementBlock as K, Fragment as Q, renderList as R, createTextVNode as C, toDisplayString as W } from "vue";
2
+ import { ElMessage as x } from "element-plus";
3
+ import { aiDialogState as s, hideAiDialog as X, AI_DIALOG_OPEN_EVENT as L } from "../dialog-state.js";
4
+ import { listPrompts as Y } from "../api/prompt.js";
5
+ import { getAiTaskConfig as Z } from "../config.js";
6
+ import { useScopedAiTaskStore as ee } from "../useScopedStore.js";
7
+ const ie = /* @__PURE__ */ $({
8
+ __name: "AiUseDialog",
9
+ props: {
10
+ title: { default: "AI 生成" },
11
+ freeText: { default: "" },
12
+ promptId: {},
13
+ autoMatch: { type: Boolean, default: !1 },
14
+ prompts: {},
15
+ showAutoMatch: { type: Boolean, default: !0 },
16
+ autoMatchLabel: { default: "自动匹配提示词" },
17
+ promptLabel: { default: "提示词" },
18
+ freeTextLabel: { default: "需求描述" },
19
+ freeTextPlaceholder: { default: "描述要生成的页面或项目 JSON" },
20
+ submitText: { default: "提交任务(后台异步)" },
21
+ width: { default: "520px" },
22
+ modelValue: { type: Boolean },
23
+ showDialog: { type: Boolean }
24
+ },
25
+ emits: ["update:modelValue", "submitted"],
26
+ setup(d, { emit: O }) {
27
+ const o = d, I = O, k = ee(), n = A(() => o.modelValue !== void 0), u = v(!1);
28
+ h(
29
+ () => o.modelValue,
30
+ (e) => {
31
+ n.value && (u.value = !!e);
32
+ },
33
+ { immediate: !0 }
34
+ ), h(u, (e) => {
35
+ if (n.value) {
36
+ I("update:modelValue", e);
37
+ return;
38
+ }
39
+ s.visible = e, e || X();
40
+ }), h(
41
+ () => s.visible,
42
+ (e) => {
43
+ n.value || (u.value = e);
44
+ },
45
+ { immediate: !0 }
46
+ );
47
+ function w(e) {
48
+ if (n.value) return;
49
+ const l = e.detail ?? {};
50
+ M(l), u.value = !0;
51
+ }
52
+ j(() => {
53
+ globalThis.addEventListener(L, w), n.value || (u.value = s.visible);
54
+ }), z(() => {
55
+ globalThis.removeEventListener(L, w);
56
+ });
57
+ const B = A(
58
+ () => (n.value ? void 0 : s.options.title) ?? o.title ?? "AI 生成"
59
+ ), t = v({
60
+ freeText: o.freeText,
61
+ promptId: o.promptId,
62
+ autoMatch: o.autoMatch
63
+ }), f = v(o.prompts ? [...o.prompts] : []), T = v(!1), b = v(!1), y = v();
64
+ function M(e) {
65
+ var l, i;
66
+ t.value.freeText = e.freeText ?? o.freeText ?? "", t.value.promptId = e.promptId ?? o.promptId, t.value.autoMatch = e.autoMatch ?? o.autoMatch ?? !1, y.value = e.onFinish, (l = e.prompts) != null && l.length ? f.value = [...e.prompts] : (i = o.prompts) != null && i.length && (f.value = [...o.prompts]);
67
+ }
68
+ async function D() {
69
+ if (!(f.value.length > 0)) {
70
+ T.value = !0;
71
+ try {
72
+ const e = Z().listPrompts;
73
+ f.value = e ? await e() : await Y();
74
+ } catch {
75
+ x.warning("加载提示词失败");
76
+ } finally {
77
+ T.value = !1;
78
+ }
79
+ }
80
+ }
81
+ function E() {
82
+ n.value ? M({}) : M(s.options), D();
83
+ }
84
+ h(
85
+ () => o.prompts,
86
+ (e) => {
87
+ e != null && e.length && (f.value = [...e]);
88
+ },
89
+ { deep: !0 }
90
+ ), h(
91
+ () => [o.freeText, o.promptId, o.autoMatch],
92
+ ([e, l, i]) => {
93
+ u.value || (t.value.freeText = e ?? "", t.value.promptId = l, t.value.autoMatch = i ?? !1);
94
+ }
95
+ );
96
+ function P() {
97
+ t.value.autoMatch && (t.value.promptId = void 0);
98
+ }
99
+ function S() {
100
+ b.value = !1;
101
+ }
102
+ async function N() {
103
+ var i, c;
104
+ if (!t.value.freeText.trim()) {
105
+ x.warning("请填写需求描述");
106
+ return;
107
+ }
108
+ if (!t.value.autoMatch && !t.value.promptId) {
109
+ x.warning("请选择提示词或开启自动匹配");
110
+ return;
111
+ }
112
+ b.value = !0;
113
+ const e = n.value ? y.value : s.options.onFinish, l = k.enqueue({
114
+ freeText: t.value.freeText.trim(),
115
+ promptId: t.value.promptId,
116
+ autoMatch: t.value.autoMatch && !t.value.promptId ? !0 : void 0,
117
+ showPanel: !0,
118
+ onFinish: e
119
+ });
120
+ n.value ? I("submitted", l) : (c = (i = s.options).onSubmitted) == null || c.call(i, l), u.value = !1, b.value = !1, x.success("已加入任务队列,可在任务面板查看进度");
121
+ }
122
+ return (e, l) => {
123
+ const i = m("el-switch"), c = m("el-form-item"), U = m("el-option"), F = m("el-select"), q = m("el-input"), G = m("el-form"), _ = m("el-button"), J = m("el-dialog");
124
+ return g(), V(J, {
125
+ modelValue: u.value,
126
+ "onUpdate:modelValue": l[4] || (l[4] = (a) => u.value = a),
127
+ title: B.value,
128
+ width: d.width,
129
+ "append-to-body": "",
130
+ class: "ai-use-dialog",
131
+ onClosed: S,
132
+ onOpen: E
133
+ }, {
134
+ footer: r(() => [
135
+ p(_, {
136
+ onClick: l[3] || (l[3] = (a) => u.value = !1)
137
+ }, {
138
+ default: r(() => [...l[5] || (l[5] = [
139
+ C("取消", -1)
140
+ ])]),
141
+ _: 1
142
+ }),
143
+ p(_, {
144
+ type: "primary",
145
+ loading: b.value,
146
+ onClick: N
147
+ }, {
148
+ default: r(() => [
149
+ C(W(d.submitText), 1)
150
+ ]),
151
+ _: 1
152
+ }, 8, ["loading"])
153
+ ]),
154
+ default: r(() => [
155
+ p(G, { "label-position": "top" }, {
156
+ default: r(() => [
157
+ d.showAutoMatch ? (g(), V(c, {
158
+ key: 0,
159
+ label: d.autoMatchLabel
160
+ }, {
161
+ default: r(() => [
162
+ p(i, {
163
+ modelValue: t.value.autoMatch,
164
+ "onUpdate:modelValue": l[0] || (l[0] = (a) => t.value.autoMatch = a),
165
+ "active-text": "按需求自动选",
166
+ "inactive-text": "手动指定",
167
+ onChange: P
168
+ }, null, 8, ["modelValue"])
169
+ ]),
170
+ _: 1
171
+ }, 8, ["label"])) : H("", !0),
172
+ p(c, {
173
+ label: d.promptLabel,
174
+ required: !t.value.autoMatch
175
+ }, {
176
+ default: r(() => [
177
+ p(F, {
178
+ modelValue: t.value.promptId,
179
+ "onUpdate:modelValue": l[1] || (l[1] = (a) => t.value.promptId = a),
180
+ filterable: "",
181
+ clearable: "",
182
+ placeholder: t.value.autoMatch ? "留空则自动匹配" : "请选择提示词",
183
+ style: { width: "100%" },
184
+ loading: T.value
185
+ }, {
186
+ default: r(() => [
187
+ (g(!0), K(Q, null, R(f.value, (a) => (g(), V(U, {
188
+ key: a.id,
189
+ label: a.name,
190
+ value: a.id
191
+ }, null, 8, ["label", "value"]))), 128))
192
+ ]),
193
+ _: 1
194
+ }, 8, ["modelValue", "placeholder", "loading"])
195
+ ]),
196
+ _: 1
197
+ }, 8, ["label", "required"]),
198
+ p(c, {
199
+ label: d.freeTextLabel,
200
+ required: ""
201
+ }, {
202
+ default: r(() => [
203
+ p(q, {
204
+ modelValue: t.value.freeText,
205
+ "onUpdate:modelValue": l[2] || (l[2] = (a) => t.value.freeText = a),
206
+ type: "textarea",
207
+ rows: 4,
208
+ placeholder: d.freeTextPlaceholder
209
+ }, null, 8, ["modelValue", "placeholder"])
210
+ ]),
211
+ _: 1
212
+ }, 8, ["label"])
213
+ ]),
214
+ _: 1
215
+ })
216
+ ]),
217
+ _: 1
218
+ }, 8, ["modelValue", "title", "width"]);
219
+ };
220
+ }
221
+ });
222
+ export {
223
+ ie as default
224
+ };
@@ -0,0 +1,62 @@
1
+ import { Ref, ComputedRef } from 'vue';
2
+ import { AiTaskStatus, AiTaskItem, AiUseDialogOptions, AiTaskSubmitOptions } from '..';
3
+ import { AiTaskFinishHandler } from './useAiTask';
4
+ export type { AiTaskFinishHandler, AiTaskFinishPayload } from '../types';
5
+ /**
6
+ * AI 任务组件对外 API。
7
+ * 须在 YcAiTaskProvider 内部使用(通过 inject 与弹窗共用同一 store)。
8
+ */
9
+ export declare function useAiTask(): {
10
+ tasks: Ref<{
11
+ id: string;
12
+ title: string;
13
+ freeText: string;
14
+ promptId?: number | undefined;
15
+ autoMatch?: boolean | undefined;
16
+ status: AiTaskStatus;
17
+ progress: number;
18
+ summary: string;
19
+ runId?: number | undefined;
20
+ result?: Record<string, unknown> | undefined;
21
+ errorMessage?: string | undefined;
22
+ createdAt: number;
23
+ finishedAt?: number | undefined;
24
+ logs: string[];
25
+ }[], AiTaskItem[] | {
26
+ id: string;
27
+ title: string;
28
+ freeText: string;
29
+ promptId?: number | undefined;
30
+ autoMatch?: boolean | undefined;
31
+ status: AiTaskStatus;
32
+ progress: number;
33
+ summary: string;
34
+ runId?: number | undefined;
35
+ result?: Record<string, unknown> | undefined;
36
+ errorMessage?: string | undefined;
37
+ createdAt: number;
38
+ finishedAt?: number | undefined;
39
+ logs: string[];
40
+ }[]>;
41
+ panelVisible: Ref<boolean, boolean>;
42
+ panelMinimized: Ref<boolean, boolean>;
43
+ dialogVisible: Ref<boolean, boolean>;
44
+ runningCount: ComputedRef<number>;
45
+ activeCount: ComputedRef<number>;
46
+ panelTitle: ComputedRef<"AI 处理中" | "部分任务失败" | "AI 任务">;
47
+ panelSubtitle: ComputedRef<string>;
48
+ openUseDialog: (options?: AiUseDialogOptions) => void;
49
+ closeUseDialog: () => void;
50
+ openTaskPanel: () => void;
51
+ hideTaskPanel: () => void;
52
+ togglePanelMinimize: () => void;
53
+ submitTask: (options: AiTaskSubmitOptions) => string;
54
+ cancelTask: (id: string) => Promise<void>;
55
+ cancelAll: () => void;
56
+ clearFinished: () => void;
57
+ removeTask: (id: string) => void;
58
+ loadTaskResult: (id: string) => Promise<Record<string, unknown> | null>;
59
+ refreshTasks: () => Promise<void>;
60
+ onTaskFinish: (handler: AiTaskFinishHandler) => () => boolean;
61
+ };
62
+ //# sourceMappingURL=useAiTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAiTask.d.ts","sourceRoot":"","sources":["../../../src/ai-task/composables/useAiTask.ts"],"names":[],"mappings":";;;AAKA,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAExE;;;GAGG;AACH,wBAAgB,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMxB"}