@meshagent/meshagent 0.27.0 → 0.28.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 +9 -0
- package/dist/browser/agent-client.d.ts +12 -25
- package/dist/browser/agent-client.js +64 -45
- package/dist/browser/agent.d.ts +14 -34
- package/dist/browser/agent.js +67 -75
- package/dist/browser/database-client.js +2 -2
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/meshagent-client.d.ts +8 -1
- package/dist/browser/meshagent-client.js +18 -6
- package/dist/browser/queues-client.js +1 -1
- package/dist/browser/response.d.ts +14 -14
- package/dist/browser/response.js +42 -42
- package/dist/browser/room-client.d.ts +2 -2
- package/dist/browser/room-client.js +2 -2
- package/dist/browser/secrets-client.d.ts +2 -2
- package/dist/browser/secrets-client.js +11 -11
- package/dist/browser/storage-client.d.ts +2 -2
- package/dist/browser/tool-content-type.d.ts +13 -0
- package/dist/browser/tool-content-type.js +68 -0
- package/dist/esm/agent-client.d.ts +12 -25
- package/dist/esm/agent-client.js +63 -43
- package/dist/esm/agent.d.ts +14 -34
- package/dist/esm/agent.js +67 -73
- package/dist/esm/database-client.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 +8 -1
- package/dist/esm/meshagent-client.js +18 -6
- package/dist/esm/queues-client.js +2 -2
- package/dist/esm/response.d.ts +14 -14
- package/dist/esm/response.js +34 -34
- package/dist/esm/room-client.d.ts +2 -2
- package/dist/esm/room-client.js +3 -3
- package/dist/esm/secrets-client.d.ts +2 -2
- package/dist/esm/secrets-client.js +12 -12
- package/dist/esm/storage-client.d.ts +2 -2
- package/dist/esm/tool-content-type.d.ts +13 -0
- package/dist/esm/tool-content-type.js +64 -0
- package/dist/node/agent-client.d.ts +12 -25
- package/dist/node/agent-client.js +64 -45
- package/dist/node/agent.d.ts +14 -34
- package/dist/node/agent.js +67 -75
- package/dist/node/database-client.js +2 -2
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/meshagent-client.d.ts +8 -1
- package/dist/node/meshagent-client.js +18 -6
- package/dist/node/queues-client.js +1 -1
- package/dist/node/response.d.ts +14 -14
- package/dist/node/response.js +42 -42
- package/dist/node/room-client.d.ts +2 -2
- package/dist/node/room-client.js +2 -2
- package/dist/node/secrets-client.d.ts +2 -2
- package/dist/node/secrets-client.js +11 -11
- package/dist/node/storage-client.d.ts +2 -2
- package/dist/node/tool-content-type.d.ts +13 -0
- package/dist/node/tool-content-type.js +68 -0
- package/package.json +1 -1
package/dist/esm/agent.d.ts
CHANGED
|
@@ -1,47 +1,27 @@
|
|
|
1
1
|
import { RoomClient } from "./room-client";
|
|
2
2
|
import { RequiredToolkit } from "./requirement";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
messages: Array<Record<string, any>>;
|
|
6
|
-
readonly systemRole: string;
|
|
7
|
-
constructor({ messages, systemRole }: {
|
|
8
|
-
messages?: Array<Record<string, any>>;
|
|
9
|
-
systemRole?: string;
|
|
10
|
-
});
|
|
11
|
-
appendRules(rules: string[]): void;
|
|
12
|
-
appendUserMessage(message: string): void;
|
|
13
|
-
appendUserImage(url: string): void;
|
|
14
|
-
copy(): AgentChatContext;
|
|
15
|
-
toJson(): Record<string, any>;
|
|
16
|
-
static fromJson(json: Record<string, any>): AgentChatContext;
|
|
17
|
-
}
|
|
18
|
-
export declare class TaskContext {
|
|
19
|
-
private readonly _jwt;
|
|
20
|
-
private readonly _chat;
|
|
21
|
-
private readonly _apiUrl;
|
|
22
|
-
constructor({ chat, jwt, api_url }: {
|
|
23
|
-
chat: AgentChatContext;
|
|
24
|
-
jwt: string;
|
|
25
|
-
api_url: string;
|
|
26
|
-
});
|
|
27
|
-
get chat(): AgentChatContext;
|
|
28
|
-
get jwt(): string;
|
|
29
|
-
get api_url(): string;
|
|
30
|
-
}
|
|
3
|
+
import { Content } from "./response";
|
|
4
|
+
import { ToolContentSpec } from "./tool-content-type";
|
|
31
5
|
export declare abstract class Tool {
|
|
32
6
|
readonly name: string;
|
|
33
7
|
readonly description: string;
|
|
34
8
|
readonly title: string;
|
|
35
|
-
readonly
|
|
9
|
+
readonly inputSpec?: ToolContentSpec;
|
|
10
|
+
readonly outputSpec?: ToolContentSpec;
|
|
36
11
|
readonly thumbnailUrl?: string;
|
|
37
|
-
constructor({ name, description, title, inputSchema, thumbnailUrl }: {
|
|
12
|
+
constructor({ name, description, title, inputSchema, inputSpec, outputSpec, outputSchema, thumbnailUrl }: {
|
|
38
13
|
name: string;
|
|
39
14
|
description: string;
|
|
40
15
|
title: string;
|
|
41
|
-
inputSchema
|
|
16
|
+
inputSchema?: Record<string, any>;
|
|
17
|
+
inputSpec?: ToolContentSpec;
|
|
18
|
+
outputSpec?: ToolContentSpec;
|
|
19
|
+
outputSchema?: Record<string, any>;
|
|
42
20
|
thumbnailUrl?: string;
|
|
43
21
|
});
|
|
44
|
-
|
|
22
|
+
get inputSchema(): Record<string, any> | undefined;
|
|
23
|
+
get outputSchema(): Record<string, any> | undefined;
|
|
24
|
+
abstract execute(arguments_: Record<string, any>): Promise<Content>;
|
|
45
25
|
}
|
|
46
26
|
export declare abstract class Toolkit {
|
|
47
27
|
readonly tools: Tool[];
|
|
@@ -52,7 +32,7 @@ export declare abstract class Toolkit {
|
|
|
52
32
|
});
|
|
53
33
|
getTool(name: string): Tool;
|
|
54
34
|
getTools(): Record<string, any>;
|
|
55
|
-
execute(name: string, args: Record<string, any>): Promise<
|
|
35
|
+
execute(name: string, args: Record<string, any>): Promise<Content>;
|
|
56
36
|
}
|
|
57
37
|
export declare abstract class RemoteToolkit extends Toolkit {
|
|
58
38
|
protected readonly client: RoomClient;
|
|
@@ -96,5 +76,5 @@ export declare abstract class RemoteTaskRunner {
|
|
|
96
76
|
});
|
|
97
77
|
start(): Promise<void>;
|
|
98
78
|
stop(): Promise<void>;
|
|
99
|
-
abstract ask(
|
|
79
|
+
abstract ask(arguments_: Record<string, any>): Promise<Record<string, any>>;
|
|
100
80
|
}
|
package/dist/esm/agent.js
CHANGED
|
@@ -1,80 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorContent } from "./response";
|
|
2
|
+
import { ToolContentSpec } from "./tool-content-type";
|
|
2
3
|
import { unpackMessage } from "./utils";
|
|
3
|
-
export class AgentChatContext {
|
|
4
|
-
constructor({ messages, systemRole = "system" }) {
|
|
5
|
-
this.messages = messages ? [...messages] : [];
|
|
6
|
-
this.systemRole = systemRole;
|
|
7
|
-
}
|
|
8
|
-
appendRules(rules) {
|
|
9
|
-
let systemMessage = this.messages.find((m) => m["role"] === this.systemRole);
|
|
10
|
-
if (!systemMessage) {
|
|
11
|
-
systemMessage = { role: this.systemRole, content: "" };
|
|
12
|
-
this.messages.push(systemMessage);
|
|
13
|
-
}
|
|
14
|
-
const plan = `
|
|
15
|
-
Rules:
|
|
16
|
-
-${rules.join("\n-")}
|
|
17
|
-
`;
|
|
18
|
-
systemMessage["content"] += plan;
|
|
19
|
-
}
|
|
20
|
-
appendUserMessage(message) {
|
|
21
|
-
this.messages.push({ role: "user", content: message });
|
|
22
|
-
}
|
|
23
|
-
appendUserImage(url) {
|
|
24
|
-
this.messages.push({
|
|
25
|
-
role: "user",
|
|
26
|
-
content: [
|
|
27
|
-
{
|
|
28
|
-
type: "image_url",
|
|
29
|
-
image_url: { url: url, detail: "auto" },
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
copy() {
|
|
35
|
-
const cloned = JSON.parse(JSON.stringify(this.messages));
|
|
36
|
-
return new AgentChatContext({
|
|
37
|
-
messages: cloned,
|
|
38
|
-
systemRole: this.systemRole,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
toJson() {
|
|
42
|
-
return {
|
|
43
|
-
messages: this.messages,
|
|
44
|
-
system_role: this.systemRole,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
static fromJson(json) {
|
|
48
|
-
return new AgentChatContext({
|
|
49
|
-
messages: json["messages"],
|
|
50
|
-
systemRole: json["system_role"] || "system",
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
export class TaskContext {
|
|
55
|
-
constructor({ chat, jwt, api_url }) {
|
|
56
|
-
this._jwt = jwt;
|
|
57
|
-
this._chat = chat;
|
|
58
|
-
this._apiUrl = api_url;
|
|
59
|
-
}
|
|
60
|
-
get chat() {
|
|
61
|
-
return this._chat;
|
|
62
|
-
}
|
|
63
|
-
get jwt() {
|
|
64
|
-
return this._jwt;
|
|
65
|
-
}
|
|
66
|
-
get api_url() {
|
|
67
|
-
return this._apiUrl;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
4
|
export class Tool {
|
|
71
|
-
constructor({ name, description, title, inputSchema, thumbnailUrl }) {
|
|
5
|
+
constructor({ name, description, title, inputSchema, inputSpec, outputSpec, outputSchema, thumbnailUrl }) {
|
|
72
6
|
this.name = name;
|
|
73
7
|
this.description = description;
|
|
74
8
|
this.title = title;
|
|
75
|
-
|
|
9
|
+
if (inputSpec !== undefined && inputSchema !== undefined) {
|
|
10
|
+
this.inputSpec = new ToolContentSpec({
|
|
11
|
+
types: [...inputSpec.types],
|
|
12
|
+
stream: inputSpec.stream,
|
|
13
|
+
schema: inputSchema,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
else if (inputSpec !== undefined) {
|
|
17
|
+
this.inputSpec = inputSpec;
|
|
18
|
+
}
|
|
19
|
+
else if (inputSchema !== undefined) {
|
|
20
|
+
this.inputSpec = new ToolContentSpec({
|
|
21
|
+
types: ["json"],
|
|
22
|
+
stream: false,
|
|
23
|
+
schema: inputSchema,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (outputSpec !== undefined && outputSchema !== undefined) {
|
|
27
|
+
this.outputSpec = new ToolContentSpec({
|
|
28
|
+
types: [...outputSpec.types],
|
|
29
|
+
stream: outputSpec.stream,
|
|
30
|
+
schema: outputSchema,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else if (outputSpec !== undefined) {
|
|
34
|
+
this.outputSpec = outputSpec;
|
|
35
|
+
}
|
|
36
|
+
else if (outputSchema !== undefined) {
|
|
37
|
+
this.outputSpec = new ToolContentSpec({
|
|
38
|
+
types: ["json"],
|
|
39
|
+
stream: false,
|
|
40
|
+
schema: outputSchema,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
76
43
|
this.thumbnailUrl = thumbnailUrl;
|
|
77
44
|
}
|
|
45
|
+
get inputSchema() {
|
|
46
|
+
return this.inputSpec?.schema;
|
|
47
|
+
}
|
|
48
|
+
get outputSchema() {
|
|
49
|
+
return this.outputSpec?.schema;
|
|
50
|
+
}
|
|
78
51
|
}
|
|
79
52
|
export class Toolkit {
|
|
80
53
|
constructor({ tools, rules = [] }) {
|
|
@@ -94,7 +67,8 @@ export class Toolkit {
|
|
|
94
67
|
json[tool.name] = {
|
|
95
68
|
description: tool.description,
|
|
96
69
|
title: tool.title,
|
|
97
|
-
|
|
70
|
+
input_spec: tool.inputSpec?.toJson(),
|
|
71
|
+
output_spec: tool.outputSpec?.toJson(),
|
|
98
72
|
thumbnail_url: tool.thumbnailUrl,
|
|
99
73
|
};
|
|
100
74
|
}
|
|
@@ -143,12 +117,32 @@ export class RemoteToolkit extends Toolkit {
|
|
|
143
117
|
try {
|
|
144
118
|
const [message, _] = unpackMessage(data);
|
|
145
119
|
const toolName = message["name"];
|
|
146
|
-
const
|
|
120
|
+
const rawArguments = message["arguments"];
|
|
121
|
+
let args;
|
|
122
|
+
if (rawArguments &&
|
|
123
|
+
typeof rawArguments === "object" &&
|
|
124
|
+
!Array.isArray(rawArguments) &&
|
|
125
|
+
"type" in rawArguments) {
|
|
126
|
+
const content = rawArguments;
|
|
127
|
+
const contentType = content["type"];
|
|
128
|
+
if (contentType === "json") {
|
|
129
|
+
args = content["json"] ?? {};
|
|
130
|
+
}
|
|
131
|
+
else if (contentType === "empty") {
|
|
132
|
+
args = {};
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
throw new Error(`tool '${toolName}' requires JSON object input, received content type '${String(contentType)}'`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
args = rawArguments ?? {};
|
|
140
|
+
}
|
|
147
141
|
const response = await this.execute(toolName, args);
|
|
148
142
|
await this.client.protocol.send("agent.tool_call_response", response.pack(), messageId);
|
|
149
143
|
}
|
|
150
144
|
catch (e) {
|
|
151
|
-
const err = new
|
|
145
|
+
const err = new ErrorContent({ text: String(e) });
|
|
152
146
|
await this.client.protocol.send("agent.tool_call_response", err.pack(), messageId);
|
|
153
147
|
}
|
|
154
148
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonContent } from "./response";
|
|
2
2
|
export class DatabaseClient {
|
|
3
3
|
constructor({ room }) {
|
|
4
4
|
this.room = room;
|
|
@@ -66,7 +66,7 @@ export class DatabaseClient {
|
|
|
66
66
|
params,
|
|
67
67
|
};
|
|
68
68
|
const response = await this.room.sendRequest("database.sql", payload);
|
|
69
|
-
if (response instanceof
|
|
69
|
+
if (response instanceof JsonContent) {
|
|
70
70
|
if (response?.json?.results) {
|
|
71
71
|
return response.json.results;
|
|
72
72
|
}
|
|
@@ -97,7 +97,7 @@ export class DatabaseClient {
|
|
|
97
97
|
payload.vector = vector;
|
|
98
98
|
}
|
|
99
99
|
const response = await this.room.sendRequest("database.search", payload);
|
|
100
|
-
if (response instanceof
|
|
100
|
+
if (response instanceof JsonContent) {
|
|
101
101
|
if (response?.json?.results) {
|
|
102
102
|
return response.json.results;
|
|
103
103
|
}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -30,6 +30,7 @@ export interface RoomInfo {
|
|
|
30
30
|
id: string;
|
|
31
31
|
name: string;
|
|
32
32
|
metadata: Record<string, unknown>;
|
|
33
|
+
annotations: Record<string, string>;
|
|
33
34
|
}
|
|
34
35
|
export interface ProjectRoomGrant {
|
|
35
36
|
room: RoomInfo;
|
|
@@ -79,6 +80,7 @@ export interface ServiceMetadata {
|
|
|
79
80
|
}
|
|
80
81
|
export interface ContainerSpec {
|
|
81
82
|
command?: string | null;
|
|
83
|
+
working_dir?: string | null;
|
|
82
84
|
image: string;
|
|
83
85
|
environment?: EnvironmentVariable[] | null;
|
|
84
86
|
secrets?: string[];
|
|
@@ -137,6 +139,7 @@ export interface ServiceSpec {
|
|
|
137
139
|
export interface Mailbox {
|
|
138
140
|
address: string;
|
|
139
141
|
room: string;
|
|
142
|
+
roomId?: string;
|
|
140
143
|
queue: string;
|
|
141
144
|
}
|
|
142
145
|
export interface Balance {
|
|
@@ -322,10 +325,14 @@ export declare class Meshagent {
|
|
|
322
325
|
name: string;
|
|
323
326
|
ifNotExists?: boolean;
|
|
324
327
|
metadata?: Record<string, unknown>;
|
|
328
|
+
annotations?: Record<string, string>;
|
|
325
329
|
permissions?: Record<string, ApiScope>;
|
|
326
330
|
}): Promise<RoomInfo>;
|
|
327
331
|
getRoom(projectId: string, name: string): Promise<RoomInfo>;
|
|
328
|
-
updateRoom(projectId: string, roomId: string, name: string
|
|
332
|
+
updateRoom(projectId: string, roomId: string, name: string, options?: {
|
|
333
|
+
metadata?: Record<string, unknown>;
|
|
334
|
+
annotations?: Record<string, string>;
|
|
335
|
+
}): Promise<void>;
|
|
329
336
|
deleteRoom(projectId: string, roomId: string): Promise<void>;
|
|
330
337
|
connectRoom(projectId: string, room: string): Promise<RoomConnectionInfo>;
|
|
331
338
|
createRoomGrant(params: {
|
|
@@ -173,7 +173,7 @@ export class Meshagent {
|
|
|
173
173
|
if (!data || typeof data !== "object") {
|
|
174
174
|
throw new RoomException("Invalid room payload");
|
|
175
175
|
}
|
|
176
|
-
const { id, name, metadata } = data;
|
|
176
|
+
const { id, name, metadata, annotations } = data;
|
|
177
177
|
if (typeof id !== "string" || typeof name !== "string") {
|
|
178
178
|
throw new RoomException("Invalid room payload: missing id or name");
|
|
179
179
|
}
|
|
@@ -181,6 +181,7 @@ export class Meshagent {
|
|
|
181
181
|
id,
|
|
182
182
|
name,
|
|
183
183
|
metadata: metadata && typeof metadata === "object" ? metadata : {},
|
|
184
|
+
annotations: annotations && typeof annotations === "object" ? annotations : {},
|
|
184
185
|
};
|
|
185
186
|
}
|
|
186
187
|
parseProjectRoomGrant(data) {
|
|
@@ -707,11 +708,14 @@ export class Meshagent {
|
|
|
707
708
|
if (!item || typeof item !== "object") {
|
|
708
709
|
throw new RoomException("Invalid mailbox payload");
|
|
709
710
|
}
|
|
710
|
-
const { address, room, queue } = item;
|
|
711
|
+
const { address, room, room_id, queue } = item;
|
|
711
712
|
if (typeof address !== "string" || typeof room !== "string" || typeof queue !== "string") {
|
|
712
713
|
throw new RoomException("Invalid mailbox payload: missing fields");
|
|
713
714
|
}
|
|
714
|
-
|
|
715
|
+
if (room_id !== undefined && typeof room_id !== "string") {
|
|
716
|
+
throw new RoomException("Invalid mailbox payload: invalid room_id");
|
|
717
|
+
}
|
|
718
|
+
return { address, room, roomId: room_id, queue };
|
|
715
719
|
});
|
|
716
720
|
}
|
|
717
721
|
async deleteMailbox(projectId, address) {
|
|
@@ -836,11 +840,12 @@ export class Meshagent {
|
|
|
836
840
|
return secrets.map((item) => this.parseSecret(item));
|
|
837
841
|
}
|
|
838
842
|
async createRoom(params) {
|
|
839
|
-
const { projectId, name, ifNotExists = false, metadata, permissions } = params;
|
|
843
|
+
const { projectId, name, ifNotExists = false, metadata, annotations, permissions } = params;
|
|
840
844
|
const payload = {
|
|
841
845
|
name,
|
|
842
846
|
if_not_exists: Boolean(ifNotExists),
|
|
843
847
|
metadata,
|
|
848
|
+
annotations,
|
|
844
849
|
};
|
|
845
850
|
if (permissions) {
|
|
846
851
|
const serialized = {};
|
|
@@ -862,10 +867,17 @@ export class Meshagent {
|
|
|
862
867
|
});
|
|
863
868
|
return this.parseRoom(data);
|
|
864
869
|
}
|
|
865
|
-
async updateRoom(projectId, roomId, name) {
|
|
870
|
+
async updateRoom(projectId, roomId, name, options = {}) {
|
|
871
|
+
const payload = { name };
|
|
872
|
+
if (options.metadata !== undefined) {
|
|
873
|
+
payload["metadata"] = options.metadata;
|
|
874
|
+
}
|
|
875
|
+
if (options.annotations !== undefined) {
|
|
876
|
+
payload["annotations"] = options.annotations;
|
|
877
|
+
}
|
|
866
878
|
await this.request(`/accounts/projects/${projectId}/rooms/${roomId}`, {
|
|
867
879
|
method: "PUT",
|
|
868
|
-
json:
|
|
880
|
+
json: payload,
|
|
869
881
|
action: "update room",
|
|
870
882
|
responseType: "void",
|
|
871
883
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EmptyContent } from "./response";
|
|
2
2
|
export class Queue {
|
|
3
3
|
constructor({ name, size }) {
|
|
4
4
|
this.name = name;
|
|
@@ -32,7 +32,7 @@ export class QueuesClient {
|
|
|
32
32
|
create,
|
|
33
33
|
wait,
|
|
34
34
|
});
|
|
35
|
-
if (response instanceof
|
|
35
|
+
if (response instanceof EmptyContent) {
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
else {
|
package/dist/esm/response.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface Content {
|
|
2
2
|
pack(): Uint8Array;
|
|
3
3
|
}
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class LinkContent implements Content {
|
|
5
5
|
url: string;
|
|
6
6
|
name: string;
|
|
7
7
|
constructor({ url, name }: {
|
|
8
8
|
url: string;
|
|
9
9
|
name: string;
|
|
10
10
|
});
|
|
11
|
-
static unpack(header: Record<string, any>,
|
|
11
|
+
static unpack(header: Record<string, any>, _payload: Uint8Array): LinkContent;
|
|
12
12
|
pack(): Uint8Array;
|
|
13
13
|
toString(): string;
|
|
14
14
|
}
|
|
15
|
-
export declare class
|
|
15
|
+
export declare class FileContent implements Content {
|
|
16
16
|
data: Uint8Array;
|
|
17
17
|
name: string;
|
|
18
18
|
mimeType: string;
|
|
@@ -21,40 +21,40 @@ export declare class FileResponse implements Response {
|
|
|
21
21
|
name: string;
|
|
22
22
|
mimeType: string;
|
|
23
23
|
});
|
|
24
|
-
static unpack(header: Record<string, any>, payload: Uint8Array):
|
|
24
|
+
static unpack(header: Record<string, any>, payload: Uint8Array): FileContent;
|
|
25
25
|
pack(): Uint8Array;
|
|
26
26
|
toString(): string;
|
|
27
27
|
}
|
|
28
|
-
export declare class
|
|
28
|
+
export declare class TextContent implements Content {
|
|
29
29
|
text: string;
|
|
30
30
|
constructor({ text }: {
|
|
31
31
|
text: string;
|
|
32
32
|
});
|
|
33
|
-
static unpack(header: Record<string, any>,
|
|
33
|
+
static unpack(header: Record<string, any>, _payload: Uint8Array): TextContent;
|
|
34
34
|
pack(): Uint8Array;
|
|
35
35
|
toString(): string;
|
|
36
36
|
}
|
|
37
|
-
export declare class
|
|
37
|
+
export declare class JsonContent implements Content {
|
|
38
38
|
json: Record<string, any>;
|
|
39
39
|
constructor({ json }: {
|
|
40
40
|
json: Record<string, any>;
|
|
41
41
|
});
|
|
42
|
-
static unpack(header: Record<string, any>,
|
|
42
|
+
static unpack(header: Record<string, any>, _payload: Uint8Array): JsonContent;
|
|
43
43
|
pack(): Uint8Array;
|
|
44
44
|
toString(): string;
|
|
45
45
|
}
|
|
46
|
-
export declare class
|
|
46
|
+
export declare class ErrorContent implements Content {
|
|
47
47
|
text: string;
|
|
48
48
|
constructor({ text }: {
|
|
49
49
|
text: string;
|
|
50
50
|
});
|
|
51
|
-
static unpack(header: Record<string, any>,
|
|
51
|
+
static unpack(header: Record<string, any>, _payload: Uint8Array): ErrorContent;
|
|
52
52
|
pack(): Uint8Array;
|
|
53
53
|
toString(): string;
|
|
54
54
|
}
|
|
55
|
-
export declare class
|
|
56
|
-
static unpack(
|
|
55
|
+
export declare class EmptyContent implements Content {
|
|
56
|
+
static unpack(_header: Record<string, any>, _payload: Uint8Array): EmptyContent;
|
|
57
57
|
pack(): Uint8Array;
|
|
58
58
|
toString(): string;
|
|
59
59
|
}
|
|
60
|
-
export declare function
|
|
60
|
+
export declare function unpackContent(data: Uint8Array): Content;
|
package/dist/esm/response.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { packMessage, splitMessageHeader, splitMessagePayload } from "./utils";
|
|
2
|
-
export class
|
|
2
|
+
export class LinkContent {
|
|
3
3
|
constructor({ url, name }) {
|
|
4
4
|
this.url = url;
|
|
5
5
|
this.name = name;
|
|
6
6
|
}
|
|
7
|
-
static unpack(header,
|
|
8
|
-
return new
|
|
7
|
+
static unpack(header, _payload) {
|
|
8
|
+
return new LinkContent({
|
|
9
9
|
url: header["url"],
|
|
10
10
|
name: header["name"],
|
|
11
11
|
});
|
|
@@ -18,17 +18,17 @@ export class LinkResponse {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
toString() {
|
|
21
|
-
return `
|
|
21
|
+
return `LinkContent (${this.name}): ${this.url}`;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
export class
|
|
24
|
+
export class FileContent {
|
|
25
25
|
constructor({ data, name, mimeType }) {
|
|
26
26
|
this.data = data;
|
|
27
27
|
this.name = name;
|
|
28
28
|
this.mimeType = mimeType;
|
|
29
29
|
}
|
|
30
30
|
static unpack(header, payload) {
|
|
31
|
-
return new
|
|
31
|
+
return new FileContent({
|
|
32
32
|
data: payload,
|
|
33
33
|
name: header["name"],
|
|
34
34
|
mimeType: header["mime_type"],
|
|
@@ -42,15 +42,15 @@ export class FileResponse {
|
|
|
42
42
|
}, this.data);
|
|
43
43
|
}
|
|
44
44
|
toString() {
|
|
45
|
-
return `
|
|
45
|
+
return `FileContent (${this.name}): ${this.mimeType}`;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
export class
|
|
48
|
+
export class TextContent {
|
|
49
49
|
constructor({ text }) {
|
|
50
50
|
this.text = text;
|
|
51
51
|
}
|
|
52
|
-
static unpack(header,
|
|
53
|
-
return new
|
|
52
|
+
static unpack(header, _payload) {
|
|
53
|
+
return new TextContent({
|
|
54
54
|
text: header["text"],
|
|
55
55
|
});
|
|
56
56
|
}
|
|
@@ -61,15 +61,15 @@ export class TextResponse {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
toString() {
|
|
64
|
-
return `
|
|
64
|
+
return `TextContent: ${this.text}`;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
export class
|
|
67
|
+
export class JsonContent {
|
|
68
68
|
constructor({ json }) {
|
|
69
69
|
this.json = json;
|
|
70
70
|
}
|
|
71
|
-
static unpack(header,
|
|
72
|
-
return new
|
|
71
|
+
static unpack(header, _payload) {
|
|
72
|
+
return new JsonContent({ json: header["json"] });
|
|
73
73
|
}
|
|
74
74
|
pack() {
|
|
75
75
|
return packMessage({
|
|
@@ -78,15 +78,15 @@ export class JsonResponse {
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
toString() {
|
|
81
|
-
return `
|
|
81
|
+
return `JsonContent: ${JSON.stringify(this.json)}`;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
export class
|
|
84
|
+
export class ErrorContent {
|
|
85
85
|
constructor({ text }) {
|
|
86
86
|
this.text = text;
|
|
87
87
|
}
|
|
88
|
-
static unpack(header,
|
|
89
|
-
return new
|
|
88
|
+
static unpack(header, _payload) {
|
|
89
|
+
return new ErrorContent({ text: header["text"] });
|
|
90
90
|
}
|
|
91
91
|
pack() {
|
|
92
92
|
return packMessage({
|
|
@@ -95,34 +95,34 @@ export class ErrorResponse {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
toString() {
|
|
98
|
-
return `
|
|
98
|
+
return `ErrorContent: ${this.text}`;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
export class
|
|
102
|
-
static unpack(
|
|
103
|
-
return new
|
|
101
|
+
export class EmptyContent {
|
|
102
|
+
static unpack(_header, _payload) {
|
|
103
|
+
return new EmptyContent();
|
|
104
104
|
}
|
|
105
105
|
pack() {
|
|
106
106
|
return packMessage({ type: "empty" });
|
|
107
107
|
}
|
|
108
108
|
toString() {
|
|
109
|
-
return `
|
|
109
|
+
return `EmptyContent`;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
const
|
|
113
|
-
empty:
|
|
114
|
-
error:
|
|
115
|
-
file:
|
|
116
|
-
json:
|
|
117
|
-
link:
|
|
118
|
-
text:
|
|
112
|
+
const _contentTypes = {
|
|
113
|
+
empty: EmptyContent.unpack,
|
|
114
|
+
error: ErrorContent.unpack,
|
|
115
|
+
file: FileContent.unpack,
|
|
116
|
+
json: JsonContent.unpack,
|
|
117
|
+
link: LinkContent.unpack,
|
|
118
|
+
text: TextContent.unpack,
|
|
119
119
|
};
|
|
120
|
-
export function
|
|
120
|
+
export function unpackContent(data) {
|
|
121
121
|
const header = JSON.parse(splitMessageHeader(data));
|
|
122
122
|
const payload = splitMessagePayload(data);
|
|
123
123
|
const typeKey = header["type"];
|
|
124
|
-
if (!
|
|
125
|
-
throw new Error(`Unknown
|
|
124
|
+
if (!_contentTypes[typeKey]) {
|
|
125
|
+
throw new Error(`Unknown content type: ${typeKey}`);
|
|
126
126
|
}
|
|
127
|
-
return
|
|
127
|
+
return _contentTypes[typeKey](header, payload);
|
|
128
128
|
}
|
|
@@ -9,7 +9,7 @@ import { DatabaseClient } from "./database-client";
|
|
|
9
9
|
import { AgentsClient } from "./agent-client";
|
|
10
10
|
import { SecretsClient } from "./secrets-client";
|
|
11
11
|
import { RoomEvent } from "./room-event";
|
|
12
|
-
import {
|
|
12
|
+
import { Content } from "./response";
|
|
13
13
|
interface RequestHeader {
|
|
14
14
|
[key: string]: any;
|
|
15
15
|
}
|
|
@@ -37,7 +37,7 @@ export declare class RoomClient {
|
|
|
37
37
|
onError?: (error: Error) => void;
|
|
38
38
|
}): Promise<void>;
|
|
39
39
|
dispose(): void;
|
|
40
|
-
sendRequest(type: string, request: RequestHeader, data?: Uint8Array): Promise<
|
|
40
|
+
sendRequest(type: string, request: RequestHeader, data?: Uint8Array): Promise<Content>;
|
|
41
41
|
private _handleResponse;
|
|
42
42
|
private _handleRoomReady;
|
|
43
43
|
private _onParticipantInit;
|
package/dist/esm/room-client.js
CHANGED
|
@@ -10,7 +10,7 @@ import { QueuesClient } from "./queues-client";
|
|
|
10
10
|
import { DatabaseClient } from "./database-client";
|
|
11
11
|
import { AgentsClient } from "./agent-client";
|
|
12
12
|
import { SecretsClient } from "./secrets-client";
|
|
13
|
-
import {
|
|
13
|
+
import { ErrorContent, unpackContent } from "./response";
|
|
14
14
|
export class RoomClient {
|
|
15
15
|
constructor({ protocol }) {
|
|
16
16
|
this._pendingRequests = new Map();
|
|
@@ -63,7 +63,7 @@ export class RoomClient {
|
|
|
63
63
|
console.error("No data in response");
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
const response =
|
|
66
|
+
const response = unpackContent(data);
|
|
67
67
|
console.log("GOT RESPONSE", response);
|
|
68
68
|
if (!response) {
|
|
69
69
|
console.error("No response");
|
|
@@ -72,7 +72,7 @@ export class RoomClient {
|
|
|
72
72
|
if (this._pendingRequests.has(messageId)) {
|
|
73
73
|
const pr = this._pendingRequests.get(messageId);
|
|
74
74
|
this._pendingRequests.delete(messageId);
|
|
75
|
-
if (response instanceof
|
|
75
|
+
if (response instanceof ErrorContent) {
|
|
76
76
|
pr.reject(new Error(response.text));
|
|
77
77
|
}
|
|
78
78
|
else {
|