@dudousxd/nestjs-agent-core 0.30.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-CfnSyIQf.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-CfnSyIQf.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-DdwZ0NFG.cjs';
2
- import { A as Actor, a as ToolHandler } from '../tool-CfnSyIQf.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-8c9g9J6R.js';
2
- import { A as Actor, a as ToolHandler } from '../tool-CfnSyIQf.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
@@ -48,6 +48,7 @@ __export(src_exports, {
48
48
  AGENT_SPAN_EVENTS: () => AGENT_SPAN_EVENTS,
49
49
  AGENT_STORE: () => AGENT_STORE,
50
50
  AGENT_TOOL_REGISTRY: () => AGENT_TOOL_REGISTRY,
51
+ ALL_AGENTS: () => ALL_AGENTS,
51
52
  APPROVAL_EXPIRED_REASON: () => APPROVAL_EXPIRED_REASON,
52
53
  ASK_TOOL_DESCRIPTION: () => ASK_TOOL_DESCRIPTION,
53
54
  ASK_TOOL_NAME: () => ASK_TOOL_NAME,
@@ -122,6 +123,7 @@ __export(src_exports, {
122
123
  gateFollowUps: () => gateFollowUps,
123
124
  gateTail: () => gateTail,
124
125
  invokeWithTransientRetry: () => invokeWithTransientRetry,
126
+ isChatQueueStore: () => isChatQueueStore,
125
127
  isControlFlowSignal: () => isControlFlowSignal,
126
128
  isReplayIntegrityError: () => isReplayIntegrityError,
127
129
  isToolEnabled: () => isToolEnabled,
@@ -150,12 +152,14 @@ __export(src_exports, {
150
152
  publishAgentToolCall: () => publishAgentToolCall,
151
153
  publishAgentToolRetry: () => publishAgentToolRetry,
152
154
  questionOptions: () => questionOptions,
155
+ queuedMessageView: () => queuedMessageView,
153
156
  quotaPeriodRange: () => quotaPeriodRange,
154
157
  quotaUsedRatio: () => quotaUsedRatio,
155
158
  quotaWarning: () => quotaWarning,
156
159
  readElicitationInput: () => readElicitationInput,
157
160
  readElicitationQuestions: () => readElicitationQuestions,
158
161
  releaseGatedFrames: () => releaseGatedFrames,
162
+ releaseThreadRun: () => releaseThreadRun,
159
163
  rememberInputSchema: () => rememberInputSchema,
160
164
  rememberToolDefinition: () => rememberToolDefinition,
161
165
  renderElicitationAnswers: () => renderElicitationAnswers,
@@ -490,6 +494,59 @@ function mergeUi(...lists) {
490
494
  }
491
495
  __name(mergeUi, "mergeUi");
492
496
 
497
+ // src/tool-presentation.ts
498
+ var ALL_AGENTS = "*";
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
+
493
550
  // src/spi/quota-provider.ts
494
551
  function exhaustedWindow(windows) {
495
552
  for (const window of windows) {
@@ -4880,6 +4937,9 @@ var InMemoryAgentStore = class {
4880
4937
  __name(this, "InMemoryAgentStore");
4881
4938
  }
4882
4939
  threads = /* @__PURE__ */ new Map();
4940
+ /** Each thread's waiting messages, in run order. */
4941
+ queues = /* @__PURE__ */ new Map();
4942
+ pauses = /* @__PURE__ */ new Map();
4883
4943
  toolCalls = /* @__PURE__ */ new Map();
4884
4944
  usage = [];
4885
4945
  runs = /* @__PURE__ */ new Map();
@@ -5136,6 +5196,142 @@ var InMemoryAgentStore = class {
5136
5196
  }
5137
5197
  }
5138
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
+ }
5139
5335
  async appendMessage(input) {
5140
5336
  const row = this.threads.get(input.threadId);
5141
5337
  if (row === void 0) {
@@ -5578,6 +5774,7 @@ var InMemoryAgentStore = class {
5578
5774
  AGENT_SPAN_EVENTS,
5579
5775
  AGENT_STORE,
5580
5776
  AGENT_TOOL_REGISTRY,
5777
+ ALL_AGENTS,
5581
5778
  APPROVAL_EXPIRED_REASON,
5582
5779
  ASK_TOOL_DESCRIPTION,
5583
5780
  ASK_TOOL_NAME,
@@ -5652,6 +5849,7 @@ var InMemoryAgentStore = class {
5652
5849
  gateFollowUps,
5653
5850
  gateTail,
5654
5851
  invokeWithTransientRetry,
5852
+ isChatQueueStore,
5655
5853
  isControlFlowSignal,
5656
5854
  isReplayIntegrityError,
5657
5855
  isToolEnabled,
@@ -5680,12 +5878,14 @@ var InMemoryAgentStore = class {
5680
5878
  publishAgentToolCall,
5681
5879
  publishAgentToolRetry,
5682
5880
  questionOptions,
5881
+ queuedMessageView,
5683
5882
  quotaPeriodRange,
5684
5883
  quotaUsedRatio,
5685
5884
  quotaWarning,
5686
5885
  readElicitationInput,
5687
5886
  readElicitationQuestions,
5688
5887
  releaseGatedFrames,
5888
+ releaseThreadRun,
5689
5889
  rememberInputSchema,
5690
5890
  rememberToolDefinition,
5691
5891
  renderElicitationAnswers,