@meshagent/meshagent 0.42.0 → 0.43.0
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 +15 -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 +21 -3
- package/dist/browser/containers-client.js +126 -78
- 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 +21 -3
- package/dist/esm/containers-client.js +132 -89
- 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 +21 -3
- package/dist/node/containers-client.js +126 -78
- 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/esm/protocol.js
CHANGED
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WebSocketClientProtocol = exports.Protocol = exports.ProtocolMessageStream = exports.WebSocketProtocolChannel = exports.StreamProtocolChannel = exports.ProtocolHandshakeException = exports.ProtocolCloseException = exports.ProtocolReconnectUnsupportedException = exports.ProtocolCloseKind = void 0;
|
|
7
|
-
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
8
|
-
const completer_1 = require("./completer");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import WebSocket from "isomorphic-ws";
|
|
2
|
+
import { Completer } from "./completer.js";
|
|
3
|
+
import { decoder, encoder, mergeUint8Arrays, unpackMessage } from "./utils.js";
|
|
10
4
|
class ProtocolMessage {
|
|
11
5
|
constructor({ id, type, data }) {
|
|
12
6
|
this.id = id;
|
|
13
7
|
this.type = type;
|
|
14
8
|
this.data = data;
|
|
15
|
-
this.sent = new
|
|
9
|
+
this.sent = new Completer();
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
var ProtocolCloseKind;
|
|
12
|
+
export var ProtocolCloseKind;
|
|
19
13
|
(function (ProtocolCloseKind) {
|
|
20
14
|
ProtocolCloseKind["CLIENT"] = "client";
|
|
21
15
|
ProtocolCloseKind["SERVER"] = "server";
|
|
22
16
|
ProtocolCloseKind["ERROR"] = "error";
|
|
23
|
-
})(ProtocolCloseKind || (
|
|
24
|
-
class ProtocolReconnectUnsupportedException extends Error {
|
|
17
|
+
})(ProtocolCloseKind || (ProtocolCloseKind = {}));
|
|
18
|
+
export class ProtocolReconnectUnsupportedException extends Error {
|
|
25
19
|
constructor(message) {
|
|
26
20
|
super(message);
|
|
27
21
|
this.name = "ProtocolReconnectUnsupportedException";
|
|
28
22
|
}
|
|
29
23
|
}
|
|
30
|
-
|
|
31
|
-
class ProtocolCloseException extends Error {
|
|
24
|
+
export class ProtocolCloseException extends Error {
|
|
32
25
|
constructor({ closeCode, reason }) {
|
|
33
26
|
super(reason == null || reason.trim().length === 0 ? `connection closed with status ${closeCode}` : reason);
|
|
34
27
|
this.name = "ProtocolCloseException";
|
|
@@ -36,8 +29,7 @@ class ProtocolCloseException extends Error {
|
|
|
36
29
|
this.reason = reason;
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
|
-
|
|
40
|
-
class ProtocolHandshakeException extends Error {
|
|
32
|
+
export class ProtocolHandshakeException extends Error {
|
|
41
33
|
constructor({ statusCode, statusText }) {
|
|
42
34
|
const normalizedStatusText = statusText?.trim();
|
|
43
35
|
super(normalizedStatusText == null || normalizedStatusText.length === 0
|
|
@@ -48,11 +40,21 @@ class ProtocolHandshakeException extends Error {
|
|
|
48
40
|
this.statusText = normalizedStatusText;
|
|
49
41
|
}
|
|
50
42
|
}
|
|
51
|
-
exports.ProtocolHandshakeException = ProtocolHandshakeException;
|
|
52
43
|
function isNodeRuntime() {
|
|
53
44
|
return typeof process !== "undefined" && process.release?.name === "node";
|
|
54
45
|
}
|
|
55
|
-
|
|
46
|
+
function resolveWebSocketUrl(url) {
|
|
47
|
+
const baseUrl = globalThis.location?.href;
|
|
48
|
+
const resolved = baseUrl == null ? new URL(url) : new URL(url, baseUrl);
|
|
49
|
+
if (resolved.protocol === "https:") {
|
|
50
|
+
resolved.protocol = "wss:";
|
|
51
|
+
}
|
|
52
|
+
else if (resolved.protocol === "http:") {
|
|
53
|
+
resolved.protocol = "ws:";
|
|
54
|
+
}
|
|
55
|
+
return resolved;
|
|
56
|
+
}
|
|
57
|
+
export class StreamProtocolChannel {
|
|
56
58
|
constructor({ input, output, }) {
|
|
57
59
|
this.started = false;
|
|
58
60
|
this._iterator = null;
|
|
@@ -90,11 +92,10 @@ class StreamProtocolChannel {
|
|
|
90
92
|
this.output.add(data);
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
|
-
|
|
94
|
-
class WebSocketProtocolChannel {
|
|
95
|
+
export class WebSocketProtocolChannel {
|
|
95
96
|
constructor({ url, jwt }) {
|
|
96
97
|
this.webSocket = null;
|
|
97
|
-
this._opened = new
|
|
98
|
+
this._opened = new Completer();
|
|
98
99
|
this._finished = false;
|
|
99
100
|
this._onUnexpectedResponse = (_request, response) => {
|
|
100
101
|
const statusCode = response.statusCode;
|
|
@@ -121,7 +122,7 @@ class WebSocketProtocolChannel {
|
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
123
124
|
if (typeof data === "string") {
|
|
124
|
-
this._onDataReceived?.(
|
|
125
|
+
this._onDataReceived?.(encoder.encode(data));
|
|
125
126
|
return;
|
|
126
127
|
}
|
|
127
128
|
if (data instanceof ArrayBuffer) {
|
|
@@ -151,16 +152,18 @@ class WebSocketProtocolChannel {
|
|
|
151
152
|
this.jwt = jwt;
|
|
152
153
|
}
|
|
153
154
|
start(onDataReceived, { onDone, onError }) {
|
|
154
|
-
const url =
|
|
155
|
-
|
|
156
|
-
this._opened = new completer_1.Completer();
|
|
155
|
+
const url = resolveWebSocketUrl(this.url);
|
|
156
|
+
this._opened = new Completer();
|
|
157
157
|
this._finished = false;
|
|
158
158
|
this._onDataReceived = onDataReceived;
|
|
159
159
|
this._doneHandler = onDone;
|
|
160
160
|
this._errorHandler = onError;
|
|
161
161
|
const socket = isNodeRuntime()
|
|
162
|
-
? new
|
|
163
|
-
|
|
162
|
+
? new WebSocket(url.toString(), [], {
|
|
163
|
+
headers: this.jwt == null ? undefined : { Authorization: `Bearer ${this.jwt}` },
|
|
164
|
+
perMessageDeflate: true,
|
|
165
|
+
})
|
|
166
|
+
: new WebSocket(url.toString(), this.jwt == null ? [] : [`meshagent-room.${this.jwt}`]);
|
|
164
167
|
this.webSocket = socket;
|
|
165
168
|
if (isNodeRuntime()) {
|
|
166
169
|
socket.on("unexpected-response", this._onUnexpectedResponse);
|
|
@@ -195,7 +198,7 @@ class WebSocketProtocolChannel {
|
|
|
195
198
|
if (isNodeRuntime()) {
|
|
196
199
|
socket.off("unexpected-response", this._onUnexpectedResponse);
|
|
197
200
|
}
|
|
198
|
-
if (socket.readyState ===
|
|
201
|
+
if (socket.readyState === WebSocket.CONNECTING || socket.readyState === WebSocket.OPEN) {
|
|
199
202
|
socket.close(1000);
|
|
200
203
|
}
|
|
201
204
|
}
|
|
@@ -208,11 +211,10 @@ class WebSocketProtocolChannel {
|
|
|
208
211
|
socket.send(data);
|
|
209
212
|
}
|
|
210
213
|
}
|
|
211
|
-
|
|
212
|
-
class ProtocolMessageStream {
|
|
214
|
+
export class ProtocolMessageStream {
|
|
213
215
|
constructor() {
|
|
214
216
|
this._messages = [];
|
|
215
|
-
this._messageAdded = new
|
|
217
|
+
this._messageAdded = new Completer();
|
|
216
218
|
this._closed = false;
|
|
217
219
|
}
|
|
218
220
|
add(message) {
|
|
@@ -230,7 +232,7 @@ class ProtocolMessageStream {
|
|
|
230
232
|
async *stream() {
|
|
231
233
|
while (!this._closed) {
|
|
232
234
|
await this._messageAdded.fut;
|
|
233
|
-
this._messageAdded = new
|
|
235
|
+
this._messageAdded = new Completer();
|
|
234
236
|
while (this._messages.length > 0 && !this._closed) {
|
|
235
237
|
const message = this._messages.shift();
|
|
236
238
|
if (message !== undefined) {
|
|
@@ -240,13 +242,12 @@ class ProtocolMessageStream {
|
|
|
240
242
|
}
|
|
241
243
|
}
|
|
242
244
|
}
|
|
243
|
-
|
|
244
|
-
class Protocol {
|
|
245
|
+
export class Protocol {
|
|
245
246
|
constructor({ channel }) {
|
|
246
247
|
this.handlers = {};
|
|
247
248
|
this._id = 0;
|
|
248
249
|
this._send = new ProtocolMessageStream();
|
|
249
|
-
this._done = new
|
|
250
|
+
this._done = new Completer();
|
|
250
251
|
this._sendLoop = null;
|
|
251
252
|
this._open = false;
|
|
252
253
|
this._closed = false;
|
|
@@ -325,7 +326,7 @@ class Protocol {
|
|
|
325
326
|
async handleMessage(messageId, type, data) {
|
|
326
327
|
const handler = this.handlers[type] ?? this.handlers["*"];
|
|
327
328
|
if (handler == null) {
|
|
328
|
-
const unpacked =
|
|
329
|
+
const unpacked = unpackMessage(data);
|
|
329
330
|
console.warn(`No handler for message type ${type}; data:`, unpacked);
|
|
330
331
|
return;
|
|
331
332
|
}
|
|
@@ -357,7 +358,7 @@ class Protocol {
|
|
|
357
358
|
await message.sent.fut;
|
|
358
359
|
}
|
|
359
360
|
async sendJson(object) {
|
|
360
|
-
await this.send("application/json",
|
|
361
|
+
await this.send("application/json", encoder.encode(JSON.stringify(object)));
|
|
361
362
|
}
|
|
362
363
|
start({ onMessage, onDone, onError, } = {}) {
|
|
363
364
|
if (this._sendLoop != null) {
|
|
@@ -419,14 +420,14 @@ class Protocol {
|
|
|
419
420
|
headerView.setUint32(4, message.id & 0xffffffff, false);
|
|
420
421
|
headerView.setUint32(8, 0, false);
|
|
421
422
|
headerView.setUint32(12, packets, false);
|
|
422
|
-
await this.channel.sendData(
|
|
423
|
+
await this.channel.sendData(mergeUint8Arrays(header, encoder.encode(message.type)));
|
|
423
424
|
for (let i = 0; i < packets; i += 1) {
|
|
424
425
|
const packetHeader = new Uint8Array(12);
|
|
425
426
|
const packetHeaderView = new DataView(packetHeader.buffer);
|
|
426
427
|
packetHeaderView.setUint32(0, Math.floor(message.id / 2 ** 32), false);
|
|
427
428
|
packetHeaderView.setUint32(4, message.id & 0xffffffff, false);
|
|
428
429
|
packetHeaderView.setUint32(8, i + 1, false);
|
|
429
|
-
await this.channel.sendData(
|
|
430
|
+
await this.channel.sendData(mergeUint8Arrays(packetHeader, message.data.subarray(i * 1024, Math.min((i + 1) * 1024, message.data.length))));
|
|
430
431
|
}
|
|
431
432
|
if (!message.sent.completed) {
|
|
432
433
|
message.sent.complete();
|
|
@@ -461,10 +462,10 @@ class Protocol {
|
|
|
461
462
|
if (this._recvState === "ready" || this._recvState === "error") {
|
|
462
463
|
this._recvPacketTotal = dataView.getUint32(12, false);
|
|
463
464
|
this._recvMessageId = messageId;
|
|
464
|
-
this._recvType =
|
|
465
|
+
this._recvType = decoder.decode(dataPacket.subarray(16));
|
|
465
466
|
if (this._recvPacketTotal === 0) {
|
|
466
467
|
try {
|
|
467
|
-
const merged =
|
|
468
|
+
const merged = mergeUint8Arrays(...this._recvPackets);
|
|
468
469
|
this._recvPackets.length = 0;
|
|
469
470
|
this._dispatchMessage({ messageId, type: this._recvType, data: merged });
|
|
470
471
|
}
|
|
@@ -498,7 +499,7 @@ class Protocol {
|
|
|
498
499
|
this._recvPackets.push(dataPacket.subarray(12));
|
|
499
500
|
if (this._recvPacketTotal === this._recvPacketId) {
|
|
500
501
|
try {
|
|
501
|
-
const merged =
|
|
502
|
+
const merged = mergeUint8Arrays(...this._recvPackets);
|
|
502
503
|
this._recvPackets.length = 0;
|
|
503
504
|
this._dispatchMessage({ messageId, type: this._recvType, data: merged });
|
|
504
505
|
}
|
|
@@ -518,8 +519,7 @@ class Protocol {
|
|
|
518
519
|
});
|
|
519
520
|
}
|
|
520
521
|
}
|
|
521
|
-
|
|
522
|
-
class WebSocketClientProtocol extends Protocol {
|
|
522
|
+
export class WebSocketClientProtocol extends Protocol {
|
|
523
523
|
constructor({ url, token }) {
|
|
524
524
|
super({
|
|
525
525
|
channel: new WebSocketProtocolChannel({ url, jwt: token }),
|
|
@@ -527,6 +527,9 @@ class WebSocketClientProtocol extends Protocol {
|
|
|
527
527
|
this._url = url;
|
|
528
528
|
this._token = token;
|
|
529
529
|
}
|
|
530
|
+
static withIAP({ url = "./.well-known/meshagent/room/connect" } = {}) {
|
|
531
|
+
return new WebSocketClientProtocol({ url, token: null });
|
|
532
|
+
}
|
|
530
533
|
get url() {
|
|
531
534
|
return this._url;
|
|
532
535
|
}
|
|
@@ -534,4 +537,3 @@ class WebSocketClientProtocol extends Protocol {
|
|
|
534
537
|
return this._token;
|
|
535
538
|
}
|
|
536
539
|
}
|
|
537
|
-
exports.WebSocketClientProtocol = WebSocketClientProtocol;
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const response_1 = require("./response");
|
|
5
|
-
const room_server_client_1 = require("./room-server-client");
|
|
6
|
-
class Queue {
|
|
1
|
+
import { EmptyContent, JsonContent } from "./response.js";
|
|
2
|
+
import { RoomServerException } from "./room-server-client.js";
|
|
3
|
+
export class Queue {
|
|
7
4
|
constructor({ name, size }) {
|
|
8
5
|
this.name = name;
|
|
9
6
|
this.size = size;
|
|
10
7
|
}
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
class QueuesClient {
|
|
9
|
+
export class QueuesClient {
|
|
14
10
|
constructor({ room }) {
|
|
15
11
|
this.client = room;
|
|
16
12
|
}
|
|
17
13
|
_unexpectedResponseError(operation) {
|
|
18
|
-
return new
|
|
14
|
+
return new RoomServerException(`unexpected return type from queues.${operation}`);
|
|
19
15
|
}
|
|
20
16
|
async _invoke(operation, arguments_) {
|
|
21
17
|
return await this.client.invoke({
|
|
@@ -26,7 +22,7 @@ class QueuesClient {
|
|
|
26
22
|
}
|
|
27
23
|
async list() {
|
|
28
24
|
const response = await this._invoke("list", {});
|
|
29
|
-
if (!(response instanceof
|
|
25
|
+
if (!(response instanceof JsonContent)) {
|
|
30
26
|
throw this._unexpectedResponseError("list");
|
|
31
27
|
}
|
|
32
28
|
const queues = response.json["queues"];
|
|
@@ -34,25 +30,25 @@ class QueuesClient {
|
|
|
34
30
|
}
|
|
35
31
|
async open(name) {
|
|
36
32
|
const response = await this._invoke("open", { name });
|
|
37
|
-
if (!(response instanceof
|
|
33
|
+
if (!(response instanceof EmptyContent)) {
|
|
38
34
|
throw this._unexpectedResponseError("open");
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
37
|
async drain(name) {
|
|
42
38
|
const response = await this._invoke("drain", { name });
|
|
43
|
-
if (!(response instanceof
|
|
39
|
+
if (!(response instanceof EmptyContent)) {
|
|
44
40
|
throw this._unexpectedResponseError("drain");
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
async close(name) {
|
|
48
44
|
const response = await this._invoke("close", { name });
|
|
49
|
-
if (!(response instanceof
|
|
45
|
+
if (!(response instanceof EmptyContent)) {
|
|
50
46
|
throw this._unexpectedResponseError("close");
|
|
51
47
|
}
|
|
52
48
|
}
|
|
53
49
|
async send(name, message, { create = true }) {
|
|
54
50
|
const response = await this._invoke("send", { name, create, message });
|
|
55
|
-
if (!(response instanceof
|
|
51
|
+
if (!(response instanceof EmptyContent)) {
|
|
56
52
|
throw this._unexpectedResponseError("send");
|
|
57
53
|
}
|
|
58
54
|
}
|
|
@@ -62,13 +58,12 @@ class QueuesClient {
|
|
|
62
58
|
create,
|
|
63
59
|
wait,
|
|
64
60
|
});
|
|
65
|
-
if (response instanceof
|
|
61
|
+
if (response instanceof EmptyContent) {
|
|
66
62
|
return null;
|
|
67
63
|
}
|
|
68
|
-
if (response instanceof
|
|
64
|
+
if (response instanceof JsonContent) {
|
|
69
65
|
return response.json;
|
|
70
66
|
}
|
|
71
67
|
throw this._unexpectedResponseError("receive");
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
|
-
exports.QueuesClient = QueuesClient;
|
package/dist/esm/requirement.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequiredSchema = exports.RequiredToolkit = exports.Requirement = exports.RoomException = void 0;
|
|
4
|
-
class RoomException extends Error {
|
|
1
|
+
export class RoomException extends Error {
|
|
5
2
|
constructor(message) {
|
|
6
3
|
super(message);
|
|
7
4
|
this.name = "RoomException";
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
class Requirement {
|
|
7
|
+
export class Requirement {
|
|
12
8
|
constructor({ name }) {
|
|
13
9
|
this.name = name;
|
|
14
10
|
}
|
|
@@ -26,8 +22,7 @@ class Requirement {
|
|
|
26
22
|
throw new RoomException("invalid requirement json");
|
|
27
23
|
}
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
class RequiredToolkit extends Requirement {
|
|
25
|
+
export class RequiredToolkit extends Requirement {
|
|
31
26
|
constructor({ name, tools, participantName, }) {
|
|
32
27
|
super({ name });
|
|
33
28
|
this.tools = tools;
|
|
@@ -41,8 +36,7 @@ class RequiredToolkit extends Requirement {
|
|
|
41
36
|
};
|
|
42
37
|
}
|
|
43
38
|
}
|
|
44
|
-
|
|
45
|
-
class RequiredSchema extends Requirement {
|
|
39
|
+
export class RequiredSchema extends Requirement {
|
|
46
40
|
constructor({ name }) {
|
|
47
41
|
super({ name });
|
|
48
42
|
}
|
|
@@ -52,4 +46,3 @@ class RequiredSchema extends Requirement {
|
|
|
52
46
|
};
|
|
53
47
|
}
|
|
54
48
|
}
|
|
55
|
-
exports.RequiredSchema = RequiredSchema;
|
package/dist/esm/response.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ControlContent = exports.ControlCloseStatus = exports.EmptyContent = exports.ErrorContent = exports.JsonContent = exports.TextContent = exports.FileContent = exports.LinkContent = exports.BinaryContent = void 0;
|
|
4
|
-
exports.unpackContent = unpackContent;
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
class BinaryContent {
|
|
1
|
+
import { packMessage, splitMessageHeader, splitMessagePayload } from "./utils.js";
|
|
2
|
+
export class BinaryContent {
|
|
7
3
|
constructor({ data, headers = {} }) {
|
|
8
4
|
this.data = data;
|
|
9
5
|
this.headers = headers;
|
|
@@ -15,7 +11,7 @@ class BinaryContent {
|
|
|
15
11
|
});
|
|
16
12
|
}
|
|
17
13
|
pack() {
|
|
18
|
-
return
|
|
14
|
+
return packMessage({
|
|
19
15
|
type: "binary",
|
|
20
16
|
headers: this.headers,
|
|
21
17
|
}, this.data);
|
|
@@ -24,8 +20,7 @@ class BinaryContent {
|
|
|
24
20
|
return `BinaryContent: headers=${JSON.stringify(this.headers)} length=${this.data.length}`;
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
class LinkContent {
|
|
23
|
+
export class LinkContent {
|
|
29
24
|
constructor({ url, name }) {
|
|
30
25
|
this.url = url;
|
|
31
26
|
this.name = name;
|
|
@@ -37,7 +32,7 @@ class LinkContent {
|
|
|
37
32
|
});
|
|
38
33
|
}
|
|
39
34
|
pack() {
|
|
40
|
-
return
|
|
35
|
+
return packMessage({
|
|
41
36
|
type: "link",
|
|
42
37
|
name: this.name,
|
|
43
38
|
url: this.url,
|
|
@@ -47,8 +42,7 @@ class LinkContent {
|
|
|
47
42
|
return `LinkContent (${this.name}): ${this.url}`;
|
|
48
43
|
}
|
|
49
44
|
}
|
|
50
|
-
|
|
51
|
-
class FileContent {
|
|
45
|
+
export class FileContent {
|
|
52
46
|
constructor({ data, name, mimeType }) {
|
|
53
47
|
this.data = data;
|
|
54
48
|
this.name = name;
|
|
@@ -62,7 +56,7 @@ class FileContent {
|
|
|
62
56
|
});
|
|
63
57
|
}
|
|
64
58
|
pack() {
|
|
65
|
-
return
|
|
59
|
+
return packMessage({
|
|
66
60
|
type: "file",
|
|
67
61
|
name: this.name,
|
|
68
62
|
mime_type: this.mimeType,
|
|
@@ -72,8 +66,7 @@ class FileContent {
|
|
|
72
66
|
return `FileContent (${this.name}): ${this.mimeType}`;
|
|
73
67
|
}
|
|
74
68
|
}
|
|
75
|
-
|
|
76
|
-
class TextContent {
|
|
69
|
+
export class TextContent {
|
|
77
70
|
constructor({ text }) {
|
|
78
71
|
this.text = text;
|
|
79
72
|
}
|
|
@@ -83,7 +76,7 @@ class TextContent {
|
|
|
83
76
|
});
|
|
84
77
|
}
|
|
85
78
|
pack() {
|
|
86
|
-
return
|
|
79
|
+
return packMessage({
|
|
87
80
|
type: "text",
|
|
88
81
|
text: this.text,
|
|
89
82
|
});
|
|
@@ -92,8 +85,7 @@ class TextContent {
|
|
|
92
85
|
return `TextContent: ${this.text}`;
|
|
93
86
|
}
|
|
94
87
|
}
|
|
95
|
-
|
|
96
|
-
class JsonContent {
|
|
88
|
+
export class JsonContent {
|
|
97
89
|
constructor({ json }) {
|
|
98
90
|
this.json = json;
|
|
99
91
|
}
|
|
@@ -101,7 +93,7 @@ class JsonContent {
|
|
|
101
93
|
return new JsonContent({ json: header["json"] });
|
|
102
94
|
}
|
|
103
95
|
pack() {
|
|
104
|
-
return
|
|
96
|
+
return packMessage({
|
|
105
97
|
type: "json",
|
|
106
98
|
json: this.json,
|
|
107
99
|
});
|
|
@@ -110,8 +102,7 @@ class JsonContent {
|
|
|
110
102
|
return `JsonContent: ${JSON.stringify(this.json)}`;
|
|
111
103
|
}
|
|
112
104
|
}
|
|
113
|
-
|
|
114
|
-
class ErrorContent {
|
|
105
|
+
export class ErrorContent {
|
|
115
106
|
constructor({ text, code }) {
|
|
116
107
|
this.text = text;
|
|
117
108
|
this.code = code;
|
|
@@ -138,7 +129,7 @@ class ErrorContent {
|
|
|
138
129
|
if (this.code !== undefined) {
|
|
139
130
|
header["code"] = this.code;
|
|
140
131
|
}
|
|
141
|
-
return
|
|
132
|
+
return packMessage(header);
|
|
142
133
|
}
|
|
143
134
|
toString() {
|
|
144
135
|
return this.code !== undefined
|
|
@@ -146,25 +137,23 @@ class ErrorContent {
|
|
|
146
137
|
: `ErrorContent: ${this.text}`;
|
|
147
138
|
}
|
|
148
139
|
}
|
|
149
|
-
|
|
150
|
-
class EmptyContent {
|
|
140
|
+
export class EmptyContent {
|
|
151
141
|
static unpack(_header, _payload) {
|
|
152
142
|
return new EmptyContent();
|
|
153
143
|
}
|
|
154
144
|
pack() {
|
|
155
|
-
return
|
|
145
|
+
return packMessage({ type: "empty" });
|
|
156
146
|
}
|
|
157
147
|
toString() {
|
|
158
148
|
return `EmptyContent`;
|
|
159
149
|
}
|
|
160
150
|
}
|
|
161
|
-
|
|
162
|
-
var ControlCloseStatus;
|
|
151
|
+
export var ControlCloseStatus;
|
|
163
152
|
(function (ControlCloseStatus) {
|
|
164
153
|
ControlCloseStatus[ControlCloseStatus["NORMAL"] = 1000] = "NORMAL";
|
|
165
154
|
ControlCloseStatus[ControlCloseStatus["INVALID_DATA"] = 1007] = "INVALID_DATA";
|
|
166
|
-
})(ControlCloseStatus || (
|
|
167
|
-
class ControlContent {
|
|
155
|
+
})(ControlCloseStatus || (ControlCloseStatus = {}));
|
|
156
|
+
export class ControlContent {
|
|
168
157
|
constructor({ method, statusCode, message, }) {
|
|
169
158
|
this.method = method;
|
|
170
159
|
this.statusCode = method === "close" ? statusCode ?? ControlCloseStatus.NORMAL : statusCode;
|
|
@@ -203,13 +192,12 @@ class ControlContent {
|
|
|
203
192
|
header["message"] = this.message;
|
|
204
193
|
}
|
|
205
194
|
}
|
|
206
|
-
return
|
|
195
|
+
return packMessage(header);
|
|
207
196
|
}
|
|
208
197
|
toString() {
|
|
209
198
|
return `ControlContent: ${this.method}`;
|
|
210
199
|
}
|
|
211
200
|
}
|
|
212
|
-
exports.ControlContent = ControlContent;
|
|
213
201
|
const _contentTypes = {
|
|
214
202
|
binary: BinaryContent.unpack,
|
|
215
203
|
control: ControlContent.unpack,
|
|
@@ -220,9 +208,9 @@ const _contentTypes = {
|
|
|
220
208
|
link: LinkContent.unpack,
|
|
221
209
|
text: TextContent.unpack,
|
|
222
210
|
};
|
|
223
|
-
function unpackContent(data) {
|
|
224
|
-
const header = JSON.parse(
|
|
225
|
-
const payload =
|
|
211
|
+
export function unpackContent(data) {
|
|
212
|
+
const header = JSON.parse(splitMessageHeader(data));
|
|
213
|
+
const payload = splitMessagePayload(data);
|
|
226
214
|
const typeKey = header["type"];
|
|
227
215
|
if (!_contentTypes[typeKey]) {
|
|
228
216
|
throw new Error(`Unknown content type: ${typeKey}`);
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { DatasetsClient } from "./datasets-client";
|
|
2
|
-
import { DeveloperClient } from "./developer-client";
|
|
3
|
-
import { type EventHandler, type EventName } from "./event-emitter";
|
|
4
|
-
import { MessagingClient } from "./messaging-client";
|
|
5
|
-
import { MemoryClient } from "./memory-client";
|
|
6
|
-
import { LocalParticipant } from "./participant";
|
|
7
|
-
import { Protocol, ProtocolCloseKind, type MessageHandler, type ProtocolFactory } from "./protocol";
|
|
8
|
-
import { QueuesClient } from "./queues-client";
|
|
9
|
-
import type { Content } from "./response";
|
|
10
|
-
import { RoomEvent } from "./room-event";
|
|
11
|
-
import { RoomServerException } from "./room-server-client";
|
|
12
|
-
import { SecretsClient, type OAuthTokenRequestHandler, type SecretRequestHandler } from "./secrets-client";
|
|
13
|
-
import { ServicesClient } from "./services-client";
|
|
14
|
-
import { StorageClient } from "./storage-client";
|
|
15
|
-
import { SyncClient } from "./sync-client";
|
|
16
|
-
import { AgentsClient, ToolkitDescription } from "./agent-client";
|
|
17
|
-
import { ContainersClient } from "./containers-client";
|
|
1
|
+
import { DatasetsClient } from "./datasets-client.js";
|
|
2
|
+
import { DeveloperClient } from "./developer-client.js";
|
|
3
|
+
import { type EventHandler, type EventName } from "./event-emitter.js";
|
|
4
|
+
import { MessagingClient } from "./messaging-client.js";
|
|
5
|
+
import { MemoryClient } from "./memory-client.js";
|
|
6
|
+
import { LocalParticipant } from "./participant.js";
|
|
7
|
+
import { Protocol, ProtocolCloseKind, type MessageHandler, type ProtocolFactory } from "./protocol.js";
|
|
8
|
+
import { QueuesClient } from "./queues-client.js";
|
|
9
|
+
import type { Content } from "./response.js";
|
|
10
|
+
import { RoomEvent } from "./room-event.js";
|
|
11
|
+
import { RoomServerException } from "./room-server-client.js";
|
|
12
|
+
import { SecretsClient, type OAuthTokenRequestHandler, type SecretRequestHandler } from "./secrets-client.js";
|
|
13
|
+
import { ServicesClient } from "./services-client.js";
|
|
14
|
+
import { StorageClient } from "./storage-client.js";
|
|
15
|
+
import { SyncClient } from "./sync-client.js";
|
|
16
|
+
import { AgentsClient, ToolkitDescription } from "./agent-client.js";
|
|
17
|
+
import { ContainersClient } from "./containers-client.js";
|
|
18
18
|
interface RequestHeader {
|
|
19
19
|
[key: string]: unknown;
|
|
20
20
|
}
|
|
@@ -98,6 +98,12 @@ export declare class RoomClient {
|
|
|
98
98
|
oauthTokenRequestHandler?: OAuthTokenRequestHandler;
|
|
99
99
|
secretRequestHandler?: SecretRequestHandler;
|
|
100
100
|
});
|
|
101
|
+
static withIAP({ url, reconnectTimeout, oauthTokenRequestHandler, secretRequestHandler, }?: {
|
|
102
|
+
url?: string;
|
|
103
|
+
reconnectTimeout?: number | null;
|
|
104
|
+
oauthTokenRequestHandler?: OAuthTokenRequestHandler;
|
|
105
|
+
secretRequestHandler?: SecretRequestHandler;
|
|
106
|
+
}): RoomClient;
|
|
101
107
|
get localParticipant(): LocalParticipant | null;
|
|
102
108
|
get ready(): Promise<void>;
|
|
103
109
|
get isConnected(): boolean;
|