@meshagent/meshagent-agents 0.47.0 → 0.48.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.
@@ -13,6 +13,7 @@ export const agentThreadLoadedType = "meshagent.agent.thread.loaded";
13
13
  export const agentThreadStartRejectedType = "meshagent.agent.thread.start.rejected";
14
14
  export const agentThreadOpenType = "meshagent.agent.thread.open";
15
15
  export const agentThreadCloseType = "meshagent.agent.thread.close";
16
+ export const agentMessagesInjectType = "meshagent.agent.messages.inject";
16
17
  export const agentParticipantConnectType = "meshagent.agent.participant.connect";
17
18
  export const agentParticipantDisconnectType = "meshagent.agent.participant.disconnect";
18
19
  export const agentThreadDeleteType = "meshagent.agent.thread.delete";
@@ -82,6 +83,33 @@ export const agentToolApproveType = "meshagent.agent.tool_call.approve";
82
83
  export const agentToolRejectType = "meshagent.agent.tool_call.reject";
83
84
  export const agentSecretResponseType = "meshagent.agent.secret.response";
84
85
  export const agentClientToolCallResponseType = "meshagent.agent.client_tool_call.response";
86
+ export class AgentFileContent {
87
+ constructor({ url, name }) {
88
+ this.type = "file";
89
+ this.url = url;
90
+ this.name = name;
91
+ }
92
+ static fromJson(json) {
93
+ return new AgentFileContent({
94
+ url: requiredString(json, "url"),
95
+ name: stringOrNull(json.name),
96
+ });
97
+ }
98
+ toJson() {
99
+ return {
100
+ type: this.type,
101
+ url: this.url,
102
+ ...(this.name != null ? { name: this.name } : {}),
103
+ };
104
+ }
105
+ formatWith(values) {
106
+ const format = (value) => value.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (token, key) => values[key] ?? token);
107
+ return new AgentFileContent({
108
+ url: format(this.url),
109
+ name: this.name == null ? undefined : format(this.name),
110
+ });
111
+ }
112
+ }
85
113
  const globalScope = globalThis;
86
114
  function hasOwn(value, key) {
87
115
  return Object.prototype.hasOwnProperty.call(value, key);
@@ -129,13 +157,6 @@ function requiredString(json, key) {
129
157
  }
130
158
  throw new TypeError(`missing string field '${key}'`);
131
159
  }
132
- function requiredInt(json, key) {
133
- const value = intOrNull(json[key]);
134
- if (value !== undefined) {
135
- return value;
136
- }
137
- throw new TypeError(`missing integer field '${key}'`);
138
- }
139
160
  function requiredMap(json, key) {
140
161
  const value = dynamicMapOrNull(json[key]);
141
162
  if (value != null) {
@@ -216,7 +237,7 @@ function inputContentFromJson(value) {
216
237
  return { type: "text", text: requiredString(json, "text") };
217
238
  }
218
239
  if (json.type === "file") {
219
- return { type: "file", url: requiredString(json, "url") };
240
+ return AgentFileContent.fromJson(json);
220
241
  }
221
242
  throw new TypeError("unsupported agent input content type");
222
243
  }
@@ -233,7 +254,17 @@ function objectList(value, fromJson) {
233
254
  if (!Array.isArray(value)) {
234
255
  return [];
235
256
  }
236
- return value.map((entry) => fromJson(requiredObjectValue(entry)));
257
+ return value.map((entry) => (entry != null && typeof entry === "object" && typeof entry.toJson === "function"
258
+ ? entry
259
+ : fromJson(requiredObjectValue(entry))));
260
+ }
261
+ function agentMessageList(value) {
262
+ if (!Array.isArray(value)) {
263
+ return [];
264
+ }
265
+ return value.map((entry) => (entry instanceof AgentMessage
266
+ ? entry
267
+ : AgentMessage.fromJson(requiredObjectValue(entry))));
237
268
  }
238
269
  function mapListOrNull(value) {
239
270
  if (!Array.isArray(value)) {
@@ -272,16 +303,19 @@ function maybeToJson(value) {
272
303
  return value != null && typeof value.toJson === "function" ? value.toJson() : value;
273
304
  }
274
305
  function contentToJson(value) {
275
- return { ...value };
306
+ return value instanceof AgentFileContent ? value.toJson() : { ...value };
276
307
  }
277
308
  function objectOrNull(value, fromJson) {
309
+ if (value != null && typeof value === "object" && typeof value.toJson === "function") {
310
+ return value;
311
+ }
278
312
  const map = dynamicMapOrNull(value);
279
313
  return map == null ? undefined : fromJson(map);
280
314
  }
281
315
  export class ToolChoice {
282
- constructor({ toolkitName, toolName, toolkit_name, tool_name }) {
283
- this.toolkitName = String(toolkitName ?? toolkit_name);
284
- this.toolName = String(toolName ?? tool_name);
316
+ constructor({ toolkitName, toolName }) {
317
+ this.toolkitName = toolkitName;
318
+ this.toolName = toolName;
285
319
  }
286
320
  static fromJson(json) {
287
321
  return new ToolChoice({ toolkitName: requiredString(json, "toolkit_name"), toolName: requiredString(json, "tool_name") });
@@ -292,7 +326,7 @@ export class ToolChoice {
292
326
  }
293
327
  export class TurnMcpConfig {
294
328
  constructor({ servers = [] } = {}) {
295
- this.servers = mapListOrNull(servers) ?? [];
329
+ this.servers = servers;
296
330
  }
297
331
  static fromJson(json) {
298
332
  return new TurnMcpConfig({ servers: mapListOrNull(json.servers) ?? [] });
@@ -302,18 +336,18 @@ export class TurnMcpConfig {
302
336
  }
303
337
  }
304
338
  export class ClientToolkitDescription {
305
- constructor({ name, title, description, inputSchema, input_schema }) {
306
- this.name = String(name);
307
- this.title = stringOrNull(title);
308
- this.description = stringOrNull(description);
309
- this.inputSchema = dynamicMapOrNull(inputSchema ?? input_schema) ?? {};
339
+ constructor({ name, title, description, inputSchema }) {
340
+ this.name = name;
341
+ this.title = title;
342
+ this.description = description;
343
+ this.inputSchema = inputSchema;
310
344
  }
311
345
  static fromJson(json) {
312
346
  return new ClientToolkitDescription({
313
347
  name: requiredString(json, "name"),
314
348
  title: stringOrNull(json.title),
315
349
  description: stringOrNull(json.description),
316
- inputSchema: dynamicMapOrNull(json.input_schema ?? json.inputSchema) ?? requiredMap(json, "input_schema"),
350
+ inputSchema: requiredMap(json, "input_schema"),
317
351
  });
318
352
  }
319
353
  toJson() {
@@ -326,8 +360,8 @@ export class ClientToolkitDescription {
326
360
  }
327
361
  }
328
362
  export class TurnToolkitConfig {
329
- constructor({ clientOptions, client_options } = {}) {
330
- this.clientOptions = dynamicMapOrNull(clientOptions ?? client_options);
363
+ constructor({ clientOptions } = {}) {
364
+ this.clientOptions = clientOptions;
331
365
  }
332
366
  static fromJson(json) {
333
367
  return new TurnToolkitConfig({ clientOptions: dynamicMapOrNull(json.client_options) });
@@ -350,15 +384,15 @@ function turnMcpConfigOrNull(value) {
350
384
  return objectOrNull(value, TurnMcpConfig.fromJson);
351
385
  }
352
386
  export class AgentAudioFormat {
353
- constructor({ type = "audio/pcm", sampleRate, sample_rate, bitrate } = {}) {
354
- this.type = String(type);
355
- this.sampleRate = intOrNull(sampleRate ?? sample_rate);
356
- this.bitrate = intOrNull(bitrate);
387
+ constructor({ type = "audio/pcm", sampleRate = 24000, bitrate } = {}) {
388
+ this.type = type;
389
+ this.sampleRate = sampleRate ?? undefined;
390
+ this.bitrate = bitrate;
357
391
  }
358
392
  static fromJson(json) {
359
393
  return new AgentAudioFormat({
360
394
  type: stringOrNull(json.type) ?? "audio/pcm",
361
- sampleRate: intOrNull(json.sample_rate),
395
+ sampleRate: intOrNull(json.sample_rate) ?? null,
362
396
  bitrate: intOrNull(json.bitrate),
363
397
  });
364
398
  }
@@ -390,9 +424,9 @@ export class AgentError {
390
424
  }
391
425
  export class ToolkitToolCapabilities {
392
426
  constructor({ name, title, description }) {
393
- this.name = String(name);
394
- this.title = stringOrNull(title);
395
- this.description = stringOrNull(description);
427
+ this.name = name;
428
+ this.title = title;
429
+ this.description = description;
396
430
  }
397
431
  static fromJson(json) {
398
432
  return new ToolkitToolCapabilities({
@@ -410,25 +444,31 @@ export class ToolkitToolCapabilities {
410
444
  }
411
445
  }
412
446
  export class ToolkitCapabilities {
413
- constructor(params) {
414
- this.name = String(params.name);
415
- this.title = stringOrNull(params.title);
416
- this.description = stringOrNull(params.description);
417
- this.thumbnailUrl = stringOrNull(params.thumbnailUrl ?? params.thumbnail_url);
418
- this.rules = stringList(params.rules);
419
- this.clientOptions = dynamicMapOrNull(params.clientOptions ?? params.client_options);
420
- this.hidden = params.hidden === true;
421
- this.tools = Array.isArray(params.tools) ? params.tools.map((entry) => entry instanceof ToolkitToolCapabilities ? entry : ToolkitToolCapabilities.fromJson(requiredObjectValue(entry))) : [];
447
+ constructor({ name, title, description, rules = [], clientOptions, hidden = false, tools = [] }) {
448
+ this.name = name;
449
+ this.title = title;
450
+ this.description = description;
451
+ this.rules = rules;
452
+ this.clientOptions = clientOptions;
453
+ this.hidden = hidden;
454
+ this.tools = tools;
422
455
  }
423
456
  static fromJson(json) {
424
- return new ToolkitCapabilities(json);
457
+ return new ToolkitCapabilities({
458
+ name: requiredString(json, "name"),
459
+ title: stringOrNull(json.title),
460
+ description: stringOrNull(json.description),
461
+ rules: stringList(json.rules),
462
+ clientOptions: dynamicMapOrNull(json.client_options),
463
+ hidden: json.hidden === true,
464
+ tools: objectList(json.tools, ToolkitToolCapabilities.fromJson),
465
+ });
425
466
  }
426
467
  toJson() {
427
468
  return {
428
469
  name: this.name,
429
470
  ...(this.title != null ? { title: this.title } : {}),
430
471
  ...(this.description != null ? { description: this.description } : {}),
431
- ...(this.thumbnailUrl != null ? { thumbnail_url: this.thumbnailUrl } : {}),
432
472
  rules: this.rules,
433
473
  ...(this.clientOptions != null ? { client_options: this.clientOptions } : {}),
434
474
  hidden: this.hidden,
@@ -437,23 +477,41 @@ export class ToolkitCapabilities {
437
477
  }
438
478
  }
439
479
  export class AgentModelInfo {
440
- constructor(params) {
441
- this.name = String(params.name);
442
- this.friendlyName = stringOrNull(params.friendlyName ?? params.friendly_name);
443
- this.description = stringOrNull(params.description);
444
- this.contextWindow = intOrNull(params.contextWindow ?? params.context_window);
445
- this.pricing = doubleMapOrNull(params.pricing);
446
- this.modalities = stringList(params.modalities, ["text"]);
447
- this.availableVoices = stringList(params.availableVoices ?? params.available_voices);
448
- this.defaultOutputVoice = stringOrNull(params.defaultOutputVoice ?? params.default_output_voice);
449
- this.inputFormat = params.inputFormat instanceof AgentAudioFormat ? params.inputFormat : audioFormatOrNull(params.inputFormat ?? params.input_format);
450
- this.outputFormat = params.outputFormat instanceof AgentAudioFormat ? params.outputFormat : audioFormatOrNull(params.outputFormat ?? params.output_format);
451
- this.turnDetection = stringOrNull(params.turnDetection ?? params.turn_detection);
452
- this.realtimeProtocols = stringList(params.realtimeProtocols ?? params.realtime_protocols);
453
- this.active = params.active === true;
480
+ constructor({ name, friendlyName, description, contextWindow, pricing, modalities = ["text"], availableVoices = [], defaultOutputVoice, inputFormat, outputFormat, turnDetection, realtimeProtocols = [], supportsAttachments = false, accepts = [], active = false }) {
481
+ this.name = name;
482
+ this.friendlyName = friendlyName;
483
+ this.description = description;
484
+ this.contextWindow = contextWindow;
485
+ this.pricing = pricing;
486
+ this.modalities = modalities;
487
+ this.availableVoices = availableVoices;
488
+ this.defaultOutputVoice = defaultOutputVoice;
489
+ this.inputFormat = inputFormat;
490
+ this.outputFormat = outputFormat;
491
+ this.turnDetection = turnDetection;
492
+ this.realtimeProtocols = realtimeProtocols;
493
+ this.supportsAttachments = supportsAttachments;
494
+ this.accepts = accepts;
495
+ this.active = active;
454
496
  }
455
497
  static fromJson(json) {
456
- return new AgentModelInfo(json);
498
+ return new AgentModelInfo({
499
+ name: requiredString(json, "name"),
500
+ friendlyName: stringOrNull(json.friendly_name),
501
+ description: stringOrNull(json.description),
502
+ contextWindow: intOrNull(json.context_window),
503
+ pricing: doubleMapOrNull(json.pricing),
504
+ modalities: stringList(json.modalities, ["text"]),
505
+ availableVoices: stringList(json.available_voices),
506
+ defaultOutputVoice: stringOrNull(json.default_output_voice),
507
+ inputFormat: audioFormatOrNull(json.input_format),
508
+ outputFormat: audioFormatOrNull(json.output_format),
509
+ turnDetection: stringOrNull(json.turn_detection),
510
+ realtimeProtocols: stringList(json.realtime_protocols),
511
+ supportsAttachments: json.supports_attachments === true,
512
+ accepts: stringList(json.accepts),
513
+ active: json.active === true,
514
+ });
457
515
  }
458
516
  toJson() {
459
517
  return {
@@ -469,21 +527,30 @@ export class AgentModelInfo {
469
527
  ...(this.outputFormat != null ? { output_format: this.outputFormat.toJson() } : {}),
470
528
  ...(this.turnDetection != null ? { turn_detection: this.turnDetection } : {}),
471
529
  realtime_protocols: this.realtimeProtocols,
530
+ supports_attachments: this.supportsAttachments,
531
+ accepts: this.accepts,
472
532
  active: this.active,
473
533
  };
474
534
  }
475
535
  }
476
536
  export class AgentProviderInfo {
477
- constructor(params) {
478
- this.name = String(params.name);
479
- this.friendlyName = String(params.friendlyName ?? params.friendly_name);
480
- this.description = stringOrNull(params.description);
481
- this.backend = stringOrNull(params.backend);
482
- this.defaultModel = String(params.defaultModel ?? params.default_model);
483
- this.models = Array.isArray(params.models) ? params.models.map((entry) => entry instanceof AgentModelInfo ? entry : AgentModelInfo.fromJson(requiredObjectValue(entry))) : [];
537
+ constructor({ name, friendlyName, description, backend, defaultModel, models = [] }) {
538
+ this.name = name;
539
+ this.friendlyName = friendlyName;
540
+ this.description = description;
541
+ this.backend = backend;
542
+ this.defaultModel = defaultModel;
543
+ this.models = models;
484
544
  }
485
545
  static fromJson(json) {
486
- return new AgentProviderInfo(json);
546
+ return new AgentProviderInfo({
547
+ name: requiredString(json, "name"),
548
+ friendlyName: requiredString(json, "friendly_name"),
549
+ description: stringOrNull(json.description),
550
+ backend: stringOrNull(json.backend),
551
+ defaultModel: requiredString(json, "default_model"),
552
+ models: objectList(json.models, AgentModelInfo.fromJson),
553
+ });
487
554
  }
488
555
  toJson() {
489
556
  return {
@@ -497,16 +564,16 @@ export class AgentProviderInfo {
497
564
  }
498
565
  }
499
566
  export class AgentThreadListEntry {
500
- constructor(params) {
501
- this.path = String(params.path);
502
- this.name = String(params.name ?? "");
503
- this.createdAt = String(params.createdAt ?? params.created_at ?? "");
504
- this.modifiedAt = String(params.modifiedAt ?? params.modified_at ?? "");
567
+ constructor({ path, name, createdAt, modifiedAt }) {
568
+ this.path = path;
569
+ this.name = name;
570
+ this.createdAt = createdAt;
571
+ this.modifiedAt = modifiedAt;
505
572
  }
506
573
  static fromJson(json) {
507
574
  return new AgentThreadListEntry({
508
575
  path: requiredString(json, "path"),
509
- name: stringOrNull(json.name) ?? "",
576
+ name: requiredString(json, "name"),
510
577
  createdAt: stringOrNull(json.created_at) ?? "",
511
578
  modifiedAt: stringOrNull(json.modified_at) ?? "",
512
579
  });
@@ -521,11 +588,11 @@ export class AgentThreadListEntry {
521
588
  }
522
589
  }
523
590
  export class AgentRealtimeConnectionInfo {
524
- constructor(params) {
525
- this.protocol = String(params.protocol);
526
- this.url = String(params.url);
527
- this.headers = stringMap(params.headers);
528
- this.webOnlyProtocol = stringOrNull(params.webOnlyProtocol ?? params.web_only_protocol);
591
+ constructor({ protocol, url, headers = {}, webOnlyProtocol }) {
592
+ this.protocol = protocol;
593
+ this.url = url;
594
+ this.headers = headers;
595
+ this.webOnlyProtocol = webOnlyProtocol;
529
596
  }
530
597
  static fromJson(json) {
531
598
  return new AgentRealtimeConnectionInfo({
@@ -546,8 +613,8 @@ export class AgentRealtimeConnectionInfo {
546
613
  }
547
614
  export class AgentToolCallLogLine {
548
615
  constructor({ source, text }) {
549
- this.source = String(source);
550
- this.text = String(text);
616
+ this.source = source;
617
+ this.text = text;
551
618
  }
552
619
  static fromJson(json) {
553
620
  return new AgentToolCallLogLine({ source: requiredString(json, "source"), text: requiredString(json, "text") });
@@ -557,17 +624,25 @@ export class AgentToolCallLogLine {
557
624
  }
558
625
  }
559
626
  export class AgentGeneratedImage {
560
- constructor(params = {}) {
561
- this.uri = stringOrNull(params.uri);
562
- this.mimeType = stringOrNull(params.mimeType ?? params.mime_type);
563
- this.createdAt = stringOrNull(params.createdAt ?? params.created_at);
564
- this.createdBy = stringOrNull(params.createdBy ?? params.created_by);
565
- this.width = numOrNull(params.width);
566
- this.height = numOrNull(params.height);
567
- this.status = stringOrNull(params.status);
627
+ constructor({ uri, mimeType, createdAt, createdBy, width, height, status } = {}) {
628
+ this.uri = uri;
629
+ this.mimeType = mimeType;
630
+ this.createdAt = createdAt;
631
+ this.createdBy = createdBy;
632
+ this.width = width;
633
+ this.height = height;
634
+ this.status = status;
568
635
  }
569
636
  static fromJson(json) {
570
- return new AgentGeneratedImage(json);
637
+ return new AgentGeneratedImage({
638
+ uri: stringOrNull(json.uri),
639
+ mimeType: stringOrNull(json.mime_type),
640
+ createdAt: stringOrNull(json.created_at),
641
+ createdBy: stringOrNull(json.created_by),
642
+ width: numOrNull(json.width),
643
+ height: numOrNull(json.height),
644
+ status: stringOrNull(json.status),
645
+ });
571
646
  }
572
647
  toJson() {
573
648
  return omitUndefined({
@@ -582,16 +657,23 @@ export class AgentGeneratedImage {
582
657
  }
583
658
  }
584
659
  export class AgentGeneratedAudio {
585
- constructor(params = {}) {
586
- this.uri = stringOrNull(params.uri);
587
- this.mimeType = stringOrNull(params.mimeType ?? params.mime_type);
588
- this.createdAt = stringOrNull(params.createdAt ?? params.created_at);
589
- this.createdBy = stringOrNull(params.createdBy ?? params.created_by);
590
- this.status = stringOrNull(params.status);
591
- this.transcript = stringOrNull(params.transcript);
660
+ constructor({ uri, mimeType, createdAt, createdBy, status, transcript } = {}) {
661
+ this.uri = uri;
662
+ this.mimeType = mimeType;
663
+ this.createdAt = createdAt;
664
+ this.createdBy = createdBy;
665
+ this.status = status;
666
+ this.transcript = transcript;
592
667
  }
593
668
  static fromJson(json) {
594
- return new AgentGeneratedAudio(json);
669
+ return new AgentGeneratedAudio({
670
+ uri: stringOrNull(json.uri),
671
+ mimeType: stringOrNull(json.mime_type),
672
+ createdAt: stringOrNull(json.created_at),
673
+ createdBy: stringOrNull(json.created_by),
674
+ status: stringOrNull(json.status),
675
+ transcript: stringOrNull(json.transcript),
676
+ });
595
677
  }
596
678
  toJson() {
597
679
  return omitUndefined({
@@ -605,11 +687,11 @@ export class AgentGeneratedAudio {
605
687
  }
606
688
  }
607
689
  export class AgentContextWindowUsage {
608
- constructor(params) {
609
- this.usedTokens = Number(params.usedTokens ?? params.used_tokens);
610
- this.totalTokens = intOrNull(params.totalTokens ?? params.total_tokens);
611
- this.compactionMode = stringOrNull(params.compactionMode ?? params.compaction_mode);
612
- this.compactionThreshold = intOrNull(params.compactionThreshold ?? params.compaction_threshold);
690
+ constructor({ usedTokens, totalTokens, compactionMode, compactionThreshold }) {
691
+ this.usedTokens = usedTokens;
692
+ this.totalTokens = totalTokens;
693
+ this.compactionMode = compactionMode;
694
+ this.compactionThreshold = compactionThreshold;
613
695
  }
614
696
  static fromJson(json) {
615
697
  const usedTokens = intOrNull(json.used_tokens ?? json.usedTokens) ?? 0;
@@ -638,19 +720,22 @@ export class AgentMessage {
638
720
  const resolvedMessageId = stringOrNull(messageId ?? message_id)?.trim();
639
721
  this.messageId = resolvedMessageId == null || resolvedMessageId.length === 0 ? uuidv4() : resolvedMessageId;
640
722
  this.senderName = stringOrNull(senderName ?? sender_name);
641
- this.createdAt = stringOrNull(createdAt ?? created_at) ?? new Date().toISOString();
723
+ const createdAtValue = createdAt ?? created_at;
724
+ const parsedCreatedAt = createdAtValue instanceof Date ? createdAtValue : new Date(String(createdAtValue ?? ""));
725
+ this.createdAtUtc = Number.isNaN(parsedCreatedAt.getTime()) ? new Date() : parsedCreatedAt;
642
726
  this.metadata = dynamicMapOrNull(metadata) ?? {};
643
727
  }
644
728
  toJson() {
645
729
  return {
646
730
  type: this.type,
647
731
  message_id: this.messageId,
648
- created_at: this.createdAt,
732
+ created_at: this.createdAtUtc.toISOString(),
649
733
  ...(Object.keys(this.metadata).length > 0 ? { metadata: this.metadata } : {}),
650
734
  ...(this.senderName != null ? { sender_name: this.senderName } : {}),
651
735
  };
652
736
  }
653
737
  static fromJson(json) {
738
+ json = normalizeAgentMessageJson(json);
654
739
  const type = json.type;
655
740
  if (typeof type !== "string" || type.trim() === "") {
656
741
  throw new TypeError("missing string field 'type'");
@@ -690,9 +775,55 @@ function register(type, ctor) {
690
775
  messageConstructors[type] = ctor;
691
776
  return ctor;
692
777
  }
693
- function makeMessageClass({ type, base = "message", fields = [], }) {
778
+ const agentMessageTypesWithRequiredItemId = new Set([
779
+ agentReasoningContentStartedType,
780
+ agentReasoningContentDeltaType,
781
+ agentReasoningContentEndedType,
782
+ agentTextContentStartedType,
783
+ agentTextContentDeltaType,
784
+ agentTextContentEndedType,
785
+ agentFileContentStartedType,
786
+ agentFileContentDeltaType,
787
+ agentFileContentEndedType,
788
+ agentToolCallPendingType,
789
+ agentToolCallInProgressType,
790
+ agentToolCallStartedType,
791
+ agentToolCallArgumentsDeltaType,
792
+ agentToolCallLogDeltaType,
793
+ agentToolCallEndedType,
794
+ agentToolCallApprovalRequestedType,
795
+ agentImageGenerationStartedType,
796
+ agentImageGenerationPartialType,
797
+ agentImageGenerationCompletedType,
798
+ agentImageGenerationFailedType,
799
+ ]);
800
+ function normalizeAgentMessageJson(json) {
801
+ const type = stringOrNull(json.type);
802
+ if (type == null || !agentMessageTypesWithRequiredItemId.has(type) || normalizedString(json.item_id) != null) {
803
+ return json;
804
+ }
805
+ const itemId = fallbackItemId(json, type);
806
+ return itemId == null ? json : { ...json, item_id: itemId };
807
+ }
808
+ function fallbackItemId(json, type) {
809
+ const direct = normalizedString(json.itemId)
810
+ ?? normalizedString(json.id)
811
+ ?? normalizedString(json.call_id)
812
+ ?? normalizedString(json.request_id)
813
+ ?? normalizedString(json.message_id);
814
+ if (direct != null) {
815
+ return direct;
816
+ }
817
+ const turnId = normalizedString(json.turn_id) ?? normalizedString(json.turnId);
818
+ return turnId == null ? undefined : `${turnId}:${type}`;
819
+ }
820
+ function normalizedString(value) {
821
+ const normalized = stringOrNull(value)?.trim();
822
+ return normalized === "" ? undefined : normalized;
823
+ }
824
+ function makeMessageClass(className, { type, base = "message", fields = [], }) {
694
825
  const Parent = base === "llm" ? AgentLLMMessage : base === "thread" ? AgentThreadMessage : AgentMessage;
695
- return register(type, class extends Parent {
826
+ const GeneratedMessage = class extends Parent {
696
827
  constructor(params = {}) {
697
828
  super({ ...params, type });
698
829
  for (const field of fields) {
@@ -756,7 +887,9 @@ function makeMessageClass({ type, base = "message", fields = [], }) {
756
887
  }
757
888
  return json;
758
889
  }
759
- });
890
+ };
891
+ Object.defineProperty(GeneratedMessage, "name", { value: className });
892
+ return register(type, GeneratedMessage);
760
893
  }
761
894
  const s = (prop, json = snake(prop), required = false) => ({
762
895
  prop,
@@ -881,7 +1014,7 @@ const imageGeneration = [
881
1014
  { prop: "tool", json: "tool", from: (value) => stringOrNull(value) ?? "image_generation", default: () => "image_generation", always: true },
882
1015
  m("arguments"),
883
1016
  ];
884
- export const StartThread = makeMessageClass({
1017
+ export const StartThread = makeMessageClass("StartThread", {
885
1018
  type: agentThreadStartType,
886
1019
  fields: [
887
1020
  contentList("content", true),
@@ -899,96 +1032,114 @@ export const StartThread = makeMessageClass({
899
1032
  obj("toolChoice", "tool_choice", ToolChoice.fromJson),
900
1033
  ],
901
1034
  });
902
- export const TurnStart = makeMessageClass({ type: agentTurnStartType, base: "thread", fields: turnOptions });
903
- export const TurnSteer = makeMessageClass({ type: agentTurnSteerType, base: "thread", fields: [s("turnId", "turn_id", true), contentList("content")] });
904
- export const TurnInterrupt = makeMessageClass({ type: agentTurnInterruptType, base: "thread", fields: [s("turnId", "turn_id", true)] });
905
- export const AgentRealtimeAudioChunk = makeMessageClass({ type: agentRealtimeAudioChunkType, base: "thread", fields: [bytesField("data"), audioFormat("format", "format", true)] });
906
- export const AgentRealtimeAudioCommit = makeMessageClass({ type: agentRealtimeAudioCommitType, base: "thread", fields: [s("turnId"), s("text"), s("status"), s("transcriptionItemId")] });
907
- export const ClearThread = makeMessageClass({ type: agentThreadClearType, base: "thread" });
908
- export const OpenThread = makeMessageClass({ type: agentThreadOpenType, base: "thread", fields: [{ prop: "load", json: "load", from: (value) => typeof value === "boolean" ? value : undefined }, s("sinceTurn")] });
909
- export const CloseThread = makeMessageClass({ type: agentThreadCloseType, base: "thread" });
910
- export const ParticipantConnect = makeMessageClass({ type: agentParticipantConnectType, fields: [s("participantId"), s("participantName"), m("attributes")] });
911
- export const ParticipantDisconnect = makeMessageClass({ type: agentParticipantDisconnectType, fields: [s("participantId"), s("participantName"), s("reason")] });
912
- export const DeleteThread = makeMessageClass({ type: agentThreadDeleteType, base: "thread" });
913
- export const RenameThread = makeMessageClass({ type: agentThreadRenameType, base: "thread", fields: [s("name", "name", true)] });
914
- export const ListThreads = makeMessageClass({ type: agentThreadListType, fields: [{ prop: "limit", json: "limit", from: (value) => intOrNull(value) ?? 200, default: () => 200, always: true }, { prop: "offset", json: "offset", from: (value) => intOrNull(value) ?? 0, default: () => 0, always: true }] });
915
- export const WatchThreads = makeMessageClass({ type: agentThreadWatchType });
916
- export const UnwatchThreads = makeMessageClass({ type: agentThreadUnwatchType });
917
- export const ThreadsListed = makeMessageClass({ type: agentThreadListedType, fields: [s("sourceMessageId", "source_message_id", true), objList("threads", "threads", AgentThreadListEntry.fromJson, true), i("total"), i("offset"), i("limit")] });
918
- export const ThreadCreated = makeMessageClass({ type: agentThreadCreatedType, fields: [obj("thread", "thread", AgentThreadListEntry.fromJson, true)] });
919
- export const ThreadUpdated = makeMessageClass({ type: agentThreadUpdatedType, fields: [obj("thread", "thread", AgentThreadListEntry.fromJson, true)] });
920
- export const ThreadDeleted = makeMessageClass({ type: agentThreadDeletedType, fields: [s("path", "path", true)] });
921
- export const CapabilitiesRequest = makeMessageClass({ type: agentCapabilitiesRequestType, base: "thread" });
922
- export const CapabilitiesResponse = makeMessageClass({ type: agentCapabilitiesResponseType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true), s("version", "version", true), objList("toolkits", "toolkits", ToolkitCapabilities.fromJson, true)] });
923
- export const ModelsRequest = makeMessageClass({ type: agentModelsRequestType });
924
- export const ModelsResponse = makeMessageClass({ type: agentModelsResponseType, fields: [s("sourceMessageId", "source_message_id", true), objList("providers", "providers", AgentProviderInfo.fromJson, true)] });
925
- export const ChangeModel = makeMessageClass({ type: agentModelChangeType, base: "thread", fields: [s("backend"), s("provider"), s("model"), s("voice")] });
926
- export const AgentModelChanged = makeMessageClass({ type: agentModelChangedType, base: "thread", fields: [s("sourceMessageId"), s("backend"), s("provider", "provider", true), s("model", "model", true), s("voice"), audioFormat("inputFormat"), audioFormat("outputFormat"), s("turnDetection"), sl("outputModalities", "output_modalities", ["text"], true), sl("realtimeProtocols", "realtime_protocols", [], true), { prop: "supportsAttachments", json: "supports_attachments", from: (value) => value === true, default: () => false }, sl("accepts", "accepts", [], true)] });
927
- export const ThreadCleared = makeMessageClass({ type: agentThreadClearedType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true)] });
928
- export const TurnStartAccepted = makeMessageClass({ type: agentTurnStartAcceptedType, base: "thread", fields: [s("turnId"), s("sourceMessageId", "source_message_id", true), contentList("content")] });
929
- export const TurnStartRejected = makeMessageClass({ type: agentTurnStartRejectedType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
930
- export const TurnInterruptAccepted = makeMessageClass({ type: agentTurnInterruptAcceptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
931
- export const TurnInterrupted = makeMessageClass({ type: agentTurnInterruptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
932
- export const TurnSteerAccepted = makeMessageClass({ type: agentTurnSteerAcceptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true), contentList("content")] });
933
- export const TurnSteered = makeMessageClass({ type: agentTurnSteeredType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
934
- export const TurnSteerRejected = makeMessageClass({ type: agentTurnSteerRejectedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
935
- export const TurnStarted = makeMessageClass({ type: agentTurnStartedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
936
- export const TurnEnded = makeMessageClass({ type: agentTurnEndedType, base: "thread", fields: [s("turnId", "turn_id", true), obj("error", "error", AgentError.fromJson)] });
937
- export const ThreadStarted = makeMessageClass({ type: agentThreadStartedType, fields: [s("sourceMessageId", "source_message_id", true), s("threadId", "thread_id", true), obj("realtimeConnection", "realtime_connection", AgentRealtimeConnectionInfo.fromJson)] });
938
- export const ThreadLoaded = makeMessageClass({ type: agentThreadLoadedType, base: "thread", fields: [s("sourceMessageId"), s("sinceTurn")] });
939
- export const ThreadStartRejected = makeMessageClass({ type: agentThreadStartRejectedType, fields: [s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
940
- export const AgentReasoningContentStarted = makeMessageClass({ type: agentReasoningContentStartedType, base: "llm", fields: contentPart });
941
- export const AgentReasoningContentDelta = makeMessageClass({ type: agentReasoningContentDeltaType, base: "llm", fields: [...contentPart, s("text", "text", true)] });
942
- export const AgentReasoningContentEnded = makeMessageClass({ type: agentReasoningContentEndedType, base: "llm", fields: contentPart });
943
- export const AgentTextContentStarted = makeMessageClass({ type: agentTextContentStartedType, base: "llm", fields: [...contentPart, s("phase")] });
944
- export const AgentTextContentDelta = makeMessageClass({ type: agentTextContentDeltaType, base: "llm", fields: [...contentPart, s("phase"), s("text", "text", true)] });
945
- export const AgentTextContentEnded = makeMessageClass({ type: agentTextContentEndedType, base: "llm", fields: [...contentPart, s("phase")] });
946
- export const AgentFileContentStarted = makeMessageClass({ type: agentFileContentStartedType, base: "llm", fields: contentPart });
947
- export const AgentFileContentDelta = makeMessageClass({ type: agentFileContentDeltaType, base: "llm", fields: [...contentPart, s("url", "url", true)] });
948
- export const AgentFileContentEnded = makeMessageClass({ type: agentFileContentEndedType, base: "llm", fields: contentPart });
949
- export const AgentToolCallPending = makeMessageClass({ type: agentToolCallPendingType, base: "llm", fields: toolState });
950
- export const AgentToolCallInProgress = makeMessageClass({ type: agentToolCallInProgressType, base: "llm", fields: toolState });
951
- export const AgentToolCallStarted = makeMessageClass({ type: agentToolCallStartedType, base: "llm", fields: toolState });
952
- export const AgentToolCallArgumentsDelta = makeMessageClass({ type: agentToolCallArgumentsDeltaType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), s("delta", "delta", true)] });
953
- export const AgentToolCallLogDelta = makeMessageClass({ type: agentToolCallLogDeltaType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), objList("lines", "lines", AgentToolCallLogLine.fromJson, true)] });
954
- export const AgentToolCallEnded = makeMessageClass({ type: agentToolCallEndedType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), s("toolkit"), s("tool"), { prop: "result", json: "result", from: contentOrNull, to: contentHeader }, obj("error", "error", AgentError.fromJson)] });
955
- export const AgentToolCallApprovalRequested = makeMessageClass({ type: agentToolCallApprovalRequestedType, base: "llm", fields: toolState.filter((field) => field.prop !== "argumentBytes") });
956
- export const AgentSecretRequested = makeMessageClass({ type: agentSecretRequestedType, base: "llm", fields: [...contentPart, s("requestId", "request_id", true), s("name", "name", true), s("scope")] });
957
- export const AgentClientToolCallRequested = makeMessageClass({ type: agentClientToolCallRequestedType, base: "llm", fields: [...contentPart, s("requestId", "request_id", true), s("targetParticipantId"), s("toolkit", "toolkit", true), s("tool", "tool", true), m("arguments", "arguments", true)] });
958
- export const AgentClientToolCallCancelled = makeMessageClass({ type: agentClientToolCallCancelledType, base: "llm", fields: [...contentPart, s("requestId", "request_id", true), s("targetParticipantId"), s("reason")] });
959
- export const AgentThreadStatus = makeMessageClass({ type: agentThreadStatusType, base: "thread", fields: [s("status"), s("mode"), s("startedAt"), s("turnId"), s("pendingItemId"), i("totalBytes"), i("linesAdded"), i("linesRemoved")] });
960
- export const AgentConnectionStatus = makeMessageClass({ type: agentConnectionStatusType, fields: [s("status", "status", true), s("message"), s("reason"), n("retryInSeconds"), s("participantId")] });
961
- export const AgentThreadEvent = makeMessageClass({ type: agentThreadEventType, base: "llm", fields: [m("event", "event", true)] });
962
- export const AgentImageGenerationStarted = makeMessageClass({ type: agentImageGenerationStartedType, base: "llm", fields: imageGeneration });
963
- export const AgentImageGenerationPartial = makeMessageClass({ type: agentImageGenerationPartialType, base: "llm", fields: [...imageGeneration, obj("image", "image", AgentGeneratedImage.fromJson), i("partialIndex")] });
964
- export const AgentImageGenerationCompleted = makeMessageClass({ type: agentImageGenerationCompletedType, base: "llm", fields: [...imageGeneration, objList("images", "images", AgentGeneratedImage.fromJson, true)] });
965
- export const AgentImageGenerationFailed = makeMessageClass({ type: agentImageGenerationFailedType, base: "llm", fields: [...imageGeneration, obj("error", "error", AgentError.fromJson)] });
966
- export const AgentAudioGenerationStarted = makeMessageClass({ type: agentAudioGenerationStartedType, base: "llm", fields: responsePart });
967
- export const AgentAudioGenerationDelta = makeMessageClass({ type: agentAudioGenerationDeltaType, base: "llm", fields: [...responsePart, bytesField("data"), s("mimeType"), audioFormat("outputFormat")] });
968
- export const AgentAudioGenerationCompleted = makeMessageClass({ type: agentAudioGenerationCompletedType, base: "llm", fields: [...responsePart, obj("audio", "audio", AgentGeneratedAudio.fromJson), audioFormat("outputFormat")] });
969
- export const AgentAudioGenerationFailed = makeMessageClass({ type: agentAudioGenerationFailedType, base: "llm", fields: [...responsePart, obj("error", "error", AgentError.fromJson)] });
970
- export const AgentAudioTranscriptionStarted = makeMessageClass({ type: agentAudioTranscriptionStartedType, base: "llm", fields: [...responsePart, s("role")] });
971
- export const AgentAudioTranscriptionDelta = makeMessageClass({ type: agentAudioTranscriptionDeltaType, base: "llm", fields: [...responsePart, s("role"), s("text", "text", true)] });
972
- export const AgentAudioTranscriptionCompleted = makeMessageClass({ type: agentAudioTranscriptionCompletedType, base: "llm", fields: [...responsePart, s("role"), s("text")] });
973
- export const AgentAudioTranscriptionFailed = makeMessageClass({ type: agentAudioTranscriptionFailedType, base: "llm", fields: [...responsePart, s("role"), obj("error", "error", AgentError.fromJson)] });
974
- export const AgentAudioInputSpeechStarted = makeMessageClass({ type: agentAudioInputSpeechStartedType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId"), i("audioStartMs")] });
975
- export const AgentAudioInputSpeechEnded = makeMessageClass({ type: agentAudioInputSpeechEndedType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId"), i("audioEndMs")] });
976
- export const AgentContextCompacted = makeMessageClass({ type: agentContextCompactedType, base: "thread", fields: [s("checkpointId", "checkpoint_id", true), s("path", "path", true), i("throughSequence", "through_sequence", true), s("createdAt"), { prop: "messages", json: "messages", from: mapListOrNull }] });
977
- export const AgentUsageUpdated = makeMessageClass({ type: agentUsageUpdatedType, base: "thread", fields: [s("turnId"), { prop: "usage", json: "usage", from: doubleMap, default: () => ({}), always: true }, obj("contextWindow", "context_window", AgentContextWindowUsage.fromJson, true)] });
978
- export const ApproveAgentToolCall = makeMessageClass({ type: agentToolApproveType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId", "item_id", true)] });
979
- export const RejectAgentToolCall = makeMessageClass({ type: agentToolRejectType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId", "item_id", true)] });
980
- export const AgentSecretResponse = makeMessageClass({ type: agentSecretResponseType, base: "thread", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("value"), obj("error", "error", AgentError.fromJson)] });
981
- export const AgentClientToolCallResponse = makeMessageClass({ type: agentClientToolCallResponseType, base: "thread", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), { prop: "response", json: "response", from: contentOrNull, to: contentHeader }] });
982
- export function agentInputContent({ text, attachments }) {
1035
+ export const TurnStart = makeMessageClass("TurnStart", { type: agentTurnStartType, base: "thread", fields: turnOptions });
1036
+ export const TurnSteer = makeMessageClass("TurnSteer", { type: agentTurnSteerType, base: "thread", fields: [s("turnId", "turn_id", true), contentList("content")] });
1037
+ export const TurnInterrupt = makeMessageClass("TurnInterrupt", { type: agentTurnInterruptType, base: "thread", fields: [s("turnId", "turn_id", true)] });
1038
+ export const AgentRealtimeAudioChunk = makeMessageClass("AgentRealtimeAudioChunk", { type: agentRealtimeAudioChunkType, base: "thread", fields: [bytesField("data"), audioFormat("format", "format", true)] });
1039
+ export const AgentRealtimeAudioCommit = makeMessageClass("AgentRealtimeAudioCommit", { type: agentRealtimeAudioCommitType, base: "thread", fields: [s("turnId"), s("text"), s("status"), s("transcriptionItemId")] });
1040
+ export const ClearThread = makeMessageClass("ClearThread", { type: agentThreadClearType, base: "thread" });
1041
+ export const OpenThread = makeMessageClass("OpenThread", { type: agentThreadOpenType, base: "thread", fields: [s("backend"), { prop: "load", json: "load", from: (value) => typeof value === "boolean" ? value : undefined }, s("sinceTurn")] });
1042
+ export const CloseThread = makeMessageClass("CloseThread", { type: agentThreadCloseType, base: "thread" });
1043
+ export const InjectMessages = makeMessageClass("InjectMessages", {
1044
+ type: agentMessagesInjectType,
1045
+ base: "thread",
1046
+ fields: [{
1047
+ prop: "messages",
1048
+ json: "messages",
1049
+ from: agentMessageList,
1050
+ default: () => [],
1051
+ always: true,
1052
+ to: (messages) => messages.map((message) => message.toJson()),
1053
+ }],
1054
+ });
1055
+ export const ParticipantConnect = makeMessageClass("ParticipantConnect", { type: agentParticipantConnectType, fields: [s("participantId", "participant_id", true)] });
1056
+ export const ParticipantDisconnect = makeMessageClass("ParticipantDisconnect", { type: agentParticipantDisconnectType, fields: [s("participantId", "participant_id", true)] });
1057
+ export const DeleteThread = makeMessageClass("DeleteThread", { type: agentThreadDeleteType, base: "thread" });
1058
+ export const RenameThread = makeMessageClass("RenameThread", { type: agentThreadRenameType, base: "thread", fields: [s("name", "name", true)] });
1059
+ export const ListThreads = makeMessageClass("ListThreads", { type: agentThreadListType, fields: [{ prop: "limit", json: "limit", from: (value) => intOrNull(value) ?? 200, default: () => 200, always: true }, { prop: "offset", json: "offset", from: (value) => intOrNull(value) ?? 0, default: () => 0, always: true }] });
1060
+ export const WatchThreads = makeMessageClass("WatchThreads", { type: agentThreadWatchType });
1061
+ export const UnwatchThreads = makeMessageClass("UnwatchThreads", { type: agentThreadUnwatchType });
1062
+ export const ThreadsListed = makeMessageClass("ThreadsListed", { type: agentThreadListedType, fields: [s("sourceMessageId", "source_message_id", true), { prop: "threads", json: "threads", from: (value) => objectList(value, AgentThreadListEntry.fromJson), default: () => [], always: true, to: (value) => value.map(maybeToJson) }, { prop: "total", json: "total", from: intOrNull, default: (params) => Array.isArray(params.threads) ? params.threads.length : 0, always: true }, { prop: "offset", json: "offset", from: (value) => intOrNull(value) ?? 0, default: () => 0, always: true }, { prop: "limit", json: "limit", from: intOrNull, default: (params) => Array.isArray(params.threads) ? params.threads.length : 0, always: true }] });
1063
+ export const ThreadCreated = makeMessageClass("ThreadCreated", { type: agentThreadCreatedType, fields: [obj("thread", "thread", AgentThreadListEntry.fromJson, true)] });
1064
+ export const ThreadUpdated = makeMessageClass("ThreadUpdated", { type: agentThreadUpdatedType, fields: [obj("thread", "thread", AgentThreadListEntry.fromJson, true)] });
1065
+ export const ThreadDeleted = makeMessageClass("ThreadDeleted", { type: agentThreadDeletedType, fields: [s("path", "path", true)] });
1066
+ export const CapabilitiesRequest = makeMessageClass("CapabilitiesRequest", { type: agentCapabilitiesRequestType, base: "thread" });
1067
+ export const CapabilitiesResponse = makeMessageClass("CapabilitiesResponse", { type: agentCapabilitiesResponseType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true), s("version", "version", true), { prop: "toolkits", json: "toolkits", from: (value) => objectList(value, ToolkitCapabilities.fromJson), default: () => [], always: true, to: (value) => value.map(maybeToJson) }] });
1068
+ export const ModelsRequest = makeMessageClass("ModelsRequest", { type: agentModelsRequestType });
1069
+ export const ModelsResponse = makeMessageClass("ModelsResponse", { type: agentModelsResponseType, fields: [s("sourceMessageId", "source_message_id", true), { prop: "providers", json: "providers", from: (value) => objectList(value, AgentProviderInfo.fromJson), default: () => [], always: true, to: (value) => value.map(maybeToJson) }] });
1070
+ export const ChangeModel = makeMessageClass("ChangeModel", { type: agentModelChangeType, base: "thread", fields: [s("backend"), s("provider"), s("model"), s("voice")] });
1071
+ export const AgentModelChanged = makeMessageClass("AgentModelChanged", { type: agentModelChangedType, base: "thread", fields: [s("sourceMessageId"), s("backend"), s("provider", "provider", true), s("model", "model", true), s("voice"), audioFormat("inputFormat"), audioFormat("outputFormat"), s("turnDetection"), sl("outputModalities", "output_modalities", ["text"], true), sl("realtimeProtocols", "realtime_protocols", [], true), { prop: "supportsAttachments", json: "supports_attachments", from: (value) => value === true, default: () => false }, sl("accepts", "accepts", [], true)] });
1072
+ export const ThreadCleared = makeMessageClass("ThreadCleared", { type: agentThreadClearedType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true)] });
1073
+ export const TurnStartAccepted = makeMessageClass("TurnStartAccepted", { type: agentTurnStartAcceptedType, base: "thread", fields: [s("turnId"), s("sourceMessageId", "source_message_id", true), contentList("content")] });
1074
+ export const TurnStartRejected = makeMessageClass("TurnStartRejected", { type: agentTurnStartRejectedType, base: "thread", fields: [s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
1075
+ export const TurnInterruptAccepted = makeMessageClass("TurnInterruptAccepted", { type: agentTurnInterruptAcceptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
1076
+ export const TurnInterrupted = makeMessageClass("TurnInterrupted", { type: agentTurnInterruptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
1077
+ export const TurnSteerAccepted = makeMessageClass("TurnSteerAccepted", { type: agentTurnSteerAcceptedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true), contentList("content")] });
1078
+ export const TurnSteered = makeMessageClass("TurnSteered", { type: agentTurnSteeredType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
1079
+ export const TurnSteerRejected = makeMessageClass("TurnSteerRejected", { type: agentTurnSteerRejectedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
1080
+ export const TurnStarted = makeMessageClass("TurnStarted", { type: agentTurnStartedType, base: "thread", fields: [s("turnId", "turn_id", true), s("sourceMessageId", "source_message_id", true)] });
1081
+ export const TurnEnded = makeMessageClass("TurnEnded", { type: agentTurnEndedType, base: "thread", fields: [s("turnId", "turn_id", true), obj("error", "error", AgentError.fromJson)] });
1082
+ export const ThreadStarted = makeMessageClass("ThreadStarted", { type: agentThreadStartedType, fields: [s("sourceMessageId", "source_message_id", true), s("threadId", "thread_id", true), obj("realtimeConnection", "realtime_connection", AgentRealtimeConnectionInfo.fromJson)] });
1083
+ export const ThreadLoaded = makeMessageClass("ThreadLoaded", { type: agentThreadLoadedType, base: "thread", fields: [s("sourceMessageId"), s("sinceTurn")] });
1084
+ export const ThreadStartRejected = makeMessageClass("ThreadStartRejected", { type: agentThreadStartRejectedType, fields: [s("sourceMessageId", "source_message_id", true), obj("error", "error", AgentError.fromJson, true)] });
1085
+ export const AgentReasoningContentStarted = makeMessageClass("AgentReasoningContentStarted", { type: agentReasoningContentStartedType, base: "llm", fields: contentPart });
1086
+ export const AgentReasoningContentDelta = makeMessageClass("AgentReasoningContentDelta", { type: agentReasoningContentDeltaType, base: "llm", fields: [...contentPart, s("text", "text", true)] });
1087
+ export const AgentReasoningContentEnded = makeMessageClass("AgentReasoningContentEnded", { type: agentReasoningContentEndedType, base: "llm", fields: contentPart });
1088
+ export const AgentTextContentStarted = makeMessageClass("AgentTextContentStarted", { type: agentTextContentStartedType, base: "llm", fields: [...contentPart, s("phase")] });
1089
+ export const AgentTextContentDelta = makeMessageClass("AgentTextContentDelta", { type: agentTextContentDeltaType, base: "llm", fields: [...contentPart, s("phase"), s("text", "text", true)] });
1090
+ export const AgentTextContentEnded = makeMessageClass("AgentTextContentEnded", { type: agentTextContentEndedType, base: "llm", fields: [...contentPart, s("phase")] });
1091
+ export const AgentFileContentStarted = makeMessageClass("AgentFileContentStarted", { type: agentFileContentStartedType, base: "llm", fields: contentPart });
1092
+ export const AgentFileContentDelta = makeMessageClass("AgentFileContentDelta", { type: agentFileContentDeltaType, base: "llm", fields: [...contentPart, s("url", "url", true)] });
1093
+ export const AgentFileContentEnded = makeMessageClass("AgentFileContentEnded", { type: agentFileContentEndedType, base: "llm", fields: contentPart });
1094
+ export const AgentToolCallPending = makeMessageClass("AgentToolCallPending", { type: agentToolCallPendingType, base: "llm", fields: toolState });
1095
+ export const AgentToolCallInProgress = makeMessageClass("AgentToolCallInProgress", { type: agentToolCallInProgressType, base: "llm", fields: toolState });
1096
+ export const AgentToolCallStarted = makeMessageClass("AgentToolCallStarted", { type: agentToolCallStartedType, base: "llm", fields: toolState });
1097
+ export const AgentToolCallArgumentsDelta = makeMessageClass("AgentToolCallArgumentsDelta", { type: agentToolCallArgumentsDeltaType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), s("delta", "delta", true)] });
1098
+ export const AgentToolCallLogDelta = makeMessageClass("AgentToolCallLogDelta", { type: agentToolCallLogDeltaType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), { prop: "lines", json: "lines", from: (value) => objectList(value, AgentToolCallLogLine.fromJson), default: () => [], always: true, to: (value) => value.map(maybeToJson) }] });
1099
+ export const AgentToolCallEnded = makeMessageClass("AgentToolCallEnded", { type: agentToolCallEndedType, base: "llm", fields: [...contentPart, { prop: "namespace", json: "namespace", from: (value) => stringOrNull(value) ?? "meshagent", default: () => "meshagent", always: true }, s("callId"), s("toolkit"), s("tool"), { prop: "result", json: "result", from: contentOrNull, to: contentHeader }, obj("error", "error", AgentError.fromJson)] });
1100
+ export const AgentToolCallApprovalRequested = makeMessageClass("AgentToolCallApprovalRequested", { type: agentToolCallApprovalRequestedType, base: "llm", fields: toolState.filter((field) => field.prop !== "argumentBytes") });
1101
+ export const AgentSecretRequested = makeMessageClass("AgentSecretRequested", { type: agentSecretRequestedType, base: "llm", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("secretName", "secret_name", true), s("prompt"), m("oauth"), s("challenge")] });
1102
+ export const AgentClientToolCallRequested = makeMessageClass("AgentClientToolCallRequested", { type: agentClientToolCallRequestedType, base: "llm", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("targetParticipantId"), s("toolkit", "toolkit", true), s("tool", "tool", true), { prop: "arguments", json: "arguments", from: (value) => dynamicMapOrNull(value) ?? {}, default: () => ({}), always: true }] });
1103
+ export const AgentClientToolCallCancelled = makeMessageClass("AgentClientToolCallCancelled", { type: agentClientToolCallCancelledType, base: "llm", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("targetParticipantId"), s("toolkit", "toolkit", true), s("tool", "tool", true), s("reason")] });
1104
+ export const AgentThreadStatus = makeMessageClass("AgentThreadStatus", { type: agentThreadStatusType, base: "thread", fields: [s("status"), s("mode"), s("startedAt"), s("turnId"), s("pendingItemId"), i("totalBytes"), i("linesAdded"), i("linesRemoved")] });
1105
+ export const AgentConnectionStatus = makeMessageClass("AgentConnectionStatus", { type: agentConnectionStatusType, fields: [s("status", "status", true), s("message"), s("reason"), n("retryInSeconds"), s("participantId")] });
1106
+ export const AgentThreadEvent = makeMessageClass("AgentThreadEvent", { type: agentThreadEventType, base: "llm", fields: [m("event", "event", true)] });
1107
+ export const AgentImageGenerationStarted = makeMessageClass("AgentImageGenerationStarted", { type: agentImageGenerationStartedType, base: "llm", fields: imageGeneration });
1108
+ export const AgentImageGenerationPartial = makeMessageClass("AgentImageGenerationPartial", { type: agentImageGenerationPartialType, base: "llm", fields: [...imageGeneration, obj("image", "image", AgentGeneratedImage.fromJson), i("partialIndex")] });
1109
+ export const AgentImageGenerationCompleted = makeMessageClass("AgentImageGenerationCompleted", { type: agentImageGenerationCompletedType, base: "llm", fields: [...imageGeneration, objList("images", "images", AgentGeneratedImage.fromJson, true)] });
1110
+ export const AgentImageGenerationFailed = makeMessageClass("AgentImageGenerationFailed", { type: agentImageGenerationFailedType, base: "llm", fields: [...imageGeneration, obj("error", "error", AgentError.fromJson)] });
1111
+ export const AgentAudioGenerationStarted = makeMessageClass("AgentAudioGenerationStarted", { type: agentAudioGenerationStartedType, base: "llm", fields: responsePart });
1112
+ export const AgentAudioGenerationDelta = makeMessageClass("AgentAudioGenerationDelta", { type: agentAudioGenerationDeltaType, base: "llm", fields: [...responsePart, bytesField("data"), s("mimeType"), audioFormat("outputFormat")] });
1113
+ export const AgentAudioGenerationCompleted = makeMessageClass("AgentAudioGenerationCompleted", { type: agentAudioGenerationCompletedType, base: "llm", fields: [...responsePart, obj("audio", "audio", AgentGeneratedAudio.fromJson), audioFormat("outputFormat")] });
1114
+ export const AgentAudioGenerationFailed = makeMessageClass("AgentAudioGenerationFailed", { type: agentAudioGenerationFailedType, base: "llm", fields: [...responsePart, obj("error", "error", AgentError.fromJson)] });
1115
+ export const AgentAudioTranscriptionStarted = makeMessageClass("AgentAudioTranscriptionStarted", { type: agentAudioTranscriptionStartedType, base: "llm", fields: [...responsePart, s("role")] });
1116
+ export const AgentAudioTranscriptionDelta = makeMessageClass("AgentAudioTranscriptionDelta", { type: agentAudioTranscriptionDeltaType, base: "llm", fields: [...responsePart, s("role"), s("text", "text", true)] });
1117
+ export const AgentAudioTranscriptionCompleted = makeMessageClass("AgentAudioTranscriptionCompleted", { type: agentAudioTranscriptionCompletedType, base: "llm", fields: [...responsePart, s("role"), s("text")] });
1118
+ export const AgentAudioTranscriptionFailed = makeMessageClass("AgentAudioTranscriptionFailed", { type: agentAudioTranscriptionFailedType, base: "llm", fields: [...responsePart, s("role"), obj("error", "error", AgentError.fromJson)] });
1119
+ export const AgentAudioInputSpeechStarted = makeMessageClass("AgentAudioInputSpeechStarted", { type: agentAudioInputSpeechStartedType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId"), i("audioStartMs")] });
1120
+ export const AgentAudioInputSpeechEnded = makeMessageClass("AgentAudioInputSpeechEnded", { type: agentAudioInputSpeechEndedType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId"), i("audioEndMs")] });
1121
+ export const AgentContextCompacted = makeMessageClass("AgentContextCompacted", { type: agentContextCompactedType, base: "thread", fields: [s("checkpointId", "checkpoint_id", true), s("path", "path", true), i("throughSequence", "through_sequence", true), s("createdAt"), { prop: "messages", json: "messages", from: mapListOrNull }] });
1122
+ export const AgentUsageUpdated = makeMessageClass("AgentUsageUpdated", { type: agentUsageUpdatedType, base: "thread", fields: [s("turnId"), { prop: "usage", json: "usage", from: doubleMap, default: () => ({}), always: true }, obj("contextWindow", "context_window", AgentContextWindowUsage.fromJson, true)] });
1123
+ export const ApproveAgentToolCall = makeMessageClass("ApproveAgentToolCall", { type: agentToolApproveType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId", "item_id", true)] });
1124
+ export const RejectAgentToolCall = makeMessageClass("RejectAgentToolCall", { type: agentToolRejectType, base: "thread", fields: [s("turnId", "turn_id", true), s("itemId", "item_id", true)] });
1125
+ export const AgentSecretResponse = makeMessageClass("AgentSecretResponse", { type: agentSecretResponseType, base: "thread", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), s("value"), s("authorizationCode"), s("redirectUri"), s("error")] });
1126
+ export const AgentClientToolCallResponse = makeMessageClass("AgentClientToolCallResponse", { type: agentClientToolCallResponseType, base: "thread", fields: [s("turnId", "turn_id", true), s("requestId", "request_id", true), { prop: "response", json: "response", required: true, from: (value) => { const content = contentOrNull(value); if (content == null)
1127
+ throw new TypeError("missing content field 'response'"); return content; }, to: contentHeader }] });
1128
+ export function agentInputContent({ text, attachments, }) {
983
1129
  const content = [];
984
1130
  if (text.trim() !== "") {
985
1131
  content.push({ type: "text", text });
986
1132
  }
987
1133
  for (const attachment of attachments) {
988
- const normalized = attachment.trim();
989
- if (normalized !== "") {
990
- content.push({ type: "file", url: normalized });
1134
+ const url = attachment.url.trim();
1135
+ if (url === "") {
1136
+ continue;
991
1137
  }
1138
+ const name = attachment.name?.trim();
1139
+ content.push(new AgentFileContent({
1140
+ url,
1141
+ name: name == null || name === "" ? undefined : name,
1142
+ }));
992
1143
  }
993
1144
  return content;
994
1145
  }