@meshagent/meshagent 0.42.2 → 0.43.1

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 (161) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/browser/agent-client.d.ts +4 -4
  3. package/dist/browser/agent-client.js +16 -16
  4. package/dist/browser/agent.d.ts +6 -6
  5. package/dist/browser/agent.js +57 -57
  6. package/dist/browser/api_keys.js +7 -3
  7. package/dist/browser/containers-client.d.ts +3 -3
  8. package/dist/browser/containers-client.js +76 -76
  9. package/dist/browser/datasets-client.d.ts +1 -1
  10. package/dist/browser/datasets-client.js +83 -83
  11. package/dist/browser/developer-client.d.ts +3 -3
  12. package/dist/browser/developer-client.js +11 -11
  13. package/dist/browser/document.d.ts +2 -2
  14. package/dist/browser/document.js +3 -3
  15. package/dist/browser/helpers.d.ts +4 -4
  16. package/dist/browser/helpers.js +9 -9
  17. package/dist/browser/index.d.ts +35 -35
  18. package/dist/browser/index.js +35 -35
  19. package/dist/browser/memory-client.d.ts +1 -1
  20. package/dist/browser/memory-client.js +6 -6
  21. package/dist/browser/meshagent-client.d.ts +1 -1
  22. package/dist/browser/meshagent-client.js +78 -78
  23. package/dist/browser/messaging-client.d.ts +4 -4
  24. package/dist/browser/messaging-client.js +33 -33
  25. package/dist/browser/participant-token.d.ts +1 -1
  26. package/dist/browser/participant-token.js +5 -5
  27. package/dist/browser/participant.d.ts +1 -1
  28. package/dist/browser/protocol.d.ts +7 -4
  29. package/dist/browser/protocol.js +36 -20
  30. package/dist/browser/queues-client.d.ts +1 -1
  31. package/dist/browser/queues-client.js +10 -10
  32. package/dist/browser/response.js +11 -11
  33. package/dist/browser/room-client.d.ts +23 -17
  34. package/dist/browser/room-client.js +138 -130
  35. package/dist/browser/room-server-client.d.ts +2 -2
  36. package/dist/browser/room-server-client.js +10 -10
  37. package/dist/browser/secrets-client.d.ts +3 -3
  38. package/dist/browser/secrets-client.js +30 -30
  39. package/dist/browser/services-client.d.ts +2 -2
  40. package/dist/browser/services-client.js +8 -8
  41. package/dist/browser/storage-client.d.ts +5 -5
  42. package/dist/browser/storage-client.js +30 -30
  43. package/dist/browser/sync-client.d.ts +4 -4
  44. package/dist/browser/sync-client.js +38 -38
  45. package/dist/browser/toolkit-config.d.ts +3 -3
  46. package/dist/esm/agent-client.d.ts +4 -4
  47. package/dist/esm/agent-client.js +19 -25
  48. package/dist/esm/agent.d.ts +6 -6
  49. package/dist/esm/agent.js +73 -93
  50. package/dist/esm/api_keys.js +12 -21
  51. package/dist/esm/client.js +7 -13
  52. package/dist/esm/completer.js +1 -5
  53. package/dist/esm/containers-client.d.ts +3 -3
  54. package/dist/esm/containers-client.js +82 -87
  55. package/dist/esm/datasets-client.d.ts +1 -1
  56. package/dist/esm/datasets-client.js +101 -111
  57. package/dist/esm/developer-client.d.ts +3 -3
  58. package/dist/esm/developer-client.js +11 -15
  59. package/dist/esm/document.d.ts +2 -2
  60. package/dist/esm/document.js +11 -20
  61. package/dist/esm/entrypoint.js +1 -12
  62. package/dist/esm/event-emitter.js +1 -5
  63. package/dist/esm/helpers.d.ts +4 -4
  64. package/dist/esm/helpers.js +15 -23
  65. package/dist/esm/index.d.ts +35 -35
  66. package/dist/esm/index.js +35 -51
  67. package/dist/esm/memory-client.d.ts +1 -1
  68. package/dist/esm/memory-client.js +7 -11
  69. package/dist/esm/meshagent-client.d.ts +1 -1
  70. package/dist/esm/meshagent-client.js +79 -83
  71. package/dist/esm/messaging-client.d.ts +4 -4
  72. package/dist/esm/messaging-client.js +33 -37
  73. package/dist/esm/oauth-scopes.js +2 -5
  74. package/dist/esm/participant-token.d.ts +1 -1
  75. package/dist/esm/participant-token.js +34 -62
  76. package/dist/esm/participant.d.ts +1 -1
  77. package/dist/esm/participant.js +3 -9
  78. package/dist/esm/protocol.d.ts +7 -4
  79. package/dist/esm/protocol.js +48 -46
  80. package/dist/esm/queues-client.d.ts +1 -1
  81. package/dist/esm/queues-client.js +12 -17
  82. package/dist/esm/requirement.js +4 -11
  83. package/dist/esm/response.js +22 -34
  84. package/dist/esm/room-client.d.ts +23 -17
  85. package/dist/esm/room-client.js +140 -137
  86. package/dist/esm/room-event.js +9 -21
  87. package/dist/esm/room-server-client.d.ts +2 -2
  88. package/dist/esm/room-server-client.js +13 -18
  89. package/dist/esm/runtime.js +1 -10
  90. package/dist/esm/schema.js +9 -18
  91. package/dist/esm/secrets-client.d.ts +3 -3
  92. package/dist/esm/secrets-client.js +31 -35
  93. package/dist/esm/services-client.d.ts +2 -2
  94. package/dist/esm/services-client.js +9 -13
  95. package/dist/esm/storage-client.d.ts +5 -5
  96. package/dist/esm/storage-client.js +32 -38
  97. package/dist/esm/stream-controller.js +1 -5
  98. package/dist/esm/sync-client.d.ts +4 -4
  99. package/dist/esm/sync-client.js +38 -42
  100. package/dist/esm/tool-content-type.js +1 -5
  101. package/dist/esm/toolkit-config.d.ts +3 -3
  102. package/dist/esm/toolkit-config.js +5 -13
  103. package/dist/esm/utils.js +10 -20
  104. package/dist/esm/version.js +1 -4
  105. package/dist/node/agent-client.d.ts +4 -4
  106. package/dist/node/agent-client.js +16 -16
  107. package/dist/node/agent.d.ts +6 -6
  108. package/dist/node/agent.js +57 -57
  109. package/dist/node/api_keys.js +7 -3
  110. package/dist/node/containers-client.d.ts +3 -3
  111. package/dist/node/containers-client.js +76 -76
  112. package/dist/node/datasets-client.d.ts +1 -1
  113. package/dist/node/datasets-client.js +83 -83
  114. package/dist/node/developer-client.d.ts +3 -3
  115. package/dist/node/developer-client.js +11 -11
  116. package/dist/node/document.d.ts +2 -2
  117. package/dist/node/document.js +3 -3
  118. package/dist/node/helpers.d.ts +4 -4
  119. package/dist/node/helpers.js +9 -9
  120. package/dist/node/index.d.ts +35 -35
  121. package/dist/node/index.js +35 -35
  122. package/dist/node/memory-client.d.ts +1 -1
  123. package/dist/node/memory-client.js +6 -6
  124. package/dist/node/meshagent-client.d.ts +1 -1
  125. package/dist/node/meshagent-client.js +78 -78
  126. package/dist/node/messaging-client.d.ts +4 -4
  127. package/dist/node/messaging-client.js +33 -33
  128. package/dist/node/participant-token.d.ts +1 -1
  129. package/dist/node/participant-token.js +5 -5
  130. package/dist/node/participant.d.ts +1 -1
  131. package/dist/node/protocol.d.ts +7 -4
  132. package/dist/node/protocol.js +36 -20
  133. package/dist/node/queues-client.d.ts +1 -1
  134. package/dist/node/queues-client.js +10 -10
  135. package/dist/node/response.js +11 -11
  136. package/dist/node/room-client.d.ts +23 -17
  137. package/dist/node/room-client.js +138 -130
  138. package/dist/node/room-server-client.d.ts +2 -2
  139. package/dist/node/room-server-client.js +10 -10
  140. package/dist/node/secrets-client.d.ts +3 -3
  141. package/dist/node/secrets-client.js +30 -30
  142. package/dist/node/services-client.d.ts +2 -2
  143. package/dist/node/services-client.js +8 -8
  144. package/dist/node/storage-client.d.ts +5 -5
  145. package/dist/node/storage-client.js +30 -30
  146. package/dist/node/sync-client.d.ts +4 -4
  147. package/dist/node/sync-client.js +38 -38
  148. package/dist/node/toolkit-config.d.ts +3 -3
  149. package/package.json +11 -5
  150. package/dist/browser/lk-client.d.ts +0 -18
  151. package/dist/browser/lk-client.js +0 -33
  152. package/dist/browser/lk-protocol.d.ts +0 -22
  153. package/dist/browser/lk-protocol.js +0 -37
  154. package/dist/esm/lk-client.d.ts +0 -18
  155. package/dist/esm/lk-client.js +0 -33
  156. package/dist/esm/lk-protocol.d.ts +0 -22
  157. package/dist/esm/lk-protocol.js +0 -37
  158. package/dist/node/lk-client.d.ts +0 -18
  159. package/dist/node/lk-client.js +0 -33
  160. package/dist/node/lk-protocol.d.ts +0 -22
  161. package/dist/node/lk-protocol.js +0 -37
@@ -1,26 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RoomClient = exports.RoomProtocolProxy = void 0;
4
- const completer_1 = require("./completer");
5
- const datasets_client_1 = require("./datasets-client");
6
- const developer_client_1 = require("./developer-client");
7
- const event_emitter_1 = require("./event-emitter");
8
- const messaging_client_1 = require("./messaging-client");
9
- const memory_client_1 = require("./memory-client");
10
- const participant_1 = require("./participant");
11
- const protocol_1 = require("./protocol");
12
- const queues_client_1 = require("./queues-client");
13
- const response_1 = require("./response");
14
- const room_event_1 = require("./room-event");
15
- const room_server_client_1 = require("./room-server-client");
16
- const secrets_client_1 = require("./secrets-client");
17
- const services_client_1 = require("./services-client");
18
- const storage_client_1 = require("./storage-client");
19
- const stream_controller_1 = require("./stream-controller");
20
- const sync_client_1 = require("./sync-client");
21
- const utils_1 = require("./utils");
22
- const agent_client_1 = require("./agent-client");
23
- const containers_client_1 = require("./containers-client");
1
+ import { Completer } from "./completer.js";
2
+ import { DatasetsClient } from "./datasets-client.js";
3
+ import { DeveloperClient } from "./developer-client.js";
4
+ import { EventEmitter } from "./event-emitter.js";
5
+ import { MessagingClient } from "./messaging-client.js";
6
+ import { MemoryClient } from "./memory-client.js";
7
+ import { LocalParticipant } from "./participant.js";
8
+ import { ProtocolCloseException, ProtocolCloseKind, ProtocolHandshakeException, ProtocolReconnectUnsupportedException, WebSocketClientProtocol, } from "./protocol.js";
9
+ import { QueuesClient } from "./queues-client.js";
10
+ import { BinaryContent, ControlContent, EmptyContent, ErrorContent, FileContent, JsonContent, LinkContent, TextContent, unpackContent } from "./response.js";
11
+ import { RoomStatusEvent } from "./room-event.js";
12
+ import { RoomServerException } from "./room-server-client.js";
13
+ import { SecretsClient } from "./secrets-client.js";
14
+ import { ServicesClient } from "./services-client.js";
15
+ import { StorageClient } from "./storage-client.js";
16
+ import { StreamController } from "./stream-controller.js";
17
+ import { SyncClient } from "./sync-client.js";
18
+ import { splitMessageHeader, splitMessagePayload, packMessage, unpackMessage } from "./utils.js";
19
+ import { AgentsClient, ToolkitDescription } from "./agent-client.js";
20
+ import { ContainersClient } from "./containers-client.js";
24
21
  class ProtocolStartupFailure extends Error {
25
22
  constructor({ kind, reason }) {
26
23
  super(reason ?? kind);
@@ -30,7 +27,7 @@ class ProtocolStartupFailure extends Error {
30
27
  }
31
28
  }
32
29
  function isRetryableStartupClose({ kind, reason, }) {
33
- if (kind === protocol_1.ProtocolCloseKind.ERROR) {
30
+ if (kind === ProtocolCloseKind.ERROR) {
34
31
  return true;
35
32
  }
36
33
  return (reason ?? "").toLowerCase().includes("1013");
@@ -42,16 +39,16 @@ class RoomClientTerminalState {
42
39
  this.messageSendMessage = messageSendMessage;
43
40
  }
44
41
  requestError() {
45
- return new room_server_client_1.RoomServerException(this.requestMessage);
42
+ return new RoomServerException(this.requestMessage);
46
43
  }
47
44
  toolCallError() {
48
- return new room_server_client_1.RoomServerException(this.toolCallMessage);
45
+ return new RoomServerException(this.toolCallMessage);
49
46
  }
50
47
  messageSendError() {
51
- return new room_server_client_1.RoomServerException(this.messageSendMessage);
48
+ return new RoomServerException(this.messageSendMessage);
52
49
  }
53
50
  }
54
- class RoomConnectionStatusException extends room_server_client_1.RoomServerException {
51
+ class RoomConnectionStatusException extends RoomServerException {
55
52
  constructor({ statusCode, statusText, }) {
56
53
  const normalizedStatusText = statusText?.trim();
57
54
  super(normalizedStatusText == null || normalizedStatusText.length === 0
@@ -69,19 +66,19 @@ function normalizeCloseReason(reason) {
69
66
  return normalized.length === 0 ? null : normalized;
70
67
  }
71
68
  function wrapRoomConnectionError(error) {
72
- if (error instanceof room_server_client_1.RoomServerException) {
69
+ if (error instanceof RoomServerException) {
73
70
  return error;
74
71
  }
75
- if (error instanceof protocol_1.ProtocolHandshakeException) {
72
+ if (error instanceof ProtocolHandshakeException) {
76
73
  return new RoomConnectionStatusException({
77
74
  statusCode: error.statusCode,
78
75
  statusText: error.statusText,
79
76
  });
80
77
  }
81
- if (error instanceof protocol_1.ProtocolCloseException) {
82
- return new room_server_client_1.RoomServerException(normalizeCloseReason(error.reason) ?? `room connection closed with status ${error.closeCode}`);
78
+ if (error instanceof ProtocolCloseException) {
79
+ return new RoomServerException(normalizeCloseReason(error.reason) ?? `room connection closed with status ${error.closeCode}`);
83
80
  }
84
- return new room_server_client_1.RoomServerException(`room connection error: ${String(error)}`);
81
+ return new RoomServerException(`room connection error: ${String(error)}`);
85
82
  }
86
83
  function nonRetryableConnectFailureReason(error) {
87
84
  if (error instanceof RoomConnectionStatusException
@@ -91,7 +88,7 @@ function nonRetryableConnectFailureReason(error) {
91
88
  return null;
92
89
  }
93
90
  function roomClosedBeforeReadyError(protocol) {
94
- return new room_server_client_1.RoomServerException(normalizeCloseReason(protocol.closeReason) ?? "room connection closed before request completed");
91
+ return new RoomServerException(normalizeCloseReason(protocol.closeReason) ?? "room connection closed before request completed");
95
92
  }
96
93
  function getEnvironmentValue(name) {
97
94
  if (typeof process === "undefined") {
@@ -118,12 +115,12 @@ function createProtocolFactoryFromEnvironment() {
118
115
  if (roomName == null || roomName.trim().length === 0 || token == null || token.trim().length === 0) {
119
116
  throw new Error("protocolFactory must be configured or MESHAGENT_ROOM and MESHAGENT_TOKEN must be set in the environment");
120
117
  }
121
- return protocol_1.WebSocketClientProtocol.createFactory({
118
+ return WebSocketClientProtocol.createFactory({
122
119
  url: websocketRoomUrlFromEnvironment(roomName),
123
120
  token,
124
121
  });
125
122
  }
126
- class RoomProtocolProxy {
123
+ export class RoomProtocolProxy {
127
124
  constructor({ room }) {
128
125
  this._handlers = new Map();
129
126
  this._room = room;
@@ -207,20 +204,19 @@ class RoomProtocolProxy {
207
204
  return this._room._protocolInstance.url;
208
205
  }
209
206
  }
210
- exports.RoomProtocolProxy = RoomProtocolProxy;
211
- class RoomClient {
207
+ export class RoomClient {
212
208
  constructor({ protocolFactory = null, reconnectTimeout = null, oauthTokenRequestHandler, secretRequestHandler, } = {}) {
213
209
  this._entered = false;
214
210
  this._allowDisconnectedRequests = false;
215
- this._eventsController = new stream_controller_1.StreamController();
216
- this._eventEmitter = new event_emitter_1.EventEmitter();
211
+ this._eventsController = new StreamController();
212
+ this._eventEmitter = new EventEmitter();
217
213
  this._pendingRequests = new Map();
218
214
  this._toolCallStreams = new Map();
219
215
  this._ignoredResponseLabels = new Map();
220
- this._ready = new completer_1.Completer();
221
- this._roomClosed = new completer_1.Completer();
222
- this._connectionReady = new completer_1.Completer();
223
- this._localParticipantReady = new completer_1.Completer();
216
+ this._ready = new Completer();
217
+ this._roomClosed = new Completer();
218
+ this._connectionReady = new Completer();
219
+ this._localParticipantReady = new Completer();
224
220
  this._connected = false;
225
221
  this._closing = false;
226
222
  this._localParticipant = null;
@@ -249,21 +245,29 @@ class RoomClient {
249
245
  this.protocol.addHandler("connected", this._handleParticipantBound);
250
246
  this.protocol.addHandler("__response__", this._handleResponseBound);
251
247
  this.protocol.addHandler("room.tool_call_response_chunk", this._handleToolCallResponseChunkBound);
252
- this.sync = new sync_client_1.SyncClient({ room: this });
253
- this.storage = new storage_client_1.StorageClient({ room: this });
254
- this.developer = new developer_client_1.DeveloperClient({ room: this });
255
- this.messaging = new messaging_client_1.MessagingClient({ room: this });
256
- this.queues = new queues_client_1.QueuesClient({ room: this });
257
- this.datasets = new datasets_client_1.DatasetsClient({ room: this });
258
- this.agents = new agent_client_1.AgentsClient({ room: this });
259
- this.secrets = new secrets_client_1.SecretsClient({
248
+ this.sync = new SyncClient({ room: this });
249
+ this.storage = new StorageClient({ room: this });
250
+ this.developer = new DeveloperClient({ room: this });
251
+ this.messaging = new MessagingClient({ room: this });
252
+ this.queues = new QueuesClient({ room: this });
253
+ this.datasets = new DatasetsClient({ room: this });
254
+ this.agents = new AgentsClient({ room: this });
255
+ this.secrets = new SecretsClient({
260
256
  room: this,
261
257
  oauthTokenRequestHandler,
262
258
  secretRequestHandler,
263
259
  });
264
- this.containers = new containers_client_1.ContainersClient({ room: this });
265
- this.memory = new memory_client_1.MemoryClient({ room: this });
266
- this.services = new services_client_1.ServicesClient({ room: this });
260
+ this.containers = new ContainersClient({ room: this });
261
+ this.memory = new MemoryClient({ room: this });
262
+ this.services = new ServicesClient({ room: this });
263
+ }
264
+ static withIAP({ url = "./.well-known/meshagent/room/connect", reconnectTimeout = null, oauthTokenRequestHandler, secretRequestHandler, } = {}) {
265
+ return new RoomClient({
266
+ protocolFactory: () => WebSocketClientProtocol.withIAP({ url }),
267
+ reconnectTimeout,
268
+ oauthTokenRequestHandler,
269
+ secretRequestHandler,
270
+ });
267
271
  }
268
272
  get localParticipant() {
269
273
  return this._localParticipant;
@@ -440,7 +444,7 @@ class RoomClient {
440
444
  return `${baseMessage}: ${normalized}`;
441
445
  }
442
446
  _connectionFailureReason(error) {
443
- if (error instanceof room_server_client_1.RoomServerException) {
447
+ if (error instanceof RoomServerException) {
444
448
  return normalizeCloseReason(error.message);
445
449
  }
446
450
  return normalizeCloseReason(String(error));
@@ -488,12 +492,12 @@ class RoomClient {
488
492
  const normalizedCloseReason = normalizeCloseReason(closeReason);
489
493
  this._closeKind = closeKind;
490
494
  this._closeReason = normalizedCloseReason;
491
- if (closeKind === protocol_1.ProtocolCloseKind.ERROR) {
495
+ if (closeKind === ProtocolCloseKind.ERROR) {
492
496
  this._setTerminalState({
493
497
  state: this._unexpectedCloseTerminalState({ closeReason: normalizedCloseReason }),
494
498
  });
495
499
  }
496
- else if (closeKind === protocol_1.ProtocolCloseKind.CLIENT) {
500
+ else if (closeKind === ProtocolCloseKind.CLIENT) {
497
501
  this._setTerminalState({ state: this._clientClosedTerminalState() });
498
502
  }
499
503
  else {
@@ -525,22 +529,22 @@ class RoomClient {
525
529
  }
526
530
  }
527
531
  _disconnectedError({ baseMessage }) {
528
- return new room_server_client_1.RoomServerException(this._formatClosedMessage({
532
+ return new RoomServerException(this._formatClosedMessage({
529
533
  baseMessage,
530
534
  }));
531
535
  }
532
536
  _messageDisconnectedError({ baseMessage, }) {
533
- return new room_server_client_1.RoomServerException(this._formatClosedMessage({
537
+ return new RoomServerException(this._formatClosedMessage({
534
538
  baseMessage,
535
539
  }));
536
540
  }
537
541
  _startupException({ closeKind, closeReason, protocol, }) {
538
- const baseMessage = closeKind === protocol_1.ProtocolCloseKind.ERROR
542
+ const baseMessage = closeKind === ProtocolCloseKind.ERROR
539
543
  ? "room connection unexpectedly closed before the room became ready"
540
- : closeKind === protocol_1.ProtocolCloseKind.CLIENT
544
+ : closeKind === ProtocolCloseKind.CLIENT
541
545
  ? "room client was closed before the room became ready"
542
546
  : "room connection closed before the room became ready";
543
- return new room_server_client_1.RoomServerException(this._formatClosedMessage({
547
+ return new RoomServerException(this._formatClosedMessage({
544
548
  baseMessage,
545
549
  protocol,
546
550
  closeReason,
@@ -576,7 +580,7 @@ class RoomClient {
576
580
  if (this._closing && this._terminalState != null) {
577
581
  return this._terminalState.messageSendError();
578
582
  }
579
- return new room_server_client_1.RoomServerException("Cannot send messages because messaging has been stopped");
583
+ return new RoomServerException("Cannot send messages because messaging has been stopped");
580
584
  }
581
585
  _failPendingRequests(error) {
582
586
  if (this._pendingRequests.size === 0) {
@@ -597,7 +601,7 @@ class RoomClient {
597
601
  const streams = [...this._toolCallStreams.values()];
598
602
  this._toolCallStreams.clear();
599
603
  for (const stream of streams) {
600
- stream.add(new response_1.ErrorContent({ text: error.message }));
604
+ stream.add(new ErrorContent({ text: error.message }));
601
605
  stream.close();
602
606
  }
603
607
  }
@@ -607,8 +611,8 @@ class RoomClient {
607
611
  }
608
612
  async _openProtocol({ initial }) {
609
613
  const protocol = this._protocolInstance;
610
- this._connectionReady = new completer_1.Completer();
611
- this._localParticipantReady = new completer_1.Completer();
614
+ this._connectionReady = new Completer();
615
+ this._localParticipantReady = new Completer();
612
616
  protocol.start({
613
617
  onDone: () => {
614
618
  const error = roomClosedBeforeReadyError(protocol);
@@ -639,8 +643,8 @@ class RoomClient {
639
643
  await Promise.all([this._connectionReady.fut, this._localParticipantReady.fut]);
640
644
  }
641
645
  catch (error) {
642
- const kind = protocol.closeKind ?? protocol_1.ProtocolCloseKind.ERROR;
643
- if (!initial && kind !== protocol_1.ProtocolCloseKind.ERROR) {
646
+ const kind = protocol.closeKind ?? ProtocolCloseKind.ERROR;
647
+ if (!initial && kind !== ProtocolCloseKind.ERROR) {
644
648
  throw new ProtocolStartupFailure({
645
649
  kind,
646
650
  reason: normalizeCloseReason(protocol.closeReason),
@@ -651,7 +655,7 @@ class RoomClient {
651
655
  }
652
656
  async start({ onDone, onError, } = {}) {
653
657
  if (this._entered) {
654
- throw new room_server_client_1.RoomServerException("room client already started");
658
+ throw new RoomServerException("room client already started");
655
659
  }
656
660
  this._doneHandler = onDone;
657
661
  this._errorHandler = onError;
@@ -691,7 +695,7 @@ class RoomClient {
691
695
  this._finalizeInitialStartupRetryFailure({
692
696
  retryResult: {
693
697
  connected: false,
694
- closeKind: protocol_1.ProtocolCloseKind.ERROR,
698
+ closeKind: ProtocolCloseKind.ERROR,
695
699
  closeReason: nonRetryableCloseReason,
696
700
  },
697
701
  });
@@ -714,12 +718,12 @@ class RoomClient {
714
718
  const closeReason = this._connectionFailureReason(error);
715
719
  if (this._reconnectTimeout === 0) {
716
720
  this._setStartupTerminalState({
717
- closeKind: protocol_1.ProtocolCloseKind.ERROR,
721
+ closeKind: ProtocolCloseKind.ERROR,
718
722
  closeReason,
719
723
  protocol: this._protocolInstance,
720
724
  });
721
725
  throw this._startupException({
722
- closeKind: protocol_1.ProtocolCloseKind.ERROR,
726
+ closeKind: ProtocolCloseKind.ERROR,
723
727
  closeReason,
724
728
  protocol: this._protocolInstance,
725
729
  });
@@ -846,14 +850,14 @@ class RoomClient {
846
850
  }
847
851
  return {
848
852
  connected: false,
849
- closeKind: protocol_1.ProtocolCloseKind.ERROR,
853
+ closeKind: ProtocolCloseKind.ERROR,
850
854
  closeReason: this._reconnectTimeoutReason({ disconnectReason }),
851
855
  };
852
856
  }
853
857
  async _closeAfterUnexpectedDisconnect({ closeReason, }) {
854
858
  const normalized = normalizeCloseReason(closeReason);
855
859
  const state = this._unexpectedCloseTerminalState({ closeReason: normalized });
856
- this._closeKind = protocol_1.ProtocolCloseKind.ERROR;
860
+ this._closeKind = ProtocolCloseKind.ERROR;
857
861
  this._closeReason = normalized;
858
862
  this._setTerminalState({ state });
859
863
  this._completeRoomClosed();
@@ -908,10 +912,10 @@ class RoomClient {
908
912
  nextProtocol = this._protocolFactory();
909
913
  }
910
914
  catch (error) {
911
- if (error instanceof protocol_1.ProtocolReconnectUnsupportedException) {
915
+ if (error instanceof ProtocolReconnectUnsupportedException) {
912
916
  return {
913
917
  connected: false,
914
- closeKind: protocol_1.ProtocolCloseKind.ERROR,
918
+ closeKind: ProtocolCloseKind.ERROR,
915
919
  closeReason: failureReason,
916
920
  };
917
921
  }
@@ -946,7 +950,7 @@ class RoomClient {
946
950
  await this._closeProtocol(nextProtocol);
947
951
  return {
948
952
  connected: false,
949
- closeKind: protocol_1.ProtocolCloseKind.ERROR,
953
+ closeKind: ProtocolCloseKind.ERROR,
950
954
  closeReason: nonRetryableCloseReason,
951
955
  };
952
956
  }
@@ -959,7 +963,7 @@ class RoomClient {
959
963
  }
960
964
  return {
961
965
  connected: false,
962
- closeKind: protocol_1.ProtocolCloseKind.CLIENT,
966
+ closeKind: ProtocolCloseKind.CLIENT,
963
967
  closeReason: this.closeReason,
964
968
  };
965
969
  }
@@ -978,7 +982,7 @@ class RoomClient {
978
982
  return true;
979
983
  }
980
984
  const closeKind = retryResult.closeKind ?? null;
981
- if (closeKind === protocol_1.ProtocolCloseKind.ERROR) {
985
+ if (closeKind === ProtocolCloseKind.ERROR) {
982
986
  const closeReason = retryResult.closeReason ?? null;
983
987
  if (closeReason != null && closeReason.startsWith("room reconnect timed out after")) {
984
988
  console.warn(`${closeReason}; closing room client`);
@@ -1001,14 +1005,14 @@ class RoomClient {
1001
1005
  while (true) {
1002
1006
  const protocol = this._protocolInstance;
1003
1007
  await protocol.done;
1004
- const closeKind = protocol.closeKind ?? protocol_1.ProtocolCloseKind.ERROR;
1008
+ const closeKind = protocol.closeKind ?? ProtocolCloseKind.ERROR;
1005
1009
  const closeReason = normalizeCloseReason(protocol.closeReason);
1006
1010
  const state = this._protocolTerminalState({ protocol });
1007
1011
  if (this._closing) {
1008
1012
  this._completeRoomClosed();
1009
1013
  return;
1010
1014
  }
1011
- if (closeKind !== protocol_1.ProtocolCloseKind.ERROR) {
1015
+ if (closeKind !== ProtocolCloseKind.ERROR) {
1012
1016
  this._setTerminalState({ state });
1013
1017
  }
1014
1018
  this._markDisconnected({ reason: closeReason, kind: closeKind });
@@ -1020,7 +1024,7 @@ class RoomClient {
1020
1024
  this.messaging._onRoomDisconnect({ reason: closeReason });
1021
1025
  await this._failPendingWork({ state });
1022
1026
  await this._closeProtocol(protocol);
1023
- if (closeKind === protocol_1.ProtocolCloseKind.ERROR) {
1027
+ if (closeKind === ProtocolCloseKind.ERROR) {
1024
1028
  if (this._reconnectTimeout === 0) {
1025
1029
  if (closeReason == null) {
1026
1030
  console.warn("room connection lost; automatic reconnect disabled");
@@ -1053,7 +1057,7 @@ class RoomClient {
1053
1057
  this._closing = true;
1054
1058
  this._markDisconnected({
1055
1059
  reason: this.closeReason,
1056
- kind: this.closeKind ?? protocol_1.ProtocolCloseKind.CLIENT,
1060
+ kind: this.closeKind ?? ProtocolCloseKind.CLIENT,
1057
1061
  });
1058
1062
  const closingState = this._clientClosedTerminalState();
1059
1063
  this._setTerminalState({ state: closingState });
@@ -1063,7 +1067,7 @@ class RoomClient {
1063
1067
  void this.messaging.stop();
1064
1068
  this._protocolInstance.dispose();
1065
1069
  this._entered = false;
1066
- this._closeKind = protocol_1.ProtocolCloseKind.CLIENT;
1070
+ this._closeKind = ProtocolCloseKind.CLIENT;
1067
1071
  this._completeRoomClosed();
1068
1072
  this._invokeTerminalCallbacks({ useErrorCallback: false });
1069
1073
  this._localParticipant = null;
@@ -1103,14 +1107,14 @@ class RoomClient {
1103
1107
  _sendRoomRequestNowait(type, request, { data, label, expectResponse = false, }) {
1104
1108
  return this._sendProtocolNowait({
1105
1109
  type,
1106
- data: (0, utils_1.packMessage)(request, data),
1110
+ data: packMessage(request, data),
1107
1111
  label,
1108
1112
  expectResponse,
1109
1113
  });
1110
1114
  }
1111
1115
  invokeNowait({ toolkit, tool, input, participantId, onBehalfOfId, }) {
1112
- const resolvedInput = input ?? new response_1.EmptyContent();
1113
- const packedInput = (0, utils_1.unpackMessage)(resolvedInput.pack());
1116
+ const resolvedInput = input ?? new EmptyContent();
1117
+ const packedInput = unpackMessage(resolvedInput.pack());
1114
1118
  const request = {
1115
1119
  toolkit,
1116
1120
  tool,
@@ -1128,7 +1132,7 @@ class RoomClient {
1128
1132
  _sendLocalAttributesNowait(attributes) {
1129
1133
  this._sendProtocolNowait({
1130
1134
  type: "set_attributes",
1131
- data: (0, utils_1.packMessage)(attributes),
1135
+ data: packMessage(attributes),
1132
1136
  label: "local participant attribute update",
1133
1137
  });
1134
1138
  }
@@ -1149,10 +1153,10 @@ class RoomClient {
1149
1153
  throw this._disconnectedError({ baseMessage: "room connection is disconnected" });
1150
1154
  }
1151
1155
  const requestId = this._protocolInstance.getNextMessageId();
1152
- const completer = new completer_1.Completer();
1156
+ const completer = new Completer();
1153
1157
  this._pendingRequests.set(requestId, completer);
1154
1158
  try {
1155
- await this._protocolInstance.send(type, (0, utils_1.packMessage)(request, data), requestId);
1159
+ await this._protocolInstance.send(type, packMessage(request, data), requestId);
1156
1160
  return await completer.fut;
1157
1161
  }
1158
1162
  catch (error) {
@@ -1175,39 +1179,39 @@ class RoomClient {
1175
1179
  request["timeout"] = params.timeout;
1176
1180
  }
1177
1181
  const result = await this.sendRequest("room.list_toolkits", request);
1178
- if (!(result instanceof response_1.JsonContent)) {
1179
- throw new room_server_client_1.RoomServerException("unexpected return type from room.list_toolkits");
1182
+ if (!(result instanceof JsonContent)) {
1183
+ throw new RoomServerException("unexpected return type from room.list_toolkits");
1180
1184
  }
1181
1185
  const tools = result.json["tools"];
1182
1186
  if (typeof tools !== "object" || tools === null || Array.isArray(tools)) {
1183
- throw new room_server_client_1.RoomServerException("unexpected return type from room.list_toolkits");
1187
+ throw new RoomServerException("unexpected return type from room.list_toolkits");
1184
1188
  }
1185
1189
  const toolkits = [];
1186
1190
  for (const [name, data] of Object.entries(tools)) {
1187
1191
  if (typeof data !== "object" || data === null || Array.isArray(data)) {
1188
- throw new room_server_client_1.RoomServerException("unexpected toolkit description from room.list_toolkits");
1192
+ throw new RoomServerException("unexpected toolkit description from room.list_toolkits");
1189
1193
  }
1190
- toolkits.push(agent_client_1.ToolkitDescription.fromJson(data, { name }));
1194
+ toolkits.push(ToolkitDescription.fromJson(data, { name }));
1191
1195
  }
1192
1196
  return toolkits;
1193
1197
  }
1194
1198
  async invoke(params) {
1195
- const input = params.input ?? params.arguments ?? new response_1.EmptyContent();
1199
+ const input = params.input ?? params.arguments ?? new EmptyContent();
1196
1200
  const request = {
1197
1201
  toolkit: params.toolkit,
1198
1202
  tool: params.tool,
1199
1203
  };
1200
1204
  let requestData;
1201
- if (input instanceof response_1.BinaryContent ||
1202
- input instanceof response_1.EmptyContent ||
1203
- input instanceof response_1.ErrorContent ||
1204
- input instanceof response_1.FileContent ||
1205
- input instanceof response_1.JsonContent ||
1206
- input instanceof response_1.LinkContent ||
1207
- input instanceof response_1.TextContent) {
1205
+ if (input instanceof BinaryContent ||
1206
+ input instanceof EmptyContent ||
1207
+ input instanceof ErrorContent ||
1208
+ input instanceof FileContent ||
1209
+ input instanceof JsonContent ||
1210
+ input instanceof LinkContent ||
1211
+ input instanceof TextContent) {
1208
1212
  const packed = input.pack();
1209
- request["arguments"] = JSON.parse((0, utils_1.splitMessageHeader)(packed));
1210
- const payload = (0, utils_1.splitMessagePayload)(packed);
1213
+ request["arguments"] = JSON.parse(splitMessageHeader(packed));
1214
+ const payload = splitMessagePayload(packed);
1211
1215
  if (payload.length > 0) {
1212
1216
  requestData = payload;
1213
1217
  }
@@ -1219,7 +1223,7 @@ class RoomClient {
1219
1223
  };
1220
1224
  }
1221
1225
  else {
1222
- throw new room_server_client_1.RoomServerException("invoke input must be a content value or JSON object");
1226
+ throw new RoomServerException("invoke input must be a content value or JSON object");
1223
1227
  }
1224
1228
  if (params.participantId != null) {
1225
1229
  request["participant_id"] = params.participantId;
@@ -1231,7 +1235,7 @@ class RoomClient {
1231
1235
  }
1232
1236
  async invokeToolCall(params) {
1233
1237
  const toolCallId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
1234
- const controller = new stream_controller_1.StreamController();
1238
+ const controller = new StreamController();
1235
1239
  const responseIterator = controller.stream[Symbol.asyncIterator]();
1236
1240
  this._toolCallStreams.set(toolCallId, controller);
1237
1241
  const request = {
@@ -1248,8 +1252,8 @@ class RoomClient {
1248
1252
  else {
1249
1253
  const input = params.input;
1250
1254
  const packed = input.pack();
1251
- request["arguments"] = JSON.parse((0, utils_1.splitMessageHeader)(packed));
1252
- const payload = (0, utils_1.splitMessagePayload)(packed);
1255
+ request["arguments"] = JSON.parse(splitMessageHeader(packed));
1256
+ const payload = splitMessagePayload(packed);
1253
1257
  if (payload.length > 0) {
1254
1258
  requestData = payload;
1255
1259
  }
@@ -1262,14 +1266,14 @@ class RoomClient {
1262
1266
  }
1263
1267
  try {
1264
1268
  const response = await this.sendRequest("room.invoke_tool", request, requestData);
1265
- if (response instanceof response_1.ControlContent && response.method === "open") {
1269
+ if (response instanceof ControlContent && response.method === "open") {
1266
1270
  if (requestTask != null) {
1267
1271
  void requestTask.catch((error) => {
1268
1272
  const stream = this._toolCallStreams.get(toolCallId);
1269
1273
  if (stream == null) {
1270
1274
  return;
1271
1275
  }
1272
- stream.add(new response_1.ErrorContent({ text: `request stream failed: ${String(error)}` }));
1276
+ stream.add(new ErrorContent({ text: `request stream failed: ${String(error)}` }));
1273
1277
  stream.close();
1274
1278
  this._toolCallStreams.delete(toolCallId);
1275
1279
  });
@@ -1316,8 +1320,8 @@ class RoomClient {
1316
1320
  try {
1317
1321
  const response = await this.sendRequest("room.invoke_tool", request);
1318
1322
  await requestTask;
1319
- if (response instanceof response_1.ControlContent && response.method === "open") {
1320
- throw new room_server_client_1.RoomServerException(`unexpected return type from ${params.toolkit}.${params.tool}`);
1323
+ if (response instanceof ControlContent && response.method === "open") {
1324
+ throw new RoomServerException(`unexpected return type from ${params.toolkit}.${params.tool}`);
1321
1325
  }
1322
1326
  return response;
1323
1327
  }
@@ -1328,7 +1332,7 @@ class RoomClient {
1328
1332
  }
1329
1333
  async invokeStream(params) {
1330
1334
  const toolCallId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
1331
- const controller = new stream_controller_1.StreamController();
1335
+ const controller = new StreamController();
1332
1336
  const responseIterator = controller.stream[Symbol.asyncIterator]();
1333
1337
  this._toolCallStreams.set(toolCallId, controller);
1334
1338
  const request = {
@@ -1349,15 +1353,15 @@ class RoomClient {
1349
1353
  if (stream == null) {
1350
1354
  return;
1351
1355
  }
1352
- stream.add(new response_1.ErrorContent({ text: `request stream failed: ${String(error)}` }));
1356
+ stream.add(new ErrorContent({ text: `request stream failed: ${String(error)}` }));
1353
1357
  stream.close();
1354
1358
  this._toolCallStreams.delete(toolCallId);
1355
1359
  });
1356
1360
  const response = await this.sendRequest("room.invoke_tool", request);
1357
- if (!(response instanceof response_1.ControlContent) || response.method !== "open") {
1361
+ if (!(response instanceof ControlContent) || response.method !== "open") {
1358
1362
  this._toolCallStreams.delete(toolCallId);
1359
1363
  controller.close();
1360
- throw new room_server_client_1.RoomServerException(`unexpected return type from ${params.toolkit}.${params.tool}`);
1364
+ throw new RoomServerException(`unexpected return type from ${params.toolkit}.${params.tool}`);
1361
1365
  }
1362
1366
  return {
1363
1367
  [Symbol.asyncIterator]() {
@@ -1369,9 +1373,9 @@ class RoomClient {
1369
1373
  const packed = chunk.pack();
1370
1374
  const request = {
1371
1375
  tool_call_id: toolCallId,
1372
- chunk: JSON.parse((0, utils_1.splitMessageHeader)(packed)),
1376
+ chunk: JSON.parse(splitMessageHeader(packed)),
1373
1377
  };
1374
- const payload = (0, utils_1.splitMessagePayload)(packed);
1378
+ const payload = splitMessagePayload(packed);
1375
1379
  await this.sendRequest("room.tool_call_request_chunk", request, payload.length > 0 ? payload : undefined);
1376
1380
  }
1377
1381
  async _streamInvokeToolRequestChunks(toolCallId, input) {
@@ -1382,7 +1386,7 @@ class RoomClient {
1382
1386
  }
1383
1387
  }
1384
1388
  finally {
1385
- await this._sendToolCallRequestChunk(toolCallId, new response_1.ControlContent({ method: "close" }));
1389
+ await this._sendToolCallRequestChunk(toolCallId, new ControlContent({ method: "close" }));
1386
1390
  }
1387
1391
  }
1388
1392
  _decodeToolCallContent(params) {
@@ -1390,17 +1394,17 @@ class RoomClient {
1390
1394
  if (typeof chunk === "object" && chunk !== null && !Array.isArray(chunk)) {
1391
1395
  const chunkMap = chunk;
1392
1396
  if (typeof chunkMap["type"] === "string") {
1393
- return (0, response_1.unpackContent)((0, utils_1.packMessage)(chunkMap, params.payload.length > 0 ? params.payload : undefined));
1397
+ return unpackContent(packMessage(chunkMap, params.payload.length > 0 ? params.payload : undefined));
1394
1398
  }
1395
- return new response_1.JsonContent({ json: chunkMap });
1399
+ return new JsonContent({ json: chunkMap });
1396
1400
  }
1397
- return new response_1.JsonContent({ json: { chunk } });
1401
+ return new JsonContent({ json: { chunk } });
1398
1402
  }
1399
1403
  async _handleToolCallResponseChunk(protocol, _messageId, _type, data) {
1400
1404
  if (!this.isActiveProtocol(protocol)) {
1401
1405
  return;
1402
1406
  }
1403
- const [header, payload] = (0, utils_1.unpackMessage)(data);
1407
+ const [header, payload] = unpackMessage(data);
1404
1408
  const toolCallId = header["tool_call_id"];
1405
1409
  if (typeof toolCallId !== "string" || toolCallId.length === 0) {
1406
1410
  return;
@@ -1411,7 +1415,7 @@ class RoomClient {
1411
1415
  }
1412
1416
  const content = this._decodeToolCallContent({ header, payload });
1413
1417
  stream.add(content);
1414
- if (content instanceof response_1.ControlContent && content.method === "close") {
1418
+ if (content instanceof ControlContent && content.method === "close") {
1415
1419
  stream.close();
1416
1420
  this._toolCallStreams.delete(toolCallId);
1417
1421
  }
@@ -1420,12 +1424,12 @@ class RoomClient {
1420
1424
  if (!this.isActiveProtocol(protocol)) {
1421
1425
  return;
1422
1426
  }
1423
- const response = (0, response_1.unpackContent)(data);
1427
+ const response = unpackContent(data);
1424
1428
  const pending = this._pendingRequests.get(messageId);
1425
1429
  if (pending != null) {
1426
1430
  this._pendingRequests.delete(messageId);
1427
- if (response instanceof response_1.ErrorContent) {
1428
- pending.completeError(new room_server_client_1.RoomServerException(response.text, response.code));
1431
+ if (response instanceof ErrorContent) {
1432
+ pending.completeError(new RoomServerException(response.text, response.code));
1429
1433
  }
1430
1434
  else {
1431
1435
  pending.complete(response);
@@ -1435,7 +1439,7 @@ class RoomClient {
1435
1439
  const ignoredLabel = this._ignoredResponseLabels.get(messageId);
1436
1440
  if (ignoredLabel != null) {
1437
1441
  this._ignoredResponseLabels.delete(messageId);
1438
- if (response instanceof response_1.ErrorContent) {
1442
+ if (response instanceof ErrorContent) {
1439
1443
  console.warn(`one-way room request failed for ${ignoredLabel}: ${response.text}`);
1440
1444
  }
1441
1445
  }
@@ -1444,14 +1448,14 @@ class RoomClient {
1444
1448
  if (!this.isActiveProtocol(protocol)) {
1445
1449
  return;
1446
1450
  }
1447
- const [payload] = (0, utils_1.unpackMessage)(data);
1448
- this.emit(room_event_1.RoomStatusEvent.fromJson(payload));
1451
+ const [payload] = unpackMessage(data);
1452
+ this.emit(RoomStatusEvent.fromJson(payload));
1449
1453
  }
1450
1454
  async _handleRoomReady(protocol, _messageId, _type, data) {
1451
1455
  if (!this.isActiveProtocol(protocol)) {
1452
1456
  return;
1453
1457
  }
1454
- const [message] = (0, utils_1.unpackMessage)(data);
1458
+ const [message] = unpackMessage(data);
1455
1459
  this._roomName = typeof message["room_name"] === "string" ? message["room_name"] : null;
1456
1460
  this._roomUrl = typeof message["room_url"] === "string" ? message["room_url"] : null;
1457
1461
  this._sessionId = typeof message["session_id"] === "string" ? message["session_id"] : null;
@@ -1464,7 +1468,7 @@ class RoomClient {
1464
1468
  }
1465
1469
  _onParticipantInit(participantId, attributes) {
1466
1470
  if (this._localParticipant == null) {
1467
- this._localParticipant = new participant_1.LocalParticipant(this, participantId);
1471
+ this._localParticipant = new LocalParticipant(this, participantId);
1468
1472
  this._localParticipant._setAttributes(attributes);
1469
1473
  }
1470
1474
  else {
@@ -1482,7 +1486,7 @@ class RoomClient {
1482
1486
  if (!this.isActiveProtocol(protocol)) {
1483
1487
  return;
1484
1488
  }
1485
- const [message] = (0, utils_1.unpackMessage)(data);
1489
+ const [message] = unpackMessage(data);
1486
1490
  switch (message["type"]) {
1487
1491
  case "init": {
1488
1492
  const participantId = message["participantId"];
@@ -1500,9 +1504,8 @@ class RoomClient {
1500
1504
  }
1501
1505
  }
1502
1506
  _emitStatus({ status, message, }) {
1503
- this.emit(new room_event_1.RoomStatusEvent({ status, message }));
1507
+ this.emit(new RoomStatusEvent({ status, message }));
1504
1508
  }
1505
1509
  }
1506
- exports.RoomClient = RoomClient;
1507
1510
  RoomClient.RECONNECT_RETRY_BASE_DELAY_MS = 500;
1508
1511
  RoomClient.RECONNECT_RETRY_MAX_DELAY_MS = 30000;