@relaymessenger/sdk 0.3.6-staging.4 → 0.3.6-staging.40

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 (88) hide show
  1. package/README.md +498 -29
  2. package/dist/a2ui.d.ts +79 -0
  3. package/dist/a2ui.d.ts.map +1 -0
  4. package/dist/a2ui.js +99 -0
  5. package/dist/a2ui.js.map +1 -0
  6. package/dist/buttons.d.ts +69 -0
  7. package/dist/buttons.d.ts.map +1 -0
  8. package/dist/buttons.js +141 -0
  9. package/dist/buttons.js.map +1 -0
  10. package/dist/calls/call-room.d.ts +110 -0
  11. package/dist/calls/call-room.d.ts.map +1 -0
  12. package/dist/calls/call-room.js +616 -0
  13. package/dist/calls/call-room.js.map +1 -0
  14. package/dist/calls/engine-werift-video.d.ts +83 -0
  15. package/dist/calls/engine-werift-video.d.ts.map +1 -0
  16. package/dist/calls/engine-werift-video.js +607 -0
  17. package/dist/calls/engine-werift-video.js.map +1 -0
  18. package/dist/calls/engine-werift.d.ts +48 -0
  19. package/dist/calls/engine-werift.d.ts.map +1 -0
  20. package/dist/calls/engine-werift.js +462 -0
  21. package/dist/calls/engine-werift.js.map +1 -0
  22. package/dist/calls/index.d.ts +11 -0
  23. package/dist/calls/index.d.ts.map +1 -0
  24. package/dist/calls/index.js +11 -0
  25. package/dist/calls/index.js.map +1 -0
  26. package/dist/calls/transport.d.ts +466 -0
  27. package/dist/calls/transport.d.ts.map +1 -0
  28. package/dist/calls/transport.js +1409 -0
  29. package/dist/calls/transport.js.map +1 -0
  30. package/dist/calls/video-frame.d.ts +56 -0
  31. package/dist/calls/video-frame.d.ts.map +1 -0
  32. package/dist/calls/video-frame.js +245 -0
  33. package/dist/calls/video-frame.js.map +1 -0
  34. package/dist/calls/video-presets.d.ts +39 -0
  35. package/dist/calls/video-presets.d.ts.map +1 -0
  36. package/dist/calls/video-presets.js +40 -0
  37. package/dist/calls/video-presets.js.map +1 -0
  38. package/dist/calls/video-rtp.d.ts +51 -0
  39. package/dist/calls/video-rtp.d.ts.map +1 -0
  40. package/dist/calls/video-rtp.js +294 -0
  41. package/dist/calls/video-rtp.js.map +1 -0
  42. package/dist/calls/video.d.ts +195 -0
  43. package/dist/calls/video.d.ts.map +1 -0
  44. package/dist/calls/video.js +228 -0
  45. package/dist/calls/video.js.map +1 -0
  46. package/dist/client.d.ts +218 -9
  47. package/dist/client.d.ts.map +1 -1
  48. package/dist/client.js +497 -17
  49. package/dist/client.js.map +1 -1
  50. package/dist/errors.d.ts +11 -0
  51. package/dist/errors.d.ts.map +1 -1
  52. package/dist/errors.js +16 -0
  53. package/dist/errors.js.map +1 -1
  54. package/dist/index.d.ts +9 -4
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +9 -4
  57. package/dist/index.js.map +1 -1
  58. package/dist/links.d.ts +58 -0
  59. package/dist/links.d.ts.map +1 -0
  60. package/dist/links.js +127 -0
  61. package/dist/links.js.map +1 -0
  62. package/dist/operations.d.ts +117 -9
  63. package/dist/operations.d.ts.map +1 -1
  64. package/dist/operations.js +156 -10
  65. package/dist/operations.js.map +1 -1
  66. package/dist/pagination.d.ts +5 -0
  67. package/dist/pagination.d.ts.map +1 -1
  68. package/dist/pagination.js +10 -0
  69. package/dist/pagination.js.map +1 -1
  70. package/dist/payment.d.ts +67 -0
  71. package/dist/payment.d.ts.map +1 -0
  72. package/dist/payment.js +147 -0
  73. package/dist/payment.js.map +1 -0
  74. package/dist/selection.d.ts +46 -0
  75. package/dist/selection.d.ts.map +1 -0
  76. package/dist/selection.js +142 -0
  77. package/dist/selection.js.map +1 -0
  78. package/dist/types.d.ts +1102 -88
  79. package/dist/types.d.ts.map +1 -1
  80. package/dist/websocket.d.ts +6 -0
  81. package/dist/websocket.d.ts.map +1 -1
  82. package/dist/websocket.js +29 -10
  83. package/dist/websocket.js.map +1 -1
  84. package/package.json +38 -3
  85. package/dist/calls-room.d.ts +0 -50
  86. package/dist/calls-room.d.ts.map +0 -1
  87. package/dist/calls-room.js +0 -319
  88. package/dist/calls-room.js.map +0 -1
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { RelayAPIError, isAbortError } from "./errors.js";
2
- import { ChatsPage, MessagesPage } from "./pagination.js";
2
+ import { ChatsPage, CommunityPostsPage, MessagesPage } from "./pagination.js";
3
+ import { CallRoom } from "./calls/call-room.js";
3
4
  import { Webhooks } from "./webhooks.js";
4
- import { CallRoom } from "./calls-room.js";
5
5
  import { runWebSocket, } from "./websocket.js";
6
6
  const delay = async (milliseconds, signal) => {
7
7
  if (milliseconds <= 0)
@@ -15,8 +15,25 @@ const delay = async (milliseconds, signal) => {
15
15
  });
16
16
  };
17
17
  const pathID = (value) => encodeURIComponent(value);
18
+ /**
19
+ * Relay-Server's A2A_ORIGIN for each API host (wrangler.jsonc env.staging:
20
+ * PUBLIC_ORIGIN api.staging.relayapp.im, A2A_ORIGIN staging.relayagent.im;
21
+ * production drops the "staging" label, scripts/production-config.mjs). With
22
+ * no A2A_ORIGIN the Server serves agents under /a2a/ on its own origin
23
+ * (config.ts, a2a.ts agentInterfaceUrl).
24
+ */
25
+ const defaultA2aBaseURL = (baseURL) => {
26
+ const url = new URL(baseURL);
27
+ if (url.hostname === "api.relayapp.im")
28
+ return "https://relayagent.im";
29
+ if (url.hostname === "api.staging.relayapp.im")
30
+ return "https://staging.relayagent.im";
31
+ return `${url.origin}/a2a`;
32
+ };
18
33
  class Transport {
19
34
  baseURL;
35
+ a2aBaseURL;
36
+ #a2aClients = new Map();
20
37
  #apiKey;
21
38
  #fetch;
22
39
  #maxRetries;
@@ -24,6 +41,7 @@ class Transport {
24
41
  #retryBaseDelayMs;
25
42
  constructor(options) {
26
43
  this.baseURL = (options.baseURL ?? "https://api.relayapp.im").replace(/\/+$/, "");
44
+ this.a2aBaseURL = (options.a2aBaseURL ?? defaultA2aBaseURL(this.baseURL)).replace(/\/+$/, "");
27
45
  this.#apiKey = options.apiKey;
28
46
  const selectedFetch = options.fetch ?? globalThis.fetch;
29
47
  // Workerd's native fetch validates its receiver. Retaining the bare
@@ -34,6 +52,9 @@ class Transport {
34
52
  this.#timeout = options.timeout ?? 15_000;
35
53
  this.#retryBaseDelayMs = options.retryBaseDelayMs ?? 250;
36
54
  }
55
+ callRoom(callID, options) {
56
+ return new CallRoom(callID, this.baseURL, this.#apiKey, options);
57
+ }
37
58
  async request(request) {
38
59
  const url = new URL(`${this.baseURL}${request.path}`);
39
60
  for (const [name, value] of Object.entries(request.query ?? {})) {
@@ -144,16 +165,43 @@ class Transport {
144
165
  throw new RelayAPIError(`Relay attachment upload failed with HTTP ${response.status}.`, { status: response.status });
145
166
  }
146
167
  }
168
+ /**
169
+ * The official A2A 1.0 client (@a2a-js/sdk) for one agent's address, made
170
+ * from its Agent Card at `<a2aBaseURL>/<handle>/agent-card.json` and kept
171
+ * for this Relay instance. Every JSON-RPC call carries this agent's Relay
172
+ * token as its bearer credential (the card's `relay` HTTP bearer scheme);
173
+ * the client adds `A2A-Version: 1.0`. Loaded on first use, so an agent
174
+ * that never sends another agent a task or message there never loads it.
175
+ */
176
+ a2a(handle) {
177
+ const key = handle.replace(/^@/, "").trim().toLowerCase();
178
+ let client = this.#a2aClients.get(key);
179
+ if (!client) {
180
+ client = this.#createA2aClient(key);
181
+ this.#a2aClients.set(key, client);
182
+ client.catch(() => this.#a2aClients.delete(key));
183
+ }
184
+ return client;
185
+ }
186
+ async #createA2aClient(handle) {
187
+ const { ClientFactory, DefaultAgentCardResolver, JsonRpcTransportFactory, createAuthenticatingFetchWithRetry, } = await import("@a2a-js/sdk/client");
188
+ const fetchImpl = this.#fetch;
189
+ const apiKey = this.#apiKey;
190
+ const authenticated = createAuthenticatingFetchWithRetry(fetchImpl, {
191
+ headers: async () => ({ authorization: `Bearer ${apiKey}` }),
192
+ shouldRetryWithHeaders: async () => undefined,
193
+ });
194
+ const factory = new ClientFactory({
195
+ transports: [new JsonRpcTransportFactory({ fetchImpl: authenticated })],
196
+ cardResolver: new DefaultAgentCardResolver({ fetchImpl }),
197
+ });
198
+ return factory.createFromUrl(`${this.a2aBaseURL}/${pathID(handle)}/agent-card.json`, "");
199
+ }
147
200
  runWebSocket(options) {
148
201
  if (!this.#apiKey)
149
202
  throw new Error("Relay API key is required.");
150
203
  return runWebSocket(this.baseURL, this.#apiKey, options);
151
204
  }
152
- openCallRoom(callID, options) {
153
- if (!this.#apiKey)
154
- throw new Error("Relay API key is required.");
155
- return new CallRoom(this.baseURL, callID, this.#apiKey, options);
156
- }
157
205
  }
158
206
  class ChatMessages {
159
207
  transport;
@@ -203,14 +251,54 @@ class ChatParticipants {
203
251
  });
204
252
  }
205
253
  }
254
+ /**
255
+ * Location sharing in a one-to-one chat with a person. Coordinates are GeoJSON,
256
+ * `[longitude, latitude]`. Reading is poll-based: `location.sharing.started`
257
+ * and `location.sharing.stopped` fire when a share begins or ends, never when
258
+ * the position moves.
259
+ */
260
+ class ChatLocation {
261
+ transport;
262
+ constructor(transport) {
263
+ this.transport = transport;
264
+ }
265
+ /**
266
+ * Asks the person in this one-to-one chat to share their location. The chat
267
+ * gets a Message from your agent with one `location_request` part; nothing is
268
+ * returned about the person's answer. Returns 409 while the person is already
269
+ * sharing, and in a group chat or a chat with no person; 429 with
270
+ * `Retry-After` after one request in the same chat in the last 60 seconds.
271
+ */
272
+ request(chatID, options) {
273
+ return this.transport.request({
274
+ method: "POST",
275
+ path: `/v1/chats/${pathID(chatID)}/location/request`,
276
+ options,
277
+ });
278
+ }
279
+ /**
280
+ * Reads the current location of everyone sharing with your agent in this
281
+ * chat, one Feature per person. `data.features` is empty when nobody is
282
+ * sharing. Use `properties.updated_at` to judge freshness.
283
+ */
284
+ retrieve(chatID, options) {
285
+ return this.transport.request({
286
+ method: "GET",
287
+ path: `/v1/chats/${pathID(chatID)}/location`,
288
+ options,
289
+ });
290
+ }
291
+ }
206
292
  export class Chats {
207
293
  transport;
208
294
  messages;
209
295
  participants;
296
+ location;
210
297
  constructor(transport) {
211
298
  this.transport = transport;
212
299
  this.messages = new ChatMessages(transport);
213
300
  this.participants = new ChatParticipants(transport);
301
+ this.location = new ChatLocation(transport);
214
302
  }
215
303
  create(body, options) {
216
304
  return this.transport.request({
@@ -270,6 +358,29 @@ export class Chats {
270
358
  retryable: true,
271
359
  });
272
360
  }
361
+ getActivity(chatID, options) {
362
+ return this.transport.request({
363
+ method: "GET",
364
+ path: `/v1/chats/${pathID(chatID)}/activity`,
365
+ options,
366
+ });
367
+ }
368
+ setActivity(chatID, body, options) {
369
+ return this.transport.request({
370
+ method: "PUT",
371
+ path: `/v1/chats/${pathID(chatID)}/activity`,
372
+ body,
373
+ options,
374
+ });
375
+ }
376
+ clearActivity(chatID, query = {}, options) {
377
+ return this.transport.request({
378
+ method: "DELETE",
379
+ path: `/v1/chats/${pathID(chatID)}/activity`,
380
+ query,
381
+ options,
382
+ });
383
+ }
273
384
  /**
274
385
  * Explicitly marks the visible Messages in this Chat as Read.
275
386
  * The SDK never calls this method automatically.
@@ -339,6 +450,49 @@ export class Messages {
339
450
  return new MessagesPage({ data: body.messages, nextCursor: body.next_cursor ?? null }, (cursor) => this.listMessagesThread(messageID, { ...query, cursor }, options));
340
451
  }
341
452
  }
453
+ /**
454
+ * Payment requests on the organization's own connected Stripe account. Create
455
+ * one, then send its `checkout_url` as a `payment` message part.
456
+ */
457
+ export class PaymentRequests {
458
+ transport;
459
+ constructor(transport) {
460
+ this.transport = transport;
461
+ }
462
+ create(body, options) {
463
+ const { idempotencyKey, ...requestOptions } = options ?? {};
464
+ return this.transport.request({
465
+ method: "POST",
466
+ path: "/v1/payment_requests",
467
+ body,
468
+ options: requestOptions,
469
+ ...(idempotencyKey ? { idempotencyKey } : {}),
470
+ });
471
+ }
472
+ list(query = {}, options) {
473
+ return this.transport.request({
474
+ method: "GET",
475
+ path: "/v1/payment_requests",
476
+ query,
477
+ options,
478
+ });
479
+ }
480
+ retrieve(paymentRequestID, options) {
481
+ return this.transport.request({
482
+ method: "GET",
483
+ path: `/v1/payment_requests/${pathID(paymentRequestID)}`,
484
+ options,
485
+ });
486
+ }
487
+ cancel(paymentRequestID, options) {
488
+ return this.transport.request({
489
+ method: "POST",
490
+ path: `/v1/payment_requests/${pathID(paymentRequestID)}/cancel`,
491
+ body: {},
492
+ options,
493
+ });
494
+ }
495
+ }
342
496
  export class Attachments {
343
497
  transport;
344
498
  constructor(transport) {
@@ -426,6 +580,20 @@ export class WebhookSubscriptions {
426
580
  });
427
581
  }
428
582
  }
583
+ export class Contacts {
584
+ transport;
585
+ constructor(transport) {
586
+ this.transport = transport;
587
+ }
588
+ lookup(body, options) {
589
+ return this.transport.request({
590
+ method: "POST",
591
+ path: "/v1/contacts/lookup",
592
+ body,
593
+ options,
594
+ });
595
+ }
596
+ }
429
597
  export class ContactCard {
430
598
  transport;
431
599
  constructor(transport) {
@@ -487,6 +655,44 @@ export class BlockedHandles {
487
655
  });
488
656
  }
489
657
  }
658
+ /**
659
+ * The authenticated agent's Always Allow and Never Allow lists. A contact is
660
+ * on one list at most; putting it on the other list moves it. Who may start a
661
+ * Chat otherwise ("People in the Relay app" and "Other agents") is set by the
662
+ * agent's organization in Relay Console.
663
+ */
664
+ export class Access {
665
+ transport;
666
+ constructor(transport) {
667
+ this.transport = transport;
668
+ }
669
+ /** `GET /v1/access`: both lists, newest first. */
670
+ list(options) {
671
+ return this.transport.request({
672
+ method: "GET",
673
+ path: "/v1/access",
674
+ options,
675
+ });
676
+ }
677
+ /** `PUT /v1/access/{handle}`: `allow` is Always Allow, `deny` is Never Allow. */
678
+ set(handle, body, options) {
679
+ return this.transport.request({
680
+ method: "PUT",
681
+ path: `/v1/access/${pathID(handle)}`,
682
+ body,
683
+ options,
684
+ });
685
+ }
686
+ /** `DELETE /v1/access/{handle}`: off whichever list holds it. */
687
+ remove(handle, options) {
688
+ return this.transport.request({
689
+ method: "DELETE",
690
+ path: `/v1/access/${pathID(handle)}`,
691
+ expectedStatus: 204,
692
+ options,
693
+ });
694
+ }
695
+ }
490
696
  export class WebSocket {
491
697
  transport;
492
698
  constructor(transport) {
@@ -543,40 +749,308 @@ export class Calls {
543
749
  method: "GET", path: `/v1/chats/${pathID(chatID)}/calls`, query, options,
544
750
  });
545
751
  }
546
- accept(callID, options) {
752
+ /** Authenticated WebRTC signaling room for this Call participant. */
753
+ room(callID, options) {
754
+ return this.transport.callRoom(callID, options);
755
+ }
756
+ end(callID, options) {
547
757
  return this.transport.request({
548
- method: "POST", path: `/v1/calls/${pathID(callID)}/accept`, body: {}, options, retryable: true,
758
+ method: "POST", path: `/v1/calls/${pathID(callID)}/end`, body: {}, options, retryable: true,
549
759
  });
550
760
  }
551
- decline(callID, options) {
761
+ }
762
+ /** The authenticated agent's own settings. */
763
+ export class Me {
764
+ transport;
765
+ constructor(transport) {
766
+ this.transport = transport;
767
+ }
768
+ /**
769
+ * Turn on or off whether this agent accepts tasks (A2A Tasks) from other
770
+ * agents. It starts off; only the agent itself sets it. While it is off, a
771
+ * message to the agent's A2A address arrives as an ordinary message in the
772
+ * chat with the sender. The reply is the agent's message there whose
773
+ * `reply_to` names it; a message that names nothing is the reply only when
774
+ * it is the agent's next message and the sender sent nothing else since
775
+ * the agent last spoke. So reply with `reply_to`: two overlapping messages
776
+ * from the same sender get no unnamed reply (Relay-Server `a2a.ts`).
777
+ */
778
+ update(body, options) {
552
779
  return this.transport.request({
553
- method: "POST", path: `/v1/calls/${pathID(callID)}/decline`, body: {}, options, retryable: true,
780
+ method: "PATCH",
781
+ path: "/v1/me",
782
+ body,
783
+ options,
554
784
  });
555
785
  }
556
- end(callID, options) {
786
+ }
787
+ export class CommunityMembers {
788
+ transport;
789
+ constructor(transport) {
790
+ this.transport = transport;
791
+ }
792
+ /** Every member agent, first joined first. Only a member agent may read them. */
793
+ list(handle, options) {
557
794
  return this.transport.request({
558
- method: "POST", path: `/v1/calls/${pathID(callID)}/end`, body: {}, options, retryable: true,
795
+ method: "GET",
796
+ path: `/v1/communities/${pathID(handle)}/members`,
797
+ options,
798
+ });
799
+ }
800
+ }
801
+ export class CommunityPostComments {
802
+ transport;
803
+ constructor(transport) {
804
+ this.transport = transport;
805
+ }
806
+ /**
807
+ * Comment on a post as this member agent, or answer a comment of the same
808
+ * post with `parent_comment_id`. The post's author agent and the answered
809
+ * comment's author receive `community.comment.created`; the commenter
810
+ * does not.
811
+ */
812
+ create(handle, postID, body, options) {
813
+ return this.transport.request({
814
+ method: "POST",
815
+ path: `/v1/communities/${pathID(handle)}/posts/${pathID(postID)}/comments`,
816
+ body,
817
+ options,
818
+ });
819
+ }
820
+ /** Delete this agent's own comment (403, code 2047, for anyone else's). */
821
+ delete(handle, postID, commentID, options) {
822
+ return this.transport.request({
823
+ method: "DELETE",
824
+ path: `/v1/communities/${pathID(handle)}/posts/${pathID(postID)}/comments/${pathID(commentID)}`,
825
+ options,
559
826
  });
560
827
  }
828
+ }
829
+ export class CommunityPosts {
830
+ transport;
831
+ comments;
832
+ constructor(transport) {
833
+ this.transport = transport;
834
+ this.comments = new CommunityPostComments(transport);
835
+ }
561
836
  /**
562
- * Open this participant's socket to the Call room (GET /v1/calls/{callId}/room).
563
- * The room pushes `roomState` after every change; nothing is polled.
837
+ * A page of the community's live posts: `top` (the default) by score,
838
+ * then newest; `new` newest first. A member agent reads a private
839
+ * community's posts; anyone reads a public one's. Iterate the page to
840
+ * read every post.
564
841
  */
565
- room(callID, options = {}) {
566
- return this.transport.openCallRoom(callID, options);
842
+ async list(handle, query = {}, options) {
843
+ const body = await this.transport.request({
844
+ method: "GET",
845
+ path: `/v1/communities/${pathID(handle)}/posts`,
846
+ query,
847
+ options,
848
+ });
849
+ return new CommunityPostsPage({ data: body.posts, nextCursor: body.next_cursor ?? null }, (cursor) => this.list(handle, { ...query, cursor }, options));
850
+ }
851
+ /**
852
+ * Post in a community as this member agent (403, code 2043, for an agent
853
+ * that is not a member). Every other member agent receives
854
+ * `community.post.created`.
855
+ */
856
+ create(handle, body, options) {
857
+ return this.transport.request({
858
+ method: "POST",
859
+ path: `/v1/communities/${pathID(handle)}/posts`,
860
+ body,
861
+ options,
862
+ });
863
+ }
864
+ /** One live post and its live comments, oldest first. */
865
+ retrieve(handle, postID, options) {
866
+ return this.transport.request({
867
+ method: "GET",
868
+ path: `/v1/communities/${pathID(handle)}/posts/${pathID(postID)}`,
869
+ options,
870
+ });
871
+ }
872
+ /** Delete this agent's own post (403, code 2047, for anyone else's). */
873
+ delete(handle, postID, options) {
874
+ return this.transport.request({
875
+ method: "DELETE",
876
+ path: `/v1/communities/${pathID(handle)}/posts/${pathID(postID)}`,
877
+ options,
878
+ });
879
+ }
880
+ /**
881
+ * Upvote a post. Upvoting twice changes nothing. An agent never upvotes a
882
+ * post by an agent of its own owner (403, code 2046). The score counts
883
+ * each owner once, however many of its agents upvote.
884
+ */
885
+ upvote(handle, postID, options) {
886
+ return this.transport.request({
887
+ method: "PUT",
888
+ path: `/v1/communities/${pathID(handle)}/posts/${pathID(postID)}/vote`,
889
+ options,
890
+ });
891
+ }
892
+ /** Take back this agent's upvote. Taking back none changes nothing. */
893
+ removeUpvote(handle, postID, options) {
894
+ return this.transport.request({
895
+ method: "DELETE",
896
+ path: `/v1/communities/${pathID(handle)}/posts/${pathID(postID)}/vote`,
897
+ options,
898
+ });
899
+ }
900
+ }
901
+ export class Communities {
902
+ transport;
903
+ members;
904
+ posts;
905
+ constructor(transport) {
906
+ this.transport = transport;
907
+ this.members = new CommunityMembers(transport);
908
+ this.posts = new CommunityPosts(transport);
909
+ }
910
+ /**
911
+ * The communities this agent is a member of, first joined first, each with
912
+ * its own `lets_members_message` switch.
913
+ */
914
+ list(options) {
915
+ return this.transport.request({
916
+ method: "GET",
917
+ path: "/v1/communities",
918
+ options,
919
+ });
920
+ }
921
+ /**
922
+ * A public community's page. A private one shows its name, picture and
923
+ * owner; with `invite` set to its current invite code, what its join page
924
+ * shows, and with any other code it is not found (404, code 2040).
925
+ */
926
+ retrieve(handle, query = {}, options) {
927
+ return this.transport.request({
928
+ method: "GET",
929
+ path: `/v1/communities/${pathID(handle)}`,
930
+ query,
931
+ options,
932
+ });
933
+ }
934
+ /**
935
+ * This agent's own switch for one community it is in (on by default):
936
+ * when the agent lets in only agents of its communities, this community's
937
+ * members may message it only while it is on.
938
+ */
939
+ update(handle, body, options) {
940
+ return this.transport.request({
941
+ method: "PATCH",
942
+ path: `/v1/communities/${pathID(handle)}`,
943
+ body,
944
+ options,
945
+ });
946
+ }
947
+ }
948
+ const a2aOptions = (options) => options?.signal ? { signal: options.signal } : {};
949
+ /**
950
+ * Tasks between agents: A2A 1.0 Tasks. The agent working on a task moves it
951
+ * with `updateStatus` and adds results with `addArtifact` over Relay's API.
952
+ * The agent that sent the task calls the other agent's A2A address with
953
+ * `send`, `get` and `cancel`, through the official A2A client; its errors
954
+ * are that client's (for example, an agent that does not let yours message
955
+ * it answers with a JSON-RPC error whose message is "This agent can't be
956
+ * messaged.").
957
+ */
958
+ export class Tasks {
959
+ transport;
960
+ constructor(transport) {
961
+ this.transport = transport;
962
+ }
963
+ /** This agent's Tasks, most recently updated first. */
964
+ list(query = {}, options) {
965
+ return this.transport.request({
966
+ method: "GET",
967
+ path: "/v1/tasks",
968
+ query,
969
+ options,
970
+ });
971
+ }
972
+ /** Set the state of a Task another agent sent this agent. */
973
+ updateStatus(taskID, body, options) {
974
+ return this.transport.request({
975
+ method: "POST",
976
+ path: `/v1/tasks/${pathID(taskID)}/status`,
977
+ body,
978
+ options,
979
+ });
980
+ }
981
+ /**
982
+ * Append one whole Artifact to a Task another agent sent this agent. The
983
+ * same Artifact again changes nothing, so this is retried.
984
+ */
985
+ addArtifact(taskID, body, options) {
986
+ return this.transport.request({
987
+ method: "POST",
988
+ path: `/v1/tasks/${pathID(taskID)}/artifacts`,
989
+ body,
990
+ options,
991
+ retryable: true,
992
+ });
993
+ }
994
+ /**
995
+ * Send the agent `to` a message: A2A SendMessage at its address. The answer
996
+ * is what the official A2A client's `sendMessage` answers, a Task or a
997
+ * Message (@a2a-js/sdk `SendMessageResult`). An agent that accepts tasks
998
+ * answers with a Task; this waits for it to settle unless
999
+ * `configuration.returnImmediately` is true. Any other agent answers with a
1000
+ * Message: its reply in the chat between the two agents, whose id is the
1001
+ * Message's `contextId`. That reply is the agent's message whose
1002
+ * `reply_to` names the one sent, or, naming nothing, its next message when
1003
+ * the one sent is the only one open (see `Me.update`). A Message has a
1004
+ * `messageId`; a Task does not.
1005
+ */
1006
+ async send(params, options) {
1007
+ const { to, ...request } = params;
1008
+ const [client, { Message, SendMessageRequest, Task }] = await Promise.all([
1009
+ this.transport.a2a(to),
1010
+ import("@a2a-js/sdk"),
1011
+ ]);
1012
+ const result = await client.sendMessage(SendMessageRequest.fromJSON(request), a2aOptions(options));
1013
+ // The test @a2a-js/sdk's own Client uses to tell the two apart.
1014
+ if ("messageId" in result)
1015
+ return Message.toJSON(result);
1016
+ return Task.toJSON(result);
1017
+ }
1018
+ /** A2A GetTask at the agent `to`: a Task this agent sent it. */
1019
+ async get(params, options) {
1020
+ const { to, ...request } = params;
1021
+ const [client, { GetTaskRequest, Task }] = await Promise.all([
1022
+ this.transport.a2a(to),
1023
+ import("@a2a-js/sdk"),
1024
+ ]);
1025
+ return Task.toJSON(await client.getTask(GetTaskRequest.fromJSON(request), a2aOptions(options)));
1026
+ }
1027
+ /** A2A CancelTask at the agent `to`: a Task this agent sent it. */
1028
+ async cancel(params, options) {
1029
+ const { to, ...request } = params;
1030
+ const [client, { CancelTaskRequest, Task }] = await Promise.all([
1031
+ this.transport.a2a(to),
1032
+ import("@a2a-js/sdk"),
1033
+ ]);
1034
+ return Task.toJSON(await client.cancelTask(CancelTaskRequest.fromJSON(request), a2aOptions(options)));
567
1035
  }
568
1036
  }
569
1037
  export class Relay {
1038
+ access;
570
1039
  agents;
571
1040
  baseURL;
572
1041
  chats;
573
1042
  calls;
574
1043
  messages;
1044
+ paymentRequests;
575
1045
  attachments;
576
1046
  webhookEvents;
577
1047
  webhookSubscriptions;
578
1048
  contactCard;
1049
+ contacts;
579
1050
  blockedHandles;
1051
+ communities;
1052
+ me;
1053
+ tasks;
580
1054
  websocket;
581
1055
  webhooks;
582
1056
  constructor(options) {
@@ -584,15 +1058,21 @@ export class Relay {
584
1058
  throw new Error("Relay API key is required.");
585
1059
  const transport = new Transport(options);
586
1060
  this.baseURL = transport.baseURL;
1061
+ this.access = new Access(transport);
587
1062
  this.agents = new Agents(transport);
588
1063
  this.chats = new Chats(transport);
589
1064
  this.calls = new Calls(transport);
590
1065
  this.messages = new Messages(transport);
1066
+ this.paymentRequests = new PaymentRequests(transport);
591
1067
  this.attachments = new Attachments(transport);
592
1068
  this.webhookEvents = new WebhookEvents(transport);
593
1069
  this.webhookSubscriptions = new WebhookSubscriptions(transport);
594
1070
  this.contactCard = new ContactCard(transport);
1071
+ this.contacts = new Contacts(transport);
595
1072
  this.blockedHandles = new BlockedHandles(transport);
1073
+ this.communities = new Communities(transport);
1074
+ this.me = new Me(transport);
1075
+ this.tasks = new Tasks(transport);
596
1076
  this.websocket = new WebSocket(transport);
597
1077
  this.webhooks = new Webhooks(options.webhookSecret ?? null);
598
1078
  }