@dudousxd/nestjs-agent 1.29.0 → 1.31.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.
Files changed (37) hide show
  1. package/dist/a2ui/index.cjs +207 -11
  2. package/dist/a2ui/index.cjs.map +1 -1
  3. package/dist/a2ui/index.d.cts +3 -3
  4. package/dist/a2ui/index.d.ts +3 -3
  5. package/dist/a2ui/index.js +203 -12
  6. package/dist/a2ui/index.js.map +1 -1
  7. package/dist/agent-genui.module-D0X3YnzO.d.cts +147 -0
  8. package/dist/agent-genui.module-D0X3YnzO.d.ts +147 -0
  9. package/dist/{chat-queue.service-B-fVOJGf.d.ts → chat-queue.service-Bdz43pAC.d.ts} +1 -1
  10. package/dist/{chat-queue.service-Bk7DCKGV.d.cts → chat-queue.service-ZwQ9p-Ps.d.cts} +1 -1
  11. package/dist/durable/index.cjs +249 -32
  12. package/dist/durable/index.cjs.map +1 -1
  13. package/dist/durable/index.d.cts +2 -2
  14. package/dist/durable/index.d.ts +2 -2
  15. package/dist/durable/index.js +240 -28
  16. package/dist/durable/index.js.map +1 -1
  17. package/dist/genui/index.cjs +211 -11
  18. package/dist/genui/index.cjs.map +1 -1
  19. package/dist/genui/index.d.cts +27 -94
  20. package/dist/genui/index.d.ts +27 -94
  21. package/dist/genui/index.js +205 -12
  22. package/dist/genui/index.js.map +1 -1
  23. package/dist/{index-APh8WN3z.d.ts → index-BGevU_Ih.d.ts} +8 -1
  24. package/dist/{index-D9EM7ivO.d.cts → index-DoCdfNrO.d.cts} +8 -1
  25. package/dist/index.cjs +240 -26
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +8 -6
  28. package/dist/index.d.ts +8 -6
  29. package/dist/index.js +236 -27
  30. package/dist/index.js.map +1 -1
  31. package/dist/vite/index.cjs +48 -0
  32. package/dist/vite/index.cjs.map +1 -0
  33. package/dist/vite/index.d.cts +32 -0
  34. package/dist/vite/index.d.ts +32 -0
  35. package/dist/vite/index.js +21 -0
  36. package/dist/vite/index.js.map +1 -0
  37. package/package.json +17 -3
package/dist/index.cjs CHANGED
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __esm = (fn, res) => function __init() {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ };
7
12
  var __export = (target, all) => {
8
13
  for (var name in all)
9
14
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,8 +22,66 @@ var __copyProps = (to, from, except, desc) => {
17
22
  return to;
18
23
  };
19
24
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
20
33
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
34
 
35
+ // src/vite/index.ts
36
+ var import_kit, NEST_SANDBOX_KIT_DESCRIPTOR;
37
+ var init_vite = __esm({
38
+ "src/vite/index.ts"() {
39
+ "use strict";
40
+ import_kit = require("@dudousxd/nestjs-agent-core/genui/kit");
41
+ NEST_SANDBOX_KIT_DESCRIPTOR = ".genui/sandbox-kit.json";
42
+ }
43
+ });
44
+
45
+ // src/genui/kit.ts
46
+ var kit_exports = {};
47
+ __export(kit_exports, {
48
+ NEST_SANDBOX_KIT_MANIFEST: () => NEST_SANDBOX_KIT_MANIFEST,
49
+ nestSandboxKitDiscovery: () => nestSandboxKitDiscovery
50
+ });
51
+ function nestSandboxKitDiscovery(options = {}) {
52
+ const manifest = options.manifest ?? NEST_SANDBOX_KIT_MANIFEST;
53
+ return (0, import_kit2.sandboxKitDiscovery)({
54
+ root: (0, import_node_path.resolve)(options.root ?? process.cwd()),
55
+ descriptor: options.descriptor ?? NEST_SANDBOX_KIT_DESCRIPTOR,
56
+ ...manifest !== false ? {
57
+ manifest: {
58
+ file: manifest.file,
59
+ outDir: manifest.outDir
60
+ }
61
+ } : {},
62
+ ...options.kitUrl !== void 0 ? {
63
+ kitUrl: options.kitUrl
64
+ } : {},
65
+ ...options.production !== void 0 ? {
66
+ production: options.production
67
+ } : {}
68
+ });
69
+ }
70
+ var import_node_path, import_kit2, NEST_SANDBOX_KIT_MANIFEST;
71
+ var init_kit = __esm({
72
+ "src/genui/kit.ts"() {
73
+ "use strict";
74
+ import_node_path = require("path");
75
+ import_kit2 = require("@dudousxd/nestjs-agent-core/genui/kit");
76
+ init_vite();
77
+ NEST_SANDBOX_KIT_MANIFEST = Object.freeze({
78
+ file: "public/.vite/manifest.json",
79
+ outDir: "public"
80
+ });
81
+ __name(nestSandboxKitDiscovery, "nestSandboxKitDiscovery");
82
+ }
83
+ });
84
+
22
85
  // src/index.ts
23
86
  var index_exports = {};
24
87
  __export(index_exports, {
@@ -143,6 +206,26 @@ function provideAgentTools(factory, inject) {
143
206
  __name(provideAgentTools, "provideAgentTools");
144
207
  var defineTool = import_nestjs_agent_core.createFunctionalTool;
145
208
 
209
+ // src/genui/agent-genui.token.ts
210
+ var AGENT_GENUI = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui");
211
+ var AgentGenui = class {
212
+ static {
213
+ __name(this, "AgentGenui");
214
+ }
215
+ catalog;
216
+ resolveCatalog;
217
+ channels;
218
+ base;
219
+ sandboxClient;
220
+ constructor(catalog, resolveCatalog2, channels, base = {}, sandboxClient) {
221
+ this.catalog = catalog;
222
+ this.resolveCatalog = resolveCatalog2;
223
+ this.channels = channels;
224
+ this.base = base;
225
+ this.sandboxClient = sandboxClient;
226
+ }
227
+ };
228
+
146
229
  // src/genui/agent-genui.module.ts
147
230
  function _ts_decorate(decorators, target, key, desc) {
148
231
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -160,6 +243,7 @@ function _ts_decorate(decorators, target, key, desc) {
160
243
  __name(_ts_decorate, "_ts_decorate");
161
244
  var GENUI_CATALOG = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-catalog");
162
245
  var GENUI_OPTIONS = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-options");
246
+ var GENUI_RESOLVED = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-resolved");
163
247
  var GenuiCatalogResolver = class {
164
248
  static {
165
249
  __name(this, "GenuiCatalogResolver");
@@ -178,20 +262,99 @@ function resolverProviders(resolver) {
178
262
  ];
179
263
  }
180
264
  __name(resolverProviders, "resolverProviders");
181
- function toolOptions(options, resolver) {
182
- const { catalog: _catalog, sandbox: _sandbox, ...rest } = options;
265
+ function mergeSandboxClients(clients) {
266
+ const merged = {
267
+ theme: false
268
+ };
269
+ for (const client of clients) {
270
+ const one = client();
271
+ merged.theme ||= one.theme;
272
+ if (one.tailwind !== void 0) merged.tailwind ??= one.tailwind;
273
+ if (one.kit !== void 0) merged.kit ??= one.kit;
274
+ }
275
+ return merged;
276
+ }
277
+ __name(mergeSandboxClients, "mergeSandboxClients");
278
+ async function resolveGenui(options) {
279
+ const { sandbox: asked, channels: askedChannels } = options;
280
+ (0, import_genui.assertGenuiChannels)(askedChannels);
281
+ const clients = [];
282
+ let discovery;
283
+ const resolveSandbox = /* @__PURE__ */ __name(async (value) => {
284
+ if (value === void 0 || value === false) return value;
285
+ const [{ nestSandboxKitDiscovery: nestSandboxKitDiscovery2 }, { resolveSandboxServer }] = await Promise.all([
286
+ Promise.resolve().then(() => (init_kit(), kit_exports)),
287
+ import("@dudousxd/nestjs-agent-core/genui/kit")
288
+ ]);
289
+ discovery ??= nestSandboxKitDiscovery2(options.sandboxKit);
290
+ const resolved = resolveSandboxServer(value, discovery);
291
+ clients.push(resolved.client);
292
+ return resolved.define;
293
+ }, "resolveSandbox");
294
+ const sandbox = await resolveSandbox(asked);
295
+ const own = options.catalog?.components.find((each) => (0, import_genui.sandboxPolicyOf)(each) !== void 0);
296
+ const ownOptions = asked === void 0 && own?.sandboxOptions !== void 0 && (own.sandboxView?.kit === true || own.sandboxView?.tailwind === true) ? await resolveSandbox({
297
+ ...own.sandboxOptions,
298
+ name: own.name
299
+ }) : void 0;
300
+ let channels;
301
+ if (askedChannels !== void 0) {
302
+ channels = {};
303
+ for (const [name, entry] of Object.entries(askedChannels)) {
304
+ if (entry === void 0) continue;
305
+ const own2 = await resolveSandbox(entry.sandbox);
306
+ channels[name] = {
307
+ ...entry,
308
+ ...own2 !== void 0 ? {
309
+ sandbox: own2
310
+ } : {}
311
+ };
312
+ }
313
+ }
314
+ return {
315
+ ...sandbox !== void 0 ? {
316
+ sandbox
317
+ } : {},
318
+ ...typeof ownOptions === "object" ? {
319
+ catalogSandbox: ownOptions
320
+ } : {},
321
+ ...channels !== void 0 ? {
322
+ channels
323
+ } : {},
324
+ ...clients.length > 0 ? {
325
+ sandboxClient: /* @__PURE__ */ __name(() => mergeSandboxClients(clients), "sandboxClient")
326
+ } : {}
327
+ };
328
+ }
329
+ __name(resolveGenui, "resolveGenui");
330
+ function perRequest(resolver) {
331
+ return resolver === void 0 ? void 0 : (scope) => resolver.resolve(scope);
332
+ }
333
+ __name(perRequest, "perRequest");
334
+ function toolOptions(options, resolved, resolver) {
335
+ const { catalog: _catalog, sandbox: _sandbox, channels: _channels, sandboxKit: _sandboxKit, ...rest } = options;
336
+ const resolveCatalog2 = perRequest(resolver);
183
337
  return {
184
338
  ...rest,
185
- ...resolver !== void 0 ? {
186
- resolveCatalog: /* @__PURE__ */ __name((scope) => resolver.resolve(scope), "resolveCatalog")
339
+ ...resolved.channels !== void 0 ? {
340
+ channels: resolved.channels
341
+ } : {},
342
+ ...resolved.sandbox !== void 0 ? {
343
+ sandbox: resolved.sandbox
344
+ } : {},
345
+ ...resolveCatalog2 !== void 0 ? {
346
+ resolveCatalog: resolveCatalog2
187
347
  } : {}
188
348
  };
189
349
  }
190
350
  __name(toolOptions, "toolOptions");
191
- function withSandbox(options) {
351
+ function withSandbox(options, resolved) {
192
352
  const base = options.catalog ?? (0, import_genui.defineCatalog)([]);
193
- const { sandbox } = options;
194
- return sandbox === void 0 || sandbox === false ? base : base.extend([
353
+ const { sandbox, catalogSandbox } = resolved;
354
+ if (sandbox === void 0 || sandbox === false) return catalogSandbox !== void 0 ? base.extend([
355
+ (0, import_genui.defineSandbox)(catalogSandbox)
356
+ ]) : base;
357
+ return base.extend([
195
358
  (0, import_genui.defineSandbox)(sandbox === true ? {} : sandbox)
196
359
  ]);
197
360
  }
@@ -199,18 +362,50 @@ __name(withSandbox, "withSandbox");
199
362
  function coreProviders(resolver) {
200
363
  return [
201
364
  {
202
- provide: GENUI_CATALOG,
203
- useFactory: /* @__PURE__ */ __name((options) => withSandbox(options), "useFactory"),
365
+ provide: GENUI_RESOLVED,
366
+ useFactory: /* @__PURE__ */ __name((options) => resolveGenui(options), "useFactory"),
204
367
  inject: [
205
368
  GENUI_OPTIONS
206
369
  ]
207
370
  },
371
+ {
372
+ provide: GENUI_CATALOG,
373
+ useFactory: /* @__PURE__ */ __name((options, resolved) => withSandbox(options, resolved), "useFactory"),
374
+ inject: [
375
+ GENUI_OPTIONS,
376
+ GENUI_RESOLVED
377
+ ]
378
+ },
379
+ {
380
+ provide: AGENT_GENUI,
381
+ useFactory: /* @__PURE__ */ __name((options, catalog, resolved, resolverInstance) => new AgentGenui(catalog, perRequest(resolverInstance), resolved.channels, {
382
+ ...options.mode !== void 0 ? {
383
+ mode: options.mode
384
+ } : {},
385
+ ...options.streaming !== void 0 ? {
386
+ streaming: options.streaming
387
+ } : {},
388
+ ...resolved.sandbox !== void 0 ? {
389
+ sandbox: resolved.sandbox
390
+ } : {}
391
+ }, resolved.sandboxClient), "useFactory"),
392
+ inject: [
393
+ GENUI_OPTIONS,
394
+ GENUI_CATALOG,
395
+ GENUI_RESOLVED,
396
+ {
397
+ token: GenuiCatalogResolver,
398
+ optional: true
399
+ }
400
+ ]
401
+ },
208
402
  ...resolverProviders(resolver),
209
403
  // The generated tools, registered by the agent module's discovery like any `provideAgentTool`.
210
404
  // Built from the injected catalog, so `overrideProvider(GENUI_CATALOG)` changes them too.
211
- provideAgentTools((options, catalog, perRequest) => (0, import_genui.genuiTools)(catalog, toolOptions(options, perRequest)), [
405
+ provideAgentTools((options, catalog, resolved, perRequestResolver) => (0, import_genui.genuiTools)(catalog, toolOptions(options, resolved, perRequestResolver)), [
212
406
  GENUI_OPTIONS,
213
407
  GENUI_CATALOG,
408
+ GENUI_RESOLVED,
214
409
  {
215
410
  token: GenuiCatalogResolver,
216
411
  optional: true
@@ -221,7 +416,8 @@ function coreProviders(resolver) {
221
416
  __name(coreProviders, "coreProviders");
222
417
  var EXPORTS = [
223
418
  GENUI_CATALOG,
224
- GENUI_OPTIONS
419
+ GENUI_OPTIONS,
420
+ AGENT_GENUI
225
421
  ];
226
422
  var AgentGenuiModule = class _AgentGenuiModule {
227
423
  static {
@@ -553,7 +749,7 @@ var AgentDepsFactory2 = class {
553
749
  id: persona.id,
554
750
  label: persona.label
555
751
  };
556
- const resolve = /* @__PURE__ */ __name(async (prompt, ctx) => typeof prompt === "function" ? prompt(ctx) : prompt, "resolve");
752
+ const resolve2 = /* @__PURE__ */ __name(async (prompt, ctx) => typeof prompt === "function" ? prompt(ctx) : prompt, "resolve");
557
753
  const own = persona.systemPrompt;
558
754
  const systemPrompt = /* @__PURE__ */ __name(async (ctx) => {
559
755
  const scoped = {
@@ -561,10 +757,10 @@ var AgentDepsFactory2 = class {
561
757
  persona: ref
562
758
  };
563
759
  if (own === void 0) {
564
- return resolve(base, scoped);
760
+ return resolve2(base, scoped);
565
761
  }
566
- const basePrompt = typeof own === "function" ? await resolve(base, scoped) : void 0;
567
- return resolve(own, {
762
+ const basePrompt = typeof own === "function" ? await resolve2(base, scoped) : void 0;
763
+ return resolve2(own, {
568
764
  ...scoped,
569
765
  ...basePrompt !== void 0 ? {
570
766
  basePrompt
@@ -1485,8 +1681,16 @@ function sendableParams(params) {
1485
1681
  message: "nothing to answer: send a non-empty message, an attachment, or regenerate"
1486
1682
  });
1487
1683
  }
1488
- return text === message ? params : {
1489
- ...params,
1684
+ const { channel, ...rest } = params;
1685
+ const stamped = channel === void 0 ? params : {
1686
+ ...rest,
1687
+ pageContext: {
1688
+ ...params.pageContext,
1689
+ channel
1690
+ }
1691
+ };
1692
+ return text === message ? stamped : {
1693
+ ...stamped,
1490
1694
  message: text
1491
1695
  };
1492
1696
  }
@@ -3408,11 +3612,13 @@ var ConfigController = class {
3408
3612
  actorResolver;
3409
3613
  staging;
3410
3614
  models;
3411
- constructor(options, actorResolver, staging, models) {
3615
+ genui;
3616
+ constructor(options, actorResolver, staging, models, genui) {
3412
3617
  this.options = options;
3413
3618
  this.actorResolver = actorResolver;
3414
3619
  this.staging = staging;
3415
3620
  this.models = models;
3621
+ this.genui = genui;
3416
3622
  }
3417
3623
  async config(req) {
3418
3624
  await this.actorResolver.resolve(req);
@@ -3426,7 +3632,12 @@ var ConfigController = class {
3426
3632
  },
3427
3633
  identity: {
3428
3634
  anonymous: this.actorResolver instanceof AnonymousActorResolver
3429
- }
3635
+ },
3636
+ ...this.genui?.sandboxClient !== void 0 ? {
3637
+ genui: {
3638
+ sandbox: this.genui.sandboxClient()
3639
+ }
3640
+ } : {}
3430
3641
  };
3431
3642
  }
3432
3643
  };
@@ -3447,11 +3658,14 @@ ConfigController = _ts_decorate10([
3447
3658
  _ts_param9(2, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_ATTACHMENT_STAGING)),
3448
3659
  _ts_param9(3, (0, import_common11.Optional)()),
3449
3660
  _ts_param9(3, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_MODEL_CATALOG)),
3661
+ _ts_param9(4, (0, import_common11.Optional)()),
3662
+ _ts_param9(4, (0, import_common11.Inject)(AGENT_GENUI)),
3450
3663
  _ts_metadata9("design:type", Function),
3451
3664
  _ts_metadata9("design:paramtypes", [
3452
3665
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
3453
3666
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3454
3667
  Object,
3668
+ Object,
3455
3669
  Object
3456
3670
  ])
3457
3671
  ], ConfigController);
@@ -5133,8 +5347,8 @@ var InProcessTokenStreamSink = class {
5133
5347
  return buf;
5134
5348
  }
5135
5349
  wake(buf) {
5136
- for (const resolve of buf.notify) {
5137
- resolve();
5350
+ for (const resolve2 of buf.notify) {
5351
+ resolve2();
5138
5352
  }
5139
5353
  buf.notify.clear();
5140
5354
  }
@@ -5173,7 +5387,7 @@ var InProcessTokenStreamSink = class {
5173
5387
  }
5174
5388
  return;
5175
5389
  }
5176
- await new Promise((resolve) => buf.notify.add(resolve));
5390
+ await new Promise((resolve2) => buf.notify.add(resolve2));
5177
5391
  }
5178
5392
  }
5179
5393
  close(runId) {
@@ -5850,12 +6064,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
5850
6064
  }
5851
6065
  const key = `${runId}:${toolCallId2}`;
5852
6066
  let timer;
5853
- const lapse = new Promise((resolve) => {
6067
+ const lapse = new Promise((resolve2) => {
5854
6068
  timer = setTimeout(() => {
5855
6069
  const entry = this.pending.get(key);
5856
6070
  if (entry !== void 0) {
5857
6071
  this.pending.delete(key);
5858
- resolve({
6072
+ resolve2({
5859
6073
  approved: false,
5860
6074
  expired: true
5861
6075
  });
@@ -5869,9 +6083,9 @@ var InlineAgentRunner = class _InlineAgentRunner {
5869
6083
  ]).finally(() => clearTimeout(timer));
5870
6084
  }
5871
6085
  park(runId, toolCallId2) {
5872
- return new Promise((resolve, reject) => {
6086
+ return new Promise((resolve2, reject) => {
5873
6087
  this.pending.set(`${runId}:${toolCallId2}`, {
5874
- resolve,
6088
+ resolve: resolve2,
5875
6089
  reject
5876
6090
  });
5877
6091
  });