@dudousxd/nestjs-agent-core 0.31.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/genui/index.d.cts +1 -1
- package/dist/genui/index.d.ts +1 -1
- package/dist/guardrails/index.d.cts +2 -2
- package/dist/guardrails/index.d.ts +2 -2
- package/dist/index.cjs +202 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -333
- package/dist/index.d.ts +43 -333
- package/dist/index.js +199 -0
- package/dist/index.js.map +1 -1
- package/dist/{processors-C3Qx3ZdF.d.ts → processors-C1jir8eB.d.ts} +1 -1
- package/dist/{processors-DdnRmmlq.d.cts → processors-DvZDW5zS.d.cts} +1 -1
- package/dist/{tool-B0J4Fjyd.d.cts → tool-CMTuoJ2v.d.cts} +584 -97
- package/dist/{tool-B0J4Fjyd.d.ts → tool-CMTuoJ2v.d.ts} +584 -97
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -292,6 +292,56 @@ __name(mergeUi, "mergeUi");
|
|
|
292
292
|
// src/tool-presentation.ts
|
|
293
293
|
var ALL_AGENTS = "*";
|
|
294
294
|
|
|
295
|
+
// src/spi/chat-queue.ts
|
|
296
|
+
var CHAT_QUEUE_METHODS = [
|
|
297
|
+
"enqueueMessage",
|
|
298
|
+
"listQueue",
|
|
299
|
+
"getQueuedMessage",
|
|
300
|
+
"updateQueuedMessage",
|
|
301
|
+
"moveQueuedMessage",
|
|
302
|
+
"removeQueuedMessage",
|
|
303
|
+
"clearQueue",
|
|
304
|
+
"queuePause",
|
|
305
|
+
"setQueuePause",
|
|
306
|
+
"activeRunForThread",
|
|
307
|
+
"claimActiveStream",
|
|
308
|
+
"releaseActiveStream"
|
|
309
|
+
];
|
|
310
|
+
function isChatQueueStore(store) {
|
|
311
|
+
const candidate = store;
|
|
312
|
+
return CHAT_QUEUE_METHODS.every((method) => typeof candidate[method] === "function");
|
|
313
|
+
}
|
|
314
|
+
__name(isChatQueueStore, "isChatQueueStore");
|
|
315
|
+
async function releaseThreadRun(store, threadId, runId) {
|
|
316
|
+
if (isChatQueueStore(store)) {
|
|
317
|
+
await store.releaseActiveStream(threadId, runId);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
await store.setActiveStream(threadId, null);
|
|
321
|
+
}
|
|
322
|
+
__name(releaseThreadRun, "releaseThreadRun");
|
|
323
|
+
function queuedMessageView(message) {
|
|
324
|
+
return {
|
|
325
|
+
id: message.id,
|
|
326
|
+
content: message.content,
|
|
327
|
+
...message.attachments !== void 0 && message.attachments.length > 0 ? {
|
|
328
|
+
attachments: message.attachments
|
|
329
|
+
} : {},
|
|
330
|
+
...message.agentName !== void 0 ? {
|
|
331
|
+
agentName: message.agentName
|
|
332
|
+
} : {},
|
|
333
|
+
...message.model !== void 0 ? {
|
|
334
|
+
model: message.model
|
|
335
|
+
} : {},
|
|
336
|
+
...message.interrupt === true ? {
|
|
337
|
+
interrupt: true
|
|
338
|
+
} : {},
|
|
339
|
+
createdAt: message.createdAt,
|
|
340
|
+
updatedAt: message.updatedAt
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
__name(queuedMessageView, "queuedMessageView");
|
|
344
|
+
|
|
295
345
|
// src/spi/quota-provider.ts
|
|
296
346
|
function exhaustedWindow(windows) {
|
|
297
347
|
for (const window of windows) {
|
|
@@ -4682,6 +4732,9 @@ var InMemoryAgentStore = class {
|
|
|
4682
4732
|
__name(this, "InMemoryAgentStore");
|
|
4683
4733
|
}
|
|
4684
4734
|
threads = /* @__PURE__ */ new Map();
|
|
4735
|
+
/** Each thread's waiting messages, in run order. */
|
|
4736
|
+
queues = /* @__PURE__ */ new Map();
|
|
4737
|
+
pauses = /* @__PURE__ */ new Map();
|
|
4685
4738
|
toolCalls = /* @__PURE__ */ new Map();
|
|
4686
4739
|
usage = [];
|
|
4687
4740
|
runs = /* @__PURE__ */ new Map();
|
|
@@ -4938,6 +4991,149 @@ var InMemoryAgentStore = class {
|
|
|
4938
4991
|
}
|
|
4939
4992
|
}
|
|
4940
4993
|
}
|
|
4994
|
+
async claimActiveStream(threadId, runId, options = {}) {
|
|
4995
|
+
const row = this.threads.get(threadId);
|
|
4996
|
+
if (row === void 0) {
|
|
4997
|
+
return false;
|
|
4998
|
+
}
|
|
4999
|
+
const holder = row.activeStreamId;
|
|
5000
|
+
if (holder !== void 0 && holder !== runId && holder !== options.replacing) {
|
|
5001
|
+
return false;
|
|
5002
|
+
}
|
|
5003
|
+
row.activeStreamId = runId;
|
|
5004
|
+
return true;
|
|
5005
|
+
}
|
|
5006
|
+
async releaseActiveStream(threadId, runId) {
|
|
5007
|
+
const row = this.threads.get(threadId);
|
|
5008
|
+
if (row?.activeStreamId !== runId) {
|
|
5009
|
+
return false;
|
|
5010
|
+
}
|
|
5011
|
+
delete row.activeStreamId;
|
|
5012
|
+
return true;
|
|
5013
|
+
}
|
|
5014
|
+
async enqueueMessage(input) {
|
|
5015
|
+
const ts = this.now();
|
|
5016
|
+
const message = {
|
|
5017
|
+
id: crypto.randomUUID(),
|
|
5018
|
+
threadId: input.threadId,
|
|
5019
|
+
actor: input.actor,
|
|
5020
|
+
content: input.content,
|
|
5021
|
+
...input.attachments !== void 0 && input.attachments.length > 0 ? {
|
|
5022
|
+
attachments: input.attachments
|
|
5023
|
+
} : {},
|
|
5024
|
+
...input.agentName !== void 0 ? {
|
|
5025
|
+
agentName: input.agentName
|
|
5026
|
+
} : {},
|
|
5027
|
+
...input.model !== void 0 ? {
|
|
5028
|
+
model: input.model
|
|
5029
|
+
} : {},
|
|
5030
|
+
...input.pageContext !== void 0 ? {
|
|
5031
|
+
pageContext: input.pageContext
|
|
5032
|
+
} : {},
|
|
5033
|
+
...input.interrupt === true ? {
|
|
5034
|
+
interrupt: true
|
|
5035
|
+
} : {},
|
|
5036
|
+
createdAt: ts,
|
|
5037
|
+
updatedAt: ts
|
|
5038
|
+
};
|
|
5039
|
+
const queue = this.queues.get(input.threadId) ?? [];
|
|
5040
|
+
if (input.at === "head") {
|
|
5041
|
+
queue.unshift(message);
|
|
5042
|
+
} else {
|
|
5043
|
+
queue.push(message);
|
|
5044
|
+
}
|
|
5045
|
+
this.queues.set(input.threadId, queue);
|
|
5046
|
+
return {
|
|
5047
|
+
...message
|
|
5048
|
+
};
|
|
5049
|
+
}
|
|
5050
|
+
async listQueue(threadId) {
|
|
5051
|
+
return (this.queues.get(threadId) ?? []).map((message) => ({
|
|
5052
|
+
...message
|
|
5053
|
+
}));
|
|
5054
|
+
}
|
|
5055
|
+
async getQueuedMessage(id) {
|
|
5056
|
+
const found = this.findQueued(id);
|
|
5057
|
+
return found === void 0 ? null : {
|
|
5058
|
+
...found.message
|
|
5059
|
+
};
|
|
5060
|
+
}
|
|
5061
|
+
async updateQueuedMessage(id, patch) {
|
|
5062
|
+
const found = this.findQueued(id);
|
|
5063
|
+
if (found === void 0) {
|
|
5064
|
+
return null;
|
|
5065
|
+
}
|
|
5066
|
+
const { message } = found;
|
|
5067
|
+
if (patch.content !== void 0) {
|
|
5068
|
+
message.content = patch.content;
|
|
5069
|
+
}
|
|
5070
|
+
if (patch.attachments !== void 0) {
|
|
5071
|
+
if (patch.attachments === null || patch.attachments.length === 0) {
|
|
5072
|
+
delete message.attachments;
|
|
5073
|
+
} else {
|
|
5074
|
+
message.attachments = patch.attachments;
|
|
5075
|
+
}
|
|
5076
|
+
}
|
|
5077
|
+
if (patch.interrupt !== void 0) {
|
|
5078
|
+
if (patch.interrupt) {
|
|
5079
|
+
message.interrupt = true;
|
|
5080
|
+
} else {
|
|
5081
|
+
delete message.interrupt;
|
|
5082
|
+
}
|
|
5083
|
+
}
|
|
5084
|
+
message.updatedAt = this.now();
|
|
5085
|
+
return {
|
|
5086
|
+
...message
|
|
5087
|
+
};
|
|
5088
|
+
}
|
|
5089
|
+
async moveQueuedMessage(id, index) {
|
|
5090
|
+
const found = this.findQueued(id);
|
|
5091
|
+
if (found === void 0) {
|
|
5092
|
+
return false;
|
|
5093
|
+
}
|
|
5094
|
+
const { queue, position, message } = found;
|
|
5095
|
+
queue.splice(position, 1);
|
|
5096
|
+
const target = Math.max(0, Math.min(queue.length, Math.trunc(index)));
|
|
5097
|
+
queue.splice(target, 0, message);
|
|
5098
|
+
return true;
|
|
5099
|
+
}
|
|
5100
|
+
async removeQueuedMessage(id) {
|
|
5101
|
+
const found = this.findQueued(id);
|
|
5102
|
+
if (found === void 0) {
|
|
5103
|
+
return false;
|
|
5104
|
+
}
|
|
5105
|
+
found.queue.splice(found.position, 1);
|
|
5106
|
+
return true;
|
|
5107
|
+
}
|
|
5108
|
+
async clearQueue(threadId) {
|
|
5109
|
+
const count = this.queues.get(threadId)?.length ?? 0;
|
|
5110
|
+
this.queues.delete(threadId);
|
|
5111
|
+
return count;
|
|
5112
|
+
}
|
|
5113
|
+
async queuePause(threadId) {
|
|
5114
|
+
return this.pauses.get(threadId) ?? null;
|
|
5115
|
+
}
|
|
5116
|
+
async setQueuePause(threadId, pause) {
|
|
5117
|
+
if (pause === null) {
|
|
5118
|
+
this.pauses.delete(threadId);
|
|
5119
|
+
} else {
|
|
5120
|
+
this.pauses.set(threadId, pause);
|
|
5121
|
+
}
|
|
5122
|
+
}
|
|
5123
|
+
findQueued(id) {
|
|
5124
|
+
for (const queue of this.queues.values()) {
|
|
5125
|
+
const position = queue.findIndex((message2) => message2.id === id);
|
|
5126
|
+
const message = queue[position];
|
|
5127
|
+
if (message !== void 0) {
|
|
5128
|
+
return {
|
|
5129
|
+
queue,
|
|
5130
|
+
position,
|
|
5131
|
+
message
|
|
5132
|
+
};
|
|
5133
|
+
}
|
|
5134
|
+
}
|
|
5135
|
+
return void 0;
|
|
5136
|
+
}
|
|
4941
5137
|
async appendMessage(input) {
|
|
4942
5138
|
const row = this.threads.get(input.threadId);
|
|
4943
5139
|
if (row === void 0) {
|
|
@@ -5454,6 +5650,7 @@ export {
|
|
|
5454
5650
|
gateFollowUps,
|
|
5455
5651
|
gateTail,
|
|
5456
5652
|
invokeWithTransientRetry,
|
|
5653
|
+
isChatQueueStore,
|
|
5457
5654
|
isControlFlowSignal,
|
|
5458
5655
|
isReplayIntegrityError,
|
|
5459
5656
|
isToolEnabled,
|
|
@@ -5482,12 +5679,14 @@ export {
|
|
|
5482
5679
|
publishAgentToolCall,
|
|
5483
5680
|
publishAgentToolRetry,
|
|
5484
5681
|
questionOptions,
|
|
5682
|
+
queuedMessageView,
|
|
5485
5683
|
quotaPeriodRange,
|
|
5486
5684
|
quotaUsedRatio,
|
|
5487
5685
|
quotaWarning,
|
|
5488
5686
|
readElicitationInput,
|
|
5489
5687
|
readElicitationQuestions,
|
|
5490
5688
|
releaseGatedFrames,
|
|
5689
|
+
releaseThreadRun,
|
|
5491
5690
|
rememberInputSchema,
|
|
5492
5691
|
rememberToolDefinition,
|
|
5493
5692
|
renderElicitationAnswers,
|