@meshagent/meshagent 0.39.3 → 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.
- package/CHANGELOG.md +7 -0
- package/README.md +134 -21
- package/dist/browser/entrypoint.d.ts +1426 -1464
- package/dist/browser/meshagent-client.js +7 -2
- package/dist/browser/package.json +1 -0
- package/dist/esm/agent-client.js +18 -12
- package/dist/esm/agent.js +26 -18
- package/dist/esm/api_keys.js +21 -11
- package/dist/esm/client.js +13 -7
- package/dist/esm/completer.js +5 -1
- package/dist/esm/containers-client.js +85 -80
- package/dist/esm/datasets-client.js +105 -95
- package/dist/esm/developer-client.js +15 -11
- package/dist/esm/document.js +20 -11
- package/dist/esm/entrypoint.d.ts +1426 -1464
- package/dist/esm/entrypoint.js +12 -1
- package/dist/esm/event-emitter.js +5 -1
- package/dist/esm/helpers.js +23 -15
- package/dist/esm/index.js +49 -33
- package/dist/esm/lk-client.js +12 -7
- package/dist/esm/lk-protocol.js +8 -4
- package/dist/esm/memory-client.js +11 -7
- package/dist/esm/meshagent-client.js +88 -79
- package/dist/esm/messaging-client.js +37 -33
- package/dist/esm/package.json +1 -0
- package/dist/esm/participant-token.js +62 -34
- package/dist/esm/participant.js +9 -3
- package/dist/esm/protocol.js +43 -29
- package/dist/esm/queues-client.js +17 -12
- package/dist/esm/requirement.js +11 -4
- package/dist/esm/response.js +34 -22
- package/dist/esm/room-client.js +134 -129
- package/dist/esm/room-event.js +21 -9
- package/dist/esm/room-server-client.js +18 -13
- package/dist/esm/runtime.js +10 -1
- package/dist/esm/schema.js +18 -9
- package/dist/esm/secrets-client.js +35 -31
- package/dist/esm/services-client.js +13 -9
- package/dist/esm/storage-client.js +38 -32
- package/dist/esm/stream-controller.js +5 -1
- package/dist/esm/sync-client.js +42 -38
- package/dist/esm/tool-content-type.js +5 -1
- package/dist/esm/utils.js +20 -10
- package/dist/esm/version.js +4 -1
- package/dist/node/entrypoint.d.ts +1426 -1464
- package/dist/node/meshagent-client.js +7 -2
- package/dist/node/package.json +1 -0
- package/package.json +1 -1
package/dist/esm/room-client.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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");
|
|
21
24
|
class ProtocolStartupFailure extends Error {
|
|
22
25
|
constructor({ kind, reason }) {
|
|
23
26
|
super(reason ?? kind);
|
|
@@ -33,16 +36,16 @@ class RoomClientTerminalState {
|
|
|
33
36
|
this.messageSendMessage = messageSendMessage;
|
|
34
37
|
}
|
|
35
38
|
requestError() {
|
|
36
|
-
return new RoomServerException(this.requestMessage);
|
|
39
|
+
return new room_server_client_1.RoomServerException(this.requestMessage);
|
|
37
40
|
}
|
|
38
41
|
toolCallError() {
|
|
39
|
-
return new RoomServerException(this.toolCallMessage);
|
|
42
|
+
return new room_server_client_1.RoomServerException(this.toolCallMessage);
|
|
40
43
|
}
|
|
41
44
|
messageSendError() {
|
|
42
|
-
return new RoomServerException(this.messageSendMessage);
|
|
45
|
+
return new room_server_client_1.RoomServerException(this.messageSendMessage);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
|
-
class RoomConnectionStatusException extends RoomServerException {
|
|
48
|
+
class RoomConnectionStatusException extends room_server_client_1.RoomServerException {
|
|
46
49
|
constructor({ statusCode, statusText, }) {
|
|
47
50
|
const normalizedStatusText = statusText?.trim();
|
|
48
51
|
super(normalizedStatusText == null || normalizedStatusText.length === 0
|
|
@@ -60,19 +63,19 @@ function normalizeCloseReason(reason) {
|
|
|
60
63
|
return normalized.length === 0 ? null : normalized;
|
|
61
64
|
}
|
|
62
65
|
function wrapRoomConnectionError(error) {
|
|
63
|
-
if (error instanceof RoomServerException) {
|
|
66
|
+
if (error instanceof room_server_client_1.RoomServerException) {
|
|
64
67
|
return error;
|
|
65
68
|
}
|
|
66
|
-
if (error instanceof ProtocolHandshakeException) {
|
|
69
|
+
if (error instanceof protocol_1.ProtocolHandshakeException) {
|
|
67
70
|
return new RoomConnectionStatusException({
|
|
68
71
|
statusCode: error.statusCode,
|
|
69
72
|
statusText: error.statusText,
|
|
70
73
|
});
|
|
71
74
|
}
|
|
72
|
-
if (error instanceof ProtocolCloseException) {
|
|
73
|
-
return new RoomServerException(normalizeCloseReason(error.reason) ?? `room connection closed with status ${error.closeCode}`);
|
|
75
|
+
if (error instanceof protocol_1.ProtocolCloseException) {
|
|
76
|
+
return new room_server_client_1.RoomServerException(normalizeCloseReason(error.reason) ?? `room connection closed with status ${error.closeCode}`);
|
|
74
77
|
}
|
|
75
|
-
return new RoomServerException(`room connection error: ${String(error)}`);
|
|
78
|
+
return new room_server_client_1.RoomServerException(`room connection error: ${String(error)}`);
|
|
76
79
|
}
|
|
77
80
|
function nonRetryableConnectFailureReason(error) {
|
|
78
81
|
if (error instanceof RoomConnectionStatusException
|
|
@@ -82,7 +85,7 @@ function nonRetryableConnectFailureReason(error) {
|
|
|
82
85
|
return null;
|
|
83
86
|
}
|
|
84
87
|
function roomClosedBeforeReadyError(protocol) {
|
|
85
|
-
return new RoomServerException(normalizeCloseReason(protocol.closeReason) ?? "room connection closed before request completed");
|
|
88
|
+
return new room_server_client_1.RoomServerException(normalizeCloseReason(protocol.closeReason) ?? "room connection closed before request completed");
|
|
86
89
|
}
|
|
87
90
|
function getEnvironmentValue(name) {
|
|
88
91
|
if (typeof process === "undefined") {
|
|
@@ -109,12 +112,12 @@ function createProtocolFactoryFromEnvironment() {
|
|
|
109
112
|
if (roomName == null || roomName.trim().length === 0 || token == null || token.trim().length === 0) {
|
|
110
113
|
throw new Error("protocolFactory must be configured or MESHAGENT_ROOM and MESHAGENT_TOKEN must be set in the environment");
|
|
111
114
|
}
|
|
112
|
-
return WebSocketClientProtocol.createFactory({
|
|
115
|
+
return protocol_1.WebSocketClientProtocol.createFactory({
|
|
113
116
|
url: websocketRoomUrlFromEnvironment(roomName),
|
|
114
117
|
token,
|
|
115
118
|
});
|
|
116
119
|
}
|
|
117
|
-
|
|
120
|
+
class RoomProtocolProxy {
|
|
118
121
|
constructor({ room }) {
|
|
119
122
|
this._handlers = new Map();
|
|
120
123
|
this._room = room;
|
|
@@ -198,19 +201,20 @@ export class RoomProtocolProxy {
|
|
|
198
201
|
return this._room._protocolInstance.url;
|
|
199
202
|
}
|
|
200
203
|
}
|
|
201
|
-
|
|
204
|
+
exports.RoomProtocolProxy = RoomProtocolProxy;
|
|
205
|
+
class RoomClient {
|
|
202
206
|
constructor({ protocolFactory = null, reconnectTimeout = null, oauthTokenRequestHandler, secretRequestHandler, } = {}) {
|
|
203
207
|
this._entered = false;
|
|
204
208
|
this._allowDisconnectedRequests = false;
|
|
205
|
-
this._eventsController = new StreamController();
|
|
206
|
-
this._eventEmitter = new EventEmitter();
|
|
209
|
+
this._eventsController = new stream_controller_1.StreamController();
|
|
210
|
+
this._eventEmitter = new event_emitter_1.EventEmitter();
|
|
207
211
|
this._pendingRequests = new Map();
|
|
208
212
|
this._toolCallStreams = new Map();
|
|
209
213
|
this._ignoredResponseLabels = new Map();
|
|
210
|
-
this._ready = new Completer();
|
|
211
|
-
this._roomClosed = new Completer();
|
|
212
|
-
this._connectionReady = new Completer();
|
|
213
|
-
this._localParticipantReady = new Completer();
|
|
214
|
+
this._ready = new completer_1.Completer();
|
|
215
|
+
this._roomClosed = new completer_1.Completer();
|
|
216
|
+
this._connectionReady = new completer_1.Completer();
|
|
217
|
+
this._localParticipantReady = new completer_1.Completer();
|
|
214
218
|
this._connected = false;
|
|
215
219
|
this._closing = false;
|
|
216
220
|
this._localParticipant = null;
|
|
@@ -239,21 +243,21 @@ export class RoomClient {
|
|
|
239
243
|
this.protocol.addHandler("connected", this._handleParticipantBound);
|
|
240
244
|
this.protocol.addHandler("__response__", this._handleResponseBound);
|
|
241
245
|
this.protocol.addHandler("room.tool_call_response_chunk", this._handleToolCallResponseChunkBound);
|
|
242
|
-
this.sync = new SyncClient({ room: this });
|
|
243
|
-
this.storage = new StorageClient({ room: this });
|
|
244
|
-
this.developer = new DeveloperClient({ room: this });
|
|
245
|
-
this.messaging = new MessagingClient({ room: this });
|
|
246
|
-
this.queues = new QueuesClient({ room: this });
|
|
247
|
-
this.datasets = new DatasetsClient({ room: this });
|
|
248
|
-
this.agents = new AgentsClient({ room: this });
|
|
249
|
-
this.secrets = new SecretsClient({
|
|
246
|
+
this.sync = new sync_client_1.SyncClient({ room: this });
|
|
247
|
+
this.storage = new storage_client_1.StorageClient({ room: this });
|
|
248
|
+
this.developer = new developer_client_1.DeveloperClient({ room: this });
|
|
249
|
+
this.messaging = new messaging_client_1.MessagingClient({ room: this });
|
|
250
|
+
this.queues = new queues_client_1.QueuesClient({ room: this });
|
|
251
|
+
this.datasets = new datasets_client_1.DatasetsClient({ room: this });
|
|
252
|
+
this.agents = new agent_client_1.AgentsClient({ room: this });
|
|
253
|
+
this.secrets = new secrets_client_1.SecretsClient({
|
|
250
254
|
room: this,
|
|
251
255
|
oauthTokenRequestHandler,
|
|
252
256
|
secretRequestHandler,
|
|
253
257
|
});
|
|
254
|
-
this.containers = new ContainersClient({ room: this });
|
|
255
|
-
this.memory = new MemoryClient({ room: this });
|
|
256
|
-
this.services = new ServicesClient({ room: this });
|
|
258
|
+
this.containers = new containers_client_1.ContainersClient({ room: this });
|
|
259
|
+
this.memory = new memory_client_1.MemoryClient({ room: this });
|
|
260
|
+
this.services = new services_client_1.ServicesClient({ room: this });
|
|
257
261
|
}
|
|
258
262
|
get localParticipant() {
|
|
259
263
|
return this._localParticipant;
|
|
@@ -430,7 +434,7 @@ export class RoomClient {
|
|
|
430
434
|
return `${baseMessage}: ${normalized}`;
|
|
431
435
|
}
|
|
432
436
|
_connectionFailureReason(error) {
|
|
433
|
-
if (error instanceof RoomServerException) {
|
|
437
|
+
if (error instanceof room_server_client_1.RoomServerException) {
|
|
434
438
|
return normalizeCloseReason(error.message);
|
|
435
439
|
}
|
|
436
440
|
return normalizeCloseReason(String(error));
|
|
@@ -478,12 +482,12 @@ export class RoomClient {
|
|
|
478
482
|
const normalizedCloseReason = normalizeCloseReason(closeReason);
|
|
479
483
|
this._closeKind = closeKind;
|
|
480
484
|
this._closeReason = normalizedCloseReason;
|
|
481
|
-
if (closeKind === ProtocolCloseKind.ERROR) {
|
|
485
|
+
if (closeKind === protocol_1.ProtocolCloseKind.ERROR) {
|
|
482
486
|
this._setTerminalState({
|
|
483
487
|
state: this._unexpectedCloseTerminalState({ closeReason: normalizedCloseReason }),
|
|
484
488
|
});
|
|
485
489
|
}
|
|
486
|
-
else if (closeKind === ProtocolCloseKind.CLIENT) {
|
|
490
|
+
else if (closeKind === protocol_1.ProtocolCloseKind.CLIENT) {
|
|
487
491
|
this._setTerminalState({ state: this._clientClosedTerminalState() });
|
|
488
492
|
}
|
|
489
493
|
else {
|
|
@@ -515,22 +519,22 @@ export class RoomClient {
|
|
|
515
519
|
}
|
|
516
520
|
}
|
|
517
521
|
_disconnectedError({ baseMessage }) {
|
|
518
|
-
return new RoomServerException(this._formatClosedMessage({
|
|
522
|
+
return new room_server_client_1.RoomServerException(this._formatClosedMessage({
|
|
519
523
|
baseMessage,
|
|
520
524
|
}));
|
|
521
525
|
}
|
|
522
526
|
_messageDisconnectedError({ baseMessage, }) {
|
|
523
|
-
return new RoomServerException(this._formatClosedMessage({
|
|
527
|
+
return new room_server_client_1.RoomServerException(this._formatClosedMessage({
|
|
524
528
|
baseMessage,
|
|
525
529
|
}));
|
|
526
530
|
}
|
|
527
531
|
_startupException({ closeKind, closeReason, protocol, }) {
|
|
528
|
-
const baseMessage = closeKind === ProtocolCloseKind.ERROR
|
|
532
|
+
const baseMessage = closeKind === protocol_1.ProtocolCloseKind.ERROR
|
|
529
533
|
? "room connection unexpectedly closed before the room became ready"
|
|
530
|
-
: closeKind === ProtocolCloseKind.CLIENT
|
|
534
|
+
: closeKind === protocol_1.ProtocolCloseKind.CLIENT
|
|
531
535
|
? "room client was closed before the room became ready"
|
|
532
536
|
: "room connection closed before the room became ready";
|
|
533
|
-
return new RoomServerException(this._formatClosedMessage({
|
|
537
|
+
return new room_server_client_1.RoomServerException(this._formatClosedMessage({
|
|
534
538
|
baseMessage,
|
|
535
539
|
protocol,
|
|
536
540
|
closeReason,
|
|
@@ -566,7 +570,7 @@ export class RoomClient {
|
|
|
566
570
|
if (this._closing && this._terminalState != null) {
|
|
567
571
|
return this._terminalState.messageSendError();
|
|
568
572
|
}
|
|
569
|
-
return new RoomServerException("Cannot send messages because messaging has been stopped");
|
|
573
|
+
return new room_server_client_1.RoomServerException("Cannot send messages because messaging has been stopped");
|
|
570
574
|
}
|
|
571
575
|
_failPendingRequests(error) {
|
|
572
576
|
if (this._pendingRequests.size === 0) {
|
|
@@ -587,7 +591,7 @@ export class RoomClient {
|
|
|
587
591
|
const streams = [...this._toolCallStreams.values()];
|
|
588
592
|
this._toolCallStreams.clear();
|
|
589
593
|
for (const stream of streams) {
|
|
590
|
-
stream.add(new ErrorContent({ text: error.message }));
|
|
594
|
+
stream.add(new response_1.ErrorContent({ text: error.message }));
|
|
591
595
|
stream.close();
|
|
592
596
|
}
|
|
593
597
|
}
|
|
@@ -597,8 +601,8 @@ export class RoomClient {
|
|
|
597
601
|
}
|
|
598
602
|
async _openProtocol({ initial }) {
|
|
599
603
|
const protocol = this._protocolInstance;
|
|
600
|
-
this._connectionReady = new Completer();
|
|
601
|
-
this._localParticipantReady = new Completer();
|
|
604
|
+
this._connectionReady = new completer_1.Completer();
|
|
605
|
+
this._localParticipantReady = new completer_1.Completer();
|
|
602
606
|
protocol.start({
|
|
603
607
|
onDone: () => {
|
|
604
608
|
const error = roomClosedBeforeReadyError(protocol);
|
|
@@ -629,8 +633,8 @@ export class RoomClient {
|
|
|
629
633
|
await Promise.all([this._connectionReady.fut, this._localParticipantReady.fut]);
|
|
630
634
|
}
|
|
631
635
|
catch (error) {
|
|
632
|
-
const kind = protocol.closeKind ?? ProtocolCloseKind.ERROR;
|
|
633
|
-
if (!initial && kind !== ProtocolCloseKind.ERROR) {
|
|
636
|
+
const kind = protocol.closeKind ?? protocol_1.ProtocolCloseKind.ERROR;
|
|
637
|
+
if (!initial && kind !== protocol_1.ProtocolCloseKind.ERROR) {
|
|
634
638
|
throw new ProtocolStartupFailure({
|
|
635
639
|
kind,
|
|
636
640
|
reason: normalizeCloseReason(protocol.closeReason),
|
|
@@ -641,7 +645,7 @@ export class RoomClient {
|
|
|
641
645
|
}
|
|
642
646
|
async start({ onDone, onError, } = {}) {
|
|
643
647
|
if (this._entered) {
|
|
644
|
-
throw new RoomServerException("room client already started");
|
|
648
|
+
throw new room_server_client_1.RoomServerException("room client already started");
|
|
645
649
|
}
|
|
646
650
|
this._doneHandler = onDone;
|
|
647
651
|
this._errorHandler = onError;
|
|
@@ -651,7 +655,7 @@ export class RoomClient {
|
|
|
651
655
|
}
|
|
652
656
|
catch (error) {
|
|
653
657
|
if (error instanceof ProtocolStartupFailure) {
|
|
654
|
-
if (error.kind !== ProtocolCloseKind.ERROR || this._reconnectTimeout === 0) {
|
|
658
|
+
if (error.kind !== protocol_1.ProtocolCloseKind.ERROR || this._reconnectTimeout === 0) {
|
|
655
659
|
this._setStartupTerminalState({
|
|
656
660
|
closeKind: error.kind,
|
|
657
661
|
closeReason: error.reason,
|
|
@@ -680,14 +684,14 @@ export class RoomClient {
|
|
|
680
684
|
this._finalizeInitialStartupRetryFailure({
|
|
681
685
|
retryResult: {
|
|
682
686
|
connected: false,
|
|
683
|
-
closeKind: ProtocolCloseKind.ERROR,
|
|
687
|
+
closeKind: protocol_1.ProtocolCloseKind.ERROR,
|
|
684
688
|
closeReason: nonRetryableCloseReason,
|
|
685
689
|
},
|
|
686
690
|
});
|
|
687
691
|
}
|
|
688
692
|
const closeKind = this._protocolInstance.closeKind;
|
|
689
693
|
const protocolCloseReason = normalizeCloseReason(this._protocolInstance.closeReason);
|
|
690
|
-
if (closeKind != null && closeKind !== ProtocolCloseKind.ERROR) {
|
|
694
|
+
if (closeKind != null && closeKind !== protocol_1.ProtocolCloseKind.ERROR) {
|
|
691
695
|
this._setStartupTerminalState({
|
|
692
696
|
closeKind,
|
|
693
697
|
closeReason: protocolCloseReason,
|
|
@@ -702,12 +706,12 @@ export class RoomClient {
|
|
|
702
706
|
const closeReason = this._connectionFailureReason(error);
|
|
703
707
|
if (this._reconnectTimeout === 0) {
|
|
704
708
|
this._setStartupTerminalState({
|
|
705
|
-
closeKind: ProtocolCloseKind.ERROR,
|
|
709
|
+
closeKind: protocol_1.ProtocolCloseKind.ERROR,
|
|
706
710
|
closeReason,
|
|
707
711
|
protocol: this._protocolInstance,
|
|
708
712
|
});
|
|
709
713
|
throw this._startupException({
|
|
710
|
-
closeKind: ProtocolCloseKind.ERROR,
|
|
714
|
+
closeKind: protocol_1.ProtocolCloseKind.ERROR,
|
|
711
715
|
closeReason,
|
|
712
716
|
protocol: this._protocolInstance,
|
|
713
717
|
});
|
|
@@ -831,14 +835,14 @@ export class RoomClient {
|
|
|
831
835
|
}
|
|
832
836
|
return {
|
|
833
837
|
connected: false,
|
|
834
|
-
closeKind: ProtocolCloseKind.ERROR,
|
|
838
|
+
closeKind: protocol_1.ProtocolCloseKind.ERROR,
|
|
835
839
|
closeReason: this._reconnectTimeoutReason({ disconnectReason }),
|
|
836
840
|
};
|
|
837
841
|
}
|
|
838
842
|
async _closeAfterUnexpectedDisconnect({ closeReason, }) {
|
|
839
843
|
const normalized = normalizeCloseReason(closeReason);
|
|
840
844
|
const state = this._unexpectedCloseTerminalState({ closeReason: normalized });
|
|
841
|
-
this._closeKind = ProtocolCloseKind.ERROR;
|
|
845
|
+
this._closeKind = protocol_1.ProtocolCloseKind.ERROR;
|
|
842
846
|
this._closeReason = normalized;
|
|
843
847
|
this._setTerminalState({ state });
|
|
844
848
|
this._completeRoomClosed();
|
|
@@ -889,10 +893,10 @@ export class RoomClient {
|
|
|
889
893
|
nextProtocol = this._protocolFactory();
|
|
890
894
|
}
|
|
891
895
|
catch (error) {
|
|
892
|
-
if (error instanceof ProtocolReconnectUnsupportedException) {
|
|
896
|
+
if (error instanceof protocol_1.ProtocolReconnectUnsupportedException) {
|
|
893
897
|
return {
|
|
894
898
|
connected: false,
|
|
895
|
-
closeKind: ProtocolCloseKind.ERROR,
|
|
899
|
+
closeKind: protocol_1.ProtocolCloseKind.ERROR,
|
|
896
900
|
closeReason: failureReason,
|
|
897
901
|
};
|
|
898
902
|
}
|
|
@@ -913,7 +917,7 @@ export class RoomClient {
|
|
|
913
917
|
if (error instanceof ProtocolStartupFailure) {
|
|
914
918
|
recordFailureReason(error.reason);
|
|
915
919
|
await this._closeProtocol(nextProtocol);
|
|
916
|
-
if (error.kind !== ProtocolCloseKind.ERROR) {
|
|
920
|
+
if (error.kind !== protocol_1.ProtocolCloseKind.ERROR) {
|
|
917
921
|
return {
|
|
918
922
|
connected: false,
|
|
919
923
|
closeKind: error.kind,
|
|
@@ -927,7 +931,7 @@ export class RoomClient {
|
|
|
927
931
|
await this._closeProtocol(nextProtocol);
|
|
928
932
|
return {
|
|
929
933
|
connected: false,
|
|
930
|
-
closeKind: ProtocolCloseKind.ERROR,
|
|
934
|
+
closeKind: protocol_1.ProtocolCloseKind.ERROR,
|
|
931
935
|
closeReason: nonRetryableCloseReason,
|
|
932
936
|
};
|
|
933
937
|
}
|
|
@@ -940,7 +944,7 @@ export class RoomClient {
|
|
|
940
944
|
}
|
|
941
945
|
return {
|
|
942
946
|
connected: false,
|
|
943
|
-
closeKind: ProtocolCloseKind.CLIENT,
|
|
947
|
+
closeKind: protocol_1.ProtocolCloseKind.CLIENT,
|
|
944
948
|
closeReason: this.closeReason,
|
|
945
949
|
};
|
|
946
950
|
}
|
|
@@ -959,7 +963,7 @@ export class RoomClient {
|
|
|
959
963
|
return true;
|
|
960
964
|
}
|
|
961
965
|
const closeKind = retryResult.closeKind ?? null;
|
|
962
|
-
if (closeKind === ProtocolCloseKind.ERROR) {
|
|
966
|
+
if (closeKind === protocol_1.ProtocolCloseKind.ERROR) {
|
|
963
967
|
const closeReason = retryResult.closeReason ?? null;
|
|
964
968
|
if (closeReason != null && closeReason.startsWith("room reconnect timed out after")) {
|
|
965
969
|
console.warn(`${closeReason}; closing room client`);
|
|
@@ -982,14 +986,14 @@ export class RoomClient {
|
|
|
982
986
|
while (true) {
|
|
983
987
|
const protocol = this._protocolInstance;
|
|
984
988
|
await protocol.done;
|
|
985
|
-
const closeKind = protocol.closeKind ?? ProtocolCloseKind.ERROR;
|
|
989
|
+
const closeKind = protocol.closeKind ?? protocol_1.ProtocolCloseKind.ERROR;
|
|
986
990
|
const closeReason = normalizeCloseReason(protocol.closeReason);
|
|
987
991
|
const state = this._protocolTerminalState({ protocol });
|
|
988
992
|
if (this._closing) {
|
|
989
993
|
this._completeRoomClosed();
|
|
990
994
|
return;
|
|
991
995
|
}
|
|
992
|
-
if (closeKind !== ProtocolCloseKind.ERROR) {
|
|
996
|
+
if (closeKind !== protocol_1.ProtocolCloseKind.ERROR) {
|
|
993
997
|
this._setTerminalState({ state });
|
|
994
998
|
}
|
|
995
999
|
this._markDisconnected({ reason: closeReason, kind: closeKind });
|
|
@@ -1001,7 +1005,7 @@ export class RoomClient {
|
|
|
1001
1005
|
this.messaging._onRoomDisconnect({ reason: closeReason });
|
|
1002
1006
|
await this._failPendingWork({ state });
|
|
1003
1007
|
await this._closeProtocol(protocol);
|
|
1004
|
-
if (closeKind === ProtocolCloseKind.ERROR) {
|
|
1008
|
+
if (closeKind === protocol_1.ProtocolCloseKind.ERROR) {
|
|
1005
1009
|
if (this._reconnectTimeout === 0) {
|
|
1006
1010
|
if (closeReason == null) {
|
|
1007
1011
|
console.warn("room connection lost; automatic reconnect disabled");
|
|
@@ -1034,7 +1038,7 @@ export class RoomClient {
|
|
|
1034
1038
|
this._closing = true;
|
|
1035
1039
|
this._markDisconnected({
|
|
1036
1040
|
reason: this.closeReason,
|
|
1037
|
-
kind: this.closeKind ?? ProtocolCloseKind.CLIENT,
|
|
1041
|
+
kind: this.closeKind ?? protocol_1.ProtocolCloseKind.CLIENT,
|
|
1038
1042
|
});
|
|
1039
1043
|
const closingState = this._clientClosedTerminalState();
|
|
1040
1044
|
this._setTerminalState({ state: closingState });
|
|
@@ -1044,7 +1048,7 @@ export class RoomClient {
|
|
|
1044
1048
|
void this.messaging.stop();
|
|
1045
1049
|
this._protocolInstance.dispose();
|
|
1046
1050
|
this._entered = false;
|
|
1047
|
-
this._closeKind = ProtocolCloseKind.CLIENT;
|
|
1051
|
+
this._closeKind = protocol_1.ProtocolCloseKind.CLIENT;
|
|
1048
1052
|
this._completeRoomClosed();
|
|
1049
1053
|
this._invokeTerminalCallbacks({ useErrorCallback: false });
|
|
1050
1054
|
this._localParticipant = null;
|
|
@@ -1084,14 +1088,14 @@ export class RoomClient {
|
|
|
1084
1088
|
_sendRoomRequestNowait(type, request, { data, label, expectResponse = false, }) {
|
|
1085
1089
|
return this._sendProtocolNowait({
|
|
1086
1090
|
type,
|
|
1087
|
-
data: packMessage(request, data),
|
|
1091
|
+
data: (0, utils_1.packMessage)(request, data),
|
|
1088
1092
|
label,
|
|
1089
1093
|
expectResponse,
|
|
1090
1094
|
});
|
|
1091
1095
|
}
|
|
1092
1096
|
invokeNowait({ toolkit, tool, input, participantId, onBehalfOfId, callerContext, }) {
|
|
1093
|
-
const resolvedInput = input ?? new EmptyContent();
|
|
1094
|
-
const packedInput = unpackMessage(resolvedInput.pack());
|
|
1097
|
+
const resolvedInput = input ?? new response_1.EmptyContent();
|
|
1098
|
+
const packedInput = (0, utils_1.unpackMessage)(resolvedInput.pack());
|
|
1095
1099
|
const request = {
|
|
1096
1100
|
toolkit,
|
|
1097
1101
|
tool,
|
|
@@ -1110,7 +1114,7 @@ export class RoomClient {
|
|
|
1110
1114
|
_sendLocalAttributesNowait(attributes) {
|
|
1111
1115
|
this._sendProtocolNowait({
|
|
1112
1116
|
type: "set_attributes",
|
|
1113
|
-
data: packMessage(attributes),
|
|
1117
|
+
data: (0, utils_1.packMessage)(attributes),
|
|
1114
1118
|
label: "local participant attribute update",
|
|
1115
1119
|
});
|
|
1116
1120
|
}
|
|
@@ -1131,10 +1135,10 @@ export class RoomClient {
|
|
|
1131
1135
|
throw this._disconnectedError({ baseMessage: "room connection is disconnected" });
|
|
1132
1136
|
}
|
|
1133
1137
|
const requestId = this._protocolInstance.getNextMessageId();
|
|
1134
|
-
const completer = new Completer();
|
|
1138
|
+
const completer = new completer_1.Completer();
|
|
1135
1139
|
this._pendingRequests.set(requestId, completer);
|
|
1136
1140
|
try {
|
|
1137
|
-
await this._protocolInstance.send(type, packMessage(request, data), requestId);
|
|
1141
|
+
await this._protocolInstance.send(type, (0, utils_1.packMessage)(request, data), requestId);
|
|
1138
1142
|
return await completer.fut;
|
|
1139
1143
|
}
|
|
1140
1144
|
catch (error) {
|
|
@@ -1157,39 +1161,39 @@ export class RoomClient {
|
|
|
1157
1161
|
request["timeout"] = params.timeout;
|
|
1158
1162
|
}
|
|
1159
1163
|
const result = await this.sendRequest("room.list_toolkits", request);
|
|
1160
|
-
if (!(result instanceof JsonContent)) {
|
|
1161
|
-
throw new RoomServerException("unexpected return type from room.list_toolkits");
|
|
1164
|
+
if (!(result instanceof response_1.JsonContent)) {
|
|
1165
|
+
throw new room_server_client_1.RoomServerException("unexpected return type from room.list_toolkits");
|
|
1162
1166
|
}
|
|
1163
1167
|
const tools = result.json["tools"];
|
|
1164
1168
|
if (typeof tools !== "object" || tools === null || Array.isArray(tools)) {
|
|
1165
|
-
throw new RoomServerException("unexpected return type from room.list_toolkits");
|
|
1169
|
+
throw new room_server_client_1.RoomServerException("unexpected return type from room.list_toolkits");
|
|
1166
1170
|
}
|
|
1167
1171
|
const toolkits = [];
|
|
1168
1172
|
for (const [name, data] of Object.entries(tools)) {
|
|
1169
1173
|
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
1170
|
-
throw new RoomServerException("unexpected toolkit description from room.list_toolkits");
|
|
1174
|
+
throw new room_server_client_1.RoomServerException("unexpected toolkit description from room.list_toolkits");
|
|
1171
1175
|
}
|
|
1172
|
-
toolkits.push(ToolkitDescription.fromJson(data, { name }));
|
|
1176
|
+
toolkits.push(agent_client_1.ToolkitDescription.fromJson(data, { name }));
|
|
1173
1177
|
}
|
|
1174
1178
|
return toolkits;
|
|
1175
1179
|
}
|
|
1176
1180
|
async invoke(params) {
|
|
1177
|
-
const input = params.input ?? params.arguments ?? new EmptyContent();
|
|
1181
|
+
const input = params.input ?? params.arguments ?? new response_1.EmptyContent();
|
|
1178
1182
|
const request = {
|
|
1179
1183
|
toolkit: params.toolkit,
|
|
1180
1184
|
tool: params.tool,
|
|
1181
1185
|
};
|
|
1182
1186
|
let requestData;
|
|
1183
|
-
if (input instanceof BinaryContent ||
|
|
1184
|
-
input instanceof EmptyContent ||
|
|
1185
|
-
input instanceof ErrorContent ||
|
|
1186
|
-
input instanceof FileContent ||
|
|
1187
|
-
input instanceof JsonContent ||
|
|
1188
|
-
input instanceof LinkContent ||
|
|
1189
|
-
input instanceof TextContent) {
|
|
1187
|
+
if (input instanceof response_1.BinaryContent ||
|
|
1188
|
+
input instanceof response_1.EmptyContent ||
|
|
1189
|
+
input instanceof response_1.ErrorContent ||
|
|
1190
|
+
input instanceof response_1.FileContent ||
|
|
1191
|
+
input instanceof response_1.JsonContent ||
|
|
1192
|
+
input instanceof response_1.LinkContent ||
|
|
1193
|
+
input instanceof response_1.TextContent) {
|
|
1190
1194
|
const packed = input.pack();
|
|
1191
|
-
request["arguments"] = JSON.parse(splitMessageHeader(packed));
|
|
1192
|
-
const payload = splitMessagePayload(packed);
|
|
1195
|
+
request["arguments"] = JSON.parse((0, utils_1.splitMessageHeader)(packed));
|
|
1196
|
+
const payload = (0, utils_1.splitMessagePayload)(packed);
|
|
1193
1197
|
if (payload.length > 0) {
|
|
1194
1198
|
requestData = payload;
|
|
1195
1199
|
}
|
|
@@ -1201,7 +1205,7 @@ export class RoomClient {
|
|
|
1201
1205
|
};
|
|
1202
1206
|
}
|
|
1203
1207
|
else {
|
|
1204
|
-
throw new RoomServerException("invoke input must be a content value or JSON object");
|
|
1208
|
+
throw new room_server_client_1.RoomServerException("invoke input must be a content value or JSON object");
|
|
1205
1209
|
}
|
|
1206
1210
|
if (params.participantId != null) {
|
|
1207
1211
|
request["participant_id"] = params.participantId;
|
|
@@ -1235,8 +1239,8 @@ export class RoomClient {
|
|
|
1235
1239
|
try {
|
|
1236
1240
|
const response = await this.sendRequest("room.invoke_tool", request);
|
|
1237
1241
|
await requestTask;
|
|
1238
|
-
if (response instanceof ControlContent && response.method === "open") {
|
|
1239
|
-
throw new RoomServerException(`unexpected return type from ${params.toolkit}.${params.tool}`);
|
|
1242
|
+
if (response instanceof response_1.ControlContent && response.method === "open") {
|
|
1243
|
+
throw new room_server_client_1.RoomServerException(`unexpected return type from ${params.toolkit}.${params.tool}`);
|
|
1240
1244
|
}
|
|
1241
1245
|
return response;
|
|
1242
1246
|
}
|
|
@@ -1247,7 +1251,7 @@ export class RoomClient {
|
|
|
1247
1251
|
}
|
|
1248
1252
|
async invokeStream(params) {
|
|
1249
1253
|
const toolCallId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
1250
|
-
const controller = new StreamController();
|
|
1254
|
+
const controller = new stream_controller_1.StreamController();
|
|
1251
1255
|
const responseIterator = controller.stream[Symbol.asyncIterator]();
|
|
1252
1256
|
this._toolCallStreams.set(toolCallId, controller);
|
|
1253
1257
|
const request = {
|
|
@@ -1271,15 +1275,15 @@ export class RoomClient {
|
|
|
1271
1275
|
if (stream == null) {
|
|
1272
1276
|
return;
|
|
1273
1277
|
}
|
|
1274
|
-
stream.add(new ErrorContent({ text: `request stream failed: ${String(error)}` }));
|
|
1278
|
+
stream.add(new response_1.ErrorContent({ text: `request stream failed: ${String(error)}` }));
|
|
1275
1279
|
stream.close();
|
|
1276
1280
|
this._toolCallStreams.delete(toolCallId);
|
|
1277
1281
|
});
|
|
1278
1282
|
const response = await this.sendRequest("room.invoke_tool", request);
|
|
1279
|
-
if (!(response instanceof ControlContent) || response.method !== "open") {
|
|
1283
|
+
if (!(response instanceof response_1.ControlContent) || response.method !== "open") {
|
|
1280
1284
|
this._toolCallStreams.delete(toolCallId);
|
|
1281
1285
|
controller.close();
|
|
1282
|
-
throw new RoomServerException(`unexpected return type from ${params.toolkit}.${params.tool}`);
|
|
1286
|
+
throw new room_server_client_1.RoomServerException(`unexpected return type from ${params.toolkit}.${params.tool}`);
|
|
1283
1287
|
}
|
|
1284
1288
|
return {
|
|
1285
1289
|
[Symbol.asyncIterator]() {
|
|
@@ -1291,9 +1295,9 @@ export class RoomClient {
|
|
|
1291
1295
|
const packed = chunk.pack();
|
|
1292
1296
|
const request = {
|
|
1293
1297
|
tool_call_id: toolCallId,
|
|
1294
|
-
chunk: JSON.parse(splitMessageHeader(packed)),
|
|
1298
|
+
chunk: JSON.parse((0, utils_1.splitMessageHeader)(packed)),
|
|
1295
1299
|
};
|
|
1296
|
-
const payload = splitMessagePayload(packed);
|
|
1300
|
+
const payload = (0, utils_1.splitMessagePayload)(packed);
|
|
1297
1301
|
await this.sendRequest("room.tool_call_request_chunk", request, payload.length > 0 ? payload : undefined);
|
|
1298
1302
|
}
|
|
1299
1303
|
async _streamInvokeToolRequestChunks(toolCallId, input) {
|
|
@@ -1304,7 +1308,7 @@ export class RoomClient {
|
|
|
1304
1308
|
}
|
|
1305
1309
|
}
|
|
1306
1310
|
finally {
|
|
1307
|
-
await this._sendToolCallRequestChunk(toolCallId, new ControlContent({ method: "close" }));
|
|
1311
|
+
await this._sendToolCallRequestChunk(toolCallId, new response_1.ControlContent({ method: "close" }));
|
|
1308
1312
|
}
|
|
1309
1313
|
}
|
|
1310
1314
|
_decodeToolCallContent(params) {
|
|
@@ -1312,17 +1316,17 @@ export class RoomClient {
|
|
|
1312
1316
|
if (typeof chunk === "object" && chunk !== null && !Array.isArray(chunk)) {
|
|
1313
1317
|
const chunkMap = chunk;
|
|
1314
1318
|
if (typeof chunkMap["type"] === "string") {
|
|
1315
|
-
return unpackContent(packMessage(chunkMap, params.payload.length > 0 ? params.payload : undefined));
|
|
1319
|
+
return (0, response_1.unpackContent)((0, utils_1.packMessage)(chunkMap, params.payload.length > 0 ? params.payload : undefined));
|
|
1316
1320
|
}
|
|
1317
|
-
return new JsonContent({ json: chunkMap });
|
|
1321
|
+
return new response_1.JsonContent({ json: chunkMap });
|
|
1318
1322
|
}
|
|
1319
|
-
return new JsonContent({ json: { chunk } });
|
|
1323
|
+
return new response_1.JsonContent({ json: { chunk } });
|
|
1320
1324
|
}
|
|
1321
1325
|
async _handleToolCallResponseChunk(protocol, _messageId, _type, data) {
|
|
1322
1326
|
if (!this.isActiveProtocol(protocol)) {
|
|
1323
1327
|
return;
|
|
1324
1328
|
}
|
|
1325
|
-
const [header, payload] = unpackMessage(data);
|
|
1329
|
+
const [header, payload] = (0, utils_1.unpackMessage)(data);
|
|
1326
1330
|
const toolCallId = header["tool_call_id"];
|
|
1327
1331
|
if (typeof toolCallId !== "string" || toolCallId.length === 0) {
|
|
1328
1332
|
return;
|
|
@@ -1333,7 +1337,7 @@ export class RoomClient {
|
|
|
1333
1337
|
}
|
|
1334
1338
|
const content = this._decodeToolCallContent({ header, payload });
|
|
1335
1339
|
stream.add(content);
|
|
1336
|
-
if (content instanceof ControlContent && content.method === "close") {
|
|
1340
|
+
if (content instanceof response_1.ControlContent && content.method === "close") {
|
|
1337
1341
|
stream.close();
|
|
1338
1342
|
this._toolCallStreams.delete(toolCallId);
|
|
1339
1343
|
}
|
|
@@ -1342,12 +1346,12 @@ export class RoomClient {
|
|
|
1342
1346
|
if (!this.isActiveProtocol(protocol)) {
|
|
1343
1347
|
return;
|
|
1344
1348
|
}
|
|
1345
|
-
const response = unpackContent(data);
|
|
1349
|
+
const response = (0, response_1.unpackContent)(data);
|
|
1346
1350
|
const pending = this._pendingRequests.get(messageId);
|
|
1347
1351
|
if (pending != null) {
|
|
1348
1352
|
this._pendingRequests.delete(messageId);
|
|
1349
|
-
if (response instanceof ErrorContent) {
|
|
1350
|
-
pending.completeError(new RoomServerException(response.text, response.code));
|
|
1353
|
+
if (response instanceof response_1.ErrorContent) {
|
|
1354
|
+
pending.completeError(new room_server_client_1.RoomServerException(response.text, response.code));
|
|
1351
1355
|
}
|
|
1352
1356
|
else {
|
|
1353
1357
|
pending.complete(response);
|
|
@@ -1357,7 +1361,7 @@ export class RoomClient {
|
|
|
1357
1361
|
const ignoredLabel = this._ignoredResponseLabels.get(messageId);
|
|
1358
1362
|
if (ignoredLabel != null) {
|
|
1359
1363
|
this._ignoredResponseLabels.delete(messageId);
|
|
1360
|
-
if (response instanceof ErrorContent) {
|
|
1364
|
+
if (response instanceof response_1.ErrorContent) {
|
|
1361
1365
|
console.warn(`one-way room request failed for ${ignoredLabel}: ${response.text}`);
|
|
1362
1366
|
}
|
|
1363
1367
|
}
|
|
@@ -1366,14 +1370,14 @@ export class RoomClient {
|
|
|
1366
1370
|
if (!this.isActiveProtocol(protocol)) {
|
|
1367
1371
|
return;
|
|
1368
1372
|
}
|
|
1369
|
-
const [payload] = unpackMessage(data);
|
|
1370
|
-
this.emit(RoomStatusEvent.fromJson(payload));
|
|
1373
|
+
const [payload] = (0, utils_1.unpackMessage)(data);
|
|
1374
|
+
this.emit(room_event_1.RoomStatusEvent.fromJson(payload));
|
|
1371
1375
|
}
|
|
1372
1376
|
async _handleRoomReady(protocol, _messageId, _type, data) {
|
|
1373
1377
|
if (!this.isActiveProtocol(protocol)) {
|
|
1374
1378
|
return;
|
|
1375
1379
|
}
|
|
1376
|
-
const [message] = unpackMessage(data);
|
|
1380
|
+
const [message] = (0, utils_1.unpackMessage)(data);
|
|
1377
1381
|
this._roomName = typeof message["room_name"] === "string" ? message["room_name"] : null;
|
|
1378
1382
|
this._roomUrl = typeof message["room_url"] === "string" ? message["room_url"] : null;
|
|
1379
1383
|
this._sessionId = typeof message["session_id"] === "string" ? message["session_id"] : null;
|
|
@@ -1386,7 +1390,7 @@ export class RoomClient {
|
|
|
1386
1390
|
}
|
|
1387
1391
|
_onParticipantInit(participantId, attributes) {
|
|
1388
1392
|
if (this._localParticipant == null) {
|
|
1389
|
-
this._localParticipant = new LocalParticipant(this, participantId);
|
|
1393
|
+
this._localParticipant = new participant_1.LocalParticipant(this, participantId);
|
|
1390
1394
|
this._localParticipant._setAttributes(attributes);
|
|
1391
1395
|
}
|
|
1392
1396
|
else {
|
|
@@ -1404,7 +1408,7 @@ export class RoomClient {
|
|
|
1404
1408
|
if (!this.isActiveProtocol(protocol)) {
|
|
1405
1409
|
return;
|
|
1406
1410
|
}
|
|
1407
|
-
const [message] = unpackMessage(data);
|
|
1411
|
+
const [message] = (0, utils_1.unpackMessage)(data);
|
|
1408
1412
|
switch (message["type"]) {
|
|
1409
1413
|
case "init": {
|
|
1410
1414
|
const participantId = message["participantId"];
|
|
@@ -1422,7 +1426,8 @@ export class RoomClient {
|
|
|
1422
1426
|
}
|
|
1423
1427
|
}
|
|
1424
1428
|
_emitStatus({ status, message, }) {
|
|
1425
|
-
this.emit(new RoomStatusEvent({ status, message }));
|
|
1429
|
+
this.emit(new room_event_1.RoomStatusEvent({ status, message }));
|
|
1426
1430
|
}
|
|
1427
1431
|
}
|
|
1432
|
+
exports.RoomClient = RoomClient;
|
|
1428
1433
|
RoomClient.RECONNECT_RETRY_INTERVAL_MS = 1000;
|