@meshagent/meshagent 0.39.2 → 0.39.4

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 (48) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +134 -21
  3. package/dist/browser/entrypoint.d.ts +1426 -1464
  4. package/dist/browser/meshagent-client.js +7 -2
  5. package/dist/browser/package.json +1 -0
  6. package/dist/esm/agent-client.js +18 -12
  7. package/dist/esm/agent.js +26 -18
  8. package/dist/esm/api_keys.js +21 -11
  9. package/dist/esm/client.js +13 -7
  10. package/dist/esm/completer.js +5 -1
  11. package/dist/esm/containers-client.js +85 -80
  12. package/dist/esm/datasets-client.js +105 -95
  13. package/dist/esm/developer-client.js +15 -11
  14. package/dist/esm/document.js +20 -11
  15. package/dist/esm/entrypoint.d.ts +1426 -1464
  16. package/dist/esm/entrypoint.js +12 -1
  17. package/dist/esm/event-emitter.js +5 -1
  18. package/dist/esm/helpers.js +23 -15
  19. package/dist/esm/index.js +49 -33
  20. package/dist/esm/lk-client.js +12 -7
  21. package/dist/esm/lk-protocol.js +8 -4
  22. package/dist/esm/memory-client.js +11 -7
  23. package/dist/esm/meshagent-client.js +88 -79
  24. package/dist/esm/messaging-client.js +37 -33
  25. package/dist/esm/package.json +1 -0
  26. package/dist/esm/participant-token.js +62 -34
  27. package/dist/esm/participant.js +9 -3
  28. package/dist/esm/protocol.js +43 -29
  29. package/dist/esm/queues-client.js +17 -12
  30. package/dist/esm/requirement.js +11 -4
  31. package/dist/esm/response.js +34 -22
  32. package/dist/esm/room-client.js +134 -129
  33. package/dist/esm/room-event.js +21 -9
  34. package/dist/esm/room-server-client.js +18 -13
  35. package/dist/esm/runtime.js +10 -1
  36. package/dist/esm/schema.js +18 -9
  37. package/dist/esm/secrets-client.js +35 -31
  38. package/dist/esm/services-client.js +13 -9
  39. package/dist/esm/storage-client.js +38 -32
  40. package/dist/esm/stream-controller.js +5 -1
  41. package/dist/esm/sync-client.js +42 -38
  42. package/dist/esm/tool-content-type.js +5 -1
  43. package/dist/esm/utils.js +20 -10
  44. package/dist/esm/version.js +4 -1
  45. package/dist/node/entrypoint.d.ts +1426 -1464
  46. package/dist/node/meshagent-client.js +7 -2
  47. package/dist/node/package.json +1 -0
  48. package/package.json +1 -1
@@ -1,7 +1,10 @@
1
- import { meshagentBaseUrl } from "./helpers";
2
- import { RoomException } from "./requirement";
3
- import { ApiScope } from "./participant-token";
4
- import { decoder, encoder } from "./utils";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Meshagent = void 0;
4
+ const helpers_1 = require("./helpers");
5
+ const requirement_1 = require("./requirement");
6
+ const participant_token_1 = require("./participant-token");
7
+ const utils_1 = require("./utils");
5
8
  function pruneUndefinedValues(value) {
6
9
  if (Array.isArray(value)) {
7
10
  const prunedItems = value
@@ -42,6 +45,11 @@ function serializeServiceSpec(service) {
42
45
  agents,
43
46
  });
44
47
  }
48
+ function serializeCreateServiceSpec(service) {
49
+ const payload = serializeServiceSpec(service);
50
+ delete payload.id;
51
+ return payload;
52
+ }
45
53
  const globalScope = globalThis;
46
54
  function bytesToBase64(bytes) {
47
55
  if (globalScope.Buffer) {
@@ -87,9 +95,9 @@ function normalizeBinary(data) {
87
95
  }
88
96
  return new Uint8Array(data);
89
97
  }
90
- export class Meshagent {
98
+ class Meshagent {
91
99
  constructor({ baseUrl, token } = {}) {
92
- const resolvedBaseUrl = meshagentBaseUrl(baseUrl).replace(/\/+$/, "");
100
+ const resolvedBaseUrl = (0, helpers_1.meshagentBaseUrl)(baseUrl).replace(/\/+$/, "");
93
101
  this.baseUrl = resolvedBaseUrl || "https://api.meshagent.com";
94
102
  const envToken = typeof process !== "undefined" ? process.env?.MESHAGENT_API_KEY : undefined;
95
103
  this.token = token ?? envToken ?? undefined;
@@ -144,7 +152,7 @@ export class Meshagent {
144
152
  catch {
145
153
  message = "<unable to read body>";
146
154
  }
147
- throw new RoomException(`Failed to ${action}. Status code: ${response.status}, body: ${message}`);
155
+ throw new requirement_1.RoomException(`Failed to ${action}. Status code: ${response.status}, body: ${message}`);
148
156
  }
149
157
  switch (responseType) {
150
158
  case "json":
@@ -163,15 +171,15 @@ export class Meshagent {
163
171
  }
164
172
  parseRoomShare(data) {
165
173
  if (!data || typeof data !== "object") {
166
- throw new RoomException("Invalid room share payload: expected object");
174
+ throw new requirement_1.RoomException("Invalid room share payload: expected object");
167
175
  }
168
176
  const { id, project_id: projectId, projectId: projectIdAlt, settings } = data;
169
177
  if (typeof id !== "string") {
170
- throw new RoomException("Invalid room share payload: missing id");
178
+ throw new requirement_1.RoomException("Invalid room share payload: missing id");
171
179
  }
172
180
  const finalProjectId = typeof projectIdAlt === "string" ? projectIdAlt : typeof projectId === "string" ? projectId : undefined;
173
181
  if (!finalProjectId) {
174
- throw new RoomException("Invalid room share payload: missing project id");
182
+ throw new requirement_1.RoomException("Invalid room share payload: missing project id");
175
183
  }
176
184
  return {
177
185
  id,
@@ -181,23 +189,23 @@ export class Meshagent {
181
189
  }
182
190
  parseRoomSession(data) {
183
191
  if (!data || typeof data !== "object") {
184
- throw new RoomException("Invalid room session payload");
192
+ throw new requirement_1.RoomException("Invalid room session payload");
185
193
  }
186
194
  const { id, room_id: roomIdRaw, roomId, room_name: roomNameRaw, roomName, created_at: createdRaw, createdAt, is_active: isActiveRaw, isActive, participants } = data;
187
195
  if (typeof id !== "string") {
188
- throw new RoomException("Invalid room session payload: missing id");
196
+ throw new requirement_1.RoomException("Invalid room session payload: missing id");
189
197
  }
190
198
  const roomNameValue = typeof roomName === "string" ? roomName : roomNameRaw;
191
199
  if (typeof roomNameValue !== "string") {
192
- throw new RoomException("Invalid room session payload: missing room name");
200
+ throw new requirement_1.RoomException("Invalid room session payload: missing room name");
193
201
  }
194
202
  const created = typeof createdAt === "string" ? createdAt : createdRaw;
195
203
  if (typeof created !== "string") {
196
- throw new RoomException("Invalid room session payload: missing created_at");
204
+ throw new requirement_1.RoomException("Invalid room session payload: missing created_at");
197
205
  }
198
206
  const isActiveValue = typeof isActive === "boolean" ? isActive : isActiveRaw;
199
207
  if (typeof isActiveValue !== "boolean") {
200
- throw new RoomException("Invalid room session payload: missing is_active");
208
+ throw new requirement_1.RoomException("Invalid room session payload: missing is_active");
201
209
  }
202
210
  return {
203
211
  id,
@@ -210,11 +218,11 @@ export class Meshagent {
210
218
  }
211
219
  parseRoom(data) {
212
220
  if (!data || typeof data !== "object") {
213
- throw new RoomException("Invalid room payload");
221
+ throw new requirement_1.RoomException("Invalid room payload");
214
222
  }
215
223
  const { id, name, metadata, annotations } = data;
216
224
  if (typeof id !== "string" || typeof name !== "string") {
217
- throw new RoomException("Invalid room payload: missing id or name");
225
+ throw new requirement_1.RoomException("Invalid room payload: missing id or name");
218
226
  }
219
227
  return {
220
228
  id,
@@ -225,7 +233,7 @@ export class Meshagent {
225
233
  }
226
234
  parseFeed(data) {
227
235
  if (!data || typeof data !== "object") {
228
- throw new RoomException("Invalid feed payload");
236
+ throw new requirement_1.RoomException("Invalid feed payload");
229
237
  }
230
238
  const { id, project_id: projectIdRaw, projectId, created_at: createdAtRaw, createdAt, name, description, visibility, paused, annotations, message_schema: messageSchemaRaw, messageSchema, } = data;
231
239
  const projectIdValue = typeof projectId === "string"
@@ -251,7 +259,7 @@ export class Meshagent {
251
259
  typeof createdAtValue !== "string" ||
252
260
  typeof name !== "string" ||
253
261
  visibilityValue === undefined) {
254
- throw new RoomException("Invalid feed payload: missing required fields");
262
+ throw new requirement_1.RoomException("Invalid feed payload: missing required fields");
255
263
  }
256
264
  return {
257
265
  id,
@@ -267,7 +275,7 @@ export class Meshagent {
267
275
  }
268
276
  parseFeedSubscription(data) {
269
277
  if (!data || typeof data !== "object") {
270
- throw new RoomException("Invalid feed subscription payload");
278
+ throw new requirement_1.RoomException("Invalid feed subscription payload");
271
279
  }
272
280
  const { id, feed_id: feedIdRaw, feedId, project_id: projectIdRaw, projectId, room, room_id: roomIdRaw, roomId, path, created_at: createdAtRaw, createdAt, annotations, } = data;
273
281
  const feedIdValue = typeof feedId === "string" ? feedId : feedIdRaw;
@@ -280,7 +288,7 @@ export class Meshagent {
280
288
  typeof room !== "string" ||
281
289
  typeof path !== "string" ||
282
290
  typeof createdAtValue !== "string") {
283
- throw new RoomException("Invalid feed subscription payload: missing required fields");
291
+ throw new requirement_1.RoomException("Invalid feed subscription payload: missing required fields");
284
292
  }
285
293
  return {
286
294
  id,
@@ -295,7 +303,7 @@ export class Meshagent {
295
303
  }
296
304
  parseLLMLogger(data) {
297
305
  if (!data || typeof data !== "object") {
298
- throw new RoomException("Invalid LLM logger payload");
306
+ throw new requirement_1.RoomException("Invalid LLM logger payload");
299
307
  }
300
308
  const { id, project_id: projectIdRaw, projectId, destination_feed_id: destinationFeedIdRaw, destinationFeedId, filter_expression: filterExpressionRaw, filterExpression, paused, created_at: createdAtRaw, createdAt, annotations, } = data;
301
309
  const projectIdValue = typeof projectId === "string" ? projectId : projectIdRaw;
@@ -307,7 +315,7 @@ export class Meshagent {
307
315
  typeof destinationFeedIdValue !== "string" ||
308
316
  typeof filterExpressionValue !== "string" ||
309
317
  typeof createdAtValue !== "string") {
310
- throw new RoomException("Invalid LLM logger payload: missing required fields");
318
+ throw new requirement_1.RoomException("Invalid LLM logger payload: missing required fields");
311
319
  }
312
320
  return {
313
321
  id,
@@ -321,7 +329,7 @@ export class Meshagent {
321
329
  }
322
330
  parseProjectRepository(data) {
323
331
  if (!data || typeof data !== "object") {
324
- throw new RoomException("Invalid repository payload");
332
+ throw new requirement_1.RoomException("Invalid repository payload");
325
333
  }
326
334
  const { id, project_id: projectIdRaw, projectId, name, description, annotations, created_at: createdAtRaw, createdAt, } = data;
327
335
  const projectIdValue = typeof projectId === "string"
@@ -335,7 +343,7 @@ export class Meshagent {
335
343
  ? createdAtRaw
336
344
  : undefined;
337
345
  if (typeof id !== "string" || typeof projectIdValue !== "string" || typeof name !== "string" || typeof createdAtValue !== "string") {
338
- throw new RoomException("Invalid repository payload: missing required fields");
346
+ throw new requirement_1.RoomException("Invalid repository payload: missing required fields");
339
347
  }
340
348
  return {
341
349
  id,
@@ -348,44 +356,44 @@ export class Meshagent {
348
356
  }
349
357
  parseProjectRoomGrant(data) {
350
358
  if (!data || typeof data !== "object") {
351
- throw new RoomException("Invalid room grant payload");
359
+ throw new requirement_1.RoomException("Invalid room grant payload");
352
360
  }
353
361
  const roomData = data.room;
354
362
  const room = this.parseRoom(roomData);
355
363
  const userId = data.user_id ?? data.userId;
356
364
  if (typeof userId !== "string") {
357
- throw new RoomException("Invalid room grant payload: missing user_id");
365
+ throw new requirement_1.RoomException("Invalid room grant payload: missing user_id");
358
366
  }
359
367
  const permissionsRaw = data.permissions;
360
- const permissions = permissionsRaw && typeof permissionsRaw === "object" ? ApiScope.fromJSON(permissionsRaw) : new ApiScope();
368
+ const permissions = permissionsRaw && typeof permissionsRaw === "object" ? participant_token_1.ApiScope.fromJSON(permissionsRaw) : new participant_token_1.ApiScope();
361
369
  return { room, userId, permissions };
362
370
  }
363
371
  parseProjectRoomGrantCount(data) {
364
372
  const roomData = (data && typeof data === "object") ? (data.room ?? { id: data.room_id, name: data.room_name, metadata: data.metadata ?? {} }) : undefined;
365
373
  if (!roomData) {
366
- throw new RoomException("Invalid room grant count payload: missing room");
374
+ throw new requirement_1.RoomException("Invalid room grant count payload: missing room");
367
375
  }
368
376
  const room = this.parseRoom(roomData);
369
377
  const count = data.count;
370
378
  if (typeof count !== "number") {
371
- throw new RoomException("Invalid room grant count payload: missing count");
379
+ throw new requirement_1.RoomException("Invalid room grant count payload: missing count");
372
380
  }
373
381
  return { room, count };
374
382
  }
375
383
  parseProjectUserGrantCount(data) {
376
384
  if (!data || typeof data !== "object") {
377
- throw new RoomException("Invalid room grant user count payload");
385
+ throw new requirement_1.RoomException("Invalid room grant user count payload");
378
386
  }
379
387
  const { user_id: userIdRaw, userId, count, first_name: firstNameRaw, firstName, last_name: lastNameRaw, lastName, email } = data;
380
388
  const userIdValue = typeof userId === "string" ? userId : userIdRaw;
381
389
  if (typeof userIdValue !== "string") {
382
- throw new RoomException("Invalid room grant user count payload: missing user_id");
390
+ throw new requirement_1.RoomException("Invalid room grant user count payload: missing user_id");
383
391
  }
384
392
  if (typeof count !== "number") {
385
- throw new RoomException("Invalid room grant user count payload: missing count");
393
+ throw new requirement_1.RoomException("Invalid room grant user count payload: missing count");
386
394
  }
387
395
  if (typeof email !== "string") {
388
- throw new RoomException("Invalid room grant user count payload: missing email");
396
+ throw new requirement_1.RoomException("Invalid room grant user count payload: missing email");
389
397
  }
390
398
  return {
391
399
  userId: userIdValue,
@@ -397,11 +405,11 @@ export class Meshagent {
397
405
  }
398
406
  parseBalance(data) {
399
407
  if (!data || typeof data !== "object") {
400
- throw new RoomException("Invalid balance payload");
408
+ throw new requirement_1.RoomException("Invalid balance payload");
401
409
  }
402
410
  const balanceValue = data.balance;
403
411
  if (typeof balanceValue !== "number") {
404
- throw new RoomException("Invalid balance payload: missing balance");
412
+ throw new requirement_1.RoomException("Invalid balance payload: missing balance");
405
413
  }
406
414
  const threshold = data.auto_recharge_threshold ?? data.autoRechargeThreshold;
407
415
  const amount = data.auto_recharge_amount ?? data.autoRechargeAmount;
@@ -421,15 +429,15 @@ export class Meshagent {
421
429
  }
422
430
  parseTransaction(data) {
423
431
  if (!data || typeof data !== "object") {
424
- throw new RoomException("Invalid transaction payload");
432
+ throw new requirement_1.RoomException("Invalid transaction payload");
425
433
  }
426
434
  const { id, amount, reference, referenceType, reference_type: referenceTypeRaw, description, created_at: createdAtRaw, createdAt } = data;
427
435
  if (typeof id !== "string" || typeof amount !== "number" || typeof description !== "string") {
428
- throw new RoomException("Invalid transaction payload: missing fields");
436
+ throw new requirement_1.RoomException("Invalid transaction payload: missing fields");
429
437
  }
430
438
  const createdValue = typeof createdAt === "string" ? createdAt : createdAtRaw;
431
439
  if (typeof createdValue !== "string") {
432
- throw new RoomException("Invalid transaction payload: missing created_at");
440
+ throw new requirement_1.RoomException("Invalid transaction payload: missing created_at");
433
441
  }
434
442
  const referenceTypeValue = typeof referenceType === "string" ? referenceType : referenceTypeRaw;
435
443
  return {
@@ -443,7 +451,7 @@ export class Meshagent {
443
451
  }
444
452
  parseSecret(data) {
445
453
  if (!data || typeof data !== "object") {
446
- throw new RoomException("Invalid secret payload");
454
+ throw new requirement_1.RoomException("Invalid secret payload");
447
455
  }
448
456
  const type = data.type;
449
457
  if (type === "docker") {
@@ -451,7 +459,7 @@ export class Meshagent {
451
459
  const username = data.username;
452
460
  const password = data.password;
453
461
  if (typeof server !== "string" || typeof username !== "string" || typeof password !== "string") {
454
- throw new RoomException("Invalid docker secret payload");
462
+ throw new requirement_1.RoomException("Invalid docker secret payload");
455
463
  }
456
464
  return {
457
465
  id: typeof data.id === "string" ? data.id : undefined,
@@ -466,7 +474,7 @@ export class Meshagent {
466
474
  if (type === "keys") {
467
475
  const record = data.data;
468
476
  if (!record || typeof record !== "object") {
469
- throw new RoomException("Invalid keys secret payload");
477
+ throw new requirement_1.RoomException("Invalid keys secret payload");
470
478
  }
471
479
  return {
472
480
  id: typeof data.id === "string" ? data.id : undefined,
@@ -475,15 +483,15 @@ export class Meshagent {
475
483
  data: record,
476
484
  };
477
485
  }
478
- throw new RoomException(`Unknown secret type: ${type}`);
486
+ throw new requirement_1.RoomException(`Unknown secret type: ${type}`);
479
487
  }
480
488
  parseManagedSecretInfo(data) {
481
489
  if (!data || typeof data !== "object") {
482
- throw new RoomException("Invalid managed secret payload");
490
+ throw new requirement_1.RoomException("Invalid managed secret payload");
483
491
  }
484
492
  const { id, type, name, delegated_to: delegatedToRaw, delegatedTo } = data;
485
493
  if (typeof id !== "string" || typeof type !== "string" || typeof name !== "string") {
486
- throw new RoomException("Invalid managed secret payload: missing id, type, or name");
494
+ throw new requirement_1.RoomException("Invalid managed secret payload: missing id, type, or name");
487
495
  }
488
496
  const delegatedToValue = typeof delegatedTo === "string"
489
497
  ? delegatedTo
@@ -501,7 +509,7 @@ export class Meshagent {
501
509
  const secret = this.parseManagedSecretInfo(data);
502
510
  const dataBase64 = data.data_base64 ?? data.dataBase64;
503
511
  if (typeof dataBase64 !== "string") {
504
- throw new RoomException("Invalid managed secret payload: missing data_base64");
512
+ throw new requirement_1.RoomException("Invalid managed secret payload: missing data_base64");
505
513
  }
506
514
  return {
507
515
  ...secret,
@@ -512,18 +520,18 @@ export class Meshagent {
512
520
  parseSecretPayload(secret, rawData) {
513
521
  let payload;
514
522
  try {
515
- payload = JSON.parse(decoder.decode(rawData));
523
+ payload = JSON.parse(utils_1.decoder.decode(rawData));
516
524
  }
517
525
  catch {
518
- throw new RoomException(`Invalid secret payload for ${secret.id}`);
526
+ throw new requirement_1.RoomException(`Invalid secret payload for ${secret.id}`);
519
527
  }
520
528
  if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
521
- throw new RoomException(`Invalid secret payload for ${secret.id}`);
529
+ throw new requirement_1.RoomException(`Invalid secret payload for ${secret.id}`);
522
530
  }
523
531
  if (secret.type === "docker") {
524
532
  const { server, username, password, email } = payload;
525
533
  if (typeof server !== "string" || typeof username !== "string" || typeof password !== "string") {
526
- throw new RoomException(`Invalid secret payload for ${secret.id}`);
534
+ throw new requirement_1.RoomException(`Invalid secret payload for ${secret.id}`);
527
535
  }
528
536
  return {
529
537
  id: secret.id,
@@ -537,7 +545,7 @@ export class Meshagent {
537
545
  }
538
546
  const entries = Object.entries(payload);
539
547
  if (entries.some(([, value]) => typeof value !== "string")) {
540
- throw new RoomException(`Invalid secret payload for ${secret.id}`);
548
+ throw new requirement_1.RoomException(`Invalid secret payload for ${secret.id}`);
541
549
  }
542
550
  return {
543
551
  id: secret.id,
@@ -570,7 +578,7 @@ export class Meshagent {
570
578
  return null;
571
579
  }
572
580
  if (typeof data !== "object") {
573
- throw new RoomException("Invalid connector payload");
581
+ throw new requirement_1.RoomException("Invalid connector payload");
574
582
  }
575
583
  const { openai_connector_id: openaiConnectorIdRaw, openaiConnectorId, server_url: serverUrlRaw, serverUrl, client_secret_id: clientSecretIdRaw, clientSecretId, } = data;
576
584
  return {
@@ -609,14 +617,14 @@ export class Meshagent {
609
617
  }
610
618
  parseExternalOAuthClientRegistration(data) {
611
619
  if (!data || typeof data !== "object") {
612
- throw new RoomException("Invalid external oauth registration payload");
620
+ throw new requirement_1.RoomException("Invalid external oauth registration payload");
613
621
  }
614
622
  const { id, delegated_to: delegatedToRaw, delegatedTo, connector, oauth, client_id: clientIdRaw, clientId, client_secret: clientSecretRaw, clientSecret, } = data;
615
623
  const delegatedToValue = typeof delegatedTo === "string" ? delegatedTo : delegatedToRaw;
616
624
  const clientIdValue = typeof clientId === "string" ? clientId : clientIdRaw;
617
625
  const clientSecretValue = typeof clientSecret === "string" ? clientSecret : clientSecretRaw;
618
626
  if (typeof id !== "string" || typeof delegatedToValue !== "string" || typeof clientIdValue !== "string") {
619
- throw new RoomException("Invalid external oauth registration payload: missing fields");
627
+ throw new requirement_1.RoomException("Invalid external oauth registration payload: missing fields");
620
628
  }
621
629
  return {
622
630
  id,
@@ -629,7 +637,7 @@ export class Meshagent {
629
637
  }
630
638
  parseOAuthClient(data) {
631
639
  if (!data || typeof data !== "object") {
632
- throw new RoomException("Invalid OAuth client payload");
640
+ throw new requirement_1.RoomException("Invalid OAuth client payload");
633
641
  }
634
642
  const { client_id: clientIdRaw, clientId, client_secret: clientSecretRaw, clientSecret, grant_types: grantTypesRaw, grantTypes, response_types: responseTypesRaw, responseTypes, redirect_uris: redirectUrisRaw, redirectUris, scope, project_id: projectIdRaw, projectId, metadata } = data;
635
643
  const clientIdValue = typeof clientId === "string" ? clientId : clientIdRaw;
@@ -645,7 +653,7 @@ export class Meshagent {
645
653
  !Array.isArray(redirectUrisValue) ||
646
654
  typeof scope !== "string" ||
647
655
  typeof projectIdValue !== "string") {
648
- throw new RoomException("Invalid OAuth client payload: missing required fields");
656
+ throw new requirement_1.RoomException("Invalid OAuth client payload: missing required fields");
649
657
  }
650
658
  return {
651
659
  clientId: clientIdValue,
@@ -660,14 +668,14 @@ export class Meshagent {
660
668
  }
661
669
  parseRoomConnectionInfo(data) {
662
670
  if (!data || typeof data !== "object") {
663
- throw new RoomException("Invalid room connection payload");
671
+ throw new requirement_1.RoomException("Invalid room connection payload");
664
672
  }
665
673
  const { jwt, room_name: roomNameRaw, roomName, project_id: projectIdRaw, projectId, room_url: roomUrlRaw, roomUrl } = data;
666
674
  const roomNameValue = typeof roomName === "string" ? roomName : roomNameRaw;
667
675
  const projectIdValue = typeof projectId === "string" ? projectId : projectIdRaw;
668
676
  const roomUrlValue = typeof roomUrl === "string" ? roomUrl : roomUrlRaw;
669
677
  if (typeof jwt !== "string" || typeof roomNameValue !== "string" || typeof projectIdValue !== "string" || typeof roomUrlValue !== "string") {
670
- throw new RoomException("Invalid room connection payload: missing fields");
678
+ throw new requirement_1.RoomException("Invalid room connection payload: missing fields");
671
679
  }
672
680
  return { jwt, roomName: roomNameValue, projectId: projectIdValue, roomUrl: roomUrlValue };
673
681
  }
@@ -702,7 +710,7 @@ export class Meshagent {
702
710
  });
703
711
  const role = payload?.role;
704
712
  if (role !== "member" && role !== "admin" && role !== "developer") {
705
- throw new RoomException("Invalid role payload");
713
+ throw new requirement_1.RoomException("Invalid role payload");
706
714
  }
707
715
  return role;
708
716
  }
@@ -836,7 +844,7 @@ export class Meshagent {
836
844
  });
837
845
  const enabled = data?.["enabled"];
838
846
  if (typeof enabled !== "boolean") {
839
- throw new RoomException("Invalid status payload: expected boolean 'enabled'");
847
+ throw new requirement_1.RoomException("Invalid status payload: expected boolean 'enabled'");
840
848
  }
841
849
  return enabled;
842
850
  }
@@ -869,7 +877,7 @@ export class Meshagent {
869
877
  });
870
878
  const url = data?.["checkout_url"];
871
879
  if (typeof url !== "string") {
872
- throw new RoomException("Invalid subscription payload: expected 'checkout_url' string");
880
+ throw new requirement_1.RoomException("Invalid subscription payload: expected 'checkout_url' string");
873
881
  }
874
882
  return url;
875
883
  }
@@ -881,7 +889,7 @@ export class Meshagent {
881
889
  });
882
890
  const url = data?.["checkout_url"];
883
891
  if (typeof url !== "string") {
884
- throw new RoomException("Invalid credits payload: expected 'checkout_url' string");
892
+ throw new requirement_1.RoomException("Invalid credits payload: expected 'checkout_url' string");
885
893
  }
886
894
  return url;
887
895
  }
@@ -910,7 +918,7 @@ export class Meshagent {
910
918
  });
911
919
  const usage = data?.["usage"];
912
920
  if (!Array.isArray(usage)) {
913
- throw new RoomException("Invalid usage payload: expected 'usage' to be a list");
921
+ throw new requirement_1.RoomException("Invalid usage payload: expected 'usage' to be a list");
914
922
  }
915
923
  return usage.filter((item) => item && typeof item === "object");
916
924
  }
@@ -1009,14 +1017,14 @@ export class Meshagent {
1009
1017
  }
1010
1018
  parseMailbox(item) {
1011
1019
  if (!item || typeof item !== "object") {
1012
- throw new RoomException("Invalid mailbox payload");
1020
+ throw new requirement_1.RoomException("Invalid mailbox payload");
1013
1021
  }
1014
1022
  const { address, room, room_id, queue } = item;
1015
1023
  if (typeof address !== "string" || typeof room !== "string" || typeof queue !== "string") {
1016
- throw new RoomException("Invalid mailbox payload: missing fields");
1024
+ throw new requirement_1.RoomException("Invalid mailbox payload: missing fields");
1017
1025
  }
1018
1026
  if (room_id !== undefined && typeof room_id !== "string") {
1019
- throw new RoomException("Invalid mailbox payload: invalid room_id");
1027
+ throw new requirement_1.RoomException("Invalid mailbox payload: invalid room_id");
1020
1028
  }
1021
1029
  return { address, room, roomId: room_id, queue };
1022
1030
  }
@@ -1258,22 +1266,22 @@ export class Meshagent {
1258
1266
  async createService(projectId, service) {
1259
1267
  const data = await this.request(`/accounts/projects/${projectId}/services`, {
1260
1268
  method: "POST",
1261
- json: serializeServiceSpec(service),
1269
+ json: serializeCreateServiceSpec(service),
1262
1270
  action: "create service",
1263
1271
  });
1264
1272
  if (!data || typeof data !== "object" || typeof data.id !== "string") {
1265
- throw new RoomException("Invalid create service response payload");
1273
+ throw new requirement_1.RoomException("Invalid create service response payload");
1266
1274
  }
1267
1275
  return data.id;
1268
1276
  }
1269
1277
  async createRoomService(projectId, roomName, service) {
1270
1278
  const data = await this.request(`/accounts/projects/${projectId}/rooms/${roomName}/services`, {
1271
1279
  method: "POST",
1272
- json: serializeServiceSpec(service),
1280
+ json: serializeCreateServiceSpec(service),
1273
1281
  action: "create room service",
1274
1282
  });
1275
1283
  if (!data || typeof data !== "object" || typeof data.id !== "string") {
1276
- throw new RoomException("Invalid create room service response payload");
1284
+ throw new requirement_1.RoomException("Invalid create room service response payload");
1277
1285
  }
1278
1286
  return data.id;
1279
1287
  }
@@ -1307,7 +1315,7 @@ export class Meshagent {
1307
1315
  }
1308
1316
  async updateService(projectId, serviceId, service) {
1309
1317
  if (!service.id) {
1310
- throw new RoomException("Service id must be set to update a service");
1318
+ throw new requirement_1.RoomException("Service id must be set to update a service");
1311
1319
  }
1312
1320
  await this.request(`/accounts/projects/${projectId}/services/${serviceId}`, {
1313
1321
  method: "PUT",
@@ -1348,7 +1356,7 @@ export class Meshagent {
1348
1356
  action: "create project secret",
1349
1357
  });
1350
1358
  if (!payload || typeof payload !== "object" || typeof payload.id !== "string") {
1351
- throw new RoomException("Invalid create project secret response payload");
1359
+ throw new requirement_1.RoomException("Invalid create project secret response payload");
1352
1360
  }
1353
1361
  return payload.id;
1354
1362
  }
@@ -1400,7 +1408,7 @@ export class Meshagent {
1400
1408
  action: "create room secret",
1401
1409
  });
1402
1410
  if (!payload || typeof payload !== "object" || typeof payload.id !== "string") {
1403
- throw new RoomException("Invalid create room secret response payload");
1411
+ throw new requirement_1.RoomException("Invalid create room secret response payload");
1404
1412
  }
1405
1413
  return payload.id;
1406
1414
  }
@@ -1458,19 +1466,19 @@ export class Meshagent {
1458
1466
  projectId,
1459
1467
  name: secret.name,
1460
1468
  type: secret.type,
1461
- data: encoder.encode(JSON.stringify(this.toSecretPayload(secret).data)),
1469
+ data: utils_1.encoder.encode(JSON.stringify(this.toSecretPayload(secret).data)),
1462
1470
  });
1463
1471
  }
1464
1472
  async updateSecret(projectId, secret) {
1465
1473
  if (!secret.id) {
1466
- throw new RoomException("Secret id is required to update a secret");
1474
+ throw new requirement_1.RoomException("Secret id is required to update a secret");
1467
1475
  }
1468
1476
  await this.updateProjectSecret({
1469
1477
  projectId,
1470
1478
  secretId: secret.id,
1471
1479
  name: secret.name,
1472
1480
  type: secret.type,
1473
- data: encoder.encode(JSON.stringify(this.toSecretPayload(secret).data)),
1481
+ data: utils_1.encoder.encode(JSON.stringify(this.toSecretPayload(secret).data)),
1474
1482
  });
1475
1483
  }
1476
1484
  async deleteSecret(projectId, secretId) {
@@ -1498,7 +1506,7 @@ export class Meshagent {
1498
1506
  action: "create project external oauth registration",
1499
1507
  });
1500
1508
  if (!payload || typeof payload !== "object" || typeof payload.id !== "string") {
1501
- throw new RoomException("Invalid create project external oauth registration response payload");
1509
+ throw new requirement_1.RoomException("Invalid create project external oauth registration response payload");
1502
1510
  }
1503
1511
  return payload.id;
1504
1512
  }
@@ -1553,7 +1561,7 @@ export class Meshagent {
1553
1561
  action: "create room external oauth registration",
1554
1562
  });
1555
1563
  if (!payload || typeof payload !== "object" || typeof payload.id !== "string") {
1556
- throw new RoomException("Invalid create room external oauth registration response payload");
1564
+ throw new requirement_1.RoomException("Invalid create room external oauth registration response payload");
1557
1565
  }
1558
1566
  return payload.id;
1559
1567
  }
@@ -1605,7 +1613,7 @@ export class Meshagent {
1605
1613
  if (permissions) {
1606
1614
  const serialized = {};
1607
1615
  for (const [key, value] of Object.entries(permissions)) {
1608
- serialized[key] = value instanceof ApiScope ? value.toJSON() : value;
1616
+ serialized[key] = value instanceof participant_token_1.ApiScope ? value.toJSON() : value;
1609
1617
  }
1610
1618
  payload["permissions"] = serialized;
1611
1619
  }
@@ -1825,3 +1833,4 @@ export class Meshagent {
1825
1833
  });
1826
1834
  }
1827
1835
  }
1836
+ exports.Meshagent = Meshagent;