@meshagent/meshagent 0.29.4 → 0.30.1
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 +9 -0
- package/dist/browser/agent-client.js +3 -28
- package/dist/browser/agent.js +6 -6
- package/dist/browser/containers-client.d.ts +125 -0
- package/dist/browser/containers-client.js +458 -0
- package/dist/browser/database-client.d.ts +42 -6
- package/dist/browser/database-client.js +610 -77
- package/dist/browser/developer-client.d.ts +2 -2
- package/dist/browser/developer-client.js +60 -15
- package/dist/browser/helpers.js +4 -3
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/lk-client.js +12 -3
- package/dist/browser/meshagent-client.d.ts +5 -0
- package/dist/browser/messaging-client.d.ts +1 -0
- package/dist/browser/messaging-client.js +52 -8
- package/dist/browser/queues-client.d.ts +2 -0
- package/dist/browser/queues-client.js +34 -7
- package/dist/browser/response.d.ts +28 -0
- package/dist/browser/response.js +76 -1
- package/dist/browser/room-client.d.ts +43 -1
- package/dist/browser/room-client.js +204 -0
- package/dist/browser/secrets-client.d.ts +1 -0
- package/dist/browser/secrets-client.js +32 -27
- package/dist/browser/storage-client.d.ts +22 -7
- package/dist/browser/storage-client.js +353 -15
- package/dist/browser/sync-client.d.ts +12 -13
- package/dist/browser/sync-client.js +263 -65
- package/dist/esm/agent-client.js +3 -28
- package/dist/esm/agent.js +6 -6
- package/dist/esm/containers-client.d.ts +125 -0
- package/dist/esm/containers-client.js +453 -0
- package/dist/esm/database-client.d.ts +42 -6
- package/dist/esm/database-client.js +611 -78
- package/dist/esm/developer-client.d.ts +2 -2
- package/dist/esm/developer-client.js +61 -16
- package/dist/esm/helpers.js +4 -3
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/lk-client.js +12 -3
- package/dist/esm/meshagent-client.d.ts +5 -0
- package/dist/esm/messaging-client.d.ts +1 -0
- package/dist/esm/messaging-client.js +52 -8
- package/dist/esm/queues-client.d.ts +2 -0
- package/dist/esm/queues-client.js +35 -8
- package/dist/esm/response.d.ts +28 -0
- package/dist/esm/response.js +73 -0
- package/dist/esm/room-client.d.ts +43 -1
- package/dist/esm/room-client.js +207 -3
- package/dist/esm/secrets-client.d.ts +1 -0
- package/dist/esm/secrets-client.js +33 -28
- package/dist/esm/storage-client.d.ts +22 -7
- package/dist/esm/storage-client.js +353 -15
- package/dist/esm/sync-client.d.ts +12 -13
- package/dist/esm/sync-client.js +263 -64
- package/dist/node/agent-client.js +3 -28
- package/dist/node/agent.js +6 -6
- package/dist/node/containers-client.d.ts +125 -0
- package/dist/node/containers-client.js +458 -0
- package/dist/node/database-client.d.ts +42 -6
- package/dist/node/database-client.js +610 -77
- package/dist/node/developer-client.d.ts +2 -2
- package/dist/node/developer-client.js +60 -15
- package/dist/node/helpers.js +4 -3
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/lk-client.js +12 -3
- package/dist/node/meshagent-client.d.ts +5 -0
- package/dist/node/messaging-client.d.ts +1 -0
- package/dist/node/messaging-client.js +52 -8
- package/dist/node/queues-client.d.ts +2 -0
- package/dist/node/queues-client.js +34 -7
- package/dist/node/response.d.ts +28 -0
- package/dist/node/response.js +76 -1
- package/dist/node/room-client.d.ts +43 -1
- package/dist/node/room-client.js +204 -0
- package/dist/node/secrets-client.d.ts +1 -0
- package/dist/node/secrets-client.js +32 -27
- package/dist/node/storage-client.d.ts +22 -7
- package/dist/node/storage-client.js +353 -15
- package/dist/node/sync-client.d.ts +12 -13
- package/dist/node/sync-client.js +263 -65
- package/package.json +1 -1
|
@@ -6,8 +6,8 @@ export declare class DeveloperClient extends EventEmitter<RoomLogEvent> {
|
|
|
6
6
|
constructor({ room }: {
|
|
7
7
|
room: RoomClient;
|
|
8
8
|
});
|
|
9
|
+
private _emitDeveloperLog;
|
|
9
10
|
private _handleDeveloperLog;
|
|
10
11
|
log(type: string, data: Record<string, any>): Promise<void>;
|
|
11
|
-
|
|
12
|
-
disable(): Promise<void>;
|
|
12
|
+
logs(): AsyncIterable<RoomLogEvent>;
|
|
13
13
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "./event-emitter";
|
|
2
|
-
import {
|
|
2
|
+
import { BinaryContent, ControlContent, ErrorContent } from "./response";
|
|
3
|
+
import { unpackMessage } from "./utils";
|
|
3
4
|
import { RoomLogEvent } from "./room-event";
|
|
4
5
|
export class DeveloperClient extends EventEmitter {
|
|
5
6
|
constructor({ room }) {
|
|
@@ -7,25 +8,69 @@ export class DeveloperClient extends EventEmitter {
|
|
|
7
8
|
this.client = room;
|
|
8
9
|
this.client.protocol.addHandler("developer.log", this._handleDeveloperLog.bind(this));
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const event = new RoomLogEvent({
|
|
13
|
-
type: rawJson["type"],
|
|
14
|
-
data: rawJson["data"],
|
|
15
|
-
});
|
|
11
|
+
_emitDeveloperLog(type, data) {
|
|
12
|
+
const event = new RoomLogEvent({ type, data });
|
|
16
13
|
this.client.emit(event);
|
|
17
14
|
this.emit("log", event);
|
|
18
15
|
}
|
|
19
|
-
async
|
|
20
|
-
const
|
|
21
|
-
|
|
16
|
+
async _handleDeveloperLog(protocol, messageId, type, bytes) {
|
|
17
|
+
const [rawJson, _] = unpackMessage(bytes || new Uint8Array());
|
|
18
|
+
this._emitDeveloperLog(rawJson["type"], rawJson["data"]);
|
|
22
19
|
}
|
|
23
|
-
async
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
async log(type, data) {
|
|
21
|
+
await this.client.invoke({
|
|
22
|
+
toolkit: "developer",
|
|
23
|
+
tool: "log",
|
|
24
|
+
input: { type, data },
|
|
25
|
+
});
|
|
26
26
|
}
|
|
27
|
-
async
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
async *logs() {
|
|
28
|
+
let resolveClosed;
|
|
29
|
+
const closed = new Promise((resolve) => {
|
|
30
|
+
resolveClosed = resolve;
|
|
31
|
+
});
|
|
32
|
+
const input = (async function* () {
|
|
33
|
+
await closed;
|
|
34
|
+
})();
|
|
35
|
+
const stream = await this.client.invokeStream({
|
|
36
|
+
toolkit: "developer",
|
|
37
|
+
tool: "logs",
|
|
38
|
+
input,
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
for await (const chunk of stream) {
|
|
42
|
+
if (chunk instanceof ErrorContent) {
|
|
43
|
+
throw new Error(chunk.text);
|
|
44
|
+
}
|
|
45
|
+
if (chunk instanceof ControlContent) {
|
|
46
|
+
if (chunk.method === "close") {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
throw new Error("unexpected return type from developer.logs");
|
|
50
|
+
}
|
|
51
|
+
if (!(chunk instanceof BinaryContent)) {
|
|
52
|
+
throw new Error("unexpected return type from developer.logs");
|
|
53
|
+
}
|
|
54
|
+
const logType = chunk.headers["type"];
|
|
55
|
+
if (typeof logType !== "string" || logType.length === 0) {
|
|
56
|
+
throw new Error("developer.logs returned a chunk without a valid type");
|
|
57
|
+
}
|
|
58
|
+
const decoded = chunk.data.length === 0
|
|
59
|
+
? {}
|
|
60
|
+
: JSON.parse(new TextDecoder().decode(chunk.data));
|
|
61
|
+
if (typeof decoded !== "object" || decoded === null || Array.isArray(decoded)) {
|
|
62
|
+
throw new Error("developer.logs returned invalid JSON data");
|
|
63
|
+
}
|
|
64
|
+
const event = new RoomLogEvent({ type: logType, data: decoded });
|
|
65
|
+
this.client.emit(event);
|
|
66
|
+
this.emit("log", event);
|
|
67
|
+
yield event;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
if (resolveClosed) {
|
|
72
|
+
resolveClosed();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
30
75
|
}
|
|
31
76
|
}
|
package/dist/esm/helpers.js
CHANGED
|
@@ -9,10 +9,11 @@ export function validateSchemaName(name) {
|
|
|
9
9
|
}
|
|
10
10
|
export async function deploySchema({ room, schema, name, overwrite = true }) {
|
|
11
11
|
validateSchemaName(name);
|
|
12
|
-
const handle = await room.storage.open(`.schemas/${name}.json`, { overwrite });
|
|
13
12
|
const data = Buffer.from(JSON.stringify(schema.toJson()), 'utf-8');
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
async function* singleChunk() {
|
|
14
|
+
yield data;
|
|
15
|
+
}
|
|
16
|
+
await room.storage.uploadStream(`.schemas/${name}.json`, singleChunk(), { overwrite, size: data.length });
|
|
16
17
|
}
|
|
17
18
|
export function meshagentBaseUrl(baseUrl) {
|
|
18
19
|
if (baseUrl) {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './agent-client';
|
|
|
3
3
|
export * from './event-emitter';
|
|
4
4
|
export * from './client';
|
|
5
5
|
export * from './completer';
|
|
6
|
+
export * from './containers-client';
|
|
6
7
|
export * from './data-types';
|
|
7
8
|
export * from './database-client';
|
|
8
9
|
export * from './developer-client';
|
package/dist/esm/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from './agent-client';
|
|
|
3
3
|
export * from './event-emitter';
|
|
4
4
|
export * from './client';
|
|
5
5
|
export * from './completer';
|
|
6
|
+
export * from './containers-client';
|
|
6
7
|
export * from './data-types';
|
|
7
8
|
export * from './database-client';
|
|
8
9
|
export * from './developer-client';
|
package/dist/esm/lk-client.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { JsonContent } from './response';
|
|
2
|
+
import { RoomServerException } from './room-server-client';
|
|
1
3
|
export class LivekitConnectionInfo {
|
|
2
4
|
constructor({ url, token }) {
|
|
3
5
|
this.url = url;
|
|
@@ -9,11 +11,18 @@ export class LivekitClient {
|
|
|
9
11
|
this.room = room;
|
|
10
12
|
}
|
|
11
13
|
async getConnectionInfo({ breakoutRoom }) {
|
|
12
|
-
const response =
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const response = await this.room.invoke({
|
|
15
|
+
toolkit: 'livekit',
|
|
16
|
+
tool: 'connect',
|
|
17
|
+
input: { breakout_room: breakoutRoom ?? null },
|
|
18
|
+
});
|
|
19
|
+
if (!(response instanceof JsonContent)) {
|
|
20
|
+
throw new RoomServerException('unexpected return type from livekit.connect');
|
|
15
21
|
}
|
|
16
22
|
const { url, token } = response.json;
|
|
23
|
+
if (typeof url !== 'string' || typeof token !== 'string') {
|
|
24
|
+
throw new RoomServerException('unexpected return type from livekit.connect');
|
|
25
|
+
}
|
|
17
26
|
return new LivekitConnectionInfo({ url, token });
|
|
18
27
|
}
|
|
19
28
|
}
|
|
@@ -62,9 +62,14 @@ export interface ProjectStorageMountSpec {
|
|
|
62
62
|
subpath?: string | null;
|
|
63
63
|
read_only?: boolean;
|
|
64
64
|
}
|
|
65
|
+
export interface EmptyDirMountSpec {
|
|
66
|
+
path: string;
|
|
67
|
+
read_only?: boolean;
|
|
68
|
+
}
|
|
65
69
|
export interface ContainerMountSpec {
|
|
66
70
|
room?: RoomStorageMountSpec[];
|
|
67
71
|
project?: ProjectStorageMountSpec[];
|
|
72
|
+
empty_dirs?: EmptyDirMountSpec[];
|
|
68
73
|
}
|
|
69
74
|
export interface ServiceApiKeySpec {
|
|
70
75
|
role: "admin";
|
|
@@ -5,6 +5,20 @@ import { RoomMessage, RoomMessageEvent } from "./room-event";
|
|
|
5
5
|
import { splitMessageHeader, splitMessagePayload } from "./utils";
|
|
6
6
|
import { StreamController } from "./stream-controller";
|
|
7
7
|
import { Completer } from "./completer";
|
|
8
|
+
const globalScope = globalThis;
|
|
9
|
+
function bytesToBase64(bytes) {
|
|
10
|
+
if (globalScope.Buffer) {
|
|
11
|
+
return globalScope.Buffer.from(bytes).toString("base64");
|
|
12
|
+
}
|
|
13
|
+
if (!globalScope.btoa) {
|
|
14
|
+
throw new Error("base64 encoding is not available in this runtime");
|
|
15
|
+
}
|
|
16
|
+
let binary = "";
|
|
17
|
+
for (const byte of bytes) {
|
|
18
|
+
binary += String.fromCharCode(byte);
|
|
19
|
+
}
|
|
20
|
+
return globalScope.btoa(binary);
|
|
21
|
+
}
|
|
8
22
|
export class MessageStreamChunk {
|
|
9
23
|
constructor({ header, data }) {
|
|
10
24
|
this.header = header;
|
|
@@ -20,6 +34,19 @@ export class MessagingClient extends EventEmitter {
|
|
|
20
34
|
this.client = room;
|
|
21
35
|
this.client.protocol.addHandler("messaging.send", this._handleMessageSend.bind(this));
|
|
22
36
|
}
|
|
37
|
+
_messageInput(params) {
|
|
38
|
+
const input = {
|
|
39
|
+
type: params.type,
|
|
40
|
+
message_json: JSON.stringify(params.message),
|
|
41
|
+
};
|
|
42
|
+
if (params.attachment !== undefined) {
|
|
43
|
+
input["attachment_base64"] = bytesToBase64(params.attachment);
|
|
44
|
+
}
|
|
45
|
+
if (params.toParticipantId !== undefined) {
|
|
46
|
+
input["to_participant_id"] = params.toParticipantId;
|
|
47
|
+
}
|
|
48
|
+
return input;
|
|
49
|
+
}
|
|
23
50
|
async createStream({ to, header }) {
|
|
24
51
|
const streamId = uuidV4();
|
|
25
52
|
const completer = new Completer();
|
|
@@ -32,21 +59,38 @@ export class MessagingClient extends EventEmitter {
|
|
|
32
59
|
return completer.fut;
|
|
33
60
|
}
|
|
34
61
|
async sendMessage({ to, type, message, attachment }) {
|
|
35
|
-
await this.client.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
await this.client.invoke({
|
|
63
|
+
toolkit: "messaging",
|
|
64
|
+
tool: "send",
|
|
65
|
+
input: this._messageInput({
|
|
66
|
+
toParticipantId: to.id,
|
|
67
|
+
type,
|
|
68
|
+
message,
|
|
69
|
+
attachment,
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
40
72
|
}
|
|
41
73
|
async enable(onStreamAccept) {
|
|
42
|
-
await this.client.
|
|
74
|
+
await this.client.invoke({
|
|
75
|
+
toolkit: "messaging",
|
|
76
|
+
tool: "enable",
|
|
77
|
+
input: {},
|
|
78
|
+
});
|
|
43
79
|
this._onStreamAcceptCallback = onStreamAccept;
|
|
44
80
|
}
|
|
45
81
|
async disable() {
|
|
46
|
-
await this.client.
|
|
82
|
+
await this.client.invoke({
|
|
83
|
+
toolkit: "messaging",
|
|
84
|
+
tool: "disable",
|
|
85
|
+
input: {},
|
|
86
|
+
});
|
|
47
87
|
}
|
|
48
88
|
async broadcastMessage({ type, message, attachment }) {
|
|
49
|
-
await this.client.
|
|
89
|
+
await this.client.invoke({
|
|
90
|
+
toolkit: "messaging",
|
|
91
|
+
tool: "broadcast",
|
|
92
|
+
input: this._messageInput({ type, message, attachment }),
|
|
93
|
+
});
|
|
50
94
|
}
|
|
51
95
|
get remoteParticipants() {
|
|
52
96
|
return Object.values(this._participants);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EmptyContent } from "./response";
|
|
1
|
+
import { EmptyContent, JsonContent } from "./response";
|
|
2
|
+
import { RoomServerException } from "./room-server-client";
|
|
2
3
|
export class Queue {
|
|
3
4
|
constructor({ name, size }) {
|
|
4
5
|
this.name = name;
|
|
@@ -9,25 +10,50 @@ export class QueuesClient {
|
|
|
9
10
|
constructor({ room }) {
|
|
10
11
|
this.client = room;
|
|
11
12
|
}
|
|
13
|
+
_unexpectedResponseError(operation) {
|
|
14
|
+
return new RoomServerException(`unexpected return type from queues.${operation}`);
|
|
15
|
+
}
|
|
16
|
+
async _invoke(operation, arguments_) {
|
|
17
|
+
return await this.client.invoke({
|
|
18
|
+
toolkit: "queues",
|
|
19
|
+
tool: operation,
|
|
20
|
+
arguments: arguments_,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
12
23
|
async list() {
|
|
13
|
-
const response =
|
|
24
|
+
const response = await this._invoke("list", {});
|
|
25
|
+
if (!(response instanceof JsonContent)) {
|
|
26
|
+
throw this._unexpectedResponseError("list");
|
|
27
|
+
}
|
|
14
28
|
const queues = response.json["queues"];
|
|
15
29
|
return queues.map((q) => new Queue({ name: q["name"], size: q["size"] }));
|
|
16
30
|
}
|
|
17
31
|
async open(name) {
|
|
18
|
-
await this.
|
|
32
|
+
const response = await this._invoke("open", { name });
|
|
33
|
+
if (!(response instanceof EmptyContent)) {
|
|
34
|
+
throw this._unexpectedResponseError("open");
|
|
35
|
+
}
|
|
19
36
|
}
|
|
20
37
|
async drain(name) {
|
|
21
|
-
await this.
|
|
38
|
+
const response = await this._invoke("drain", { name });
|
|
39
|
+
if (!(response instanceof EmptyContent)) {
|
|
40
|
+
throw this._unexpectedResponseError("drain");
|
|
41
|
+
}
|
|
22
42
|
}
|
|
23
43
|
async close(name) {
|
|
24
|
-
await this.
|
|
44
|
+
const response = await this._invoke("close", { name });
|
|
45
|
+
if (!(response instanceof EmptyContent)) {
|
|
46
|
+
throw this._unexpectedResponseError("close");
|
|
47
|
+
}
|
|
25
48
|
}
|
|
26
49
|
async send(name, message, { create = true }) {
|
|
27
|
-
await this.
|
|
50
|
+
const response = await this._invoke("send", { name, create, message });
|
|
51
|
+
if (!(response instanceof EmptyContent)) {
|
|
52
|
+
throw this._unexpectedResponseError("send");
|
|
53
|
+
}
|
|
28
54
|
}
|
|
29
55
|
async receive(name, { create = true, wait = true }) {
|
|
30
|
-
const response = await this.
|
|
56
|
+
const response = await this._invoke("receive", {
|
|
31
57
|
name,
|
|
32
58
|
create,
|
|
33
59
|
wait,
|
|
@@ -35,8 +61,9 @@ export class QueuesClient {
|
|
|
35
61
|
if (response instanceof EmptyContent) {
|
|
36
62
|
return null;
|
|
37
63
|
}
|
|
38
|
-
|
|
64
|
+
if (response instanceof JsonContent) {
|
|
39
65
|
return response.json;
|
|
40
66
|
}
|
|
67
|
+
throw this._unexpectedResponseError("receive");
|
|
41
68
|
}
|
|
42
69
|
}
|
package/dist/esm/response.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
export interface Content {
|
|
2
2
|
pack(): Uint8Array;
|
|
3
3
|
}
|
|
4
|
+
export declare class BinaryContent implements Content {
|
|
5
|
+
data: Uint8Array;
|
|
6
|
+
headers: Record<string, any>;
|
|
7
|
+
constructor({ data, headers }: {
|
|
8
|
+
data: Uint8Array;
|
|
9
|
+
headers?: Record<string, any>;
|
|
10
|
+
});
|
|
11
|
+
static unpack(header: Record<string, any>, payload: Uint8Array): BinaryContent;
|
|
12
|
+
pack(): Uint8Array;
|
|
13
|
+
toString(): string;
|
|
14
|
+
}
|
|
4
15
|
export declare class LinkContent implements Content {
|
|
5
16
|
url: string;
|
|
6
17
|
name: string;
|
|
@@ -59,4 +70,21 @@ export declare class EmptyContent implements Content {
|
|
|
59
70
|
pack(): Uint8Array;
|
|
60
71
|
toString(): string;
|
|
61
72
|
}
|
|
73
|
+
export declare enum ControlCloseStatus {
|
|
74
|
+
NORMAL = 1000,
|
|
75
|
+
INVALID_DATA = 1007
|
|
76
|
+
}
|
|
77
|
+
export declare class ControlContent implements Content {
|
|
78
|
+
method: "open" | "close";
|
|
79
|
+
statusCode?: number;
|
|
80
|
+
message?: string;
|
|
81
|
+
constructor({ method, statusCode, message, }: {
|
|
82
|
+
method: "open" | "close";
|
|
83
|
+
statusCode?: number;
|
|
84
|
+
message?: string;
|
|
85
|
+
});
|
|
86
|
+
static unpack(header: Record<string, any>, _payload: Uint8Array): ControlContent;
|
|
87
|
+
pack(): Uint8Array;
|
|
88
|
+
toString(): string;
|
|
89
|
+
}
|
|
62
90
|
export declare function unpackContent(data: Uint8Array): Content;
|
package/dist/esm/response.js
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import { packMessage, splitMessageHeader, splitMessagePayload } from "./utils";
|
|
2
|
+
export class BinaryContent {
|
|
3
|
+
constructor({ data, headers = {} }) {
|
|
4
|
+
this.data = data;
|
|
5
|
+
this.headers = headers;
|
|
6
|
+
}
|
|
7
|
+
static unpack(header, payload) {
|
|
8
|
+
return new BinaryContent({
|
|
9
|
+
data: payload,
|
|
10
|
+
headers: typeof header["headers"] === "object" && header["headers"] != null ? header["headers"] : {},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
pack() {
|
|
14
|
+
return packMessage({
|
|
15
|
+
type: "binary",
|
|
16
|
+
headers: this.headers,
|
|
17
|
+
}, this.data);
|
|
18
|
+
}
|
|
19
|
+
toString() {
|
|
20
|
+
return `BinaryContent: headers=${JSON.stringify(this.headers)} length=${this.data.length}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
2
23
|
export class LinkContent {
|
|
3
24
|
constructor({ url, name }) {
|
|
4
25
|
this.url = url;
|
|
@@ -127,7 +148,59 @@ export class EmptyContent {
|
|
|
127
148
|
return `EmptyContent`;
|
|
128
149
|
}
|
|
129
150
|
}
|
|
151
|
+
export var ControlCloseStatus;
|
|
152
|
+
(function (ControlCloseStatus) {
|
|
153
|
+
ControlCloseStatus[ControlCloseStatus["NORMAL"] = 1000] = "NORMAL";
|
|
154
|
+
ControlCloseStatus[ControlCloseStatus["INVALID_DATA"] = 1007] = "INVALID_DATA";
|
|
155
|
+
})(ControlCloseStatus || (ControlCloseStatus = {}));
|
|
156
|
+
export class ControlContent {
|
|
157
|
+
constructor({ method, statusCode, message, }) {
|
|
158
|
+
this.method = method;
|
|
159
|
+
this.statusCode = method === "close" ? statusCode ?? ControlCloseStatus.NORMAL : statusCode;
|
|
160
|
+
this.message = message;
|
|
161
|
+
}
|
|
162
|
+
static unpack(header, _payload) {
|
|
163
|
+
const method = header["method"];
|
|
164
|
+
if (method !== "open" && method !== "close") {
|
|
165
|
+
throw new Error(`Invalid control method: ${method}`);
|
|
166
|
+
}
|
|
167
|
+
const rawStatusCode = header["status_code"];
|
|
168
|
+
let statusCode;
|
|
169
|
+
if (typeof rawStatusCode === "number" && Number.isInteger(rawStatusCode)) {
|
|
170
|
+
statusCode = rawStatusCode;
|
|
171
|
+
}
|
|
172
|
+
else if (typeof rawStatusCode === "string") {
|
|
173
|
+
const parsed = Number.parseInt(rawStatusCode, 10);
|
|
174
|
+
if (!Number.isNaN(parsed)) {
|
|
175
|
+
statusCode = parsed;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return new ControlContent({
|
|
179
|
+
method,
|
|
180
|
+
statusCode,
|
|
181
|
+
message: typeof header["message"] === "string" ? header["message"] : undefined,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
pack() {
|
|
185
|
+
const header = {
|
|
186
|
+
type: "control",
|
|
187
|
+
method: this.method,
|
|
188
|
+
};
|
|
189
|
+
if (this.method === "close") {
|
|
190
|
+
header["status_code"] = this.statusCode ?? ControlCloseStatus.NORMAL;
|
|
191
|
+
if (this.message !== undefined) {
|
|
192
|
+
header["message"] = this.message;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return packMessage(header);
|
|
196
|
+
}
|
|
197
|
+
toString() {
|
|
198
|
+
return `ControlContent: ${this.method}`;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
130
201
|
const _contentTypes = {
|
|
202
|
+
binary: BinaryContent.unpack,
|
|
203
|
+
control: ControlContent.unpack,
|
|
131
204
|
empty: EmptyContent.unpack,
|
|
132
205
|
error: ErrorContent.unpack,
|
|
133
206
|
file: FileContent.unpack,
|
|
@@ -6,8 +6,9 @@ import { StorageClient } from "./storage-client";
|
|
|
6
6
|
import { MessagingClient } from "./messaging-client";
|
|
7
7
|
import { QueuesClient } from "./queues-client";
|
|
8
8
|
import { DatabaseClient } from "./database-client";
|
|
9
|
-
import { AgentsClient } from "./agent-client";
|
|
9
|
+
import { AgentsClient, ToolkitDescription } from "./agent-client";
|
|
10
10
|
import { SecretsClient } from "./secrets-client";
|
|
11
|
+
import { ContainersClient } from "./containers-client";
|
|
11
12
|
import { RoomEvent } from "./room-event";
|
|
12
13
|
import { Content } from "./response";
|
|
13
14
|
interface RequestHeader {
|
|
@@ -23,10 +24,12 @@ export declare class RoomClient {
|
|
|
23
24
|
readonly database: DatabaseClient;
|
|
24
25
|
readonly agents: AgentsClient;
|
|
25
26
|
readonly secrets: SecretsClient;
|
|
27
|
+
readonly containers: ContainersClient;
|
|
26
28
|
private _pendingRequests;
|
|
27
29
|
private _ready;
|
|
28
30
|
private _localParticipant;
|
|
29
31
|
private _eventsController;
|
|
32
|
+
private _toolCallStreams;
|
|
30
33
|
constructor({ protocol }: {
|
|
31
34
|
protocol: Protocol;
|
|
32
35
|
});
|
|
@@ -38,6 +41,45 @@ export declare class RoomClient {
|
|
|
38
41
|
}): Promise<void>;
|
|
39
42
|
dispose(): void;
|
|
40
43
|
sendRequest(type: string, request: RequestHeader, data?: Uint8Array): Promise<Content>;
|
|
44
|
+
call(params: {
|
|
45
|
+
name: string;
|
|
46
|
+
url: string;
|
|
47
|
+
arguments: Record<string, any>;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
listToolkits(params?: {
|
|
50
|
+
participantId?: string;
|
|
51
|
+
participantName?: string;
|
|
52
|
+
timeout?: number;
|
|
53
|
+
}): Promise<ToolkitDescription[]>;
|
|
54
|
+
invoke(params: {
|
|
55
|
+
toolkit: string;
|
|
56
|
+
tool: string;
|
|
57
|
+
arguments?: Record<string, any>;
|
|
58
|
+
input?: Record<string, any> | Content;
|
|
59
|
+
participantId?: string;
|
|
60
|
+
onBehalfOfId?: string;
|
|
61
|
+
callerContext?: Record<string, any>;
|
|
62
|
+
}): Promise<Content>;
|
|
63
|
+
invokeWithStreamInput(params: {
|
|
64
|
+
toolkit: string;
|
|
65
|
+
tool: string;
|
|
66
|
+
input: AsyncIterable<Content>;
|
|
67
|
+
participantId?: string;
|
|
68
|
+
onBehalfOfId?: string;
|
|
69
|
+
callerContext?: Record<string, any>;
|
|
70
|
+
}): Promise<Content>;
|
|
71
|
+
invokeStream(params: {
|
|
72
|
+
toolkit: string;
|
|
73
|
+
tool: string;
|
|
74
|
+
input: AsyncIterable<Content>;
|
|
75
|
+
participantId?: string;
|
|
76
|
+
onBehalfOfId?: string;
|
|
77
|
+
callerContext?: Record<string, any>;
|
|
78
|
+
}): Promise<AsyncIterable<Content>>;
|
|
79
|
+
private _sendToolCallRequestChunk;
|
|
80
|
+
private _streamInvokeToolRequestChunks;
|
|
81
|
+
private _decodeToolCallContent;
|
|
82
|
+
private _handleToolCallResponseChunk;
|
|
41
83
|
private _handleResponse;
|
|
42
84
|
private _handleRoomReady;
|
|
43
85
|
private _onParticipantInit;
|