@meshagent/meshagent 0.47.0 → 0.48.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 +12 -0
- package/dist/browser/agent.js +6 -6
- package/dist/browser/containers-client.d.ts +1 -0
- package/dist/browser/containers-client.js +34 -0
- package/dist/browser/entrypoint.d.ts +1 -0
- package/dist/browser/entrypoint.js +3 -3
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/meshagent-client.d.ts +9 -1
- package/dist/browser/meshagent-client.js +1 -0
- package/dist/browser/messaging-client.d.ts +72 -1
- package/dist/browser/messaging-client.js +302 -1
- package/dist/browser/mounts-client.d.ts +21 -0
- package/dist/browser/mounts-client.js +82 -0
- package/dist/browser/participant-token.d.ts +1 -0
- package/dist/browser/participant-token.js +3 -0
- package/dist/browser/room-client.d.ts +4 -1
- package/dist/browser/room-client.js +27 -12
- package/dist/esm/agent.js +6 -6
- package/dist/esm/containers-client.d.ts +1 -0
- package/dist/esm/containers-client.js +34 -0
- package/dist/esm/entrypoint.d.ts +1 -0
- package/dist/esm/entrypoint.js +3 -3
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/meshagent-client.d.ts +9 -1
- package/dist/esm/meshagent-client.js +1 -0
- package/dist/esm/messaging-client.d.ts +72 -1
- package/dist/esm/messaging-client.js +301 -1
- package/dist/esm/mounts-client.d.ts +21 -0
- package/dist/esm/mounts-client.js +78 -0
- package/dist/esm/participant-token.d.ts +1 -0
- package/dist/esm/participant-token.js +3 -0
- package/dist/esm/room-client.d.ts +4 -1
- package/dist/esm/room-client.js +27 -12
- package/dist/node/agent.js +6 -6
- package/dist/node/containers-client.d.ts +1 -0
- package/dist/node/containers-client.js +34 -0
- package/dist/node/entrypoint.d.ts +1 -0
- package/dist/node/entrypoint.js +3 -3
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/meshagent-client.d.ts +9 -1
- package/dist/node/meshagent-client.js +1 -0
- package/dist/node/messaging-client.d.ts +72 -1
- package/dist/node/messaging-client.js +302 -1
- package/dist/node/mounts-client.d.ts +21 -0
- package/dist/node/mounts-client.js +82 -0
- package/dist/node/participant-token.d.ts +1 -0
- package/dist/node/participant-token.js +3 -0
- package/dist/node/room-client.d.ts +4 -1
- package/dist/node/room-client.js +27 -12
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MountsClient = void 0;
|
|
4
|
+
const response_js_1 = require("./response.js");
|
|
5
|
+
const room_server_client_js_1 = require("./room-server-client.js");
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function parseMountedVolume(value) {
|
|
10
|
+
if (!isRecord(value)
|
|
11
|
+
|| typeof value["id"] !== "string"
|
|
12
|
+
|| typeof value["name"] !== "string"
|
|
13
|
+
|| typeof value["required"] !== "boolean") {
|
|
14
|
+
throw new room_server_client_js_1.RoomServerException("unexpected return type from mounts.list");
|
|
15
|
+
}
|
|
16
|
+
const metadata = isRecord(value["metadata"]) ? value["metadata"] : {};
|
|
17
|
+
const rawAnnotations = isRecord(value["annotations"]) ? value["annotations"] : {};
|
|
18
|
+
const annotations = {};
|
|
19
|
+
for (const [key, item] of Object.entries(rawAnnotations)) {
|
|
20
|
+
if (typeof item === "string") {
|
|
21
|
+
annotations[key] = item;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const rawConsumers = value["consumers"] ?? [];
|
|
25
|
+
if (!Array.isArray(rawConsumers)) {
|
|
26
|
+
throw new room_server_client_js_1.RoomServerException("unexpected return type from mounts.list");
|
|
27
|
+
}
|
|
28
|
+
const consumers = rawConsumers.map((consumer) => {
|
|
29
|
+
if (!isRecord(consumer)
|
|
30
|
+
|| (consumer["kind"] !== "room" && consumer["kind"] !== "container")
|
|
31
|
+
|| (consumer["kind"] === "container" && typeof consumer["container_id"] !== "string")
|
|
32
|
+
|| (consumer["kind"] === "room" && consumer["container_id"] !== undefined)) {
|
|
33
|
+
throw new room_server_client_js_1.RoomServerException("unexpected return type from mounts.list");
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
kind: consumer["kind"],
|
|
37
|
+
containerId: typeof consumer["container_id"] === "string"
|
|
38
|
+
? consumer["container_id"]
|
|
39
|
+
: undefined,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
const storageClass = value["storage_class"] ?? "standard";
|
|
43
|
+
if (storageClass !== "standard" && storageClass !== "juice" && storageClass !== "zerofs") {
|
|
44
|
+
throw new room_server_client_js_1.RoomServerException("unexpected return type from mounts.list");
|
|
45
|
+
}
|
|
46
|
+
const maxSizeMb = value["max_size_mb"];
|
|
47
|
+
if (maxSizeMb !== undefined && (typeof maxSizeMb !== "number" || !Number.isInteger(maxSizeMb) || maxSizeMb <= 0)) {
|
|
48
|
+
throw new room_server_client_js_1.RoomServerException("unexpected return type from mounts.list");
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
id: value["id"],
|
|
52
|
+
name: value["name"],
|
|
53
|
+
required: value["required"],
|
|
54
|
+
description: typeof value["description"] === "string" ? value["description"] : "",
|
|
55
|
+
metadata,
|
|
56
|
+
annotations,
|
|
57
|
+
storageClass,
|
|
58
|
+
maxSizeMb,
|
|
59
|
+
consumers,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
class MountsClient {
|
|
63
|
+
constructor(room) {
|
|
64
|
+
this.room = room;
|
|
65
|
+
}
|
|
66
|
+
async list() {
|
|
67
|
+
const response = await this.room.invokeContent({
|
|
68
|
+
toolkit: "mounts",
|
|
69
|
+
tool: "list",
|
|
70
|
+
input: {},
|
|
71
|
+
});
|
|
72
|
+
if (!(response instanceof response_js_1.JsonContent)) {
|
|
73
|
+
throw new room_server_client_js_1.RoomServerException("unexpected return type from mounts.list");
|
|
74
|
+
}
|
|
75
|
+
const volumes = response.json["volumes"];
|
|
76
|
+
if (!Array.isArray(volumes)) {
|
|
77
|
+
throw new room_server_client_js_1.RoomServerException("unexpected return type from mounts.list");
|
|
78
|
+
}
|
|
79
|
+
return volumes.map(parseMountedVolume);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.MountsClient = MountsClient;
|
|
@@ -404,6 +404,7 @@ export declare class ParticipantToken {
|
|
|
404
404
|
addTunnelGrant(ports: number[]): void;
|
|
405
405
|
addRoleGrant(role: string): void;
|
|
406
406
|
addRoomGrant(roomName: string): void;
|
|
407
|
+
addSiteGrant(roomName: string): void;
|
|
407
408
|
addApiGrant(grant: ApiScope): void;
|
|
408
409
|
grantScope(name: string): string | ApiScope | undefined;
|
|
409
410
|
getApiGrant(): ApiScope | undefined;
|
|
@@ -1323,6 +1323,9 @@ class ParticipantToken {
|
|
|
1323
1323
|
addRoomGrant(roomName) {
|
|
1324
1324
|
this.grants.push(new ParticipantGrant({ name: "room", scope: roomName }));
|
|
1325
1325
|
}
|
|
1326
|
+
addSiteGrant(roomName) {
|
|
1327
|
+
this.grants.push(new ParticipantGrant({ name: "site", scope: roomName }));
|
|
1328
|
+
}
|
|
1326
1329
|
addApiGrant(grant) {
|
|
1327
1330
|
for (const existingGrant of this.grants) {
|
|
1328
1331
|
if (existingGrant.name === "api") {
|
|
@@ -4,6 +4,7 @@ import { DeveloperClient } from "./developer-client.js";
|
|
|
4
4
|
import { type EventHandler, type EventName } from "./event-emitter.js";
|
|
5
5
|
import { MessagingClient } from "./messaging-client.js";
|
|
6
6
|
import { MemoryClient } from "./memory-client.js";
|
|
7
|
+
import { MountsClient } from "./mounts-client.js";
|
|
7
8
|
import { LocalParticipant } from "./participant.js";
|
|
8
9
|
import { Protocol, ProtocolCloseKind, type MessageHandler, type ProtocolFactory } from "./protocol.js";
|
|
9
10
|
import { QueuesClient } from "./queues-client.js";
|
|
@@ -59,6 +60,7 @@ export declare class RoomClient {
|
|
|
59
60
|
readonly containers: ContainersClient;
|
|
60
61
|
readonly memory: MemoryClient;
|
|
61
62
|
readonly services: ServicesClient;
|
|
63
|
+
readonly mounts: MountsClient;
|
|
62
64
|
_protocolInstance: Protocol;
|
|
63
65
|
_entered: boolean;
|
|
64
66
|
_allowDisconnectedRequests: boolean;
|
|
@@ -190,6 +192,7 @@ export declare class RoomClient {
|
|
|
190
192
|
_sendLocalAttributesNowait(attributes: Record<string, unknown>): void;
|
|
191
193
|
_resendLocalAttributesNowait(): void;
|
|
192
194
|
sendRequest(type: string, request: RequestHeader, data?: Uint8Array, afterSend?: () => void): Promise<Content>;
|
|
195
|
+
private _dispatchRequest;
|
|
193
196
|
call(params: {
|
|
194
197
|
name: string;
|
|
195
198
|
url: string;
|
|
@@ -249,7 +252,7 @@ export declare class RoomClient {
|
|
|
249
252
|
participantId?: string;
|
|
250
253
|
onBehalfOfId?: string;
|
|
251
254
|
}): Promise<AsyncIterable<Content>>;
|
|
252
|
-
private
|
|
255
|
+
private _dispatchToolCallRequestChunk;
|
|
253
256
|
private _streamInvokeToolRequestChunks;
|
|
254
257
|
private _decodeToolCallContent;
|
|
255
258
|
private _handleToolCallResponseChunk;
|
package/dist/node/room-client.js
CHANGED
|
@@ -8,6 +8,7 @@ const developer_client_js_1 = require("./developer-client.js");
|
|
|
8
8
|
const event_emitter_js_1 = require("./event-emitter.js");
|
|
9
9
|
const messaging_client_js_1 = require("./messaging-client.js");
|
|
10
10
|
const memory_client_js_1 = require("./memory-client.js");
|
|
11
|
+
const mounts_client_js_1 = require("./mounts-client.js");
|
|
11
12
|
const participant_js_1 = require("./participant.js");
|
|
12
13
|
const protocol_js_1 = require("./protocol.js");
|
|
13
14
|
const queues_client_js_1 = require("./queues-client.js");
|
|
@@ -261,6 +262,7 @@ class RoomClient {
|
|
|
261
262
|
this.containers = new containers_client_js_1.ContainersClient({ room: this });
|
|
262
263
|
this.memory = new memory_client_js_1.MemoryClient({ room: this });
|
|
263
264
|
this.services = new services_client_js_1.ServicesClient({ room: this });
|
|
265
|
+
this.mounts = new mounts_client_js_1.MountsClient(this);
|
|
264
266
|
}
|
|
265
267
|
static withIAP({ url = "./.well-known/meshagent/room/connect", reconnectTimeout = null, } = {}) {
|
|
266
268
|
return new RoomClient({
|
|
@@ -1147,6 +1149,11 @@ class RoomClient {
|
|
|
1147
1149
|
this._sendLocalAttributesNowait(attributes);
|
|
1148
1150
|
}
|
|
1149
1151
|
async sendRequest(type, request, data, afterSend) {
|
|
1152
|
+
const response = this._dispatchRequest(type, request, data);
|
|
1153
|
+
afterSend?.();
|
|
1154
|
+
return await response;
|
|
1155
|
+
}
|
|
1156
|
+
_dispatchRequest(type, request, data) {
|
|
1150
1157
|
this._raiseIfTerminal();
|
|
1151
1158
|
if (this._entered && !this._connected && !this._allowDisconnectedRequests) {
|
|
1152
1159
|
throw this._disconnectedError({ baseMessage: "room connection is disconnected" });
|
|
@@ -1155,9 +1162,8 @@ class RoomClient {
|
|
|
1155
1162
|
const completer = new completer_js_1.Completer();
|
|
1156
1163
|
this._pendingRequests.set(requestId, completer);
|
|
1157
1164
|
try {
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
return await completer.fut;
|
|
1165
|
+
this._protocolInstance.sendNowait(type, (0, utils_js_1.packMessage)(request, data), { id: requestId });
|
|
1166
|
+
return completer.fut;
|
|
1161
1167
|
}
|
|
1162
1168
|
catch (error) {
|
|
1163
1169
|
this._pendingRequests.delete(requestId);
|
|
@@ -1263,7 +1269,6 @@ class RoomClient {
|
|
|
1263
1269
|
let requestTask;
|
|
1264
1270
|
if (params.streamInput === true) {
|
|
1265
1271
|
request["arguments"] = { type: "control", method: "open" };
|
|
1266
|
-
requestTask = this._streamInvokeToolRequestChunks(toolCallId, params.input);
|
|
1267
1272
|
}
|
|
1268
1273
|
else {
|
|
1269
1274
|
const input = params.input;
|
|
@@ -1280,9 +1285,14 @@ class RoomClient {
|
|
|
1280
1285
|
if (params.onBehalfOfId != null) {
|
|
1281
1286
|
request["on_behalf_of_id"] = params.onBehalfOfId;
|
|
1282
1287
|
}
|
|
1288
|
+
const responseRequest = this._dispatchRequest("room.invoke_tool", request, requestData);
|
|
1289
|
+
params.afterSend?.();
|
|
1290
|
+
if (params.streamInput === true) {
|
|
1291
|
+
requestTask = this._streamInvokeToolRequestChunks(toolCallId, params.input);
|
|
1292
|
+
}
|
|
1283
1293
|
try {
|
|
1284
1294
|
const response = await Promise.race([
|
|
1285
|
-
|
|
1295
|
+
responseRequest,
|
|
1286
1296
|
preOpenError.fut,
|
|
1287
1297
|
]);
|
|
1288
1298
|
this._toolCallPreOpenErrors.delete(toolCallId);
|
|
@@ -1337,9 +1347,10 @@ class RoomClient {
|
|
|
1337
1347
|
if (params.onBehalfOfId != null) {
|
|
1338
1348
|
request["on_behalf_of_id"] = params.onBehalfOfId;
|
|
1339
1349
|
}
|
|
1350
|
+
const responseRequest = this._dispatchRequest("room.invoke_tool", request);
|
|
1340
1351
|
const requestTask = this._streamInvokeToolRequestChunks(toolCallId, params.input);
|
|
1341
1352
|
try {
|
|
1342
|
-
const response = await
|
|
1353
|
+
const response = await responseRequest;
|
|
1343
1354
|
await requestTask;
|
|
1344
1355
|
if (response instanceof response_js_1.ControlContent && response.method === "open") {
|
|
1345
1356
|
throw new room_server_client_js_1.RoomServerException(`unexpected return type from ${params.toolkit}.${params.tool}`);
|
|
@@ -1370,6 +1381,7 @@ class RoomClient {
|
|
|
1370
1381
|
if (params.onBehalfOfId != null) {
|
|
1371
1382
|
request["on_behalf_of_id"] = params.onBehalfOfId;
|
|
1372
1383
|
}
|
|
1384
|
+
const responseRequest = this._dispatchRequest("room.invoke_tool", request);
|
|
1373
1385
|
const requestTask = this._streamInvokeToolRequestChunks(toolCallId, params.input);
|
|
1374
1386
|
void requestTask.catch((error) => {
|
|
1375
1387
|
const stream = this._toolCallStreams.get(toolCallId);
|
|
@@ -1383,7 +1395,7 @@ class RoomClient {
|
|
|
1383
1395
|
let response;
|
|
1384
1396
|
try {
|
|
1385
1397
|
response = await Promise.race([
|
|
1386
|
-
|
|
1398
|
+
responseRequest,
|
|
1387
1399
|
preOpenError.fut,
|
|
1388
1400
|
]);
|
|
1389
1401
|
}
|
|
@@ -1405,24 +1417,27 @@ class RoomClient {
|
|
|
1405
1417
|
},
|
|
1406
1418
|
};
|
|
1407
1419
|
}
|
|
1408
|
-
|
|
1420
|
+
_dispatchToolCallRequestChunk(toolCallId, chunk) {
|
|
1421
|
+
this._raiseIfTerminal();
|
|
1422
|
+
if (this._entered && !this._connected && !this._allowDisconnectedRequests) {
|
|
1423
|
+
throw this._disconnectedError({ baseMessage: "room connection is disconnected" });
|
|
1424
|
+
}
|
|
1409
1425
|
const packed = chunk.pack();
|
|
1410
1426
|
const request = {
|
|
1411
1427
|
tool_call_id: toolCallId,
|
|
1412
1428
|
chunk: JSON.parse((0, utils_js_1.splitMessageHeader)(packed)),
|
|
1413
1429
|
};
|
|
1414
1430
|
const payload = (0, utils_js_1.splitMessagePayload)(packed);
|
|
1415
|
-
|
|
1431
|
+
this._protocolInstance.sendNowait("room.tool_call_request_chunk", (0, utils_js_1.packMessage)(request, payload.length > 0 ? payload : undefined));
|
|
1416
1432
|
}
|
|
1417
1433
|
async _streamInvokeToolRequestChunks(toolCallId, input) {
|
|
1418
|
-
await Promise.resolve();
|
|
1419
1434
|
try {
|
|
1420
1435
|
for await (const item of input) {
|
|
1421
|
-
|
|
1436
|
+
this._dispatchToolCallRequestChunk(toolCallId, item);
|
|
1422
1437
|
}
|
|
1423
1438
|
}
|
|
1424
1439
|
finally {
|
|
1425
|
-
|
|
1440
|
+
this._dispatchToolCallRequestChunk(toolCallId, new response_js_1.ControlContent({ method: "close" }));
|
|
1426
1441
|
}
|
|
1427
1442
|
}
|
|
1428
1443
|
_decodeToolCallContent(params) {
|