@meshagent/meshagent 0.42.2 → 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 +7 -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
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
const event_emitter_1 = require("./event-emitter");
|
|
8
|
-
const room_server_client_1 = require("./room-server-client");
|
|
1
|
+
import { FileDeletedEvent, FileMovedEvent, FileUpdatedEvent } from "./room-event.js";
|
|
2
|
+
import { BinaryContent, ControlContent, ErrorContent, JsonContent, FileContent } from "./response.js";
|
|
3
|
+
import { unpackMessage } from "./utils.js";
|
|
4
|
+
import { EventEmitter } from "./event-emitter.js";
|
|
5
|
+
import { RoomServerException } from "./room-server-client.js";
|
|
9
6
|
const _DEFAULT_UPLOAD_MIME_TYPE = "application/octet-stream";
|
|
10
7
|
const _UPLOAD_MIME_TYPES_BY_SUFFIX = new Map([
|
|
11
8
|
[".tar.gz", "application/x-tar"],
|
|
@@ -41,7 +38,7 @@ const _UPLOAD_MIME_TYPES_BY_EXTENSION = new Map([
|
|
|
41
38
|
[".zip", "application/zip"],
|
|
42
39
|
]);
|
|
43
40
|
function _unexpectedStorageResponseError(operation) {
|
|
44
|
-
return new
|
|
41
|
+
return new RoomServerException(`unexpected return type from storage.${operation}`);
|
|
45
42
|
}
|
|
46
43
|
function _parseStorageTimestamp(value, operation) {
|
|
47
44
|
if (value == null) {
|
|
@@ -56,13 +53,12 @@ function _parseStorageTimestamp(value, operation) {
|
|
|
56
53
|
}
|
|
57
54
|
return timestamp;
|
|
58
55
|
}
|
|
59
|
-
class FileHandle {
|
|
56
|
+
export class FileHandle {
|
|
60
57
|
constructor({ id }) {
|
|
61
58
|
this.id = id;
|
|
62
59
|
}
|
|
63
60
|
}
|
|
64
|
-
|
|
65
|
-
class StorageEntry {
|
|
61
|
+
export class StorageEntry {
|
|
66
62
|
constructor({ name, isFolder, size = null, createdAt = null, updatedAt = null }) {
|
|
67
63
|
this.name = name;
|
|
68
64
|
this.isFolder = isFolder;
|
|
@@ -79,8 +75,7 @@ class StorageEntry {
|
|
|
79
75
|
.replace(/\.[^/.]+$/, "");
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
|
-
|
|
83
|
-
class StorageClient extends event_emitter_1.EventEmitter {
|
|
78
|
+
export class StorageClient extends EventEmitter {
|
|
84
79
|
constructor({ room }) {
|
|
85
80
|
super();
|
|
86
81
|
this.client = room;
|
|
@@ -92,8 +87,8 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
92
87
|
if (!this.client.isActiveProtocol(protocol)) {
|
|
93
88
|
return;
|
|
94
89
|
}
|
|
95
|
-
const [data, _] =
|
|
96
|
-
const event = new
|
|
90
|
+
const [data, _] = unpackMessage(bytes || new Uint8Array());
|
|
91
|
+
const event = new FileUpdatedEvent({ path: data["path"], participantId: data["participant_id"] });
|
|
97
92
|
this.client.emit(event);
|
|
98
93
|
this.emit('file.updated', event);
|
|
99
94
|
}
|
|
@@ -101,8 +96,8 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
101
96
|
if (!this.client.isActiveProtocol(protocol)) {
|
|
102
97
|
return;
|
|
103
98
|
}
|
|
104
|
-
const [data, _] =
|
|
105
|
-
const event = new
|
|
99
|
+
const [data, _] = unpackMessage(bytes || new Uint8Array());
|
|
100
|
+
const event = new FileDeletedEvent({ path: data["path"], participantId: data["participant_id"] });
|
|
106
101
|
this.client.emit(event);
|
|
107
102
|
this.emit('file.deleted', event);
|
|
108
103
|
}
|
|
@@ -110,8 +105,8 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
110
105
|
if (!this.client.isActiveProtocol(protocol)) {
|
|
111
106
|
return;
|
|
112
107
|
}
|
|
113
|
-
const [data, _] =
|
|
114
|
-
const event = new
|
|
108
|
+
const [data, _] = unpackMessage(bytes || new Uint8Array());
|
|
109
|
+
const event = new FileMovedEvent({
|
|
115
110
|
sourcePath: data["source_path"],
|
|
116
111
|
destinationPath: data["destination_path"],
|
|
117
112
|
participantId: data["participant_id"],
|
|
@@ -145,7 +140,7 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
145
140
|
}
|
|
146
141
|
async list(path) {
|
|
147
142
|
const response = await this._invoke("list", { path });
|
|
148
|
-
if (!(response instanceof
|
|
143
|
+
if (!(response instanceof JsonContent) || !Array.isArray(response.json["files"])) {
|
|
149
144
|
throw this._unexpectedResponseError("list");
|
|
150
145
|
}
|
|
151
146
|
const files = response.json["files"];
|
|
@@ -155,7 +150,7 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
155
150
|
}
|
|
156
151
|
async stat(path) {
|
|
157
152
|
const response = await this._invoke("stat", { path });
|
|
158
|
-
if (!(response instanceof
|
|
153
|
+
if (!(response instanceof JsonContent) || typeof response.json["exists"] !== "boolean") {
|
|
159
154
|
throw this._unexpectedResponseError("stat");
|
|
160
155
|
}
|
|
161
156
|
if (!response.json["exists"]) {
|
|
@@ -175,7 +170,7 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
175
170
|
}
|
|
176
171
|
async exists(path) {
|
|
177
172
|
const result = await this._invoke("exists", { path });
|
|
178
|
-
if (!(result instanceof
|
|
173
|
+
if (!(result instanceof JsonContent)) {
|
|
179
174
|
throw this._unexpectedResponseError("exists");
|
|
180
175
|
}
|
|
181
176
|
return result.json["exists"];
|
|
@@ -234,16 +229,16 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
234
229
|
});
|
|
235
230
|
try {
|
|
236
231
|
for await (const chunk of response) {
|
|
237
|
-
if (chunk instanceof
|
|
238
|
-
throw new
|
|
232
|
+
if (chunk instanceof ErrorContent) {
|
|
233
|
+
throw new RoomServerException(chunk.text, chunk.code);
|
|
239
234
|
}
|
|
240
|
-
if (chunk instanceof
|
|
235
|
+
if (chunk instanceof ControlContent) {
|
|
241
236
|
if (chunk.method === "close") {
|
|
242
237
|
return;
|
|
243
238
|
}
|
|
244
239
|
throw this._unexpectedResponseError("upload");
|
|
245
240
|
}
|
|
246
|
-
if (!(chunk instanceof
|
|
241
|
+
if (!(chunk instanceof BinaryContent)) {
|
|
247
242
|
throw this._unexpectedResponseError("upload");
|
|
248
243
|
}
|
|
249
244
|
if (chunk.headers["kind"] !== "pull") {
|
|
@@ -299,7 +294,7 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
299
294
|
data.set(part, offset);
|
|
300
295
|
offset += part.length;
|
|
301
296
|
}
|
|
302
|
-
return new
|
|
297
|
+
return new FileContent({ data, name, mimeType });
|
|
303
298
|
}
|
|
304
299
|
async downloadStream(path, { chunkSize = 64 * 1024, } = {}) {
|
|
305
300
|
const input = new _StorageDownloadInputStream({ path, chunkSize });
|
|
@@ -316,10 +311,10 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
316
311
|
let bytesReceived = 0;
|
|
317
312
|
try {
|
|
318
313
|
for await (const chunk of response) {
|
|
319
|
-
if (chunk instanceof
|
|
320
|
-
throw new
|
|
314
|
+
if (chunk instanceof ErrorContent) {
|
|
315
|
+
throw new RoomServerException(chunk.text, chunk.code);
|
|
321
316
|
}
|
|
322
|
-
if (chunk instanceof
|
|
317
|
+
if (chunk instanceof ControlContent) {
|
|
323
318
|
if (chunk.method === "close") {
|
|
324
319
|
if (!metadataReceived || expectedSize == null || bytesReceived !== expectedSize) {
|
|
325
320
|
throw self._unexpectedResponseError("download");
|
|
@@ -328,7 +323,7 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
328
323
|
}
|
|
329
324
|
throw self._unexpectedResponseError("download");
|
|
330
325
|
}
|
|
331
|
-
if (!(chunk instanceof
|
|
326
|
+
if (!(chunk instanceof BinaryContent)) {
|
|
332
327
|
throw self._unexpectedResponseError("download");
|
|
333
328
|
}
|
|
334
329
|
const kind = chunk.headers["kind"];
|
|
@@ -377,13 +372,12 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
377
372
|
path,
|
|
378
373
|
download: options.download ?? false,
|
|
379
374
|
});
|
|
380
|
-
if (!(response instanceof
|
|
375
|
+
if (!(response instanceof JsonContent)) {
|
|
381
376
|
throw this._unexpectedResponseError("download_url");
|
|
382
377
|
}
|
|
383
378
|
return response.json["url"];
|
|
384
379
|
}
|
|
385
380
|
}
|
|
386
|
-
exports.StorageClient = StorageClient;
|
|
387
381
|
class _StorageDownloadInputStream {
|
|
388
382
|
constructor({ path, chunkSize }) {
|
|
389
383
|
this.closed = false;
|
|
@@ -415,7 +409,7 @@ class _StorageDownloadInputStream {
|
|
|
415
409
|
}
|
|
416
410
|
}
|
|
417
411
|
async *stream() {
|
|
418
|
-
yield new
|
|
412
|
+
yield new BinaryContent({
|
|
419
413
|
data: new Uint8Array(0),
|
|
420
414
|
headers: {
|
|
421
415
|
kind: "start",
|
|
@@ -436,7 +430,7 @@ class _StorageDownloadInputStream {
|
|
|
436
430
|
continue;
|
|
437
431
|
}
|
|
438
432
|
this.pendingPulls -= 1;
|
|
439
|
-
yield new
|
|
433
|
+
yield new BinaryContent({
|
|
440
434
|
data: new Uint8Array(0),
|
|
441
435
|
headers: { kind: "pull" },
|
|
442
436
|
});
|
|
@@ -523,7 +517,7 @@ class _StorageUploadInputStream {
|
|
|
523
517
|
return combined;
|
|
524
518
|
}
|
|
525
519
|
async *stream() {
|
|
526
|
-
yield new
|
|
520
|
+
yield new BinaryContent({
|
|
527
521
|
data: new Uint8Array(0),
|
|
528
522
|
headers: {
|
|
529
523
|
kind: "start",
|
|
@@ -553,7 +547,7 @@ class _StorageUploadInputStream {
|
|
|
553
547
|
if (chunk == null) {
|
|
554
548
|
return;
|
|
555
549
|
}
|
|
556
|
-
yield new
|
|
550
|
+
yield new BinaryContent({
|
|
557
551
|
data: chunk,
|
|
558
552
|
headers: { kind: "data" },
|
|
559
553
|
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StreamController = void 0;
|
|
4
|
-
class StreamController {
|
|
1
|
+
export class StreamController {
|
|
5
2
|
constructor() {
|
|
6
3
|
this.closed = false;
|
|
7
4
|
this.subs = new Set();
|
|
@@ -75,4 +72,3 @@ class StreamController {
|
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
|
-
exports.StreamController = StreamController;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventEmitter } from "./event-emitter";
|
|
2
|
-
import { MeshSchema } from "./schema";
|
|
3
|
-
import { RoomClient } from "./room-client";
|
|
4
|
-
import { MeshDocument } from "./room-server-client";
|
|
1
|
+
import { EventEmitter } from "./event-emitter.js";
|
|
2
|
+
import { MeshSchema } from "./schema.js";
|
|
3
|
+
import { RoomClient } from "./room-client.js";
|
|
4
|
+
import { MeshDocument } from "./room-server-client.js";
|
|
5
5
|
export interface SyncClientEvent {
|
|
6
6
|
type: string;
|
|
7
7
|
doc?: MeshDocument;
|
package/dist/esm/sync-client.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const room_server_client_1 = require("./room-server-client");
|
|
9
|
-
const runtime_1 = require("./runtime");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { Completer } from "./completer.js";
|
|
2
|
+
import { EventEmitter } from "./event-emitter.js";
|
|
3
|
+
import { MeshSchema } from "./schema.js";
|
|
4
|
+
import { BinaryContent, ControlContent, ErrorContent } from "./response.js";
|
|
5
|
+
import { MeshDocument, RoomServerException } from "./room-server-client.js";
|
|
6
|
+
import { applyBackendChanges, unregisterDocument } from "./runtime.js";
|
|
7
|
+
import { decoder, encoder, RefCount } from "./utils.js";
|
|
11
8
|
function normalizeSyncPath(path) {
|
|
12
9
|
let normalized = path;
|
|
13
10
|
while (normalized.startsWith("./")) {
|
|
@@ -27,7 +24,7 @@ function parseSyncOpenStateChunkHeaders(headers) {
|
|
|
27
24
|
typeof headers["schema"] !== "object" ||
|
|
28
25
|
headers["schema"] == null ||
|
|
29
26
|
Array.isArray(headers["schema"])) {
|
|
30
|
-
throw new
|
|
27
|
+
throw new RoomServerException("unexpected return type from sync.open");
|
|
31
28
|
}
|
|
32
29
|
return {
|
|
33
30
|
kind: "state",
|
|
@@ -38,7 +35,7 @@ function parseSyncOpenStateChunkHeaders(headers) {
|
|
|
38
35
|
function parseSyncOpenOutputChunkHeaders(headers) {
|
|
39
36
|
const kind = headers["kind"];
|
|
40
37
|
if ((kind !== "state" && kind !== "sync") || typeof headers["path"] !== "string") {
|
|
41
|
-
throw new
|
|
38
|
+
throw new RoomServerException("unexpected return type from sync.open");
|
|
42
39
|
}
|
|
43
40
|
return {
|
|
44
41
|
kind,
|
|
@@ -70,7 +67,7 @@ class SyncOpenStreamState {
|
|
|
70
67
|
});
|
|
71
68
|
}
|
|
72
69
|
async *inputStream() {
|
|
73
|
-
yield new
|
|
70
|
+
yield new BinaryContent({
|
|
74
71
|
data: new Uint8Array(),
|
|
75
72
|
headers: {
|
|
76
73
|
kind: "start",
|
|
@@ -113,12 +110,12 @@ class SyncOpenStreamState {
|
|
|
113
110
|
throw this._error;
|
|
114
111
|
}
|
|
115
112
|
if (this._error !== undefined) {
|
|
116
|
-
throw new
|
|
113
|
+
throw new RoomServerException(`sync stream failed: ${String(this._error)}`);
|
|
117
114
|
}
|
|
118
115
|
if (this._inputClosed) {
|
|
119
|
-
throw new
|
|
116
|
+
throw new RoomServerException("attempted to sync to a document that is not connected");
|
|
120
117
|
}
|
|
121
|
-
this._enqueueChunk(new
|
|
118
|
+
this._enqueueChunk(new BinaryContent({
|
|
122
119
|
data,
|
|
123
120
|
headers: { kind: "sync" },
|
|
124
121
|
}));
|
|
@@ -128,7 +125,7 @@ class SyncOpenStreamState {
|
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
127
|
SyncOpenStreamState.INPUT_STREAM_CLOSE = Symbol("sync-open-input-close");
|
|
131
|
-
class SyncClient extends
|
|
128
|
+
export class SyncClient extends EventEmitter {
|
|
132
129
|
constructor({ room }) {
|
|
133
130
|
super();
|
|
134
131
|
this._connectingDocuments = {};
|
|
@@ -141,7 +138,7 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
141
138
|
}
|
|
142
139
|
start() {
|
|
143
140
|
if (this._started) {
|
|
144
|
-
throw new
|
|
141
|
+
throw new RoomServerException("client already started");
|
|
145
142
|
}
|
|
146
143
|
this._started = true;
|
|
147
144
|
}
|
|
@@ -151,7 +148,7 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
151
148
|
streamState.closeInputStream();
|
|
152
149
|
}
|
|
153
150
|
for (const doc of Object.values(this._connectedDocuments)) {
|
|
154
|
-
|
|
151
|
+
unregisterDocument(doc.ref.id);
|
|
155
152
|
}
|
|
156
153
|
Object.keys(this._documentStreams).forEach((key) => delete this._documentStreams[key]);
|
|
157
154
|
Object.keys(this._documentConfigs).forEach((key) => delete this._documentConfigs[key]);
|
|
@@ -161,7 +158,7 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
161
158
|
this._started = false;
|
|
162
159
|
}
|
|
163
160
|
_unexpectedResponseError(operation) {
|
|
164
|
-
return new
|
|
161
|
+
return new RoomServerException(`unexpected return type from sync.${operation}`);
|
|
165
162
|
}
|
|
166
163
|
async _invoke(operation, input) {
|
|
167
164
|
return await this.room.invoke({
|
|
@@ -172,7 +169,7 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
172
169
|
}
|
|
173
170
|
_applySyncPayload(rc, payload) {
|
|
174
171
|
if (payload.length > 0) {
|
|
175
|
-
|
|
172
|
+
applyBackendChanges(rc.ref.id, decoder.decode(payload));
|
|
176
173
|
}
|
|
177
174
|
if (!rc.ref.isSynchronized) {
|
|
178
175
|
rc.ref.setSynchronizedComplete();
|
|
@@ -202,7 +199,7 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
202
199
|
connected.count += 1;
|
|
203
200
|
return connected.ref;
|
|
204
201
|
}
|
|
205
|
-
const connecting = new
|
|
202
|
+
const connecting = new Completer();
|
|
206
203
|
this._connectingDocuments[normalizedPath] = connecting.fut;
|
|
207
204
|
try {
|
|
208
205
|
const config = {
|
|
@@ -216,8 +213,8 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
216
213
|
vector: null,
|
|
217
214
|
initialJson: initialJson ?? null,
|
|
218
215
|
});
|
|
219
|
-
const resolvedSchema =
|
|
220
|
-
const doc = new
|
|
216
|
+
const resolvedSchema = MeshSchema.fromJson(openResult.stateHeaders.schema);
|
|
217
|
+
const doc = new MeshDocument({
|
|
221
218
|
schema: resolvedSchema,
|
|
222
219
|
sendChangesToBackend: (base64) => {
|
|
223
220
|
const currentStream = this._documentStreams[normalizedPath];
|
|
@@ -225,13 +222,13 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
225
222
|
return;
|
|
226
223
|
}
|
|
227
224
|
try {
|
|
228
|
-
currentStream.queueSync(
|
|
225
|
+
currentStream.queueSync(encoder.encode(base64));
|
|
229
226
|
}
|
|
230
227
|
catch {
|
|
231
228
|
}
|
|
232
229
|
},
|
|
233
230
|
});
|
|
234
|
-
const rc = new
|
|
231
|
+
const rc = new RefCount(doc);
|
|
235
232
|
this._connectedDocuments[normalizedPath] = rc;
|
|
236
233
|
this._documentConfigs[normalizedPath] = config;
|
|
237
234
|
this._documentStreams[normalizedPath] = openResult.streamState;
|
|
@@ -259,7 +256,7 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
259
256
|
const normalizedPath = normalizeSyncPath(path);
|
|
260
257
|
const rc = this._connectedDocuments[normalizedPath];
|
|
261
258
|
if (rc == null) {
|
|
262
|
-
throw new
|
|
259
|
+
throw new RoomServerException(`Not connected to ${normalizedPath}`);
|
|
263
260
|
}
|
|
264
261
|
rc.count -= 1;
|
|
265
262
|
if (rc.count === 0) {
|
|
@@ -274,11 +271,11 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
274
271
|
await streamState.wait();
|
|
275
272
|
}
|
|
276
273
|
finally {
|
|
277
|
-
|
|
274
|
+
unregisterDocument(rc.ref.id);
|
|
278
275
|
}
|
|
279
276
|
}
|
|
280
277
|
else {
|
|
281
|
-
|
|
278
|
+
unregisterDocument(rc.ref.id);
|
|
282
279
|
}
|
|
283
280
|
})();
|
|
284
281
|
this._closingDocuments[normalizedPath] = closeFuture;
|
|
@@ -296,11 +293,11 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
296
293
|
async sync(path, data) {
|
|
297
294
|
const normalizedPath = normalizeSyncPath(path);
|
|
298
295
|
if (this._connectedDocuments[normalizedPath] == null) {
|
|
299
|
-
throw new
|
|
296
|
+
throw new RoomServerException("attempted to sync to a document that is not connected");
|
|
300
297
|
}
|
|
301
298
|
const streamState = this._documentStreams[normalizedPath];
|
|
302
299
|
if (streamState == null) {
|
|
303
|
-
throw new
|
|
300
|
+
throw new RoomServerException("attempted to sync to a document that is not connected");
|
|
304
301
|
}
|
|
305
302
|
streamState.queueSync(data);
|
|
306
303
|
}
|
|
@@ -312,21 +309,21 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
312
309
|
return;
|
|
313
310
|
}
|
|
314
311
|
const chunk = next.value;
|
|
315
|
-
if (chunk instanceof
|
|
316
|
-
throw new
|
|
312
|
+
if (chunk instanceof ErrorContent) {
|
|
313
|
+
throw new RoomServerException(chunk.text, chunk.code);
|
|
317
314
|
}
|
|
318
|
-
if (chunk instanceof
|
|
315
|
+
if (chunk instanceof ControlContent) {
|
|
319
316
|
if (chunk.method === "close") {
|
|
320
317
|
return;
|
|
321
318
|
}
|
|
322
319
|
throw this._unexpectedResponseError("open");
|
|
323
320
|
}
|
|
324
|
-
if (!(chunk instanceof
|
|
321
|
+
if (!(chunk instanceof BinaryContent)) {
|
|
325
322
|
throw this._unexpectedResponseError("open");
|
|
326
323
|
}
|
|
327
324
|
const headers = parseSyncOpenOutputChunkHeaders(chunk.headers);
|
|
328
325
|
if (normalizeSyncPath(headers.path) !== path) {
|
|
329
|
-
throw new
|
|
326
|
+
throw new RoomServerException("sync.open stream returned a mismatched path");
|
|
330
327
|
}
|
|
331
328
|
this._applySyncPayload(rc, chunk.data);
|
|
332
329
|
}
|
|
@@ -355,18 +352,18 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
355
352
|
iterator = responseStream[Symbol.asyncIterator]();
|
|
356
353
|
const first = await iterator.next();
|
|
357
354
|
if (first.done || first.value === undefined) {
|
|
358
|
-
throw new
|
|
355
|
+
throw new RoomServerException("sync.open stream closed before the initial document state was returned");
|
|
359
356
|
}
|
|
360
357
|
const firstChunk = first.value;
|
|
361
|
-
if (firstChunk instanceof
|
|
362
|
-
throw new
|
|
358
|
+
if (firstChunk instanceof ErrorContent) {
|
|
359
|
+
throw new RoomServerException(firstChunk.text, firstChunk.code);
|
|
363
360
|
}
|
|
364
|
-
if (!(firstChunk instanceof
|
|
361
|
+
if (!(firstChunk instanceof BinaryContent)) {
|
|
365
362
|
throw this._unexpectedResponseError("open");
|
|
366
363
|
}
|
|
367
364
|
const stateHeaders = parseSyncOpenStateChunkHeaders(firstChunk.headers);
|
|
368
365
|
if (normalizeSyncPath(stateHeaders.path) !== path) {
|
|
369
|
-
throw new
|
|
366
|
+
throw new RoomServerException("sync.open stream returned a mismatched path");
|
|
370
367
|
}
|
|
371
368
|
return {
|
|
372
369
|
streamState,
|
|
@@ -421,4 +418,3 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
421
418
|
}
|
|
422
419
|
}
|
|
423
420
|
}
|
|
424
|
-
exports.SyncClient = SyncClient;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ToolContentSpec = void 0;
|
|
4
1
|
const SUPPORTED_TOOL_CONTENT_TYPES = new Set([
|
|
5
2
|
"binary",
|
|
6
3
|
"json",
|
|
@@ -12,7 +9,7 @@ const SUPPORTED_TOOL_CONTENT_TYPES = new Set([
|
|
|
12
9
|
function isRecord(value) {
|
|
13
10
|
return typeof value === "object" && value !== null;
|
|
14
11
|
}
|
|
15
|
-
class ToolContentSpec {
|
|
12
|
+
export class ToolContentSpec {
|
|
16
13
|
constructor({ types, stream = false, schema, }) {
|
|
17
14
|
if (!Array.isArray(types) || types.length === 0) {
|
|
18
15
|
throw new Error("ToolContentSpec.types must contain at least one supported type");
|
|
@@ -66,4 +63,3 @@ class ToolContentSpec {
|
|
|
66
63
|
return new ToolContentSpec({ types, stream, schema });
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
|
-
exports.ToolContentSpec = ToolContentSpec;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ConnectorRef, OAuthClientConfig, ServiceSpec } from "./meshagent-client";
|
|
2
|
-
import type { RemoteParticipant } from "./participant";
|
|
3
|
-
import type { RoomClient } from "./room-client";
|
|
1
|
+
import type { ConnectorRef, OAuthClientConfig, ServiceSpec } from "./meshagent-client.js";
|
|
2
|
+
import type { RemoteParticipant } from "./participant.js";
|
|
3
|
+
import type { RoomClient } from "./room-client.js";
|
|
4
4
|
export declare class MCPHeader {
|
|
5
5
|
readonly name: string;
|
|
6
6
|
readonly value: string;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAIConnectors = exports.Connector = exports.MCPServer = exports.MCPHeader = void 0;
|
|
4
|
-
exports.mcpConnectorsFromRoomServices = mcpConnectorsFromRoomServices;
|
|
5
|
-
class MCPHeader {
|
|
1
|
+
export class MCPHeader {
|
|
6
2
|
constructor({ name, value }) {
|
|
7
3
|
this.name = name;
|
|
8
4
|
this.value = value;
|
|
@@ -20,7 +16,6 @@ class MCPHeader {
|
|
|
20
16
|
};
|
|
21
17
|
}
|
|
22
18
|
}
|
|
23
|
-
exports.MCPHeader = MCPHeader;
|
|
24
19
|
function isRecord(value) {
|
|
25
20
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26
21
|
}
|
|
@@ -44,7 +39,7 @@ function parseMcpHeaders(value) {
|
|
|
44
39
|
}
|
|
45
40
|
throw new Error("MCPServer.headers must be a header list or object");
|
|
46
41
|
}
|
|
47
|
-
class MCPServer {
|
|
42
|
+
export class MCPServer {
|
|
48
43
|
constructor({ serverLabel, authorization, serverUrl, allowedTools, headers, requireApproval, alwaysRequireApproval, neverRequireApproval, openaiConnectorId, }) {
|
|
49
44
|
this.serverLabel = serverLabel;
|
|
50
45
|
this.authorization = authorization ?? undefined;
|
|
@@ -137,8 +132,7 @@ class MCPServer {
|
|
|
137
132
|
});
|
|
138
133
|
}
|
|
139
134
|
}
|
|
140
|
-
|
|
141
|
-
class Connector {
|
|
135
|
+
export class Connector {
|
|
142
136
|
constructor({ name, server, oauth, }) {
|
|
143
137
|
this.name = name;
|
|
144
138
|
this.server = server;
|
|
@@ -206,7 +200,6 @@ class Connector {
|
|
|
206
200
|
});
|
|
207
201
|
}
|
|
208
202
|
}
|
|
209
|
-
exports.Connector = Connector;
|
|
210
203
|
function headersFromEndpointSpec(headers) {
|
|
211
204
|
if (headers == null || Object.keys(headers).length === 0) {
|
|
212
205
|
return undefined;
|
|
@@ -259,7 +252,7 @@ function roomServiceMcpServerUrl({ service, port, endpoint, }) {
|
|
|
259
252
|
const fragment = baseUrl.hash;
|
|
260
253
|
return `${baseUrl.protocol}//${userInfo}${bracketIpv6Host(baseUrl.hostname)}:${portValue}${joinedPath}${query}${fragment}`;
|
|
261
254
|
}
|
|
262
|
-
function mcpConnectorsFromRoomServices({ services, agentName, }) {
|
|
255
|
+
export function mcpConnectorsFromRoomServices({ services, agentName, }) {
|
|
263
256
|
const connectors = [];
|
|
264
257
|
for (const service of services) {
|
|
265
258
|
const filter = service.metadata.annotations?.["meshagent.agent.filter"];
|
|
@@ -294,9 +287,8 @@ function getEnvValue(name) {
|
|
|
294
287
|
}
|
|
295
288
|
return process.env?.[name] ?? "";
|
|
296
289
|
}
|
|
297
|
-
class OpenAIConnectors {
|
|
290
|
+
export class OpenAIConnectors {
|
|
298
291
|
}
|
|
299
|
-
exports.OpenAIConnectors = OpenAIConnectors;
|
|
300
292
|
OpenAIConnectors.dropbox = new Connector({
|
|
301
293
|
name: "Dropbox",
|
|
302
294
|
server: new MCPServer({ serverLabel: "Dropbox", openaiConnectorId: "connector_dropbox" }),
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.unpackMessage = unpackMessage;
|
|
7
|
-
exports.packMessage = packMessage;
|
|
8
|
-
exports.mergeUint8Arrays = mergeUint8Arrays;
|
|
9
|
-
const text_encoding_1 = require("@kayahr/text-encoding");
|
|
10
|
-
const encoder = new text_encoding_1.TextEncoder();
|
|
11
|
-
exports.encoder = encoder;
|
|
12
|
-
const decoder = new text_encoding_1.TextDecoder();
|
|
13
|
-
exports.decoder = decoder;
|
|
14
|
-
function splitMessagePayload(packet) {
|
|
1
|
+
import { TextDecoder, TextEncoder } from "@kayahr/text-encoding";
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
const decoder = new TextDecoder();
|
|
4
|
+
export { encoder, decoder };
|
|
5
|
+
export function splitMessagePayload(packet) {
|
|
15
6
|
const dataView = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
16
7
|
const headerSize = dataView.getUint32(4, false) + dataView.getUint32(0, false) * Math.pow(2, 32);
|
|
17
8
|
return packet.subarray(8 + headerSize, packet.length);
|
|
18
9
|
}
|
|
19
|
-
function splitMessageHeader(packet) {
|
|
10
|
+
export function splitMessageHeader(packet) {
|
|
20
11
|
const dataView = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
21
12
|
const headerSize = dataView.getUint32(4, false) + dataView.getUint32(0, false) * Math.pow(2, 32);
|
|
22
13
|
const payload = packet.subarray(8, 8 + headerSize);
|
|
23
14
|
return decoder.decode(payload);
|
|
24
15
|
}
|
|
25
|
-
function unpackMessage(packet) {
|
|
16
|
+
export function unpackMessage(packet) {
|
|
26
17
|
return [JSON.parse(splitMessageHeader(packet)), splitMessagePayload(packet)];
|
|
27
18
|
}
|
|
28
|
-
function packMessage(request, data) {
|
|
19
|
+
export function packMessage(request, data) {
|
|
29
20
|
const jsonMessage = encoder.encode(JSON.stringify(request));
|
|
30
21
|
const size = jsonMessage.length;
|
|
31
22
|
const header = new Uint8Array(4 * 2);
|
|
@@ -34,7 +25,7 @@ function packMessage(request, data) {
|
|
|
34
25
|
dataView.setUint32(4, size & 0xffffffff, false);
|
|
35
26
|
return mergeUint8Arrays(header, jsonMessage, data ?? new Uint8Array(0));
|
|
36
27
|
}
|
|
37
|
-
function mergeUint8Arrays(...arrays) {
|
|
28
|
+
export function mergeUint8Arrays(...arrays) {
|
|
38
29
|
const totalSize = arrays.reduce((acc, e) => acc + e.length, 0);
|
|
39
30
|
const merged = new Uint8Array(totalSize);
|
|
40
31
|
arrays.forEach((array, i, arrays) => {
|
|
@@ -45,10 +36,9 @@ function mergeUint8Arrays(...arrays) {
|
|
|
45
36
|
});
|
|
46
37
|
return merged;
|
|
47
38
|
}
|
|
48
|
-
class RefCount {
|
|
39
|
+
export class RefCount {
|
|
49
40
|
constructor(ref) {
|
|
50
41
|
this.ref = ref;
|
|
51
42
|
this.count = 1;
|
|
52
43
|
}
|
|
53
44
|
}
|
|
54
|
-
exports.RefCount = RefCount;
|
package/dist/esm/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RoomClient } from "./room-client";
|
|
2
|
-
import type { Content } from "./response";
|
|
3
|
-
import { ToolInput, type ToolCallOutput } from "./agent";
|
|
4
|
-
import { ToolContentSpec } from "./tool-content-type";
|
|
1
|
+
import { RoomClient } from "./room-client.js";
|
|
2
|
+
import type { Content } from "./response.js";
|
|
3
|
+
import { ToolInput, type ToolCallOutput } from "./agent.js";
|
|
4
|
+
import { ToolContentSpec } from "./tool-content-type.js";
|
|
5
5
|
export declare class ToolDescription {
|
|
6
6
|
title: string;
|
|
7
7
|
name: string;
|