@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.
@@ -1,7 +1,7 @@
1
1
  import { a as Catalog, J as JsonSchema, G as GenuiValidation, b as GenuiIssue } from '../catalog-CrzetM3_.cjs';
2
2
  export { A as AjvLike, c as COMPONENT_NAME, d as CatalogOptions, C as ComponentDefinition, e as JsonSchemaValidator, P as PropsSchema, f as ajvValidator, g as builtinJsonSchemaValidator, h as defineCatalog, i as defineComponent, j as formatIssues, k as isStandardSchema, t as toJsonSchema, l as toSnakeCase, m as toolNameFor, v as validateProps, n as validatePropsSync } from '../catalog-CrzetM3_.cjs';
3
3
  import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
4
- import { A as Actor, T as ToolSpec, a as ToolHandler, b as ToolPresentation } from '../tool-B0J4Fjyd.cjs';
4
+ import { A as Actor, T as ToolSpec, a as ToolHandler, b as ToolPresentation } from '../tool-BhhzEI40.cjs';
5
5
 
6
6
  /**
7
7
  * One node of a composed UI: a catalog component, its props, and — for components declared with
@@ -1,7 +1,7 @@
1
1
  import { a as Catalog, J as JsonSchema, G as GenuiValidation, b as GenuiIssue } from '../catalog-CrzetM3_.js';
2
2
  export { A as AjvLike, c as COMPONENT_NAME, d as CatalogOptions, C as ComponentDefinition, e as JsonSchemaValidator, P as PropsSchema, f as ajvValidator, g as builtinJsonSchemaValidator, h as defineCatalog, i as defineComponent, j as formatIssues, k as isStandardSchema, t as toJsonSchema, l as toSnakeCase, m as toolNameFor, v as validateProps, n as validatePropsSync } from '../catalog-CrzetM3_.js';
3
3
  import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
4
- import { A as Actor, T as ToolSpec, a as ToolHandler, b as ToolPresentation } from '../tool-B0J4Fjyd.js';
4
+ import { A as Actor, T as ToolSpec, a as ToolHandler, b as ToolPresentation } from '../tool-BhhzEI40.js';
5
5
 
6
6
  /**
7
7
  * One node of a composed UI: a catalog component, its props, and — for components declared with
@@ -1,5 +1,5 @@
1
- import { I as InputProcessor, O as OutputProcessor } from '../processors-DdnRmmlq.cjs';
2
- import { A as Actor, a as ToolHandler } from '../tool-B0J4Fjyd.cjs';
1
+ import { I as InputProcessor, O as OutputProcessor } from '../processors-DQJ5sWw7.cjs';
2
+ import { A as Actor, a as ToolHandler } from '../tool-BhhzEI40.cjs';
3
3
  import '@standard-schema/spec';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { I as InputProcessor, O as OutputProcessor } from '../processors-C3Qx3ZdF.js';
2
- import { A as Actor, a as ToolHandler } from '../tool-B0J4Fjyd.js';
1
+ import { I as InputProcessor, O as OutputProcessor } from '../processors-BIVqOR1Q.js';
2
+ import { A as Actor, a as ToolHandler } from '../tool-BhhzEI40.js';
3
3
  import '@standard-schema/spec';
4
4
 
5
5
  /**
package/dist/index.cjs CHANGED
@@ -123,6 +123,7 @@ __export(src_exports, {
123
123
  gateFollowUps: () => gateFollowUps,
124
124
  gateTail: () => gateTail,
125
125
  invokeWithTransientRetry: () => invokeWithTransientRetry,
126
+ isChatQueueStore: () => isChatQueueStore,
126
127
  isControlFlowSignal: () => isControlFlowSignal,
127
128
  isReplayIntegrityError: () => isReplayIntegrityError,
128
129
  isToolEnabled: () => isToolEnabled,
@@ -151,12 +152,14 @@ __export(src_exports, {
151
152
  publishAgentToolCall: () => publishAgentToolCall,
152
153
  publishAgentToolRetry: () => publishAgentToolRetry,
153
154
  questionOptions: () => questionOptions,
155
+ queuedMessageView: () => queuedMessageView,
154
156
  quotaPeriodRange: () => quotaPeriodRange,
155
157
  quotaUsedRatio: () => quotaUsedRatio,
156
158
  quotaWarning: () => quotaWarning,
157
159
  readElicitationInput: () => readElicitationInput,
158
160
  readElicitationQuestions: () => readElicitationQuestions,
159
161
  releaseGatedFrames: () => releaseGatedFrames,
162
+ releaseThreadRun: () => releaseThreadRun,
160
163
  rememberInputSchema: () => rememberInputSchema,
161
164
  rememberToolDefinition: () => rememberToolDefinition,
162
165
  renderElicitationAnswers: () => renderElicitationAnswers,
@@ -494,6 +497,56 @@ __name(mergeUi, "mergeUi");
494
497
  // src/tool-presentation.ts
495
498
  var ALL_AGENTS = "*";
496
499
 
500
+ // src/spi/chat-queue.ts
501
+ var CHAT_QUEUE_METHODS = [
502
+ "enqueueMessage",
503
+ "listQueue",
504
+ "getQueuedMessage",
505
+ "updateQueuedMessage",
506
+ "moveQueuedMessage",
507
+ "removeQueuedMessage",
508
+ "clearQueue",
509
+ "queuePause",
510
+ "setQueuePause",
511
+ "activeRunForThread",
512
+ "claimActiveStream",
513
+ "releaseActiveStream"
514
+ ];
515
+ function isChatQueueStore(store) {
516
+ const candidate = store;
517
+ return CHAT_QUEUE_METHODS.every((method) => typeof candidate[method] === "function");
518
+ }
519
+ __name(isChatQueueStore, "isChatQueueStore");
520
+ async function releaseThreadRun(store, threadId, runId) {
521
+ if (isChatQueueStore(store)) {
522
+ await store.releaseActiveStream(threadId, runId);
523
+ return;
524
+ }
525
+ await store.setActiveStream(threadId, null);
526
+ }
527
+ __name(releaseThreadRun, "releaseThreadRun");
528
+ function queuedMessageView(message) {
529
+ return {
530
+ id: message.id,
531
+ content: message.content,
532
+ ...message.attachments !== void 0 && message.attachments.length > 0 ? {
533
+ attachments: message.attachments
534
+ } : {},
535
+ ...message.agentName !== void 0 ? {
536
+ agentName: message.agentName
537
+ } : {},
538
+ ...message.model !== void 0 ? {
539
+ model: message.model
540
+ } : {},
541
+ ...message.interrupt === true ? {
542
+ interrupt: true
543
+ } : {},
544
+ createdAt: message.createdAt,
545
+ updatedAt: message.updatedAt
546
+ };
547
+ }
548
+ __name(queuedMessageView, "queuedMessageView");
549
+
497
550
  // src/spi/quota-provider.ts
498
551
  function exhaustedWindow(windows) {
499
552
  for (const window of windows) {
@@ -4884,6 +4937,9 @@ var InMemoryAgentStore = class {
4884
4937
  __name(this, "InMemoryAgentStore");
4885
4938
  }
4886
4939
  threads = /* @__PURE__ */ new Map();
4940
+ /** Each thread's waiting messages, in run order. */
4941
+ queues = /* @__PURE__ */ new Map();
4942
+ pauses = /* @__PURE__ */ new Map();
4887
4943
  toolCalls = /* @__PURE__ */ new Map();
4888
4944
  usage = [];
4889
4945
  runs = /* @__PURE__ */ new Map();
@@ -5140,6 +5196,142 @@ var InMemoryAgentStore = class {
5140
5196
  }
5141
5197
  }
5142
5198
  }
5199
+ async claimActiveStream(threadId, runId, options = {}) {
5200
+ const row = this.threads.get(threadId);
5201
+ if (row === void 0) {
5202
+ return false;
5203
+ }
5204
+ const holder = row.activeStreamId;
5205
+ if (holder !== void 0 && holder !== runId && holder !== options.replacing) {
5206
+ return false;
5207
+ }
5208
+ row.activeStreamId = runId;
5209
+ return true;
5210
+ }
5211
+ async releaseActiveStream(threadId, runId) {
5212
+ const row = this.threads.get(threadId);
5213
+ if (row?.activeStreamId !== runId) {
5214
+ return false;
5215
+ }
5216
+ delete row.activeStreamId;
5217
+ return true;
5218
+ }
5219
+ async enqueueMessage(input) {
5220
+ const ts = this.now();
5221
+ const message = {
5222
+ id: crypto.randomUUID(),
5223
+ threadId: input.threadId,
5224
+ actor: input.actor,
5225
+ content: input.content,
5226
+ ...input.attachments !== void 0 && input.attachments.length > 0 ? {
5227
+ attachments: input.attachments
5228
+ } : {},
5229
+ ...input.agentName !== void 0 ? {
5230
+ agentName: input.agentName
5231
+ } : {},
5232
+ ...input.model !== void 0 ? {
5233
+ model: input.model
5234
+ } : {},
5235
+ ...input.pageContext !== void 0 ? {
5236
+ pageContext: input.pageContext
5237
+ } : {},
5238
+ ...input.interrupt === true ? {
5239
+ interrupt: true
5240
+ } : {},
5241
+ createdAt: ts,
5242
+ updatedAt: ts
5243
+ };
5244
+ const queue = this.queues.get(input.threadId) ?? [];
5245
+ if (input.at === "head") {
5246
+ queue.unshift(message);
5247
+ } else {
5248
+ queue.push(message);
5249
+ }
5250
+ this.queues.set(input.threadId, queue);
5251
+ return {
5252
+ ...message
5253
+ };
5254
+ }
5255
+ async listQueue(threadId) {
5256
+ return (this.queues.get(threadId) ?? []).map((message) => ({
5257
+ ...message
5258
+ }));
5259
+ }
5260
+ async getQueuedMessage(id) {
5261
+ const found = this.findQueued(id);
5262
+ return found === void 0 ? null : {
5263
+ ...found.message
5264
+ };
5265
+ }
5266
+ async updateQueuedMessage(id, patch) {
5267
+ const found = this.findQueued(id);
5268
+ if (found === void 0) {
5269
+ return null;
5270
+ }
5271
+ const { message } = found;
5272
+ if (patch.content !== void 0) {
5273
+ message.content = patch.content;
5274
+ }
5275
+ if (patch.attachments !== void 0) {
5276
+ if (patch.attachments === null || patch.attachments.length === 0) {
5277
+ delete message.attachments;
5278
+ } else {
5279
+ message.attachments = patch.attachments;
5280
+ }
5281
+ }
5282
+ message.updatedAt = this.now();
5283
+ return {
5284
+ ...message
5285
+ };
5286
+ }
5287
+ async moveQueuedMessage(id, index) {
5288
+ const found = this.findQueued(id);
5289
+ if (found === void 0) {
5290
+ return false;
5291
+ }
5292
+ const { queue, position, message } = found;
5293
+ queue.splice(position, 1);
5294
+ const target = Math.max(0, Math.min(queue.length, Math.trunc(index)));
5295
+ queue.splice(target, 0, message);
5296
+ return true;
5297
+ }
5298
+ async removeQueuedMessage(id) {
5299
+ const found = this.findQueued(id);
5300
+ if (found === void 0) {
5301
+ return false;
5302
+ }
5303
+ found.queue.splice(found.position, 1);
5304
+ return true;
5305
+ }
5306
+ async clearQueue(threadId) {
5307
+ const count = this.queues.get(threadId)?.length ?? 0;
5308
+ this.queues.delete(threadId);
5309
+ return count;
5310
+ }
5311
+ async queuePause(threadId) {
5312
+ return this.pauses.get(threadId) ?? null;
5313
+ }
5314
+ async setQueuePause(threadId, pause) {
5315
+ if (pause === null) {
5316
+ this.pauses.delete(threadId);
5317
+ } else {
5318
+ this.pauses.set(threadId, pause);
5319
+ }
5320
+ }
5321
+ findQueued(id) {
5322
+ for (const queue of this.queues.values()) {
5323
+ const position = queue.findIndex((message2) => message2.id === id);
5324
+ const message = queue[position];
5325
+ if (message !== void 0) {
5326
+ return {
5327
+ queue,
5328
+ position,
5329
+ message
5330
+ };
5331
+ }
5332
+ }
5333
+ return void 0;
5334
+ }
5143
5335
  async appendMessage(input) {
5144
5336
  const row = this.threads.get(input.threadId);
5145
5337
  if (row === void 0) {
@@ -5657,6 +5849,7 @@ var InMemoryAgentStore = class {
5657
5849
  gateFollowUps,
5658
5850
  gateTail,
5659
5851
  invokeWithTransientRetry,
5852
+ isChatQueueStore,
5660
5853
  isControlFlowSignal,
5661
5854
  isReplayIntegrityError,
5662
5855
  isToolEnabled,
@@ -5685,12 +5878,14 @@ var InMemoryAgentStore = class {
5685
5878
  publishAgentToolCall,
5686
5879
  publishAgentToolRetry,
5687
5880
  questionOptions,
5881
+ queuedMessageView,
5688
5882
  quotaPeriodRange,
5689
5883
  quotaUsedRatio,
5690
5884
  quotaWarning,
5691
5885
  readElicitationInput,
5692
5886
  readElicitationQuestions,
5693
5887
  releaseGatedFrames,
5888
+ releaseThreadRun,
5694
5889
  rememberInputSchema,
5695
5890
  rememberToolDefinition,
5696
5891
  renderElicitationAnswers,