@dudousxd/nestjs-agent 1.23.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.
package/dist/index.cjs CHANGED
@@ -6452,7 +6452,10 @@ var AgUiRunHandler = class {
6452
6452
  if (owner !== null && owner !== actor.id) {
6453
6453
  throw new import_common28.ForbiddenException("thread belongs to another actor");
6454
6454
  }
6455
- if (owner !== null && turn.media.length === 0) {
6455
+ if (forwarded.regenerate === true && owner === null) {
6456
+ throw invalid("invalid_input", "regenerate needs a thread that already has an exchange");
6457
+ }
6458
+ if (owner !== null && forwarded.regenerate !== true && turn.media.length === 0 && turn.staged.length === 0) {
6456
6459
  const decision = await this.agent.handleTextDecision(input.threadId, actor, turn.text);
6457
6460
  if ("proposalDecision" in decision) {
6458
6461
  this.writeEvents(res, [
@@ -6467,7 +6470,7 @@ var AgUiRunHandler = class {
6467
6470
  return;
6468
6471
  }
6469
6472
  }
6470
- const refs = await this.stage(actor, turn.media, warnings);
6473
+ const refs = await this.stage(actor, turn.media, warnings, turn.staged);
6471
6474
  if (turn.text.trim().length === 0 && refs.length === 0) {
6472
6475
  throw invalid("no_user_message", "the user message to answer is empty");
6473
6476
  }
@@ -6503,6 +6506,9 @@ var AgUiRunHandler = class {
6503
6506
  } : {},
6504
6507
  ...refs.length > 0 ? {
6505
6508
  attachments: refs
6509
+ } : {},
6510
+ ...forwarded.regenerate === true ? {
6511
+ regenerate: true
6506
6512
  } : {}
6507
6513
  });
6508
6514
  await this.pipe(res, started.runId, {
@@ -6514,10 +6520,25 @@ var AgUiRunHandler = class {
6514
6520
  preamble: warningEvents(warnings)
6515
6521
  });
6516
6522
  }
6517
- /** Stage the turn's inline media through the bound store, within its limits; say what was not used. */
6518
- async stage(actor, media, warnings) {
6523
+ /**
6524
+ * The turn's attachments: the ones already staged (by mediaId), then its inline media staged
6525
+ * through the bound store — all within the store's limits; say what was not used.
6526
+ */
6527
+ async stage(actor, media, warnings, staged = []) {
6519
6528
  const refs = [];
6520
6529
  const limits = attachmentLimits(this.options, this.staging);
6530
+ for (const ref of staged) {
6531
+ const label = `The attachment ${ref.mediaId} was not used`;
6532
+ if (this.staging === void 0) {
6533
+ warnings.push(`${label}: attachments are not enabled on this agent.`);
6534
+ } else if (refs.length >= limits.maxPerMessage) {
6535
+ warnings.push(`${label}: a message carries at most ${limits.maxPerMessage} attachments.`);
6536
+ } else {
6537
+ refs.push({
6538
+ mediaId: ref.mediaId
6539
+ });
6540
+ }
6541
+ }
6521
6542
  for (const item of media) {
6522
6543
  const label = `The ${item.kind} "${item.filename}" was not used`;
6523
6544
  if (this.staging === void 0) {
@@ -6530,7 +6551,7 @@ var AgUiRunHandler = class {
6530
6551
  warnings.push(`${label}: it is larger than ${limits.maxBytes} bytes.`);
6531
6552
  } else {
6532
6553
  try {
6533
- const staged = await this.staging.stage({
6554
+ const staged2 = await this.staging.stage({
6534
6555
  data: item.data,
6535
6556
  filename: item.filename,
6536
6557
  contentType: item.contentType,
@@ -6538,7 +6559,7 @@ var AgUiRunHandler = class {
6538
6559
  actor
6539
6560
  });
6540
6561
  refs.push({
6541
- mediaId: staged.mediaId
6562
+ mediaId: staged2.mediaId
6542
6563
  });
6543
6564
  } catch {
6544
6565
  warnings.push(`${label}: it could not be stored.`);
@@ -6656,11 +6677,17 @@ var AgUiRunHandler = class {
6656
6677
  res.setHeader("X-Agent-Run-Id", runId);
6657
6678
  res.flushHeaders();
6658
6679
  let terminal = false;
6680
+ const cursor = {
6681
+ seq: 0
6682
+ };
6659
6683
  try {
6660
6684
  const frames = (0, import_ag_ui.agUiFramesFromNdjson)(this.agent.subscribe(runId));
6661
- for await (const event of (0, import_ag_ui.agUiEvents)(frames, options)) {
6685
+ for await (const event of (0, import_ag_ui.agUiEvents)(frames, {
6686
+ ...options,
6687
+ cursor
6688
+ })) {
6662
6689
  if (event.type === "RUN_FINISHED" || event.type === "RUN_ERROR") terminal = true;
6663
- res.write((0, import_ag_ui.agUiSse)(event));
6690
+ res.write((0, import_ag_ui.agUiSse)(event, cursor.seq));
6664
6691
  }
6665
6692
  } catch {
6666
6693
  if (!terminal) {