@meshagent/meshagent 0.42.2 → 0.43.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 +13 -0
- package/dist/browser/agent-client.d.ts +4 -4
- package/dist/browser/agent-client.js +16 -16
- package/dist/browser/agent.d.ts +6 -6
- package/dist/browser/agent.js +57 -57
- package/dist/browser/api_keys.js +7 -3
- package/dist/browser/containers-client.d.ts +3 -3
- package/dist/browser/containers-client.js +76 -76
- package/dist/browser/datasets-client.d.ts +1 -1
- package/dist/browser/datasets-client.js +83 -83
- package/dist/browser/developer-client.d.ts +3 -3
- package/dist/browser/developer-client.js +11 -11
- package/dist/browser/document.d.ts +2 -2
- package/dist/browser/document.js +3 -3
- package/dist/browser/helpers.d.ts +4 -4
- package/dist/browser/helpers.js +9 -9
- package/dist/browser/index.d.ts +35 -35
- package/dist/browser/index.js +35 -35
- package/dist/browser/memory-client.d.ts +1 -1
- package/dist/browser/memory-client.js +6 -6
- package/dist/browser/meshagent-client.d.ts +1 -1
- package/dist/browser/meshagent-client.js +78 -78
- package/dist/browser/messaging-client.d.ts +4 -4
- package/dist/browser/messaging-client.js +33 -33
- package/dist/browser/participant-token.d.ts +1 -1
- package/dist/browser/participant-token.js +5 -5
- package/dist/browser/participant.d.ts +1 -1
- package/dist/browser/protocol.d.ts +7 -4
- package/dist/browser/protocol.js +36 -20
- package/dist/browser/queues-client.d.ts +1 -1
- package/dist/browser/queues-client.js +10 -10
- package/dist/browser/response.js +11 -11
- package/dist/browser/room-client.d.ts +23 -17
- package/dist/browser/room-client.js +138 -130
- package/dist/browser/room-server-client.d.ts +2 -2
- package/dist/browser/room-server-client.js +10 -10
- package/dist/browser/secrets-client.d.ts +3 -3
- package/dist/browser/secrets-client.js +30 -30
- package/dist/browser/services-client.d.ts +2 -2
- package/dist/browser/services-client.js +8 -8
- package/dist/browser/storage-client.d.ts +5 -5
- package/dist/browser/storage-client.js +30 -30
- package/dist/browser/sync-client.d.ts +4 -4
- package/dist/browser/sync-client.js +38 -38
- package/dist/browser/toolkit-config.d.ts +3 -3
- package/dist/esm/agent-client.d.ts +4 -4
- package/dist/esm/agent-client.js +19 -25
- package/dist/esm/agent.d.ts +6 -6
- package/dist/esm/agent.js +73 -93
- package/dist/esm/api_keys.js +12 -21
- package/dist/esm/client.js +7 -13
- package/dist/esm/completer.js +1 -5
- package/dist/esm/containers-client.d.ts +3 -3
- package/dist/esm/containers-client.js +82 -87
- package/dist/esm/datasets-client.d.ts +1 -1
- package/dist/esm/datasets-client.js +101 -111
- package/dist/esm/developer-client.d.ts +3 -3
- package/dist/esm/developer-client.js +11 -15
- package/dist/esm/document.d.ts +2 -2
- package/dist/esm/document.js +11 -20
- package/dist/esm/entrypoint.js +1 -12
- package/dist/esm/event-emitter.js +1 -5
- package/dist/esm/helpers.d.ts +4 -4
- package/dist/esm/helpers.js +15 -23
- package/dist/esm/index.d.ts +35 -35
- package/dist/esm/index.js +35 -51
- package/dist/esm/memory-client.d.ts +1 -1
- package/dist/esm/memory-client.js +7 -11
- package/dist/esm/meshagent-client.d.ts +1 -1
- package/dist/esm/meshagent-client.js +79 -83
- package/dist/esm/messaging-client.d.ts +4 -4
- package/dist/esm/messaging-client.js +33 -37
- package/dist/esm/oauth-scopes.js +2 -5
- package/dist/esm/participant-token.d.ts +1 -1
- package/dist/esm/participant-token.js +34 -62
- package/dist/esm/participant.d.ts +1 -1
- package/dist/esm/participant.js +3 -9
- package/dist/esm/protocol.d.ts +7 -4
- package/dist/esm/protocol.js +48 -46
- package/dist/esm/queues-client.d.ts +1 -1
- package/dist/esm/queues-client.js +12 -17
- package/dist/esm/requirement.js +4 -11
- package/dist/esm/response.js +22 -34
- package/dist/esm/room-client.d.ts +23 -17
- package/dist/esm/room-client.js +140 -137
- package/dist/esm/room-event.js +9 -21
- package/dist/esm/room-server-client.d.ts +2 -2
- package/dist/esm/room-server-client.js +13 -18
- package/dist/esm/runtime.js +1 -10
- package/dist/esm/schema.js +9 -18
- package/dist/esm/secrets-client.d.ts +3 -3
- package/dist/esm/secrets-client.js +31 -35
- package/dist/esm/services-client.d.ts +2 -2
- package/dist/esm/services-client.js +9 -13
- package/dist/esm/storage-client.d.ts +5 -5
- package/dist/esm/storage-client.js +32 -38
- package/dist/esm/stream-controller.js +1 -5
- package/dist/esm/sync-client.d.ts +4 -4
- package/dist/esm/sync-client.js +38 -42
- package/dist/esm/tool-content-type.js +1 -5
- package/dist/esm/toolkit-config.d.ts +3 -3
- package/dist/esm/toolkit-config.js +5 -13
- package/dist/esm/utils.js +10 -20
- package/dist/esm/version.js +1 -4
- package/dist/node/agent-client.d.ts +4 -4
- package/dist/node/agent-client.js +16 -16
- package/dist/node/agent.d.ts +6 -6
- package/dist/node/agent.js +57 -57
- package/dist/node/api_keys.js +7 -3
- package/dist/node/containers-client.d.ts +3 -3
- package/dist/node/containers-client.js +76 -76
- package/dist/node/datasets-client.d.ts +1 -1
- package/dist/node/datasets-client.js +83 -83
- package/dist/node/developer-client.d.ts +3 -3
- package/dist/node/developer-client.js +11 -11
- package/dist/node/document.d.ts +2 -2
- package/dist/node/document.js +3 -3
- package/dist/node/helpers.d.ts +4 -4
- package/dist/node/helpers.js +9 -9
- package/dist/node/index.d.ts +35 -35
- package/dist/node/index.js +35 -35
- package/dist/node/memory-client.d.ts +1 -1
- package/dist/node/memory-client.js +6 -6
- package/dist/node/meshagent-client.d.ts +1 -1
- package/dist/node/meshagent-client.js +78 -78
- package/dist/node/messaging-client.d.ts +4 -4
- package/dist/node/messaging-client.js +33 -33
- package/dist/node/participant-token.d.ts +1 -1
- package/dist/node/participant-token.js +5 -5
- package/dist/node/participant.d.ts +1 -1
- package/dist/node/protocol.d.ts +7 -4
- package/dist/node/protocol.js +36 -20
- package/dist/node/queues-client.d.ts +1 -1
- package/dist/node/queues-client.js +10 -10
- package/dist/node/response.js +11 -11
- package/dist/node/room-client.d.ts +23 -17
- package/dist/node/room-client.js +138 -130
- package/dist/node/room-server-client.d.ts +2 -2
- package/dist/node/room-server-client.js +10 -10
- package/dist/node/secrets-client.d.ts +3 -3
- package/dist/node/secrets-client.js +30 -30
- package/dist/node/services-client.d.ts +2 -2
- package/dist/node/services-client.js +8 -8
- package/dist/node/storage-client.d.ts +5 -5
- package/dist/node/storage-client.js +30 -30
- package/dist/node/sync-client.d.ts +4 -4
- package/dist/node/sync-client.js +38 -38
- package/dist/node/toolkit-config.d.ts +3 -3
- package/package.json +11 -5
- package/dist/browser/lk-client.d.ts +0 -18
- package/dist/browser/lk-client.js +0 -33
- package/dist/browser/lk-protocol.d.ts +0 -22
- package/dist/browser/lk-protocol.js +0 -37
- package/dist/esm/lk-client.d.ts +0 -18
- package/dist/esm/lk-client.js +0 -33
- package/dist/esm/lk-protocol.d.ts +0 -22
- package/dist/esm/lk-protocol.js +0 -37
- package/dist/node/lk-client.d.ts +0 -18
- package/dist/node/lk-client.js +0 -33
- package/dist/node/lk-protocol.d.ts +0 -22
- package/dist/node/lk-protocol.js +0 -37
package/dist/esm/agent.js
CHANGED
|
@@ -1,71 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const room_event_1 = require("./room-event");
|
|
10
|
-
const participant_1 = require("./participant");
|
|
11
|
-
const stream_controller_1 = require("./stream-controller");
|
|
12
|
-
class InvalidToolDataException extends room_server_client_1.RoomServerException {
|
|
1
|
+
import { BinaryContent, ControlCloseStatus, ControlContent, EmptyContent, ErrorContent, FileContent, JsonContent, LinkContent, TextContent, unpackContent, } from "./response.js";
|
|
2
|
+
import { RoomServerException } from "./room-server-client.js";
|
|
3
|
+
import { ToolContentSpec } from "./tool-content-type.js";
|
|
4
|
+
import { packMessage, unpackMessage } from "./utils.js";
|
|
5
|
+
import { RoomStatusEvent } from "./room-event.js";
|
|
6
|
+
import { RemoteParticipant } from "./participant.js";
|
|
7
|
+
import { StreamController } from "./stream-controller.js";
|
|
8
|
+
export class InvalidToolDataException extends RoomServerException {
|
|
13
9
|
constructor(message) {
|
|
14
10
|
super(message);
|
|
15
11
|
this.name = "InvalidToolDataException";
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
class ToolContext {
|
|
14
|
+
export class ToolContext {
|
|
20
15
|
constructor({ caller, onBehalfOf } = {}) {
|
|
21
16
|
this.caller = caller;
|
|
22
17
|
this.onBehalfOf = onBehalfOf;
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
class RoomToolContext extends ToolContext {
|
|
20
|
+
export class RoomToolContext extends ToolContext {
|
|
27
21
|
constructor({ room, caller, onBehalfOf }) {
|
|
28
22
|
super({ caller, onBehalfOf });
|
|
29
23
|
this.room = room;
|
|
30
24
|
}
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
class ToolInput {
|
|
26
|
+
export class ToolInput {
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
class ToolContentInput extends ToolInput {
|
|
28
|
+
export class ToolContentInput extends ToolInput {
|
|
37
29
|
constructor(content) {
|
|
38
30
|
super();
|
|
39
31
|
this.content = content;
|
|
40
32
|
}
|
|
41
33
|
}
|
|
42
|
-
|
|
43
|
-
class ToolStreamInput extends ToolInput {
|
|
34
|
+
export class ToolStreamInput extends ToolInput {
|
|
44
35
|
constructor(stream) {
|
|
45
36
|
super();
|
|
46
37
|
this.stream = stream;
|
|
47
38
|
}
|
|
48
39
|
}
|
|
49
|
-
|
|
50
|
-
class ToolCallOutput {
|
|
40
|
+
export class ToolCallOutput {
|
|
51
41
|
}
|
|
52
|
-
|
|
53
|
-
class ToolContentOutput extends ToolCallOutput {
|
|
42
|
+
export class ToolContentOutput extends ToolCallOutput {
|
|
54
43
|
constructor(content) {
|
|
55
44
|
super();
|
|
56
45
|
this.content = content;
|
|
57
46
|
}
|
|
58
47
|
}
|
|
59
|
-
|
|
60
|
-
class ToolStreamOutput extends ToolCallOutput {
|
|
48
|
+
export class ToolStreamOutput extends ToolCallOutput {
|
|
61
49
|
constructor(stream, { inputClosed } = {}) {
|
|
62
50
|
super();
|
|
63
51
|
this.stream = stream;
|
|
64
52
|
this.inputClosed = inputClosed;
|
|
65
53
|
}
|
|
66
54
|
}
|
|
67
|
-
|
|
68
|
-
class BaseTool {
|
|
55
|
+
export class BaseTool {
|
|
69
56
|
constructor({ name, description, title, inputSchema, inputSpec, outputSpec, outputSchema, defs }) {
|
|
70
57
|
this.name = name;
|
|
71
58
|
this.description = description;
|
|
@@ -77,23 +64,20 @@ class BaseTool {
|
|
|
77
64
|
this.defs = defs;
|
|
78
65
|
}
|
|
79
66
|
}
|
|
80
|
-
|
|
81
|
-
class FunctionTool extends BaseTool {
|
|
67
|
+
export class FunctionTool extends BaseTool {
|
|
82
68
|
async *executeStream(context, arguments_) {
|
|
83
69
|
yield await this.execute(context, arguments_);
|
|
84
70
|
}
|
|
85
71
|
}
|
|
86
|
-
|
|
87
|
-
class ContentTool extends BaseTool {
|
|
72
|
+
export class ContentTool extends BaseTool {
|
|
88
73
|
}
|
|
89
|
-
|
|
90
|
-
class Tool extends BaseTool {
|
|
74
|
+
export class Tool extends BaseTool {
|
|
91
75
|
constructor(params) {
|
|
92
76
|
const inputSpec = params.inputSpec !== undefined && params.inputSchema !== undefined
|
|
93
|
-
? new
|
|
77
|
+
? new ToolContentSpec({ types: [...params.inputSpec.types], stream: params.inputSpec.stream, schema: params.inputSchema })
|
|
94
78
|
: params.inputSpec;
|
|
95
79
|
const outputSpec = params.outputSpec !== undefined && params.outputSchema !== undefined
|
|
96
|
-
? new
|
|
80
|
+
? new ToolContentSpec({ types: [...params.outputSpec.types], stream: params.outputSpec.stream, schema: params.outputSchema })
|
|
97
81
|
: params.outputSpec;
|
|
98
82
|
super({
|
|
99
83
|
name: params.name,
|
|
@@ -101,53 +85,52 @@ class Tool extends BaseTool {
|
|
|
101
85
|
title: params.title,
|
|
102
86
|
inputSchema: params.inputSchema,
|
|
103
87
|
inputSpec: inputSpec ?? (params.inputSchema !== undefined
|
|
104
|
-
? new
|
|
88
|
+
? new ToolContentSpec({ types: ["json"], stream: false, schema: params.inputSchema })
|
|
105
89
|
: undefined),
|
|
106
90
|
outputSpec: outputSpec ?? (params.outputSchema !== undefined
|
|
107
|
-
? new
|
|
91
|
+
? new ToolContentSpec({ types: ["json"], stream: false, schema: params.outputSchema })
|
|
108
92
|
: undefined),
|
|
109
93
|
outputSchema: params.outputSchema,
|
|
110
94
|
defs: params.defs,
|
|
111
95
|
});
|
|
112
96
|
}
|
|
113
97
|
}
|
|
114
|
-
exports.Tool = Tool;
|
|
115
98
|
function isRecord(value) {
|
|
116
99
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
117
100
|
}
|
|
118
101
|
function contentType(content) {
|
|
119
|
-
if (content instanceof
|
|
102
|
+
if (content instanceof BinaryContent)
|
|
120
103
|
return "binary";
|
|
121
|
-
if (content instanceof
|
|
104
|
+
if (content instanceof JsonContent)
|
|
122
105
|
return "json";
|
|
123
|
-
if (content instanceof
|
|
106
|
+
if (content instanceof TextContent)
|
|
124
107
|
return "text";
|
|
125
|
-
if (content instanceof
|
|
108
|
+
if (content instanceof FileContent)
|
|
126
109
|
return "file";
|
|
127
|
-
if (content instanceof
|
|
110
|
+
if (content instanceof LinkContent)
|
|
128
111
|
return "link";
|
|
129
|
-
if (content instanceof
|
|
112
|
+
if (content instanceof EmptyContent)
|
|
130
113
|
return "empty";
|
|
131
114
|
return undefined;
|
|
132
115
|
}
|
|
133
116
|
function schemaValue(content) {
|
|
134
|
-
if (content instanceof
|
|
117
|
+
if (content instanceof BinaryContent)
|
|
135
118
|
return content.headers;
|
|
136
|
-
if (content instanceof
|
|
119
|
+
if (content instanceof JsonContent)
|
|
137
120
|
return content.json;
|
|
138
|
-
if (content instanceof
|
|
121
|
+
if (content instanceof TextContent)
|
|
139
122
|
return content.text;
|
|
140
|
-
if (content instanceof
|
|
123
|
+
if (content instanceof EmptyContent)
|
|
141
124
|
return null;
|
|
142
|
-
if (content instanceof
|
|
125
|
+
if (content instanceof LinkContent)
|
|
143
126
|
return { name: content.name, url: content.url };
|
|
144
|
-
if (content instanceof
|
|
127
|
+
if (content instanceof FileContent)
|
|
145
128
|
return { name: content.name, mime_type: content.mimeType, size: content.data.length };
|
|
146
|
-
if (content instanceof
|
|
129
|
+
if (content instanceof ControlContent)
|
|
147
130
|
return { method: content.method };
|
|
148
|
-
if (content instanceof
|
|
131
|
+
if (content instanceof ErrorContent)
|
|
149
132
|
return content.code === undefined ? { text: content.text } : { text: content.text, code: content.code };
|
|
150
|
-
const [header] =
|
|
133
|
+
const [header] = unpackMessage(content.pack());
|
|
151
134
|
return header;
|
|
152
135
|
}
|
|
153
136
|
function schemaWithDefs(schema, defs) {
|
|
@@ -237,7 +220,7 @@ function validateJsonSchemaValue(schema, value, root = schema) {
|
|
|
237
220
|
}
|
|
238
221
|
return undefined;
|
|
239
222
|
}
|
|
240
|
-
class Toolkit {
|
|
223
|
+
export class Toolkit {
|
|
241
224
|
constructor({ name, title = name, description = "", tools, rules = [], validationMode = "full" }) {
|
|
242
225
|
this.name = name;
|
|
243
226
|
this.title = title;
|
|
@@ -268,7 +251,7 @@ class Toolkit {
|
|
|
268
251
|
}
|
|
269
252
|
async execute(first, second, third) {
|
|
270
253
|
if (typeof first === "string") {
|
|
271
|
-
const output = await this.executeTool(new ToolContext(), first, new ToolContentInput(new
|
|
254
|
+
const output = await this.executeTool(new ToolContext(), first, new ToolContentInput(new JsonContent({ json: second })));
|
|
272
255
|
if (output instanceof ToolContentOutput) {
|
|
273
256
|
return output.content;
|
|
274
257
|
}
|
|
@@ -297,9 +280,9 @@ class Toolkit {
|
|
|
297
280
|
throw new Error(`tool ${name} has unsupported type`);
|
|
298
281
|
}
|
|
299
282
|
decodeFunctionToolArguments(toolName, input) {
|
|
300
|
-
if (input instanceof
|
|
283
|
+
if (input instanceof EmptyContent)
|
|
301
284
|
return {};
|
|
302
|
-
if (input instanceof
|
|
285
|
+
if (input instanceof JsonContent) {
|
|
303
286
|
if (!isRecord(input.json)) {
|
|
304
287
|
throw new Error(`tool ${toolName} requires JSON object input`);
|
|
305
288
|
}
|
|
@@ -318,18 +301,18 @@ class Toolkit {
|
|
|
318
301
|
return tool.inputSpec;
|
|
319
302
|
if (tool.inputSpec !== undefined)
|
|
320
303
|
return tool.inputSpec;
|
|
321
|
-
return new
|
|
304
|
+
return new ToolContentSpec({ types: ["json"], stream: false, schema: tool.inputSchema ?? { type: "object", additionalProperties: true } });
|
|
322
305
|
}
|
|
323
306
|
resolveOutputSpec(tool) {
|
|
324
307
|
if (tool.outputSpec !== undefined) {
|
|
325
308
|
if (tool.outputSchema !== undefined && tool.outputSpec.schema === undefined && tool.outputSpec.types.includes("json")) {
|
|
326
|
-
return new
|
|
309
|
+
return new ToolContentSpec({ types: [...tool.outputSpec.types], stream: tool.outputSpec.stream, schema: tool.outputSchema });
|
|
327
310
|
}
|
|
328
311
|
return tool.outputSpec;
|
|
329
312
|
}
|
|
330
313
|
if (tool.outputSchema === undefined)
|
|
331
314
|
return undefined;
|
|
332
|
-
return new
|
|
315
|
+
return new ToolContentSpec({ types: ["json"], stream: false, schema: tool.outputSchema });
|
|
333
316
|
}
|
|
334
317
|
validateStreamMode({ tool, direction, spec, stream }) {
|
|
335
318
|
if (!this.shouldValidateContentTypes || spec === undefined)
|
|
@@ -372,8 +355,7 @@ class Toolkit {
|
|
|
372
355
|
this.validateSchema({ tool, direction: "output", content, schema: spec?.schema });
|
|
373
356
|
}
|
|
374
357
|
}
|
|
375
|
-
|
|
376
|
-
class HostedToolkit {
|
|
358
|
+
export class HostedToolkit {
|
|
377
359
|
constructor({ toolkit, stopHostedToolkit }) {
|
|
378
360
|
this.toolkit = toolkit;
|
|
379
361
|
this._stopHostedToolkit = stopHostedToolkit;
|
|
@@ -382,7 +364,6 @@ class HostedToolkit {
|
|
|
382
364
|
await this._stopHostedToolkit();
|
|
383
365
|
}
|
|
384
366
|
}
|
|
385
|
-
exports.HostedToolkit = HostedToolkit;
|
|
386
367
|
class _RemoteToolkitWrapper {
|
|
387
368
|
constructor({ toolkit, room }) {
|
|
388
369
|
this._toolCallHandler = this._toolCall.bind(this);
|
|
@@ -399,7 +380,7 @@ class _RemoteToolkitWrapper {
|
|
|
399
380
|
}
|
|
400
381
|
async start({ public_: isPublic = false } = {}) {
|
|
401
382
|
if (this._started) {
|
|
402
|
-
throw new
|
|
383
|
+
throw new RoomServerException(`toolkit ${this.toolkit.name} is already started`);
|
|
403
384
|
}
|
|
404
385
|
this._public = isPublic;
|
|
405
386
|
this.client.protocol.addHandler(`room.tool_call.${this.toolkit.name}`, this._toolCallHandler);
|
|
@@ -425,7 +406,7 @@ class _RemoteToolkitWrapper {
|
|
|
425
406
|
this._started = false;
|
|
426
407
|
this.client.off("disconnected", this._roomEventHandler);
|
|
427
408
|
this.client.off("reconnected", this._roomEventHandler);
|
|
428
|
-
this._failActiveRequestStreams(new
|
|
409
|
+
this._failActiveRequestStreams(new RoomServerException("hosted toolkit stopped"));
|
|
429
410
|
try {
|
|
430
411
|
await this._unregister();
|
|
431
412
|
}
|
|
@@ -484,13 +465,13 @@ class _RemoteToolkitWrapper {
|
|
|
484
465
|
});
|
|
485
466
|
}
|
|
486
467
|
_onRoomEvent(event) {
|
|
487
|
-
if (!this._started || !(event instanceof
|
|
468
|
+
if (!this._started || !(event instanceof RoomStatusEvent)) {
|
|
488
469
|
return;
|
|
489
470
|
}
|
|
490
471
|
if (event.status === "disconnected") {
|
|
491
472
|
this._registrationId = undefined;
|
|
492
473
|
const message = event.message?.trim();
|
|
493
|
-
this._failActiveRequestStreams(new
|
|
474
|
+
this._failActiveRequestStreams(new RoomServerException(message == null || message.length === 0
|
|
494
475
|
? "room connection lost before streamed tool call request completed"
|
|
495
476
|
: `room connection lost before streamed tool call request completed: ${message}`));
|
|
496
477
|
return;
|
|
@@ -509,16 +490,16 @@ class _RemoteToolkitWrapper {
|
|
|
509
490
|
if (remote.id === participantId)
|
|
510
491
|
return remote;
|
|
511
492
|
}
|
|
512
|
-
return new
|
|
493
|
+
return new RemoteParticipant(this.client, participantId, "user");
|
|
513
494
|
}
|
|
514
495
|
_contentFromToolCallArguments(rawArguments, payload) {
|
|
515
496
|
if (!isRecord(rawArguments)) {
|
|
516
497
|
throw new Error("arguments must be a content header object");
|
|
517
498
|
}
|
|
518
499
|
if (typeof rawArguments.type === "string") {
|
|
519
|
-
return
|
|
500
|
+
return unpackContent(packMessage(rawArguments, payload.length > 0 ? payload : undefined));
|
|
520
501
|
}
|
|
521
|
-
return new
|
|
502
|
+
return new JsonContent({ json: rawArguments });
|
|
522
503
|
}
|
|
523
504
|
async _sendToolCallResponse(messageId, chunk) {
|
|
524
505
|
try {
|
|
@@ -531,9 +512,9 @@ class _RemoteToolkitWrapper {
|
|
|
531
512
|
}
|
|
532
513
|
}
|
|
533
514
|
async _sendToolCallResponseChunk(messageId, toolCallId, chunk) {
|
|
534
|
-
const [header, payload] =
|
|
515
|
+
const [header, payload] = unpackMessage(chunk.pack());
|
|
535
516
|
try {
|
|
536
|
-
await this.client.protocol.send("room.tool_call_response_chunk",
|
|
517
|
+
await this.client.protocol.send("room.tool_call_response_chunk", packMessage({ tool_call_id: toolCallId, chunk: header }, payload.length > 0 ? payload : undefined), { id: messageId });
|
|
537
518
|
return true;
|
|
538
519
|
}
|
|
539
520
|
catch (error) {
|
|
@@ -553,7 +534,7 @@ class _RemoteToolkitWrapper {
|
|
|
553
534
|
};
|
|
554
535
|
}
|
|
555
536
|
_enqueueRequestStreamChunk(stream, chunk, tool) {
|
|
556
|
-
if (chunk instanceof
|
|
537
|
+
if (chunk instanceof ControlContent) {
|
|
557
538
|
if (chunk.method === "open")
|
|
558
539
|
return;
|
|
559
540
|
if (chunk.method === "close") {
|
|
@@ -582,7 +563,7 @@ class _RemoteToolkitWrapper {
|
|
|
582
563
|
let toolCallId = toolCallIdFallback;
|
|
583
564
|
let openedResponseStream = false;
|
|
584
565
|
try {
|
|
585
|
-
const [message, payload] =
|
|
566
|
+
const [message, payload] = unpackMessage(data);
|
|
586
567
|
const toolName = message["name"];
|
|
587
568
|
if (typeof toolName !== "string" || toolName.length === 0) {
|
|
588
569
|
throw new Error("tool call requires a tool name");
|
|
@@ -591,19 +572,19 @@ class _RemoteToolkitWrapper {
|
|
|
591
572
|
? message["tool_call_id"]
|
|
592
573
|
: toolCallIdFallback;
|
|
593
574
|
const inputChunk = this._contentFromToolCallArguments(message["arguments"], payload);
|
|
594
|
-
const requestStream = inputChunk instanceof
|
|
595
|
-
if (inputChunk instanceof
|
|
596
|
-
await this._sendToolCallResponse(messageId, new
|
|
575
|
+
const requestStream = inputChunk instanceof ControlContent && inputChunk.method === "open";
|
|
576
|
+
if (inputChunk instanceof ControlContent && !requestStream) {
|
|
577
|
+
await this._sendToolCallResponse(messageId, new ErrorContent({ text: "request stream must start with an open control chunk" }));
|
|
597
578
|
return;
|
|
598
579
|
}
|
|
599
580
|
const tool = this.toolkit.getTool(toolName);
|
|
600
581
|
this.toolkit.validateStreamMode({ tool, direction: "input", spec: this.toolkit.resolveInputSpec(tool), stream: requestStream });
|
|
601
582
|
let resolvedInput;
|
|
602
583
|
if (requestStream) {
|
|
603
|
-
const controller = new
|
|
584
|
+
const controller = new StreamController();
|
|
604
585
|
this._requestStreams.set(toolCallId, controller);
|
|
605
586
|
this._requestStreamTools.set(toolCallId, tool);
|
|
606
|
-
this._enqueueRequestStreamChunk(controller, new
|
|
587
|
+
this._enqueueRequestStreamChunk(controller, new ControlContent({ method: "open" }), tool);
|
|
607
588
|
const buffered = this._pendingRequestChunks.get(toolCallId) ?? [];
|
|
608
589
|
this._pendingRequestChunks.delete(toolCallId);
|
|
609
590
|
for (const chunk of buffered) {
|
|
@@ -630,29 +611,29 @@ class _RemoteToolkitWrapper {
|
|
|
630
611
|
if (output instanceof ToolStreamOutput) {
|
|
631
612
|
this.toolkit.validateStreamMode({ tool, direction: "output", spec: this.toolkit.resolveOutputSpec(tool), stream: true });
|
|
632
613
|
openedResponseStream = true;
|
|
633
|
-
if (!await this._sendToolCallResponse(messageId, new
|
|
614
|
+
if (!await this._sendToolCallResponse(messageId, new ControlContent({ method: "open" })))
|
|
634
615
|
return;
|
|
635
616
|
for await (const chunk of output.stream) {
|
|
636
617
|
this.toolkit.validateOutputContent(tool, chunk);
|
|
637
618
|
if (!await this._sendToolCallResponseChunk(messageId, toolCallId, chunk))
|
|
638
619
|
return;
|
|
639
620
|
}
|
|
640
|
-
await this._sendToolCallResponseChunk(messageId, toolCallId, new
|
|
621
|
+
await this._sendToolCallResponseChunk(messageId, toolCallId, new ControlContent({ method: "close" }));
|
|
641
622
|
return;
|
|
642
623
|
}
|
|
643
624
|
throw new Error(`tool ${toolName} returned unsupported output`);
|
|
644
625
|
}
|
|
645
626
|
catch (error) {
|
|
646
627
|
if (!openedResponseStream) {
|
|
647
|
-
await this._sendToolCallResponse(messageId, new
|
|
628
|
+
await this._sendToolCallResponse(messageId, new ErrorContent({ text: String(error) }));
|
|
648
629
|
return;
|
|
649
630
|
}
|
|
650
631
|
if (!(error instanceof InvalidToolDataException)) {
|
|
651
|
-
await this._sendToolCallResponseChunk(messageId, toolCallId, new
|
|
632
|
+
await this._sendToolCallResponseChunk(messageId, toolCallId, new ErrorContent({ text: String(error) }));
|
|
652
633
|
}
|
|
653
|
-
await this._sendToolCallResponseChunk(messageId, toolCallId, new
|
|
634
|
+
await this._sendToolCallResponseChunk(messageId, toolCallId, new ControlContent({
|
|
654
635
|
method: "close",
|
|
655
|
-
statusCode: error instanceof InvalidToolDataException ?
|
|
636
|
+
statusCode: error instanceof InvalidToolDataException ? ControlCloseStatus.INVALID_DATA : undefined,
|
|
656
637
|
message: error instanceof InvalidToolDataException ? error.message : undefined,
|
|
657
638
|
}));
|
|
658
639
|
}
|
|
@@ -665,14 +646,14 @@ class _RemoteToolkitWrapper {
|
|
|
665
646
|
return;
|
|
666
647
|
}
|
|
667
648
|
try {
|
|
668
|
-
const [message, payload] =
|
|
649
|
+
const [message, payload] = unpackMessage(data);
|
|
669
650
|
const toolCallId = message["tool_call_id"];
|
|
670
651
|
if (typeof toolCallId !== "string" || toolCallId.length === 0)
|
|
671
652
|
return;
|
|
672
653
|
const chunkHeader = message["chunk"];
|
|
673
654
|
if (!isRecord(chunkHeader))
|
|
674
655
|
return;
|
|
675
|
-
const chunk =
|
|
656
|
+
const chunk = unpackContent(packMessage(chunkHeader, payload.length > 0 ? payload : undefined));
|
|
676
657
|
const stream = this._requestStreams.get(toolCallId);
|
|
677
658
|
if (stream === undefined) {
|
|
678
659
|
const buffered = this._pendingRequestChunks.get(toolCallId) ?? [];
|
|
@@ -687,7 +668,7 @@ class _RemoteToolkitWrapper {
|
|
|
687
668
|
}
|
|
688
669
|
}
|
|
689
670
|
}
|
|
690
|
-
async function startHostedToolkit({ room, toolkit, public_: isPublic = false }) {
|
|
671
|
+
export async function startHostedToolkit({ room, toolkit, public_: isPublic = false }) {
|
|
691
672
|
const wrapper = new _RemoteToolkitWrapper({ toolkit, room });
|
|
692
673
|
await wrapper.start({ public_: isPublic });
|
|
693
674
|
return new HostedToolkit({
|
|
@@ -695,7 +676,7 @@ async function startHostedToolkit({ room, toolkit, public_: isPublic = false })
|
|
|
695
676
|
stopHostedToolkit: () => wrapper.stop(),
|
|
696
677
|
});
|
|
697
678
|
}
|
|
698
|
-
class RemoteTaskRunner {
|
|
679
|
+
export class RemoteTaskRunner {
|
|
699
680
|
constructor({ name, description, client, inputSchema, outputSchema, supportsTools = false, required = [], }) {
|
|
700
681
|
this.client = client;
|
|
701
682
|
this.name = name;
|
|
@@ -714,4 +695,3 @@ class RemoteTaskRunner {
|
|
|
714
695
|
}
|
|
715
696
|
}
|
|
716
697
|
}
|
|
717
|
-
exports.RemoteTaskRunner = RemoteTaskRunner;
|
package/dist/esm/api_keys.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.base36Encode = base36Encode;
|
|
4
|
-
exports.base36Decode = base36Decode;
|
|
5
|
-
exports.compressUuid = compressUuid;
|
|
6
|
-
exports.decompressUuid = decompressUuid;
|
|
7
|
-
exports.base64CompressUuid = base64CompressUuid;
|
|
8
|
-
exports.base64DecompressUuid = base64DecompressUuid;
|
|
9
|
-
exports.parseApiKey = parseApiKey;
|
|
10
|
-
exports.encodeApiKey = encodeApiKey;
|
|
11
|
-
const base_64_1 = require("base-64");
|
|
1
|
+
import base64 from "base-64";
|
|
2
|
+
const { encode: base64Encode, decode: base64Decode } = base64;
|
|
12
3
|
const BASE36_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
13
4
|
const BASE36 = 36n;
|
|
14
5
|
const UUID_HEX_REGEX = /^[0-9a-f]{32}$/;
|
|
@@ -24,7 +15,7 @@ function toBigInt(value) {
|
|
|
24
15
|
}
|
|
25
16
|
throw new TypeError("number must be an integer");
|
|
26
17
|
}
|
|
27
|
-
function base36Encode(value) {
|
|
18
|
+
export function base36Encode(value) {
|
|
28
19
|
const number = toBigInt(value);
|
|
29
20
|
if (number < 0n) {
|
|
30
21
|
throw new RangeError("number must be non-negative");
|
|
@@ -41,7 +32,7 @@ function base36Encode(value) {
|
|
|
41
32
|
}
|
|
42
33
|
return base36;
|
|
43
34
|
}
|
|
44
|
-
function base36Decode(numberStr) {
|
|
35
|
+
export function base36Decode(numberStr) {
|
|
45
36
|
const sanitized = numberStr.trim().toLowerCase();
|
|
46
37
|
if (sanitized === "") {
|
|
47
38
|
return 0n;
|
|
@@ -95,7 +86,7 @@ function bytesToBase64(bytes) {
|
|
|
95
86
|
if (globalScope.btoa) {
|
|
96
87
|
return globalScope.btoa(binary);
|
|
97
88
|
}
|
|
98
|
-
return (
|
|
89
|
+
return base64Encode(binary);
|
|
99
90
|
}
|
|
100
91
|
function base64ToBytes(base64) {
|
|
101
92
|
if (globalScope.Buffer) {
|
|
@@ -107,7 +98,7 @@ function base64ToBytes(base64) {
|
|
|
107
98
|
binary = globalScope.atob(base64);
|
|
108
99
|
}
|
|
109
100
|
else {
|
|
110
|
-
binary = (
|
|
101
|
+
binary = base64Decode(base64);
|
|
111
102
|
}
|
|
112
103
|
const bytes = new Uint8Array(binary.length);
|
|
113
104
|
for (let i = 0; i < binary.length; i += 1) {
|
|
@@ -115,17 +106,17 @@ function base64ToBytes(base64) {
|
|
|
115
106
|
}
|
|
116
107
|
return bytes;
|
|
117
108
|
}
|
|
118
|
-
function compressUuid(guidString) {
|
|
109
|
+
export function compressUuid(guidString) {
|
|
119
110
|
const hex = normalizeUuidHex(guidString);
|
|
120
111
|
const guidInt = BigInt(`0x${hex}`);
|
|
121
112
|
return base36Encode(guidInt);
|
|
122
113
|
}
|
|
123
|
-
function decompressUuid(compressedUuid) {
|
|
114
|
+
export function decompressUuid(compressedUuid) {
|
|
124
115
|
const guidInt = base36Decode(compressedUuid);
|
|
125
116
|
const hex = guidInt.toString(16).padStart(32, "0");
|
|
126
117
|
return formatUuidFromHex(hex);
|
|
127
118
|
}
|
|
128
|
-
function base64CompressUuid(id) {
|
|
119
|
+
export function base64CompressUuid(id) {
|
|
129
120
|
const hex = normalizeUuidHex(id);
|
|
130
121
|
const bytes = hexToBytes(hex);
|
|
131
122
|
const base64 = bytesToBase64(bytes)
|
|
@@ -133,7 +124,7 @@ function base64CompressUuid(id) {
|
|
|
133
124
|
.replace(/\//g, "_");
|
|
134
125
|
return base64.replace(/-/g, ".").replace(/=+$/g, "");
|
|
135
126
|
}
|
|
136
|
-
function base64DecompressUuid(id) {
|
|
127
|
+
export function base64DecompressUuid(id) {
|
|
137
128
|
let base64 = id.replace(/\./g, "-");
|
|
138
129
|
const paddingNeeded = base64.length % 4;
|
|
139
130
|
if (paddingNeeded !== 0) {
|
|
@@ -164,7 +155,7 @@ function splitApiKey(key) {
|
|
|
164
155
|
}
|
|
165
156
|
return { idPart, projectPart, secret };
|
|
166
157
|
}
|
|
167
|
-
function parseApiKey(key) {
|
|
158
|
+
export function parseApiKey(key) {
|
|
168
159
|
if (!key.startsWith("ma-")) {
|
|
169
160
|
throw new Error("invalid api key");
|
|
170
161
|
}
|
|
@@ -175,7 +166,7 @@ function parseApiKey(key) {
|
|
|
175
166
|
secret,
|
|
176
167
|
};
|
|
177
168
|
}
|
|
178
|
-
function encodeApiKey(key) {
|
|
169
|
+
export function encodeApiKey(key) {
|
|
179
170
|
return ("ma-" +
|
|
180
171
|
base64CompressUuid(key.id) +
|
|
181
172
|
"-" +
|
package/dist/esm/client.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ClientXmlDocument = exports.XmlText = exports.XmlElement = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
class XmlElement {
|
|
1
|
+
import { v4 as uuid } from "uuid";
|
|
2
|
+
export class XmlElement {
|
|
6
3
|
constructor(parent, { tagName, attributes }, doc) {
|
|
7
4
|
this._data = {
|
|
8
5
|
tagName,
|
|
@@ -69,7 +66,7 @@ class XmlElement {
|
|
|
69
66
|
});
|
|
70
67
|
}
|
|
71
68
|
createChildElement(tagName, attributes) {
|
|
72
|
-
const newId = (
|
|
69
|
+
const newId = uuid();
|
|
73
70
|
const elementData = {
|
|
74
71
|
name: tagName,
|
|
75
72
|
attributes: {
|
|
@@ -96,7 +93,7 @@ class XmlElement {
|
|
|
96
93
|
return this.getNodeByID(newId);
|
|
97
94
|
}
|
|
98
95
|
createChildElementAt(index, tagName, attributes) {
|
|
99
|
-
const newId = (
|
|
96
|
+
const newId = uuid();
|
|
100
97
|
const elementData = {
|
|
101
98
|
name: tagName,
|
|
102
99
|
attributes: {
|
|
@@ -134,7 +131,7 @@ class XmlElement {
|
|
|
134
131
|
throw new Error("Text does not belong to this node");
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
|
-
const newId = (
|
|
134
|
+
const newId = uuid();
|
|
138
135
|
const elementData = {
|
|
139
136
|
name: tagName,
|
|
140
137
|
attributes: {
|
|
@@ -188,8 +185,7 @@ class XmlElement {
|
|
|
188
185
|
return this._data.children;
|
|
189
186
|
}
|
|
190
187
|
}
|
|
191
|
-
|
|
192
|
-
class XmlText {
|
|
188
|
+
export class XmlText {
|
|
193
189
|
constructor(parent, data, doc) {
|
|
194
190
|
this._data = data;
|
|
195
191
|
this.parent = parent;
|
|
@@ -246,8 +242,7 @@ class XmlText {
|
|
|
246
242
|
return this.parent?.id;
|
|
247
243
|
}
|
|
248
244
|
}
|
|
249
|
-
|
|
250
|
-
class ClientXmlDocument {
|
|
245
|
+
export class ClientXmlDocument {
|
|
251
246
|
constructor({ id, sendChanges, }) {
|
|
252
247
|
this._root = new XmlElement(null, { tagName: "root", attributes: {} }, this);
|
|
253
248
|
this.sendChanges = sendChanges;
|
|
@@ -446,4 +441,3 @@ class ClientXmlDocument {
|
|
|
446
441
|
}
|
|
447
442
|
}
|
|
448
443
|
}
|
|
449
|
-
exports.ClientXmlDocument = ClientXmlDocument;
|
package/dist/esm/completer.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Completer = void 0;
|
|
4
|
-
class Completer {
|
|
1
|
+
export class Completer {
|
|
5
2
|
constructor() {
|
|
6
3
|
this.completed = false;
|
|
7
4
|
this.fut = new Promise((resolve, reject) => {
|
|
@@ -22,4 +19,3 @@ class Completer {
|
|
|
22
19
|
this.reject(reason);
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.Completer = Completer;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ContainerMountSpec } from "./meshagent-client";
|
|
2
|
-
import { type Content } from "./response";
|
|
3
|
-
import { RoomClient } from "./room-client";
|
|
1
|
+
import type { ContainerMountSpec } from "./meshagent-client.js";
|
|
2
|
+
import { type Content } from "./response.js";
|
|
3
|
+
import { RoomClient } from "./room-client.js";
|
|
4
4
|
export interface DockerSecret {
|
|
5
5
|
username: string;
|
|
6
6
|
password: string;
|