@dudousxd/nestjs-agent 1.22.0 → 1.23.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/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit, ConflictException, OnModuleDestroy } from '@nestjs/common';
2
- import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter, e as AgentSkillsOptions } from './chat-queue.service-Dx9OsjcF.cjs';
3
- export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, j as QueueSettleOutcome, k as QueuedTurn, l as QueuedTurnStarter, m as QuotaLimits, n as QuotaWindowLimits, o as defineTool, p as delegateToolName, q as provideAgentTool, r as provideAgentTools, u as utcDay } from './chat-queue.service-Dx9OsjcF.cjs';
2
+ import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter, e as AgentSkillsOptions } from './chat-queue.service-D1z3WjFI.cjs';
3
+ export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentEngine, j as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, k as QueueSettleOutcome, l as QueuedTurn, m as QueuedTurnStarter, n as QuotaLimits, o as QuotaWindowLimits, p as defineTool, q as delegateToolName, r as provideAgentTool, s as provideAgentTools, u as utcDay } from './chat-queue.service-D1z3WjFI.cjs';
4
4
  import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
5
- import { AgentStore, Actor, ListActionProposals, ActionProposalMutationView, AgentRunner, AttachmentStagingStore, ModelCatalog, QuotaProvider, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver, AgentApprovalPort, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolSpec, ToolPresentation, AgentHistoryWindow, AgentIntake, Persona, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
5
+ import { AgentStore, Actor, ListActionProposals, ActionProposalMutationView, AgentRunner, AttachmentStagingStore, ModelCatalog, QuotaProvider, QuotaReport, ModelCatalogView, AgentHostContext, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver, AgentApprovalPort, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolSpec, ToolPresentation, AgentHistoryWindow, AgentIntake, Persona, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
6
6
  export * from '@dudousxd/nestjs-agent-core';
7
7
  export { FunctionalToolDefinition } from '@dudousxd/nestjs-agent-core';
8
8
  import { Request, Response } from 'express';
@@ -96,6 +96,14 @@ interface ChatParams {
96
96
  uiCapabilities?: UiCapabilities;
97
97
  actor: Actor;
98
98
  message: string;
99
+ /** The host's own facts about this send — see `AgentRunInput.hostContext`. */
100
+ hostContext?: AgentHostContext;
101
+ /**
102
+ * The HOST already decided this actor may write this thread — a chat-app thread several people
103
+ * share, where anyone in it may continue the conversation. Skips the thread-ownership check of a
104
+ * send; never set it from a request's own claim.
105
+ */
106
+ authorized?: boolean;
99
107
  threadId?: string;
100
108
  agentName?: string;
101
109
  /**
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit, ConflictException, OnModuleDestroy } from '@nestjs/common';
2
- import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter, e as AgentSkillsOptions } from './chat-queue.service-CTyX_yNr.js';
3
- export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, j as QueueSettleOutcome, k as QueuedTurn, l as QueuedTurnStarter, m as QuotaLimits, n as QuotaWindowLimits, o as defineTool, p as delegateToolName, q as provideAgentTool, r as provideAgentTools, u as utcDay } from './chat-queue.service-CTyX_yNr.js';
2
+ import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter, e as AgentSkillsOptions } from './chat-queue.service-CwxJDrBM.js';
3
+ export { f as AGENT_TOOL_BRAND, g as AgentAttachmentsOptions, h as AgentDeps, i as AgentEngine, j as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, k as QueueSettleOutcome, l as QueuedTurn, m as QueuedTurnStarter, n as QuotaLimits, o as QuotaWindowLimits, p as defineTool, q as delegateToolName, r as provideAgentTool, s as provideAgentTools, u as utcDay } from './chat-queue.service-CwxJDrBM.js';
4
4
  import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
5
- import { AgentStore, Actor, ListActionProposals, ActionProposalMutationView, AgentRunner, AttachmentStagingStore, ModelCatalog, QuotaProvider, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver, AgentApprovalPort, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolSpec, ToolPresentation, AgentHistoryWindow, AgentIntake, Persona, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
5
+ import { AgentStore, Actor, ListActionProposals, ActionProposalMutationView, AgentRunner, AttachmentStagingStore, ModelCatalog, QuotaProvider, QuotaReport, ModelCatalogView, AgentHostContext, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver, AgentApprovalPort, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolSpec, ToolPresentation, AgentHistoryWindow, AgentIntake, Persona, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
6
6
  export * from '@dudousxd/nestjs-agent-core';
7
7
  export { FunctionalToolDefinition } from '@dudousxd/nestjs-agent-core';
8
8
  import { Request, Response } from 'express';
@@ -96,6 +96,14 @@ interface ChatParams {
96
96
  uiCapabilities?: UiCapabilities;
97
97
  actor: Actor;
98
98
  message: string;
99
+ /** The host's own facts about this send — see `AgentRunInput.hostContext`. */
100
+ hostContext?: AgentHostContext;
101
+ /**
102
+ * The HOST already decided this actor may write this thread — a chat-app thread several people
103
+ * share, where anyone in it may continue the conversation. Skips the thread-ownership check of a
104
+ * send; never set it from a request's own claim.
105
+ */
106
+ authorized?: boolean;
99
107
  threadId?: string;
100
108
  agentName?: string;
101
109
  /**
package/dist/index.js CHANGED
@@ -1092,6 +1092,9 @@ var ChatQueueService = class _ChatQueueService {
1092
1092
  } : {},
1093
1093
  ...input.uiCapabilities !== void 0 ? {
1094
1094
  uiCapabilities: input.uiCapabilities
1095
+ } : {},
1096
+ ...input.hostContext !== void 0 ? {
1097
+ hostContext: input.hostContext
1095
1098
  } : {}
1096
1099
  });
1097
1100
  await store.setQueuePause(threadId, {
@@ -1177,6 +1180,9 @@ var ChatQueueService = class _ChatQueueService {
1177
1180
  ...message.uiCapabilities !== void 0 ? {
1178
1181
  uiCapabilities: message.uiCapabilities
1179
1182
  } : {},
1183
+ ...message.hostContext !== void 0 ? {
1184
+ hostContext: message.hostContext
1185
+ } : {},
1180
1186
  ...message.model !== void 0 ? {
1181
1187
  model: message.model
1182
1188
  } : {}
@@ -1547,6 +1553,9 @@ var AgentService = class {
1547
1553
  }
1548
1554
  const created = await this.store.createThread({
1549
1555
  actor: params.actor,
1556
+ ...agentName !== void 0 ? {
1557
+ agentName
1558
+ } : {},
1550
1559
  ...params.transient === true ? {
1551
1560
  transient: true
1552
1561
  } : {},
@@ -1559,7 +1568,7 @@ var AgentService = class {
1559
1568
  });
1560
1569
  threadId = created.id;
1561
1570
  } else {
1562
- await this.assertOwnsThread(params.actor, threadId);
1571
+ if (params.authorized !== true) await this.assertOwnsThread(params.actor, threadId);
1563
1572
  if (params.personaId !== void 0) {
1564
1573
  await this.pinThreadPersona(threadId, params.personaId);
1565
1574
  }
@@ -1585,6 +1594,9 @@ var AgentService = class {
1585
1594
  ...params.uiCapabilities !== void 0 ? {
1586
1595
  uiCapabilities: params.uiCapabilities
1587
1596
  } : {},
1597
+ ...params.hostContext !== void 0 ? {
1598
+ hostContext: params.hostContext
1599
+ } : {},
1588
1600
  ...model !== void 0 ? {
1589
1601
  model
1590
1602
  } : {}
@@ -1607,7 +1619,7 @@ var AgentService = class {
1607
1619
  });
1608
1620
  }
1609
1621
  if (live === null && mode !== "queue") {
1610
- const runId = crypto.randomUUID();
1622
+ const runId = this.runner.runIdFor?.(input) ?? crypto.randomUUID();
1611
1623
  if (await queue.queueStore().claimActiveStream(threadId, runId, stale !== null ? {
1612
1624
  replacing: stale
1613
1625
  } : {})) {
@@ -1675,6 +1687,9 @@ var AgentService = class {
1675
1687
  ...input.uiCapabilities !== void 0 ? {
1676
1688
  uiCapabilities: input.uiCapabilities
1677
1689
  } : {},
1690
+ ...input.hostContext !== void 0 ? {
1691
+ hostContext: input.hostContext
1692
+ } : {},
1678
1693
  ...interrupting !== void 0 ? {
1679
1694
  interrupt: true,
1680
1695
  at: "head"
@@ -5886,11 +5901,11 @@ function isQuotaProvider(quota) {
5886
5901
  __name(isQuotaProvider, "isQuotaProvider");
5887
5902
  function resolveCatalog(options) {
5888
5903
  if (options.models !== void 0) return options.models;
5889
- const carried = options.model.catalog;
5904
+ const carried = options.model?.catalog;
5890
5905
  return carried !== void 0 && typeof carried.list === "function" ? carried : void 0;
5891
5906
  }
5892
5907
  __name(resolveCatalog, "resolveCatalog");
5893
- function sharedProviders(durable) {
5908
+ function sharedProviders(durable, engine) {
5894
5909
  const providers = [
5895
5910
  {
5896
5911
  provide: AGENT_TOOL_REGISTRY3,
@@ -6021,7 +6036,12 @@ function sharedProviders(durable) {
6021
6036
  ModulesContainer
6022
6037
  ]
6023
6038
  });
6024
- if (durable) {
6039
+ if (engine !== void 0) {
6040
+ providers.push(...engine.providers, {
6041
+ provide: AGENT_RUNNER2,
6042
+ useExisting: engine.runner
6043
+ });
6044
+ } else if (durable) {
6025
6045
  providers.push({
6026
6046
  provide: AGENT_RUNNER2,
6027
6047
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
@@ -6046,8 +6066,9 @@ function sharedProviders(durable) {
6046
6066
  return providers;
6047
6067
  }
6048
6068
  __name(sharedProviders, "sharedProviders");
6049
- function exportsFor() {
6069
+ function exportsFor(engine) {
6050
6070
  return [
6071
+ ...engine?.exports ?? [],
6051
6072
  AGENT_OPTIONS9,
6052
6073
  AGENT_TOOL_REGISTRY3,
6053
6074
  AGENT_REGISTRY6,
@@ -6097,10 +6118,11 @@ function adapterProviders(adapters) {
6097
6118
  return (adapters ?? []).flatMap((adapter) => adapter.providers ?? []);
6098
6119
  }
6099
6120
  __name(adapterProviders, "adapterProviders");
6100
- function controllersForSurface(surface, adapters) {
6121
+ function controllersForSurface(surface, adapters, engine) {
6101
6122
  return surface === "engine" ? [] : [
6102
6123
  ...BASE_CONTROLLERS,
6103
- ...adapterControllers(adapters)
6124
+ ...adapterControllers(adapters),
6125
+ ...engine?.controllers ?? []
6104
6126
  ];
6105
6127
  }
6106
6128
  __name(controllersForSurface, "controllersForSurface");
@@ -6130,12 +6152,22 @@ function routerFor(path) {
6130
6152
  ]);
6131
6153
  }
6132
6154
  __name(routerFor, "routerFor");
6155
+ function assertRunnable(options) {
6156
+ if (options.engine !== void 0 && options.durable === true) {
6157
+ throw new Error(`AgentModule: \`durable: true\` runs turns on the library's loop, but the \`${options.engine.name}\` engine runs them instead. Drop \`durable\` (the engine decides how its turns survive a restart).`);
6158
+ }
6159
+ if (options.engine === void 0 && options.model === void 0) {
6160
+ throw new Error("AgentModule: set `model` (the loop runs the turns) or `engine` (something else does).");
6161
+ }
6162
+ }
6163
+ __name(assertRunnable, "assertRunnable");
6133
6164
  var AgentModule = class _AgentModule {
6134
6165
  static {
6135
6166
  __name(this, "AgentModule");
6136
6167
  }
6137
6168
  static forRoot(options) {
6138
6169
  const path = options.path ?? DEFAULT_PATH;
6170
+ assertRunnable(options);
6139
6171
  applyGuards(options.guards, options.adapters);
6140
6172
  return {
6141
6173
  module: _AgentModule,
@@ -6144,21 +6176,27 @@ var AgentModule = class _AgentModule {
6144
6176
  DiscoveryModule,
6145
6177
  routerFor(path)
6146
6178
  ],
6147
- controllers: controllersForSurface(options.surface, options.adapters),
6179
+ controllers: controllersForSurface(options.surface, options.adapters, options.engine),
6148
6180
  providers: [
6149
6181
  {
6150
6182
  provide: AGENT_OPTIONS9,
6151
6183
  useValue: options
6152
6184
  },
6153
- ...sharedProviders(options.durable ?? false),
6185
+ ...sharedProviders(options.durable ?? false, options.engine),
6154
6186
  ...guardProviders(options.guards),
6155
6187
  ...adapterProviders(options.adapters)
6156
6188
  ],
6157
- exports: exportsFor()
6189
+ exports: exportsFor(options.engine)
6158
6190
  };
6159
6191
  }
6160
6192
  static forRootAsync(options) {
6161
6193
  const path = options.path ?? DEFAULT_PATH;
6194
+ if (options.engine !== void 0) {
6195
+ assertRunnable({
6196
+ engine: options.engine,
6197
+ durable: options.durable ?? false
6198
+ });
6199
+ }
6162
6200
  applyGuards(options.guards, options.adapters);
6163
6201
  return {
6164
6202
  module: _AgentModule,
@@ -6168,7 +6206,7 @@ var AgentModule = class _AgentModule {
6168
6206
  routerFor(path),
6169
6207
  ...options.imports ?? []
6170
6208
  ],
6171
- controllers: controllersForSurface(options.surface, options.adapters),
6209
+ controllers: controllersForSurface(options.surface, options.adapters, options.engine),
6172
6210
  providers: [
6173
6211
  {
6174
6212
  provide: AGENT_OPTIONS9,
@@ -6178,18 +6216,25 @@ var AgentModule = class _AgentModule {
6178
6216
  // anything today (AgentDurableModule takes its own mirror option — see its doc for why),
6179
6217
  // but it's stamped here too so the EFFECTIVE value is always observable off
6180
6218
  // AGENT_OPTIONS, sync or async alike.
6181
- useFactory: /* @__PURE__ */ __name(async (...args) => ({
6182
- ...await options.useFactory(...args),
6183
- durable: options.durable ?? false,
6184
- surface: options.surface ?? "both"
6185
- }), "useFactory"),
6219
+ useFactory: /* @__PURE__ */ __name(async (...args) => {
6220
+ const resolved = {
6221
+ ...await options.useFactory(...args),
6222
+ durable: options.durable ?? false,
6223
+ surface: options.surface ?? "both",
6224
+ ...options.engine !== void 0 ? {
6225
+ engine: options.engine
6226
+ } : {}
6227
+ };
6228
+ assertRunnable(resolved);
6229
+ return resolved;
6230
+ }, "useFactory"),
6186
6231
  inject: options.inject ?? []
6187
6232
  },
6188
- ...sharedProviders(options.durable ?? false),
6233
+ ...sharedProviders(options.durable ?? false, options.engine),
6189
6234
  ...guardProviders(options.guards),
6190
6235
  ...adapterProviders(options.adapters)
6191
6236
  ],
6192
- exports: exportsFor()
6237
+ exports: exportsFor(options.engine)
6193
6238
  };
6194
6239
  }
6195
6240
  };