@dudousxd/nestjs-agent 1.22.0 → 1.23.1

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 { AgentStore, AgentRunInput, AgentLoopResult, LlmStepEnvelope, BufferedModelTurnResult, ToolStepEnvelope, AgentRunner, TokenStreamSink, AgentRunStartOptions, HumanReply } from '@dudousxd/nestjs-agent-core';
2
2
  import { WorkflowService } from '@dudousxd/nestjs-durable';
3
3
  import { RunGateway, WorkflowCtx } from '@dudousxd/nestjs-durable-core';
4
- import { A as AgentDepsFactory, C as ChatQueueService, a as AgentSurface, b as AgentModuleOptions } from '../chat-queue.service-Dx9OsjcF.cjs';
4
+ import { A as AgentDepsFactory, C as ChatQueueService, a as AgentSurface, b as AgentModuleOptions } from '../chat-queue.service-D1z3WjFI.cjs';
5
5
  import { DynamicModule } from '@nestjs/common';
6
6
  import '@dudousxd/nestjs-agent-core/genui';
7
7
  import '@standard-schema/spec';
@@ -1,7 +1,7 @@
1
1
  import { AgentStore, AgentRunInput, AgentLoopResult, LlmStepEnvelope, BufferedModelTurnResult, ToolStepEnvelope, AgentRunner, TokenStreamSink, AgentRunStartOptions, HumanReply } from '@dudousxd/nestjs-agent-core';
2
2
  import { WorkflowService } from '@dudousxd/nestjs-durable';
3
3
  import { RunGateway, WorkflowCtx } from '@dudousxd/nestjs-durable-core';
4
- import { A as AgentDepsFactory, C as ChatQueueService, a as AgentSurface, b as AgentModuleOptions } from '../chat-queue.service-CTyX_yNr.js';
4
+ import { A as AgentDepsFactory, C as ChatQueueService, a as AgentSurface, b as AgentModuleOptions } from '../chat-queue.service-CwxJDrBM.js';
5
5
  import { DynamicModule } from '@nestjs/common';
6
6
  import '@dudousxd/nestjs-agent-core/genui';
7
7
  import '@standard-schema/spec';
@@ -2223,6 +2223,9 @@ var ChatQueueService2 = class _ChatQueueService {
2223
2223
  } : {},
2224
2224
  ...input.uiCapabilities !== void 0 ? {
2225
2225
  uiCapabilities: input.uiCapabilities
2226
+ } : {},
2227
+ ...input.hostContext !== void 0 ? {
2228
+ hostContext: input.hostContext
2226
2229
  } : {}
2227
2230
  });
2228
2231
  await store.setQueuePause(threadId, {
@@ -2308,6 +2311,9 @@ var ChatQueueService2 = class _ChatQueueService {
2308
2311
  ...message.uiCapabilities !== void 0 ? {
2309
2312
  uiCapabilities: message.uiCapabilities
2310
2313
  } : {},
2314
+ ...message.hostContext !== void 0 ? {
2315
+ hostContext: message.hostContext
2316
+ } : {},
2311
2317
  ...message.model !== void 0 ? {
2312
2318
  model: message.model
2313
2319
  } : {}
@@ -2678,6 +2684,9 @@ var AgentService = class {
2678
2684
  }
2679
2685
  const created = await this.store.createThread({
2680
2686
  actor: params.actor,
2687
+ ...agentName !== void 0 ? {
2688
+ agentName
2689
+ } : {},
2681
2690
  ...params.transient === true ? {
2682
2691
  transient: true
2683
2692
  } : {},
@@ -2690,7 +2699,7 @@ var AgentService = class {
2690
2699
  });
2691
2700
  threadId = created.id;
2692
2701
  } else {
2693
- await this.assertOwnsThread(params.actor, threadId);
2702
+ if (params.authorized !== true) await this.assertOwnsThread(params.actor, threadId);
2694
2703
  if (params.personaId !== void 0) {
2695
2704
  await this.pinThreadPersona(threadId, params.personaId);
2696
2705
  }
@@ -2716,6 +2725,9 @@ var AgentService = class {
2716
2725
  ...params.uiCapabilities !== void 0 ? {
2717
2726
  uiCapabilities: params.uiCapabilities
2718
2727
  } : {},
2728
+ ...params.hostContext !== void 0 ? {
2729
+ hostContext: params.hostContext
2730
+ } : {},
2719
2731
  ...model !== void 0 ? {
2720
2732
  model
2721
2733
  } : {}
@@ -2738,7 +2750,7 @@ var AgentService = class {
2738
2750
  });
2739
2751
  }
2740
2752
  if (live === null && mode !== "queue") {
2741
- const runId = crypto.randomUUID();
2753
+ const runId = this.runner.runIdFor?.(input) ?? crypto.randomUUID();
2742
2754
  if (await queue.queueStore().claimActiveStream(threadId, runId, stale !== null ? {
2743
2755
  replacing: stale
2744
2756
  } : {})) {
@@ -2806,6 +2818,9 @@ var AgentService = class {
2806
2818
  ...input.uiCapabilities !== void 0 ? {
2807
2819
  uiCapabilities: input.uiCapabilities
2808
2820
  } : {},
2821
+ ...input.hostContext !== void 0 ? {
2822
+ hostContext: input.hostContext
2823
+ } : {},
2809
2824
  ...interrupting !== void 0 ? {
2810
2825
  interrupt: true,
2811
2826
  at: "head"
@@ -6902,11 +6917,11 @@ function isQuotaProvider(quota) {
6902
6917
  __name(isQuotaProvider, "isQuotaProvider");
6903
6918
  function resolveCatalog(options) {
6904
6919
  if (options.models !== void 0) return options.models;
6905
- const carried = options.model.catalog;
6920
+ const carried = options.model?.catalog;
6906
6921
  return carried !== void 0 && typeof carried.list === "function" ? carried : void 0;
6907
6922
  }
6908
6923
  __name(resolveCatalog, "resolveCatalog");
6909
- function sharedProviders(durable) {
6924
+ function sharedProviders(durable, engine) {
6910
6925
  const providers = [
6911
6926
  {
6912
6927
  provide: AGENT_TOOL_REGISTRY3,
@@ -7037,7 +7052,12 @@ function sharedProviders(durable) {
7037
7052
  ModulesContainer
7038
7053
  ]
7039
7054
  });
7040
- if (durable) {
7055
+ if (engine !== void 0) {
7056
+ providers.push(...engine.providers, {
7057
+ provide: AGENT_RUNNER2,
7058
+ useExisting: engine.runner
7059
+ });
7060
+ } else if (durable) {
7041
7061
  providers.push({
7042
7062
  provide: AGENT_RUNNER2,
7043
7063
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
@@ -7062,8 +7082,9 @@ function sharedProviders(durable) {
7062
7082
  return providers;
7063
7083
  }
7064
7084
  __name(sharedProviders, "sharedProviders");
7065
- function exportsFor() {
7085
+ function exportsFor(engine) {
7066
7086
  return [
7087
+ ...engine?.exports ?? [],
7067
7088
  AGENT_OPTIONS9,
7068
7089
  AGENT_TOOL_REGISTRY3,
7069
7090
  AGENT_REGISTRY6,
@@ -7113,10 +7134,11 @@ function adapterProviders(adapters) {
7113
7134
  return (adapters ?? []).flatMap((adapter) => adapter.providers ?? []);
7114
7135
  }
7115
7136
  __name(adapterProviders, "adapterProviders");
7116
- function controllersForSurface(surface, adapters) {
7137
+ function controllersForSurface(surface, adapters, engine) {
7117
7138
  return surface === "engine" ? [] : [
7118
7139
  ...BASE_CONTROLLERS,
7119
- ...adapterControllers(adapters)
7140
+ ...adapterControllers(adapters),
7141
+ ...engine?.controllers ?? []
7120
7142
  ];
7121
7143
  }
7122
7144
  __name(controllersForSurface, "controllersForSurface");
@@ -7146,12 +7168,22 @@ function routerFor(path) {
7146
7168
  ]);
7147
7169
  }
7148
7170
  __name(routerFor, "routerFor");
7171
+ function assertRunnable(options) {
7172
+ if (options.engine !== void 0 && options.durable === true) {
7173
+ 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).`);
7174
+ }
7175
+ if (options.engine === void 0 && options.model === void 0) {
7176
+ throw new Error("AgentModule: set `model` (the loop runs the turns) or `engine` (something else does).");
7177
+ }
7178
+ }
7179
+ __name(assertRunnable, "assertRunnable");
7149
7180
  var AgentModule = class _AgentModule {
7150
7181
  static {
7151
7182
  __name(this, "AgentModule");
7152
7183
  }
7153
7184
  static forRoot(options) {
7154
7185
  const path = options.path ?? DEFAULT_PATH;
7186
+ assertRunnable(options);
7155
7187
  applyGuards(options.guards, options.adapters);
7156
7188
  return {
7157
7189
  module: _AgentModule,
@@ -7160,21 +7192,27 @@ var AgentModule = class _AgentModule {
7160
7192
  DiscoveryModule,
7161
7193
  routerFor(path)
7162
7194
  ],
7163
- controllers: controllersForSurface(options.surface, options.adapters),
7195
+ controllers: controllersForSurface(options.surface, options.adapters, options.engine),
7164
7196
  providers: [
7165
7197
  {
7166
7198
  provide: AGENT_OPTIONS9,
7167
7199
  useValue: options
7168
7200
  },
7169
- ...sharedProviders(options.durable ?? false),
7201
+ ...sharedProviders(options.durable ?? false, options.engine),
7170
7202
  ...guardProviders(options.guards),
7171
7203
  ...adapterProviders(options.adapters)
7172
7204
  ],
7173
- exports: exportsFor()
7205
+ exports: exportsFor(options.engine)
7174
7206
  };
7175
7207
  }
7176
7208
  static forRootAsync(options) {
7177
7209
  const path = options.path ?? DEFAULT_PATH;
7210
+ if (options.engine !== void 0) {
7211
+ assertRunnable({
7212
+ engine: options.engine,
7213
+ durable: options.durable ?? false
7214
+ });
7215
+ }
7178
7216
  applyGuards(options.guards, options.adapters);
7179
7217
  return {
7180
7218
  module: _AgentModule,
@@ -7184,7 +7222,7 @@ var AgentModule = class _AgentModule {
7184
7222
  routerFor(path),
7185
7223
  ...options.imports ?? []
7186
7224
  ],
7187
- controllers: controllersForSurface(options.surface, options.adapters),
7225
+ controllers: controllersForSurface(options.surface, options.adapters, options.engine),
7188
7226
  providers: [
7189
7227
  {
7190
7228
  provide: AGENT_OPTIONS9,
@@ -7194,18 +7232,25 @@ var AgentModule = class _AgentModule {
7194
7232
  // anything today (AgentDurableModule takes its own mirror option — see its doc for why),
7195
7233
  // but it's stamped here too so the EFFECTIVE value is always observable off
7196
7234
  // AGENT_OPTIONS, sync or async alike.
7197
- useFactory: /* @__PURE__ */ __name(async (...args) => ({
7198
- ...await options.useFactory(...args),
7199
- durable: options.durable ?? false,
7200
- surface: options.surface ?? "both"
7201
- }), "useFactory"),
7235
+ useFactory: /* @__PURE__ */ __name(async (...args) => {
7236
+ const resolved = {
7237
+ ...await options.useFactory(...args),
7238
+ durable: options.durable ?? false,
7239
+ surface: options.surface ?? "both",
7240
+ ...options.engine !== void 0 ? {
7241
+ engine: options.engine
7242
+ } : {}
7243
+ };
7244
+ assertRunnable(resolved);
7245
+ return resolved;
7246
+ }, "useFactory"),
7202
7247
  inject: options.inject ?? []
7203
7248
  },
7204
- ...sharedProviders(options.durable ?? false),
7249
+ ...sharedProviders(options.durable ?? false, options.engine),
7205
7250
  ...guardProviders(options.guards),
7206
7251
  ...adapterProviders(options.adapters)
7207
7252
  ],
7208
- exports: exportsFor()
7253
+ exports: exportsFor(options.engine)
7209
7254
  };
7210
7255
  }
7211
7256
  };