@dudousxd/nestjs-agent-core 0.41.0 → 0.42.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,6 +1,6 @@
1
- import { A as AgentStreamEvent, U as UiCapabilities } from '../stream-events-CF-6-Y6L.cjs';
1
+ import { A as AgentStreamEvent, U as UiCapabilities } from '../stream-events-BfxJAckJ.cjs';
2
2
  import '@standard-schema/spec';
3
- import '../catalog-BKS3Yxo6.cjs';
3
+ import '../catalog-G8usJpx5.cjs';
4
4
 
5
5
  /**
6
6
  * The slice of AG-UI 1.0 (https://docs.ag-ui.com/spec/1.0) this producer writes and reads. Typed by
@@ -141,6 +141,13 @@ type AgUiPartSource = {
141
141
  provider?: string;
142
142
  mimeType?: string;
143
143
  };
144
+ /**
145
+ * The `provider` of a `file` content part whose `value` is a `mediaId` this library staged
146
+ * (`POST <path>/attachments`, or the media module's upload routes). The producer takes such a part as
147
+ * an attachment reference and resolves it for the caller exactly as the native `chat` route does —
148
+ * a mediaId the caller does not own is refused. Any other `file` part is dropped.
149
+ */
150
+ declare const AG_UI_MEDIA_PROVIDER = "nestjs-agent";
144
151
  type AgUiContentPart = {
145
152
  type: 'text';
146
153
  text: string;
@@ -195,7 +202,7 @@ declare const AG_UI_CUSTOM: {
195
202
  /** The approval request as the native protocol carries it, for a consumer that renders it live. */
196
203
  readonly approvalRequested: "agora.approval-requested";
197
204
  readonly approvalSettled: "agora.approval-settled";
198
- /** The whole question set of an elicitation (`ElicitationRequest`). */
205
+ /** `{ id, runId, request }` — the whole question set of an elicitation, under its tool-call id. */
199
206
  readonly elicitation: "agora.elicitation";
200
207
  /** `{ usage, costUsd, reasoningMs }` of one model step. */
201
208
  readonly stepUsage: "agora.step-usage";
@@ -285,9 +292,6 @@ interface AgUiEncoderOptions {
285
292
  * - `cancelled` → the cancelled outcome; an error frame → `RUN_ERROR`;
286
293
  * - generative UI, title, queue and the native approval/elicitation frames → `CUSTOM` events named
287
294
  * in {@link AG_UI_CUSTOM}, for what AG-UI has no event for.
288
- *
289
- * Not mapped: sub-agent attribution (`subagentRunId`) — a delegated agent's frames are projected
290
- * flat, as the protocol allows of a producer that does not attribute.
291
295
  */
292
296
  declare class AgUiEncoder {
293
297
  private readonly options;
@@ -343,6 +347,11 @@ declare class AgUiEncoder {
343
347
  private closeText;
344
348
  private closeReasoning;
345
349
  private closeStreams;
350
+ /**
351
+ * `metadata['agora.toolKind']` says whether the call is an `action` (it may park for approval) or
352
+ * a `read`, and `metadata['agora.parentId']` the call it runs under — what the native
353
+ * `tool-input-start` frame carries and AG-UI's event has no field for.
354
+ */
346
355
  private callStart;
347
356
  private result;
348
357
  private addUsage;
@@ -399,6 +408,14 @@ interface UserTurn {
399
408
  /** The text of the message the run answers. */
400
409
  text: string;
401
410
  media: InlineMedia[];
411
+ /**
412
+ * Attachments the consumer already staged with this library, by `mediaId` — `file` parts whose
413
+ * `provider` is {@link AG_UI_MEDIA_PROVIDER}. Resolved (and ownership-checked) like the native
414
+ * route's `attachments`.
415
+ */
416
+ staged: {
417
+ mediaId: string;
418
+ }[];
402
419
  /** Why a part was not used, one sentence each — reported, never fatal. */
403
420
  dropped: string[];
404
421
  }
@@ -408,8 +425,10 @@ interface UserTurn {
408
425
  * agent resumes from is what it stored.
409
426
  *
410
427
  * Multimodal parts: text parts are the message's text; a media part carried inline (`data`) becomes
411
- * an attachment. A part by `url` or by provider `file` handle is dropped and said so — this producer
412
- * hands the model only bytes it staged itself, never an address a caller supplied.
428
+ * an attachment, and a `file` part whose `provider` is {@link AG_UI_MEDIA_PROVIDER} names one this
429
+ * library already staged (its `mediaId`). A part by `url` or by another provider's `file` handle is
430
+ * dropped and said so — this producer hands the model only bytes it staged itself, never an address
431
+ * a caller supplied.
413
432
  */
414
433
  declare function readUserTurn(messages: readonly AgUiMessage[]): UserTurn | null;
415
434
  /** `context` entries as the library's page context carries them, or `undefined` for none. */
@@ -424,6 +443,11 @@ interface ForwardedOptions {
424
443
  model?: string;
425
444
  persona?: string;
426
445
  pageContext?: Record<string, unknown>;
446
+ /**
447
+ * Re-run the thread's last exchange instead of appending a turn — what the native `chat` body's
448
+ * `regenerate: true` asks. The user message is the one being answered again.
449
+ */
450
+ regenerate?: boolean;
427
451
  }
428
452
  declare function readForwardedProps(forwarded: unknown): ForwardedOptions;
429
453
  /** One resume entry this producer can act on. */
@@ -462,7 +486,20 @@ interface AgUiStreamOptions extends AgUiEncoderOptions {
462
486
  quietMs?: number;
463
487
  /** Events to write right after `RUN_STARTED` (warnings about input that was dropped). */
464
488
  preamble?: AgUiEvent[];
489
+ /**
490
+ * Kept at the run's own sequence number (the native stream's SSE `id:`) of the library frame
491
+ * whose events are being yielded — `0` before the first. Write it as each event's SSE `id:`
492
+ * ({@link agUiSse}) and a consumer can re-attach to the native stream with `?after=` exactly where
493
+ * this AG-UI run left off.
494
+ */
495
+ cursor?: AgUiCursor;
465
496
  }
497
+ /** See {@link AgUiStreamOptions.cursor}. */
498
+ interface AgUiCursor {
499
+ seq: number;
500
+ }
501
+ /** The run's own sequence number of a frame read by {@link agUiFramesFromNdjson}, if known. */
502
+ declare function frameSeq(frame: AgUiSourceFrame): number | undefined;
466
503
  /**
467
504
  * One AG-UI run over a library run's stream.
468
505
  *
@@ -473,8 +510,12 @@ interface AgUiStreamOptions extends AgUiEncoderOptions {
473
510
  * with the interrupt outcome, and leaves the library run parked for the resume to pick up.
474
511
  */
475
512
  declare function agUiEvents(frames: AsyncIterable<AgUiSourceFrame>, options: AgUiStreamOptions): AsyncGenerator<AgUiEvent>;
476
- /** One AG-UI event as an SSE frame: a single `data:` line, LF-terminated, as the binding pins. */
477
- declare function agUiSse(event: AgUiEvent): string;
513
+ /**
514
+ * One AG-UI event as an SSE frame: a single `data:` line, LF-terminated, as the binding pins. With a
515
+ * positive `id`, an SSE `id:` line first — the run's sequence number ({@link AgUiStreamOptions.cursor}),
516
+ * which AG-UI clients ignore and this library's React client re-attaches with.
517
+ */
518
+ declare function agUiSse(event: AgUiEvent, id?: number): string;
478
519
  /**
479
520
  * A byte sink's stream (NDJSON {@link AgentStreamEvent}s, one per line, as the NestJS sinks carry
480
521
  * it) as the frames the encoder reads. A line that is not a stream event is bare model text — the
@@ -492,4 +533,4 @@ declare function actionProposalDecisionEvents(input: {
492
533
  proposalDecision: unknown;
493
534
  }): AgUiEvent[];
494
535
 
495
- export { AG_UI_CUSTOM, AG_UI_PROTOCOL_VERSION, type AgUiContentPart, type AgUiContext, AgUiEncoder, type AgUiEncoderOptions, type AgUiEvent, type AgUiInterrupt, type AgUiMessage, type AgUiMetadata, type AgUiPartSource, type AgUiResumeEntry, type AgUiRunInput, type AgUiRunOutcome, type AgUiSourceFrame, type AgUiStreamOptions, type AgUiTokenUsage, type ForwardedOptions, type InlineMedia, type InterruptAddress, type ResumeDecision, type ResumePlan, type UserTurn, actionProposalDecisionEvents, agUiEvents, agUiFramesFromNdjson, agUiSse, decodeInterruptId, encodeInterruptId, parseRunInput, planResume, readAnswersPayload, readApprovalPayload, readContext, readForwardedProps, readUserTurn };
536
+ export { AG_UI_CUSTOM, AG_UI_MEDIA_PROVIDER, AG_UI_PROTOCOL_VERSION, type AgUiContentPart, type AgUiContext, type AgUiCursor, AgUiEncoder, type AgUiEncoderOptions, type AgUiEvent, type AgUiInterrupt, type AgUiMessage, type AgUiMetadata, type AgUiPartSource, type AgUiResumeEntry, type AgUiRunInput, type AgUiRunOutcome, type AgUiSourceFrame, type AgUiStreamOptions, type AgUiTokenUsage, type ForwardedOptions, type InlineMedia, type InterruptAddress, type ResumeDecision, type ResumePlan, type UserTurn, actionProposalDecisionEvents, agUiEvents, agUiFramesFromNdjson, agUiSse, decodeInterruptId, encodeInterruptId, frameSeq, parseRunInput, planResume, readAnswersPayload, readApprovalPayload, readContext, readForwardedProps, readUserTurn };
@@ -1,6 +1,6 @@
1
- import { A as AgentStreamEvent, U as UiCapabilities } from '../stream-events-BGKLD6RX.js';
1
+ import { A as AgentStreamEvent, U as UiCapabilities } from '../stream-events-DFa2Do42.js';
2
2
  import '@standard-schema/spec';
3
- import '../catalog-BKS3Yxo6.js';
3
+ import '../catalog-G8usJpx5.js';
4
4
 
5
5
  /**
6
6
  * The slice of AG-UI 1.0 (https://docs.ag-ui.com/spec/1.0) this producer writes and reads. Typed by
@@ -141,6 +141,13 @@ type AgUiPartSource = {
141
141
  provider?: string;
142
142
  mimeType?: string;
143
143
  };
144
+ /**
145
+ * The `provider` of a `file` content part whose `value` is a `mediaId` this library staged
146
+ * (`POST <path>/attachments`, or the media module's upload routes). The producer takes such a part as
147
+ * an attachment reference and resolves it for the caller exactly as the native `chat` route does —
148
+ * a mediaId the caller does not own is refused. Any other `file` part is dropped.
149
+ */
150
+ declare const AG_UI_MEDIA_PROVIDER = "nestjs-agent";
144
151
  type AgUiContentPart = {
145
152
  type: 'text';
146
153
  text: string;
@@ -195,7 +202,7 @@ declare const AG_UI_CUSTOM: {
195
202
  /** The approval request as the native protocol carries it, for a consumer that renders it live. */
196
203
  readonly approvalRequested: "agora.approval-requested";
197
204
  readonly approvalSettled: "agora.approval-settled";
198
- /** The whole question set of an elicitation (`ElicitationRequest`). */
205
+ /** `{ id, runId, request }` — the whole question set of an elicitation, under its tool-call id. */
199
206
  readonly elicitation: "agora.elicitation";
200
207
  /** `{ usage, costUsd, reasoningMs }` of one model step. */
201
208
  readonly stepUsage: "agora.step-usage";
@@ -285,9 +292,6 @@ interface AgUiEncoderOptions {
285
292
  * - `cancelled` → the cancelled outcome; an error frame → `RUN_ERROR`;
286
293
  * - generative UI, title, queue and the native approval/elicitation frames → `CUSTOM` events named
287
294
  * in {@link AG_UI_CUSTOM}, for what AG-UI has no event for.
288
- *
289
- * Not mapped: sub-agent attribution (`subagentRunId`) — a delegated agent's frames are projected
290
- * flat, as the protocol allows of a producer that does not attribute.
291
295
  */
292
296
  declare class AgUiEncoder {
293
297
  private readonly options;
@@ -343,6 +347,11 @@ declare class AgUiEncoder {
343
347
  private closeText;
344
348
  private closeReasoning;
345
349
  private closeStreams;
350
+ /**
351
+ * `metadata['agora.toolKind']` says whether the call is an `action` (it may park for approval) or
352
+ * a `read`, and `metadata['agora.parentId']` the call it runs under — what the native
353
+ * `tool-input-start` frame carries and AG-UI's event has no field for.
354
+ */
346
355
  private callStart;
347
356
  private result;
348
357
  private addUsage;
@@ -399,6 +408,14 @@ interface UserTurn {
399
408
  /** The text of the message the run answers. */
400
409
  text: string;
401
410
  media: InlineMedia[];
411
+ /**
412
+ * Attachments the consumer already staged with this library, by `mediaId` — `file` parts whose
413
+ * `provider` is {@link AG_UI_MEDIA_PROVIDER}. Resolved (and ownership-checked) like the native
414
+ * route's `attachments`.
415
+ */
416
+ staged: {
417
+ mediaId: string;
418
+ }[];
402
419
  /** Why a part was not used, one sentence each — reported, never fatal. */
403
420
  dropped: string[];
404
421
  }
@@ -408,8 +425,10 @@ interface UserTurn {
408
425
  * agent resumes from is what it stored.
409
426
  *
410
427
  * Multimodal parts: text parts are the message's text; a media part carried inline (`data`) becomes
411
- * an attachment. A part by `url` or by provider `file` handle is dropped and said so — this producer
412
- * hands the model only bytes it staged itself, never an address a caller supplied.
428
+ * an attachment, and a `file` part whose `provider` is {@link AG_UI_MEDIA_PROVIDER} names one this
429
+ * library already staged (its `mediaId`). A part by `url` or by another provider's `file` handle is
430
+ * dropped and said so — this producer hands the model only bytes it staged itself, never an address
431
+ * a caller supplied.
413
432
  */
414
433
  declare function readUserTurn(messages: readonly AgUiMessage[]): UserTurn | null;
415
434
  /** `context` entries as the library's page context carries them, or `undefined` for none. */
@@ -424,6 +443,11 @@ interface ForwardedOptions {
424
443
  model?: string;
425
444
  persona?: string;
426
445
  pageContext?: Record<string, unknown>;
446
+ /**
447
+ * Re-run the thread's last exchange instead of appending a turn — what the native `chat` body's
448
+ * `regenerate: true` asks. The user message is the one being answered again.
449
+ */
450
+ regenerate?: boolean;
427
451
  }
428
452
  declare function readForwardedProps(forwarded: unknown): ForwardedOptions;
429
453
  /** One resume entry this producer can act on. */
@@ -462,7 +486,20 @@ interface AgUiStreamOptions extends AgUiEncoderOptions {
462
486
  quietMs?: number;
463
487
  /** Events to write right after `RUN_STARTED` (warnings about input that was dropped). */
464
488
  preamble?: AgUiEvent[];
489
+ /**
490
+ * Kept at the run's own sequence number (the native stream's SSE `id:`) of the library frame
491
+ * whose events are being yielded — `0` before the first. Write it as each event's SSE `id:`
492
+ * ({@link agUiSse}) and a consumer can re-attach to the native stream with `?after=` exactly where
493
+ * this AG-UI run left off.
494
+ */
495
+ cursor?: AgUiCursor;
465
496
  }
497
+ /** See {@link AgUiStreamOptions.cursor}. */
498
+ interface AgUiCursor {
499
+ seq: number;
500
+ }
501
+ /** The run's own sequence number of a frame read by {@link agUiFramesFromNdjson}, if known. */
502
+ declare function frameSeq(frame: AgUiSourceFrame): number | undefined;
466
503
  /**
467
504
  * One AG-UI run over a library run's stream.
468
505
  *
@@ -473,8 +510,12 @@ interface AgUiStreamOptions extends AgUiEncoderOptions {
473
510
  * with the interrupt outcome, and leaves the library run parked for the resume to pick up.
474
511
  */
475
512
  declare function agUiEvents(frames: AsyncIterable<AgUiSourceFrame>, options: AgUiStreamOptions): AsyncGenerator<AgUiEvent>;
476
- /** One AG-UI event as an SSE frame: a single `data:` line, LF-terminated, as the binding pins. */
477
- declare function agUiSse(event: AgUiEvent): string;
513
+ /**
514
+ * One AG-UI event as an SSE frame: a single `data:` line, LF-terminated, as the binding pins. With a
515
+ * positive `id`, an SSE `id:` line first — the run's sequence number ({@link AgUiStreamOptions.cursor}),
516
+ * which AG-UI clients ignore and this library's React client re-attaches with.
517
+ */
518
+ declare function agUiSse(event: AgUiEvent, id?: number): string;
478
519
  /**
479
520
  * A byte sink's stream (NDJSON {@link AgentStreamEvent}s, one per line, as the NestJS sinks carry
480
521
  * it) as the frames the encoder reads. A line that is not a stream event is bare model text — the
@@ -492,4 +533,4 @@ declare function actionProposalDecisionEvents(input: {
492
533
  proposalDecision: unknown;
493
534
  }): AgUiEvent[];
494
535
 
495
- export { AG_UI_CUSTOM, AG_UI_PROTOCOL_VERSION, type AgUiContentPart, type AgUiContext, AgUiEncoder, type AgUiEncoderOptions, type AgUiEvent, type AgUiInterrupt, type AgUiMessage, type AgUiMetadata, type AgUiPartSource, type AgUiResumeEntry, type AgUiRunInput, type AgUiRunOutcome, type AgUiSourceFrame, type AgUiStreamOptions, type AgUiTokenUsage, type ForwardedOptions, type InlineMedia, type InterruptAddress, type ResumeDecision, type ResumePlan, type UserTurn, actionProposalDecisionEvents, agUiEvents, agUiFramesFromNdjson, agUiSse, decodeInterruptId, encodeInterruptId, parseRunInput, planResume, readAnswersPayload, readApprovalPayload, readContext, readForwardedProps, readUserTurn };
536
+ export { AG_UI_CUSTOM, AG_UI_MEDIA_PROVIDER, AG_UI_PROTOCOL_VERSION, type AgUiContentPart, type AgUiContext, type AgUiCursor, AgUiEncoder, type AgUiEncoderOptions, type AgUiEvent, type AgUiInterrupt, type AgUiMessage, type AgUiMetadata, type AgUiPartSource, type AgUiResumeEntry, type AgUiRunInput, type AgUiRunOutcome, type AgUiSourceFrame, type AgUiStreamOptions, type AgUiTokenUsage, type ForwardedOptions, type InlineMedia, type InterruptAddress, type ResumeDecision, type ResumePlan, type UserTurn, actionProposalDecisionEvents, agUiEvents, agUiFramesFromNdjson, agUiSse, decodeInterruptId, encodeInterruptId, frameSeq, parseRunInput, planResume, readAnswersPayload, readApprovalPayload, readContext, readForwardedProps, readUserTurn };
@@ -48,6 +48,7 @@ __name(decodeInterruptId, "decodeInterruptId");
48
48
 
49
49
  // src/ag-ui/types.ts
50
50
  var AG_UI_PROTOCOL_VERSION = "1.0";
51
+ var AG_UI_MEDIA_PROVIDER = "nestjs-agent";
51
52
  var AG_UI_CUSTOM = {
52
53
  /** `{ runId, threadId }` — the library's own ids for the run behind this stream (cancel, re-attach). */
53
54
  run: "agora.run",
@@ -58,7 +59,7 @@ var AG_UI_CUSTOM = {
58
59
  /** The approval request as the native protocol carries it, for a consumer that renders it live. */
59
60
  approvalRequested: "agora.approval-requested",
60
61
  approvalSettled: "agora.approval-settled",
61
- /** The whole question set of an elicitation (`ElicitationRequest`). */
62
+ /** `{ id, runId, request }` — the whole question set of an elicitation, under its tool-call id. */
62
63
  elicitation: "agora.elicitation",
63
64
  /** `{ usage, costUsd, reasoningMs }` of one model step. */
64
65
  stepUsage: "agora.step-usage",
@@ -337,6 +338,7 @@ var AgUiEncoder = class {
337
338
  });
338
339
  return [
339
340
  this.custom(AG_UI_CUSTOM.elicitation, {
341
+ id: event.id,
340
342
  runId: parked,
341
343
  request: event.request
342
344
  })
@@ -392,7 +394,7 @@ var AgUiEncoder = class {
392
394
  sawDelta: false,
393
395
  answered: false
394
396
  });
395
- out.push(this.callStart(event.id, event.name));
397
+ out.push(this.callStart(event.id, event.name, event.toolKind, event.parentId));
396
398
  return out;
397
399
  }
398
400
  case "tool-input-delta": {
@@ -420,7 +422,7 @@ var AgUiEncoder = class {
420
422
  };
421
423
  if (!call.started) {
422
424
  call.started = true;
423
- out.push(this.callStart(event.id, event.name));
425
+ out.push(this.callStart(event.id, event.name, event.toolKind, event.parentId));
424
426
  }
425
427
  if (!call.sawDelta) {
426
428
  out.push({
@@ -626,13 +628,29 @@ var AgUiEncoder = class {
626
628
  ...this.closeText()
627
629
  ];
628
630
  }
629
- callStart(id, name) {
631
+ /**
632
+ * `metadata['agora.toolKind']` says whether the call is an `action` (it may park for approval) or
633
+ * a `read`, and `metadata['agora.parentId']` the call it runs under — what the native
634
+ * `tool-input-start` frame carries and AG-UI's event has no field for.
635
+ */
636
+ callStart(id, name, toolKind, parentId) {
637
+ const metadata = {
638
+ ...toolKind !== void 0 ? {
639
+ "agora.toolKind": toolKind
640
+ } : {},
641
+ ...parentId !== void 0 ? {
642
+ "agora.parentId": parentId
643
+ } : {}
644
+ };
630
645
  return {
631
646
  type: "TOOL_CALL_START",
632
647
  toolCallId: id,
633
648
  toolCallName: name,
634
649
  ...this.stepMessage !== void 0 ? {
635
650
  parentMessageId: this.stepMessage
651
+ } : {},
652
+ ...Object.keys(metadata).length > 0 ? {
653
+ metadata
636
654
  } : {}
637
655
  };
638
656
  }
@@ -790,18 +808,23 @@ function readUserTurn(messages) {
790
808
  }
791
809
  }
792
810
  if (last === void 0) return null;
793
- if (typeof last.content === "string") return {
794
- text: last.content,
795
- media: [],
796
- dropped: []
797
- };
811
+ if (typeof last.content === "string") {
812
+ return {
813
+ text: last.content,
814
+ media: [],
815
+ staged: [],
816
+ dropped: []
817
+ };
818
+ }
798
819
  if (!Array.isArray(last.content)) return {
799
820
  text: "",
800
821
  media: [],
822
+ staged: [],
801
823
  dropped: []
802
824
  };
803
825
  const texts = [];
804
826
  const media = [];
827
+ const staged = [];
805
828
  const dropped = [];
806
829
  last.content.forEach((part, index) => {
807
830
  if (!isRecord(part)) return;
@@ -813,6 +836,12 @@ function readUserTurn(messages) {
813
836
  return;
814
837
  }
815
838
  const source = part.source;
839
+ if (isRecord(source) && source.type === "file" && source.provider === AG_UI_MEDIA_PROVIDER && typeof source.value === "string" && source.value.length > 0) {
840
+ staged.push({
841
+ mediaId: source.value
842
+ });
843
+ return;
844
+ }
816
845
  if (!isRecord(source) || source.type !== "data") {
817
846
  const how = isRecord(source) && typeof source.type === "string" ? source.type : "unknown";
818
847
  dropped.push(`The ${part.type} part ${index + 1} was not used: only inline data is accepted, not a ${how} source.`);
@@ -838,6 +867,7 @@ function readUserTurn(messages) {
838
867
  return {
839
868
  text: texts.join("\n"),
840
869
  media,
870
+ staged,
841
871
  dropped
842
872
  };
843
873
  }
@@ -872,6 +902,9 @@ function readForwardedProps(forwarded) {
872
902
  } : {},
873
903
  ...isRecord(forwarded.pageContext) ? {
874
904
  pageContext: forwarded.pageContext
905
+ } : {},
906
+ ...forwarded.regenerate === true ? {
907
+ regenerate: true
875
908
  } : {}
876
909
  };
877
910
  }
@@ -971,6 +1004,11 @@ function decodeStreamEvent(line) {
971
1004
  __name(decodeStreamEvent, "decodeStreamEvent");
972
1005
 
973
1006
  // src/ag-ui/stream.ts
1007
+ var frameSeqs = /* @__PURE__ */ new WeakMap();
1008
+ function frameSeq(frame) {
1009
+ return frameSeqs.get(frame);
1010
+ }
1011
+ __name(frameSeq, "frameSeq");
974
1012
  var DEFAULT_QUIET_MS = 750;
975
1013
  var GRACE_MS = 50;
976
1014
  async function* agUiEvents(frames, options) {
@@ -997,6 +1035,9 @@ async function* agUiEvents(frames, options) {
997
1035
  ended = true;
998
1036
  break;
999
1037
  }
1038
+ if (options.cursor !== void 0) {
1039
+ options.cursor.seq = frameSeq(next.value) ?? encoder2.consumed + 1;
1040
+ }
1000
1041
  yield* encoder2.encode(next.value);
1001
1042
  }
1002
1043
  } finally {
@@ -1018,8 +1059,10 @@ function raceQuiet(upcoming, ms) {
1018
1059
  });
1019
1060
  }
1020
1061
  __name(raceQuiet, "raceQuiet");
1021
- function agUiSse(event) {
1022
- return `data: ${JSON.stringify(event)}
1062
+ function agUiSse(event, id) {
1063
+ const head = id !== void 0 && id > 0 ? `id: ${id}
1064
+ ` : "";
1065
+ return `${head}data: ${JSON.stringify(event)}
1023
1066
 
1024
1067
  `;
1025
1068
  }
@@ -1027,7 +1070,14 @@ __name(agUiSse, "agUiSse");
1027
1070
  async function* agUiFramesFromNdjson(chunks) {
1028
1071
  const decoder = new TextDecoder();
1029
1072
  let buffer = "";
1073
+ let seq = 0;
1030
1074
  const read = /* @__PURE__ */ __name((line) => {
1075
+ seq += 1;
1076
+ const frames = parse(line);
1077
+ for (const frame of frames) frameSeqs.set(frame, seq);
1078
+ return frames;
1079
+ }, "read");
1080
+ const parse = /* @__PURE__ */ __name((line) => {
1031
1081
  const event = decodeStreamEvent(line);
1032
1082
  if (event !== null) return [
1033
1083
  event
@@ -1047,7 +1097,7 @@ async function* agUiFramesFromNdjson(chunks) {
1047
1097
  text: line
1048
1098
  }
1049
1099
  ];
1050
- }, "read");
1100
+ }, "parse");
1051
1101
  try {
1052
1102
  for await (const chunk of chunks) {
1053
1103
  buffer += decoder.decode(chunk, {
@@ -1119,6 +1169,7 @@ function actionProposalDecisionEvents(input) {
1119
1169
  __name(actionProposalDecisionEvents, "actionProposalDecisionEvents");
1120
1170
  export {
1121
1171
  AG_UI_CUSTOM,
1172
+ AG_UI_MEDIA_PROVIDER,
1122
1173
  AG_UI_PROTOCOL_VERSION,
1123
1174
  AgUiEncoder,
1124
1175
  actionProposalDecisionEvents,
@@ -1127,6 +1178,7 @@ export {
1127
1178
  agUiSse,
1128
1179
  decodeInterruptId,
1129
1180
  encodeInterruptId,
1181
+ frameSeq,
1130
1182
  parseRunInput,
1131
1183
  planResume,
1132
1184
  readAnswersPayload,