@dudousxd/nestjs-agent-core 0.42.0 → 0.43.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.
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  var ag_ui_exports = {};
23
23
  __export(ag_ui_exports, {
24
24
  AG_UI_CUSTOM: () => AG_UI_CUSTOM,
25
+ AG_UI_MEDIA_PROVIDER: () => AG_UI_MEDIA_PROVIDER,
25
26
  AG_UI_PROTOCOL_VERSION: () => AG_UI_PROTOCOL_VERSION,
26
27
  AgUiEncoder: () => AgUiEncoder,
27
28
  actionProposalDecisionEvents: () => actionProposalDecisionEvents,
@@ -30,6 +31,7 @@ __export(ag_ui_exports, {
30
31
  agUiSse: () => agUiSse,
31
32
  decodeInterruptId: () => decodeInterruptId,
32
33
  encodeInterruptId: () => encodeInterruptId,
34
+ frameSeq: () => frameSeq,
33
35
  parseRunInput: () => parseRunInput,
34
36
  planResume: () => planResume,
35
37
  readAnswersPayload: () => readAnswersPayload,
@@ -87,6 +89,7 @@ __name(decodeInterruptId, "decodeInterruptId");
87
89
 
88
90
  // src/ag-ui/types.ts
89
91
  var AG_UI_PROTOCOL_VERSION = "1.0";
92
+ var AG_UI_MEDIA_PROVIDER = "nestjs-agent";
90
93
  var AG_UI_CUSTOM = {
91
94
  /** `{ runId, threadId }` — the library's own ids for the run behind this stream (cancel, re-attach). */
92
95
  run: "agora.run",
@@ -97,7 +100,7 @@ var AG_UI_CUSTOM = {
97
100
  /** The approval request as the native protocol carries it, for a consumer that renders it live. */
98
101
  approvalRequested: "agora.approval-requested",
99
102
  approvalSettled: "agora.approval-settled",
100
- /** The whole question set of an elicitation (`ElicitationRequest`). */
103
+ /** `{ id, runId, request }` — the whole question set of an elicitation, under its tool-call id. */
101
104
  elicitation: "agora.elicitation",
102
105
  /** `{ usage, costUsd, reasoningMs }` of one model step. */
103
106
  stepUsage: "agora.step-usage",
@@ -376,6 +379,7 @@ var AgUiEncoder = class {
376
379
  });
377
380
  return [
378
381
  this.custom(AG_UI_CUSTOM.elicitation, {
382
+ id: event.id,
379
383
  runId: parked,
380
384
  request: event.request
381
385
  })
@@ -431,7 +435,7 @@ var AgUiEncoder = class {
431
435
  sawDelta: false,
432
436
  answered: false
433
437
  });
434
- out.push(this.callStart(event.id, event.name));
438
+ out.push(this.callStart(event.id, event.name, event.toolKind, event.parentId));
435
439
  return out;
436
440
  }
437
441
  case "tool-input-delta": {
@@ -459,7 +463,7 @@ var AgUiEncoder = class {
459
463
  };
460
464
  if (!call.started) {
461
465
  call.started = true;
462
- out.push(this.callStart(event.id, event.name));
466
+ out.push(this.callStart(event.id, event.name, event.toolKind, event.parentId));
463
467
  }
464
468
  if (!call.sawDelta) {
465
469
  out.push({
@@ -665,13 +669,29 @@ var AgUiEncoder = class {
665
669
  ...this.closeText()
666
670
  ];
667
671
  }
668
- callStart(id, name) {
672
+ /**
673
+ * `metadata['agora.toolKind']` says whether the call is an `action` (it may park for approval) or
674
+ * a `read`, and `metadata['agora.parentId']` the call it runs under — what the native
675
+ * `tool-input-start` frame carries and AG-UI's event has no field for.
676
+ */
677
+ callStart(id, name, toolKind, parentId) {
678
+ const metadata = {
679
+ ...toolKind !== void 0 ? {
680
+ "agora.toolKind": toolKind
681
+ } : {},
682
+ ...parentId !== void 0 ? {
683
+ "agora.parentId": parentId
684
+ } : {}
685
+ };
669
686
  return {
670
687
  type: "TOOL_CALL_START",
671
688
  toolCallId: id,
672
689
  toolCallName: name,
673
690
  ...this.stepMessage !== void 0 ? {
674
691
  parentMessageId: this.stepMessage
692
+ } : {},
693
+ ...Object.keys(metadata).length > 0 ? {
694
+ metadata
675
695
  } : {}
676
696
  };
677
697
  }
@@ -829,18 +849,23 @@ function readUserTurn(messages) {
829
849
  }
830
850
  }
831
851
  if (last === void 0) return null;
832
- if (typeof last.content === "string") return {
833
- text: last.content,
834
- media: [],
835
- dropped: []
836
- };
852
+ if (typeof last.content === "string") {
853
+ return {
854
+ text: last.content,
855
+ media: [],
856
+ staged: [],
857
+ dropped: []
858
+ };
859
+ }
837
860
  if (!Array.isArray(last.content)) return {
838
861
  text: "",
839
862
  media: [],
863
+ staged: [],
840
864
  dropped: []
841
865
  };
842
866
  const texts = [];
843
867
  const media = [];
868
+ const staged = [];
844
869
  const dropped = [];
845
870
  last.content.forEach((part, index) => {
846
871
  if (!isRecord(part)) return;
@@ -852,6 +877,12 @@ function readUserTurn(messages) {
852
877
  return;
853
878
  }
854
879
  const source = part.source;
880
+ if (isRecord(source) && source.type === "file" && source.provider === AG_UI_MEDIA_PROVIDER && typeof source.value === "string" && source.value.length > 0) {
881
+ staged.push({
882
+ mediaId: source.value
883
+ });
884
+ return;
885
+ }
855
886
  if (!isRecord(source) || source.type !== "data") {
856
887
  const how = isRecord(source) && typeof source.type === "string" ? source.type : "unknown";
857
888
  dropped.push(`The ${part.type} part ${index + 1} was not used: only inline data is accepted, not a ${how} source.`);
@@ -877,6 +908,7 @@ function readUserTurn(messages) {
877
908
  return {
878
909
  text: texts.join("\n"),
879
910
  media,
911
+ staged,
880
912
  dropped
881
913
  };
882
914
  }
@@ -911,6 +943,9 @@ function readForwardedProps(forwarded) {
911
943
  } : {},
912
944
  ...isRecord(forwarded.pageContext) ? {
913
945
  pageContext: forwarded.pageContext
946
+ } : {},
947
+ ...forwarded.regenerate === true ? {
948
+ regenerate: true
914
949
  } : {}
915
950
  };
916
951
  }
@@ -1010,6 +1045,11 @@ function decodeStreamEvent(line) {
1010
1045
  __name(decodeStreamEvent, "decodeStreamEvent");
1011
1046
 
1012
1047
  // src/ag-ui/stream.ts
1048
+ var frameSeqs = /* @__PURE__ */ new WeakMap();
1049
+ function frameSeq(frame) {
1050
+ return frameSeqs.get(frame);
1051
+ }
1052
+ __name(frameSeq, "frameSeq");
1013
1053
  var DEFAULT_QUIET_MS = 750;
1014
1054
  var GRACE_MS = 50;
1015
1055
  async function* agUiEvents(frames, options) {
@@ -1036,6 +1076,9 @@ async function* agUiEvents(frames, options) {
1036
1076
  ended = true;
1037
1077
  break;
1038
1078
  }
1079
+ if (options.cursor !== void 0) {
1080
+ options.cursor.seq = frameSeq(next.value) ?? encoder2.consumed + 1;
1081
+ }
1039
1082
  yield* encoder2.encode(next.value);
1040
1083
  }
1041
1084
  } finally {
@@ -1057,8 +1100,10 @@ function raceQuiet(upcoming, ms) {
1057
1100
  });
1058
1101
  }
1059
1102
  __name(raceQuiet, "raceQuiet");
1060
- function agUiSse(event) {
1061
- return `data: ${JSON.stringify(event)}
1103
+ function agUiSse(event, id) {
1104
+ const head = id !== void 0 && id > 0 ? `id: ${id}
1105
+ ` : "";
1106
+ return `${head}data: ${JSON.stringify(event)}
1062
1107
 
1063
1108
  `;
1064
1109
  }
@@ -1066,7 +1111,14 @@ __name(agUiSse, "agUiSse");
1066
1111
  async function* agUiFramesFromNdjson(chunks) {
1067
1112
  const decoder = new TextDecoder();
1068
1113
  let buffer = "";
1114
+ let seq = 0;
1069
1115
  const read = /* @__PURE__ */ __name((line) => {
1116
+ seq += 1;
1117
+ const frames = parse(line);
1118
+ for (const frame of frames) frameSeqs.set(frame, seq);
1119
+ return frames;
1120
+ }, "read");
1121
+ const parse = /* @__PURE__ */ __name((line) => {
1070
1122
  const event = decodeStreamEvent(line);
1071
1123
  if (event !== null) return [
1072
1124
  event
@@ -1086,7 +1138,7 @@ async function* agUiFramesFromNdjson(chunks) {
1086
1138
  text: line
1087
1139
  }
1088
1140
  ];
1089
- }, "read");
1141
+ }, "parse");
1090
1142
  try {
1091
1143
  for await (const chunk of chunks) {
1092
1144
  buffer += decoder.decode(chunk, {
@@ -1159,6 +1211,7 @@ __name(actionProposalDecisionEvents, "actionProposalDecisionEvents");
1159
1211
  // Annotate the CommonJS export names for ESM import in node:
1160
1212
  0 && (module.exports = {
1161
1213
  AG_UI_CUSTOM,
1214
+ AG_UI_MEDIA_PROVIDER,
1162
1215
  AG_UI_PROTOCOL_VERSION,
1163
1216
  AgUiEncoder,
1164
1217
  actionProposalDecisionEvents,
@@ -1167,6 +1220,7 @@ __name(actionProposalDecisionEvents, "actionProposalDecisionEvents");
1167
1220
  agUiSse,
1168
1221
  decodeInterruptId,
1169
1222
  encodeInterruptId,
1223
+ frameSeq,
1170
1224
  parseRunInput,
1171
1225
  planResume,
1172
1226
  readAnswersPayload,