@meshagent/meshagent 0.47.1 → 0.49.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 +16 -0
- 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 +37 -5
- package/dist/browser/meshagent-client.js +25 -7
- package/dist/browser/messaging-client.js +9 -2
- package/dist/browser/mounts-client.d.ts +21 -0
- package/dist/browser/mounts-client.js +82 -0
- package/dist/browser/room-client.d.ts +4 -0
- package/dist/browser/room-client.js +13 -3
- 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 +37 -5
- package/dist/esm/meshagent-client.js +25 -7
- package/dist/esm/messaging-client.js +9 -2
- package/dist/esm/mounts-client.d.ts +21 -0
- package/dist/esm/mounts-client.js +78 -0
- package/dist/esm/room-client.d.ts +4 -0
- package/dist/esm/room-client.js +13 -3
- 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 +37 -5
- package/dist/node/meshagent-client.js +25 -7
- package/dist/node/messaging-client.js +9 -2
- package/dist/node/mounts-client.d.ts +21 -0
- package/dist/node/mounts-client.js +82 -0
- package/dist/node/room-client.d.ts +4 -0
- package/dist/node/room-client.js +13 -3
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RoomClient } from "./room-client.js";
|
|
2
|
+
export interface MountedVolumeConsumer {
|
|
3
|
+
kind: "room" | "container";
|
|
4
|
+
containerId?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface MountedVolume {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
description: string;
|
|
11
|
+
metadata: Record<string, unknown>;
|
|
12
|
+
annotations: Record<string, string>;
|
|
13
|
+
storageClass: "standard" | "juice" | "zerofs";
|
|
14
|
+
maxSizeMb?: number;
|
|
15
|
+
consumers: MountedVolumeConsumer[];
|
|
16
|
+
}
|
|
17
|
+
export declare class MountsClient {
|
|
18
|
+
private readonly room;
|
|
19
|
+
constructor(room: RoomClient);
|
|
20
|
+
list(): Promise<MountedVolume[]>;
|
|
21
|
+
}
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -76,6 +78,7 @@ export declare class RoomClient {
|
|
|
76
78
|
private _localParticipantReady;
|
|
77
79
|
private _connected;
|
|
78
80
|
private _closing;
|
|
81
|
+
private _dismissed;
|
|
79
82
|
private _localParticipant;
|
|
80
83
|
private _lifecycleTask;
|
|
81
84
|
private _terminalState;
|
|
@@ -167,6 +170,7 @@ export declare class RoomClient {
|
|
|
167
170
|
private _retryProtocolConnection;
|
|
168
171
|
private _reconnect;
|
|
169
172
|
private _connectionLifecycle;
|
|
173
|
+
_dismiss(): void;
|
|
170
174
|
dispose(): void;
|
|
171
175
|
_sendProtocolNowait({ type, data, label, messageId, expectResponse, }: {
|
|
172
176
|
type: string;
|
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");
|
|
@@ -224,6 +225,7 @@ class RoomClient {
|
|
|
224
225
|
this._localParticipantReady = new completer_js_1.Completer();
|
|
225
226
|
this._connected = false;
|
|
226
227
|
this._closing = false;
|
|
228
|
+
this._dismissed = false;
|
|
227
229
|
this._localParticipant = null;
|
|
228
230
|
this._lifecycleTask = null;
|
|
229
231
|
this._terminalState = null;
|
|
@@ -261,6 +263,7 @@ class RoomClient {
|
|
|
261
263
|
this.containers = new containers_client_js_1.ContainersClient({ room: this });
|
|
262
264
|
this.memory = new memory_client_js_1.MemoryClient({ room: this });
|
|
263
265
|
this.services = new services_client_js_1.ServicesClient({ room: this });
|
|
266
|
+
this.mounts = new mounts_client_js_1.MountsClient(this);
|
|
264
267
|
}
|
|
265
268
|
static withIAP({ url = "./.well-known/meshagent/room/connect", reconnectTimeout = null, } = {}) {
|
|
266
269
|
return new RoomClient({
|
|
@@ -880,7 +883,7 @@ class RoomClient {
|
|
|
880
883
|
const deadline = this._reconnectTimeout == null ? null : Date.now() + this._reconnectTimeout;
|
|
881
884
|
let firstAttempt = true;
|
|
882
885
|
let retryCount = 0;
|
|
883
|
-
while (!this._closing) {
|
|
886
|
+
while (!this._closing && !this._dismissed) {
|
|
884
887
|
if (firstAttempt) {
|
|
885
888
|
firstAttempt = false;
|
|
886
889
|
if (this._reconnectTimeout == null) {
|
|
@@ -1011,7 +1014,7 @@ class RoomClient {
|
|
|
1011
1014
|
this._completeRoomClosed();
|
|
1012
1015
|
return;
|
|
1013
1016
|
}
|
|
1014
|
-
if (closeKind !== protocol_js_1.ProtocolCloseKind.ERROR) {
|
|
1017
|
+
if (closeKind !== protocol_js_1.ProtocolCloseKind.ERROR || this._dismissed) {
|
|
1015
1018
|
this._setTerminalState({ state });
|
|
1016
1019
|
}
|
|
1017
1020
|
this._markDisconnected({ reason: closeReason, kind: closeKind });
|
|
@@ -1023,7 +1026,7 @@ class RoomClient {
|
|
|
1023
1026
|
this.messaging._onRoomDisconnect({ reason: closeReason });
|
|
1024
1027
|
await this._failPendingWork({ state });
|
|
1025
1028
|
await this._closeProtocol(protocol);
|
|
1026
|
-
if (closeKind === protocol_js_1.ProtocolCloseKind.ERROR) {
|
|
1029
|
+
if (closeKind === protocol_js_1.ProtocolCloseKind.ERROR && !this._dismissed) {
|
|
1027
1030
|
if (this._reconnectTimeout === 0) {
|
|
1028
1031
|
if (closeReason == null) {
|
|
1029
1032
|
console.warn("room connection lost; automatic reconnect disabled");
|
|
@@ -1052,6 +1055,13 @@ class RoomClient {
|
|
|
1052
1055
|
return;
|
|
1053
1056
|
}
|
|
1054
1057
|
}
|
|
1058
|
+
_dismiss() {
|
|
1059
|
+
if (this._closing || this._dismissed) {
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
this._dismissed = true;
|
|
1063
|
+
this._protocolInstance.dispose();
|
|
1064
|
+
}
|
|
1055
1065
|
dispose() {
|
|
1056
1066
|
this._closing = true;
|
|
1057
1067
|
this._markDisconnected({
|