@meshagent/meshagent 0.0.30 → 0.0.31
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 +4 -1
- package/dist/browser/agent.js +6 -8
- package/dist/browser/developer-client.js +1 -1
- package/dist/browser/participant.js +1 -1
- package/dist/browser/room-client.js +3 -2
- package/dist/browser/storage-client.js +2 -4
- package/dist/browser/utils.d.ts +1 -0
- package/dist/browser/utils.js +4 -0
- package/dist/node/agent.js +6 -8
- package/dist/node/developer-client.js +1 -1
- package/dist/node/participant.js +1 -1
- package/dist/node/room-client.js +3 -2
- package/dist/node/storage-client.js +2 -4
- package/dist/node/utils.d.ts +1 -0
- package/dist/node/utils.js +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/browser/agent.js
CHANGED
|
@@ -148,8 +148,7 @@ class RemoteToolkit extends Toolkit {
|
|
|
148
148
|
}
|
|
149
149
|
async _toolCall(protocol, messageId, type, data) {
|
|
150
150
|
try {
|
|
151
|
-
const
|
|
152
|
-
const message = JSON.parse(raw);
|
|
151
|
+
const [message, _] = (0, utils_1.unpackMessage)(data);
|
|
153
152
|
const toolName = message["name"];
|
|
154
153
|
const args = message["arguments"];
|
|
155
154
|
const response = await this.execute(toolName, args);
|
|
@@ -203,8 +202,7 @@ class RemoteTaskRunner {
|
|
|
203
202
|
async _ask(protocol, messageId, msgType, data) {
|
|
204
203
|
console.info("_ask handler invoked with data", data);
|
|
205
204
|
try {
|
|
206
|
-
const
|
|
207
|
-
const message = JSON.parse(raw);
|
|
205
|
+
const [message, _] = (0, utils_1.unpackMessage)(data);
|
|
208
206
|
console.info("got message", message);
|
|
209
207
|
const jwt = message["jwt"];
|
|
210
208
|
const args = message["arguments"];
|
|
@@ -214,15 +212,15 @@ class RemoteTaskRunner {
|
|
|
214
212
|
const chat = AgentChatContext.fromJson(context_json);
|
|
215
213
|
const callContext = new AgentCallContext({ chat, jwt, api_url });
|
|
216
214
|
const answer = await this.ask(callContext, args);
|
|
217
|
-
const encoded = utils_1.
|
|
215
|
+
const encoded = (0, utils_1.packMessage)({ task_id, answer });
|
|
218
216
|
await protocol.send("agent.ask_response", encoded);
|
|
219
217
|
}
|
|
220
218
|
catch (e) {
|
|
221
|
-
const rawError =
|
|
219
|
+
const rawError = {
|
|
222
220
|
task_id: "",
|
|
223
221
|
error: String(e),
|
|
224
|
-
}
|
|
225
|
-
await protocol.send("agent.ask_response", utils_1.
|
|
222
|
+
};
|
|
223
|
+
await protocol.send("agent.ask_response", (0, utils_1.packMessage)(rawError));
|
|
226
224
|
}
|
|
227
225
|
}
|
|
228
226
|
}
|
|
@@ -11,7 +11,7 @@ class DeveloperClient extends event_emitter_1.EventEmitter {
|
|
|
11
11
|
this.client.protocol.addHandler("developer.log", this._handleDeveloperLog.bind(this));
|
|
12
12
|
}
|
|
13
13
|
async _handleDeveloperLog(protocol, messageId, type, bytes) {
|
|
14
|
-
const rawJson =
|
|
14
|
+
const [rawJson, _] = (0, utils_1.unpackMessage)(bytes || new Uint8Array());
|
|
15
15
|
const event = new room_event_1.RoomLogEvent({
|
|
16
16
|
type: rawJson["type"],
|
|
17
17
|
data: rawJson["data"],
|
|
@@ -31,7 +31,7 @@ class LocalParticipant extends Participant {
|
|
|
31
31
|
async setAttribute(name, value) {
|
|
32
32
|
this._attributes[name] = value;
|
|
33
33
|
try {
|
|
34
|
-
const payload = utils_1.
|
|
34
|
+
const payload = (0, utils_1.packMessage)({ [name]: value });
|
|
35
35
|
await this.client.protocol.send("set_attributes", payload);
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
|
@@ -85,7 +85,8 @@ class RoomClient {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
async _handleRoomReady(protocol, messageId, type, data) {
|
|
88
|
-
|
|
88
|
+
const [message, _] = (0, utils_1.unpackMessage)(data);
|
|
89
|
+
this._ready.complete(message["room_name"]);
|
|
89
90
|
}
|
|
90
91
|
_onParticipantInit(participantId, attributes) {
|
|
91
92
|
this._localParticipant = new participant_1.LocalParticipant(this, participantId);
|
|
@@ -94,7 +95,7 @@ class RoomClient {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
async _handleParticipant(protocol, messageId, type, data) {
|
|
97
|
-
const message =
|
|
98
|
+
const [message, _] = (0, utils_1.unpackMessage)(data);
|
|
98
99
|
switch (message["type"]) {
|
|
99
100
|
case "init": this._onParticipantInit(message["participantId"], message["attributes"]);
|
|
100
101
|
}
|
|
@@ -32,15 +32,13 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
32
32
|
this.client.protocol.addHandler("storage.file.updated", this._handleFileUpdated.bind(this));
|
|
33
33
|
}
|
|
34
34
|
async _handleFileUpdated(protocol, messageId, type, bytes) {
|
|
35
|
-
const
|
|
36
|
-
const data = JSON.parse(raw);
|
|
35
|
+
const [data, _] = (0, utils_1.unpackMessage)(bytes || new Uint8Array());
|
|
37
36
|
const event = new room_event_1.FileUpdatedEvent({ path: data["path"] });
|
|
38
37
|
this.client.emit(event);
|
|
39
38
|
this.emit('file.updated', event);
|
|
40
39
|
}
|
|
41
40
|
async _handleFileDeleted(protocol, messageId, type, bytes) {
|
|
42
|
-
const
|
|
43
|
-
const data = JSON.parse(raw);
|
|
41
|
+
const [data, _] = (0, utils_1.unpackMessage)(bytes || new Uint8Array());
|
|
44
42
|
const event = new room_event_1.FileDeletedEvent({ path: data["path"] });
|
|
45
43
|
this.client.emit(event);
|
|
46
44
|
this.emit('file.deleted', event);
|
package/dist/browser/utils.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare const decoder: TextDecoder;
|
|
|
4
4
|
export { encoder, decoder };
|
|
5
5
|
export declare function splitMessagePayload(packet: Uint8Array): Uint8Array;
|
|
6
6
|
export declare function splitMessageHeader(packet: Uint8Array): string;
|
|
7
|
+
export declare function unpackMessage(packet: Uint8Array): [Record<string, any>, Uint8Array];
|
|
7
8
|
export declare function packMessage(request: Record<string, any>, data?: Uint8Array): Uint8Array;
|
|
8
9
|
export declare function mergeUint8Arrays(...arrays: Uint8Array[]): Uint8Array;
|
|
9
10
|
export declare class RefCount<T> {
|
package/dist/browser/utils.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RefCount = exports.decoder = exports.encoder = void 0;
|
|
4
4
|
exports.splitMessagePayload = splitMessagePayload;
|
|
5
5
|
exports.splitMessageHeader = splitMessageHeader;
|
|
6
|
+
exports.unpackMessage = unpackMessage;
|
|
6
7
|
exports.packMessage = packMessage;
|
|
7
8
|
exports.mergeUint8Arrays = mergeUint8Arrays;
|
|
8
9
|
const text_encoding_1 = require("@kayahr/text-encoding");
|
|
@@ -21,6 +22,9 @@ function splitMessageHeader(packet) {
|
|
|
21
22
|
const payload = packet.subarray(8, 8 + headerSize);
|
|
22
23
|
return decoder.decode(payload);
|
|
23
24
|
}
|
|
25
|
+
function unpackMessage(packet) {
|
|
26
|
+
return [JSON.parse(splitMessageHeader(packet)), splitMessagePayload(packet)];
|
|
27
|
+
}
|
|
24
28
|
function packMessage(request, data) {
|
|
25
29
|
const jsonMessage = encoder.encode(JSON.stringify(request));
|
|
26
30
|
const size = jsonMessage.length;
|
package/dist/node/agent.js
CHANGED
|
@@ -148,8 +148,7 @@ class RemoteToolkit extends Toolkit {
|
|
|
148
148
|
}
|
|
149
149
|
async _toolCall(protocol, messageId, type, data) {
|
|
150
150
|
try {
|
|
151
|
-
const
|
|
152
|
-
const message = JSON.parse(raw);
|
|
151
|
+
const [message, _] = (0, utils_1.unpackMessage)(data);
|
|
153
152
|
const toolName = message["name"];
|
|
154
153
|
const args = message["arguments"];
|
|
155
154
|
const response = await this.execute(toolName, args);
|
|
@@ -203,8 +202,7 @@ class RemoteTaskRunner {
|
|
|
203
202
|
async _ask(protocol, messageId, msgType, data) {
|
|
204
203
|
console.info("_ask handler invoked with data", data);
|
|
205
204
|
try {
|
|
206
|
-
const
|
|
207
|
-
const message = JSON.parse(raw);
|
|
205
|
+
const [message, _] = (0, utils_1.unpackMessage)(data);
|
|
208
206
|
console.info("got message", message);
|
|
209
207
|
const jwt = message["jwt"];
|
|
210
208
|
const args = message["arguments"];
|
|
@@ -214,15 +212,15 @@ class RemoteTaskRunner {
|
|
|
214
212
|
const chat = AgentChatContext.fromJson(context_json);
|
|
215
213
|
const callContext = new AgentCallContext({ chat, jwt, api_url });
|
|
216
214
|
const answer = await this.ask(callContext, args);
|
|
217
|
-
const encoded = utils_1.
|
|
215
|
+
const encoded = (0, utils_1.packMessage)({ task_id, answer });
|
|
218
216
|
await protocol.send("agent.ask_response", encoded);
|
|
219
217
|
}
|
|
220
218
|
catch (e) {
|
|
221
|
-
const rawError =
|
|
219
|
+
const rawError = {
|
|
222
220
|
task_id: "",
|
|
223
221
|
error: String(e),
|
|
224
|
-
}
|
|
225
|
-
await protocol.send("agent.ask_response", utils_1.
|
|
222
|
+
};
|
|
223
|
+
await protocol.send("agent.ask_response", (0, utils_1.packMessage)(rawError));
|
|
226
224
|
}
|
|
227
225
|
}
|
|
228
226
|
}
|
|
@@ -11,7 +11,7 @@ class DeveloperClient extends event_emitter_1.EventEmitter {
|
|
|
11
11
|
this.client.protocol.addHandler("developer.log", this._handleDeveloperLog.bind(this));
|
|
12
12
|
}
|
|
13
13
|
async _handleDeveloperLog(protocol, messageId, type, bytes) {
|
|
14
|
-
const rawJson =
|
|
14
|
+
const [rawJson, _] = (0, utils_1.unpackMessage)(bytes || new Uint8Array());
|
|
15
15
|
const event = new room_event_1.RoomLogEvent({
|
|
16
16
|
type: rawJson["type"],
|
|
17
17
|
data: rawJson["data"],
|
package/dist/node/participant.js
CHANGED
|
@@ -31,7 +31,7 @@ class LocalParticipant extends Participant {
|
|
|
31
31
|
async setAttribute(name, value) {
|
|
32
32
|
this._attributes[name] = value;
|
|
33
33
|
try {
|
|
34
|
-
const payload = utils_1.
|
|
34
|
+
const payload = (0, utils_1.packMessage)({ [name]: value });
|
|
35
35
|
await this.client.protocol.send("set_attributes", payload);
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
package/dist/node/room-client.js
CHANGED
|
@@ -85,7 +85,8 @@ class RoomClient {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
async _handleRoomReady(protocol, messageId, type, data) {
|
|
88
|
-
|
|
88
|
+
const [message, _] = (0, utils_1.unpackMessage)(data);
|
|
89
|
+
this._ready.complete(message["room_name"]);
|
|
89
90
|
}
|
|
90
91
|
_onParticipantInit(participantId, attributes) {
|
|
91
92
|
this._localParticipant = new participant_1.LocalParticipant(this, participantId);
|
|
@@ -94,7 +95,7 @@ class RoomClient {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
async _handleParticipant(protocol, messageId, type, data) {
|
|
97
|
-
const message =
|
|
98
|
+
const [message, _] = (0, utils_1.unpackMessage)(data);
|
|
98
99
|
switch (message["type"]) {
|
|
99
100
|
case "init": this._onParticipantInit(message["participantId"], message["attributes"]);
|
|
100
101
|
}
|
|
@@ -32,15 +32,13 @@ class StorageClient extends event_emitter_1.EventEmitter {
|
|
|
32
32
|
this.client.protocol.addHandler("storage.file.updated", this._handleFileUpdated.bind(this));
|
|
33
33
|
}
|
|
34
34
|
async _handleFileUpdated(protocol, messageId, type, bytes) {
|
|
35
|
-
const
|
|
36
|
-
const data = JSON.parse(raw);
|
|
35
|
+
const [data, _] = (0, utils_1.unpackMessage)(bytes || new Uint8Array());
|
|
37
36
|
const event = new room_event_1.FileUpdatedEvent({ path: data["path"] });
|
|
38
37
|
this.client.emit(event);
|
|
39
38
|
this.emit('file.updated', event);
|
|
40
39
|
}
|
|
41
40
|
async _handleFileDeleted(protocol, messageId, type, bytes) {
|
|
42
|
-
const
|
|
43
|
-
const data = JSON.parse(raw);
|
|
41
|
+
const [data, _] = (0, utils_1.unpackMessage)(bytes || new Uint8Array());
|
|
44
42
|
const event = new room_event_1.FileDeletedEvent({ path: data["path"] });
|
|
45
43
|
this.client.emit(event);
|
|
46
44
|
this.emit('file.deleted', event);
|
package/dist/node/utils.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare const decoder: TextDecoder;
|
|
|
4
4
|
export { encoder, decoder };
|
|
5
5
|
export declare function splitMessagePayload(packet: Uint8Array): Uint8Array;
|
|
6
6
|
export declare function splitMessageHeader(packet: Uint8Array): string;
|
|
7
|
+
export declare function unpackMessage(packet: Uint8Array): [Record<string, any>, Uint8Array];
|
|
7
8
|
export declare function packMessage(request: Record<string, any>, data?: Uint8Array): Uint8Array;
|
|
8
9
|
export declare function mergeUint8Arrays(...arrays: Uint8Array[]): Uint8Array;
|
|
9
10
|
export declare class RefCount<T> {
|
package/dist/node/utils.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RefCount = exports.decoder = exports.encoder = void 0;
|
|
4
4
|
exports.splitMessagePayload = splitMessagePayload;
|
|
5
5
|
exports.splitMessageHeader = splitMessageHeader;
|
|
6
|
+
exports.unpackMessage = unpackMessage;
|
|
6
7
|
exports.packMessage = packMessage;
|
|
7
8
|
exports.mergeUint8Arrays = mergeUint8Arrays;
|
|
8
9
|
const text_encoding_1 = require("@kayahr/text-encoding");
|
|
@@ -21,6 +22,9 @@ function splitMessageHeader(packet) {
|
|
|
21
22
|
const payload = packet.subarray(8, 8 + headerSize);
|
|
22
23
|
return decoder.decode(payload);
|
|
23
24
|
}
|
|
25
|
+
function unpackMessage(packet) {
|
|
26
|
+
return [JSON.parse(splitMessageHeader(packet)), splitMessagePayload(packet)];
|
|
27
|
+
}
|
|
24
28
|
function packMessage(request, data) {
|
|
25
29
|
const jsonMessage = encoder.encode(JSON.stringify(request));
|
|
26
30
|
const size = jsonMessage.length;
|