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