iskills-vue-sdk 0.1.0-beta.1
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.
- package/dist/index.js +479 -0
- package/dist/index.umd.cjs +1 -0
- package/dist/style.css +1 -0
- package/package.json +51 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
var H = Object.defineProperty;
|
|
2
|
+
var L = (n, e, t) => e in n ? H(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var F = (n, e, t) => L(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { ref as h, computed as E, shallowRef as P, defineComponent as D, provide as K, reactive as R, openBlock as g, createElementBlock as p, renderSlot as G, createElementVNode as f, toDisplayString as I, withDirectives as V, withKeys as N, vModelDynamic as J, Fragment as B, renderList as O, normalizeClass as T, createCommentVNode as x, inject as M, watch as Q, nextTick as W, unref as k, createStaticVNode as X, createBlock as Y, vModelText as Z } from "vue";
|
|
5
|
+
class ee {
|
|
6
|
+
constructor(e) {
|
|
7
|
+
F(this, "config");
|
|
8
|
+
this.config = e;
|
|
9
|
+
}
|
|
10
|
+
getHeaders() {
|
|
11
|
+
const e = {
|
|
12
|
+
"Content-Type": "application/json"
|
|
13
|
+
};
|
|
14
|
+
return this.config.apiKey && (e.Authorization = `Bearer ${this.config.apiKey}`), e;
|
|
15
|
+
}
|
|
16
|
+
async request(e, t, s, a) {
|
|
17
|
+
const i = new URL(`/api${t}`, this.config.baseUrl);
|
|
18
|
+
s && Object.entries(s).forEach(([o, l]) => {
|
|
19
|
+
l != null && i.searchParams.append(o, String(l));
|
|
20
|
+
});
|
|
21
|
+
const u = await fetch(i.toString(), {
|
|
22
|
+
method: e,
|
|
23
|
+
headers: this.getHeaders(),
|
|
24
|
+
body: a ? JSON.stringify(a) : void 0,
|
|
25
|
+
signal: AbortSignal.timeout(this.config.timeout || 3e4)
|
|
26
|
+
});
|
|
27
|
+
if (!u.ok)
|
|
28
|
+
throw new Error(`HTTP Error: ${u.status}`);
|
|
29
|
+
const r = await u.json();
|
|
30
|
+
if (r.code !== 0 && r.code !== 200)
|
|
31
|
+
throw new Error(r.message || "Unknown error");
|
|
32
|
+
return r.data;
|
|
33
|
+
}
|
|
34
|
+
async get(e, t) {
|
|
35
|
+
return this.request("GET", e, t);
|
|
36
|
+
}
|
|
37
|
+
async post(e, t) {
|
|
38
|
+
return this.request("POST", e, void 0, t);
|
|
39
|
+
}
|
|
40
|
+
async put(e, t) {
|
|
41
|
+
return this.request("PUT", e, void 0, t);
|
|
42
|
+
}
|
|
43
|
+
async delete(e) {
|
|
44
|
+
return this.request("DELETE", e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function te(n) {
|
|
48
|
+
return new ee(n);
|
|
49
|
+
}
|
|
50
|
+
function Me(n) {
|
|
51
|
+
const e = h([]), t = h(!1), s = h(null), a = E(
|
|
52
|
+
() => e.value.filter((o) => o.status === "enabled")
|
|
53
|
+
);
|
|
54
|
+
async function i(o) {
|
|
55
|
+
t.value = !0, s.value = null;
|
|
56
|
+
try {
|
|
57
|
+
const l = await n.get("/agents/list", o);
|
|
58
|
+
e.value = l.list || [];
|
|
59
|
+
} catch (l) {
|
|
60
|
+
throw s.value = l.message, l;
|
|
61
|
+
} finally {
|
|
62
|
+
t.value = !1;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function u(o) {
|
|
66
|
+
return n.get(`/agents/${o}`);
|
|
67
|
+
}
|
|
68
|
+
function r(o) {
|
|
69
|
+
return e.value.find((l) => l.agent_id === o);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
agents: e,
|
|
73
|
+
loading: t,
|
|
74
|
+
error: s,
|
|
75
|
+
enabledAgents: a,
|
|
76
|
+
fetchAgents: i,
|
|
77
|
+
getAgent: u,
|
|
78
|
+
getAgentByAgentId: r
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function Pe(n) {
|
|
82
|
+
const e = h([]), t = h(!1), s = h(null);
|
|
83
|
+
async function a(o) {
|
|
84
|
+
t.value = !0, s.value = null;
|
|
85
|
+
try {
|
|
86
|
+
const l = await n.get("/agent-flows/", o);
|
|
87
|
+
e.value = l.list || [];
|
|
88
|
+
} catch (l) {
|
|
89
|
+
throw s.value = l.message, l;
|
|
90
|
+
} finally {
|
|
91
|
+
t.value = !1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function i(o) {
|
|
95
|
+
return n.get(`/agent-flows/${o}`);
|
|
96
|
+
}
|
|
97
|
+
async function u(o) {
|
|
98
|
+
return n.get(`/agent-flows/${o}/export`);
|
|
99
|
+
}
|
|
100
|
+
function r(o) {
|
|
101
|
+
return e.value.find((l) => l.agent_id === o && l.is_main_flow);
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
flows: e,
|
|
105
|
+
loading: t,
|
|
106
|
+
error: s,
|
|
107
|
+
fetchFlows: a,
|
|
108
|
+
getFlow: i,
|
|
109
|
+
exportFlow: u,
|
|
110
|
+
getMainFlow: r
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function ne(n) {
|
|
114
|
+
const e = h([]), t = h(!1), s = P(null), a = h(null), i = h(null);
|
|
115
|
+
function u(c) {
|
|
116
|
+
e.value.push({
|
|
117
|
+
id: Date.now(),
|
|
118
|
+
role: "user",
|
|
119
|
+
content: c,
|
|
120
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function r(c) {
|
|
124
|
+
e.value.push({
|
|
125
|
+
id: Date.now() + 1,
|
|
126
|
+
role: "assistant",
|
|
127
|
+
content: c,
|
|
128
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function o(c) {
|
|
132
|
+
e.value.push({
|
|
133
|
+
id: Date.now() + 2,
|
|
134
|
+
role: "system",
|
|
135
|
+
content: c,
|
|
136
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async function l(c, d, S) {
|
|
140
|
+
t.value = !0, i.value = null, u(d);
|
|
141
|
+
try {
|
|
142
|
+
const q = await n.post(
|
|
143
|
+
"/agent-executions",
|
|
144
|
+
{
|
|
145
|
+
flow_id: c,
|
|
146
|
+
variables: S
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
a.value = q.execution_id;
|
|
150
|
+
const C = await n.post(
|
|
151
|
+
`/agent-executions/${q.execution_id}/run`,
|
|
152
|
+
{ user_input: d }
|
|
153
|
+
);
|
|
154
|
+
return s.value = C, C.output && r(String(C.output)), C;
|
|
155
|
+
} catch (q) {
|
|
156
|
+
throw i.value = q.message, o(`执行失败: ${i.value}`), q;
|
|
157
|
+
} finally {
|
|
158
|
+
t.value = !1;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async function _(c) {
|
|
162
|
+
if (!a.value)
|
|
163
|
+
throw new Error("没有待处理的执行");
|
|
164
|
+
t.value = !0, i.value = null;
|
|
165
|
+
try {
|
|
166
|
+
const d = await n.post(
|
|
167
|
+
`/agent-executions/${a.value}/resume`,
|
|
168
|
+
c
|
|
169
|
+
);
|
|
170
|
+
return s.value = d, d.output && r(String(d.output)), d;
|
|
171
|
+
} catch (d) {
|
|
172
|
+
throw i.value = d.message, o(`恢复执行失败: ${i.value}`), d;
|
|
173
|
+
} finally {
|
|
174
|
+
t.value = !1;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function $() {
|
|
178
|
+
e.value = [];
|
|
179
|
+
}
|
|
180
|
+
function m() {
|
|
181
|
+
e.value = [], s.value = null, a.value = null, i.value = null;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
messages: e,
|
|
185
|
+
loading: t,
|
|
186
|
+
result: s,
|
|
187
|
+
executionId: a,
|
|
188
|
+
error: i,
|
|
189
|
+
execute: l,
|
|
190
|
+
resume: _,
|
|
191
|
+
clearMessages: $,
|
|
192
|
+
reset: m,
|
|
193
|
+
addUserMessage: u,
|
|
194
|
+
addAssistantMessage: r,
|
|
195
|
+
addSystemMessage: o
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function se() {
|
|
199
|
+
const n = P(null), e = h(!1), t = h(null);
|
|
200
|
+
function s(u) {
|
|
201
|
+
return n.value = u, e.value = !0, new Promise((r) => {
|
|
202
|
+
t.value = r;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function a(u) {
|
|
206
|
+
t.value && (t.value(u), t.value = null), n.value = null, e.value = !1;
|
|
207
|
+
}
|
|
208
|
+
function i() {
|
|
209
|
+
t.value && (t.value({ value: null }), t.value = null), n.value = null, e.value = !1;
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
interaction: n,
|
|
213
|
+
waiting: e,
|
|
214
|
+
showInteraction: s,
|
|
215
|
+
submit: a,
|
|
216
|
+
cancel: i
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const ae = { class: "iskills-provider" }, ie = /* @__PURE__ */ D({
|
|
220
|
+
__name: "IskillsProvider",
|
|
221
|
+
props: {
|
|
222
|
+
baseUrl: {},
|
|
223
|
+
apiKey: {},
|
|
224
|
+
theme: {},
|
|
225
|
+
locale: {}
|
|
226
|
+
},
|
|
227
|
+
setup(n) {
|
|
228
|
+
const e = n, t = te({
|
|
229
|
+
baseUrl: e.baseUrl,
|
|
230
|
+
apiKey: e.apiKey
|
|
231
|
+
});
|
|
232
|
+
return K("iskills-api", t), K("iskills-config", R({
|
|
233
|
+
baseUrl: e.baseUrl,
|
|
234
|
+
theme: e.theme || "light",
|
|
235
|
+
locale: e.locale || "zh-CN"
|
|
236
|
+
})), (s, a) => (g(), p("div", ae, [
|
|
237
|
+
G(s.$slots, "default", {}, void 0, !0)
|
|
238
|
+
]));
|
|
239
|
+
}
|
|
240
|
+
}), U = (n, e) => {
|
|
241
|
+
const t = n.__vccOpts || n;
|
|
242
|
+
for (const [s, a] of e)
|
|
243
|
+
t[s] = a;
|
|
244
|
+
return t;
|
|
245
|
+
}, Ve = /* @__PURE__ */ U(ie, [["__scopeId", "data-v-0f46f6a7"]]), oe = { class: "interaction-dialog" }, le = { class: "dialog-content" }, re = { class: "dialog-header" }, ce = { class: "dialog-body" }, ue = { class: "prompt" }, de = {
|
|
246
|
+
key: 0,
|
|
247
|
+
class: "input-group"
|
|
248
|
+
}, ve = ["type", "placeholder"], fe = {
|
|
249
|
+
key: 1,
|
|
250
|
+
class: "confirm-group"
|
|
251
|
+
}, ge = {
|
|
252
|
+
key: 2,
|
|
253
|
+
class: "select-group"
|
|
254
|
+
}, pe = ["onClick"], me = { class: "option-label" }, he = {
|
|
255
|
+
key: 0,
|
|
256
|
+
class: "option-description"
|
|
257
|
+
}, _e = { class: "dialog-footer" }, ye = ["disabled"], we = /* @__PURE__ */ D({
|
|
258
|
+
__name: "InteractionDialog",
|
|
259
|
+
props: {
|
|
260
|
+
request: {}
|
|
261
|
+
},
|
|
262
|
+
emits: ["submit", "cancel"],
|
|
263
|
+
setup(n, { emit: e }) {
|
|
264
|
+
const t = n, s = e, a = h(t.request.default_value || ""), i = h(null), u = E(() => {
|
|
265
|
+
switch (t.request.type) {
|
|
266
|
+
case "input":
|
|
267
|
+
return "请输入";
|
|
268
|
+
case "confirm":
|
|
269
|
+
return "请确认";
|
|
270
|
+
case "select":
|
|
271
|
+
return "请选择";
|
|
272
|
+
default:
|
|
273
|
+
return "交互";
|
|
274
|
+
}
|
|
275
|
+
}), r = E(() => t.request.type === "input" ? a.value.toString().trim().length > 0 : t.request.type === "select" ? i.value !== null : !0);
|
|
276
|
+
function o() {
|
|
277
|
+
var $;
|
|
278
|
+
if (r.value) {
|
|
279
|
+
if (t.request.type === "input")
|
|
280
|
+
s("submit", { value: a.value });
|
|
281
|
+
else if (t.request.type === "select" && i.value !== null) {
|
|
282
|
+
const m = ($ = t.request.options) == null ? void 0 : $[i.value];
|
|
283
|
+
s("submit", {
|
|
284
|
+
value: (m == null ? void 0 : m.value) ?? (m == null ? void 0 : m.id) ?? i.value,
|
|
285
|
+
option_id: m == null ? void 0 : m.id
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function l() {
|
|
291
|
+
s("submit", { value: !0 });
|
|
292
|
+
}
|
|
293
|
+
function _() {
|
|
294
|
+
s("cancel");
|
|
295
|
+
}
|
|
296
|
+
return ($, m) => (g(), p("div", oe, [
|
|
297
|
+
f("div", {
|
|
298
|
+
class: "dialog-overlay",
|
|
299
|
+
onClick: _
|
|
300
|
+
}),
|
|
301
|
+
f("div", le, [
|
|
302
|
+
f("div", re, [
|
|
303
|
+
f("h3", null, I(u.value), 1)
|
|
304
|
+
]),
|
|
305
|
+
f("div", ce, [
|
|
306
|
+
f("p", ue, I(n.request.prompt), 1),
|
|
307
|
+
n.request.type === "input" ? (g(), p("div", de, [
|
|
308
|
+
V(f("input", {
|
|
309
|
+
"onUpdate:modelValue": m[0] || (m[0] = (c) => a.value = c),
|
|
310
|
+
type: n.request.input_type || "text",
|
|
311
|
+
placeholder: n.request.prompt,
|
|
312
|
+
onKeyup: N(o, ["enter"])
|
|
313
|
+
}, null, 40, ve), [
|
|
314
|
+
[J, a.value]
|
|
315
|
+
])
|
|
316
|
+
])) : n.request.type === "confirm" ? (g(), p("div", fe, [
|
|
317
|
+
f("button", {
|
|
318
|
+
class: "btn btn-primary",
|
|
319
|
+
onClick: l
|
|
320
|
+
}, "确认"),
|
|
321
|
+
f("button", {
|
|
322
|
+
class: "btn btn-secondary",
|
|
323
|
+
onClick: _
|
|
324
|
+
}, "取消")
|
|
325
|
+
])) : n.request.type === "select" ? (g(), p("div", ge, [
|
|
326
|
+
(g(!0), p(B, null, O(n.request.options, (c, d) => (g(), p("div", {
|
|
327
|
+
key: d,
|
|
328
|
+
class: T(["select-option", { selected: i.value === d }]),
|
|
329
|
+
onClick: (S) => i.value = d
|
|
330
|
+
}, [
|
|
331
|
+
f("div", me, I(c.label), 1),
|
|
332
|
+
c.description ? (g(), p("div", he, I(c.description), 1)) : x("", !0)
|
|
333
|
+
], 10, pe))), 128))
|
|
334
|
+
])) : x("", !0)
|
|
335
|
+
]),
|
|
336
|
+
f("div", _e, [
|
|
337
|
+
n.request.type === "input" || n.request.type === "select" ? (g(), p("button", {
|
|
338
|
+
key: 0,
|
|
339
|
+
class: "btn btn-primary",
|
|
340
|
+
disabled: !r.value,
|
|
341
|
+
onClick: o
|
|
342
|
+
}, " 提交 ", 8, ye)) : x("", !0),
|
|
343
|
+
f("button", {
|
|
344
|
+
class: "btn btn-secondary",
|
|
345
|
+
onClick: _
|
|
346
|
+
}, "取消")
|
|
347
|
+
])
|
|
348
|
+
])
|
|
349
|
+
]));
|
|
350
|
+
}
|
|
351
|
+
}), be = /* @__PURE__ */ U(we, [["__scopeId", "data-v-fa8759d4"]]), ke = { class: "message-avatar" }, $e = { key: 0 }, qe = { key: 1 }, Ce = { key: 2 }, Ie = { class: "message-content" }, xe = { class: "message-text" }, Se = { class: "message-time" }, Ae = {
|
|
352
|
+
key: 0,
|
|
353
|
+
class: "chat-loading"
|
|
354
|
+
}, Ee = {
|
|
355
|
+
key: 1,
|
|
356
|
+
class: "chat-input"
|
|
357
|
+
}, Te = ["disabled"], De = ["disabled"], Ue = /* @__PURE__ */ D({
|
|
358
|
+
__name: "AgentChat",
|
|
359
|
+
props: {
|
|
360
|
+
agentId: {},
|
|
361
|
+
flowId: {},
|
|
362
|
+
initialVariables: {}
|
|
363
|
+
},
|
|
364
|
+
emits: ["complete", "error", "interaction"],
|
|
365
|
+
setup(n, { emit: e }) {
|
|
366
|
+
const t = n, s = e, a = M("iskills-api"), i = M("iskills-config"), {
|
|
367
|
+
messages: u,
|
|
368
|
+
loading: r,
|
|
369
|
+
execute: o,
|
|
370
|
+
resume: l
|
|
371
|
+
} = ne(a), {
|
|
372
|
+
interaction: _,
|
|
373
|
+
submit: $,
|
|
374
|
+
cancel: m
|
|
375
|
+
} = se(), c = h(""), d = h();
|
|
376
|
+
Q(u, async () => {
|
|
377
|
+
await W(), d.value && (d.value.scrollTop = d.value.scrollHeight);
|
|
378
|
+
}, { deep: !0 });
|
|
379
|
+
async function S() {
|
|
380
|
+
const w = c.value.trim();
|
|
381
|
+
if (!(!w || r.value)) {
|
|
382
|
+
c.value = "";
|
|
383
|
+
try {
|
|
384
|
+
const v = t.flowId || await j(), b = await o(v, w, t.initialVariables);
|
|
385
|
+
b.needs_interaction && b.interaction_data ? (_.value = b.interaction_data, s("interaction", b.interaction_data)) : s("complete", b);
|
|
386
|
+
} catch (v) {
|
|
387
|
+
s("error", v);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
async function q(w) {
|
|
392
|
+
await $(w), _.value = null;
|
|
393
|
+
try {
|
|
394
|
+
const v = await l(w);
|
|
395
|
+
v.needs_interaction && v.interaction_data ? (_.value = v.interaction_data, s("interaction", v.interaction_data)) : s("complete", v);
|
|
396
|
+
} catch (v) {
|
|
397
|
+
s("error", v);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function C() {
|
|
401
|
+
m(), _.value = null;
|
|
402
|
+
}
|
|
403
|
+
async function j() {
|
|
404
|
+
const v = ((await a.get("/agents/list")).list || []).find((A) => A.agent_id === t.agentId);
|
|
405
|
+
if (!v) throw new Error(`Agent ${t.agentId} not found`);
|
|
406
|
+
const y = ((await a.get("/agent-flows/", {
|
|
407
|
+
agent_id: v.agent_id
|
|
408
|
+
})).list || []).find((A) => A.is_main_flow);
|
|
409
|
+
if (!y) throw new Error("No main flow found");
|
|
410
|
+
return y.flow_id;
|
|
411
|
+
}
|
|
412
|
+
function z(w) {
|
|
413
|
+
return w.toLocaleTimeString("zh-CN", {
|
|
414
|
+
hour: "2-digit",
|
|
415
|
+
minute: "2-digit"
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
return (w, v) => {
|
|
419
|
+
var b;
|
|
420
|
+
return g(), p("div", {
|
|
421
|
+
class: T(["agent-chat", [`theme-${((b = k(i)) == null ? void 0 : b.theme) || "light"}`]])
|
|
422
|
+
}, [
|
|
423
|
+
f("div", {
|
|
424
|
+
class: "chat-messages",
|
|
425
|
+
ref_key: "messagesRef",
|
|
426
|
+
ref: d
|
|
427
|
+
}, [
|
|
428
|
+
(g(!0), p(B, null, O(k(u), (y) => (g(), p("div", {
|
|
429
|
+
key: y.id,
|
|
430
|
+
class: T(["chat-message", [`message-${y.role}`]])
|
|
431
|
+
}, [
|
|
432
|
+
f("div", ke, [
|
|
433
|
+
y.role === "user" ? (g(), p("span", $e, "👤")) : y.role === "assistant" ? (g(), p("span", qe, "🤖")) : (g(), p("span", Ce, "ℹ️"))
|
|
434
|
+
]),
|
|
435
|
+
f("div", Ie, [
|
|
436
|
+
f("div", xe, I(y.content), 1),
|
|
437
|
+
f("div", Se, I(z(y.timestamp)), 1)
|
|
438
|
+
])
|
|
439
|
+
], 2))), 128)),
|
|
440
|
+
k(r) ? (g(), p("div", Ae, [...v[1] || (v[1] = [
|
|
441
|
+
X('<div class="message-avatar" data-v-71936282>🤖</div><div class="loading-dots" data-v-71936282><span class="dot" data-v-71936282></span><span class="dot" data-v-71936282></span><span class="dot" data-v-71936282></span></div>', 2)
|
|
442
|
+
])])) : x("", !0)
|
|
443
|
+
], 512),
|
|
444
|
+
k(_) ? (g(), Y(be, {
|
|
445
|
+
key: 0,
|
|
446
|
+
request: k(_),
|
|
447
|
+
onSubmit: q,
|
|
448
|
+
onCancel: C
|
|
449
|
+
}, null, 8, ["request"])) : x("", !0),
|
|
450
|
+
k(_) ? x("", !0) : (g(), p("div", Ee, [
|
|
451
|
+
V(f("input", {
|
|
452
|
+
"onUpdate:modelValue": v[0] || (v[0] = (y) => c.value = y),
|
|
453
|
+
disabled: k(r),
|
|
454
|
+
placeholder: "输入消息...",
|
|
455
|
+
onKeyup: N(S, ["enter"])
|
|
456
|
+
}, null, 40, Te), [
|
|
457
|
+
[Z, c.value]
|
|
458
|
+
]),
|
|
459
|
+
f("button", {
|
|
460
|
+
disabled: k(r) || !c.value.trim(),
|
|
461
|
+
onClick: S
|
|
462
|
+
}, " 发送 ", 8, De)
|
|
463
|
+
]))
|
|
464
|
+
], 2);
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
}), Ne = /* @__PURE__ */ U(Ue, [["__scopeId", "data-v-71936282"]]), Be = "0.1.0";
|
|
468
|
+
export {
|
|
469
|
+
Ne as AgentChat,
|
|
470
|
+
ee as ApiClient,
|
|
471
|
+
be as InteractionDialog,
|
|
472
|
+
Ve as IskillsProvider,
|
|
473
|
+
te as createApiClient,
|
|
474
|
+
Me as useAgent,
|
|
475
|
+
ne as useExecution,
|
|
476
|
+
Pe as useFlow,
|
|
477
|
+
se as useInteraction,
|
|
478
|
+
Be as version
|
|
479
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.IskillsVueSdk={},c.Vue))})(this,function(c,e){"use strict";var fe=Object.defineProperty;var me=(c,e,w)=>e in c?fe(c,e,{enumerable:!0,configurable:!0,writable:!0,value:w}):c[e]=w;var v=(c,e,w)=>me(c,typeof e!="symbol"?e+"":e,w);class w{constructor(t){v(this,"config");this.config=t}getHeaders(){const t={"Content-Type":"application/json"};return this.config.apiKey&&(t.Authorization=`Bearer ${this.config.apiKey}`),t}async request(t,n,o,s){const l=new URL(`/api${n}`,this.config.baseUrl);o&&Object.entries(o).forEach(([i,r])=>{r!=null&&l.searchParams.append(i,String(r))});const f=await fetch(l.toString(),{method:t,headers:this.getHeaders(),body:s?JSON.stringify(s):void 0,signal:AbortSignal.timeout(this.config.timeout||3e4)});if(!f.ok)throw new Error(`HTTP Error: ${f.status}`);const d=await f.json();if(d.code!==0&&d.code!==200)throw new Error(d.message||"Unknown error");return d.data}async get(t,n){return this.request("GET",t,n)}async post(t,n){return this.request("POST",t,void 0,n)}async put(t,n){return this.request("PUT",t,void 0,n)}async delete(t){return this.request("DELETE",t)}}function $(a){return new w(a)}function D(a){const t=e.ref([]),n=e.ref(!1),o=e.ref(null),s=e.computed(()=>t.value.filter(i=>i.status==="enabled"));async function l(i){n.value=!0,o.value=null;try{const r=await a.get("/agents/list",i);t.value=r.list||[]}catch(r){throw o.value=r.message,r}finally{n.value=!1}}async function f(i){return a.get(`/agents/${i}`)}function d(i){return t.value.find(r=>r.agent_id===i)}return{agents:t,loading:n,error:o,enabledAgents:s,fetchAgents:l,getAgent:f,getAgentByAgentId:d}}function A(a){const t=e.ref([]),n=e.ref(!1),o=e.ref(null);async function s(i){n.value=!0,o.value=null;try{const r=await a.get("/agent-flows/",i);t.value=r.list||[]}catch(r){throw o.value=r.message,r}finally{n.value=!1}}async function l(i){return a.get(`/agent-flows/${i}`)}async function f(i){return a.get(`/agent-flows/${i}/export`)}function d(i){return t.value.find(r=>r.agent_id===i&&r.is_main_flow)}return{flows:t,loading:n,error:o,fetchFlows:s,getFlow:l,exportFlow:f,getMainFlow:d}}function S(a){const t=e.ref([]),n=e.ref(!1),o=e.shallowRef(null),s=e.ref(null),l=e.ref(null);function f(u){t.value.push({id:Date.now(),role:"user",content:u,timestamp:new Date})}function d(u){t.value.push({id:Date.now()+1,role:"assistant",content:u,timestamp:new Date})}function i(u){t.value.push({id:Date.now()+2,role:"system",content:u,timestamp:new Date})}async function r(u,m,C){n.value=!0,l.value=null,f(m);try{const b=await a.post("/agent-executions",{flow_id:u,variables:C});s.value=b.execution_id;const B=await a.post(`/agent-executions/${b.execution_id}/run`,{user_input:m});return o.value=B,B.output&&d(String(B.output)),B}catch(b){throw l.value=b.message,i(`执行失败: ${l.value}`),b}finally{n.value=!1}}async function h(u){if(!s.value)throw new Error("没有待处理的执行");n.value=!0,l.value=null;try{const m=await a.post(`/agent-executions/${s.value}/resume`,u);return o.value=m,m.output&&d(String(m.output)),m}catch(m){throw l.value=m.message,i(`恢复执行失败: ${l.value}`),m}finally{n.value=!1}}function E(){t.value=[]}function g(){t.value=[],o.value=null,s.value=null,l.value=null}return{messages:t,loading:n,result:o,executionId:s,error:l,execute:r,resume:h,clearMessages:E,reset:g,addUserMessage:f,addAssistantMessage:d,addSystemMessage:i}}function q(){const a=e.shallowRef(null),t=e.ref(!1),n=e.ref(null);function o(f){return a.value=f,t.value=!0,new Promise(d=>{n.value=d})}function s(f){n.value&&(n.value(f),n.value=null),a.value=null,t.value=!1}function l(){n.value&&(n.value({value:null}),n.value=null),a.value=null,t.value=!1}return{interaction:a,waiting:t,showInteraction:o,submit:s,cancel:l}}const T={class:"iskills-provider"},x=e.defineComponent({__name:"IskillsProvider",props:{baseUrl:{},apiKey:{},theme:{},locale:{}},setup(a){const t=a,n=$({baseUrl:t.baseUrl,apiKey:t.apiKey});return e.provide("iskills-api",n),e.provide("iskills-config",e.reactive({baseUrl:t.baseUrl,theme:t.theme||"light",locale:t.locale||"zh-CN"})),(o,s)=>(e.openBlock(),e.createElementBlock("div",T,[e.renderSlot(o.$slots,"default",{},void 0,!0)]))}}),V=(a,t)=>{const n=a.__vccOpts||a;for(const[o,s]of t)n[o]=s;return n},U=V(x,[["__scopeId","data-v-0f46f6a7"]]),F={class:"interaction-dialog"},P={class:"dialog-content"},K={class:"dialog-header"},M={class:"dialog-body"},j={class:"prompt"},z={key:0,class:"input-group"},O=["type","placeholder"],L={key:1,class:"confirm-group"},R={key:2,class:"select-group"},H=["onClick"],G={class:"option-label"},J={key:0,class:"option-description"},Q={class:"dialog-footer"},W=["disabled"],I=V(e.defineComponent({__name:"InteractionDialog",props:{request:{}},emits:["submit","cancel"],setup(a,{emit:t}){const n=a,o=t,s=e.ref(n.request.default_value||""),l=e.ref(null),f=e.computed(()=>{switch(n.request.type){case"input":return"请输入";case"confirm":return"请确认";case"select":return"请选择";default:return"交互"}}),d=e.computed(()=>n.request.type==="input"?s.value.toString().trim().length>0:n.request.type==="select"?l.value!==null:!0);function i(){var E;if(d.value){if(n.request.type==="input")o("submit",{value:s.value});else if(n.request.type==="select"&&l.value!==null){const g=(E=n.request.options)==null?void 0:E[l.value];o("submit",{value:(g==null?void 0:g.value)??(g==null?void 0:g.id)??l.value,option_id:g==null?void 0:g.id})}}}function r(){o("submit",{value:!0})}function h(){o("cancel")}return(E,g)=>(e.openBlock(),e.createElementBlock("div",F,[e.createElementVNode("div",{class:"dialog-overlay",onClick:h}),e.createElementVNode("div",P,[e.createElementVNode("div",K,[e.createElementVNode("h3",null,e.toDisplayString(f.value),1)]),e.createElementVNode("div",M,[e.createElementVNode("p",j,e.toDisplayString(a.request.prompt),1),a.request.type==="input"?(e.openBlock(),e.createElementBlock("div",z,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":g[0]||(g[0]=u=>s.value=u),type:a.request.input_type||"text",placeholder:a.request.prompt,onKeyup:e.withKeys(i,["enter"])},null,40,O),[[e.vModelDynamic,s.value]])])):a.request.type==="confirm"?(e.openBlock(),e.createElementBlock("div",L,[e.createElementVNode("button",{class:"btn btn-primary",onClick:r},"确认"),e.createElementVNode("button",{class:"btn btn-secondary",onClick:h},"取消")])):a.request.type==="select"?(e.openBlock(),e.createElementBlock("div",R,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.request.options,(u,m)=>(e.openBlock(),e.createElementBlock("div",{key:m,class:e.normalizeClass(["select-option",{selected:l.value===m}]),onClick:C=>l.value=m},[e.createElementVNode("div",G,e.toDisplayString(u.label),1),u.description?(e.openBlock(),e.createElementBlock("div",J,e.toDisplayString(u.description),1)):e.createCommentVNode("",!0)],10,H))),128))])):e.createCommentVNode("",!0)]),e.createElementVNode("div",Q,[a.request.type==="input"||a.request.type==="select"?(e.openBlock(),e.createElementBlock("button",{key:0,class:"btn btn-primary",disabled:!d.value,onClick:i}," 提交 ",8,W)):e.createCommentVNode("",!0),e.createElementVNode("button",{class:"btn btn-secondary",onClick:h},"取消")])])]))}}),[["__scopeId","data-v-fa8759d4"]]),X={class:"message-avatar"},Y={key:0},Z={key:1},ee={key:2},te={class:"message-content"},ne={class:"message-text"},ae={class:"message-time"},oe={key:0,class:"chat-loading"},se={key:1,class:"chat-input"},le=["disabled"],ie=["disabled"],re=V(e.defineComponent({__name:"AgentChat",props:{agentId:{},flowId:{},initialVariables:{}},emits:["complete","error","interaction"],setup(a,{emit:t}){const n=a,o=t,s=e.inject("iskills-api"),l=e.inject("iskills-config"),{messages:f,loading:d,execute:i,resume:r}=S(s),{interaction:h,submit:E,cancel:g}=q(),u=e.ref(""),m=e.ref();e.watch(f,async()=>{await e.nextTick(),m.value&&(m.value.scrollTop=m.value.scrollHeight)},{deep:!0});async function C(){const _=u.value.trim();if(!(!_||d.value)){u.value="";try{const p=n.flowId||await de(),k=await i(p,_,n.initialVariables);k.needs_interaction&&k.interaction_data?(h.value=k.interaction_data,o("interaction",k.interaction_data)):o("complete",k)}catch(p){o("error",p)}}}async function b(_){await E(_),h.value=null;try{const p=await r(_);p.needs_interaction&&p.interaction_data?(h.value=p.interaction_data,o("interaction",p.interaction_data)):o("complete",p)}catch(p){o("error",p)}}function B(){g(),h.value=null}async function de(){const p=((await s.get("/agents/list")).list||[]).find(N=>N.agent_id===n.agentId);if(!p)throw new Error(`Agent ${n.agentId} not found`);const y=((await s.get("/agent-flows/",{agent_id:p.agent_id})).list||[]).find(N=>N.is_main_flow);if(!y)throw new Error("No main flow found");return y.flow_id}function ue(_){return _.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"})}return(_,p)=>{var k;return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["agent-chat",[`theme-${((k=e.unref(l))==null?void 0:k.theme)||"light"}`]])},[e.createElementVNode("div",{class:"chat-messages",ref_key:"messagesRef",ref:m},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(f),y=>(e.openBlock(),e.createElementBlock("div",{key:y.id,class:e.normalizeClass(["chat-message",[`message-${y.role}`]])},[e.createElementVNode("div",X,[y.role==="user"?(e.openBlock(),e.createElementBlock("span",Y,"👤")):y.role==="assistant"?(e.openBlock(),e.createElementBlock("span",Z,"🤖")):(e.openBlock(),e.createElementBlock("span",ee,"ℹ️"))]),e.createElementVNode("div",te,[e.createElementVNode("div",ne,e.toDisplayString(y.content),1),e.createElementVNode("div",ae,e.toDisplayString(ue(y.timestamp)),1)])],2))),128)),e.unref(d)?(e.openBlock(),e.createElementBlock("div",oe,[...p[1]||(p[1]=[e.createStaticVNode('<div class="message-avatar" data-v-71936282>🤖</div><div class="loading-dots" data-v-71936282><span class="dot" data-v-71936282></span><span class="dot" data-v-71936282></span><span class="dot" data-v-71936282></span></div>',2)])])):e.createCommentVNode("",!0)],512),e.unref(h)?(e.openBlock(),e.createBlock(I,{key:0,request:e.unref(h),onSubmit:b,onCancel:B},null,8,["request"])):e.createCommentVNode("",!0),e.unref(h)?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",se,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":p[0]||(p[0]=y=>u.value=y),disabled:e.unref(d),placeholder:"输入消息...",onKeyup:e.withKeys(C,["enter"])},null,40,le),[[e.vModelText,u.value]]),e.createElementVNode("button",{disabled:e.unref(d)||!u.value.trim(),onClick:C}," 发送 ",8,ie)]))],2)}}}),[["__scopeId","data-v-71936282"]]),ce="0.1.0";c.AgentChat=re,c.ApiClient=w,c.InteractionDialog=I,c.IskillsProvider=U,c.createApiClient=$,c.useAgent=D,c.useExecution=S,c.useFlow=A,c.useInteraction=q,c.version=ce,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.iskills-provider[data-v-0f46f6a7]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif}.interaction-dialog[data-v-fa8759d4]{position:fixed;top:0;left:0;right:0;bottom:0;display:flex;align-items:center;justify-content:center;z-index:1000}.dialog-overlay[data-v-fa8759d4]{position:absolute;top:0;left:0;right:0;bottom:0;background:#00000080}.dialog-content[data-v-fa8759d4]{position:relative;background:#fff;border-radius:8px;box-shadow:0 4px 12px #00000026;max-width:480px;width:90%}.dialog-header[data-v-fa8759d4]{padding:16px 20px;border-bottom:1px solid #e4e7ed}.dialog-header h3[data-v-fa8759d4]{margin:0;font-size:16px;color:#303133}.dialog-body[data-v-fa8759d4]{padding:20px}.prompt[data-v-fa8759d4]{margin:0 0 16px;color:#606266;line-height:1.5}.input-group input[data-v-fa8759d4]{width:100%;padding:8px 12px;border:1px solid #dcdfe6;border-radius:4px;outline:none;box-sizing:border-box}.input-group input[data-v-fa8759d4]:focus{border-color:#409eff}.confirm-group[data-v-fa8759d4]{display:flex;gap:12px;justify-content:center}.select-group[data-v-fa8759d4]{display:flex;flex-direction:column;gap:8px}.select-option[data-v-fa8759d4]{padding:12px;border:1px solid #dcdfe6;border-radius:4px;cursor:pointer;transition:all .2s}.select-option[data-v-fa8759d4]:hover,.select-option.selected[data-v-fa8759d4]{border-color:#409eff;background:#ecf5ff}.option-label[data-v-fa8759d4]{font-weight:500;color:#303133}.option-description[data-v-fa8759d4]{font-size:12px;color:#909399;margin-top:4px}.dialog-footer[data-v-fa8759d4]{display:flex;justify-content:flex-end;gap:8px;padding:12px 20px;border-top:1px solid #e4e7ed}.btn[data-v-fa8759d4]{padding:8px 16px;border:none;border-radius:4px;cursor:pointer;font-size:14px}.btn-primary[data-v-fa8759d4]{background:#409eff;color:#fff}.btn-primary[data-v-fa8759d4]:disabled{background:#a0cfff;cursor:not-allowed}.btn-secondary[data-v-fa8759d4]{background:#909399;color:#fff}.agent-chat[data-v-71936282]{display:flex;flex-direction:column;height:100%;border:1px solid #e4e7ed;border-radius:8px;overflow:hidden}.chat-messages[data-v-71936282]{flex:1;overflow-y:auto;padding:16px}.chat-message[data-v-71936282]{display:flex;gap:12px;margin-bottom:16px}.message-user[data-v-71936282]{flex-direction:row-reverse}.message-content[data-v-71936282]{max-width:70%}.message-text[data-v-71936282]{padding:10px 14px;border-radius:8px;line-height:1.5}.message-user .message-text[data-v-71936282]{background:#409eff;color:#fff}.message-assistant .message-text[data-v-71936282]{background:#f4f4f5;color:#303133}.message-system .message-text[data-v-71936282]{background:#fdf6ec;color:#e6a23c;font-size:12px}.message-time[data-v-71936282]{font-size:12px;color:#909399;margin-top:4px}.chat-loading[data-v-71936282]{display:flex;gap:12px;margin-bottom:16px}.loading-dots[data-v-71936282]{display:flex;gap:4px;padding:10px 14px;background:#f4f4f5;border-radius:8px}.dot[data-v-71936282]{width:8px;height:8px;background:#909399;border-radius:50%;animation:bounce-71936282 1.4s infinite ease-in-out}.dot[data-v-71936282]:nth-child(1){animation-delay:-.32s}.dot[data-v-71936282]:nth-child(2){animation-delay:-.16s}@keyframes bounce-71936282{0%,80%,to{transform:scale(0)}40%{transform:scale(1)}}.chat-input[data-v-71936282]{display:flex;gap:8px;padding:12px;border-top:1px solid #e4e7ed}.chat-input input[data-v-71936282]{flex:1;padding:8px 12px;border:1px solid #dcdfe6;border-radius:4px;outline:none}.chat-input input[data-v-71936282]:focus{border-color:#409eff}.chat-input button[data-v-71936282]{padding:8px 16px;background:#409eff;color:#fff;border:none;border-radius:4px;cursor:pointer}.chat-input button[data-v-71936282]:disabled{background:#a0cfff;cursor:not-allowed}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "iskills-vue-sdk",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "iSkills Vue3 SDK - 智能体流程执行组件库",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./style.css": "./dist/style.css"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"dev": "vite",
|
|
22
|
+
"build": "vue-tsc --noEmit && vite build",
|
|
23
|
+
"preview": "vite preview",
|
|
24
|
+
"type-check": "vue-tsc --noEmit",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"vue": "^3.3.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
32
|
+
"typescript": "^5.3.0",
|
|
33
|
+
"vite": "^5.0.0",
|
|
34
|
+
"vue": "^3.3.0",
|
|
35
|
+
"vue-tsc": "^2.0.0"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"vue",
|
|
39
|
+
"vue3",
|
|
40
|
+
"iskills",
|
|
41
|
+
"agent",
|
|
42
|
+
"workflow",
|
|
43
|
+
"ai"
|
|
44
|
+
],
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/your-org/iskills-sdk.git"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/your-org/iskills-sdk#readme"
|
|
51
|
+
}
|