@dudousxd/nestjs-agent-core 0.31.0 → 0.32.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 +195 -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 +192 -0
- package/dist/index.js.map +1 -1
- package/dist/{processors-C3Qx3ZdF.d.ts → processors-BIVqOR1Q.d.ts} +1 -1
- package/dist/{processors-DdnRmmlq.d.cts → processors-DQJ5sWw7.d.cts} +1 -1
- package/dist/{tool-B0J4Fjyd.d.cts → tool-BhhzEI40.d.cts} +576 -97
- package/dist/{tool-B0J4Fjyd.d.ts → tool-BhhzEI40.d.ts} +576 -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,142 @@ 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
|
+
message.updatedAt = this.now();
|
|
5078
|
+
return {
|
|
5079
|
+
...message
|
|
5080
|
+
};
|
|
5081
|
+
}
|
|
5082
|
+
async moveQueuedMessage(id, index) {
|
|
5083
|
+
const found = this.findQueued(id);
|
|
5084
|
+
if (found === void 0) {
|
|
5085
|
+
return false;
|
|
5086
|
+
}
|
|
5087
|
+
const { queue, position, message } = found;
|
|
5088
|
+
queue.splice(position, 1);
|
|
5089
|
+
const target = Math.max(0, Math.min(queue.length, Math.trunc(index)));
|
|
5090
|
+
queue.splice(target, 0, message);
|
|
5091
|
+
return true;
|
|
5092
|
+
}
|
|
5093
|
+
async removeQueuedMessage(id) {
|
|
5094
|
+
const found = this.findQueued(id);
|
|
5095
|
+
if (found === void 0) {
|
|
5096
|
+
return false;
|
|
5097
|
+
}
|
|
5098
|
+
found.queue.splice(found.position, 1);
|
|
5099
|
+
return true;
|
|
5100
|
+
}
|
|
5101
|
+
async clearQueue(threadId) {
|
|
5102
|
+
const count = this.queues.get(threadId)?.length ?? 0;
|
|
5103
|
+
this.queues.delete(threadId);
|
|
5104
|
+
return count;
|
|
5105
|
+
}
|
|
5106
|
+
async queuePause(threadId) {
|
|
5107
|
+
return this.pauses.get(threadId) ?? null;
|
|
5108
|
+
}
|
|
5109
|
+
async setQueuePause(threadId, pause) {
|
|
5110
|
+
if (pause === null) {
|
|
5111
|
+
this.pauses.delete(threadId);
|
|
5112
|
+
} else {
|
|
5113
|
+
this.pauses.set(threadId, pause);
|
|
5114
|
+
}
|
|
5115
|
+
}
|
|
5116
|
+
findQueued(id) {
|
|
5117
|
+
for (const queue of this.queues.values()) {
|
|
5118
|
+
const position = queue.findIndex((message2) => message2.id === id);
|
|
5119
|
+
const message = queue[position];
|
|
5120
|
+
if (message !== void 0) {
|
|
5121
|
+
return {
|
|
5122
|
+
queue,
|
|
5123
|
+
position,
|
|
5124
|
+
message
|
|
5125
|
+
};
|
|
5126
|
+
}
|
|
5127
|
+
}
|
|
5128
|
+
return void 0;
|
|
5129
|
+
}
|
|
4941
5130
|
async appendMessage(input) {
|
|
4942
5131
|
const row = this.threads.get(input.threadId);
|
|
4943
5132
|
if (row === void 0) {
|
|
@@ -5454,6 +5643,7 @@ export {
|
|
|
5454
5643
|
gateFollowUps,
|
|
5455
5644
|
gateTail,
|
|
5456
5645
|
invokeWithTransientRetry,
|
|
5646
|
+
isChatQueueStore,
|
|
5457
5647
|
isControlFlowSignal,
|
|
5458
5648
|
isReplayIntegrityError,
|
|
5459
5649
|
isToolEnabled,
|
|
@@ -5482,12 +5672,14 @@ export {
|
|
|
5482
5672
|
publishAgentToolCall,
|
|
5483
5673
|
publishAgentToolRetry,
|
|
5484
5674
|
questionOptions,
|
|
5675
|
+
queuedMessageView,
|
|
5485
5676
|
quotaPeriodRange,
|
|
5486
5677
|
quotaUsedRatio,
|
|
5487
5678
|
quotaWarning,
|
|
5488
5679
|
readElicitationInput,
|
|
5489
5680
|
readElicitationQuestions,
|
|
5490
5681
|
releaseGatedFrames,
|
|
5682
|
+
releaseThreadRun,
|
|
5491
5683
|
rememberInputSchema,
|
|
5492
5684
|
rememberToolDefinition,
|
|
5493
5685
|
renderElicitationAnswers,
|