@lovelymai/agent 1.0.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.
- package/dist/agent.js +663 -0
- package/dist/index.d.ts +1 -0
- package/dist/services/loop.d.ts +27 -0
- package/dist/services/stream.d.ts +23 -0
- package/dist/services/tool.d.ts +33 -0
- package/package.json +24 -0
package/dist/agent.js
ADDED
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
//#region node_modules/@vue/shared/dist/shared.esm-bundler.js
|
|
2
|
+
// @__NO_SIDE_EFFECTS__
|
|
3
|
+
function e(e) {
|
|
4
|
+
let t = /* @__PURE__ */ Object.create(null);
|
|
5
|
+
for (let n of e.split(",")) t[n] = 1;
|
|
6
|
+
return (e) => e in t;
|
|
7
|
+
}
|
|
8
|
+
process.env.NODE_ENV === "production" || Object.freeze({}), process.env.NODE_ENV === "production" || Object.freeze([]);
|
|
9
|
+
var t = Object.assign, n = Object.prototype.hasOwnProperty, r = (e, t) => n.call(e, t), i = Array.isArray, a = (e) => u(e) === "[object Map]", o = (e) => typeof e == "string", s = (e) => typeof e == "symbol", c = (e) => typeof e == "object" && !!e, l = Object.prototype.toString, u = (e) => l.call(e), d = (e) => u(e).slice(8, -1), f = (e) => o(e) && e !== "NaN" && e[0] !== "-" && "" + parseInt(e, 10) === e, ee = ((e) => {
|
|
10
|
+
let t = /* @__PURE__ */ Object.create(null);
|
|
11
|
+
return ((n) => t[n] || (t[n] = e(n)));
|
|
12
|
+
})((e) => e.charAt(0).toUpperCase() + e.slice(1)), p = (e, t) => !Object.is(e, t);
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
|
|
15
|
+
function m(e, ...t) {
|
|
16
|
+
console.warn(`[Vue warn] ${e}`, ...t);
|
|
17
|
+
}
|
|
18
|
+
var h, te = 0, g, _;
|
|
19
|
+
function v() {
|
|
20
|
+
te++;
|
|
21
|
+
}
|
|
22
|
+
function y() {
|
|
23
|
+
if (--te > 0) return;
|
|
24
|
+
if (_) {
|
|
25
|
+
let e = _;
|
|
26
|
+
for (_ = void 0; e;) {
|
|
27
|
+
let t = e.next;
|
|
28
|
+
e.next = void 0, e.flags &= -9, e = t;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
let e;
|
|
32
|
+
for (; g;) {
|
|
33
|
+
let t = g;
|
|
34
|
+
for (g = void 0; t;) {
|
|
35
|
+
let n = t.next;
|
|
36
|
+
if (t.next = void 0, t.flags &= -9, t.flags & 1) try {
|
|
37
|
+
t.trigger();
|
|
38
|
+
} catch (t) {
|
|
39
|
+
e ||= t;
|
|
40
|
+
}
|
|
41
|
+
t = n;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (e) throw e;
|
|
45
|
+
}
|
|
46
|
+
var b = !0, x = [];
|
|
47
|
+
function ne() {
|
|
48
|
+
x.push(b), b = !1;
|
|
49
|
+
}
|
|
50
|
+
function re() {
|
|
51
|
+
let e = x.pop();
|
|
52
|
+
b = e === void 0 || e;
|
|
53
|
+
}
|
|
54
|
+
var S = 0, ie = class {
|
|
55
|
+
constructor(e, t) {
|
|
56
|
+
this.sub = e, this.dep = t, this.version = t.version, this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
|
|
57
|
+
}
|
|
58
|
+
}, ae = class {
|
|
59
|
+
constructor(e) {
|
|
60
|
+
this.computed = e, this.version = 0, this.activeLink = void 0, this.subs = void 0, this.map = void 0, this.key = void 0, this.sc = 0, this.__v_skip = !0, process.env.NODE_ENV !== "production" && (this.subsHead = void 0);
|
|
61
|
+
}
|
|
62
|
+
track(e) {
|
|
63
|
+
if (!h || !b || h === this.computed) return;
|
|
64
|
+
let n = this.activeLink;
|
|
65
|
+
if (n === void 0 || n.sub !== h) n = this.activeLink = new ie(h, this), h.deps ? (n.prevDep = h.depsTail, h.depsTail.nextDep = n, h.depsTail = n) : h.deps = h.depsTail = n, oe(n);
|
|
66
|
+
else if (n.version === -1 && (n.version = this.version, n.nextDep)) {
|
|
67
|
+
let e = n.nextDep;
|
|
68
|
+
e.prevDep = n.prevDep, n.prevDep && (n.prevDep.nextDep = e), n.prevDep = h.depsTail, n.nextDep = void 0, h.depsTail.nextDep = n, h.depsTail = n, h.deps === n && (h.deps = e);
|
|
69
|
+
}
|
|
70
|
+
return process.env.NODE_ENV !== "production" && h.onTrack && h.onTrack(t({ effect: h }, e)), n;
|
|
71
|
+
}
|
|
72
|
+
trigger(e) {
|
|
73
|
+
this.version++, S++, this.notify(e);
|
|
74
|
+
}
|
|
75
|
+
notify(e) {
|
|
76
|
+
v();
|
|
77
|
+
try {
|
|
78
|
+
if (process.env.NODE_ENV !== "production") for (let n = this.subsHead; n; n = n.nextSub) n.sub.onTrigger && !(n.sub.flags & 8) && n.sub.onTrigger(t({ effect: n.sub }, e));
|
|
79
|
+
for (let e = this.subs; e; e = e.prevSub) e.sub.notify() && e.sub.dep.notify();
|
|
80
|
+
} finally {
|
|
81
|
+
y();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function oe(e) {
|
|
86
|
+
if (e.dep.sc++, e.sub.flags & 4) {
|
|
87
|
+
let t = e.dep.computed;
|
|
88
|
+
if (t && !e.dep.subs) {
|
|
89
|
+
t.flags |= 20;
|
|
90
|
+
for (let e = t.deps; e; e = e.nextDep) oe(e);
|
|
91
|
+
}
|
|
92
|
+
let n = e.dep.subs;
|
|
93
|
+
n !== e && (e.prevSub = n, n && (n.nextSub = e)), process.env.NODE_ENV !== "production" && e.dep.subsHead === void 0 && (e.dep.subsHead = e), e.dep.subs = e;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
var C = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ Symbol(process.env.NODE_ENV === "production" ? "" : "Object iterate"), T = /* @__PURE__ */ Symbol(process.env.NODE_ENV === "production" ? "" : "Map keys iterate"), E = /* @__PURE__ */ Symbol(process.env.NODE_ENV === "production" ? "" : "Array iterate");
|
|
97
|
+
function D(e, t, n) {
|
|
98
|
+
if (b && h) {
|
|
99
|
+
let r = C.get(e);
|
|
100
|
+
r || C.set(e, r = /* @__PURE__ */ new Map());
|
|
101
|
+
let i = r.get(n);
|
|
102
|
+
i || (r.set(n, i = new ae()), i.map = r, i.key = n), process.env.NODE_ENV === "production" ? i.track() : i.track({
|
|
103
|
+
target: e,
|
|
104
|
+
type: t,
|
|
105
|
+
key: n
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function O(e, t, n, r, o, c) {
|
|
110
|
+
let l = C.get(e);
|
|
111
|
+
if (!l) {
|
|
112
|
+
S++;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
let u = (i) => {
|
|
116
|
+
i && (process.env.NODE_ENV === "production" ? i.trigger() : i.trigger({
|
|
117
|
+
target: e,
|
|
118
|
+
type: t,
|
|
119
|
+
key: n,
|
|
120
|
+
newValue: r,
|
|
121
|
+
oldValue: o,
|
|
122
|
+
oldTarget: c
|
|
123
|
+
}));
|
|
124
|
+
};
|
|
125
|
+
if (v(), t === "clear") l.forEach(u);
|
|
126
|
+
else {
|
|
127
|
+
let o = i(e), c = o && f(n);
|
|
128
|
+
if (o && n === "length") {
|
|
129
|
+
let e = Number(r);
|
|
130
|
+
l.forEach((t, n) => {
|
|
131
|
+
(n === "length" || n === E || !s(n) && n >= e) && u(t);
|
|
132
|
+
});
|
|
133
|
+
} else switch ((n !== void 0 || l.has(void 0)) && u(l.get(n)), c && u(l.get(E)), t) {
|
|
134
|
+
case "add":
|
|
135
|
+
o ? c && u(l.get("length")) : (u(l.get(w)), a(e) && u(l.get(T)));
|
|
136
|
+
break;
|
|
137
|
+
case "delete":
|
|
138
|
+
o || (u(l.get(w)), a(e) && u(l.get(T)));
|
|
139
|
+
break;
|
|
140
|
+
case "set": a(e) && u(l.get(w));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
y();
|
|
144
|
+
}
|
|
145
|
+
function k(e) {
|
|
146
|
+
let t = /* @__PURE__ */ Y(e);
|
|
147
|
+
return t === e ? t : (D(t, "iterate", E), /* @__PURE__ */ J(e) ? t : t.map(X));
|
|
148
|
+
}
|
|
149
|
+
function A(e) {
|
|
150
|
+
return D(e = /* @__PURE__ */ Y(e), "iterate", E), e;
|
|
151
|
+
}
|
|
152
|
+
function j(e, t) {
|
|
153
|
+
return /* @__PURE__ */ q(e) ? Z(/* @__PURE__ */ we(e) ? X(t) : t) : X(t);
|
|
154
|
+
}
|
|
155
|
+
var se = {
|
|
156
|
+
__proto__: null,
|
|
157
|
+
[Symbol.iterator]() {
|
|
158
|
+
return M(this, Symbol.iterator, (e) => j(this, e));
|
|
159
|
+
},
|
|
160
|
+
concat(...e) {
|
|
161
|
+
return k(this).concat(...e.map((e) => i(e) ? k(e) : e));
|
|
162
|
+
},
|
|
163
|
+
entries() {
|
|
164
|
+
return M(this, "entries", (e) => (e[1] = j(this, e[1]), e));
|
|
165
|
+
},
|
|
166
|
+
every(e, t) {
|
|
167
|
+
return N(this, "every", e, t, void 0, arguments);
|
|
168
|
+
},
|
|
169
|
+
filter(e, t) {
|
|
170
|
+
return N(this, "filter", e, t, (e) => e.map((e) => j(this, e)), arguments);
|
|
171
|
+
},
|
|
172
|
+
find(e, t) {
|
|
173
|
+
return N(this, "find", e, t, (e) => j(this, e), arguments);
|
|
174
|
+
},
|
|
175
|
+
findIndex(e, t) {
|
|
176
|
+
return N(this, "findIndex", e, t, void 0, arguments);
|
|
177
|
+
},
|
|
178
|
+
findLast(e, t) {
|
|
179
|
+
return N(this, "findLast", e, t, (e) => j(this, e), arguments);
|
|
180
|
+
},
|
|
181
|
+
findLastIndex(e, t) {
|
|
182
|
+
return N(this, "findLastIndex", e, t, void 0, arguments);
|
|
183
|
+
},
|
|
184
|
+
forEach(e, t) {
|
|
185
|
+
return N(this, "forEach", e, t, void 0, arguments);
|
|
186
|
+
},
|
|
187
|
+
includes(...e) {
|
|
188
|
+
return P(this, "includes", e);
|
|
189
|
+
},
|
|
190
|
+
indexOf(...e) {
|
|
191
|
+
return P(this, "indexOf", e);
|
|
192
|
+
},
|
|
193
|
+
join(e) {
|
|
194
|
+
return k(this).join(e);
|
|
195
|
+
},
|
|
196
|
+
lastIndexOf(...e) {
|
|
197
|
+
return P(this, "lastIndexOf", e);
|
|
198
|
+
},
|
|
199
|
+
map(e, t) {
|
|
200
|
+
return N(this, "map", e, t, void 0, arguments);
|
|
201
|
+
},
|
|
202
|
+
pop() {
|
|
203
|
+
return F(this, "pop");
|
|
204
|
+
},
|
|
205
|
+
push(...e) {
|
|
206
|
+
return F(this, "push", e);
|
|
207
|
+
},
|
|
208
|
+
reduce(e, ...t) {
|
|
209
|
+
return le(this, "reduce", e, t);
|
|
210
|
+
},
|
|
211
|
+
reduceRight(e, ...t) {
|
|
212
|
+
return le(this, "reduceRight", e, t);
|
|
213
|
+
},
|
|
214
|
+
shift() {
|
|
215
|
+
return F(this, "shift");
|
|
216
|
+
},
|
|
217
|
+
some(e, t) {
|
|
218
|
+
return N(this, "some", e, t, void 0, arguments);
|
|
219
|
+
},
|
|
220
|
+
splice(...e) {
|
|
221
|
+
return F(this, "splice", e);
|
|
222
|
+
},
|
|
223
|
+
toReversed() {
|
|
224
|
+
return k(this).toReversed();
|
|
225
|
+
},
|
|
226
|
+
toSorted(e) {
|
|
227
|
+
return k(this).toSorted(e);
|
|
228
|
+
},
|
|
229
|
+
toSpliced(...e) {
|
|
230
|
+
return k(this).toSpliced(...e);
|
|
231
|
+
},
|
|
232
|
+
unshift(...e) {
|
|
233
|
+
return F(this, "unshift", e);
|
|
234
|
+
},
|
|
235
|
+
values() {
|
|
236
|
+
return M(this, "values", (e) => j(this, e));
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
function M(e, t, n) {
|
|
240
|
+
let r = A(e), i = r[t]();
|
|
241
|
+
return r !== e && !/* @__PURE__ */ J(e) && (i._next = i.next, i.next = () => {
|
|
242
|
+
let e = i._next();
|
|
243
|
+
return e.done || (e.value = n(e.value)), e;
|
|
244
|
+
}), i;
|
|
245
|
+
}
|
|
246
|
+
var ce = Array.prototype;
|
|
247
|
+
function N(e, t, n, r, i, a) {
|
|
248
|
+
let o = A(e), s = o !== e && !/* @__PURE__ */ J(e), c = o[t];
|
|
249
|
+
if (c !== ce[t]) {
|
|
250
|
+
let t = c.apply(e, a);
|
|
251
|
+
return s ? X(t) : t;
|
|
252
|
+
}
|
|
253
|
+
let l = n;
|
|
254
|
+
o !== e && (s ? l = function(t, r) {
|
|
255
|
+
return n.call(this, j(e, t), r, e);
|
|
256
|
+
} : n.length > 2 && (l = function(t, r) {
|
|
257
|
+
return n.call(this, t, r, e);
|
|
258
|
+
}));
|
|
259
|
+
let u = c.call(o, l, r);
|
|
260
|
+
return s && i ? i(u) : u;
|
|
261
|
+
}
|
|
262
|
+
function le(e, t, n, r) {
|
|
263
|
+
let i = A(e), a = i !== e && !/* @__PURE__ */ J(e), o = n, s = !1;
|
|
264
|
+
i !== e && (a ? (s = r.length === 0, o = function(t, r, i) {
|
|
265
|
+
return s && (s = !1, t = j(e, t)), n.call(this, t, j(e, r), i, e);
|
|
266
|
+
}) : n.length > 3 && (o = function(t, r, i) {
|
|
267
|
+
return n.call(this, t, r, i, e);
|
|
268
|
+
}));
|
|
269
|
+
let c = i[t](o, ...r);
|
|
270
|
+
return s ? j(e, c) : c;
|
|
271
|
+
}
|
|
272
|
+
function P(e, t, n) {
|
|
273
|
+
let r = /* @__PURE__ */ Y(e);
|
|
274
|
+
D(r, "iterate", E);
|
|
275
|
+
let i = r[t](...n);
|
|
276
|
+
return (i === -1 || i === !1) && /* @__PURE__ */ Te(n[0]) ? (n[0] = /* @__PURE__ */ Y(n[0]), r[t](...n)) : i;
|
|
277
|
+
}
|
|
278
|
+
function F(e, t, n = []) {
|
|
279
|
+
ne(), v();
|
|
280
|
+
let r = (/* @__PURE__ */ Y(e))[t].apply(e, n);
|
|
281
|
+
return y(), re(), r;
|
|
282
|
+
}
|
|
283
|
+
var ue = /* @__PURE__ */ e("__proto__,__v_isRef,__isVue"), I = new Set(/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((e) => e !== "arguments" && e !== "caller").map((e) => Symbol[e]).filter(s));
|
|
284
|
+
function de(e) {
|
|
285
|
+
s(e) || (e = String(e));
|
|
286
|
+
let t = /* @__PURE__ */ Y(this);
|
|
287
|
+
return D(t, "has", e), t.hasOwnProperty(e);
|
|
288
|
+
}
|
|
289
|
+
var L = class {
|
|
290
|
+
constructor(e = !1, t = !1) {
|
|
291
|
+
this._isReadonly = e, this._isShallow = t;
|
|
292
|
+
}
|
|
293
|
+
get(e, t, n) {
|
|
294
|
+
if (t === "__v_skip") return e.__v_skip;
|
|
295
|
+
let r = this._isReadonly, a = this._isShallow;
|
|
296
|
+
if (t === "__v_isReactive") return !r;
|
|
297
|
+
if (t === "__v_isReadonly") return r;
|
|
298
|
+
if (t === "__v_isShallow") return a;
|
|
299
|
+
if (t === "__v_raw") return n === (r ? a ? xe : W : a ? be : U).get(e) || Object.getPrototypeOf(e) === Object.getPrototypeOf(n) ? e : void 0;
|
|
300
|
+
let o = i(e);
|
|
301
|
+
if (!r) {
|
|
302
|
+
let e;
|
|
303
|
+
if (o && (e = se[t])) return e;
|
|
304
|
+
if (t === "hasOwnProperty") return de;
|
|
305
|
+
}
|
|
306
|
+
let l = Reflect.get(e, t, /* @__PURE__ */ Q(e) ? e : n);
|
|
307
|
+
if ((s(t) ? I.has(t) : ue(t)) || (r || D(e, "get", t), a)) return l;
|
|
308
|
+
if (/* @__PURE__ */ Q(l)) {
|
|
309
|
+
let e = o && f(t) ? l : l.value;
|
|
310
|
+
return r && c(e) ? /* @__PURE__ */ K(e) : e;
|
|
311
|
+
}
|
|
312
|
+
return c(l) ? r ? /* @__PURE__ */ K(l) : /* @__PURE__ */ G(l) : l;
|
|
313
|
+
}
|
|
314
|
+
}, fe = class extends L {
|
|
315
|
+
constructor(e = !1) {
|
|
316
|
+
super(!1, e);
|
|
317
|
+
}
|
|
318
|
+
set(e, t, n, a) {
|
|
319
|
+
let o = e[t], s = i(e) && f(t);
|
|
320
|
+
if (!this._isShallow) {
|
|
321
|
+
let r = /* @__PURE__ */ q(o);
|
|
322
|
+
if (!/* @__PURE__ */ J(n) && !/* @__PURE__ */ q(n) && (o = /* @__PURE__ */ Y(o), n = /* @__PURE__ */ Y(n)), !s && /* @__PURE__ */ Q(o) && !/* @__PURE__ */ Q(n)) return r ? (process.env.NODE_ENV !== "production" && m(`Set operation on key "${String(t)}" failed: target is readonly.`, e[t]), !0) : (o.value = n, !0);
|
|
323
|
+
}
|
|
324
|
+
let c = s ? Number(t) < e.length : r(e, t), l = Reflect.set(e, t, n, /* @__PURE__ */ Q(e) ? e : a);
|
|
325
|
+
return e === /* @__PURE__ */ Y(a) && l && (c ? p(n, o) && O(e, "set", t, n, o) : O(e, "add", t, n)), l;
|
|
326
|
+
}
|
|
327
|
+
deleteProperty(e, t) {
|
|
328
|
+
let n = r(e, t), i = e[t], a = Reflect.deleteProperty(e, t);
|
|
329
|
+
return a && n && O(e, "delete", t, void 0, i), a;
|
|
330
|
+
}
|
|
331
|
+
has(e, t) {
|
|
332
|
+
let n = Reflect.has(e, t);
|
|
333
|
+
return (!s(t) || !I.has(t)) && D(e, "has", t), n;
|
|
334
|
+
}
|
|
335
|
+
ownKeys(e) {
|
|
336
|
+
return D(e, "iterate", i(e) ? "length" : w), Reflect.ownKeys(e);
|
|
337
|
+
}
|
|
338
|
+
}, pe = class extends L {
|
|
339
|
+
constructor(e = !1) {
|
|
340
|
+
super(!0, e);
|
|
341
|
+
}
|
|
342
|
+
set(e, t) {
|
|
343
|
+
return process.env.NODE_ENV !== "production" && m(`Set operation on key "${String(t)}" failed: target is readonly.`, e), !0;
|
|
344
|
+
}
|
|
345
|
+
deleteProperty(e, t) {
|
|
346
|
+
return process.env.NODE_ENV !== "production" && m(`Delete operation on key "${String(t)}" failed: target is readonly.`, e), !0;
|
|
347
|
+
}
|
|
348
|
+
}, me = /* @__PURE__ */ new fe(), he = /* @__PURE__ */ new pe(), R = (e) => e, z = (e) => Reflect.getPrototypeOf(e);
|
|
349
|
+
function ge(e, n, r) {
|
|
350
|
+
return function(...i) {
|
|
351
|
+
let o = this.__v_raw, s = /* @__PURE__ */ Y(o), c = a(s), l = e === "entries" || e === Symbol.iterator && c, u = e === "keys" && c, d = o[e](...i), f = r ? R : n ? Z : X;
|
|
352
|
+
return !n && D(s, "iterate", u ? T : w), t(Object.create(d), { next() {
|
|
353
|
+
let { value: e, done: t } = d.next();
|
|
354
|
+
return t ? {
|
|
355
|
+
value: e,
|
|
356
|
+
done: t
|
|
357
|
+
} : {
|
|
358
|
+
value: l ? [f(e[0]), f(e[1])] : f(e),
|
|
359
|
+
done: t
|
|
360
|
+
};
|
|
361
|
+
} });
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
function B(e) {
|
|
365
|
+
return function(...t) {
|
|
366
|
+
if (process.env.NODE_ENV !== "production") {
|
|
367
|
+
let n = t[0] ? `on key "${t[0]}" ` : "";
|
|
368
|
+
m(`${ee(e)} operation ${n}failed: target is readonly.`, /* @__PURE__ */ Y(this));
|
|
369
|
+
}
|
|
370
|
+
return e === "delete" ? !1 : e === "clear" ? void 0 : this;
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function _e(e, n) {
|
|
374
|
+
let r = {
|
|
375
|
+
get(t) {
|
|
376
|
+
let r = this.__v_raw, i = /* @__PURE__ */ Y(r), a = /* @__PURE__ */ Y(t);
|
|
377
|
+
e || (p(t, a) && D(i, "get", t), D(i, "get", a));
|
|
378
|
+
let { has: o } = z(i), s = n ? R : e ? Z : X;
|
|
379
|
+
if (o.call(i, t)) return s(r.get(t));
|
|
380
|
+
if (o.call(i, a)) return s(r.get(a));
|
|
381
|
+
r !== i && r.get(t);
|
|
382
|
+
},
|
|
383
|
+
get size() {
|
|
384
|
+
let t = this.__v_raw;
|
|
385
|
+
return !e && D(/* @__PURE__ */ Y(t), "iterate", w), t.size;
|
|
386
|
+
},
|
|
387
|
+
has(t) {
|
|
388
|
+
let n = this.__v_raw, r = /* @__PURE__ */ Y(n), i = /* @__PURE__ */ Y(t);
|
|
389
|
+
return e || (p(t, i) && D(r, "has", t), D(r, "has", i)), t === i ? n.has(t) : n.has(t) || n.has(i);
|
|
390
|
+
},
|
|
391
|
+
forEach(t, r) {
|
|
392
|
+
let i = this, a = i.__v_raw, o = /* @__PURE__ */ Y(a), s = n ? R : e ? Z : X;
|
|
393
|
+
return !e && D(o, "iterate", w), a.forEach((e, n) => t.call(r, s(e), s(n), i));
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
return t(r, e ? {
|
|
397
|
+
add: B("add"),
|
|
398
|
+
set: B("set"),
|
|
399
|
+
delete: B("delete"),
|
|
400
|
+
clear: B("clear")
|
|
401
|
+
} : {
|
|
402
|
+
add(e) {
|
|
403
|
+
let t = /* @__PURE__ */ Y(this), r = z(t), i = /* @__PURE__ */ Y(e), a = !n && !/* @__PURE__ */ J(e) && !/* @__PURE__ */ q(e) ? i : e;
|
|
404
|
+
return r.has.call(t, a) || p(e, a) && r.has.call(t, e) || p(i, a) && r.has.call(t, i) || (t.add(a), O(t, "add", a, a)), this;
|
|
405
|
+
},
|
|
406
|
+
set(e, t) {
|
|
407
|
+
!n && !/* @__PURE__ */ J(t) && !/* @__PURE__ */ q(t) && (t = /* @__PURE__ */ Y(t));
|
|
408
|
+
let r = /* @__PURE__ */ Y(this), { has: i, get: a } = z(r), o = i.call(r, e);
|
|
409
|
+
o ? process.env.NODE_ENV !== "production" && H(r, i, e) : (e = /* @__PURE__ */ Y(e), o = i.call(r, e));
|
|
410
|
+
let s = a.call(r, e);
|
|
411
|
+
return r.set(e, t), o ? p(t, s) && O(r, "set", e, t, s) : O(r, "add", e, t), this;
|
|
412
|
+
},
|
|
413
|
+
delete(e) {
|
|
414
|
+
let t = /* @__PURE__ */ Y(this), { has: n, get: r } = z(t), i = n.call(t, e);
|
|
415
|
+
i ? process.env.NODE_ENV !== "production" && H(t, n, e) : (e = /* @__PURE__ */ Y(e), i = n.call(t, e));
|
|
416
|
+
let a = r ? r.call(t, e) : void 0, o = t.delete(e);
|
|
417
|
+
return i && O(t, "delete", e, void 0, a), o;
|
|
418
|
+
},
|
|
419
|
+
clear() {
|
|
420
|
+
let e = /* @__PURE__ */ Y(this), t = e.size !== 0, n = process.env.NODE_ENV === "production" ? void 0 : a(e) ? new Map(e) : new Set(e), r = e.clear();
|
|
421
|
+
return t && O(e, "clear", void 0, void 0, n), r;
|
|
422
|
+
}
|
|
423
|
+
}), [
|
|
424
|
+
"keys",
|
|
425
|
+
"values",
|
|
426
|
+
"entries",
|
|
427
|
+
Symbol.iterator
|
|
428
|
+
].forEach((t) => {
|
|
429
|
+
r[t] = ge(t, e, n);
|
|
430
|
+
}), r;
|
|
431
|
+
}
|
|
432
|
+
function V(e, t) {
|
|
433
|
+
let n = _e(e, t);
|
|
434
|
+
return (t, i, a) => i === "__v_isReactive" ? !e : i === "__v_isReadonly" ? e : i === "__v_raw" ? t : Reflect.get(r(n, i) && i in t ? n : t, i, a);
|
|
435
|
+
}
|
|
436
|
+
var ve = { get: /* @__PURE__ */ V(!1, !1) }, ye = { get: /* @__PURE__ */ V(!0, !1) };
|
|
437
|
+
function H(e, t, n) {
|
|
438
|
+
let r = /* @__PURE__ */ Y(n);
|
|
439
|
+
if (r !== n && t.call(e, r)) {
|
|
440
|
+
let t = d(e);
|
|
441
|
+
m(`Reactive ${t} contains both the raw and reactive versions of the same object${t === "Map" ? " as keys" : ""}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
var U = /* @__PURE__ */ new WeakMap(), be = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), xe = /* @__PURE__ */ new WeakMap();
|
|
445
|
+
function Se(e) {
|
|
446
|
+
switch (e) {
|
|
447
|
+
case "Object":
|
|
448
|
+
case "Array": return 1;
|
|
449
|
+
case "Map":
|
|
450
|
+
case "Set":
|
|
451
|
+
case "WeakMap":
|
|
452
|
+
case "WeakSet": return 2;
|
|
453
|
+
default: return 0;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
// @__NO_SIDE_EFFECTS__
|
|
457
|
+
function G(e) {
|
|
458
|
+
return /* @__PURE__ */ q(e) ? e : Ce(e, !1, me, ve, U);
|
|
459
|
+
}
|
|
460
|
+
// @__NO_SIDE_EFFECTS__
|
|
461
|
+
function K(e) {
|
|
462
|
+
return Ce(e, !0, he, ye, W);
|
|
463
|
+
}
|
|
464
|
+
function Ce(e, t, n, r, i) {
|
|
465
|
+
if (!c(e)) return process.env.NODE_ENV !== "production" && m(`value cannot be made ${t ? "readonly" : "reactive"}: ${String(e)}`), e;
|
|
466
|
+
if (e.__v_raw && !(t && e.__v_isReactive) || e.__v_skip || !Object.isExtensible(e)) return e;
|
|
467
|
+
let a = i.get(e);
|
|
468
|
+
if (a) return a;
|
|
469
|
+
let o = Se(d(e));
|
|
470
|
+
if (o === 0) return e;
|
|
471
|
+
let s = new Proxy(e, o === 2 ? r : n);
|
|
472
|
+
return i.set(e, s), s;
|
|
473
|
+
}
|
|
474
|
+
// @__NO_SIDE_EFFECTS__
|
|
475
|
+
function we(e) {
|
|
476
|
+
return /* @__PURE__ */ q(e) ? /* @__PURE__ */ we(e.__v_raw) : !!(e && e.__v_isReactive);
|
|
477
|
+
}
|
|
478
|
+
// @__NO_SIDE_EFFECTS__
|
|
479
|
+
function q(e) {
|
|
480
|
+
return !!(e && e.__v_isReadonly);
|
|
481
|
+
}
|
|
482
|
+
// @__NO_SIDE_EFFECTS__
|
|
483
|
+
function J(e) {
|
|
484
|
+
return !!(e && e.__v_isShallow);
|
|
485
|
+
}
|
|
486
|
+
// @__NO_SIDE_EFFECTS__
|
|
487
|
+
function Te(e) {
|
|
488
|
+
return e ? !!e.__v_raw : !1;
|
|
489
|
+
}
|
|
490
|
+
// @__NO_SIDE_EFFECTS__
|
|
491
|
+
function Y(e) {
|
|
492
|
+
let t = e && e.__v_raw;
|
|
493
|
+
return t ? /* @__PURE__ */ Y(t) : e;
|
|
494
|
+
}
|
|
495
|
+
var X = (e) => c(e) ? /* @__PURE__ */ G(e) : e, Z = (e) => c(e) ? /* @__PURE__ */ K(e) : e;
|
|
496
|
+
// @__NO_SIDE_EFFECTS__
|
|
497
|
+
function Q(e) {
|
|
498
|
+
return e ? e.__v_isRef === !0 : !1;
|
|
499
|
+
}
|
|
500
|
+
// @__NO_SIDE_EFFECTS__
|
|
501
|
+
function $(e) {
|
|
502
|
+
return De(e, !1);
|
|
503
|
+
}
|
|
504
|
+
// @__NO_SIDE_EFFECTS__
|
|
505
|
+
function Ee(e) {
|
|
506
|
+
return De(e, !0);
|
|
507
|
+
}
|
|
508
|
+
function De(e, t) {
|
|
509
|
+
return /* @__PURE__ */ Q(e) ? e : new Oe(e, t);
|
|
510
|
+
}
|
|
511
|
+
var Oe = class {
|
|
512
|
+
constructor(e, t) {
|
|
513
|
+
this.dep = new ae(), this.__v_isRef = !0, this.__v_isShallow = !1, this._rawValue = t ? e : /* @__PURE__ */ Y(e), this._value = t ? e : X(e), this.__v_isShallow = t;
|
|
514
|
+
}
|
|
515
|
+
get value() {
|
|
516
|
+
return process.env.NODE_ENV === "production" ? this.dep.track() : this.dep.track({
|
|
517
|
+
target: this,
|
|
518
|
+
type: "get",
|
|
519
|
+
key: "value"
|
|
520
|
+
}), this._value;
|
|
521
|
+
}
|
|
522
|
+
set value(e) {
|
|
523
|
+
let t = this._rawValue, n = this.__v_isShallow || /* @__PURE__ */ J(e) || /* @__PURE__ */ q(e);
|
|
524
|
+
e = n ? e : /* @__PURE__ */ Y(e), p(e, t) && (this._rawValue = e, this._value = n ? e : X(e), process.env.NODE_ENV === "production" ? this.dep.trigger() : this.dep.trigger({
|
|
525
|
+
target: this,
|
|
526
|
+
type: "set",
|
|
527
|
+
key: "value",
|
|
528
|
+
newValue: e,
|
|
529
|
+
oldValue: t
|
|
530
|
+
}));
|
|
531
|
+
}
|
|
532
|
+
}, ke = async (e, t, n, r) => {
|
|
533
|
+
let i = await e.chat.completions.create({
|
|
534
|
+
...t,
|
|
535
|
+
stream: !0,
|
|
536
|
+
tool_choice: "auto"
|
|
537
|
+
}), a = {
|
|
538
|
+
role: "assistant",
|
|
539
|
+
content: "",
|
|
540
|
+
reasoning_content: "",
|
|
541
|
+
tool_calls: []
|
|
542
|
+
};
|
|
543
|
+
for await (let e of i) {
|
|
544
|
+
if (!r.value) throw Error("主动停止");
|
|
545
|
+
let t = e.choices[0]?.delta;
|
|
546
|
+
if (t?.content && (a.content += t.content, n({ content: t.content })), t?.reasoning_content && (a.reasoning_content += t.reasoning_content, n({ reasoning_content: t.reasoning_content })), t?.tool_calls) for (let e of t.tool_calls) {
|
|
547
|
+
a.tool_calls?.[e.index] || (a.tool_calls ||= [], a.tool_calls[e.index] = {
|
|
548
|
+
id: e.id || "",
|
|
549
|
+
type: "function",
|
|
550
|
+
function: {
|
|
551
|
+
name: e.function?.name || "",
|
|
552
|
+
arguments: ""
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
let t = a.tool_calls[e.index];
|
|
556
|
+
e.id && (t.id = e.id), e.function?.name && (t.function.name = e.function.name), e.function?.arguments && (t.function.arguments += e.function.arguments);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return a.tool_calls?.length === 0 && delete a.tool_calls, a.content || delete a.content, a.reasoning_content || delete a.reasoning_content, a;
|
|
560
|
+
}, Ae = (e) => {
|
|
561
|
+
let t = e.map((e) => {
|
|
562
|
+
let t = { ...e.properties };
|
|
563
|
+
for (let e of Object.keys(t)) delete t[e].required;
|
|
564
|
+
return {
|
|
565
|
+
type: "function",
|
|
566
|
+
function: {
|
|
567
|
+
name: e.name,
|
|
568
|
+
description: e.description,
|
|
569
|
+
parameters: {
|
|
570
|
+
type: "object",
|
|
571
|
+
properties: t,
|
|
572
|
+
required: Object.keys(e.properties).filter((t) => e.properties[t].required)
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
}), n = {};
|
|
577
|
+
for (let t of e) n[t.name] = t.function;
|
|
578
|
+
return {
|
|
579
|
+
toolDefinitions: t,
|
|
580
|
+
toolExecutors: n
|
|
581
|
+
};
|
|
582
|
+
}, je = (e) => {
|
|
583
|
+
let t = /* @__PURE__ */ $({ model: "" }), n = /* @__PURE__ */ $([]), r = /* @__PURE__ */ $([]), i = /* @__PURE__ */ $({}), a = /* @__PURE__ */ $(10), o = /* @__PURE__ */ Ee({}), s = /* @__PURE__ */ $(), c = /* @__PURE__ */ $(!1);
|
|
584
|
+
return /* @__PURE__ */ G({
|
|
585
|
+
config: t,
|
|
586
|
+
messages: n,
|
|
587
|
+
maxIteration: a,
|
|
588
|
+
environment: o,
|
|
589
|
+
onEvent: s,
|
|
590
|
+
updateTools: (e) => {
|
|
591
|
+
let t = Ae(e);
|
|
592
|
+
r.value = t.toolDefinitions, i.value = t.toolExecutors;
|
|
593
|
+
},
|
|
594
|
+
start: async () => {
|
|
595
|
+
c.value = !0, s.value?.({ type: "agent_start" });
|
|
596
|
+
try {
|
|
597
|
+
for (let l = 0; l < a.value; l++) {
|
|
598
|
+
if (!c.value) return;
|
|
599
|
+
s.value?.({
|
|
600
|
+
type: "turn_start",
|
|
601
|
+
turnCount: l
|
|
602
|
+
});
|
|
603
|
+
let a = n.value.filter((e) => [
|
|
604
|
+
"system",
|
|
605
|
+
"user",
|
|
606
|
+
"assistant",
|
|
607
|
+
"tool"
|
|
608
|
+
].includes(e.role)), u = await ke(e, {
|
|
609
|
+
...t.value,
|
|
610
|
+
messages: a,
|
|
611
|
+
tools: r.value
|
|
612
|
+
}, (e) => {
|
|
613
|
+
s.value?.({
|
|
614
|
+
type: "message_update",
|
|
615
|
+
text: e
|
|
616
|
+
});
|
|
617
|
+
}, c);
|
|
618
|
+
if (n.value.push(u), !u.tool_calls) {
|
|
619
|
+
s.value?.({ type: "agent_end" });
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
for (let e of u.tool_calls) {
|
|
623
|
+
if (!c.value) throw Error("主动停止");
|
|
624
|
+
let t = i.value[e.function.name];
|
|
625
|
+
if (!t) continue;
|
|
626
|
+
s.value?.({
|
|
627
|
+
type: "tool_start",
|
|
628
|
+
toolCall: e
|
|
629
|
+
});
|
|
630
|
+
let r = JSON.parse(e.function.arguments), a;
|
|
631
|
+
try {
|
|
632
|
+
a = await t(r, o.value);
|
|
633
|
+
} catch (e) {
|
|
634
|
+
a = e instanceof Error ? e.message : e;
|
|
635
|
+
}
|
|
636
|
+
n.value.push({
|
|
637
|
+
role: "tool",
|
|
638
|
+
content: JSON.stringify(a),
|
|
639
|
+
tool_call_id: e.id
|
|
640
|
+
}), s.value?.({
|
|
641
|
+
type: "tool_end",
|
|
642
|
+
toolCall: e
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
s.value?.({
|
|
647
|
+
type: "agent_end",
|
|
648
|
+
turnCount: a.value
|
|
649
|
+
});
|
|
650
|
+
} catch (e) {
|
|
651
|
+
s.value?.({
|
|
652
|
+
type: "agent_error",
|
|
653
|
+
error: e
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
stop: () => {
|
|
658
|
+
c.value = !1;
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
};
|
|
662
|
+
//#endregion
|
|
663
|
+
export { je as createAgentManager };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createAgentManager, type AgentManager } from './services/loop';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
import type { ChatCompletionMessageParam } from 'openai/resources/chat/completions';
|
|
3
|
+
import { type Tool } from './tool';
|
|
4
|
+
export type AgentManager = {
|
|
5
|
+
/** 模型配置 */
|
|
6
|
+
config: {
|
|
7
|
+
model: string;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
/** 消息数组 */
|
|
11
|
+
messages: (ChatCompletionMessageParam & {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
})[];
|
|
14
|
+
/** 最大迭代次数 */
|
|
15
|
+
maxIteration: number;
|
|
16
|
+
/** 环境参数对象 */
|
|
17
|
+
environment: Record<string, any>;
|
|
18
|
+
/** 事件回调 */
|
|
19
|
+
onEvent?: (event: any) => void;
|
|
20
|
+
/** 更新工具 */
|
|
21
|
+
readonly updateTools: (tools: Tool[]) => void;
|
|
22
|
+
/** 开始 */
|
|
23
|
+
readonly start: () => Promise<void>;
|
|
24
|
+
/** 结束 */
|
|
25
|
+
readonly stop: () => void;
|
|
26
|
+
};
|
|
27
|
+
export declare const createAgentManager: (client: OpenAI) => AgentManager;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Ref } from '@vue/reactivity';
|
|
2
|
+
import type OpenAI from 'openai';
|
|
3
|
+
import type { ChatCompletionMessageParam, ChatCompletionTool, ChatCompletionMessageFunctionToolCall } from 'openai/resources/chat/completions';
|
|
4
|
+
export type Config = {
|
|
5
|
+
/** 模型 */
|
|
6
|
+
model: string;
|
|
7
|
+
/** 消息 */
|
|
8
|
+
messages: ChatCompletionMessageParam[];
|
|
9
|
+
/** 工具定义 */
|
|
10
|
+
tools: ChatCompletionTool[];
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
13
|
+
type Accumulated = {
|
|
14
|
+
role: 'assistant';
|
|
15
|
+
content?: string;
|
|
16
|
+
reasoning_content?: string;
|
|
17
|
+
tool_calls?: ChatCompletionMessageFunctionToolCall[];
|
|
18
|
+
};
|
|
19
|
+
export declare const streamOut: (client: OpenAI, config: Config, onChunk: (text: {
|
|
20
|
+
content?: string;
|
|
21
|
+
reasoning_content?: string;
|
|
22
|
+
}) => void, isRunning: Ref<boolean>) => Promise<Accumulated>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
type Property = {
|
|
2
|
+
type: string;
|
|
3
|
+
description: string;
|
|
4
|
+
required?: boolean;
|
|
5
|
+
items?: {
|
|
6
|
+
type: string;
|
|
7
|
+
};
|
|
8
|
+
enum?: string[];
|
|
9
|
+
minItems?: number;
|
|
10
|
+
};
|
|
11
|
+
export type Tool = {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
properties: Record<string, Property>;
|
|
15
|
+
function: (...args: any[]) => any;
|
|
16
|
+
};
|
|
17
|
+
export type ToolDefinition = {
|
|
18
|
+
type: 'function';
|
|
19
|
+
function: {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
parameters: {
|
|
23
|
+
type: 'object';
|
|
24
|
+
properties: Record<string, Omit<Property, 'required'>>;
|
|
25
|
+
required: string[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare const generateTools: (tools: Tool[]) => {
|
|
30
|
+
toolDefinitions: ToolDefinition[];
|
|
31
|
+
toolExecutors: Record<string, (...args: any[]) => any>;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lovelymai/agent",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "一个纯净极简易于使用的 Agent 框架",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"module": "dist/agent.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": ["dist"],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "vite build && tsc --declaration --emitDeclarationOnly --outDir dist"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@vue/reactivity": "^3.5.41"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"openai": "^7.7.0",
|
|
18
|
+
"typescript": "^7.0.2",
|
|
19
|
+
"vite": "^8.0.12"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"openai": ">=4.0.0"
|
|
23
|
+
}
|
|
24
|
+
}
|