@meshagent/meshagent 0.3.1 → 0.4.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 +6 -0
- package/dist/browser/entrypoint.js +7956 -5611
- package/dist/browser/helpers.d.ts +10 -4
- package/dist/browser/helpers.js +14 -39
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/participant-token.d.ts +4 -4
- package/dist/browser/participant-token.js +4 -9
- package/dist/browser/protocol.d.ts +5 -1
- package/dist/browser/protocol.js +7 -2
- package/dist/browser/room-client.d.ts +4 -1
- package/dist/browser/room-client.js +2 -2
- package/dist/browser/sync-client.d.ts +5 -1
- package/dist/browser/sync-client.js +13 -2
- package/dist/esm/agent-client.d.ts +88 -0
- package/dist/esm/agent-client.js +166 -0
- package/dist/esm/agent.d.ts +103 -0
- package/dist/esm/agent.js +218 -0
- package/dist/esm/client.d.ts +90 -0
- package/dist/esm/client.js +443 -0
- package/dist/esm/completer.d.ts +9 -0
- package/dist/esm/completer.js +21 -0
- package/dist/esm/data-types.d.ts +44 -0
- package/dist/esm/data-types.js +110 -0
- package/dist/esm/database-client.d.ts +77 -0
- package/dist/esm/database-client.js +109 -0
- package/dist/esm/developer-client.d.ts +13 -0
- package/dist/esm/developer-client.js +31 -0
- package/dist/esm/document.d.ts +84 -0
- package/dist/esm/document.js +522 -0
- package/dist/esm/entrypoint.d.ts +49722 -0
- package/dist/esm/entrypoint.js +6313 -0
- package/dist/esm/event-emitter.d.ts +13 -0
- package/dist/esm/event-emitter.js +34 -0
- package/dist/esm/helpers.d.ts +32 -0
- package/dist/esm/helpers.js +46 -0
- package/dist/esm/index.d.ts +25 -0
- package/dist/esm/index.js +25 -0
- package/dist/esm/messaging-client.d.ts +76 -0
- package/dist/esm/messaging-client.js +241 -0
- package/dist/esm/participant-token.d.ts +36 -0
- package/dist/esm/participant-token.js +91 -0
- package/dist/esm/participant.d.ts +18 -0
- package/dist/esm/participant.js +36 -0
- package/dist/esm/protocol.d.ts +91 -0
- package/dist/esm/protocol.js +287 -0
- package/dist/esm/queues-client.d.ts +26 -0
- package/dist/esm/queues-client.js +42 -0
- package/dist/esm/requirement.d.ts +25 -0
- package/dist/esm/requirement.js +42 -0
- package/dist/esm/response.d.ts +60 -0
- package/dist/esm/response.js +128 -0
- package/dist/esm/room-client.d.ts +46 -0
- package/dist/esm/room-client.js +106 -0
- package/dist/esm/room-event.d.ts +60 -0
- package/dist/esm/room-event.js +72 -0
- package/dist/esm/room-server-client.d.ts +19 -0
- package/dist/esm/room-server-client.js +45 -0
- package/dist/esm/runtime.d.ts +6 -0
- package/dist/esm/runtime.js +1 -0
- package/dist/esm/schema.d.ts +83 -0
- package/dist/esm/schema.js +312 -0
- package/dist/esm/storage-client.d.ts +38 -0
- package/dist/esm/storage-client.js +79 -0
- package/dist/esm/stream-controller.d.ts +8 -0
- package/dist/esm/stream-controller.js +51 -0
- package/dist/esm/sync-client.d.ts +37 -0
- package/dist/esm/sync-client.js +125 -0
- package/dist/esm/utils.d.ts +14 -0
- package/dist/esm/utils.js +44 -0
- package/dist/node/entrypoint.js +9 -4
- package/dist/node/helpers.d.ts +10 -4
- package/dist/node/helpers.js +14 -39
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/participant-token.d.ts +4 -4
- package/dist/node/participant-token.js +4 -9
- package/dist/node/protocol.d.ts +5 -1
- package/dist/node/protocol.js +7 -2
- package/dist/node/room-client.d.ts +4 -1
- package/dist/node/room-client.js +2 -2
- package/dist/node/sync-client.d.ts +5 -1
- package/dist/node/sync-client.js +13 -2
- package/package.json +4 -3
|
@@ -10,17 +10,23 @@ export declare function deploySchema({ room, schema, name, overwrite }: {
|
|
|
10
10
|
overwrite?: boolean;
|
|
11
11
|
}): Promise<void>;
|
|
12
12
|
export declare function meshagentBaseUrl(baseUrl?: string): string;
|
|
13
|
-
export declare function websocketRoomUrl({ roomName,
|
|
13
|
+
export declare function websocketRoomUrl({ roomName, apiUrl }: {
|
|
14
14
|
roomName: string;
|
|
15
|
-
|
|
15
|
+
apiUrl?: string;
|
|
16
16
|
}): string;
|
|
17
|
-
export declare function participantToken({ participantName, roomName, role }: {
|
|
17
|
+
export declare function participantToken({ participantName, roomName, role, projectId, apiKeyId, }: {
|
|
18
18
|
participantName: string;
|
|
19
19
|
roomName: string;
|
|
20
20
|
role?: string;
|
|
21
|
+
projectId: string;
|
|
22
|
+
apiKeyId: string;
|
|
21
23
|
}): ParticipantToken;
|
|
22
|
-
export declare function websocketProtocol({ participantName, roomName, role }: {
|
|
24
|
+
export declare function websocketProtocol({ participantName, roomName, role, projectId, apiKeyId, secret, apiUrl }: {
|
|
23
25
|
participantName: string;
|
|
24
26
|
roomName: string;
|
|
25
27
|
role?: string;
|
|
28
|
+
projectId: string;
|
|
29
|
+
apiKeyId: string;
|
|
30
|
+
secret: string;
|
|
31
|
+
apiUrl?: string;
|
|
26
32
|
}): Promise<WebSocketClientProtocol>;
|
package/dist/browser/helpers.js
CHANGED
|
@@ -25,41 +25,20 @@ function meshagentBaseUrl(baseUrl) {
|
|
|
25
25
|
if (baseUrl) {
|
|
26
26
|
return baseUrl;
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return 'https://api.meshagent.com';
|
|
29
29
|
}
|
|
30
|
-
function websocketRoomUrl({ roomName,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
if (envApiUrl.startsWith('https:')) {
|
|
38
|
-
baseUrl = 'wss:' + envApiUrl.substring('https:'.length);
|
|
39
|
-
}
|
|
40
|
-
else if (envApiUrl.startsWith('http:')) {
|
|
41
|
-
baseUrl = 'ws:' + envApiUrl.substring('http:'.length);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
baseUrl = envApiUrl;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
30
|
+
function websocketRoomUrl({ roomName, apiUrl }) {
|
|
31
|
+
const baseUrl = apiUrl || 'wss://api.meshagent.com';
|
|
32
|
+
let url = baseUrl;
|
|
33
|
+
if (baseUrl.startsWith('https:')) {
|
|
34
|
+
url = 'wss:' + baseUrl.substring('https:'.length);
|
|
47
35
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
function participantToken({ participantName, roomName, role }) {
|
|
51
|
-
const projectId = process.env.MESHAGENT_PROJECT_ID;
|
|
52
|
-
const apiKeyId = process.env.MESHAGENT_KEY_ID;
|
|
53
|
-
const secret = process.env.MESHAGENT_SECRET;
|
|
54
|
-
if (!projectId) {
|
|
55
|
-
throw new Error('MESHAGENT_PROJECT_ID must be set. You can find this in the Meshagent Studio under API keys.');
|
|
56
|
-
}
|
|
57
|
-
if (!apiKeyId) {
|
|
58
|
-
throw new Error('MESHAGENT_KEY_ID must be set. You can find this in the Meshagent Studio under API keys.');
|
|
59
|
-
}
|
|
60
|
-
if (!secret) {
|
|
61
|
-
throw new Error('MESHAGENT_SECRET must be set. You can find this in the Meshagent Studio under API keys.');
|
|
36
|
+
else if (baseUrl.startsWith('http:')) {
|
|
37
|
+
url = 'ws:' + baseUrl.substring('http:'.length);
|
|
62
38
|
}
|
|
39
|
+
return `${url}/rooms/${roomName}`;
|
|
40
|
+
}
|
|
41
|
+
function participantToken({ participantName, roomName, role, projectId, apiKeyId, }) {
|
|
63
42
|
const token = new participant_token_1.ParticipantToken({ name: participantName, projectId, apiKeyId });
|
|
64
43
|
token.addRoomGrant(roomName);
|
|
65
44
|
if (role) {
|
|
@@ -67,13 +46,9 @@ function participantToken({ participantName, roomName, role }) {
|
|
|
67
46
|
}
|
|
68
47
|
return token;
|
|
69
48
|
}
|
|
70
|
-
async function websocketProtocol({ participantName, roomName, role }) {
|
|
71
|
-
const url = websocketRoomUrl({ roomName });
|
|
72
|
-
const token = participantToken({ participantName, roomName, role });
|
|
73
|
-
const secret = process.env.MESHAGENT_SECRET;
|
|
74
|
-
if (!secret) {
|
|
75
|
-
throw new Error('MESHAGENT_SECRET must be set in the environment.');
|
|
76
|
-
}
|
|
49
|
+
async function websocketProtocol({ participantName, roomName, role, projectId, apiKeyId, secret, apiUrl }) {
|
|
50
|
+
const url = websocketRoomUrl({ roomName, apiUrl });
|
|
51
|
+
const token = participantToken({ participantName, roomName, role, projectId, apiKeyId });
|
|
77
52
|
const jwt = await token.toJwt({ token: secret });
|
|
78
53
|
return new protocol_1.WebSocketClientProtocol({ url, token: jwt });
|
|
79
54
|
}
|
package/dist/browser/index.d.ts
CHANGED
package/dist/browser/index.js
CHANGED
|
@@ -25,12 +25,12 @@ export declare class ParticipantToken {
|
|
|
25
25
|
addRoleGrant(role: string): void;
|
|
26
26
|
addRoomGrant(roomName: string): void;
|
|
27
27
|
toJson(): Record<string, any>;
|
|
28
|
-
toJwt({ token }
|
|
29
|
-
token
|
|
28
|
+
toJwt({ token }: {
|
|
29
|
+
token: string;
|
|
30
30
|
}): Promise<string>;
|
|
31
31
|
static fromJson(json: Record<string, any>): ParticipantToken;
|
|
32
|
-
static fromJwt(jwtStr: string, options
|
|
33
|
-
token
|
|
32
|
+
static fromJwt(jwtStr: string, options: {
|
|
33
|
+
token: string;
|
|
34
34
|
verify?: boolean;
|
|
35
35
|
}): Promise<ParticipantToken>;
|
|
36
36
|
}
|
|
@@ -51,9 +51,8 @@ class ParticipantToken {
|
|
|
51
51
|
grants: this.grants.map((g) => g.toJson()),
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
async toJwt({ token }
|
|
55
|
-
const
|
|
56
|
-
const secretKey = new TextEncoder().encode(secret);
|
|
54
|
+
async toJwt({ token }) {
|
|
55
|
+
const secretKey = new TextEncoder().encode(token);
|
|
57
56
|
const payload = {
|
|
58
57
|
...this.toJson(),
|
|
59
58
|
...this.extra,
|
|
@@ -75,13 +74,9 @@ class ParticipantToken {
|
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
76
|
static async fromJwt(jwtStr, options) {
|
|
78
|
-
const { token, verify = true } = options
|
|
77
|
+
const { token, verify = true } = options;
|
|
79
78
|
if (verify) {
|
|
80
|
-
const
|
|
81
|
-
if (!secret) {
|
|
82
|
-
throw new Error("No secret provided to verify JWT. Provide `token` or set MESHAGENT_SECRET");
|
|
83
|
-
}
|
|
84
|
-
const secretKey = new TextEncoder().encode(secret);
|
|
79
|
+
const secretKey = new TextEncoder().encode(token);
|
|
85
80
|
const { payload } = await (0, jose_1.jwtVerify)(jwtStr, secretKey, {
|
|
86
81
|
algorithms: ["HS256"],
|
|
87
82
|
});
|
|
@@ -75,7 +75,11 @@ export declare class Protocol {
|
|
|
75
75
|
getNextMessageId(): number;
|
|
76
76
|
send(type: string, data: Uint8Array, id?: number): Promise<void>;
|
|
77
77
|
sendJson(object: any): Promise<void>;
|
|
78
|
-
start(onMessage?:
|
|
78
|
+
start({ onMessage, onDone, onError }?: {
|
|
79
|
+
onMessage?: MessageHandler;
|
|
80
|
+
onDone?: () => void;
|
|
81
|
+
onError?: (error: any) => void;
|
|
82
|
+
}): void;
|
|
79
83
|
dispose(): void;
|
|
80
84
|
onDataReceived(dataPacket: Uint8Array): void;
|
|
81
85
|
}
|
package/dist/browser/protocol.js
CHANGED
|
@@ -168,6 +168,11 @@ class Protocol {
|
|
|
168
168
|
}
|
|
169
169
|
async handleMessage(messageId, type, data) {
|
|
170
170
|
const handler = this.handlers[type] ?? this.handlers["*"];
|
|
171
|
+
if (!handler) {
|
|
172
|
+
const d = data ? (0, utils_1.unpackMessage)(data) : null;
|
|
173
|
+
console.warn(`No handler for message type ${type}; data: ${d}`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
171
176
|
await handler(this, messageId, type, data);
|
|
172
177
|
}
|
|
173
178
|
getNextMessageId() {
|
|
@@ -181,11 +186,11 @@ class Protocol {
|
|
|
181
186
|
async sendJson(object) {
|
|
182
187
|
return await this.send("application/json", utils_1.encoder.encode(JSON.stringify(object)));
|
|
183
188
|
}
|
|
184
|
-
start(onMessage =
|
|
189
|
+
start({ onMessage, onDone, onError } = {}) {
|
|
185
190
|
if (onMessage != null) {
|
|
186
191
|
this.addHandler("*", onMessage);
|
|
187
192
|
}
|
|
188
|
-
this.channel.start(this.onDataReceived.bind(this), {});
|
|
193
|
+
this.channel.start(this.onDataReceived.bind(this), { onDone, onError });
|
|
189
194
|
this._iterator?.return(null);
|
|
190
195
|
(async () => {
|
|
191
196
|
this._iterator = this._send.stream();
|
|
@@ -30,7 +30,10 @@ export declare class RoomClient {
|
|
|
30
30
|
});
|
|
31
31
|
get localParticipant(): LocalParticipant | null;
|
|
32
32
|
get ready(): Promise<boolean>;
|
|
33
|
-
start(
|
|
33
|
+
start({ onDone, onError }?: {
|
|
34
|
+
onDone?: () => void;
|
|
35
|
+
onError?: (error: Error) => void;
|
|
36
|
+
}): Promise<void>;
|
|
34
37
|
dispose(): void;
|
|
35
38
|
sendRequest(type: string, request: RequestHeader, data?: Uint8Array): Promise<Response>;
|
|
36
39
|
private _handleResponse;
|
|
@@ -21,9 +21,13 @@ export declare class SyncClient extends EventEmitter<SyncClientEvent> {
|
|
|
21
21
|
constructor({ room }: {
|
|
22
22
|
room: RoomClient;
|
|
23
23
|
});
|
|
24
|
-
start(
|
|
24
|
+
start({ onDone, onError }?: {
|
|
25
|
+
onDone?: () => void;
|
|
26
|
+
onError?: (error: Error) => void;
|
|
27
|
+
}): void;
|
|
25
28
|
dispose(): void;
|
|
26
29
|
private _handleSync;
|
|
30
|
+
private _handleStatus;
|
|
27
31
|
create(path: string, json?: Record<string, any>): Promise<void>;
|
|
28
32
|
open(path: string, { create }?: {
|
|
29
33
|
create?: boolean;
|
|
@@ -24,9 +24,10 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
24
24
|
this._connectedDocuments = {};
|
|
25
25
|
this.client = room;
|
|
26
26
|
this.client.protocol.addHandler("room.sync", this._handleSync.bind(this));
|
|
27
|
+
this.client.protocol.addHandler("room.status", this._handleStatus.bind(this));
|
|
27
28
|
}
|
|
28
|
-
start() {
|
|
29
|
-
this.client.protocol.start();
|
|
29
|
+
start({ onDone, onError } = {}) {
|
|
30
|
+
this.client.protocol.start({ onDone, onError });
|
|
30
31
|
(async () => {
|
|
31
32
|
for await (const message of this._changesToSync.stream) {
|
|
32
33
|
await this.client.sendRequest("room.sync", { path: message.path }, utils_1.encoder.encode(message.base64));
|
|
@@ -60,6 +61,11 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
60
61
|
throw new room_server_client_1.RoomServerException(`received change for a document that is not connected: ${path}`);
|
|
61
62
|
}
|
|
62
63
|
}
|
|
64
|
+
async _handleStatus(protocol, messageId, data, bytes) {
|
|
65
|
+
const headerStr = (0, utils_1.splitMessageHeader)(bytes || new Uint8Array());
|
|
66
|
+
const header = JSON.parse(headerStr);
|
|
67
|
+
this.emit("status", header.status);
|
|
68
|
+
}
|
|
63
69
|
async create(path, json) {
|
|
64
70
|
await this.client.sendRequest("room.create", { path, json });
|
|
65
71
|
}
|
|
@@ -99,6 +105,11 @@ class SyncClient extends event_emitter_1.EventEmitter {
|
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
async close(path) {
|
|
108
|
+
const pending = this._connectingDocuments[path];
|
|
109
|
+
if (pending) {
|
|
110
|
+
await pending;
|
|
111
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
112
|
+
}
|
|
102
113
|
const rc = this._connectedDocuments[path];
|
|
103
114
|
if (!rc) {
|
|
104
115
|
throw new room_server_client_1.RoomServerException(`Not connected to ${path}`);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { RoomClient } from "./room-client";
|
|
2
|
+
import { Response } from "./response";
|
|
3
|
+
import { Requirement } from "./requirement";
|
|
4
|
+
export declare class AgentDescription {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly title: string;
|
|
7
|
+
readonly description: string;
|
|
8
|
+
readonly outputSchema?: Record<string, any>;
|
|
9
|
+
readonly inputSchema?: Record<string, any>;
|
|
10
|
+
readonly requires: Requirement[];
|
|
11
|
+
readonly labels: string[];
|
|
12
|
+
readonly supportsTools: boolean;
|
|
13
|
+
constructor({ name, title, description, outputSchema, inputSchema, requires, labels, supportsTools, }: {
|
|
14
|
+
name: string;
|
|
15
|
+
title: string;
|
|
16
|
+
description: string;
|
|
17
|
+
outputSchema?: Record<string, any>;
|
|
18
|
+
inputSchema?: Record<string, any>;
|
|
19
|
+
requires: Requirement[];
|
|
20
|
+
labels: string[];
|
|
21
|
+
supportsTools: boolean;
|
|
22
|
+
});
|
|
23
|
+
static fromJson(a: Record<string, any>): AgentDescription;
|
|
24
|
+
}
|
|
25
|
+
export declare class ToolDescription {
|
|
26
|
+
title: string;
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
inputSchema: Record<string, any>;
|
|
30
|
+
defs?: Record<string, any>;
|
|
31
|
+
thumbnailUrl?: string;
|
|
32
|
+
constructor({ title, name, description, inputSchema, thumbnailUrl, defs }: {
|
|
33
|
+
title: string;
|
|
34
|
+
name: string;
|
|
35
|
+
description: string;
|
|
36
|
+
inputSchema: Record<string, any>;
|
|
37
|
+
thumbnailUrl?: string;
|
|
38
|
+
defs?: Record<string, any>;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export declare class ToolkitDescription {
|
|
42
|
+
readonly title: string;
|
|
43
|
+
readonly name: string;
|
|
44
|
+
readonly description: string;
|
|
45
|
+
readonly tools: ToolDescription[];
|
|
46
|
+
readonly thumbnailUrl?: string;
|
|
47
|
+
private _byName;
|
|
48
|
+
constructor({ title, name, description, tools, thumbnailUrl }: {
|
|
49
|
+
title: string;
|
|
50
|
+
name: string;
|
|
51
|
+
description: string;
|
|
52
|
+
tools: ToolDescription[];
|
|
53
|
+
thumbnailUrl?: string;
|
|
54
|
+
});
|
|
55
|
+
getTool(name: string): ToolDescription | undefined;
|
|
56
|
+
static fromJson(json: Record<string, any>, opts?: {
|
|
57
|
+
name?: string;
|
|
58
|
+
}): ToolkitDescription;
|
|
59
|
+
}
|
|
60
|
+
export declare class ToolkitConfiguration {
|
|
61
|
+
name: string;
|
|
62
|
+
use?: string[] | undefined;
|
|
63
|
+
constructor(name: string, use?: string[] | undefined);
|
|
64
|
+
toJson(): Record<string, any>;
|
|
65
|
+
}
|
|
66
|
+
export declare class AgentsClient {
|
|
67
|
+
private client;
|
|
68
|
+
constructor({ room }: {
|
|
69
|
+
room: RoomClient;
|
|
70
|
+
});
|
|
71
|
+
call(params: {
|
|
72
|
+
name: string;
|
|
73
|
+
url: string;
|
|
74
|
+
arguments: Record<string, any>;
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
ask(params: {
|
|
77
|
+
agentName: string;
|
|
78
|
+
toolkits?: ToolkitConfiguration[];
|
|
79
|
+
arguments: Record<string, any>;
|
|
80
|
+
}): Promise<Record<string, any>>;
|
|
81
|
+
listToolkits(): Promise<ToolkitDescription[]>;
|
|
82
|
+
listAgents(): Promise<AgentDescription[]>;
|
|
83
|
+
invokeTool(params: {
|
|
84
|
+
toolkit: string;
|
|
85
|
+
tool: string;
|
|
86
|
+
arguments: Record<string, any>;
|
|
87
|
+
}): Promise<Response>;
|
|
88
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { RequiredToolkit, RequiredSchema } from "./requirement";
|
|
2
|
+
export class AgentDescription {
|
|
3
|
+
constructor({ name, title, description, outputSchema, inputSchema, requires, labels, supportsTools, }) {
|
|
4
|
+
this.name = name;
|
|
5
|
+
this.title = title;
|
|
6
|
+
this.description = description;
|
|
7
|
+
this.outputSchema = outputSchema;
|
|
8
|
+
this.inputSchema = inputSchema;
|
|
9
|
+
this.requires = requires;
|
|
10
|
+
this.labels = labels;
|
|
11
|
+
this.supportsTools = supportsTools;
|
|
12
|
+
}
|
|
13
|
+
static fromJson(a) {
|
|
14
|
+
let requires = [];
|
|
15
|
+
if (Array.isArray(a["requires"])) {
|
|
16
|
+
requires = a["requires"].map((e) => {
|
|
17
|
+
if (e["toolkit"] != null) {
|
|
18
|
+
return RequiredToolkit.fromJson(e);
|
|
19
|
+
}
|
|
20
|
+
if (e["schema"] != null) {
|
|
21
|
+
return RequiredSchema.fromJson(e);
|
|
22
|
+
}
|
|
23
|
+
throw new Error("Invalid requirement object");
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
let labels = [];
|
|
27
|
+
if (Array.isArray(a["labels"])) {
|
|
28
|
+
labels = a["labels"].filter((item) => typeof item === "string");
|
|
29
|
+
}
|
|
30
|
+
return new AgentDescription({
|
|
31
|
+
name: a["name"],
|
|
32
|
+
title: a["title"] ?? "",
|
|
33
|
+
description: a["description"] ?? "",
|
|
34
|
+
inputSchema: a["input_schema"] ?? undefined,
|
|
35
|
+
outputSchema: a["output_schema"] ?? undefined,
|
|
36
|
+
requires,
|
|
37
|
+
supportsTools: a["supports_tools"] === true,
|
|
38
|
+
labels,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class ToolDescription {
|
|
43
|
+
constructor({ title, name, description, inputSchema, thumbnailUrl, defs }) {
|
|
44
|
+
this.title = title;
|
|
45
|
+
this.name = name;
|
|
46
|
+
this.description = description;
|
|
47
|
+
this.inputSchema = inputSchema;
|
|
48
|
+
this.thumbnailUrl = thumbnailUrl;
|
|
49
|
+
this.defs = defs;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class ToolkitDescription {
|
|
53
|
+
constructor({ title, name, description, tools, thumbnailUrl }) {
|
|
54
|
+
this.title = title;
|
|
55
|
+
this.name = name;
|
|
56
|
+
this.description = description;
|
|
57
|
+
this.tools = tools;
|
|
58
|
+
this.thumbnailUrl = thumbnailUrl;
|
|
59
|
+
this._byName = new Map(this.tools.map((tool) => [tool.name, tool]));
|
|
60
|
+
}
|
|
61
|
+
getTool(name) {
|
|
62
|
+
return this._byName.get(name);
|
|
63
|
+
}
|
|
64
|
+
static fromJson(json, opts) {
|
|
65
|
+
const { name } = opts ?? {};
|
|
66
|
+
const title = json["title"] ?? "";
|
|
67
|
+
const finalName = name ?? json["name"] ?? "";
|
|
68
|
+
const description = json["description"] ?? "";
|
|
69
|
+
const thumbnailUrl = json["thumbnail_url"] ?? undefined;
|
|
70
|
+
const toolsList = [];
|
|
71
|
+
if (Array.isArray(json["tools"])) {
|
|
72
|
+
for (const tool of json["tools"]) {
|
|
73
|
+
toolsList.push(new ToolDescription({
|
|
74
|
+
title: tool["title"],
|
|
75
|
+
name: tool["name"],
|
|
76
|
+
description: tool["description"],
|
|
77
|
+
inputSchema: tool["input_schema"],
|
|
78
|
+
thumbnailUrl: tool["thumbnail_url"],
|
|
79
|
+
defs: tool["defs"],
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (typeof json["tools"] === "object" && json["tools"] !== null) {
|
|
84
|
+
const toolsMap = json["tools"];
|
|
85
|
+
for (const toolName of Object.keys(toolsMap)) {
|
|
86
|
+
const tool = toolsMap[toolName];
|
|
87
|
+
toolsList.push(new ToolDescription({
|
|
88
|
+
title: tool["title"],
|
|
89
|
+
name: toolName,
|
|
90
|
+
description: tool["description"],
|
|
91
|
+
inputSchema: tool["input_schema"],
|
|
92
|
+
thumbnailUrl: tool["thumbnail_url"],
|
|
93
|
+
defs: tool["defs"],
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return new ToolkitDescription({
|
|
98
|
+
title,
|
|
99
|
+
name: finalName,
|
|
100
|
+
description,
|
|
101
|
+
thumbnailUrl,
|
|
102
|
+
tools: toolsList,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export class ToolkitConfiguration {
|
|
107
|
+
constructor(name, use) {
|
|
108
|
+
this.name = name;
|
|
109
|
+
this.use = use;
|
|
110
|
+
}
|
|
111
|
+
toJson() {
|
|
112
|
+
if (!this.use) {
|
|
113
|
+
return {
|
|
114
|
+
[this.name]: {},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return {
|
|
119
|
+
[this.name]: {
|
|
120
|
+
use: this.use.reduce((acc, tool) => {
|
|
121
|
+
acc[tool] = {};
|
|
122
|
+
return acc;
|
|
123
|
+
}, {}),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export class AgentsClient {
|
|
130
|
+
constructor({ room }) {
|
|
131
|
+
this.client = room;
|
|
132
|
+
}
|
|
133
|
+
async call(params) {
|
|
134
|
+
await this.client.sendRequest("agent.call", params);
|
|
135
|
+
}
|
|
136
|
+
async ask(params) {
|
|
137
|
+
const { agentName, toolkits = [], arguments: args } = params;
|
|
138
|
+
const usedToolkits = {};
|
|
139
|
+
for (const t of toolkits) {
|
|
140
|
+
Object.assign(usedToolkits, t.toJson());
|
|
141
|
+
}
|
|
142
|
+
const result = (await this.client.sendRequest("agent.ask", {
|
|
143
|
+
agent: agentName,
|
|
144
|
+
arguments: args,
|
|
145
|
+
toolkits: usedToolkits,
|
|
146
|
+
}));
|
|
147
|
+
return result.json["answer"];
|
|
148
|
+
}
|
|
149
|
+
async listToolkits() {
|
|
150
|
+
const result = (await this.client.sendRequest("agent.list_toolkits", {}));
|
|
151
|
+
const tools = result.json["tools"];
|
|
152
|
+
const toolkits = [];
|
|
153
|
+
for (const name of Object.keys(tools)) {
|
|
154
|
+
const data = tools[name];
|
|
155
|
+
toolkits.push(ToolkitDescription.fromJson(data, { name }));
|
|
156
|
+
}
|
|
157
|
+
return toolkits;
|
|
158
|
+
}
|
|
159
|
+
async listAgents() {
|
|
160
|
+
const result = (await this.client.sendRequest("agent.list_agents", {}));
|
|
161
|
+
return (result.json["agents"] || []).map(AgentDescription.fromJson);
|
|
162
|
+
}
|
|
163
|
+
async invokeTool(params) {
|
|
164
|
+
return await this.client.sendRequest("agent.invoke_tool", params);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { RoomClient } from "./room-client";
|
|
2
|
+
import { RequiredToolkit } from "./requirement";
|
|
3
|
+
import { Response } from "./response";
|
|
4
|
+
export declare class AgentChatContext {
|
|
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 AgentCallContext {
|
|
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
|
+
}
|
|
31
|
+
export declare abstract class Tool {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly description: string;
|
|
34
|
+
readonly title: string;
|
|
35
|
+
readonly inputSchema: Record<string, any>;
|
|
36
|
+
readonly thumbnailUrl?: string;
|
|
37
|
+
constructor({ name, description, title, inputSchema, thumbnailUrl }: {
|
|
38
|
+
name: string;
|
|
39
|
+
description: string;
|
|
40
|
+
title: string;
|
|
41
|
+
inputSchema: Record<string, any>;
|
|
42
|
+
thumbnailUrl?: string;
|
|
43
|
+
});
|
|
44
|
+
abstract execute(arguments_: Record<string, any>): Promise<Response>;
|
|
45
|
+
}
|
|
46
|
+
export declare abstract class Toolkit {
|
|
47
|
+
readonly tools: Tool[];
|
|
48
|
+
readonly rules: string[];
|
|
49
|
+
constructor({ tools, rules }: {
|
|
50
|
+
tools: Tool[];
|
|
51
|
+
rules?: string[];
|
|
52
|
+
});
|
|
53
|
+
getTool(name: string): Tool;
|
|
54
|
+
getTools(): Record<string, any>;
|
|
55
|
+
execute(name: string, args: Record<string, any>): Promise<Response>;
|
|
56
|
+
}
|
|
57
|
+
export declare abstract class RemoteToolkit extends Toolkit {
|
|
58
|
+
protected readonly client: RoomClient;
|
|
59
|
+
protected readonly name: string;
|
|
60
|
+
protected readonly title: string;
|
|
61
|
+
protected readonly description: string;
|
|
62
|
+
private _registrationId?;
|
|
63
|
+
constructor({ name, title, description, room, tools, rules }: {
|
|
64
|
+
name: string;
|
|
65
|
+
title: string;
|
|
66
|
+
description: string;
|
|
67
|
+
room: RoomClient;
|
|
68
|
+
tools: Tool[];
|
|
69
|
+
rules?: string[];
|
|
70
|
+
});
|
|
71
|
+
start({ public_: isPublic }?: {
|
|
72
|
+
public_?: boolean;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
stop(): Promise<void>;
|
|
75
|
+
private _register;
|
|
76
|
+
private _unregister;
|
|
77
|
+
private _toolCall;
|
|
78
|
+
}
|
|
79
|
+
export declare abstract class RemoteTaskRunner {
|
|
80
|
+
protected readonly client: RoomClient;
|
|
81
|
+
protected readonly name: string;
|
|
82
|
+
protected readonly description: string;
|
|
83
|
+
protected readonly inputSchema?: Record<string, any>;
|
|
84
|
+
protected readonly outputSchema?: Record<string, any>;
|
|
85
|
+
protected readonly supportsTools: boolean;
|
|
86
|
+
protected readonly required: RequiredToolkit[];
|
|
87
|
+
private _registrationId?;
|
|
88
|
+
constructor({ name, description, client, inputSchema, outputSchema, supportsTools, required, }: {
|
|
89
|
+
name: string;
|
|
90
|
+
description: string;
|
|
91
|
+
client: RoomClient;
|
|
92
|
+
inputSchema?: Record<string, any>;
|
|
93
|
+
outputSchema?: Record<string, any>;
|
|
94
|
+
supportsTools?: boolean;
|
|
95
|
+
required?: RequiredToolkit[];
|
|
96
|
+
});
|
|
97
|
+
start(): Promise<void>;
|
|
98
|
+
stop(): Promise<void>;
|
|
99
|
+
protected _register(): Promise<void>;
|
|
100
|
+
protected _unregister(): Promise<void>;
|
|
101
|
+
abstract ask(context: AgentCallContext, arguments_: Record<string, any>): Promise<Record<string, any>>;
|
|
102
|
+
private _ask;
|
|
103
|
+
}
|