@dudousxd/nestjs-agent 1.14.0 → 1.15.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/README.md +19 -0
- package/dist/{agent-deps.factory-DkWvoWbD.d.cts → chat-queue.service-Bqq00NN1.d.cts} +131 -2
- package/dist/{agent-deps.factory-DkWvoWbD.d.ts → chat-queue.service-Bqq00NN1.d.ts} +131 -2
- package/dist/durable/index.cjs +1773 -751
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +26 -7
- package/dist/durable/index.d.ts +26 -7
- package/dist/durable/index.js +1603 -581
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +1577 -666
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -7
- package/dist/index.d.ts +128 -7
- package/dist/index.js +1387 -478
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/durable/index.js
CHANGED
|
@@ -2,10 +2,10 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/durable/agent-run.workflow.ts
|
|
5
|
-
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_STORE, RunCancelledError, agentFailureCode, isReplayIntegrityError, publishAgentRunFailed, runAgentLoop, settleAll, settleUnsettledDelegation } from "@dudousxd/nestjs-agent-core";
|
|
5
|
+
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_STORE as AGENT_STORE2, RunCancelledError, agentFailureCode, encodeStreamEvent as encodeStreamEvent3, isReplayIntegrityError, publishAgentRunFailed, releaseThreadRun, runAgentLoop, settleAll, settleUnsettledDelegation } from "@dudousxd/nestjs-agent-core";
|
|
6
6
|
import { RUN_GATEWAY, Workflow } from "@dudousxd/nestjs-durable";
|
|
7
7
|
import { isWorkflowControlFlowSignal } from "@dudousxd/nestjs-durable-core";
|
|
8
|
-
import { Inject as
|
|
8
|
+
import { Inject as Inject3, Injectable as Injectable3, Optional as Optional2 } from "@nestjs/common";
|
|
9
9
|
|
|
10
10
|
// src/agent-deps.ts
|
|
11
11
|
function utcDay(date = /* @__PURE__ */ new Date()) {
|
|
@@ -23,10 +23,9 @@ function childSinkWriter(writer) {
|
|
|
23
23
|
}
|
|
24
24
|
__name(childSinkWriter, "childSinkWriter");
|
|
25
25
|
|
|
26
|
-
// src/
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import { Inject, Injectable } from "@nestjs/common";
|
|
26
|
+
// src/queue/chat-queue.service.ts
|
|
27
|
+
import { AGENT_ATTACHMENT_STAGING, AGENT_OPTIONS, AGENT_QUOTA_PROVIDER, AGENT_SINK, AGENT_STORE, encodeStreamEvent, isChatQueueStore, queuedMessageView } from "@dudousxd/nestjs-agent-core";
|
|
28
|
+
import { Inject, Injectable, Logger, NotImplementedException, Optional } from "@nestjs/common";
|
|
30
29
|
function _ts_decorate(decorators, target, key, desc) {
|
|
31
30
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
32
31
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -53,6 +52,434 @@ function _ts_param(paramIndex, decorator) {
|
|
|
53
52
|
};
|
|
54
53
|
}
|
|
55
54
|
__name(_ts_param, "_ts_param");
|
|
55
|
+
var MAX_DRAIN_ATTEMPTS = 8;
|
|
56
|
+
var ChatQueueService = class _ChatQueueService {
|
|
57
|
+
static {
|
|
58
|
+
__name(this, "ChatQueueService");
|
|
59
|
+
}
|
|
60
|
+
store;
|
|
61
|
+
sink;
|
|
62
|
+
quotaProvider;
|
|
63
|
+
options;
|
|
64
|
+
staging;
|
|
65
|
+
logger = new Logger(_ChatQueueService.name);
|
|
66
|
+
/**
|
|
67
|
+
* Runs this process claimed a thread for and has not handed to a runner yet. A holder in here is
|
|
68
|
+
* alive whatever the runner says — it simply has not registered the run yet.
|
|
69
|
+
*/
|
|
70
|
+
starting = /* @__PURE__ */ new Set();
|
|
71
|
+
constructor(store, sink, quotaProvider, options, staging) {
|
|
72
|
+
this.store = store;
|
|
73
|
+
this.sink = sink;
|
|
74
|
+
this.quotaProvider = quotaProvider;
|
|
75
|
+
this.options = options;
|
|
76
|
+
this.staging = staging;
|
|
77
|
+
}
|
|
78
|
+
/** Whether the bound store can hold a queue. Without one, a busy thread is not queued. */
|
|
79
|
+
get supported() {
|
|
80
|
+
return isChatQueueStore(this.store);
|
|
81
|
+
}
|
|
82
|
+
/** The bound store as a queue store, or a 501 naming what is missing. */
|
|
83
|
+
queueStore() {
|
|
84
|
+
if (!isChatQueueStore(this.store)) {
|
|
85
|
+
throw new NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
|
|
86
|
+
}
|
|
87
|
+
return this.store;
|
|
88
|
+
}
|
|
89
|
+
async state(threadId) {
|
|
90
|
+
const store = this.queueStore();
|
|
91
|
+
const [items, paused] = await Promise.all([
|
|
92
|
+
store.listQueue(threadId),
|
|
93
|
+
store.queuePause(threadId)
|
|
94
|
+
]);
|
|
95
|
+
return {
|
|
96
|
+
items: items.map(queuedMessageView),
|
|
97
|
+
paused
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Whether `holder` is still running. A run this process is about to start is; otherwise the
|
|
102
|
+
* runner decides, and a runner that cannot tell says yes.
|
|
103
|
+
*/
|
|
104
|
+
async isAlive(holder, runner) {
|
|
105
|
+
if (this.starting.has(holder)) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if (typeof runner.isRunActive !== "function") {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
return await runner.isRunActive(holder);
|
|
113
|
+
} catch {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The run holding `threadId`, or `null` when it is free — a holder the runner reports dead counts
|
|
119
|
+
* as free, and is returned as `stale` so the caller can claim over it.
|
|
120
|
+
*/
|
|
121
|
+
async holder(threadId, runner) {
|
|
122
|
+
const holder = await this.queueStore().activeRunForThread(threadId);
|
|
123
|
+
if (holder === null) {
|
|
124
|
+
return {
|
|
125
|
+
live: null,
|
|
126
|
+
stale: null
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return await this.isAlive(holder, runner) ? {
|
|
130
|
+
live: holder,
|
|
131
|
+
stale: null
|
|
132
|
+
} : {
|
|
133
|
+
live: null,
|
|
134
|
+
stale: holder
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Decide what follows a TOP-LEVEL run that is settling on `threadId`, and move the thread there:
|
|
139
|
+
* hand it to the next queued message (claimed and popped here, started by the caller), or pause
|
|
140
|
+
* the queue, or release the thread. Call it BEFORE the run's terminal frame, so a client reading
|
|
141
|
+
* the stream learns what comes next from the `queue` frame, and so the thread is already free
|
|
142
|
+
* when the client sees the run end.
|
|
143
|
+
*
|
|
144
|
+
* A no-op returning `{}` on a store without a queue.
|
|
145
|
+
*/
|
|
146
|
+
async plan(args) {
|
|
147
|
+
if (!isChatQueueStore(this.store)) {
|
|
148
|
+
return {};
|
|
149
|
+
}
|
|
150
|
+
const store = this.store;
|
|
151
|
+
const { threadId, outcome } = args;
|
|
152
|
+
if (await store.activeRunForThread(threadId) !== args.runId) {
|
|
153
|
+
return {};
|
|
154
|
+
}
|
|
155
|
+
let holding = args.runId;
|
|
156
|
+
for (let attempt = 0; attempt < MAX_DRAIN_ATTEMPTS; attempt += 1) {
|
|
157
|
+
const items = await store.listQueue(threadId);
|
|
158
|
+
const head = items[0];
|
|
159
|
+
if (head === void 0) {
|
|
160
|
+
if (holding !== null) {
|
|
161
|
+
await store.releaseActiveStream(threadId, holding);
|
|
162
|
+
holding = null;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
let pause = await store.queuePause(threadId);
|
|
168
|
+
if (pause === null) {
|
|
169
|
+
const reason = pauseReasonFor(outcome, head);
|
|
170
|
+
if (reason !== null) {
|
|
171
|
+
pause = {
|
|
172
|
+
reason,
|
|
173
|
+
...outcome === "failed" && args.error !== void 0 ? {
|
|
174
|
+
message: args.error
|
|
175
|
+
} : {},
|
|
176
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
177
|
+
};
|
|
178
|
+
await store.setQueuePause(threadId, pause);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (pause === null) {
|
|
182
|
+
const blocked = await this.quotaBlock(head.actor);
|
|
183
|
+
if (blocked !== null) {
|
|
184
|
+
pause = {
|
|
185
|
+
reason: "quota_exceeded",
|
|
186
|
+
message: blocked,
|
|
187
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
188
|
+
};
|
|
189
|
+
await store.setQueuePause(threadId, pause);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (pause !== null) {
|
|
193
|
+
if (holding !== null) {
|
|
194
|
+
await store.releaseActiveStream(threadId, holding);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
frame: queueFrame(items, pause)
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const claimed = await store.claimActiveStream(threadId, head.id, holding !== null ? {
|
|
201
|
+
replacing: holding
|
|
202
|
+
} : {});
|
|
203
|
+
if (!claimed) {
|
|
204
|
+
return {};
|
|
205
|
+
}
|
|
206
|
+
holding = head.id;
|
|
207
|
+
if (!await store.removeQueuedMessage(head.id)) {
|
|
208
|
+
await store.releaseActiveStream(threadId, head.id);
|
|
209
|
+
holding = null;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const next = {
|
|
213
|
+
runId: head.id,
|
|
214
|
+
messageId: head.id,
|
|
215
|
+
input: await this.inputFor(head)
|
|
216
|
+
};
|
|
217
|
+
return {
|
|
218
|
+
next,
|
|
219
|
+
frame: queueFrame(items.slice(1), null, {
|
|
220
|
+
messageId: head.id,
|
|
221
|
+
runId: head.id
|
|
222
|
+
})
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
if (holding !== null) {
|
|
226
|
+
await store.releaseActiveStream(threadId, holding);
|
|
227
|
+
}
|
|
228
|
+
return {};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* {@link plan}, then start what it picked with `start`. What an in-process settle (the inline
|
|
232
|
+
* runner, a durable cancel issued outside a workflow) calls; answers the frame to write.
|
|
233
|
+
*/
|
|
234
|
+
async handoff(args, start) {
|
|
235
|
+
const plan = await this.plan(args);
|
|
236
|
+
if (plan.next === void 0) {
|
|
237
|
+
return plan.frame;
|
|
238
|
+
}
|
|
239
|
+
return await this.launch(args.threadId, plan.next, start) ? plan.frame : this.pausedFrame(args.threadId);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Start the head of an IDLE thread's queue — after a send queued behind a run that turned out to
|
|
243
|
+
* be gone, after a resume, after a stale holder. Does nothing while a live run holds the thread
|
|
244
|
+
* (its settle drains) or while the queue is paused. Answers the started run's id, if any.
|
|
245
|
+
*/
|
|
246
|
+
async kick(threadId, runner) {
|
|
247
|
+
if (!isChatQueueStore(this.store)) {
|
|
248
|
+
return void 0;
|
|
249
|
+
}
|
|
250
|
+
const { live, stale } = await this.holder(threadId, runner);
|
|
251
|
+
if (live !== null) {
|
|
252
|
+
return void 0;
|
|
253
|
+
}
|
|
254
|
+
if (stale !== null) {
|
|
255
|
+
this.logger.warn(`thread ${threadId} was held by run ${stale}, which is no longer running`);
|
|
256
|
+
}
|
|
257
|
+
const plan = await this.plan({
|
|
258
|
+
threadId,
|
|
259
|
+
runId: stale,
|
|
260
|
+
outcome: "completed"
|
|
261
|
+
});
|
|
262
|
+
if (plan.next === void 0) {
|
|
263
|
+
return void 0;
|
|
264
|
+
}
|
|
265
|
+
const started = await this.launch(threadId, plan.next, (input, runId) => runner.start(input, {
|
|
266
|
+
runId
|
|
267
|
+
}));
|
|
268
|
+
if (started && plan.frame !== void 0) {
|
|
269
|
+
await this.write(plan.next.runId, plan.frame);
|
|
270
|
+
}
|
|
271
|
+
return started ? plan.next.runId : void 0;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Start a turn the thread is already claimed for. On failure the message goes back to the head of
|
|
275
|
+
* the queue, the queue pauses (`start_failed`), and the claim is released — nothing is lost and
|
|
276
|
+
* nothing is left holding the thread.
|
|
277
|
+
*/
|
|
278
|
+
async launch(threadId, next, start) {
|
|
279
|
+
this.starting.add(next.runId);
|
|
280
|
+
try {
|
|
281
|
+
await start(next.input, next.runId);
|
|
282
|
+
return true;
|
|
283
|
+
} catch (error) {
|
|
284
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
285
|
+
this.logger.error(`queued message ${next.messageId} could not start: ${message}`);
|
|
286
|
+
await this.restore(threadId, next, "start_failed", message);
|
|
287
|
+
return false;
|
|
288
|
+
} finally {
|
|
289
|
+
this.starting.delete(next.runId);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/** Put a turn that never started back at the head of its queue, paused, and free the thread. */
|
|
293
|
+
async restore(threadId, next, reason, message) {
|
|
294
|
+
const store = this.queueStore();
|
|
295
|
+
const { input } = next;
|
|
296
|
+
await store.enqueueMessage({
|
|
297
|
+
threadId,
|
|
298
|
+
actor: input.actor,
|
|
299
|
+
content: input.userText,
|
|
300
|
+
at: "head",
|
|
301
|
+
...input.attachments !== void 0 ? {
|
|
302
|
+
attachments: input.attachments
|
|
303
|
+
} : {},
|
|
304
|
+
...input.agentName !== void 0 ? {
|
|
305
|
+
agentName: input.agentName
|
|
306
|
+
} : {},
|
|
307
|
+
...input.model !== void 0 ? {
|
|
308
|
+
model: input.model
|
|
309
|
+
} : {},
|
|
310
|
+
...input.pageContext !== void 0 ? {
|
|
311
|
+
pageContext: input.pageContext
|
|
312
|
+
} : {}
|
|
313
|
+
});
|
|
314
|
+
await store.setQueuePause(threadId, {
|
|
315
|
+
reason,
|
|
316
|
+
message,
|
|
317
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
318
|
+
});
|
|
319
|
+
await store.releaseActiveStream(threadId, next.runId);
|
|
320
|
+
}
|
|
321
|
+
/** A `queue` frame with the thread's current state. */
|
|
322
|
+
async pausedFrame(threadId) {
|
|
323
|
+
return {
|
|
324
|
+
kind: "queue",
|
|
325
|
+
queue: await this.state(threadId)
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Tell whoever is watching the thread that its queue changed: a `queue` frame into the stream of
|
|
330
|
+
* the run holding it. Best-effort — a thread nobody is streaming has no one to tell, and the next
|
|
331
|
+
* read of the thread carries the queue anyway.
|
|
332
|
+
*/
|
|
333
|
+
async publish(threadId) {
|
|
334
|
+
const state = await this.state(threadId);
|
|
335
|
+
const holder = await this.queueStore().activeRunForThread(threadId);
|
|
336
|
+
if (holder !== null) {
|
|
337
|
+
await this.write(holder, {
|
|
338
|
+
kind: "queue",
|
|
339
|
+
queue: state
|
|
340
|
+
}).catch((error) => {
|
|
341
|
+
this.logger.warn(`could not publish the queue of thread ${threadId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return state;
|
|
345
|
+
}
|
|
346
|
+
async write(runId, frame) {
|
|
347
|
+
const writer = await this.sink.open(runId);
|
|
348
|
+
await writer.write(encodeStreamEvent(frame));
|
|
349
|
+
}
|
|
350
|
+
/** Why `actor` may not start a turn now (the quota message), or `null`. */
|
|
351
|
+
async quotaBlock(actor) {
|
|
352
|
+
if (this.options?.quota === void 0 || this.quotaProvider === void 0) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
const { blocked } = await this.quotaProvider.report({
|
|
357
|
+
actor
|
|
358
|
+
});
|
|
359
|
+
if (blocked === void 0) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
return blocked.reason ?? `The ${blocked.period === "day" ? "daily" : "monthly"} quota is used up`;
|
|
363
|
+
} catch {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* The turn a queued message starts: everything it was queued with, today's date, and its
|
|
369
|
+
* attachments' urls minted afresh — the ones stored at enqueue time may have expired while it
|
|
370
|
+
* waited. An attachment the staging store no longer resolves keeps its stored url.
|
|
371
|
+
*/
|
|
372
|
+
async inputFor(message) {
|
|
373
|
+
const attachments = await this.freshAttachments(message.actor, message.attachments ?? []);
|
|
374
|
+
return {
|
|
375
|
+
threadId: message.threadId,
|
|
376
|
+
actor: message.actor,
|
|
377
|
+
userText: message.content,
|
|
378
|
+
day: utcDay(),
|
|
379
|
+
...message.agentName !== void 0 ? {
|
|
380
|
+
agentName: message.agentName
|
|
381
|
+
} : {},
|
|
382
|
+
...attachments.length > 0 ? {
|
|
383
|
+
attachments
|
|
384
|
+
} : {},
|
|
385
|
+
...message.pageContext !== void 0 ? {
|
|
386
|
+
pageContext: message.pageContext
|
|
387
|
+
} : {},
|
|
388
|
+
...message.model !== void 0 ? {
|
|
389
|
+
model: message.model
|
|
390
|
+
} : {}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
async freshAttachments(actor, attachments) {
|
|
394
|
+
const staging = this.staging;
|
|
395
|
+
if (attachments.length === 0 || staging === void 0 || typeof staging.resolve !== "function") {
|
|
396
|
+
return attachments;
|
|
397
|
+
}
|
|
398
|
+
return Promise.all(attachments.map(async (attachment) => {
|
|
399
|
+
try {
|
|
400
|
+
return await staging.resolve({
|
|
401
|
+
mediaId: attachment.mediaId,
|
|
402
|
+
actor
|
|
403
|
+
}) ?? attachment;
|
|
404
|
+
} catch {
|
|
405
|
+
return attachment;
|
|
406
|
+
}
|
|
407
|
+
}));
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
ChatQueueService = _ts_decorate([
|
|
411
|
+
Injectable(),
|
|
412
|
+
_ts_param(0, Inject(AGENT_STORE)),
|
|
413
|
+
_ts_param(1, Inject(AGENT_SINK)),
|
|
414
|
+
_ts_param(2, Optional()),
|
|
415
|
+
_ts_param(2, Inject(AGENT_QUOTA_PROVIDER)),
|
|
416
|
+
_ts_param(3, Optional()),
|
|
417
|
+
_ts_param(3, Inject(AGENT_OPTIONS)),
|
|
418
|
+
_ts_param(4, Optional()),
|
|
419
|
+
_ts_param(4, Inject(AGENT_ATTACHMENT_STAGING)),
|
|
420
|
+
_ts_metadata("design:type", Function),
|
|
421
|
+
_ts_metadata("design:paramtypes", [
|
|
422
|
+
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
423
|
+
typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
|
|
424
|
+
typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
|
|
425
|
+
typeof Pick === "undefined" ? Object : Pick,
|
|
426
|
+
typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore
|
|
427
|
+
])
|
|
428
|
+
], ChatQueueService);
|
|
429
|
+
function pauseReasonFor(outcome, head) {
|
|
430
|
+
if (outcome === "failed") {
|
|
431
|
+
return "run_failed";
|
|
432
|
+
}
|
|
433
|
+
if (outcome === "cancelled" && head.interrupt !== true) {
|
|
434
|
+
return "cancelled";
|
|
435
|
+
}
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
__name(pauseReasonFor, "pauseReasonFor");
|
|
439
|
+
function queueFrame(items, paused, started) {
|
|
440
|
+
return {
|
|
441
|
+
kind: "queue",
|
|
442
|
+
queue: {
|
|
443
|
+
items: items.map(queuedMessageView),
|
|
444
|
+
paused
|
|
445
|
+
},
|
|
446
|
+
...started !== void 0 ? {
|
|
447
|
+
started
|
|
448
|
+
} : {}
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
__name(queueFrame, "queueFrame");
|
|
452
|
+
|
|
453
|
+
// src/durable/agent-run.steps.ts
|
|
454
|
+
import { AGENT_DEPS_FACTORY, createFrameBuffer, createUiCollector, encodeStreamEvent as encodeStreamEvent2, invokeWithTransientRetry, observeTurnFrames, publishAgentToolRetry, stampToolKinds, traceLlmTurn, traceToolExecution, withAskTool, withMemoryTool, withSkillTool, withToolTimeout, withTurnFrames, wrapToolStepOutput } from "@dudousxd/nestjs-agent-core";
|
|
455
|
+
import { Step } from "@dudousxd/nestjs-durable";
|
|
456
|
+
import { Inject as Inject2, Injectable as Injectable2 } from "@nestjs/common";
|
|
457
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
458
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
459
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
460
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
461
|
+
} else {
|
|
462
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
463
|
+
if (d = decorators[i]) {
|
|
464
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
469
|
+
}
|
|
470
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
471
|
+
function _ts_metadata2(metadataKey, metadataValue) {
|
|
472
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
473
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
477
|
+
function _ts_param2(paramIndex, decorator) {
|
|
478
|
+
return function(target, key) {
|
|
479
|
+
decorator(target, key, paramIndex);
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
__name(_ts_param2, "_ts_param");
|
|
56
483
|
var AgentRunSteps = class {
|
|
57
484
|
static {
|
|
58
485
|
__name(this, "AgentRunSteps");
|
|
@@ -129,7 +556,7 @@ var AgentRunSteps = class {
|
|
|
129
556
|
let opened;
|
|
130
557
|
const ui = createUiCollector(input.toolCallId, sinkRunId === void 0 ? void 0 : async (event) => {
|
|
131
558
|
opened ??= Promise.resolve(deps.sink.open(sinkRunId)).then((writer) => input.childSink === true ? childSinkWriter(writer) : writer);
|
|
132
|
-
await (await opened).write(
|
|
559
|
+
await (await opened).write(encodeStreamEvent2(event));
|
|
133
560
|
});
|
|
134
561
|
const ctx = {
|
|
135
562
|
...input.ctx,
|
|
@@ -164,35 +591,35 @@ var AgentRunSteps = class {
|
|
|
164
591
|
return input.collectUi === true ? wrapToolStepOutput(output, ui.components()) : output;
|
|
165
592
|
}
|
|
166
593
|
};
|
|
167
|
-
|
|
594
|
+
_ts_decorate2([
|
|
168
595
|
Step({
|
|
169
596
|
retries: 3
|
|
170
597
|
}),
|
|
171
|
-
|
|
172
|
-
|
|
598
|
+
_ts_metadata2("design:type", Function),
|
|
599
|
+
_ts_metadata2("design:paramtypes", [
|
|
173
600
|
typeof DispatchedLlmInput === "undefined" ? Object : DispatchedLlmInput
|
|
174
601
|
]),
|
|
175
|
-
|
|
602
|
+
_ts_metadata2("design:returntype", Promise)
|
|
176
603
|
], AgentRunSteps.prototype, "llm", null);
|
|
177
|
-
|
|
604
|
+
_ts_decorate2([
|
|
178
605
|
Step(),
|
|
179
|
-
|
|
180
|
-
|
|
606
|
+
_ts_metadata2("design:type", Function),
|
|
607
|
+
_ts_metadata2("design:paramtypes", [
|
|
181
608
|
typeof DispatchedToolInput === "undefined" ? Object : DispatchedToolInput
|
|
182
609
|
]),
|
|
183
|
-
|
|
610
|
+
_ts_metadata2("design:returntype", Promise)
|
|
184
611
|
], AgentRunSteps.prototype, "tool", null);
|
|
185
|
-
AgentRunSteps =
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
612
|
+
AgentRunSteps = _ts_decorate2([
|
|
613
|
+
Injectable2(),
|
|
614
|
+
_ts_param2(0, Inject2(AGENT_DEPS_FACTORY)),
|
|
615
|
+
_ts_metadata2("design:type", Function),
|
|
616
|
+
_ts_metadata2("design:paramtypes", [
|
|
190
617
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
|
|
191
618
|
])
|
|
192
619
|
], AgentRunSteps);
|
|
193
620
|
|
|
194
621
|
// src/durable/agent-run.workflow.ts
|
|
195
|
-
function
|
|
622
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
196
623
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
197
624
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
198
625
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -205,19 +632,19 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
205
632
|
}
|
|
206
633
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
207
634
|
}
|
|
208
|
-
__name(
|
|
209
|
-
function
|
|
635
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
636
|
+
function _ts_metadata3(metadataKey, metadataValue) {
|
|
210
637
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
211
638
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
212
639
|
}
|
|
213
640
|
}
|
|
214
|
-
__name(
|
|
215
|
-
function
|
|
641
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
642
|
+
function _ts_param3(paramIndex, decorator) {
|
|
216
643
|
return function(target, key) {
|
|
217
644
|
decorator(target, key, paramIndex);
|
|
218
645
|
};
|
|
219
646
|
}
|
|
220
|
-
__name(
|
|
647
|
+
__name(_ts_param3, "_ts_param");
|
|
221
648
|
var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
222
649
|
static {
|
|
223
650
|
__name(this, "AgentRunWorkflow");
|
|
@@ -225,10 +652,63 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
|
225
652
|
factory;
|
|
226
653
|
store;
|
|
227
654
|
runs;
|
|
228
|
-
|
|
655
|
+
queue;
|
|
656
|
+
constructor(factory, store, runs, queue) {
|
|
229
657
|
this.factory = factory;
|
|
230
658
|
this.store = store;
|
|
231
659
|
this.runs = runs;
|
|
660
|
+
this.queue = queue;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Move the thread past this settling turn — to the next queued message, started here as a
|
|
664
|
+
* fire-and-forget `ctx.startChild` under the message's own id, or to a paused/empty queue — and
|
|
665
|
+
* answer the `queue` frame to write before the turn's terminal.
|
|
666
|
+
*
|
|
667
|
+
* Journaled: the decision (which message, claimed and popped) is one `localStep`, so a replay
|
|
668
|
+
* reads it back instead of popping a second message, and the start is the runtime's own
|
|
669
|
+
* replay-safe spawn. Gated by `ctx.patched`, so a run recorded before the queue existed replays
|
|
670
|
+
* against the history it has. A no-op for a sub-agent's run and on a store without a queue.
|
|
671
|
+
*/
|
|
672
|
+
async advanceQueue(ctx, input, outcome, error) {
|
|
673
|
+
const queue = this.queue;
|
|
674
|
+
if (queue === void 0 || !queue.supported || input.sinkRunId !== void 0 || input.deliverTo !== void 0) {
|
|
675
|
+
return void 0;
|
|
676
|
+
}
|
|
677
|
+
if (!await ctx.patched("agent:chat-queue")) {
|
|
678
|
+
return void 0;
|
|
679
|
+
}
|
|
680
|
+
const plan = await ctx.localStep(`queue:${outcome}`, async () => {
|
|
681
|
+
try {
|
|
682
|
+
const settled = outcome === "completed" && await this.isCancelled(ctx.runId) ? "cancelled" : outcome;
|
|
683
|
+
return await queue.plan({
|
|
684
|
+
threadId: input.threadId,
|
|
685
|
+
runId: ctx.runId,
|
|
686
|
+
outcome: settled,
|
|
687
|
+
...error !== void 0 ? {
|
|
688
|
+
error
|
|
689
|
+
} : {}
|
|
690
|
+
});
|
|
691
|
+
} catch {
|
|
692
|
+
return {};
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
const next = plan.next;
|
|
696
|
+
if (next === void 0) {
|
|
697
|
+
return plan.frame;
|
|
698
|
+
}
|
|
699
|
+
try {
|
|
700
|
+
await ctx.startChild(_AgentRunWorkflow, next.input, next.runId);
|
|
701
|
+
return plan.frame;
|
|
702
|
+
} catch (failure) {
|
|
703
|
+
if (isWorkflowControlFlowSignal(failure)) {
|
|
704
|
+
throw failure;
|
|
705
|
+
}
|
|
706
|
+
const reason = failure instanceof Error ? failure.message : String(failure);
|
|
707
|
+
return ctx.localStep("queue:restore", async () => {
|
|
708
|
+
await queue.restore(input.threadId, next, "start_failed", reason);
|
|
709
|
+
return queue.pausedFrame(input.threadId);
|
|
710
|
+
});
|
|
711
|
+
}
|
|
232
712
|
}
|
|
233
713
|
/**
|
|
234
714
|
* Has someone asked this run to stop? Read from the runtime's own run status, which is where
|
|
@@ -294,7 +774,25 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
|
294
774
|
const hooks = {
|
|
295
775
|
runId: ctx.runId,
|
|
296
776
|
// A child forwards into the top-level sink but must not end/fail it (the top-level run owns it).
|
|
297
|
-
|
|
777
|
+
// A thread's own turn hands the thread to its queue just before the loop ends the stream, so
|
|
778
|
+
// the reader learns what runs next from the `queue` frame, before the end.
|
|
779
|
+
openSink: /* @__PURE__ */ __name(async () => {
|
|
780
|
+
if (input.sinkRunId !== void 0) {
|
|
781
|
+
return childSinkWriter(await deps.sink.open(sinkRunId));
|
|
782
|
+
}
|
|
783
|
+
const writer = await deps.sink.open(ctx.runId);
|
|
784
|
+
return {
|
|
785
|
+
write: /* @__PURE__ */ __name((chunk) => writer.write(chunk), "write"),
|
|
786
|
+
fail: /* @__PURE__ */ __name((failure) => writer.fail(failure), "fail"),
|
|
787
|
+
end: /* @__PURE__ */ __name(async () => {
|
|
788
|
+
const frame = await this.advanceQueue(ctx, input, "completed");
|
|
789
|
+
if (frame !== void 0) {
|
|
790
|
+
await writer.write(encodeStreamEvent3(frame));
|
|
791
|
+
}
|
|
792
|
+
await writer.end();
|
|
793
|
+
}, "end")
|
|
794
|
+
};
|
|
795
|
+
}, "openSink"),
|
|
298
796
|
// A policy's time to live becomes the signal wait's own timeout: the runtime journals the
|
|
299
797
|
// deadline on the first call (a position of its own, reached only for a call the journal says
|
|
300
798
|
// has a ttl) and wakes the run when it passes. The lapse comes back as a Decision rather than a
|
|
@@ -417,14 +915,14 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
|
417
915
|
...deps,
|
|
418
916
|
day
|
|
419
917
|
}, input, hooks);
|
|
420
|
-
await ctx.localStep("deactivate", () => this.store
|
|
918
|
+
await ctx.localStep("deactivate", () => releaseThreadRun(this.store, input.threadId, ctx.runId));
|
|
421
919
|
return result;
|
|
422
920
|
} catch (error) {
|
|
423
921
|
if (isWorkflowControlFlowSignal(error)) {
|
|
424
922
|
throw error;
|
|
425
923
|
}
|
|
426
924
|
if (error instanceof RunCancelledError) {
|
|
427
|
-
await ctx.localStep("deactivate", () => this.store
|
|
925
|
+
await ctx.localStep("deactivate", () => releaseThreadRun(this.store, input.threadId, ctx.runId));
|
|
428
926
|
await this.settleDetachedParent(ctx, input, {
|
|
429
927
|
status: "cancelled"
|
|
430
928
|
});
|
|
@@ -455,12 +953,16 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
|
455
953
|
errorCode: code,
|
|
456
954
|
errorMessage: message
|
|
457
955
|
}) ?? Promise.resolve());
|
|
458
|
-
|
|
956
|
+
const queueFrame2 = await this.advanceQueue(ctx, input, "failed", message);
|
|
957
|
+
await ctx.localStep("deactivate", () => releaseThreadRun(this.store, input.threadId, ctx.runId));
|
|
459
958
|
await this.settleDetachedParent(ctx, input, {
|
|
460
959
|
status: "failed",
|
|
461
960
|
error: message
|
|
462
961
|
});
|
|
463
962
|
const writer = await hooks.openSink();
|
|
963
|
+
if (queueFrame2 !== void 0) {
|
|
964
|
+
await writer.write(encodeStreamEvent3(queueFrame2));
|
|
965
|
+
}
|
|
464
966
|
await writer.fail({
|
|
465
967
|
code,
|
|
466
968
|
message
|
|
@@ -469,21 +971,23 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
|
469
971
|
}
|
|
470
972
|
}
|
|
471
973
|
};
|
|
472
|
-
AgentRunWorkflow =
|
|
473
|
-
|
|
974
|
+
AgentRunWorkflow = _ts_decorate3([
|
|
975
|
+
Injectable3(),
|
|
474
976
|
Workflow({
|
|
475
977
|
name: "agent.run",
|
|
476
978
|
version: "1"
|
|
477
979
|
}),
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
980
|
+
_ts_param3(0, Inject3(AGENT_DEPS_FACTORY2)),
|
|
981
|
+
_ts_param3(1, Inject3(AGENT_STORE2)),
|
|
982
|
+
_ts_param3(2, Optional2()),
|
|
983
|
+
_ts_param3(2, Inject3(RUN_GATEWAY)),
|
|
984
|
+
_ts_param3(3, Optional2()),
|
|
985
|
+
_ts_metadata3("design:type", Function),
|
|
986
|
+
_ts_metadata3("design:paramtypes", [
|
|
484
987
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
485
988
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
486
|
-
typeof RunGateway === "undefined" ? Object : RunGateway
|
|
989
|
+
typeof RunGateway === "undefined" ? Object : RunGateway,
|
|
990
|
+
typeof ChatQueueService === "undefined" ? Object : ChatQueueService
|
|
487
991
|
])
|
|
488
992
|
], AgentRunWorkflow);
|
|
489
993
|
function isSignalTimeout(error) {
|
|
@@ -493,10 +997,10 @@ __name(isSignalTimeout, "isSignalTimeout");
|
|
|
493
997
|
|
|
494
998
|
// src/durable/durable-agent-runner.ts
|
|
495
999
|
import { randomUUID } from "crypto";
|
|
496
|
-
import { AGENT_SINK, AGENT_STORE as
|
|
1000
|
+
import { AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE3, encodeStreamEvent as encodeStreamEvent4, releaseThreadRun as releaseThreadRun2 } from "@dudousxd/nestjs-agent-core";
|
|
497
1001
|
import { RUN_GATEWAY as RUN_GATEWAY2, WorkflowService } from "@dudousxd/nestjs-durable";
|
|
498
1002
|
import { isWorkflowControlFlowSignal as isWorkflowControlFlowSignal2 } from "@dudousxd/nestjs-durable-core";
|
|
499
|
-
import { Inject as
|
|
1003
|
+
import { Inject as Inject4, Injectable as Injectable4, Logger as Logger2, Optional as Optional3 } from "@nestjs/common";
|
|
500
1004
|
|
|
501
1005
|
// src/in-process-sink.ts
|
|
502
1006
|
import { AgentStreamError } from "@dudousxd/nestjs-agent-core";
|
|
@@ -567,7 +1071,7 @@ var InProcessTokenStreamSink = class {
|
|
|
567
1071
|
};
|
|
568
1072
|
|
|
569
1073
|
// src/durable/durable-agent-runner.ts
|
|
570
|
-
function
|
|
1074
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
571
1075
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
572
1076
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
573
1077
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -580,19 +1084,19 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
580
1084
|
}
|
|
581
1085
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
582
1086
|
}
|
|
583
|
-
__name(
|
|
584
|
-
function
|
|
1087
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
1088
|
+
function _ts_metadata4(metadataKey, metadataValue) {
|
|
585
1089
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
586
1090
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
587
1091
|
}
|
|
588
1092
|
}
|
|
589
|
-
__name(
|
|
590
|
-
function
|
|
1093
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
1094
|
+
function _ts_param4(paramIndex, decorator) {
|
|
591
1095
|
return function(target, key) {
|
|
592
1096
|
decorator(target, key, paramIndex);
|
|
593
1097
|
};
|
|
594
1098
|
}
|
|
595
|
-
__name(
|
|
1099
|
+
__name(_ts_param4, "_ts_param");
|
|
596
1100
|
function threadOfRun(input) {
|
|
597
1101
|
if (typeof input !== "object" || input === null || !("threadId" in input)) {
|
|
598
1102
|
return void 0;
|
|
@@ -600,6 +1104,10 @@ function threadOfRun(input) {
|
|
|
600
1104
|
return typeof input.threadId === "string" ? input.threadId : void 0;
|
|
601
1105
|
}
|
|
602
1106
|
__name(threadOfRun, "threadOfRun");
|
|
1107
|
+
function isThreadTurn(input) {
|
|
1108
|
+
return typeof input === "object" && input !== null && input.sinkRunId === void 0 && input.deliverTo === void 0;
|
|
1109
|
+
}
|
|
1110
|
+
__name(isThreadTurn, "isThreadTurn");
|
|
603
1111
|
var DurableAgentRunner = class _DurableAgentRunner {
|
|
604
1112
|
static {
|
|
605
1113
|
__name(this, "DurableAgentRunner");
|
|
@@ -608,22 +1116,24 @@ var DurableAgentRunner = class _DurableAgentRunner {
|
|
|
608
1116
|
runs;
|
|
609
1117
|
store;
|
|
610
1118
|
sink;
|
|
611
|
-
|
|
612
|
-
|
|
1119
|
+
queue;
|
|
1120
|
+
logger = new Logger2(_DurableAgentRunner.name);
|
|
1121
|
+
constructor(workflows, runs, store, sink, queue) {
|
|
613
1122
|
this.workflows = workflows;
|
|
614
1123
|
this.runs = runs;
|
|
615
1124
|
this.store = store;
|
|
616
1125
|
this.sink = sink;
|
|
1126
|
+
this.queue = queue;
|
|
617
1127
|
if (this.sink instanceof InProcessTokenStreamSink) {
|
|
618
1128
|
this.logger.warn("durable: true with the default InProcessTokenStreamSink, which only buffers tokens in this process. The worker that runs the turn \u2014 and the one that serves its dispatched `llm` step \u2014 cannot stream into this buffer. Wire a cross-process TokenStreamSink (e.g. a Redis pub/sub sink) via AgentModule.forRoot({ sink }) before running multi-pod.");
|
|
619
1129
|
}
|
|
620
1130
|
}
|
|
621
|
-
async start(input) {
|
|
1131
|
+
async start(input, options = {}) {
|
|
622
1132
|
const stamped = {
|
|
623
1133
|
...input,
|
|
624
1134
|
day: input.day ?? utcDay()
|
|
625
1135
|
};
|
|
626
|
-
const runId = randomUUID();
|
|
1136
|
+
const runId = options.runId ?? randomUUID();
|
|
627
1137
|
try {
|
|
628
1138
|
await this.workflows.start(AgentRunWorkflow, stamped, runId);
|
|
629
1139
|
} catch (error) {
|
|
@@ -635,6 +1145,19 @@ var DurableAgentRunner = class _DurableAgentRunner {
|
|
|
635
1145
|
runId
|
|
636
1146
|
};
|
|
637
1147
|
}
|
|
1148
|
+
/**
|
|
1149
|
+
* From the runtime's own run row. A run it does not know yet counts as running — a queued turn is
|
|
1150
|
+
* claimed before its `startChild` lands — and so does one it cannot be asked about: only a run the
|
|
1151
|
+
* runtime reports settled (`completed`/`failed`/`cancelled`/`dead`) is stale.
|
|
1152
|
+
*/
|
|
1153
|
+
async isRunActive(runId) {
|
|
1154
|
+
try {
|
|
1155
|
+
const status = (await this.runs.getRunDetail(runId))?.run.status;
|
|
1156
|
+
return !(status === "completed" || status === "failed" || status === "cancelled" || status === "dead");
|
|
1157
|
+
} catch {
|
|
1158
|
+
return true;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
638
1161
|
async signal(runId, toolCallId2, reply) {
|
|
639
1162
|
await this.workflows.signal(`tool:${runId}:${toolCallId2}`, reply);
|
|
640
1163
|
}
|
|
@@ -664,15 +1187,32 @@ var DurableAgentRunner = class _DurableAgentRunner {
|
|
|
664
1187
|
*/
|
|
665
1188
|
async cancel(runId) {
|
|
666
1189
|
this.logger.log(`cancelling agent run ${runId}`);
|
|
667
|
-
const
|
|
1190
|
+
const input = await this.inputOf(runId);
|
|
1191
|
+
const threadId = threadOfRun(input);
|
|
668
1192
|
await this.runs.cancel(runId, {
|
|
669
1193
|
compensate: true
|
|
670
1194
|
});
|
|
1195
|
+
const writer = await this.sink.open(runId);
|
|
671
1196
|
if (threadId !== void 0) {
|
|
672
|
-
|
|
1197
|
+
if (this.queue?.supported === true && isThreadTurn(input)) {
|
|
1198
|
+
try {
|
|
1199
|
+
const frame = await this.queue.handoff({
|
|
1200
|
+
threadId,
|
|
1201
|
+
runId,
|
|
1202
|
+
outcome: "cancelled"
|
|
1203
|
+
}, (next, nextRunId) => this.start(next, {
|
|
1204
|
+
runId: nextRunId
|
|
1205
|
+
}));
|
|
1206
|
+
if (frame !== void 0) {
|
|
1207
|
+
await writer.write(encodeStreamEvent4(frame));
|
|
1208
|
+
}
|
|
1209
|
+
} catch (error) {
|
|
1210
|
+
this.logger.error(`could not advance the queue of thread ${threadId} after cancelling ${runId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
await releaseThreadRun2(this.store, threadId, runId);
|
|
673
1214
|
}
|
|
674
|
-
|
|
675
|
-
await writer.write(encodeStreamEvent2({
|
|
1215
|
+
await writer.write(encodeStreamEvent4({
|
|
676
1216
|
kind: "cancelled"
|
|
677
1217
|
}));
|
|
678
1218
|
await writer.end();
|
|
@@ -682,7 +1222,7 @@ var DurableAgentRunner = class _DurableAgentRunner {
|
|
|
682
1222
|
});
|
|
683
1223
|
}
|
|
684
1224
|
/**
|
|
685
|
-
*
|
|
1225
|
+
* The input a run was started with (which thread it was streaming), or `undefined` where the gateway cannot say.
|
|
686
1226
|
*
|
|
687
1227
|
* A read failure answers `undefined` instead of propagating, the same posture `AgentRunWorkflow`
|
|
688
1228
|
* takes for its own cancel observation: failing to ask is not an answer worth failing a cancel
|
|
@@ -691,32 +1231,34 @@ var DurableAgentRunner = class _DurableAgentRunner {
|
|
|
691
1231
|
* with a subscriber holding a stream that never settles, from the one call whose entire job is to
|
|
692
1232
|
* make a run stop.
|
|
693
1233
|
*/
|
|
694
|
-
async
|
|
1234
|
+
async inputOf(runId) {
|
|
695
1235
|
try {
|
|
696
|
-
return
|
|
1236
|
+
return (await this.runs.getRunDetail(runId))?.run.input;
|
|
697
1237
|
} catch {
|
|
698
1238
|
return void 0;
|
|
699
1239
|
}
|
|
700
1240
|
}
|
|
701
1241
|
};
|
|
702
|
-
DurableAgentRunner =
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
1242
|
+
DurableAgentRunner = _ts_decorate4([
|
|
1243
|
+
Injectable4(),
|
|
1244
|
+
_ts_param4(1, Inject4(RUN_GATEWAY2)),
|
|
1245
|
+
_ts_param4(2, Inject4(AGENT_STORE3)),
|
|
1246
|
+
_ts_param4(3, Inject4(AGENT_SINK2)),
|
|
1247
|
+
_ts_param4(4, Optional3()),
|
|
1248
|
+
_ts_metadata4("design:type", Function),
|
|
1249
|
+
_ts_metadata4("design:paramtypes", [
|
|
709
1250
|
typeof WorkflowService === "undefined" ? Object : WorkflowService,
|
|
710
1251
|
typeof RunGateway === "undefined" ? Object : RunGateway,
|
|
711
1252
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
712
|
-
typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink
|
|
1253
|
+
typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
|
|
1254
|
+
typeof ChatQueueService === "undefined" ? Object : ChatQueueService
|
|
713
1255
|
])
|
|
714
1256
|
], DurableAgentRunner);
|
|
715
1257
|
|
|
716
1258
|
// src/durable/agent-durable.module.ts
|
|
717
1259
|
import { AGENT_DURABLE_RUNNER } from "@dudousxd/nestjs-agent-core";
|
|
718
1260
|
import { Global, Module } from "@nestjs/common";
|
|
719
|
-
function
|
|
1261
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
720
1262
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
721
1263
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
722
1264
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -729,7 +1271,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
729
1271
|
}
|
|
730
1272
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
731
1273
|
}
|
|
732
|
-
__name(
|
|
1274
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
733
1275
|
function runnerProviders() {
|
|
734
1276
|
return [
|
|
735
1277
|
DurableAgentRunner,
|
|
@@ -745,7 +1287,7 @@ var AgentDurableHttpModule = class AgentDurableHttpModule2 {
|
|
|
745
1287
|
__name(this, "AgentDurableHttpModule");
|
|
746
1288
|
}
|
|
747
1289
|
};
|
|
748
|
-
AgentDurableHttpModule =
|
|
1290
|
+
AgentDurableHttpModule = _ts_decorate5([
|
|
749
1291
|
Global(),
|
|
750
1292
|
Module({
|
|
751
1293
|
providers: [
|
|
@@ -783,7 +1325,7 @@ var AgentDurableModule = class _AgentDurableModule {
|
|
|
783
1325
|
};
|
|
784
1326
|
}
|
|
785
1327
|
};
|
|
786
|
-
AgentDurableModule =
|
|
1328
|
+
AgentDurableModule = _ts_decorate5([
|
|
787
1329
|
Global(),
|
|
788
1330
|
Module({
|
|
789
1331
|
providers: [
|
|
@@ -800,15 +1342,15 @@ AgentDurableModule = _ts_decorate4([
|
|
|
800
1342
|
], AgentDurableModule);
|
|
801
1343
|
|
|
802
1344
|
// src/agent.module.ts
|
|
803
|
-
import { AGENT_ACTOR_RESOLVER as
|
|
804
|
-
import { Global as Global2, Logger as
|
|
1345
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER13, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL2, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG3, AGENT_OPTIONS as AGENT_OPTIONS7, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK4, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE7, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, DefaultRolesPolicy, InMemoryAgentStore, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
|
|
1346
|
+
import { Global as Global2, Logger as Logger7, Module as Module2 } from "@nestjs/common";
|
|
805
1347
|
import { DiscoveryModule, ModulesContainer, RouterModule } from "@nestjs/core";
|
|
806
1348
|
|
|
807
1349
|
// src/agent-deps.factory.ts
|
|
808
|
-
import { AGENT_MEMORY, AGENT_MODEL, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK as
|
|
809
|
-
import { AGENT_OPTIONS } from "@dudousxd/nestjs-agent-core";
|
|
810
|
-
import { Inject as
|
|
811
|
-
function
|
|
1350
|
+
import { AGENT_MEMORY, AGENT_MODEL, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS, AGENT_STORE as AGENT_STORE4, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2, normalizeDelegation, summarizeWithModel, windowHistory } from "@dudousxd/nestjs-agent-core";
|
|
1351
|
+
import { AGENT_OPTIONS as AGENT_OPTIONS2 } from "@dudousxd/nestjs-agent-core";
|
|
1352
|
+
import { Inject as Inject5, Injectable as Injectable5, Optional as Optional4 } from "@nestjs/common";
|
|
1353
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
812
1354
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
813
1355
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
814
1356
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -821,19 +1363,19 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
821
1363
|
}
|
|
822
1364
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
823
1365
|
}
|
|
824
|
-
__name(
|
|
825
|
-
function
|
|
1366
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
1367
|
+
function _ts_metadata5(metadataKey, metadataValue) {
|
|
826
1368
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
827
1369
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
828
1370
|
}
|
|
829
1371
|
}
|
|
830
|
-
__name(
|
|
831
|
-
function
|
|
1372
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
1373
|
+
function _ts_param5(paramIndex, decorator) {
|
|
832
1374
|
return function(target, key) {
|
|
833
1375
|
decorator(target, key, paramIndex);
|
|
834
1376
|
};
|
|
835
1377
|
}
|
|
836
|
-
__name(
|
|
1378
|
+
__name(_ts_param5, "_ts_param");
|
|
837
1379
|
function delegateToolName(args) {
|
|
838
1380
|
const slug = args.target.replace(/[^a-zA-Z0-9]+/g, "_");
|
|
839
1381
|
return args.detached === true ? `start_${slug}` : `ask_${slug}`;
|
|
@@ -1030,24 +1572,24 @@ var AgentDepsFactory2 = class {
|
|
|
1030
1572
|
return void 0;
|
|
1031
1573
|
}
|
|
1032
1574
|
};
|
|
1033
|
-
AgentDepsFactory2 =
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1575
|
+
AgentDepsFactory2 = _ts_decorate6([
|
|
1576
|
+
Injectable5(),
|
|
1577
|
+
_ts_param5(0, Inject5(AGENT_OPTIONS2)),
|
|
1578
|
+
_ts_param5(1, Inject5(AGENT_MODEL)),
|
|
1579
|
+
_ts_param5(2, Inject5(AGENT_STORE4)),
|
|
1580
|
+
_ts_param5(3, Inject5(AGENT_SINK3)),
|
|
1581
|
+
_ts_param5(4, Inject5(AGENT_ROLES_POLICY)),
|
|
1582
|
+
_ts_param5(5, Inject5(AGENT_TOOL_REGISTRY)),
|
|
1583
|
+
_ts_param5(6, Inject5(AGENT_REGISTRY)),
|
|
1584
|
+
_ts_param5(7, Inject5(AGENT_PROMPT_CONTRIBUTORS)),
|
|
1585
|
+
_ts_param5(8, Optional4()),
|
|
1586
|
+
_ts_param5(8, Inject5(AGENT_PRICING_STORE)),
|
|
1587
|
+
_ts_param5(9, Optional4()),
|
|
1588
|
+
_ts_param5(9, Inject5(AGENT_SKILLS)),
|
|
1589
|
+
_ts_param5(10, Optional4()),
|
|
1590
|
+
_ts_param5(10, Inject5(AGENT_MEMORY)),
|
|
1591
|
+
_ts_metadata5("design:type", Function),
|
|
1592
|
+
_ts_metadata5("design:paramtypes", [
|
|
1051
1593
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
1052
1594
|
typeof ModelProvider === "undefined" ? Object : ModelProvider,
|
|
1053
1595
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
@@ -1063,9 +1605,9 @@ AgentDepsFactory2 = _ts_decorate5([
|
|
|
1063
1605
|
], AgentDepsFactory2);
|
|
1064
1606
|
|
|
1065
1607
|
// src/agent.service.ts
|
|
1066
|
-
import { AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_MODEL_CATALOG, AGENT_OPTIONS as
|
|
1067
|
-
import { BadRequestException, ForbiddenException, GoneException, HttpException, HttpStatus, Inject as
|
|
1068
|
-
function
|
|
1608
|
+
import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE5, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval, readElicitationQuestions, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
|
|
1609
|
+
import { BadRequestException, ConflictException, ForbiddenException, GoneException, HttpException, HttpStatus, Inject as Inject6, Injectable as Injectable6, NotFoundException, NotImplementedException as NotImplementedException2, Optional as Optional5 } from "@nestjs/common";
|
|
1610
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
1069
1611
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1070
1612
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1071
1613
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1078,19 +1620,19 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
1078
1620
|
}
|
|
1079
1621
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1080
1622
|
}
|
|
1081
|
-
__name(
|
|
1082
|
-
function
|
|
1623
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
1624
|
+
function _ts_metadata6(metadataKey, metadataValue) {
|
|
1083
1625
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1084
1626
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1085
1627
|
}
|
|
1086
1628
|
}
|
|
1087
|
-
__name(
|
|
1088
|
-
function
|
|
1629
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
1630
|
+
function _ts_param6(paramIndex, decorator) {
|
|
1089
1631
|
return function(target, key) {
|
|
1090
1632
|
decorator(target, key, paramIndex);
|
|
1091
1633
|
};
|
|
1092
1634
|
}
|
|
1093
|
-
__name(
|
|
1635
|
+
__name(_ts_param6, "_ts_param");
|
|
1094
1636
|
var AgentService = class {
|
|
1095
1637
|
static {
|
|
1096
1638
|
__name(this, "AgentService");
|
|
@@ -1102,7 +1644,8 @@ var AgentService = class {
|
|
|
1102
1644
|
models;
|
|
1103
1645
|
quotaProvider;
|
|
1104
1646
|
options;
|
|
1105
|
-
|
|
1647
|
+
queue;
|
|
1648
|
+
constructor(runner, store, deps, staging, models, quotaProvider, options, queue) {
|
|
1106
1649
|
this.runner = runner;
|
|
1107
1650
|
this.store = store;
|
|
1108
1651
|
this.deps = deps;
|
|
@@ -1110,6 +1653,19 @@ var AgentService = class {
|
|
|
1110
1653
|
this.models = models;
|
|
1111
1654
|
this.quotaProvider = quotaProvider;
|
|
1112
1655
|
this.options = options;
|
|
1656
|
+
this.queue = queue;
|
|
1657
|
+
}
|
|
1658
|
+
/** The queue service when the bound store can hold a queue, else `undefined`. */
|
|
1659
|
+
queueing() {
|
|
1660
|
+
return this.queue?.supported === true ? this.queue : void 0;
|
|
1661
|
+
}
|
|
1662
|
+
/** The queue service, or a 501 naming what is missing. */
|
|
1663
|
+
requireQueue() {
|
|
1664
|
+
const queue = this.queueing();
|
|
1665
|
+
if (queue === void 0) {
|
|
1666
|
+
throw new NotImplementedException2("Queueing messages requires an AgentStore that implements ChatQueueStore; the bound store does not.");
|
|
1667
|
+
}
|
|
1668
|
+
return queue;
|
|
1113
1669
|
}
|
|
1114
1670
|
/**
|
|
1115
1671
|
* The actor's budget across windows (`GET <base>/quota`) — the bound {@link QuotaProvider}'s
|
|
@@ -1220,7 +1776,44 @@ var AgentService = class {
|
|
|
1220
1776
|
}
|
|
1221
1777
|
return (await this.store.getThread(threadId))?.model ?? null;
|
|
1222
1778
|
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Start a turn — for in-process callers that need a run id back. A send that would have to wait
|
|
1781
|
+
* (its thread already has a turn running) is refused with `409` instead; {@link send} is the form
|
|
1782
|
+
* that queues it.
|
|
1783
|
+
*/
|
|
1223
1784
|
async chat(params) {
|
|
1785
|
+
const result = await this.send({
|
|
1786
|
+
...params,
|
|
1787
|
+
mode: "auto"
|
|
1788
|
+
});
|
|
1789
|
+
if (result.queued !== true) {
|
|
1790
|
+
return result;
|
|
1791
|
+
}
|
|
1792
|
+
if (result.runId !== void 0) {
|
|
1793
|
+
return {
|
|
1794
|
+
runId: result.runId,
|
|
1795
|
+
threadId: result.threadId
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
const store = this.requireQueue().queueStore();
|
|
1799
|
+
if (!await store.removeQueuedMessage(result.messageId)) {
|
|
1800
|
+
return {
|
|
1801
|
+
runId: result.messageId,
|
|
1802
|
+
threadId: result.threadId
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
await this.requireQueue().publish(result.threadId);
|
|
1806
|
+
throw new ConflictException({
|
|
1807
|
+
statusCode: 409,
|
|
1808
|
+
code: "run_active",
|
|
1809
|
+
message: `thread ${result.threadId} already has a turn running`
|
|
1810
|
+
});
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* Send a message: start a turn, or — when its thread already has one running — queue the message
|
|
1814
|
+
* to run after it (see {@link ChatSendMode}). What `POST <base>/chat` calls.
|
|
1815
|
+
*/
|
|
1816
|
+
async send(params) {
|
|
1224
1817
|
await this.assertWithinQuota(params.actor);
|
|
1225
1818
|
const agentName = await this.resolveAgentName(params.agentName, params.threadId);
|
|
1226
1819
|
const model = await this.resolveModel(params.actor, agentName, params.model, params.threadId);
|
|
@@ -1237,7 +1830,7 @@ var AgentService = class {
|
|
|
1237
1830
|
} : {}
|
|
1238
1831
|
});
|
|
1239
1832
|
threadId = created.id;
|
|
1240
|
-
} else
|
|
1833
|
+
} else {
|
|
1241
1834
|
await this.assertOwnsThread(params.actor, threadId);
|
|
1242
1835
|
}
|
|
1243
1836
|
const input = {
|
|
@@ -1259,13 +1852,195 @@ var AgentService = class {
|
|
|
1259
1852
|
model
|
|
1260
1853
|
} : {}
|
|
1261
1854
|
};
|
|
1262
|
-
const
|
|
1263
|
-
|
|
1855
|
+
const queue = this.queueing();
|
|
1856
|
+
if (queue === void 0) {
|
|
1857
|
+
const { runId } = await this.runner.start(input);
|
|
1858
|
+
await this.store.setActiveStream(threadId, runId);
|
|
1859
|
+
return {
|
|
1860
|
+
runId,
|
|
1861
|
+
threadId
|
|
1862
|
+
};
|
|
1863
|
+
}
|
|
1864
|
+
const mode = params.mode ?? "auto";
|
|
1865
|
+
const { live, stale } = await queue.holder(threadId, this.runner);
|
|
1866
|
+
if (live === null && mode !== "queue") {
|
|
1867
|
+
const runId = crypto.randomUUID();
|
|
1868
|
+
if (await queue.queueStore().claimActiveStream(threadId, runId, stale !== null ? {
|
|
1869
|
+
replacing: stale
|
|
1870
|
+
} : {})) {
|
|
1871
|
+
return {
|
|
1872
|
+
runId: await this.startClaimed(input, runId),
|
|
1873
|
+
threadId
|
|
1874
|
+
};
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
if (params.regenerate === true) {
|
|
1878
|
+
throw new ConflictException({
|
|
1879
|
+
statusCode: 409,
|
|
1880
|
+
code: "run_active",
|
|
1881
|
+
message: "cannot regenerate while a turn is running on this thread"
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
return this.enqueue(queue, input, mode, live);
|
|
1885
|
+
}
|
|
1886
|
+
/**
|
|
1887
|
+
* Start a turn the thread is already claimed for, under the claimed id. A runner that minted an
|
|
1888
|
+
* id of its own anyway gets the thread re-pointed at it; one that fails to start frees the thread.
|
|
1889
|
+
*/
|
|
1890
|
+
async startClaimed(input, runId) {
|
|
1891
|
+
const store = this.requireQueue().queueStore();
|
|
1892
|
+
let started;
|
|
1893
|
+
try {
|
|
1894
|
+
started = (await this.runner.start(input, {
|
|
1895
|
+
runId
|
|
1896
|
+
})).runId;
|
|
1897
|
+
} catch (error) {
|
|
1898
|
+
await store.releaseActiveStream(input.threadId, runId);
|
|
1899
|
+
throw error;
|
|
1900
|
+
}
|
|
1901
|
+
if (started !== runId) {
|
|
1902
|
+
await store.claimActiveStream(input.threadId, started, {
|
|
1903
|
+
replacing: runId
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
return started;
|
|
1907
|
+
}
|
|
1908
|
+
/** Put a send in its thread's queue, then drain it if the thread turned out to be free. */
|
|
1909
|
+
async enqueue(queue, input, mode, live) {
|
|
1910
|
+
const store = queue.queueStore();
|
|
1911
|
+
const threadId = input.threadId;
|
|
1912
|
+
const interrupting = mode === "interrupt" && live !== null ? live : void 0;
|
|
1913
|
+
const queued = await store.enqueueMessage({
|
|
1914
|
+
threadId,
|
|
1915
|
+
actor: input.actor,
|
|
1916
|
+
content: input.userText,
|
|
1917
|
+
...input.attachments !== void 0 ? {
|
|
1918
|
+
attachments: input.attachments
|
|
1919
|
+
} : {},
|
|
1920
|
+
...input.agentName !== void 0 ? {
|
|
1921
|
+
agentName: input.agentName
|
|
1922
|
+
} : {},
|
|
1923
|
+
...input.model !== void 0 ? {
|
|
1924
|
+
model: input.model
|
|
1925
|
+
} : {},
|
|
1926
|
+
...input.pageContext !== void 0 ? {
|
|
1927
|
+
pageContext: input.pageContext
|
|
1928
|
+
} : {},
|
|
1929
|
+
...interrupting !== void 0 ? {
|
|
1930
|
+
interrupt: true,
|
|
1931
|
+
at: "head"
|
|
1932
|
+
} : {}
|
|
1933
|
+
});
|
|
1934
|
+
let runId;
|
|
1935
|
+
if (interrupting !== void 0) {
|
|
1936
|
+
await store.setQueuePause(threadId, null);
|
|
1937
|
+
await queue.publish(threadId);
|
|
1938
|
+
await this.runner.cancel(interrupting);
|
|
1939
|
+
} else {
|
|
1940
|
+
runId = await queue.kick(threadId, this.runner);
|
|
1941
|
+
if (runId === void 0) {
|
|
1942
|
+
await queue.publish(threadId);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
const state = await queue.state(threadId);
|
|
1946
|
+
const position = state.items.findIndex((item) => item.id === queued.id);
|
|
1264
1947
|
return {
|
|
1265
|
-
|
|
1266
|
-
|
|
1948
|
+
threadId,
|
|
1949
|
+
queued: true,
|
|
1950
|
+
messageId: queued.id,
|
|
1951
|
+
position: position === -1 ? 0 : position,
|
|
1952
|
+
queue: state,
|
|
1953
|
+
...runId !== void 0 && runId === queued.id ? {
|
|
1954
|
+
runId
|
|
1955
|
+
} : {},
|
|
1956
|
+
...interrupting !== void 0 ? {
|
|
1957
|
+
interrupting
|
|
1958
|
+
} : {}
|
|
1267
1959
|
};
|
|
1268
1960
|
}
|
|
1961
|
+
/** `GET <base>/threads/:id/queue` — the thread's waiting messages and whether it drains. */
|
|
1962
|
+
async getQueue(actor, threadId) {
|
|
1963
|
+
await this.assertOwnsThread(actor, threadId);
|
|
1964
|
+
return this.requireQueue().state(threadId);
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* `PATCH <base>/queue/:messageId` — change a waiting message's text and/or attachments, and/or move
|
|
1968
|
+
* it to `position` in the queue. Answers the thread's queue.
|
|
1969
|
+
*/
|
|
1970
|
+
async updateQueuedMessage(actor, messageId, patch) {
|
|
1971
|
+
const queue = this.requireQueue();
|
|
1972
|
+
const store = queue.queueStore();
|
|
1973
|
+
const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
|
|
1974
|
+
if (patch.message !== void 0 && patch.message.trim().length === 0) {
|
|
1975
|
+
throw new BadRequestException("message must not be empty");
|
|
1976
|
+
}
|
|
1977
|
+
const attachments = patch.attachments === void 0 || patch.attachments === null ? patch.attachments : await this.resolveAttachments(actor, patch.attachments);
|
|
1978
|
+
if (patch.message !== void 0 || attachments !== void 0) {
|
|
1979
|
+
const updated = await store.updateQueuedMessage(messageId, {
|
|
1980
|
+
...patch.message !== void 0 ? {
|
|
1981
|
+
content: patch.message
|
|
1982
|
+
} : {},
|
|
1983
|
+
...attachments !== void 0 ? {
|
|
1984
|
+
attachments
|
|
1985
|
+
} : {}
|
|
1986
|
+
});
|
|
1987
|
+
if (updated === null) {
|
|
1988
|
+
throw new GoneException(`queued message ${messageId} already started or was removed`);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
if (patch.position !== void 0) {
|
|
1992
|
+
if (!Number.isInteger(patch.position) || patch.position < 0) {
|
|
1993
|
+
throw new BadRequestException("position must be a non-negative integer");
|
|
1994
|
+
}
|
|
1995
|
+
if (!await store.moveQueuedMessage(messageId, patch.position)) {
|
|
1996
|
+
throw new GoneException(`queued message ${messageId} already started or was removed`);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
return queue.publish(threadId);
|
|
2000
|
+
}
|
|
2001
|
+
/** `DELETE <base>/queue/:messageId` — drop a waiting message. Answers the thread's queue. */
|
|
2002
|
+
async removeQueuedMessage(actor, messageId) {
|
|
2003
|
+
const queue = this.requireQueue();
|
|
2004
|
+
const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
|
|
2005
|
+
if (!await queue.queueStore().removeQueuedMessage(messageId)) {
|
|
2006
|
+
throw new GoneException(`queued message ${messageId} already started or was removed`);
|
|
2007
|
+
}
|
|
2008
|
+
return queue.publish(threadId);
|
|
2009
|
+
}
|
|
2010
|
+
/** `DELETE <base>/threads/:id/queue` — drop every waiting message (and any pause). */
|
|
2011
|
+
async clearQueue(actor, threadId) {
|
|
2012
|
+
await this.assertOwnsThread(actor, threadId);
|
|
2013
|
+
const queue = this.requireQueue();
|
|
2014
|
+
await queue.queueStore().clearQueue(threadId);
|
|
2015
|
+
await queue.queueStore().setQueuePause(threadId, null);
|
|
2016
|
+
return queue.publish(threadId);
|
|
2017
|
+
}
|
|
2018
|
+
/**
|
|
2019
|
+
* `POST <base>/threads/:id/queue/resume` — lift a pause and start the head when nothing is
|
|
2020
|
+
* running. Answers the queue, and the run the head started under, if it did.
|
|
2021
|
+
*/
|
|
2022
|
+
async resumeQueue(actor, threadId) {
|
|
2023
|
+
await this.assertOwnsThread(actor, threadId);
|
|
2024
|
+
const queue = this.requireQueue();
|
|
2025
|
+
await queue.queueStore().setQueuePause(threadId, null);
|
|
2026
|
+
const runId = await queue.kick(threadId, this.runner);
|
|
2027
|
+
const state = runId === void 0 ? await queue.publish(threadId) : await queue.state(threadId);
|
|
2028
|
+
return {
|
|
2029
|
+
...state,
|
|
2030
|
+
...runId !== void 0 ? {
|
|
2031
|
+
runId
|
|
2032
|
+
} : {}
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
2035
|
+
/** The thread a queued message waits on, once the caller is shown to own it. */
|
|
2036
|
+
async assertOwnsQueuedMessage(actor, messageId) {
|
|
2037
|
+
const message = await this.requireQueue().queueStore().getQueuedMessage(messageId);
|
|
2038
|
+
if (message === null) {
|
|
2039
|
+
throw new NotFoundException(`queued message ${messageId} not found`);
|
|
2040
|
+
}
|
|
2041
|
+
await this.assertOwnsThread(actor, message.threadId);
|
|
2042
|
+
return message.threadId;
|
|
2043
|
+
}
|
|
1269
2044
|
/**
|
|
1270
2045
|
* Rebuild this turn's attachments from the staging store, keyed by the ids the caller claimed.
|
|
1271
2046
|
* The model provider fetches {@link MessageAttachment.url} verbatim, so that url is only ever
|
|
@@ -1282,7 +2057,7 @@ var AgentService = class {
|
|
|
1282
2057
|
}
|
|
1283
2058
|
const staging = this.staging;
|
|
1284
2059
|
if (staging === void 0 || typeof staging.resolve !== "function") {
|
|
1285
|
-
throw new
|
|
2060
|
+
throw new NotImplementedException2("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
|
|
1286
2061
|
}
|
|
1287
2062
|
const resolved = [];
|
|
1288
2063
|
for (const ref of refs) {
|
|
@@ -1440,7 +2215,7 @@ var AgentService = class {
|
|
|
1440
2215
|
return;
|
|
1441
2216
|
}
|
|
1442
2217
|
if (this.store.updateThread === void 0) {
|
|
1443
|
-
throw new
|
|
2218
|
+
throw new NotImplementedException2("Setting a thread's defaultAgent or model requires an AgentStore that implements updateThread(); the bound store does not support it.");
|
|
1444
2219
|
}
|
|
1445
2220
|
const model = patch.model === void 0 || patch.model === null ? patch.model : await this.assertModelAllowed(actor, patch.defaultAgent ?? await this.resolveAgentName(void 0, threadId), patch.model);
|
|
1446
2221
|
await this.store.updateThread(threadId, {
|
|
@@ -1505,9 +2280,13 @@ var AgentService = class {
|
|
|
1505
2280
|
}
|
|
1506
2281
|
async toDetailView(thread, actor) {
|
|
1507
2282
|
const summary = await this.toSummaryView(thread);
|
|
2283
|
+
const queue = this.queueing();
|
|
1508
2284
|
return {
|
|
1509
2285
|
...summary,
|
|
1510
|
-
messages: await this.freshAttachmentUrls(thread.messages, actor)
|
|
2286
|
+
messages: await this.freshAttachmentUrls(thread.messages, actor),
|
|
2287
|
+
...queue !== void 0 ? {
|
|
2288
|
+
queue: await queue.state(thread.id)
|
|
2289
|
+
} : {}
|
|
1511
2290
|
};
|
|
1512
2291
|
}
|
|
1513
2292
|
/**
|
|
@@ -1570,7 +2349,7 @@ var AgentService = class {
|
|
|
1570
2349
|
throw new BadRequestException("comment must be at most 2000 characters");
|
|
1571
2350
|
}
|
|
1572
2351
|
if (this.store.threadOfMessage === void 0 || this.store.setMessageFeedback === void 0) {
|
|
1573
|
-
throw new
|
|
2352
|
+
throw new NotImplementedException2("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
|
|
1574
2353
|
}
|
|
1575
2354
|
const threadId = await this.store.threadOfMessage(messageId);
|
|
1576
2355
|
if (threadId === null) {
|
|
@@ -1622,7 +2401,7 @@ var AgentService = class {
|
|
|
1622
2401
|
const list = this.attachmentInventory();
|
|
1623
2402
|
const referencedMediaIds = this.store.referencedMediaIds?.bind(this.store);
|
|
1624
2403
|
if (referencedMediaIds === void 0) {
|
|
1625
|
-
throw new
|
|
2404
|
+
throw new NotImplementedException2("Collecting attachments requires an AgentStore that implements referencedMediaIds(); the bound store cannot say which media a message still references, and guessing would delete files that are in use.");
|
|
1626
2405
|
}
|
|
1627
2406
|
const stagedBefore = options.olderThan.toISOString();
|
|
1628
2407
|
const inventory = await list({
|
|
@@ -1644,7 +2423,7 @@ var AgentService = class {
|
|
|
1644
2423
|
attachmentInventory() {
|
|
1645
2424
|
const list = this.staging?.list?.bind(this.staging);
|
|
1646
2425
|
if (list === void 0) {
|
|
1647
|
-
throw new
|
|
2426
|
+
throw new NotImplementedException2("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
|
|
1648
2427
|
}
|
|
1649
2428
|
return list;
|
|
1650
2429
|
}
|
|
@@ -1762,34 +2541,36 @@ var AgentService = class {
|
|
|
1762
2541
|
}
|
|
1763
2542
|
}
|
|
1764
2543
|
};
|
|
1765
|
-
AgentService =
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
2544
|
+
AgentService = _ts_decorate7([
|
|
2545
|
+
Injectable6(),
|
|
2546
|
+
_ts_param6(0, Inject6(AGENT_RUNNER)),
|
|
2547
|
+
_ts_param6(1, Inject6(AGENT_STORE5)),
|
|
2548
|
+
_ts_param6(2, Inject6(AGENT_DEPS_FACTORY3)),
|
|
2549
|
+
_ts_param6(3, Optional5()),
|
|
2550
|
+
_ts_param6(3, Inject6(AGENT_ATTACHMENT_STAGING2)),
|
|
2551
|
+
_ts_param6(4, Optional5()),
|
|
2552
|
+
_ts_param6(4, Inject6(AGENT_MODEL_CATALOG)),
|
|
2553
|
+
_ts_param6(5, Optional5()),
|
|
2554
|
+
_ts_param6(5, Inject6(AGENT_QUOTA_PROVIDER2)),
|
|
2555
|
+
_ts_param6(6, Optional5()),
|
|
2556
|
+
_ts_param6(6, Inject6(AGENT_OPTIONS3)),
|
|
2557
|
+
_ts_param6(7, Optional5()),
|
|
2558
|
+
_ts_metadata6("design:type", Function),
|
|
2559
|
+
_ts_metadata6("design:paramtypes", [
|
|
1780
2560
|
typeof AgentRunner === "undefined" ? Object : AgentRunner,
|
|
1781
2561
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
1782
2562
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
1783
2563
|
typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore,
|
|
1784
2564
|
typeof ModelCatalog === "undefined" ? Object : ModelCatalog,
|
|
1785
2565
|
typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
|
|
1786
|
-
typeof Pick === "undefined" ? Object : Pick
|
|
2566
|
+
typeof Pick === "undefined" ? Object : Pick,
|
|
2567
|
+
typeof ChatQueueService === "undefined" ? Object : ChatQueueService
|
|
1787
2568
|
])
|
|
1788
2569
|
], AgentService);
|
|
1789
2570
|
|
|
1790
2571
|
// src/approval-port.adapter.ts
|
|
1791
|
-
import { Injectable as
|
|
1792
|
-
function
|
|
2572
|
+
import { Injectable as Injectable7 } from "@nestjs/common";
|
|
2573
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
1793
2574
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1794
2575
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1795
2576
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1802,13 +2583,13 @@ function _ts_decorate7(decorators, target, key, desc) {
|
|
|
1802
2583
|
}
|
|
1803
2584
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1804
2585
|
}
|
|
1805
|
-
__name(
|
|
1806
|
-
function
|
|
2586
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
2587
|
+
function _ts_metadata7(metadataKey, metadataValue) {
|
|
1807
2588
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1808
2589
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1809
2590
|
}
|
|
1810
2591
|
}
|
|
1811
|
-
__name(
|
|
2592
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
1812
2593
|
var AgentApprovalPortAdapter = class {
|
|
1813
2594
|
static {
|
|
1814
2595
|
__name(this, "AgentApprovalPortAdapter");
|
|
@@ -1846,18 +2627,18 @@ var AgentApprovalPortAdapter = class {
|
|
|
1846
2627
|
});
|
|
1847
2628
|
}
|
|
1848
2629
|
};
|
|
1849
|
-
AgentApprovalPortAdapter =
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
2630
|
+
AgentApprovalPortAdapter = _ts_decorate8([
|
|
2631
|
+
Injectable7(),
|
|
2632
|
+
_ts_metadata7("design:type", Function),
|
|
2633
|
+
_ts_metadata7("design:paramtypes", [
|
|
1853
2634
|
typeof AgentService === "undefined" ? Object : AgentService
|
|
1854
2635
|
])
|
|
1855
2636
|
], AgentApprovalPortAdapter);
|
|
1856
2637
|
|
|
1857
2638
|
// src/controller/agents.controller.ts
|
|
1858
2639
|
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_REGISTRY as AGENT_REGISTRY2, AgentRegistry as AgentRegistry3 } from "@dudousxd/nestjs-agent-core";
|
|
1859
|
-
import { Controller, Get, Inject as
|
|
1860
|
-
function
|
|
2640
|
+
import { Controller, Get, Inject as Inject7 } from "@nestjs/common";
|
|
2641
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
1861
2642
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1862
2643
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1863
2644
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1870,19 +2651,19 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
1870
2651
|
}
|
|
1871
2652
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1872
2653
|
}
|
|
1873
|
-
__name(
|
|
1874
|
-
function
|
|
2654
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
2655
|
+
function _ts_metadata8(metadataKey, metadataValue) {
|
|
1875
2656
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1876
2657
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1877
2658
|
}
|
|
1878
2659
|
}
|
|
1879
|
-
__name(
|
|
1880
|
-
function
|
|
2660
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2661
|
+
function _ts_param7(paramIndex, decorator) {
|
|
1881
2662
|
return function(target, key) {
|
|
1882
2663
|
decorator(target, key, paramIndex);
|
|
1883
2664
|
};
|
|
1884
2665
|
}
|
|
1885
|
-
__name(
|
|
2666
|
+
__name(_ts_param7, "_ts_param");
|
|
1886
2667
|
var AgentsController = class {
|
|
1887
2668
|
static {
|
|
1888
2669
|
__name(this, "AgentsController");
|
|
@@ -1904,26 +2685,26 @@ var AgentsController = class {
|
|
|
1904
2685
|
}));
|
|
1905
2686
|
}
|
|
1906
2687
|
};
|
|
1907
|
-
|
|
2688
|
+
_ts_decorate9([
|
|
1908
2689
|
Get(),
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
2690
|
+
_ts_metadata8("design:type", Function),
|
|
2691
|
+
_ts_metadata8("design:paramtypes", []),
|
|
2692
|
+
_ts_metadata8("design:returntype", Array)
|
|
1912
2693
|
], AgentsController.prototype, "list", null);
|
|
1913
|
-
AgentsController =
|
|
2694
|
+
AgentsController = _ts_decorate9([
|
|
1914
2695
|
Controller("agents"),
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
2696
|
+
_ts_param7(0, Inject7(AGENT_REGISTRY2)),
|
|
2697
|
+
_ts_param7(1, Inject7(AGENT_DEPS_FACTORY4)),
|
|
2698
|
+
_ts_metadata8("design:type", Function),
|
|
2699
|
+
_ts_metadata8("design:paramtypes", [
|
|
1919
2700
|
typeof AgentRegistry3 === "undefined" ? Object : AgentRegistry3,
|
|
1920
2701
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
|
|
1921
2702
|
])
|
|
1922
2703
|
], AgentsController);
|
|
1923
2704
|
|
|
1924
2705
|
// src/controller/attachments.controller.ts
|
|
1925
|
-
import { AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING as
|
|
1926
|
-
import { BadRequestException as BadRequestException2, Controller as Controller2, Get as Get2, Inject as
|
|
2706
|
+
import { AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING3, AGENT_OPTIONS as AGENT_OPTIONS4 } from "@dudousxd/nestjs-agent-core";
|
|
2707
|
+
import { BadRequestException as BadRequestException2, Controller as Controller2, Get as Get2, Inject as Inject8, NotImplementedException as NotImplementedException3, Optional as Optional6, PayloadTooLargeException, Post, Req, UnsupportedMediaTypeException, UploadedFile, UseInterceptors } from "@nestjs/common";
|
|
1927
2708
|
import { FileInterceptor } from "@nestjs/platform-express";
|
|
1928
2709
|
|
|
1929
2710
|
// src/attachment-limits.ts
|
|
@@ -1952,7 +2733,7 @@ function attachmentLimits(options, staging) {
|
|
|
1952
2733
|
__name(attachmentLimits, "attachmentLimits");
|
|
1953
2734
|
|
|
1954
2735
|
// src/controller/attachments.controller.ts
|
|
1955
|
-
function
|
|
2736
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
1956
2737
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1957
2738
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1958
2739
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1965,19 +2746,19 @@ function _ts_decorate9(decorators, target, key, desc) {
|
|
|
1965
2746
|
}
|
|
1966
2747
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1967
2748
|
}
|
|
1968
|
-
__name(
|
|
1969
|
-
function
|
|
2749
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
2750
|
+
function _ts_metadata9(metadataKey, metadataValue) {
|
|
1970
2751
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1971
2752
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
1972
2753
|
}
|
|
1973
2754
|
}
|
|
1974
|
-
__name(
|
|
1975
|
-
function
|
|
2755
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2756
|
+
function _ts_param8(paramIndex, decorator) {
|
|
1976
2757
|
return function(target, key) {
|
|
1977
2758
|
decorator(target, key, paramIndex);
|
|
1978
2759
|
};
|
|
1979
2760
|
}
|
|
1980
|
-
__name(
|
|
2761
|
+
__name(_ts_param8, "_ts_param");
|
|
1981
2762
|
var HARD_MAX_ATTACHMENT_BYTES = 32 * 1024 * 1024;
|
|
1982
2763
|
var ATTACHMENT_PAGE_SIZE = 50;
|
|
1983
2764
|
var AttachmentsController = class {
|
|
@@ -2011,7 +2792,7 @@ var AttachmentsController = class {
|
|
|
2011
2792
|
}
|
|
2012
2793
|
async upload(req, file) {
|
|
2013
2794
|
if (this.staging === void 0) {
|
|
2014
|
-
throw new
|
|
2795
|
+
throw new NotImplementedException3("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
|
|
2015
2796
|
}
|
|
2016
2797
|
if (file === void 0) {
|
|
2017
2798
|
throw new BadRequestException2('multipart field "file" is required');
|
|
@@ -2033,39 +2814,39 @@ var AttachmentsController = class {
|
|
|
2033
2814
|
});
|
|
2034
2815
|
}
|
|
2035
2816
|
};
|
|
2036
|
-
|
|
2817
|
+
_ts_decorate10([
|
|
2037
2818
|
Get2(),
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2819
|
+
_ts_param8(0, Req()),
|
|
2820
|
+
_ts_metadata9("design:type", Function),
|
|
2821
|
+
_ts_metadata9("design:paramtypes", [
|
|
2041
2822
|
typeof Request === "undefined" ? Object : Request
|
|
2042
2823
|
]),
|
|
2043
|
-
|
|
2824
|
+
_ts_metadata9("design:returntype", Promise)
|
|
2044
2825
|
], AttachmentsController.prototype, "list", null);
|
|
2045
|
-
|
|
2826
|
+
_ts_decorate10([
|
|
2046
2827
|
Post(),
|
|
2047
2828
|
UseInterceptors(FileInterceptor("file", {
|
|
2048
2829
|
limits: {
|
|
2049
2830
|
fileSize: HARD_MAX_ATTACHMENT_BYTES
|
|
2050
2831
|
}
|
|
2051
2832
|
})),
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2833
|
+
_ts_param8(0, Req()),
|
|
2834
|
+
_ts_param8(1, UploadedFile()),
|
|
2835
|
+
_ts_metadata9("design:type", Function),
|
|
2836
|
+
_ts_metadata9("design:paramtypes", [
|
|
2056
2837
|
typeof Request === "undefined" ? Object : Request,
|
|
2057
2838
|
Object
|
|
2058
2839
|
]),
|
|
2059
|
-
|
|
2840
|
+
_ts_metadata9("design:returntype", Promise)
|
|
2060
2841
|
], AttachmentsController.prototype, "upload", null);
|
|
2061
|
-
AttachmentsController =
|
|
2842
|
+
AttachmentsController = _ts_decorate10([
|
|
2062
2843
|
Controller2("attachments"),
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2844
|
+
_ts_param8(0, Inject8(AGENT_OPTIONS4)),
|
|
2845
|
+
_ts_param8(1, Inject8(AGENT_ACTOR_RESOLVER)),
|
|
2846
|
+
_ts_param8(3, Optional6()),
|
|
2847
|
+
_ts_param8(3, Inject8(AGENT_ATTACHMENT_STAGING3)),
|
|
2848
|
+
_ts_metadata9("design:type", Function),
|
|
2849
|
+
_ts_metadata9("design:paramtypes", [
|
|
2069
2850
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
2070
2851
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
2071
2852
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
@@ -2075,8 +2856,8 @@ AttachmentsController = _ts_decorate9([
|
|
|
2075
2856
|
|
|
2076
2857
|
// src/controller/chat.controller.ts
|
|
2077
2858
|
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER2, AgentStreamError as AgentStreamError2 } from "@dudousxd/nestjs-agent-core";
|
|
2078
|
-
import { BadRequestException as BadRequestException3, Body, Controller as Controller3, Get as Get3, Inject as
|
|
2079
|
-
function
|
|
2859
|
+
import { BadRequestException as BadRequestException3, Body, Controller as Controller3, Get as Get3, Inject as Inject9, Param, Post as Post2, Query, Req as Req2, Res } from "@nestjs/common";
|
|
2860
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
2080
2861
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2081
2862
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2082
2863
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2089,19 +2870,32 @@ function _ts_decorate10(decorators, target, key, desc) {
|
|
|
2089
2870
|
}
|
|
2090
2871
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2091
2872
|
}
|
|
2092
|
-
__name(
|
|
2093
|
-
function
|
|
2873
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
2874
|
+
function _ts_metadata10(metadataKey, metadataValue) {
|
|
2094
2875
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2095
2876
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2096
2877
|
}
|
|
2097
2878
|
}
|
|
2098
|
-
__name(
|
|
2099
|
-
function
|
|
2879
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
2880
|
+
function _ts_param9(paramIndex, decorator) {
|
|
2100
2881
|
return function(target, key) {
|
|
2101
2882
|
decorator(target, key, paramIndex);
|
|
2102
2883
|
};
|
|
2103
2884
|
}
|
|
2104
|
-
__name(
|
|
2885
|
+
__name(_ts_param9, "_ts_param");
|
|
2886
|
+
function sendMode(body) {
|
|
2887
|
+
if (body.interrupt === true) {
|
|
2888
|
+
return "interrupt";
|
|
2889
|
+
}
|
|
2890
|
+
if (body.mode === void 0 || body.mode === null) {
|
|
2891
|
+
return "auto";
|
|
2892
|
+
}
|
|
2893
|
+
if (body.mode === "auto" || body.mode === "queue" || body.mode === "interrupt") {
|
|
2894
|
+
return body.mode;
|
|
2895
|
+
}
|
|
2896
|
+
throw new BadRequestException3("mode must be 'auto', 'queue' or 'interrupt'");
|
|
2897
|
+
}
|
|
2898
|
+
__name(sendMode, "sendMode");
|
|
2105
2899
|
function attachmentRefs(claimed) {
|
|
2106
2900
|
if (claimed === void 0) {
|
|
2107
2901
|
return [];
|
|
@@ -2139,10 +2933,17 @@ var ChatController = class {
|
|
|
2139
2933
|
this.agent = agent;
|
|
2140
2934
|
this.actorResolver = actorResolver;
|
|
2141
2935
|
}
|
|
2936
|
+
/**
|
|
2937
|
+
* Start a turn and stream it — or, when the thread already has one running, queue the message and
|
|
2938
|
+
* answer `202 { queued: true, messageId, position, queue, … }` (JSON, no stream): it runs when the
|
|
2939
|
+
* turn ahead of it settles, and the stream of the run holding the thread announces it with a
|
|
2940
|
+
* `queue` frame.
|
|
2941
|
+
*/
|
|
2142
2942
|
async chat(req, res, body) {
|
|
2143
2943
|
const actor = await this.actorResolver.resolve(req);
|
|
2144
2944
|
const attachments = attachmentRefs(body.attachments);
|
|
2145
|
-
const
|
|
2945
|
+
const mode = sendMode(body);
|
|
2946
|
+
const result = await this.agent.send({
|
|
2146
2947
|
actor,
|
|
2147
2948
|
message: body.message,
|
|
2148
2949
|
...body.threadId !== void 0 ? {
|
|
@@ -2165,8 +2966,14 @@ var ChatController = class {
|
|
|
2165
2966
|
} : {},
|
|
2166
2967
|
...typeof body.model === "string" && body.model.length > 0 ? {
|
|
2167
2968
|
model: body.model
|
|
2168
|
-
} : {}
|
|
2969
|
+
} : {},
|
|
2970
|
+
mode
|
|
2169
2971
|
});
|
|
2972
|
+
if (result.queued === true) {
|
|
2973
|
+
res.status(202).json(result);
|
|
2974
|
+
return;
|
|
2975
|
+
}
|
|
2976
|
+
const { runId, threadId } = result;
|
|
2170
2977
|
await this.pipe(res, runId, this.agent.subscribe(runId), threadId);
|
|
2171
2978
|
}
|
|
2172
2979
|
/**
|
|
@@ -2256,50 +3063,50 @@ data: ${JSON.stringify(payload)}
|
|
|
2256
3063
|
res.end();
|
|
2257
3064
|
}
|
|
2258
3065
|
};
|
|
2259
|
-
|
|
3066
|
+
_ts_decorate11([
|
|
2260
3067
|
Post2("chat"),
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
3068
|
+
_ts_param9(0, Req2()),
|
|
3069
|
+
_ts_param9(1, Res()),
|
|
3070
|
+
_ts_param9(2, Body()),
|
|
3071
|
+
_ts_metadata10("design:type", Function),
|
|
3072
|
+
_ts_metadata10("design:paramtypes", [
|
|
2266
3073
|
typeof Request === "undefined" ? Object : Request,
|
|
2267
3074
|
typeof Response === "undefined" ? Object : Response,
|
|
2268
3075
|
typeof ChatBody === "undefined" ? Object : ChatBody
|
|
2269
3076
|
]),
|
|
2270
|
-
|
|
3077
|
+
_ts_metadata10("design:returntype", Promise)
|
|
2271
3078
|
], ChatController.prototype, "chat", null);
|
|
2272
|
-
|
|
3079
|
+
_ts_decorate11([
|
|
2273
3080
|
Get3("chat/:runId/stream"),
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
3081
|
+
_ts_param9(0, Req2()),
|
|
3082
|
+
_ts_param9(1, Param("runId")),
|
|
3083
|
+
_ts_param9(2, Res()),
|
|
3084
|
+
_ts_param9(3, Query("after")),
|
|
3085
|
+
_ts_metadata10("design:type", Function),
|
|
3086
|
+
_ts_metadata10("design:paramtypes", [
|
|
2280
3087
|
typeof Request === "undefined" ? Object : Request,
|
|
2281
3088
|
String,
|
|
2282
3089
|
typeof Response === "undefined" ? Object : Response,
|
|
2283
3090
|
String
|
|
2284
3091
|
]),
|
|
2285
|
-
|
|
3092
|
+
_ts_metadata10("design:returntype", Promise)
|
|
2286
3093
|
], ChatController.prototype, "stream", null);
|
|
2287
|
-
|
|
3094
|
+
_ts_decorate11([
|
|
2288
3095
|
Post2("chat/:runId/cancel"),
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
3096
|
+
_ts_param9(0, Req2()),
|
|
3097
|
+
_ts_param9(1, Param("runId")),
|
|
3098
|
+
_ts_metadata10("design:type", Function),
|
|
3099
|
+
_ts_metadata10("design:paramtypes", [
|
|
2293
3100
|
typeof Request === "undefined" ? Object : Request,
|
|
2294
3101
|
String
|
|
2295
3102
|
]),
|
|
2296
|
-
|
|
3103
|
+
_ts_metadata10("design:returntype", Promise)
|
|
2297
3104
|
], ChatController.prototype, "cancel", null);
|
|
2298
|
-
ChatController =
|
|
3105
|
+
ChatController = _ts_decorate11([
|
|
2299
3106
|
Controller3(),
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
3107
|
+
_ts_param9(1, Inject9(AGENT_ACTOR_RESOLVER2)),
|
|
3108
|
+
_ts_metadata10("design:type", Function),
|
|
3109
|
+
_ts_metadata10("design:paramtypes", [
|
|
2303
3110
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
2304
3111
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
2305
3112
|
])
|
|
@@ -2315,8 +3122,8 @@ function parseCursor(raw) {
|
|
|
2315
3122
|
__name(parseCursor, "parseCursor");
|
|
2316
3123
|
|
|
2317
3124
|
// src/controller/config.controller.ts
|
|
2318
|
-
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER3, AGENT_ATTACHMENT_STAGING as
|
|
2319
|
-
import { Controller as Controller4, Get as Get4, Inject as
|
|
3125
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER3, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING4, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG2, AGENT_OPTIONS as AGENT_OPTIONS5 } from "@dudousxd/nestjs-agent-core";
|
|
3126
|
+
import { Controller as Controller4, Get as Get4, Inject as Inject10, Optional as Optional7, Req as Req3 } from "@nestjs/common";
|
|
2320
3127
|
|
|
2321
3128
|
// src/resolver/anonymous-actor-resolver.ts
|
|
2322
3129
|
import { createHash, randomBytes } from "crypto";
|
|
@@ -2406,7 +3213,7 @@ var AnonymousActorResolver = class {
|
|
|
2406
3213
|
};
|
|
2407
3214
|
|
|
2408
3215
|
// src/controller/config.controller.ts
|
|
2409
|
-
function
|
|
3216
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
2410
3217
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2411
3218
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2412
3219
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2419,19 +3226,19 @@ function _ts_decorate11(decorators, target, key, desc) {
|
|
|
2419
3226
|
}
|
|
2420
3227
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2421
3228
|
}
|
|
2422
|
-
__name(
|
|
2423
|
-
function
|
|
3229
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
3230
|
+
function _ts_metadata11(metadataKey, metadataValue) {
|
|
2424
3231
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2425
3232
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2426
3233
|
}
|
|
2427
3234
|
}
|
|
2428
|
-
__name(
|
|
2429
|
-
function
|
|
3235
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
3236
|
+
function _ts_param10(paramIndex, decorator) {
|
|
2430
3237
|
return function(target, key) {
|
|
2431
3238
|
decorator(target, key, paramIndex);
|
|
2432
3239
|
};
|
|
2433
3240
|
}
|
|
2434
|
-
__name(
|
|
3241
|
+
__name(_ts_param10, "_ts_param");
|
|
2435
3242
|
var ConfigController = class {
|
|
2436
3243
|
static {
|
|
2437
3244
|
__name(this, "ConfigController");
|
|
@@ -2462,25 +3269,25 @@ var ConfigController = class {
|
|
|
2462
3269
|
};
|
|
2463
3270
|
}
|
|
2464
3271
|
};
|
|
2465
|
-
|
|
3272
|
+
_ts_decorate12([
|
|
2466
3273
|
Get4(),
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
3274
|
+
_ts_param10(0, Req3()),
|
|
3275
|
+
_ts_metadata11("design:type", Function),
|
|
3276
|
+
_ts_metadata11("design:paramtypes", [
|
|
2470
3277
|
typeof Request === "undefined" ? Object : Request
|
|
2471
3278
|
]),
|
|
2472
|
-
|
|
3279
|
+
_ts_metadata11("design:returntype", Promise)
|
|
2473
3280
|
], ConfigController.prototype, "config", null);
|
|
2474
|
-
ConfigController =
|
|
3281
|
+
ConfigController = _ts_decorate12([
|
|
2475
3282
|
Controller4("config"),
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
3283
|
+
_ts_param10(0, Inject10(AGENT_OPTIONS5)),
|
|
3284
|
+
_ts_param10(1, Inject10(AGENT_ACTOR_RESOLVER3)),
|
|
3285
|
+
_ts_param10(2, Optional7()),
|
|
3286
|
+
_ts_param10(2, Inject10(AGENT_ATTACHMENT_STAGING4)),
|
|
3287
|
+
_ts_param10(3, Optional7()),
|
|
3288
|
+
_ts_param10(3, Inject10(AGENT_MODEL_CATALOG2)),
|
|
3289
|
+
_ts_metadata11("design:type", Function),
|
|
3290
|
+
_ts_metadata11("design:paramtypes", [
|
|
2484
3291
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
2485
3292
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
2486
3293
|
Object,
|
|
@@ -2490,8 +3297,8 @@ ConfigController = _ts_decorate11([
|
|
|
2490
3297
|
|
|
2491
3298
|
// src/controller/memories.controller.ts
|
|
2492
3299
|
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER4, AGENT_MEMORY as AGENT_MEMORY2, memoryForgetVerdict, offerMemories } from "@dudousxd/nestjs-agent-core";
|
|
2493
|
-
import { Controller as Controller5, Delete, ForbiddenException as ForbiddenException2, Get as Get5, Inject as
|
|
2494
|
-
function
|
|
3300
|
+
import { Controller as Controller5, Delete, ForbiddenException as ForbiddenException2, Get as Get5, Inject as Inject11, NotFoundException as NotFoundException2, Optional as Optional8, Param as Param2, Query as Query2, Req as Req4 } from "@nestjs/common";
|
|
3301
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
2495
3302
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2496
3303
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2497
3304
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2504,19 +3311,19 @@ function _ts_decorate12(decorators, target, key, desc) {
|
|
|
2504
3311
|
}
|
|
2505
3312
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2506
3313
|
}
|
|
2507
|
-
__name(
|
|
2508
|
-
function
|
|
3314
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
3315
|
+
function _ts_metadata12(metadataKey, metadataValue) {
|
|
2509
3316
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2510
3317
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2511
3318
|
}
|
|
2512
3319
|
}
|
|
2513
|
-
__name(
|
|
2514
|
-
function
|
|
3320
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
3321
|
+
function _ts_param11(paramIndex, decorator) {
|
|
2515
3322
|
return function(target, key) {
|
|
2516
3323
|
decorator(target, key, paramIndex);
|
|
2517
3324
|
};
|
|
2518
3325
|
}
|
|
2519
|
-
__name(
|
|
3326
|
+
__name(_ts_param11, "_ts_param");
|
|
2520
3327
|
var MemoriesController = class {
|
|
2521
3328
|
static {
|
|
2522
3329
|
__name(this, "MemoriesController");
|
|
@@ -2589,35 +3396,35 @@ var MemoriesController = class {
|
|
|
2589
3396
|
});
|
|
2590
3397
|
}
|
|
2591
3398
|
};
|
|
2592
|
-
|
|
3399
|
+
_ts_decorate13([
|
|
2593
3400
|
Get5(),
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
3401
|
+
_ts_param11(0, Req4()),
|
|
3402
|
+
_ts_param11(1, Query2("threadId")),
|
|
3403
|
+
_ts_metadata12("design:type", Function),
|
|
3404
|
+
_ts_metadata12("design:paramtypes", [
|
|
2598
3405
|
typeof Request === "undefined" ? Object : Request,
|
|
2599
3406
|
String
|
|
2600
3407
|
]),
|
|
2601
|
-
|
|
3408
|
+
_ts_metadata12("design:returntype", Promise)
|
|
2602
3409
|
], MemoriesController.prototype, "list", null);
|
|
2603
|
-
|
|
3410
|
+
_ts_decorate13([
|
|
2604
3411
|
Delete(":id"),
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
3412
|
+
_ts_param11(0, Req4()),
|
|
3413
|
+
_ts_param11(1, Param2("id")),
|
|
3414
|
+
_ts_metadata12("design:type", Function),
|
|
3415
|
+
_ts_metadata12("design:paramtypes", [
|
|
2609
3416
|
typeof Request === "undefined" ? Object : Request,
|
|
2610
3417
|
String
|
|
2611
3418
|
]),
|
|
2612
|
-
|
|
3419
|
+
_ts_metadata12("design:returntype", Promise)
|
|
2613
3420
|
], MemoriesController.prototype, "forget", null);
|
|
2614
|
-
MemoriesController =
|
|
3421
|
+
MemoriesController = _ts_decorate13([
|
|
2615
3422
|
Controller5("memories"),
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
3423
|
+
_ts_param11(0, Inject11(AGENT_ACTOR_RESOLVER4)),
|
|
3424
|
+
_ts_param11(1, Optional8()),
|
|
3425
|
+
_ts_param11(1, Inject11(AGENT_MEMORY2)),
|
|
3426
|
+
_ts_metadata12("design:type", Function),
|
|
3427
|
+
_ts_metadata12("design:paramtypes", [
|
|
2621
3428
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
2622
3429
|
Object
|
|
2623
3430
|
])
|
|
@@ -2625,8 +3432,8 @@ MemoriesController = _ts_decorate12([
|
|
|
2625
3432
|
|
|
2626
3433
|
// src/controller/messages.controller.ts
|
|
2627
3434
|
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5 } from "@dudousxd/nestjs-agent-core";
|
|
2628
|
-
import { Body as Body2, Controller as Controller6, HttpCode, Inject as
|
|
2629
|
-
function
|
|
3435
|
+
import { Body as Body2, Controller as Controller6, HttpCode, Inject as Inject12, Param as Param3, Post as Post3, Req as Req5 } from "@nestjs/common";
|
|
3436
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
2630
3437
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2631
3438
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2632
3439
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2639,19 +3446,19 @@ function _ts_decorate13(decorators, target, key, desc) {
|
|
|
2639
3446
|
}
|
|
2640
3447
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2641
3448
|
}
|
|
2642
|
-
__name(
|
|
2643
|
-
function
|
|
3449
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
3450
|
+
function _ts_metadata13(metadataKey, metadataValue) {
|
|
2644
3451
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2645
3452
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2646
3453
|
}
|
|
2647
3454
|
}
|
|
2648
|
-
__name(
|
|
2649
|
-
function
|
|
3455
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
3456
|
+
function _ts_param12(paramIndex, decorator) {
|
|
2650
3457
|
return function(target, key) {
|
|
2651
3458
|
decorator(target, key, paramIndex);
|
|
2652
3459
|
};
|
|
2653
3460
|
}
|
|
2654
|
-
__name(
|
|
3461
|
+
__name(_ts_param12, "_ts_param");
|
|
2655
3462
|
var MessagesController = class {
|
|
2656
3463
|
static {
|
|
2657
3464
|
__name(this, "MessagesController");
|
|
@@ -2679,25 +3486,25 @@ var MessagesController = class {
|
|
|
2679
3486
|
};
|
|
2680
3487
|
}
|
|
2681
3488
|
};
|
|
2682
|
-
|
|
3489
|
+
_ts_decorate14([
|
|
2683
3490
|
Post3(":id/feedback"),
|
|
2684
3491
|
HttpCode(200),
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
3492
|
+
_ts_param12(0, Req5()),
|
|
3493
|
+
_ts_param12(1, Param3("id")),
|
|
3494
|
+
_ts_param12(2, Body2()),
|
|
3495
|
+
_ts_metadata13("design:type", Function),
|
|
3496
|
+
_ts_metadata13("design:paramtypes", [
|
|
2690
3497
|
typeof Request === "undefined" ? Object : Request,
|
|
2691
3498
|
String,
|
|
2692
3499
|
typeof FeedbackBody === "undefined" ? Object : FeedbackBody
|
|
2693
3500
|
]),
|
|
2694
|
-
|
|
3501
|
+
_ts_metadata13("design:returntype", Promise)
|
|
2695
3502
|
], MessagesController.prototype, "feedback", null);
|
|
2696
|
-
MessagesController =
|
|
3503
|
+
MessagesController = _ts_decorate14([
|
|
2697
3504
|
Controller6("messages"),
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
3505
|
+
_ts_param12(1, Inject12(AGENT_ACTOR_RESOLVER5)),
|
|
3506
|
+
_ts_metadata13("design:type", Function),
|
|
3507
|
+
_ts_metadata13("design:paramtypes", [
|
|
2701
3508
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
2702
3509
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
2703
3510
|
])
|
|
@@ -2705,8 +3512,8 @@ MessagesController = _ts_decorate13([
|
|
|
2705
3512
|
|
|
2706
3513
|
// src/controller/models.controller.ts
|
|
2707
3514
|
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER6 } from "@dudousxd/nestjs-agent-core";
|
|
2708
|
-
import { Controller as Controller7, Get as Get6, Inject as
|
|
2709
|
-
function
|
|
3515
|
+
import { Controller as Controller7, Get as Get6, Inject as Inject13, Query as Query3, Req as Req6 } from "@nestjs/common";
|
|
3516
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
2710
3517
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2711
3518
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2712
3519
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2719,19 +3526,19 @@ function _ts_decorate14(decorators, target, key, desc) {
|
|
|
2719
3526
|
}
|
|
2720
3527
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2721
3528
|
}
|
|
2722
|
-
__name(
|
|
2723
|
-
function
|
|
3529
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
3530
|
+
function _ts_metadata14(metadataKey, metadataValue) {
|
|
2724
3531
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2725
3532
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2726
3533
|
}
|
|
2727
3534
|
}
|
|
2728
|
-
__name(
|
|
2729
|
-
function
|
|
3535
|
+
__name(_ts_metadata14, "_ts_metadata");
|
|
3536
|
+
function _ts_param13(paramIndex, decorator) {
|
|
2730
3537
|
return function(target, key) {
|
|
2731
3538
|
decorator(target, key, paramIndex);
|
|
2732
3539
|
};
|
|
2733
3540
|
}
|
|
2734
|
-
__name(
|
|
3541
|
+
__name(_ts_param13, "_ts_param");
|
|
2735
3542
|
var ModelsController = class {
|
|
2736
3543
|
static {
|
|
2737
3544
|
__name(this, "ModelsController");
|
|
@@ -2751,31 +3558,31 @@ var ModelsController = class {
|
|
|
2751
3558
|
return this.agent.listModels(actor, agent);
|
|
2752
3559
|
}
|
|
2753
3560
|
};
|
|
2754
|
-
|
|
3561
|
+
_ts_decorate15([
|
|
2755
3562
|
Get6(),
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
3563
|
+
_ts_param13(0, Req6()),
|
|
3564
|
+
_ts_param13(1, Query3("agent")),
|
|
3565
|
+
_ts_metadata14("design:type", Function),
|
|
3566
|
+
_ts_metadata14("design:paramtypes", [
|
|
2760
3567
|
typeof Request === "undefined" ? Object : Request,
|
|
2761
3568
|
String
|
|
2762
3569
|
]),
|
|
2763
|
-
|
|
3570
|
+
_ts_metadata14("design:returntype", Promise)
|
|
2764
3571
|
], ModelsController.prototype, "list", null);
|
|
2765
|
-
ModelsController =
|
|
3572
|
+
ModelsController = _ts_decorate15([
|
|
2766
3573
|
Controller7("models"),
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
3574
|
+
_ts_param13(1, Inject13(AGENT_ACTOR_RESOLVER6)),
|
|
3575
|
+
_ts_metadata14("design:type", Function),
|
|
3576
|
+
_ts_metadata14("design:paramtypes", [
|
|
2770
3577
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
2771
3578
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
2772
3579
|
])
|
|
2773
3580
|
], ModelsController);
|
|
2774
3581
|
|
|
2775
|
-
// src/controller/
|
|
3582
|
+
// src/controller/queue.controller.ts
|
|
2776
3583
|
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER7 } from "@dudousxd/nestjs-agent-core";
|
|
2777
|
-
import { Controller as Controller8, Get as Get7, Inject as
|
|
2778
|
-
function
|
|
3584
|
+
import { BadRequestException as BadRequestException4, Body as Body3, Controller as Controller8, Delete as Delete2, Get as Get7, Inject as Inject14, Param as Param4, Patch, Post as Post4, Req as Req7 } from "@nestjs/common";
|
|
3585
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
2779
3586
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2780
3587
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2781
3588
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2788,19 +3595,160 @@ function _ts_decorate15(decorators, target, key, desc) {
|
|
|
2788
3595
|
}
|
|
2789
3596
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2790
3597
|
}
|
|
2791
|
-
__name(
|
|
2792
|
-
function
|
|
3598
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
3599
|
+
function _ts_metadata15(metadataKey, metadataValue) {
|
|
2793
3600
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2794
3601
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2795
3602
|
}
|
|
2796
3603
|
}
|
|
2797
|
-
__name(
|
|
2798
|
-
function
|
|
3604
|
+
__name(_ts_metadata15, "_ts_metadata");
|
|
3605
|
+
function _ts_param14(paramIndex, decorator) {
|
|
2799
3606
|
return function(target, key) {
|
|
2800
3607
|
decorator(target, key, paramIndex);
|
|
2801
3608
|
};
|
|
2802
3609
|
}
|
|
2803
|
-
__name(
|
|
3610
|
+
__name(_ts_param14, "_ts_param");
|
|
3611
|
+
var QueueController = class {
|
|
3612
|
+
static {
|
|
3613
|
+
__name(this, "QueueController");
|
|
3614
|
+
}
|
|
3615
|
+
agent;
|
|
3616
|
+
actorResolver;
|
|
3617
|
+
constructor(agent, actorResolver) {
|
|
3618
|
+
this.agent = agent;
|
|
3619
|
+
this.actorResolver = actorResolver;
|
|
3620
|
+
}
|
|
3621
|
+
async list(req, id) {
|
|
3622
|
+
return this.agent.getQueue(await this.actorResolver.resolve(req), id);
|
|
3623
|
+
}
|
|
3624
|
+
async clear(req, id) {
|
|
3625
|
+
return this.agent.clearQueue(await this.actorResolver.resolve(req), id);
|
|
3626
|
+
}
|
|
3627
|
+
/** Lift a pause; the head starts when nothing is running. Carries `runId` when it started. */
|
|
3628
|
+
async resume(req, id) {
|
|
3629
|
+
return this.agent.resumeQueue(await this.actorResolver.resolve(req), id);
|
|
3630
|
+
}
|
|
3631
|
+
async update(req, messageId, body) {
|
|
3632
|
+
const actor = await this.actorResolver.resolve(req);
|
|
3633
|
+
if (body.message !== void 0 && typeof body.message !== "string") {
|
|
3634
|
+
throw new BadRequestException4("message must be a string");
|
|
3635
|
+
}
|
|
3636
|
+
if (body.position !== void 0 && typeof body.position !== "number") {
|
|
3637
|
+
throw new BadRequestException4("position must be a number");
|
|
3638
|
+
}
|
|
3639
|
+
const attachments = body.attachments === void 0 ? void 0 : body.attachments === null ? null : attachmentRefs(body.attachments);
|
|
3640
|
+
return this.agent.updateQueuedMessage(actor, messageId, {
|
|
3641
|
+
...body.message !== void 0 ? {
|
|
3642
|
+
message: body.message
|
|
3643
|
+
} : {},
|
|
3644
|
+
...attachments !== void 0 ? {
|
|
3645
|
+
attachments
|
|
3646
|
+
} : {},
|
|
3647
|
+
...body.position !== void 0 ? {
|
|
3648
|
+
position: body.position
|
|
3649
|
+
} : {}
|
|
3650
|
+
});
|
|
3651
|
+
}
|
|
3652
|
+
async remove(req, messageId) {
|
|
3653
|
+
return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
|
|
3654
|
+
}
|
|
3655
|
+
};
|
|
3656
|
+
_ts_decorate16([
|
|
3657
|
+
Get7("threads/:id/queue"),
|
|
3658
|
+
_ts_param14(0, Req7()),
|
|
3659
|
+
_ts_param14(1, Param4("id")),
|
|
3660
|
+
_ts_metadata15("design:type", Function),
|
|
3661
|
+
_ts_metadata15("design:paramtypes", [
|
|
3662
|
+
typeof Request === "undefined" ? Object : Request,
|
|
3663
|
+
String
|
|
3664
|
+
]),
|
|
3665
|
+
_ts_metadata15("design:returntype", Promise)
|
|
3666
|
+
], QueueController.prototype, "list", null);
|
|
3667
|
+
_ts_decorate16([
|
|
3668
|
+
Delete2("threads/:id/queue"),
|
|
3669
|
+
_ts_param14(0, Req7()),
|
|
3670
|
+
_ts_param14(1, Param4("id")),
|
|
3671
|
+
_ts_metadata15("design:type", Function),
|
|
3672
|
+
_ts_metadata15("design:paramtypes", [
|
|
3673
|
+
typeof Request === "undefined" ? Object : Request,
|
|
3674
|
+
String
|
|
3675
|
+
]),
|
|
3676
|
+
_ts_metadata15("design:returntype", Promise)
|
|
3677
|
+
], QueueController.prototype, "clear", null);
|
|
3678
|
+
_ts_decorate16([
|
|
3679
|
+
Post4("threads/:id/queue/resume"),
|
|
3680
|
+
_ts_param14(0, Req7()),
|
|
3681
|
+
_ts_param14(1, Param4("id")),
|
|
3682
|
+
_ts_metadata15("design:type", Function),
|
|
3683
|
+
_ts_metadata15("design:paramtypes", [
|
|
3684
|
+
typeof Request === "undefined" ? Object : Request,
|
|
3685
|
+
String
|
|
3686
|
+
]),
|
|
3687
|
+
_ts_metadata15("design:returntype", Promise)
|
|
3688
|
+
], QueueController.prototype, "resume", null);
|
|
3689
|
+
_ts_decorate16([
|
|
3690
|
+
Patch("queue/:messageId"),
|
|
3691
|
+
_ts_param14(0, Req7()),
|
|
3692
|
+
_ts_param14(1, Param4("messageId")),
|
|
3693
|
+
_ts_param14(2, Body3()),
|
|
3694
|
+
_ts_metadata15("design:type", Function),
|
|
3695
|
+
_ts_metadata15("design:paramtypes", [
|
|
3696
|
+
typeof Request === "undefined" ? Object : Request,
|
|
3697
|
+
String,
|
|
3698
|
+
typeof UpdateQueuedMessageBody === "undefined" ? Object : UpdateQueuedMessageBody
|
|
3699
|
+
]),
|
|
3700
|
+
_ts_metadata15("design:returntype", Promise)
|
|
3701
|
+
], QueueController.prototype, "update", null);
|
|
3702
|
+
_ts_decorate16([
|
|
3703
|
+
Delete2("queue/:messageId"),
|
|
3704
|
+
_ts_param14(0, Req7()),
|
|
3705
|
+
_ts_param14(1, Param4("messageId")),
|
|
3706
|
+
_ts_metadata15("design:type", Function),
|
|
3707
|
+
_ts_metadata15("design:paramtypes", [
|
|
3708
|
+
typeof Request === "undefined" ? Object : Request,
|
|
3709
|
+
String
|
|
3710
|
+
]),
|
|
3711
|
+
_ts_metadata15("design:returntype", Promise)
|
|
3712
|
+
], QueueController.prototype, "remove", null);
|
|
3713
|
+
QueueController = _ts_decorate16([
|
|
3714
|
+
Controller8(),
|
|
3715
|
+
_ts_param14(1, Inject14(AGENT_ACTOR_RESOLVER7)),
|
|
3716
|
+
_ts_metadata15("design:type", Function),
|
|
3717
|
+
_ts_metadata15("design:paramtypes", [
|
|
3718
|
+
typeof AgentService === "undefined" ? Object : AgentService,
|
|
3719
|
+
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
3720
|
+
])
|
|
3721
|
+
], QueueController);
|
|
3722
|
+
|
|
3723
|
+
// src/controller/quota.controller.ts
|
|
3724
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER8 } from "@dudousxd/nestjs-agent-core";
|
|
3725
|
+
import { Controller as Controller9, Get as Get8, Inject as Inject15, Req as Req8 } from "@nestjs/common";
|
|
3726
|
+
function _ts_decorate17(decorators, target, key, desc) {
|
|
3727
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3728
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
3729
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
3730
|
+
} else {
|
|
3731
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
3732
|
+
if (d = decorators[i]) {
|
|
3733
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3738
|
+
}
|
|
3739
|
+
__name(_ts_decorate17, "_ts_decorate");
|
|
3740
|
+
function _ts_metadata16(metadataKey, metadataValue) {
|
|
3741
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
3742
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
__name(_ts_metadata16, "_ts_metadata");
|
|
3746
|
+
function _ts_param15(paramIndex, decorator) {
|
|
3747
|
+
return function(target, key) {
|
|
3748
|
+
decorator(target, key, paramIndex);
|
|
3749
|
+
};
|
|
3750
|
+
}
|
|
3751
|
+
__name(_ts_param15, "_ts_param");
|
|
2804
3752
|
var QuotaController = class {
|
|
2805
3753
|
static {
|
|
2806
3754
|
__name(this, "QuotaController");
|
|
@@ -2820,29 +3768,29 @@ var QuotaController = class {
|
|
|
2820
3768
|
return this.agent.quotaReport(actor);
|
|
2821
3769
|
}
|
|
2822
3770
|
};
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
3771
|
+
_ts_decorate17([
|
|
3772
|
+
Get8(),
|
|
3773
|
+
_ts_param15(0, Req8()),
|
|
3774
|
+
_ts_metadata16("design:type", Function),
|
|
3775
|
+
_ts_metadata16("design:paramtypes", [
|
|
2828
3776
|
typeof Request === "undefined" ? Object : Request
|
|
2829
3777
|
]),
|
|
2830
|
-
|
|
3778
|
+
_ts_metadata16("design:returntype", Promise)
|
|
2831
3779
|
], QuotaController.prototype, "report", null);
|
|
2832
|
-
QuotaController =
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
3780
|
+
QuotaController = _ts_decorate17([
|
|
3781
|
+
Controller9("quota"),
|
|
3782
|
+
_ts_param15(1, Inject15(AGENT_ACTOR_RESOLVER8)),
|
|
3783
|
+
_ts_metadata16("design:type", Function),
|
|
3784
|
+
_ts_metadata16("design:paramtypes", [
|
|
2837
3785
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
2838
3786
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
2839
3787
|
])
|
|
2840
3788
|
], QuotaController);
|
|
2841
3789
|
|
|
2842
3790
|
// src/controller/skills.controller.ts
|
|
2843
|
-
import { AGENT_ACTOR_RESOLVER as
|
|
2844
|
-
import { Controller as
|
|
2845
|
-
function
|
|
3791
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER9, AGENT_SKILLS as AGENT_SKILLS2, offerSkills } from "@dudousxd/nestjs-agent-core";
|
|
3792
|
+
import { Controller as Controller10, Get as Get9, Inject as Inject16, Optional as Optional9, Query as Query4, Req as Req9 } from "@nestjs/common";
|
|
3793
|
+
function _ts_decorate18(decorators, target, key, desc) {
|
|
2846
3794
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2847
3795
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2848
3796
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2855,19 +3803,19 @@ function _ts_decorate16(decorators, target, key, desc) {
|
|
|
2855
3803
|
}
|
|
2856
3804
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2857
3805
|
}
|
|
2858
|
-
__name(
|
|
2859
|
-
function
|
|
3806
|
+
__name(_ts_decorate18, "_ts_decorate");
|
|
3807
|
+
function _ts_metadata17(metadataKey, metadataValue) {
|
|
2860
3808
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2861
3809
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2862
3810
|
}
|
|
2863
3811
|
}
|
|
2864
|
-
__name(
|
|
2865
|
-
function
|
|
3812
|
+
__name(_ts_metadata17, "_ts_metadata");
|
|
3813
|
+
function _ts_param16(paramIndex, decorator) {
|
|
2866
3814
|
return function(target, key) {
|
|
2867
3815
|
decorator(target, key, paramIndex);
|
|
2868
3816
|
};
|
|
2869
3817
|
}
|
|
2870
|
-
__name(
|
|
3818
|
+
__name(_ts_param16, "_ts_param");
|
|
2871
3819
|
var SkillsController = class {
|
|
2872
3820
|
static {
|
|
2873
3821
|
__name(this, "SkillsController");
|
|
@@ -2890,33 +3838,33 @@ var SkillsController = class {
|
|
|
2890
3838
|
return offer.entries;
|
|
2891
3839
|
}
|
|
2892
3840
|
};
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
3841
|
+
_ts_decorate18([
|
|
3842
|
+
Get9(),
|
|
3843
|
+
_ts_param16(0, Req9()),
|
|
3844
|
+
_ts_param16(1, Query4("threadId")),
|
|
3845
|
+
_ts_metadata17("design:type", Function),
|
|
3846
|
+
_ts_metadata17("design:paramtypes", [
|
|
2899
3847
|
typeof Request === "undefined" ? Object : Request,
|
|
2900
3848
|
String
|
|
2901
3849
|
]),
|
|
2902
|
-
|
|
3850
|
+
_ts_metadata17("design:returntype", Promise)
|
|
2903
3851
|
], SkillsController.prototype, "list", null);
|
|
2904
|
-
SkillsController =
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
3852
|
+
SkillsController = _ts_decorate18([
|
|
3853
|
+
Controller10("skills"),
|
|
3854
|
+
_ts_param16(0, Inject16(AGENT_ACTOR_RESOLVER9)),
|
|
3855
|
+
_ts_param16(1, Optional9()),
|
|
3856
|
+
_ts_param16(1, Inject16(AGENT_SKILLS2)),
|
|
3857
|
+
_ts_metadata17("design:type", Function),
|
|
3858
|
+
_ts_metadata17("design:paramtypes", [
|
|
2911
3859
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
2912
3860
|
Object
|
|
2913
3861
|
])
|
|
2914
3862
|
], SkillsController);
|
|
2915
3863
|
|
|
2916
3864
|
// src/controller/threads.controller.ts
|
|
2917
|
-
import { AGENT_ACTOR_RESOLVER as
|
|
2918
|
-
import { Body as
|
|
2919
|
-
function
|
|
3865
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER10 } from "@dudousxd/nestjs-agent-core";
|
|
3866
|
+
import { Body as Body4, Controller as Controller11, Delete as Delete3, Get as Get10, Inject as Inject17, Param as Param5, Patch as Patch2, Post as Post5, Req as Req10 } from "@nestjs/common";
|
|
3867
|
+
function _ts_decorate19(decorators, target, key, desc) {
|
|
2920
3868
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2921
3869
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
2922
3870
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2929,19 +3877,19 @@ function _ts_decorate17(decorators, target, key, desc) {
|
|
|
2929
3877
|
}
|
|
2930
3878
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2931
3879
|
}
|
|
2932
|
-
__name(
|
|
2933
|
-
function
|
|
3880
|
+
__name(_ts_decorate19, "_ts_decorate");
|
|
3881
|
+
function _ts_metadata18(metadataKey, metadataValue) {
|
|
2934
3882
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
2935
3883
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
2936
3884
|
}
|
|
2937
3885
|
}
|
|
2938
|
-
__name(
|
|
2939
|
-
function
|
|
3886
|
+
__name(_ts_metadata18, "_ts_metadata");
|
|
3887
|
+
function _ts_param17(paramIndex, decorator) {
|
|
2940
3888
|
return function(target, key) {
|
|
2941
3889
|
decorator(target, key, paramIndex);
|
|
2942
3890
|
};
|
|
2943
3891
|
}
|
|
2944
|
-
__name(
|
|
3892
|
+
__name(_ts_param17, "_ts_param");
|
|
2945
3893
|
var ThreadsController = class {
|
|
2946
3894
|
static {
|
|
2947
3895
|
__name(this, "ThreadsController");
|
|
@@ -3008,101 +3956,101 @@ var ThreadsController = class {
|
|
|
3008
3956
|
};
|
|
3009
3957
|
}
|
|
3010
3958
|
};
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3959
|
+
_ts_decorate19([
|
|
3960
|
+
Get10(),
|
|
3961
|
+
_ts_param17(0, Req10()),
|
|
3962
|
+
_ts_metadata18("design:type", Function),
|
|
3963
|
+
_ts_metadata18("design:paramtypes", [
|
|
3016
3964
|
typeof Request === "undefined" ? Object : Request
|
|
3017
3965
|
]),
|
|
3018
|
-
|
|
3966
|
+
_ts_metadata18("design:returntype", Promise)
|
|
3019
3967
|
], ThreadsController.prototype, "list", null);
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3968
|
+
_ts_decorate19([
|
|
3969
|
+
Get10(":id"),
|
|
3970
|
+
_ts_param17(0, Req10()),
|
|
3971
|
+
_ts_param17(1, Param5("id")),
|
|
3972
|
+
_ts_metadata18("design:type", Function),
|
|
3973
|
+
_ts_metadata18("design:paramtypes", [
|
|
3026
3974
|
typeof Request === "undefined" ? Object : Request,
|
|
3027
3975
|
String
|
|
3028
3976
|
]),
|
|
3029
|
-
|
|
3977
|
+
_ts_metadata18("design:returntype", Promise)
|
|
3030
3978
|
], ThreadsController.prototype, "detail", null);
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3979
|
+
_ts_decorate19([
|
|
3980
|
+
Delete3(":id"),
|
|
3981
|
+
_ts_param17(0, Req10()),
|
|
3982
|
+
_ts_param17(1, Param5("id")),
|
|
3983
|
+
_ts_metadata18("design:type", Function),
|
|
3984
|
+
_ts_metadata18("design:paramtypes", [
|
|
3037
3985
|
typeof Request === "undefined" ? Object : Request,
|
|
3038
3986
|
String
|
|
3039
3987
|
]),
|
|
3040
|
-
|
|
3988
|
+
_ts_metadata18("design:returntype", Promise)
|
|
3041
3989
|
], ThreadsController.prototype, "remove", null);
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3990
|
+
_ts_decorate19([
|
|
3991
|
+
Post5(":id/fork-from/:messageId"),
|
|
3992
|
+
_ts_param17(0, Req10()),
|
|
3993
|
+
_ts_param17(1, Param5("id")),
|
|
3994
|
+
_ts_param17(2, Param5("messageId")),
|
|
3995
|
+
_ts_metadata18("design:type", Function),
|
|
3996
|
+
_ts_metadata18("design:paramtypes", [
|
|
3049
3997
|
typeof Request === "undefined" ? Object : Request,
|
|
3050
3998
|
String,
|
|
3051
3999
|
String
|
|
3052
4000
|
]),
|
|
3053
|
-
|
|
4001
|
+
_ts_metadata18("design:returntype", Promise)
|
|
3054
4002
|
], ThreadsController.prototype, "fork", null);
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
4003
|
+
_ts_decorate19([
|
|
4004
|
+
Patch2(":id"),
|
|
4005
|
+
_ts_param17(0, Req10()),
|
|
4006
|
+
_ts_param17(1, Param5("id")),
|
|
4007
|
+
_ts_param17(2, Body4()),
|
|
4008
|
+
_ts_metadata18("design:type", Function),
|
|
4009
|
+
_ts_metadata18("design:paramtypes", [
|
|
3062
4010
|
typeof Request === "undefined" ? Object : Request,
|
|
3063
4011
|
String,
|
|
3064
4012
|
typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
|
|
3065
4013
|
]),
|
|
3066
|
-
|
|
4014
|
+
_ts_metadata18("design:returntype", Promise)
|
|
3067
4015
|
], ThreadsController.prototype, "update", null);
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
4016
|
+
_ts_decorate19([
|
|
4017
|
+
Post5(":id/promote"),
|
|
4018
|
+
_ts_param17(0, Req10()),
|
|
4019
|
+
_ts_param17(1, Param5("id")),
|
|
4020
|
+
_ts_metadata18("design:type", Function),
|
|
4021
|
+
_ts_metadata18("design:paramtypes", [
|
|
3074
4022
|
typeof Request === "undefined" ? Object : Request,
|
|
3075
4023
|
String
|
|
3076
4024
|
]),
|
|
3077
|
-
|
|
4025
|
+
_ts_metadata18("design:returntype", Promise)
|
|
3078
4026
|
], ThreadsController.prototype, "promote", null);
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
4027
|
+
_ts_decorate19([
|
|
4028
|
+
Delete3(":id/from/:messageId"),
|
|
4029
|
+
_ts_param17(0, Req10()),
|
|
4030
|
+
_ts_param17(1, Param5("id")),
|
|
4031
|
+
_ts_param17(2, Param5("messageId")),
|
|
4032
|
+
_ts_metadata18("design:type", Function),
|
|
4033
|
+
_ts_metadata18("design:paramtypes", [
|
|
3086
4034
|
typeof Request === "undefined" ? Object : Request,
|
|
3087
4035
|
String,
|
|
3088
4036
|
String
|
|
3089
4037
|
]),
|
|
3090
|
-
|
|
4038
|
+
_ts_metadata18("design:returntype", Promise)
|
|
3091
4039
|
], ThreadsController.prototype, "truncateFrom", null);
|
|
3092
|
-
ThreadsController =
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
4040
|
+
ThreadsController = _ts_decorate19([
|
|
4041
|
+
Controller11("threads"),
|
|
4042
|
+
_ts_param17(1, Inject17(AGENT_ACTOR_RESOLVER10)),
|
|
4043
|
+
_ts_metadata18("design:type", Function),
|
|
4044
|
+
_ts_metadata18("design:paramtypes", [
|
|
3097
4045
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
3098
4046
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
3099
4047
|
])
|
|
3100
4048
|
], ThreadsController);
|
|
3101
4049
|
|
|
3102
4050
|
// src/controller/tool-call.controller.ts
|
|
3103
|
-
import { AGENT_ACTOR_RESOLVER as
|
|
3104
|
-
import { BadRequestException as
|
|
3105
|
-
function
|
|
4051
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER11 } from "@dudousxd/nestjs-agent-core";
|
|
4052
|
+
import { BadRequestException as BadRequestException5, Body as Body5, Controller as Controller12, Inject as Inject18, Post as Post6, Req as Req11 } from "@nestjs/common";
|
|
4053
|
+
function _ts_decorate20(decorators, target, key, desc) {
|
|
3106
4054
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3107
4055
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
3108
4056
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3115,19 +4063,19 @@ function _ts_decorate18(decorators, target, key, desc) {
|
|
|
3115
4063
|
}
|
|
3116
4064
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3117
4065
|
}
|
|
3118
|
-
__name(
|
|
3119
|
-
function
|
|
4066
|
+
__name(_ts_decorate20, "_ts_decorate");
|
|
4067
|
+
function _ts_metadata19(metadataKey, metadataValue) {
|
|
3120
4068
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
3121
4069
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
3122
4070
|
}
|
|
3123
4071
|
}
|
|
3124
|
-
__name(
|
|
3125
|
-
function
|
|
4072
|
+
__name(_ts_metadata19, "_ts_metadata");
|
|
4073
|
+
function _ts_param18(paramIndex, decorator) {
|
|
3126
4074
|
return function(target, key) {
|
|
3127
4075
|
decorator(target, key, paramIndex);
|
|
3128
4076
|
};
|
|
3129
4077
|
}
|
|
3130
|
-
__name(
|
|
4078
|
+
__name(_ts_param18, "_ts_param");
|
|
3131
4079
|
var MAX_ANSWERED_QUESTIONS = 100;
|
|
3132
4080
|
var MAX_VALUES_PER_QUESTION = 100;
|
|
3133
4081
|
var MAX_ANSWER_VALUE_LENGTH = 4096;
|
|
@@ -3136,7 +4084,7 @@ var MAX_VIA_LENGTH = 64;
|
|
|
3136
4084
|
var DEFAULT_VIA = "web";
|
|
3137
4085
|
function toolCallId(claimed) {
|
|
3138
4086
|
if (typeof claimed !== "string" || claimed.length === 0) {
|
|
3139
|
-
throw new
|
|
4087
|
+
throw new BadRequestException5("toolCallId must be a non-empty string");
|
|
3140
4088
|
}
|
|
3141
4089
|
return claimed;
|
|
3142
4090
|
}
|
|
@@ -3146,10 +4094,10 @@ function rejectReason(claimed) {
|
|
|
3146
4094
|
return void 0;
|
|
3147
4095
|
}
|
|
3148
4096
|
if (typeof claimed !== "string") {
|
|
3149
|
-
throw new
|
|
4097
|
+
throw new BadRequestException5("reason must be a string");
|
|
3150
4098
|
}
|
|
3151
4099
|
if (claimed.length > MAX_REJECT_REASON_LENGTH) {
|
|
3152
|
-
throw new
|
|
4100
|
+
throw new BadRequestException5(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
|
|
3153
4101
|
}
|
|
3154
4102
|
return claimed;
|
|
3155
4103
|
}
|
|
@@ -3159,7 +4107,7 @@ function remember(claimed) {
|
|
|
3159
4107
|
return false;
|
|
3160
4108
|
}
|
|
3161
4109
|
if (typeof claimed !== "boolean") {
|
|
3162
|
-
throw new
|
|
4110
|
+
throw new BadRequestException5("remember must be a boolean");
|
|
3163
4111
|
}
|
|
3164
4112
|
return claimed;
|
|
3165
4113
|
}
|
|
@@ -3169,7 +4117,7 @@ function via(claimed) {
|
|
|
3169
4117
|
return DEFAULT_VIA;
|
|
3170
4118
|
}
|
|
3171
4119
|
if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
|
|
3172
|
-
throw new
|
|
4120
|
+
throw new BadRequestException5(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
|
|
3173
4121
|
}
|
|
3174
4122
|
return claimed;
|
|
3175
4123
|
}
|
|
@@ -3179,26 +4127,26 @@ function answers(claimed) {
|
|
|
3179
4127
|
return void 0;
|
|
3180
4128
|
}
|
|
3181
4129
|
if (typeof claimed !== "object" || claimed === null || Array.isArray(claimed)) {
|
|
3182
|
-
throw new
|
|
4130
|
+
throw new BadRequestException5("answers must be an object of questionId \u2192 chosen values");
|
|
3183
4131
|
}
|
|
3184
4132
|
const entries = Object.entries(claimed);
|
|
3185
4133
|
if (entries.length > MAX_ANSWERED_QUESTIONS) {
|
|
3186
|
-
throw new
|
|
4134
|
+
throw new BadRequestException5(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
|
|
3187
4135
|
}
|
|
3188
4136
|
const validated = /* @__PURE__ */ Object.create(null);
|
|
3189
4137
|
for (const [questionId, values] of entries) {
|
|
3190
4138
|
if (!Array.isArray(values)) {
|
|
3191
|
-
throw new
|
|
4139
|
+
throw new BadRequestException5(`answers["${questionId}"] must be an array of chosen values`);
|
|
3192
4140
|
}
|
|
3193
4141
|
if (values.length > MAX_VALUES_PER_QUESTION) {
|
|
3194
|
-
throw new
|
|
4142
|
+
throw new BadRequestException5(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
|
|
3195
4143
|
}
|
|
3196
4144
|
for (const value of values) {
|
|
3197
4145
|
if (typeof value !== "string") {
|
|
3198
|
-
throw new
|
|
4146
|
+
throw new BadRequestException5(`answers["${questionId}"] must contain only strings`);
|
|
3199
4147
|
}
|
|
3200
4148
|
if (value.length > MAX_ANSWER_VALUE_LENGTH) {
|
|
3201
|
-
throw new
|
|
4149
|
+
throw new BadRequestException5(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
|
|
3202
4150
|
}
|
|
3203
4151
|
}
|
|
3204
4152
|
validated[questionId] = values;
|
|
@@ -3260,64 +4208,64 @@ var ToolCallController = class {
|
|
|
3260
4208
|
};
|
|
3261
4209
|
}
|
|
3262
4210
|
};
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
4211
|
+
_ts_decorate20([
|
|
4212
|
+
Post6("approve"),
|
|
4213
|
+
_ts_param18(0, Req11()),
|
|
4214
|
+
_ts_param18(1, Body5()),
|
|
4215
|
+
_ts_metadata19("design:type", Function),
|
|
4216
|
+
_ts_metadata19("design:paramtypes", [
|
|
3269
4217
|
typeof Request === "undefined" ? Object : Request,
|
|
3270
4218
|
typeof ApproveBody === "undefined" ? Object : ApproveBody
|
|
3271
4219
|
]),
|
|
3272
|
-
|
|
4220
|
+
_ts_metadata19("design:returntype", Promise)
|
|
3273
4221
|
], ToolCallController.prototype, "approve", null);
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
4222
|
+
_ts_decorate20([
|
|
4223
|
+
Post6("reject"),
|
|
4224
|
+
_ts_param18(0, Req11()),
|
|
4225
|
+
_ts_param18(1, Body5()),
|
|
4226
|
+
_ts_metadata19("design:type", Function),
|
|
4227
|
+
_ts_metadata19("design:paramtypes", [
|
|
3280
4228
|
typeof Request === "undefined" ? Object : Request,
|
|
3281
4229
|
typeof RejectBody === "undefined" ? Object : RejectBody
|
|
3282
4230
|
]),
|
|
3283
|
-
|
|
4231
|
+
_ts_metadata19("design:returntype", Promise)
|
|
3284
4232
|
], ToolCallController.prototype, "reject", null);
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
4233
|
+
_ts_decorate20([
|
|
4234
|
+
Post6("answer"),
|
|
4235
|
+
_ts_param18(0, Req11()),
|
|
4236
|
+
_ts_param18(1, Body5()),
|
|
4237
|
+
_ts_metadata19("design:type", Function),
|
|
4238
|
+
_ts_metadata19("design:paramtypes", [
|
|
3291
4239
|
typeof Request === "undefined" ? Object : Request,
|
|
3292
4240
|
typeof AnswerBody === "undefined" ? Object : AnswerBody
|
|
3293
4241
|
]),
|
|
3294
|
-
|
|
4242
|
+
_ts_metadata19("design:returntype", Promise)
|
|
3295
4243
|
], ToolCallController.prototype, "answer", null);
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
4244
|
+
_ts_decorate20([
|
|
4245
|
+
Post6("skip"),
|
|
4246
|
+
_ts_param18(0, Req11()),
|
|
4247
|
+
_ts_param18(1, Body5()),
|
|
4248
|
+
_ts_metadata19("design:type", Function),
|
|
4249
|
+
_ts_metadata19("design:paramtypes", [
|
|
3302
4250
|
typeof Request === "undefined" ? Object : Request,
|
|
3303
4251
|
Object
|
|
3304
4252
|
]),
|
|
3305
|
-
|
|
4253
|
+
_ts_metadata19("design:returntype", Promise)
|
|
3306
4254
|
], ToolCallController.prototype, "skip", null);
|
|
3307
|
-
ToolCallController =
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
4255
|
+
ToolCallController = _ts_decorate20([
|
|
4256
|
+
Controller12("tool-call"),
|
|
4257
|
+
_ts_param18(1, Inject18(AGENT_ACTOR_RESOLVER11)),
|
|
4258
|
+
_ts_metadata19("design:type", Function),
|
|
4259
|
+
_ts_metadata19("design:paramtypes", [
|
|
3312
4260
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
3313
4261
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
3314
4262
|
])
|
|
3315
4263
|
], ToolCallController);
|
|
3316
4264
|
|
|
3317
4265
|
// src/controller/tools.controller.ts
|
|
3318
|
-
import { AGENT_ACTOR_RESOLVER as
|
|
3319
|
-
import { Controller as
|
|
3320
|
-
function
|
|
4266
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER12, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_REGISTRY as AGENT_REGISTRY3, ALL_AGENTS, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
|
|
4267
|
+
import { Controller as Controller13, Get as Get11, Inject as Inject19, NotFoundException as NotFoundException3, Query as Query5, Req as Req12 } from "@nestjs/common";
|
|
4268
|
+
function _ts_decorate21(decorators, target, key, desc) {
|
|
3321
4269
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3322
4270
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
3323
4271
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3330,19 +4278,19 @@ function _ts_decorate19(decorators, target, key, desc) {
|
|
|
3330
4278
|
}
|
|
3331
4279
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3332
4280
|
}
|
|
3333
|
-
__name(
|
|
3334
|
-
function
|
|
4281
|
+
__name(_ts_decorate21, "_ts_decorate");
|
|
4282
|
+
function _ts_metadata20(metadataKey, metadataValue) {
|
|
3335
4283
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
3336
4284
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
3337
4285
|
}
|
|
3338
4286
|
}
|
|
3339
|
-
__name(
|
|
3340
|
-
function
|
|
4287
|
+
__name(_ts_metadata20, "_ts_metadata");
|
|
4288
|
+
function _ts_param19(paramIndex, decorator) {
|
|
3341
4289
|
return function(target, key) {
|
|
3342
4290
|
decorator(target, key, paramIndex);
|
|
3343
4291
|
};
|
|
3344
4292
|
}
|
|
3345
|
-
__name(
|
|
4293
|
+
__name(_ts_param19, "_ts_param");
|
|
3346
4294
|
var ToolsController = class {
|
|
3347
4295
|
static {
|
|
3348
4296
|
__name(this, "ToolsController");
|
|
@@ -3386,24 +4334,24 @@ var ToolsController = class {
|
|
|
3386
4334
|
];
|
|
3387
4335
|
}
|
|
3388
4336
|
};
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
4337
|
+
_ts_decorate21([
|
|
4338
|
+
Get11(),
|
|
4339
|
+
_ts_param19(0, Req12()),
|
|
4340
|
+
_ts_param19(1, Query5("agent")),
|
|
4341
|
+
_ts_metadata20("design:type", Function),
|
|
4342
|
+
_ts_metadata20("design:paramtypes", [
|
|
3395
4343
|
typeof Request === "undefined" ? Object : Request,
|
|
3396
4344
|
String
|
|
3397
4345
|
]),
|
|
3398
|
-
|
|
4346
|
+
_ts_metadata20("design:returntype", Promise)
|
|
3399
4347
|
], ToolsController.prototype, "list", null);
|
|
3400
|
-
ToolsController =
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
4348
|
+
ToolsController = _ts_decorate21([
|
|
4349
|
+
Controller13("tools"),
|
|
4350
|
+
_ts_param19(0, Inject19(AGENT_ACTOR_RESOLVER12)),
|
|
4351
|
+
_ts_param19(1, Inject19(AGENT_DEPS_FACTORY5)),
|
|
4352
|
+
_ts_param19(2, Inject19(AGENT_REGISTRY3)),
|
|
4353
|
+
_ts_metadata20("design:type", Function),
|
|
4354
|
+
_ts_metadata20("design:paramtypes", [
|
|
3407
4355
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
3408
4356
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
3409
4357
|
typeof AgentRegistry4 === "undefined" ? Object : AgentRegistry4
|
|
@@ -3412,7 +4360,7 @@ ToolsController = _ts_decorate19([
|
|
|
3412
4360
|
|
|
3413
4361
|
// src/discovery/agent-discovery.service.ts
|
|
3414
4362
|
import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY4, AgentRegistry as AgentRegistry5 } from "@dudousxd/nestjs-agent-core";
|
|
3415
|
-
import { Inject as
|
|
4363
|
+
import { Inject as Inject20, Injectable as Injectable8, Logger as Logger3 } from "@nestjs/common";
|
|
3416
4364
|
import { DiscoveryService, MetadataScanner } from "@nestjs/core";
|
|
3417
4365
|
|
|
3418
4366
|
// src/decorator/agent.decorator.ts
|
|
@@ -3429,7 +4377,7 @@ var SYSTEM_PROMPT_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:
|
|
|
3429
4377
|
var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
|
|
3430
4378
|
|
|
3431
4379
|
// src/discovery/agent-discovery.service.ts
|
|
3432
|
-
function
|
|
4380
|
+
function _ts_decorate22(decorators, target, key, desc) {
|
|
3433
4381
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3434
4382
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
3435
4383
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3442,19 +4390,19 @@ function _ts_decorate20(decorators, target, key, desc) {
|
|
|
3442
4390
|
}
|
|
3443
4391
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3444
4392
|
}
|
|
3445
|
-
__name(
|
|
3446
|
-
function
|
|
4393
|
+
__name(_ts_decorate22, "_ts_decorate");
|
|
4394
|
+
function _ts_metadata21(metadataKey, metadataValue) {
|
|
3447
4395
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
3448
4396
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
3449
4397
|
}
|
|
3450
4398
|
}
|
|
3451
|
-
__name(
|
|
3452
|
-
function
|
|
4399
|
+
__name(_ts_metadata21, "_ts_metadata");
|
|
4400
|
+
function _ts_param20(paramIndex, decorator) {
|
|
3453
4401
|
return function(target, key) {
|
|
3454
4402
|
decorator(target, key, paramIndex);
|
|
3455
4403
|
};
|
|
3456
4404
|
}
|
|
3457
|
-
__name(
|
|
4405
|
+
__name(_ts_param20, "_ts_param");
|
|
3458
4406
|
var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
3459
4407
|
static {
|
|
3460
4408
|
__name(this, "AgentDiscoveryService");
|
|
@@ -3463,7 +4411,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
|
3463
4411
|
scanner;
|
|
3464
4412
|
registry;
|
|
3465
4413
|
contributors;
|
|
3466
|
-
logger = new
|
|
4414
|
+
logger = new Logger3(_AgentDiscoveryService.name);
|
|
3467
4415
|
constructor(discovery, scanner, registry, contributors) {
|
|
3468
4416
|
this.discovery = discovery;
|
|
3469
4417
|
this.scanner = scanner;
|
|
@@ -3581,12 +4529,12 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
|
3581
4529
|
return (ctx) => candidate.call(instance, ctx);
|
|
3582
4530
|
}
|
|
3583
4531
|
};
|
|
3584
|
-
AgentDiscoveryService =
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
4532
|
+
AgentDiscoveryService = _ts_decorate22([
|
|
4533
|
+
Injectable8(),
|
|
4534
|
+
_ts_param20(2, Inject20(AGENT_REGISTRY4)),
|
|
4535
|
+
_ts_param20(3, Inject20(AGENT_PROMPT_CONTRIBUTORS2)),
|
|
4536
|
+
_ts_metadata21("design:type", Function),
|
|
4537
|
+
_ts_metadata21("design:paramtypes", [
|
|
3590
4538
|
typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
|
|
3591
4539
|
typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
|
|
3592
4540
|
typeof AgentRegistry5 === "undefined" ? Object : AgentRegistry5,
|
|
@@ -3595,8 +4543,8 @@ AgentDiscoveryService = _ts_decorate20([
|
|
|
3595
4543
|
], AgentDiscoveryService);
|
|
3596
4544
|
|
|
3597
4545
|
// src/discovery/ai-tool-discovery.service.ts
|
|
3598
|
-
import { AGENT_OPTIONS as
|
|
3599
|
-
import { Inject as
|
|
4546
|
+
import { AGENT_OPTIONS as AGENT_OPTIONS6, AGENT_REGISTRY as AGENT_REGISTRY5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2, normalizeDelegation as normalizeDelegation2 } from "@dudousxd/nestjs-agent-core";
|
|
4547
|
+
import { Inject as Inject21, Injectable as Injectable9, Logger as Logger4 } from "@nestjs/common";
|
|
3600
4548
|
import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
|
|
3601
4549
|
import { z } from "zod";
|
|
3602
4550
|
|
|
@@ -3616,7 +4564,7 @@ function isBrandedFunctionalTool(value) {
|
|
|
3616
4564
|
__name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
|
|
3617
4565
|
|
|
3618
4566
|
// src/discovery/ai-tool-discovery.service.ts
|
|
3619
|
-
function
|
|
4567
|
+
function _ts_decorate23(decorators, target, key, desc) {
|
|
3620
4568
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3621
4569
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
3622
4570
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3629,19 +4577,19 @@ function _ts_decorate21(decorators, target, key, desc) {
|
|
|
3629
4577
|
}
|
|
3630
4578
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3631
4579
|
}
|
|
3632
|
-
__name(
|
|
3633
|
-
function
|
|
4580
|
+
__name(_ts_decorate23, "_ts_decorate");
|
|
4581
|
+
function _ts_metadata22(metadataKey, metadataValue) {
|
|
3634
4582
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
3635
4583
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
3636
4584
|
}
|
|
3637
4585
|
}
|
|
3638
|
-
__name(
|
|
3639
|
-
function
|
|
4586
|
+
__name(_ts_metadata22, "_ts_metadata");
|
|
4587
|
+
function _ts_param21(paramIndex, decorator) {
|
|
3640
4588
|
return function(target, key) {
|
|
3641
4589
|
decorator(target, key, paramIndex);
|
|
3642
4590
|
};
|
|
3643
4591
|
}
|
|
3644
|
-
__name(
|
|
4592
|
+
__name(_ts_param21, "_ts_param");
|
|
3645
4593
|
var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
3646
4594
|
static {
|
|
3647
4595
|
__name(this, "AiToolDiscoveryService");
|
|
@@ -3650,7 +4598,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
3650
4598
|
registry;
|
|
3651
4599
|
agents;
|
|
3652
4600
|
options;
|
|
3653
|
-
logger = new
|
|
4601
|
+
logger = new Logger4(_AiToolDiscoveryService.name);
|
|
3654
4602
|
constructor(discovery, registry, agents, options) {
|
|
3655
4603
|
this.discovery = discovery;
|
|
3656
4604
|
this.registry = registry;
|
|
@@ -3785,13 +4733,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
3785
4733
|
return true;
|
|
3786
4734
|
}
|
|
3787
4735
|
};
|
|
3788
|
-
AiToolDiscoveryService =
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
4736
|
+
AiToolDiscoveryService = _ts_decorate23([
|
|
4737
|
+
Injectable9(),
|
|
4738
|
+
_ts_param21(1, Inject21(AGENT_TOOL_REGISTRY2)),
|
|
4739
|
+
_ts_param21(2, Inject21(AGENT_REGISTRY5)),
|
|
4740
|
+
_ts_param21(3, Inject21(AGENT_OPTIONS6)),
|
|
4741
|
+
_ts_metadata22("design:type", Function),
|
|
4742
|
+
_ts_metadata22("design:paramtypes", [
|
|
3795
4743
|
typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
|
|
3796
4744
|
typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
|
|
3797
4745
|
typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
|
|
@@ -3801,7 +4749,7 @@ AiToolDiscoveryService = _ts_decorate21([
|
|
|
3801
4749
|
|
|
3802
4750
|
// src/discovery/skill-discovery.service.ts
|
|
3803
4751
|
import { AGENT_SKILL_SOURCES } from "@dudousxd/nestjs-agent-core";
|
|
3804
|
-
import { Inject as
|
|
4752
|
+
import { Inject as Inject22, Injectable as Injectable10, Logger as Logger5 } from "@nestjs/common";
|
|
3805
4753
|
import { DiscoveryService as DiscoveryService3 } from "@nestjs/core";
|
|
3806
4754
|
|
|
3807
4755
|
// src/decorator/skill.decorator.ts
|
|
@@ -3818,7 +4766,7 @@ function skillScope(options) {
|
|
|
3818
4766
|
__name(skillScope, "skillScope");
|
|
3819
4767
|
|
|
3820
4768
|
// src/discovery/skill-discovery.service.ts
|
|
3821
|
-
function
|
|
4769
|
+
function _ts_decorate24(decorators, target, key, desc) {
|
|
3822
4770
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3823
4771
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
3824
4772
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3831,26 +4779,26 @@ function _ts_decorate22(decorators, target, key, desc) {
|
|
|
3831
4779
|
}
|
|
3832
4780
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3833
4781
|
}
|
|
3834
|
-
__name(
|
|
3835
|
-
function
|
|
4782
|
+
__name(_ts_decorate24, "_ts_decorate");
|
|
4783
|
+
function _ts_metadata23(metadataKey, metadataValue) {
|
|
3836
4784
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
3837
4785
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
3838
4786
|
}
|
|
3839
4787
|
}
|
|
3840
|
-
__name(
|
|
3841
|
-
function
|
|
4788
|
+
__name(_ts_metadata23, "_ts_metadata");
|
|
4789
|
+
function _ts_param22(paramIndex, decorator) {
|
|
3842
4790
|
return function(target, key) {
|
|
3843
4791
|
decorator(target, key, paramIndex);
|
|
3844
4792
|
};
|
|
3845
4793
|
}
|
|
3846
|
-
__name(
|
|
4794
|
+
__name(_ts_param22, "_ts_param");
|
|
3847
4795
|
var SkillDiscoveryService = class _SkillDiscoveryService {
|
|
3848
4796
|
static {
|
|
3849
4797
|
__name(this, "SkillDiscoveryService");
|
|
3850
4798
|
}
|
|
3851
4799
|
discovery;
|
|
3852
4800
|
declared;
|
|
3853
|
-
logger = new
|
|
4801
|
+
logger = new Logger5(_SkillDiscoveryService.name);
|
|
3854
4802
|
constructor(discovery, declared) {
|
|
3855
4803
|
this.discovery = discovery;
|
|
3856
4804
|
this.declared = declared;
|
|
@@ -3887,11 +4835,11 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
|
|
|
3887
4835
|
return flat === void 0 ? void 0 : () => flat;
|
|
3888
4836
|
}
|
|
3889
4837
|
};
|
|
3890
|
-
SkillDiscoveryService =
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
4838
|
+
SkillDiscoveryService = _ts_decorate24([
|
|
4839
|
+
Injectable10(),
|
|
4840
|
+
_ts_param22(1, Inject22(AGENT_SKILL_SOURCES)),
|
|
4841
|
+
_ts_metadata23("design:type", Function),
|
|
4842
|
+
_ts_metadata23("design:paramtypes", [
|
|
3895
4843
|
typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
|
|
3896
4844
|
Array
|
|
3897
4845
|
])
|
|
@@ -3960,9 +4908,9 @@ var LedgerQuotaProvider = class {
|
|
|
3960
4908
|
};
|
|
3961
4909
|
|
|
3962
4910
|
// src/runner/inline-agent-runner.ts
|
|
3963
|
-
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as
|
|
3964
|
-
import { Inject as
|
|
3965
|
-
function
|
|
4911
|
+
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE6, RunCancelledError as RunCancelledError2, agentFailureCode as agentFailureCode2, encodeStreamEvent as encodeStreamEvent5, publishAgentRunFailed as publishAgentRunFailed2, releaseThreadRun as releaseThreadRun3, runAgentLoop as runAgentLoop2, settleAll as settleAll2, settleUnsettledDelegation as settleUnsettledDelegation2 } from "@dudousxd/nestjs-agent-core";
|
|
4912
|
+
import { Inject as Inject23, Injectable as Injectable11, Logger as Logger6, Optional as Optional10 } from "@nestjs/common";
|
|
4913
|
+
function _ts_decorate25(decorators, target, key, desc) {
|
|
3966
4914
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3967
4915
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
3968
4916
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3975,26 +4923,27 @@ function _ts_decorate23(decorators, target, key, desc) {
|
|
|
3975
4923
|
}
|
|
3976
4924
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3977
4925
|
}
|
|
3978
|
-
__name(
|
|
3979
|
-
function
|
|
4926
|
+
__name(_ts_decorate25, "_ts_decorate");
|
|
4927
|
+
function _ts_metadata24(metadataKey, metadataValue) {
|
|
3980
4928
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
3981
4929
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
3982
4930
|
}
|
|
3983
4931
|
}
|
|
3984
|
-
__name(
|
|
3985
|
-
function
|
|
4932
|
+
__name(_ts_metadata24, "_ts_metadata");
|
|
4933
|
+
function _ts_param23(paramIndex, decorator) {
|
|
3986
4934
|
return function(target, key) {
|
|
3987
4935
|
decorator(target, key, paramIndex);
|
|
3988
4936
|
};
|
|
3989
4937
|
}
|
|
3990
|
-
__name(
|
|
4938
|
+
__name(_ts_param23, "_ts_param");
|
|
3991
4939
|
var InlineAgentRunner = class _InlineAgentRunner {
|
|
3992
4940
|
static {
|
|
3993
4941
|
__name(this, "InlineAgentRunner");
|
|
3994
4942
|
}
|
|
3995
4943
|
factory;
|
|
3996
4944
|
store;
|
|
3997
|
-
|
|
4945
|
+
queue;
|
|
4946
|
+
logger = new Logger6(_InlineAgentRunner.name);
|
|
3998
4947
|
pending = /* @__PURE__ */ new Map();
|
|
3999
4948
|
/**
|
|
4000
4949
|
* Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
|
|
@@ -4002,14 +4951,25 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4002
4951
|
* running it. A cancelled id is dropped once the run settles, so the set tracks live runs only.
|
|
4003
4952
|
*/
|
|
4004
4953
|
cancelled = /* @__PURE__ */ new Set();
|
|
4005
|
-
|
|
4954
|
+
/** Top-level runs this process is running now — what {@link isRunActive} answers from. */
|
|
4955
|
+
live = /* @__PURE__ */ new Set();
|
|
4956
|
+
constructor(factory, store, queue) {
|
|
4006
4957
|
this.factory = factory;
|
|
4007
4958
|
this.store = store;
|
|
4959
|
+
this.queue = queue;
|
|
4008
4960
|
}
|
|
4009
|
-
|
|
4010
|
-
|
|
4961
|
+
/**
|
|
4962
|
+
* In-process, so exact: a run this process is not running is not running anywhere — the process
|
|
4963
|
+
* that was running it is gone (a restart), and a thread it still holds is a stale claim.
|
|
4964
|
+
*/
|
|
4965
|
+
async isRunActive(runId) {
|
|
4966
|
+
return this.live.has(runId);
|
|
4967
|
+
}
|
|
4968
|
+
async start(input, options = {}) {
|
|
4969
|
+
const runId = options.runId ?? crypto.randomUUID();
|
|
4011
4970
|
const day = input.day ?? utcDay();
|
|
4012
4971
|
const deps = this.factory.forAgent(input.agentName);
|
|
4972
|
+
this.live.add(runId);
|
|
4013
4973
|
const hooks = this.topLevelHooks({
|
|
4014
4974
|
runId,
|
|
4015
4975
|
deps,
|
|
@@ -4021,14 +4981,15 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4021
4981
|
...input.agentName !== void 0 ? [
|
|
4022
4982
|
input.agentName
|
|
4023
4983
|
] : []
|
|
4024
|
-
]
|
|
4984
|
+
],
|
|
4985
|
+
input
|
|
4025
4986
|
});
|
|
4026
4987
|
void runAgentLoop2({
|
|
4027
4988
|
...deps,
|
|
4028
4989
|
day
|
|
4029
|
-
}, input, hooks).then(() => this.store
|
|
4990
|
+
}, input, hooks).then(() => releaseThreadRun3(this.store, input.threadId, runId)).catch(async (error) => {
|
|
4030
4991
|
if (error instanceof RunCancelledError2) {
|
|
4031
|
-
await this.settleCancelled(runId, input
|
|
4992
|
+
await this.settleCancelled(runId, input, deps);
|
|
4032
4993
|
return;
|
|
4033
4994
|
}
|
|
4034
4995
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -4045,13 +5006,17 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4045
5006
|
errorCode: code,
|
|
4046
5007
|
errorMessage: message
|
|
4047
5008
|
});
|
|
4048
|
-
await this.store.setActiveStream(input.threadId, null);
|
|
4049
5009
|
const writer = await deps.sink.open(runId);
|
|
5010
|
+
await this.settleQueue(writer, input, runId, "failed", message);
|
|
5011
|
+
await releaseThreadRun3(this.store, input.threadId, runId);
|
|
4050
5012
|
await writer.fail({
|
|
4051
5013
|
code,
|
|
4052
5014
|
message
|
|
4053
5015
|
});
|
|
4054
|
-
}).finally(() =>
|
|
5016
|
+
}).finally(() => {
|
|
5017
|
+
this.cancelled.delete(runId);
|
|
5018
|
+
this.live.delete(runId);
|
|
5019
|
+
});
|
|
4055
5020
|
return {
|
|
4056
5021
|
runId
|
|
4057
5022
|
};
|
|
@@ -4094,11 +5059,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4094
5059
|
* the stream ENDED after a `cancelled` frame rather than failed, so a client that retries failed
|
|
4095
5060
|
* streams does not retry this one.
|
|
4096
5061
|
*/
|
|
4097
|
-
async settleCancelled(runId,
|
|
5062
|
+
async settleCancelled(runId, input, deps) {
|
|
4098
5063
|
this.logger.log(`agent run ${runId} cancelled`);
|
|
4099
|
-
await this.store.setActiveStream(threadId, null);
|
|
4100
5064
|
const writer = await deps.sink.open(runId);
|
|
4101
|
-
await
|
|
5065
|
+
await this.settleQueue(writer, input, runId, "cancelled");
|
|
5066
|
+
await releaseThreadRun3(this.store, input.threadId, runId);
|
|
5067
|
+
await writer.write(encodeStreamEvent5({
|
|
4102
5068
|
kind: "cancelled"
|
|
4103
5069
|
}));
|
|
4104
5070
|
await writer.end();
|
|
@@ -4108,6 +5074,38 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4108
5074
|
});
|
|
4109
5075
|
}
|
|
4110
5076
|
/**
|
|
5077
|
+
* Move the thread past a settling TOP-LEVEL run — to the next queued message, which starts here,
|
|
5078
|
+
* or to a paused/empty queue — and write the resulting `queue` frame into this run's stream. A
|
|
5079
|
+
* no-op without a queue-capable store, and for a run that is not a thread's own turn.
|
|
5080
|
+
*
|
|
5081
|
+
* Never throws: the run is settling either way, and a queue that could not be advanced is picked
|
|
5082
|
+
* up by the next send or resume on the thread.
|
|
5083
|
+
*/
|
|
5084
|
+
async settleQueue(writer, input, runId, outcome, error) {
|
|
5085
|
+
const queue = this.queue;
|
|
5086
|
+
if (queue === void 0 || !queue.supported || !isThreadTurn2(input)) {
|
|
5087
|
+
return;
|
|
5088
|
+
}
|
|
5089
|
+
const settled = outcome === "completed" && this.cancelled.has(runId) ? "cancelled" : outcome;
|
|
5090
|
+
try {
|
|
5091
|
+
const frame = await queue.handoff({
|
|
5092
|
+
threadId: input.threadId,
|
|
5093
|
+
runId,
|
|
5094
|
+
outcome: settled,
|
|
5095
|
+
...error !== void 0 ? {
|
|
5096
|
+
error
|
|
5097
|
+
} : {}
|
|
5098
|
+
}, (next, nextRunId) => this.start(next, {
|
|
5099
|
+
runId: nextRunId
|
|
5100
|
+
}));
|
|
5101
|
+
if (frame !== void 0) {
|
|
5102
|
+
await writer.write(encodeStreamEvent5(frame));
|
|
5103
|
+
}
|
|
5104
|
+
} catch (failure) {
|
|
5105
|
+
this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
/**
|
|
4111
5109
|
* Park a run on a human, keyed by run + tool call. One map for approvals and for question-set
|
|
4112
5110
|
* answers alike: both wait on the same key, and `signal` cannot tell (or need to tell) which
|
|
4113
5111
|
* shape it is delivering — the loop asked for one and only ever gets what the caller sent. A
|
|
@@ -4152,10 +5150,23 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4152
5150
|
});
|
|
4153
5151
|
}
|
|
4154
5152
|
topLevelHooks(args) {
|
|
4155
|
-
const { runId, deps, actor, day, threadId, chainBelow } = args;
|
|
5153
|
+
const { runId, deps, actor, day, threadId, chainBelow, input } = args;
|
|
4156
5154
|
return {
|
|
4157
5155
|
runId,
|
|
4158
|
-
|
|
5156
|
+
// The loop ends the stream when the turn completes. Just before, the thread passes to the next
|
|
5157
|
+
// queued message (or is released), and the reader is told which — so by the time a client
|
|
5158
|
+
// sees the run end, the thread is already free or already running what it queued.
|
|
5159
|
+
openSink: /* @__PURE__ */ __name(async () => {
|
|
5160
|
+
const writer = await deps.sink.open(runId);
|
|
5161
|
+
return this.queue === void 0 ? writer : {
|
|
5162
|
+
write: /* @__PURE__ */ __name((chunk) => writer.write(chunk), "write"),
|
|
5163
|
+
fail: /* @__PURE__ */ __name((error) => writer.fail(error), "fail"),
|
|
5164
|
+
end: /* @__PURE__ */ __name(async () => {
|
|
5165
|
+
await this.settleQueue(writer, input, runId, "completed");
|
|
5166
|
+
await writer.end();
|
|
5167
|
+
}, "end")
|
|
5168
|
+
};
|
|
5169
|
+
}, "openSink"),
|
|
4159
5170
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
4160
5171
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
4161
5172
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
@@ -4368,16 +5379,22 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4368
5379
|
}
|
|
4369
5380
|
}
|
|
4370
5381
|
};
|
|
4371
|
-
InlineAgentRunner =
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
5382
|
+
InlineAgentRunner = _ts_decorate25([
|
|
5383
|
+
Injectable11(),
|
|
5384
|
+
_ts_param23(0, Inject23(AGENT_DEPS_FACTORY6)),
|
|
5385
|
+
_ts_param23(1, Inject23(AGENT_STORE6)),
|
|
5386
|
+
_ts_param23(2, Optional10()),
|
|
5387
|
+
_ts_metadata24("design:type", Function),
|
|
5388
|
+
_ts_metadata24("design:paramtypes", [
|
|
4377
5389
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
4378
|
-
typeof AgentStore === "undefined" ? Object : AgentStore
|
|
5390
|
+
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
5391
|
+
typeof ChatQueueService === "undefined" ? Object : ChatQueueService
|
|
4379
5392
|
])
|
|
4380
5393
|
], InlineAgentRunner);
|
|
5394
|
+
function isThreadTurn2(input) {
|
|
5395
|
+
return input.sinkRunId === void 0 && input.deliverTo === void 0;
|
|
5396
|
+
}
|
|
5397
|
+
__name(isThreadTurn2, "isThreadTurn");
|
|
4381
5398
|
|
|
4382
5399
|
// src/skills-config.ts
|
|
4383
5400
|
import { compositeSkillProvider } from "@dudousxd/nestjs-agent-core";
|
|
@@ -4418,7 +5435,7 @@ function resolveSkillsConfig(options, declared) {
|
|
|
4418
5435
|
__name(resolveSkillsConfig, "resolveSkillsConfig");
|
|
4419
5436
|
|
|
4420
5437
|
// src/agent.module.ts
|
|
4421
|
-
function
|
|
5438
|
+
function _ts_decorate26(decorators, target, key, desc) {
|
|
4422
5439
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4423
5440
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
4424
5441
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -4431,13 +5448,13 @@ function _ts_decorate24(decorators, target, key, desc) {
|
|
|
4431
5448
|
}
|
|
4432
5449
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4433
5450
|
}
|
|
4434
|
-
__name(
|
|
5451
|
+
__name(_ts_decorate26, "_ts_decorate");
|
|
4435
5452
|
var DEFAULT_PATH = "agent";
|
|
4436
|
-
var logger = new
|
|
5453
|
+
var logger = new Logger7("AgentModule");
|
|
4437
5454
|
function externalStoreWrapper(modules) {
|
|
4438
5455
|
for (const module of modules.values()) {
|
|
4439
5456
|
if (module.metatype === AgentModule) continue;
|
|
4440
|
-
const wrapper = module.providers.get(
|
|
5457
|
+
const wrapper = module.providers.get(AGENT_STORE7);
|
|
4441
5458
|
if (wrapper !== void 0) return wrapper;
|
|
4442
5459
|
}
|
|
4443
5460
|
return void 0;
|
|
@@ -4510,7 +5527,7 @@ function sharedProviders(durable) {
|
|
|
4510
5527
|
provide: AGENT_SKILLS3,
|
|
4511
5528
|
useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
|
|
4512
5529
|
inject: [
|
|
4513
|
-
|
|
5530
|
+
AGENT_OPTIONS7,
|
|
4514
5531
|
AGENT_SKILL_SOURCES2
|
|
4515
5532
|
]
|
|
4516
5533
|
},
|
|
@@ -4520,58 +5537,58 @@ function sharedProviders(durable) {
|
|
|
4520
5537
|
provide: AGENT_MEMORY3,
|
|
4521
5538
|
useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
|
|
4522
5539
|
inject: [
|
|
4523
|
-
|
|
5540
|
+
AGENT_OPTIONS7
|
|
4524
5541
|
]
|
|
4525
5542
|
},
|
|
4526
5543
|
{
|
|
4527
|
-
provide:
|
|
5544
|
+
provide: AGENT_SINK4,
|
|
4528
5545
|
useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
|
|
4529
5546
|
inject: [
|
|
4530
|
-
|
|
5547
|
+
AGENT_OPTIONS7
|
|
4531
5548
|
]
|
|
4532
5549
|
},
|
|
4533
5550
|
{
|
|
4534
5551
|
provide: AGENT_ROLES_POLICY2,
|
|
4535
5552
|
useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new DefaultRolesPolicy(options.defaultRoles), "useFactory"),
|
|
4536
5553
|
inject: [
|
|
4537
|
-
|
|
5554
|
+
AGENT_OPTIONS7
|
|
4538
5555
|
]
|
|
4539
5556
|
},
|
|
4540
5557
|
{
|
|
4541
|
-
provide:
|
|
5558
|
+
provide: AGENT_ACTOR_RESOLVER13,
|
|
4542
5559
|
useFactory: /* @__PURE__ */ __name((options) => {
|
|
4543
5560
|
if (options.actorResolver !== void 0) return options.actorResolver;
|
|
4544
5561
|
logger.warn("No `actorResolver` configured \u2014 the agent endpoints are PUBLIC: every browser gets its own anonymous identity (an HttpOnly cookie). Set `actorResolver: requestUserActorResolver()` (or your own) to require login.");
|
|
4545
5562
|
return new AnonymousActorResolver();
|
|
4546
5563
|
}, "useFactory"),
|
|
4547
5564
|
inject: [
|
|
4548
|
-
|
|
5565
|
+
AGENT_OPTIONS7
|
|
4549
5566
|
]
|
|
4550
5567
|
},
|
|
4551
5568
|
{
|
|
4552
5569
|
provide: AGENT_MODEL2,
|
|
4553
5570
|
useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
|
|
4554
5571
|
inject: [
|
|
4555
|
-
|
|
5572
|
+
AGENT_OPTIONS7
|
|
4556
5573
|
]
|
|
4557
5574
|
},
|
|
4558
5575
|
{
|
|
4559
5576
|
// `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
|
|
4560
5577
|
// omitted, the ledger provider still reports usage, with no ceiling to block on.
|
|
4561
|
-
provide:
|
|
5578
|
+
provide: AGENT_QUOTA_PROVIDER3,
|
|
4562
5579
|
useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
|
|
4563
5580
|
warnAt: o.quota.warnAt
|
|
4564
5581
|
} : {}), "useFactory"),
|
|
4565
5582
|
inject: [
|
|
4566
|
-
|
|
4567
|
-
|
|
5583
|
+
AGENT_OPTIONS7,
|
|
5584
|
+
AGENT_STORE7
|
|
4568
5585
|
]
|
|
4569
5586
|
},
|
|
4570
5587
|
{
|
|
4571
5588
|
provide: AGENT_MODEL_CATALOG3,
|
|
4572
5589
|
useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
|
|
4573
5590
|
inject: [
|
|
4574
|
-
|
|
5591
|
+
AGENT_OPTIONS7
|
|
4575
5592
|
]
|
|
4576
5593
|
},
|
|
4577
5594
|
AgentDepsFactory2,
|
|
@@ -4584,6 +5601,9 @@ function sharedProviders(durable) {
|
|
|
4584
5601
|
AgentDiscoveryService,
|
|
4585
5602
|
AiToolDiscoveryService,
|
|
4586
5603
|
SkillDiscoveryService,
|
|
5604
|
+
// The thread message queue — every surface, since both runners and the durable workflow settle
|
|
5605
|
+
// into it, and the chat routes enqueue into it.
|
|
5606
|
+
ChatQueueService,
|
|
4587
5607
|
InlineAgentRunner,
|
|
4588
5608
|
AgentService,
|
|
4589
5609
|
// Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
|
|
@@ -4595,10 +5615,10 @@ function sharedProviders(durable) {
|
|
|
4595
5615
|
}
|
|
4596
5616
|
];
|
|
4597
5617
|
providers.push({
|
|
4598
|
-
provide:
|
|
5618
|
+
provide: AGENT_STORE7,
|
|
4599
5619
|
useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
|
|
4600
5620
|
inject: [
|
|
4601
|
-
|
|
5621
|
+
AGENT_OPTIONS7,
|
|
4602
5622
|
ModulesContainer
|
|
4603
5623
|
]
|
|
4604
5624
|
});
|
|
@@ -4629,22 +5649,23 @@ function sharedProviders(durable) {
|
|
|
4629
5649
|
__name(sharedProviders, "sharedProviders");
|
|
4630
5650
|
function exportsFor() {
|
|
4631
5651
|
return [
|
|
4632
|
-
|
|
5652
|
+
AGENT_OPTIONS7,
|
|
4633
5653
|
AGENT_TOOL_REGISTRY3,
|
|
4634
5654
|
AGENT_REGISTRY6,
|
|
4635
|
-
|
|
5655
|
+
AGENT_SINK4,
|
|
4636
5656
|
AGENT_ROLES_POLICY2,
|
|
4637
|
-
|
|
5657
|
+
AGENT_ACTOR_RESOLVER13,
|
|
4638
5658
|
AGENT_MODEL2,
|
|
4639
|
-
|
|
5659
|
+
AGENT_STORE7,
|
|
4640
5660
|
AGENT_MODEL_CATALOG3,
|
|
4641
|
-
|
|
5661
|
+
AGENT_QUOTA_PROVIDER3,
|
|
4642
5662
|
AGENT_PROMPT_CONTRIBUTORS3,
|
|
4643
5663
|
AGENT_SKILLS3,
|
|
4644
5664
|
AGENT_MEMORY3,
|
|
4645
5665
|
AGENT_DEPS_FACTORY7,
|
|
4646
5666
|
AgentDepsFactory2,
|
|
4647
5667
|
AgentService,
|
|
5668
|
+
ChatQueueService,
|
|
4648
5669
|
InlineAgentRunner,
|
|
4649
5670
|
AGENT_APPROVAL_PORT
|
|
4650
5671
|
];
|
|
@@ -4652,6 +5673,7 @@ function exportsFor() {
|
|
|
4652
5673
|
__name(exportsFor, "exportsFor");
|
|
4653
5674
|
var BASE_CONTROLLERS = [
|
|
4654
5675
|
ChatController,
|
|
5676
|
+
QueueController,
|
|
4655
5677
|
ThreadsController,
|
|
4656
5678
|
ToolCallController,
|
|
4657
5679
|
QuotaController,
|
|
@@ -4709,7 +5731,7 @@ var AgentModule = class _AgentModule {
|
|
|
4709
5731
|
controllers: controllersForSurface(options.surface),
|
|
4710
5732
|
providers: [
|
|
4711
5733
|
{
|
|
4712
|
-
provide:
|
|
5734
|
+
provide: AGENT_OPTIONS7,
|
|
4713
5735
|
useValue: options
|
|
4714
5736
|
},
|
|
4715
5737
|
...sharedProviders(options.durable ?? false),
|
|
@@ -4732,7 +5754,7 @@ var AgentModule = class _AgentModule {
|
|
|
4732
5754
|
controllers: controllersForSurface(options.surface),
|
|
4733
5755
|
providers: [
|
|
4734
5756
|
{
|
|
4735
|
-
provide:
|
|
5757
|
+
provide: AGENT_OPTIONS7,
|
|
4736
5758
|
// Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
|
|
4737
5759
|
// authoritative on the async config object (they decided the actual wiring above), and
|
|
4738
5760
|
// the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
|
|
@@ -4753,7 +5775,7 @@ var AgentModule = class _AgentModule {
|
|
|
4753
5775
|
};
|
|
4754
5776
|
}
|
|
4755
5777
|
};
|
|
4756
|
-
AgentModule =
|
|
5778
|
+
AgentModule = _ts_decorate26([
|
|
4757
5779
|
Global2(),
|
|
4758
5780
|
Module2({})
|
|
4759
5781
|
], AgentModule);
|