@a2a-js/sdk 0.3.11 → 0.3.12

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.
@@ -575,23 +575,32 @@ var RestTransportHandler = class _RestTransportHandler {
575
575
  async getAuthenticatedExtendedAgentCard(context) {
576
576
  return this.requestHandler.getAuthenticatedExtendedAgentCard(context);
577
577
  }
578
+ /**
579
+ * Validate MessageSendParams.
580
+ */
581
+ validateMessageSendParams(params) {
582
+ if (!params.message) {
583
+ throw A2AError.invalidParams("message is required");
584
+ }
585
+ if (!params.message.messageId) {
586
+ throw A2AError.invalidParams("message.messageId is required");
587
+ }
588
+ }
578
589
  /**
579
590
  * Sends a message to the agent.
580
- * Accepts both snake_case and camelCase input, returns camelCase.
581
591
  */
582
592
  async sendMessage(params, context) {
583
- const normalized = this.normalizeMessageParams(params);
584
- return this.requestHandler.sendMessage(normalized, context);
593
+ this.validateMessageSendParams(params);
594
+ return this.requestHandler.sendMessage(params, context);
585
595
  }
586
596
  /**
587
597
  * Sends a message with streaming response.
588
- * Accepts both snake_case and camelCase input, returns camelCase stream.
589
598
  * @throws {A2AError} UnsupportedOperation if streaming not supported
590
599
  */
591
600
  async sendMessageStream(params, context) {
592
601
  await this.requireCapability("streaming");
593
- const normalized = this.normalizeMessageParams(params);
594
- return this.requestHandler.sendMessageStream(normalized, context);
602
+ this.validateMessageSendParams(params);
603
+ return this.requestHandler.sendMessageStream(params, context);
595
604
  }
596
605
  /**
597
606
  * Gets a task by ID.
@@ -623,13 +632,17 @@ var RestTransportHandler = class _RestTransportHandler {
623
632
  }
624
633
  /**
625
634
  * Sets a push notification configuration.
626
- * Accepts both snake_case and camelCase input, returns camelCase.
627
635
  * @throws {A2AError} PushNotificationNotSupported if push notifications not supported
628
636
  */
629
637
  async setTaskPushNotificationConfig(config, context) {
630
638
  await this.requireCapability("pushNotifications");
631
- const normalized = this.normalizeTaskPushNotificationConfig(config);
632
- return this.requestHandler.setTaskPushNotificationConfig(normalized, context);
639
+ if (!config.taskId) {
640
+ throw A2AError.invalidParams("taskId is required");
641
+ }
642
+ if (!config.pushNotificationConfig) {
643
+ throw A2AError.invalidParams("pushNotificationConfig is required");
644
+ }
645
+ return this.requestHandler.setTaskPushNotificationConfig(config, context);
633
646
  }
634
647
  /**
635
648
  * Lists all push notification configurations for a task.
@@ -655,28 +668,6 @@ var RestTransportHandler = class _RestTransportHandler {
655
668
  context
656
669
  );
657
670
  }
658
- // ==========================================================================
659
- // Private Transformation Methods
660
- // ==========================================================================
661
- // All type conversion between REST (snake_case) and internal (camelCase) formats
662
- /**
663
- * Validates and normalizes message parameters.
664
- * Accepts both snake_case and camelCase input.
665
- * @throws {A2AError} InvalidParams if message is missing or conversion fails
666
- */
667
- normalizeMessageParams(input) {
668
- if (!input.message) {
669
- throw A2AError.invalidParams("message is required");
670
- }
671
- try {
672
- return this.normalizeMessageSendParams(input);
673
- } catch (error) {
674
- if (error instanceof A2AError) throw error;
675
- throw A2AError.invalidParams(
676
- error instanceof Error ? error.message : "Invalid message parameters"
677
- );
678
- }
679
- }
680
671
  /**
681
672
  * Static map of capability to error for missing capabilities.
682
673
  */
@@ -710,86 +701,6 @@ var RestTransportHandler = class _RestTransportHandler {
710
701
  }
711
702
  return parsed;
712
703
  }
713
- /**
714
- * Normalizes Part input - accepts both snake_case and camelCase for file mimeType.
715
- */
716
- normalizePart(part) {
717
- if (part.kind === "text") return { kind: "text", text: part.text };
718
- if (part.kind === "file") {
719
- const file = this.normalizeFile(part.file);
720
- return { kind: "file", file, metadata: part.metadata };
721
- }
722
- return { kind: "data", data: part.data, metadata: part.metadata };
723
- }
724
- /**
725
- * Normalizes File input - accepts both snake_case (mime_type) and camelCase (mimeType).
726
- */
727
- normalizeFile(f) {
728
- const file = f;
729
- const mimeType = file.mimeType ?? file.mime_type;
730
- if ("bytes" in file) {
731
- return { bytes: file.bytes, mimeType, name: file.name };
732
- }
733
- return { uri: file.uri, mimeType, name: file.name };
734
- }
735
- /**
736
- * Normalizes Message input - accepts both snake_case and camelCase.
737
- */
738
- normalizeMessage(input) {
739
- const m = input;
740
- const messageId = m.messageId ?? m.message_id;
741
- if (!messageId) {
742
- throw A2AError.invalidParams("message.messageId is required");
743
- }
744
- if (!m.parts || !Array.isArray(m.parts)) {
745
- throw A2AError.invalidParams("message.parts must be an array");
746
- }
747
- return {
748
- contextId: m.contextId ?? m.context_id,
749
- extensions: m.extensions,
750
- kind: "message",
751
- messageId,
752
- metadata: m.metadata,
753
- parts: m.parts.map((p) => this.normalizePart(p)),
754
- referenceTaskIds: m.referenceTaskIds ?? m.reference_task_ids,
755
- role: m.role,
756
- taskId: m.taskId ?? m.task_id
757
- };
758
- }
759
- /**
760
- * Normalizes MessageSendParams - accepts both snake_case and camelCase.
761
- */
762
- normalizeMessageSendParams(input) {
763
- const p = input;
764
- const config = p.configuration;
765
- return {
766
- configuration: config ? {
767
- acceptedOutputModes: config.acceptedOutputModes ?? config.accepted_output_modes,
768
- blocking: config.blocking,
769
- historyLength: config.historyLength ?? config.history_length
770
- } : void 0,
771
- message: this.normalizeMessage(p.message),
772
- metadata: p.metadata
773
- };
774
- }
775
- /**
776
- * Normalizes TaskPushNotificationConfig - accepts both snake_case and camelCase.
777
- */
778
- normalizeTaskPushNotificationConfig(input) {
779
- const c = input;
780
- const taskId = c.taskId ?? c.task_id;
781
- if (!taskId) {
782
- throw A2AError.invalidParams("taskId is required");
783
- }
784
- const pnConfig = c.pushNotificationConfig ?? c.push_notification_config;
785
- if (!pnConfig) {
786
- throw A2AError.invalidParams("pushNotificationConfig is required");
787
- }
788
- return {
789
- pushNotificationConfig: pnConfig,
790
- taskId
791
- };
792
- }
793
704
  };
794
705
 
795
706
  // src/types/pb/a2a_types.ts
@@ -245,23 +245,32 @@ var RestTransportHandler = class _RestTransportHandler {
245
245
  async getAuthenticatedExtendedAgentCard(context) {
246
246
  return this.requestHandler.getAuthenticatedExtendedAgentCard(context);
247
247
  }
248
+ /**
249
+ * Validate MessageSendParams.
250
+ */
251
+ validateMessageSendParams(params) {
252
+ if (!params.message) {
253
+ throw A2AError.invalidParams("message is required");
254
+ }
255
+ if (!params.message.messageId) {
256
+ throw A2AError.invalidParams("message.messageId is required");
257
+ }
258
+ }
248
259
  /**
249
260
  * Sends a message to the agent.
250
- * Accepts both snake_case and camelCase input, returns camelCase.
251
261
  */
252
262
  async sendMessage(params, context) {
253
- const normalized = this.normalizeMessageParams(params);
254
- return this.requestHandler.sendMessage(normalized, context);
263
+ this.validateMessageSendParams(params);
264
+ return this.requestHandler.sendMessage(params, context);
255
265
  }
256
266
  /**
257
267
  * Sends a message with streaming response.
258
- * Accepts both snake_case and camelCase input, returns camelCase stream.
259
268
  * @throws {A2AError} UnsupportedOperation if streaming not supported
260
269
  */
261
270
  async sendMessageStream(params, context) {
262
271
  await this.requireCapability("streaming");
263
- const normalized = this.normalizeMessageParams(params);
264
- return this.requestHandler.sendMessageStream(normalized, context);
272
+ this.validateMessageSendParams(params);
273
+ return this.requestHandler.sendMessageStream(params, context);
265
274
  }
266
275
  /**
267
276
  * Gets a task by ID.
@@ -293,13 +302,17 @@ var RestTransportHandler = class _RestTransportHandler {
293
302
  }
294
303
  /**
295
304
  * Sets a push notification configuration.
296
- * Accepts both snake_case and camelCase input, returns camelCase.
297
305
  * @throws {A2AError} PushNotificationNotSupported if push notifications not supported
298
306
  */
299
307
  async setTaskPushNotificationConfig(config, context) {
300
308
  await this.requireCapability("pushNotifications");
301
- const normalized = this.normalizeTaskPushNotificationConfig(config);
302
- return this.requestHandler.setTaskPushNotificationConfig(normalized, context);
309
+ if (!config.taskId) {
310
+ throw A2AError.invalidParams("taskId is required");
311
+ }
312
+ if (!config.pushNotificationConfig) {
313
+ throw A2AError.invalidParams("pushNotificationConfig is required");
314
+ }
315
+ return this.requestHandler.setTaskPushNotificationConfig(config, context);
303
316
  }
304
317
  /**
305
318
  * Lists all push notification configurations for a task.
@@ -325,28 +338,6 @@ var RestTransportHandler = class _RestTransportHandler {
325
338
  context
326
339
  );
327
340
  }
328
- // ==========================================================================
329
- // Private Transformation Methods
330
- // ==========================================================================
331
- // All type conversion between REST (snake_case) and internal (camelCase) formats
332
- /**
333
- * Validates and normalizes message parameters.
334
- * Accepts both snake_case and camelCase input.
335
- * @throws {A2AError} InvalidParams if message is missing or conversion fails
336
- */
337
- normalizeMessageParams(input) {
338
- if (!input.message) {
339
- throw A2AError.invalidParams("message is required");
340
- }
341
- try {
342
- return this.normalizeMessageSendParams(input);
343
- } catch (error) {
344
- if (error instanceof A2AError) throw error;
345
- throw A2AError.invalidParams(
346
- error instanceof Error ? error.message : "Invalid message parameters"
347
- );
348
- }
349
- }
350
341
  /**
351
342
  * Static map of capability to error for missing capabilities.
352
343
  */
@@ -380,86 +371,6 @@ var RestTransportHandler = class _RestTransportHandler {
380
371
  }
381
372
  return parsed;
382
373
  }
383
- /**
384
- * Normalizes Part input - accepts both snake_case and camelCase for file mimeType.
385
- */
386
- normalizePart(part) {
387
- if (part.kind === "text") return { kind: "text", text: part.text };
388
- if (part.kind === "file") {
389
- const file = this.normalizeFile(part.file);
390
- return { kind: "file", file, metadata: part.metadata };
391
- }
392
- return { kind: "data", data: part.data, metadata: part.metadata };
393
- }
394
- /**
395
- * Normalizes File input - accepts both snake_case (mime_type) and camelCase (mimeType).
396
- */
397
- normalizeFile(f) {
398
- const file = f;
399
- const mimeType = file.mimeType ?? file.mime_type;
400
- if ("bytes" in file) {
401
- return { bytes: file.bytes, mimeType, name: file.name };
402
- }
403
- return { uri: file.uri, mimeType, name: file.name };
404
- }
405
- /**
406
- * Normalizes Message input - accepts both snake_case and camelCase.
407
- */
408
- normalizeMessage(input) {
409
- const m = input;
410
- const messageId = m.messageId ?? m.message_id;
411
- if (!messageId) {
412
- throw A2AError.invalidParams("message.messageId is required");
413
- }
414
- if (!m.parts || !Array.isArray(m.parts)) {
415
- throw A2AError.invalidParams("message.parts must be an array");
416
- }
417
- return {
418
- contextId: m.contextId ?? m.context_id,
419
- extensions: m.extensions,
420
- kind: "message",
421
- messageId,
422
- metadata: m.metadata,
423
- parts: m.parts.map((p) => this.normalizePart(p)),
424
- referenceTaskIds: m.referenceTaskIds ?? m.reference_task_ids,
425
- role: m.role,
426
- taskId: m.taskId ?? m.task_id
427
- };
428
- }
429
- /**
430
- * Normalizes MessageSendParams - accepts both snake_case and camelCase.
431
- */
432
- normalizeMessageSendParams(input) {
433
- const p = input;
434
- const config = p.configuration;
435
- return {
436
- configuration: config ? {
437
- acceptedOutputModes: config.acceptedOutputModes ?? config.accepted_output_modes,
438
- blocking: config.blocking,
439
- historyLength: config.historyLength ?? config.history_length
440
- } : void 0,
441
- message: this.normalizeMessage(p.message),
442
- metadata: p.metadata
443
- };
444
- }
445
- /**
446
- * Normalizes TaskPushNotificationConfig - accepts both snake_case and camelCase.
447
- */
448
- normalizeTaskPushNotificationConfig(input) {
449
- const c = input;
450
- const taskId = c.taskId ?? c.task_id;
451
- if (!taskId) {
452
- throw A2AError.invalidParams("taskId is required");
453
- }
454
- const pnConfig = c.pushNotificationConfig ?? c.push_notification_config;
455
- if (!pnConfig) {
456
- throw A2AError.invalidParams("pushNotificationConfig is required");
457
- }
458
- return {
459
- pushNotificationConfig: pnConfig,
460
- taskId
461
- };
462
- }
463
374
  };
464
375
 
465
376
  // src/server/express/rest_handler.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a2a-js/sdk",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "description": "Server & Client SDK for Agent2Agent protocol",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {