@opencode/schema 2.0.32 → 2.1.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/config/experimental.d.ts +1 -0
  2. package/dist/config/experimental.js +3 -0
  3. package/dist/config/provider.d.ts +56 -52
  4. package/dist/credential-legacy.d.ts +54 -0
  5. package/dist/credential-legacy.js +19 -0
  6. package/dist/credential.d.ts +0 -4
  7. package/dist/credential.js +0 -2
  8. package/dist/event-manifest.d.ts +1111 -1149
  9. package/dist/event-manifest.js +1 -2
  10. package/dist/form.d.ts +213 -213
  11. package/dist/instruction-entry.d.ts +1 -1
  12. package/dist/integration.d.ts +257 -257
  13. package/dist/model-compatibility.d.ts +3 -0
  14. package/dist/model-compatibility.js +2 -0
  15. package/dist/model.d.ts +76 -74
  16. package/dist/persistent-pty.d.ts +88 -88
  17. package/dist/prompt-input.d.ts +3 -3
  18. package/dist/prompt.d.ts +28 -28
  19. package/dist/provider.d.ts +2 -0
  20. package/dist/session-event.d.ts +5729 -5723
  21. package/dist/session-event.js +20 -13
  22. package/dist/session-inbox.d.ts +20 -20
  23. package/dist/session-legacy.d.ts +7 -0
  24. package/dist/session-legacy.js +118 -0
  25. package/dist/session-message.d.ts +125 -268
  26. package/dist/session-message.js +13 -12
  27. package/dist/session-revert.d.ts +407 -183
  28. package/dist/session-transfer.d.ts +33 -83
  29. package/dist/session.d.ts +109 -1
  30. package/dist/session.js +64 -2
  31. package/dist/v1/permission.d.ts +8 -8
  32. package/dist/v1/session.d.ts +696 -696
  33. package/package.json +4 -4
  34. package/dist/session-compaction-event.d.ts +0 -87
  35. package/dist/session-compaction-event.js +0 -10
  36. package/dist/session-provider-context.d.ts +0 -54
  37. package/dist/session-provider-context.js +0 -17
@@ -118,6 +118,16 @@ export const Viewed = Event.durable({
118
118
  idle: Schema.Finite,
119
119
  },
120
120
  });
121
+ export const Archived = Event.durable({
122
+ type: "session.archived",
123
+ ...options,
124
+ schema: Base,
125
+ });
126
+ export const Unarchived = Event.durable({
127
+ type: "session.unarchived",
128
+ ...options,
129
+ schema: Base,
130
+ });
121
131
  // Replay-only: older releases allowed replacing completed assistant content.
122
132
  export const MessageContentUpdated = Event.durable({
123
133
  type: "session.message.content.updated",
@@ -302,7 +312,7 @@ export var Step;
302
312
  assistantMessageID: SessionMessage.ID,
303
313
  finish: FinishReason,
304
314
  rawFinish: Schema.String.pipe(optional),
305
- providerState: SessionMessage.ProviderState.pipe(optional),
315
+ native: SessionMessage.Native.pipe(optional),
306
316
  cost: Money.USD,
307
317
  tokens: TokenUsage.Info,
308
318
  snapshot: Snapshot.ID.pipe(optional),
@@ -318,7 +328,7 @@ export var Step;
318
328
  error: SessionError.Error,
319
329
  finish: Schema.Literals(["content-filter"]).pipe(optional),
320
330
  rawFinish: Schema.String.pipe(optional),
321
- providerState: SessionMessage.ProviderState.pipe(optional),
331
+ native: SessionMessage.Native.pipe(optional),
322
332
  cost: Money.USD.pipe(optional),
323
333
  tokens: TokenUsage.Info.pipe(optional),
324
334
  snapshot: Snapshot.ID.pipe(optional),
@@ -355,7 +365,7 @@ export var Text;
355
365
  assistantMessageID: SessionMessage.ID,
356
366
  ordinal: NonNegativeInt,
357
367
  text: Schema.String,
358
- state: SessionMessage.ProviderState.pipe(optional),
368
+ native: SessionMessage.Native.pipe(optional),
359
369
  },
360
370
  });
361
371
  })(Text || (Text = {}));
@@ -368,7 +378,7 @@ export var Reasoning;
368
378
  ...Base,
369
379
  assistantMessageID: SessionMessage.ID,
370
380
  ordinal: NonNegativeInt,
371
- state: SessionMessage.ProviderState.pipe(optional),
381
+ native: SessionMessage.Native.pipe(optional),
372
382
  },
373
383
  });
374
384
  // Stream fragments are live-only; Reasoning.Ended is the replayable full-value boundary.
@@ -389,7 +399,7 @@ export var Reasoning;
389
399
  assistantMessageID: SessionMessage.ID,
390
400
  ordinal: NonNegativeInt,
391
401
  text: Schema.String,
392
- state: SessionMessage.ProviderState.pipe(optional),
402
+ native: SessionMessage.Native.pipe(optional),
393
403
  },
394
404
  });
395
405
  })(Reasoning || (Reasoning = {}));
@@ -434,7 +444,7 @@ export var Tool;
434
444
  ...ToolBase,
435
445
  input: Schema.Record(Schema.String, Schema.Unknown),
436
446
  executed: Schema.Boolean,
437
- state: SessionMessage.ProviderState.pipe(optional),
447
+ native: SessionMessage.Native.pipe(optional),
438
448
  },
439
449
  });
440
450
  /** Live replacement metadata for a running tool. */
@@ -457,7 +467,7 @@ export var Tool;
457
467
  content: Schema.NonEmptyArray(Content),
458
468
  metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
459
469
  executed: Schema.Boolean,
460
- resultState: SessionMessage.ProviderState.pipe(optional),
470
+ native: SessionMessage.Native.pipe(optional),
461
471
  },
462
472
  });
463
473
  /**
@@ -477,7 +487,7 @@ export var Tool;
477
487
  content: Schema.NonEmptyArray(Content).pipe(optional),
478
488
  metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
479
489
  executed: Schema.Boolean,
480
- resultState: SessionMessage.ProviderState.pipe(optional),
490
+ native: SessionMessage.Native.pipe(optional),
481
491
  },
482
492
  });
483
493
  })(Tool || (Tool = {}));
@@ -500,7 +510,6 @@ export var Compaction;
500
510
  schema: {
501
511
  ...Base,
502
512
  reason: Schema.Literals(["auto", "manual"]),
503
- recent: Schema.String,
504
513
  inputID: SessionMessage.ID.pipe(optional),
505
514
  },
506
515
  });
@@ -518,10 +527,8 @@ export var Compaction;
518
527
  ...Base,
519
528
  reason: Compaction.Started.data.fields.reason,
520
529
  model: SessionMessage.CompactionCompleted.fields.model,
521
- providerState: SessionMessage.CompactionCompleted.fields.providerState,
522
- providerContext: SessionMessage.CompactionCompleted.fields.providerContext,
530
+ native: SessionMessage.CompactionCompleted.fields.native,
523
531
  text: Schema.String,
524
- recent: Schema.String,
525
532
  // Repeats the internal `session.usage.recorded` figures: that event never reaches clients, and it
526
533
  // stays the accounting source for session totals and stats.
527
534
  cost: SessionMessage.CompactionCompleted.fields.cost,
@@ -555,7 +562,7 @@ export var RevertEvent;
555
562
  schema: { ...Base, to: SessionMessage.ID },
556
563
  });
557
564
  })(RevertEvent || (RevertEvent = {}));
558
- export const Definitions = Event.inventory(Created, AgentSelected, ModelSelected, Moved, Renamed, MetadataUpdated, Permissions, Viewed, UsageUpdated, Deleted, Forked, InboxDelivered, InboxEnqueued, InboxCancelled, InboxDeliveryChanged, Execution.Started, Execution.Succeeded, Execution.Failed, Execution.Interrupted, InstructionsUpdated, Synthetic, Skill.Activated, Shell.Started, Shell.Ended, Step.Started, Step.Streamed, Step.Ended, Step.Failed, Text.Started, Text.Delta, Text.Ended, Reasoning.Started, Reasoning.Delta, Reasoning.Ended, Tool.Input.Started, Tool.Input.Delta, Tool.Input.Ended, Tool.Called, Tool.Progress, Tool.Success, Tool.Failed, RetryScheduled, Compaction.Started, Compaction.Delta, Compaction.Ended, Compaction.Failed, RevertEvent.Staged, RevertEvent.Cleared, RevertEvent.Committed);
565
+ export const Definitions = Event.inventory(Created, AgentSelected, ModelSelected, Moved, Renamed, MetadataUpdated, Permissions, Viewed, Archived, Unarchived, UsageUpdated, Deleted, Forked, InboxDelivered, InboxEnqueued, InboxCancelled, InboxDeliveryChanged, Execution.Started, Execution.Succeeded, Execution.Failed, Execution.Interrupted, InstructionsUpdated, Synthetic, Skill.Activated, Shell.Started, Shell.Ended, Step.Started, Step.Streamed, Step.Ended, Step.Failed, Text.Started, Text.Delta, Text.Ended, Reasoning.Started, Reasoning.Delta, Reasoning.Ended, Tool.Input.Started, Tool.Input.Delta, Tool.Input.Ended, Tool.Called, Tool.Progress, Tool.Success, Tool.Failed, RetryScheduled, Compaction.Started, Compaction.Delta, Compaction.Ended, Compaction.Failed, RevertEvent.Staged, RevertEvent.Cleared, RevertEvent.Committed);
559
566
  // Internal and replay-only events are excluded from the public manifest.
560
567
  export const DurableDefinitions = Event.inventory(...Definitions.filter((definition) => definition.durability === "durable"), UsageRecorded, MessageContentUpdated);
561
568
  export const EphemeralDefinitions = Event.inventory(...Definitions.filter((definition) => definition.durability === "ephemeral"));
@@ -5,7 +5,6 @@ export type Delivery = typeof Delivery.Type;
5
5
  export interface UserPayload extends Schema.Schema.Type<typeof UserPayload> {
6
6
  }
7
7
  export declare const UserPayload: Schema.Struct<{
8
- readonly metadata: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Record<Schema.String, Schema.Unknown>>>, Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>, never, never>;
9
8
  readonly text: Schema.String;
10
9
  readonly files: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Array<Schema.Struct<{
11
10
  readonly data: Schema.String;
@@ -30,15 +29,15 @@ export declare const UserPayload: Schema.Struct<{
30
29
  }> & {
31
30
  create: (input: import("./prompt.js").FileAttachment) => {
32
31
  readonly data: string;
32
+ readonly mime: string;
33
33
  readonly source: {
34
34
  readonly type: "inline";
35
35
  } | {
36
36
  readonly type: "uri";
37
37
  readonly uri: string;
38
38
  };
39
- readonly mime: string;
40
- readonly description?: string | undefined;
41
39
  readonly name?: string | undefined;
40
+ readonly description?: string | undefined;
42
41
  readonly mention?: {
43
42
  readonly start: number;
44
43
  readonly end: number;
@@ -68,15 +67,15 @@ export declare const UserPayload: Schema.Struct<{
68
67
  }> & {
69
68
  create: (input: import("./prompt.js").FileAttachment) => {
70
69
  readonly data: string;
70
+ readonly mime: string;
71
71
  readonly source: {
72
72
  readonly type: "inline";
73
73
  } | {
74
74
  readonly type: "uri";
75
75
  readonly uri: string;
76
76
  };
77
- readonly mime: string;
78
- readonly description?: string | undefined;
79
77
  readonly name?: string | undefined;
78
+ readonly description?: string | undefined;
80
79
  readonly mention?: {
81
80
  readonly start: number;
82
81
  readonly end: number;
@@ -134,6 +133,7 @@ export declare const UserPayload: Schema.Struct<{
134
133
  readonly text: Schema.String;
135
134
  }>>, never, never>;
136
135
  }>>>, never, never>;
136
+ readonly metadata: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Record<Schema.String, Schema.Unknown>>>, Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>, never, never>;
137
137
  }>;
138
138
  export interface SyntheticPayload extends Schema.Schema.Type<typeof SyntheticPayload> {
139
139
  }
@@ -166,7 +166,6 @@ export declare const MovePayload: Schema.Struct<{
166
166
  export declare const Item: Schema.Union<readonly [Schema.Struct<{
167
167
  readonly type: Schema.tag<"user">;
168
168
  readonly payload: Schema.Struct<{
169
- readonly metadata: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Record<Schema.String, Schema.Unknown>>>, Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>, never, never>;
170
169
  readonly text: Schema.String;
171
170
  readonly files: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Array<Schema.Struct<{
172
171
  readonly data: Schema.String;
@@ -191,15 +190,15 @@ export declare const Item: Schema.Union<readonly [Schema.Struct<{
191
190
  }> & {
192
191
  create: (input: import("./prompt.js").FileAttachment) => {
193
192
  readonly data: string;
193
+ readonly mime: string;
194
194
  readonly source: {
195
195
  readonly type: "inline";
196
196
  } | {
197
197
  readonly type: "uri";
198
198
  readonly uri: string;
199
199
  };
200
- readonly mime: string;
201
- readonly description?: string | undefined;
202
200
  readonly name?: string | undefined;
201
+ readonly description?: string | undefined;
203
202
  readonly mention?: {
204
203
  readonly start: number;
205
204
  readonly end: number;
@@ -229,15 +228,15 @@ export declare const Item: Schema.Union<readonly [Schema.Struct<{
229
228
  }> & {
230
229
  create: (input: import("./prompt.js").FileAttachment) => {
231
230
  readonly data: string;
231
+ readonly mime: string;
232
232
  readonly source: {
233
233
  readonly type: "inline";
234
234
  } | {
235
235
  readonly type: "uri";
236
236
  readonly uri: string;
237
237
  };
238
- readonly mime: string;
239
- readonly description?: string | undefined;
240
238
  readonly name?: string | undefined;
239
+ readonly description?: string | undefined;
241
240
  readonly mention?: {
242
241
  readonly start: number;
243
242
  readonly end: number;
@@ -295,6 +294,7 @@ export declare const Item: Schema.Union<readonly [Schema.Struct<{
295
294
  readonly text: Schema.String;
296
295
  }>>, never, never>;
297
296
  }>>>, never, never>;
297
+ readonly metadata: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Record<Schema.String, Schema.Unknown>>>, Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>, never, never>;
298
298
  }>;
299
299
  readonly delivery: Schema.Literals<readonly ["steer", "queue"]>;
300
300
  }>, Schema.Struct<{
@@ -335,7 +335,6 @@ export interface User extends Schema.Schema.Type<typeof User> {
335
335
  export declare const User: Schema.Struct<{
336
336
  readonly type: Schema.tag<"user">;
337
337
  readonly payload: Schema.Struct<{
338
- readonly metadata: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Record<Schema.String, Schema.Unknown>>>, Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>, never, never>;
339
338
  readonly text: Schema.String;
340
339
  readonly files: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Array<Schema.Struct<{
341
340
  readonly data: Schema.String;
@@ -360,15 +359,15 @@ export declare const User: Schema.Struct<{
360
359
  }> & {
361
360
  create: (input: import("./prompt.js").FileAttachment) => {
362
361
  readonly data: string;
362
+ readonly mime: string;
363
363
  readonly source: {
364
364
  readonly type: "inline";
365
365
  } | {
366
366
  readonly type: "uri";
367
367
  readonly uri: string;
368
368
  };
369
- readonly mime: string;
370
- readonly description?: string | undefined;
371
369
  readonly name?: string | undefined;
370
+ readonly description?: string | undefined;
372
371
  readonly mention?: {
373
372
  readonly start: number;
374
373
  readonly end: number;
@@ -398,15 +397,15 @@ export declare const User: Schema.Struct<{
398
397
  }> & {
399
398
  create: (input: import("./prompt.js").FileAttachment) => {
400
399
  readonly data: string;
400
+ readonly mime: string;
401
401
  readonly source: {
402
402
  readonly type: "inline";
403
403
  } | {
404
404
  readonly type: "uri";
405
405
  readonly uri: string;
406
406
  };
407
- readonly mime: string;
408
- readonly description?: string | undefined;
409
407
  readonly name?: string | undefined;
408
+ readonly description?: string | undefined;
410
409
  readonly mention?: {
411
410
  readonly start: number;
412
411
  readonly end: number;
@@ -464,6 +463,7 @@ export declare const User: Schema.Struct<{
464
463
  readonly text: Schema.String;
465
464
  }>>, never, never>;
466
465
  }>>>, never, never>;
466
+ readonly metadata: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Record<Schema.String, Schema.Unknown>>>, Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>, never, never>;
467
467
  }>;
468
468
  readonly delivery: Schema.Literals<readonly ["steer", "queue"]>;
469
469
  readonly id: Schema.brand<Schema.String, "Session.Message.ID"> & {
@@ -554,7 +554,6 @@ export declare const Move: Schema.Struct<{
554
554
  export declare const Info: Schema.Union<readonly [Schema.Struct<{
555
555
  readonly type: Schema.tag<"user">;
556
556
  readonly payload: Schema.Struct<{
557
- readonly metadata: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Record<Schema.String, Schema.Unknown>>>, Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>, never, never>;
558
557
  readonly text: Schema.String;
559
558
  readonly files: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Array<Schema.Struct<{
560
559
  readonly data: Schema.String;
@@ -579,15 +578,15 @@ export declare const Info: Schema.Union<readonly [Schema.Struct<{
579
578
  }> & {
580
579
  create: (input: import("./prompt.js").FileAttachment) => {
581
580
  readonly data: string;
581
+ readonly mime: string;
582
582
  readonly source: {
583
583
  readonly type: "inline";
584
584
  } | {
585
585
  readonly type: "uri";
586
586
  readonly uri: string;
587
587
  };
588
- readonly mime: string;
589
- readonly description?: string | undefined;
590
588
  readonly name?: string | undefined;
589
+ readonly description?: string | undefined;
591
590
  readonly mention?: {
592
591
  readonly start: number;
593
592
  readonly end: number;
@@ -617,15 +616,15 @@ export declare const Info: Schema.Union<readonly [Schema.Struct<{
617
616
  }> & {
618
617
  create: (input: import("./prompt.js").FileAttachment) => {
619
618
  readonly data: string;
619
+ readonly mime: string;
620
620
  readonly source: {
621
621
  readonly type: "inline";
622
622
  } | {
623
623
  readonly type: "uri";
624
624
  readonly uri: string;
625
625
  };
626
- readonly mime: string;
627
- readonly description?: string | undefined;
628
626
  readonly name?: string | undefined;
627
+ readonly description?: string | undefined;
629
628
  readonly mention?: {
630
629
  readonly start: number;
631
630
  readonly end: number;
@@ -683,6 +682,7 @@ export declare const Info: Schema.Union<readonly [Schema.Struct<{
683
682
  readonly text: Schema.String;
684
683
  }>>, never, never>;
685
684
  }>>>, never, never>;
685
+ readonly metadata: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Record<Schema.String, Schema.Unknown>>>, Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>, never, never>;
686
686
  }>;
687
687
  readonly delivery: Schema.Literals<readonly ["steer", "queue"]>;
688
688
  readonly id: Schema.brand<Schema.String, "Session.Message.ID"> & {
@@ -0,0 +1,7 @@
1
+ export * as SessionLegacy from "./session-legacy.js";
2
+ /** Upgrades a durable event payload by event type. */
3
+ export declare function event(type: string, data: unknown): unknown;
4
+ /** Upgrades a projected message's data by message type. */
5
+ export declare function message(type: unknown, data: Record<string, unknown>): Record<string, unknown>;
6
+ /** Upgrades complete messages, such as those in an exported session, before decoding. */
7
+ export declare function messages(values: ReadonlyArray<unknown>): unknown[];
@@ -0,0 +1,118 @@
1
+ export * as SessionLegacy from "./session-legacy.js";
2
+ /**
3
+ * Storage and wire compatibility for current-architecture data written before v2.1 (not V1 contracts). Native data
4
+ * was then named `state` or `providerState`, a tool's result native data `resultState` or `providerResultState`,
5
+ * summary compactions stored the text of the messages they kept in `recent`, and provider compactions stored their
6
+ * replacement window in `providerContext`. Stored events, projected messages, and exported transcripts keep whichever
7
+ * shape they were written with, so these upgrade them before decoding.
8
+ */
9
+ const renames = {
10
+ "session.text.ended": ["state", "native"],
11
+ "session.reasoning.started": ["state", "native"],
12
+ "session.reasoning.ended": ["state", "native"],
13
+ "session.tool.called": ["state", "native"],
14
+ "session.step.ended": ["providerState", "native"],
15
+ "session.step.failed": ["providerState", "native"],
16
+ "session.tool.success": ["resultState", "native"],
17
+ "session.tool.failed": ["resultState", "native"],
18
+ };
19
+ /** Upgrades a durable event payload by event type. */
20
+ export function event(type, data) {
21
+ if (!isRecord(data))
22
+ return data;
23
+ if (type === "session.message.content.updated")
24
+ return content(data);
25
+ // Messages carry a legacy compaction's kept text; its events have no reader for it.
26
+ if (type === "session.compaction.started")
27
+ return omit(data, "recent");
28
+ if (type === "session.compaction.ended")
29
+ return providerContext(omit(rename(data, "providerState", "native"), "recent"));
30
+ const entry = renames[type];
31
+ return entry ? rename(data, entry[0], entry[1]) : data;
32
+ }
33
+ /** Upgrades a projected message's data by message type. */
34
+ export function message(type, data) {
35
+ if (type === "assistant")
36
+ return content(rename(data, "providerState", "native"));
37
+ if (type === "compaction")
38
+ return providerContext(recent(rename(data, "providerState", "native")));
39
+ return data;
40
+ }
41
+ /** Upgrades complete messages, such as those in an exported session, before decoding. */
42
+ export function messages(values) {
43
+ return values.map((value) => (isRecord(value) ? message(value.type, value) : value));
44
+ }
45
+ function content(data) {
46
+ if (!Array.isArray(data.content))
47
+ return data;
48
+ return { ...data, content: data.content.map(part) };
49
+ }
50
+ function part(value) {
51
+ if (!isRecord(value))
52
+ return value;
53
+ if (value.type === "text" || value.type === "reasoning")
54
+ return rename(value, "state", "native");
55
+ // A tool part's own `state` is its lifecycle status, not native data.
56
+ if (value.type === "tool")
57
+ return toolResult(rename(value, "providerState", "native"));
58
+ return value;
59
+ }
60
+ /** Kept text a summary compaction stored before it referenced `metadata.keepID`; replay still reads it. */
61
+ function recent(data) {
62
+ const text = data.recent;
63
+ const rest = omit(data, "recent");
64
+ if (typeof text !== "string" || !text)
65
+ return rest;
66
+ const metadata = isRecord(rest.metadata) ? rest.metadata : {};
67
+ return { ...rest, metadata: { recent: text, ...metadata } };
68
+ }
69
+ /** The window moves to `native.messages`; the `native` stored beside it was never replayed. */
70
+ function providerContext(data) {
71
+ const context = data.providerContext;
72
+ const rest = omit(data, "providerContext");
73
+ if (!isRecord(context))
74
+ return rest;
75
+ return {
76
+ ...rest,
77
+ native: { messages: Array.isArray(context.messages) ? context.messages.map(media) : context.messages },
78
+ };
79
+ }
80
+ /** Before 2.0.15, window media parts stored `mediaType` and base64 `data` directly. */
81
+ function media(message) {
82
+ if (!isRecord(message) || !Array.isArray(message.content))
83
+ return message;
84
+ return {
85
+ ...message,
86
+ content: message.content.map((part) => {
87
+ if (!isRecord(part) || part.type !== "media" || part.media !== undefined || typeof part.data !== "string")
88
+ return part;
89
+ const { mediaType, data, ...rest } = part;
90
+ return { ...rest, media: { source: { type: "base64", data, mediaType } } };
91
+ }),
92
+ };
93
+ }
94
+ function omit(value, key) {
95
+ if (!(key in value))
96
+ return value;
97
+ const { [key]: _, ...rest } = value;
98
+ return rest;
99
+ }
100
+ // Result data now merges into the tool's single `native`, as projection does for current result events.
101
+ function toolResult(value) {
102
+ if (!("providerResultState" in value))
103
+ return value;
104
+ const { providerResultState, ...rest } = value;
105
+ if (!isRecord(providerResultState))
106
+ return rest;
107
+ return { ...rest, native: { ...(isRecord(rest.native) ? rest.native : {}), ...providerResultState } };
108
+ }
109
+ // The current name wins when a payload carries both.
110
+ function rename(value, from, to) {
111
+ if (!(from in value))
112
+ return value;
113
+ const { [from]: moved, ...rest } = value;
114
+ return to in rest ? rest : { ...rest, [to]: moved };
115
+ }
116
+ function isRecord(value) {
117
+ return typeof value === "object" && value !== null && !Array.isArray(value);
118
+ }