@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.
Files changed (59) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/browser/agent-client.d.ts +12 -25
  3. package/dist/browser/agent-client.js +64 -45
  4. package/dist/browser/agent.d.ts +14 -34
  5. package/dist/browser/agent.js +67 -75
  6. package/dist/browser/database-client.js +2 -2
  7. package/dist/browser/index.d.ts +1 -0
  8. package/dist/browser/index.js +1 -0
  9. package/dist/browser/meshagent-client.d.ts +8 -1
  10. package/dist/browser/meshagent-client.js +18 -6
  11. package/dist/browser/queues-client.js +1 -1
  12. package/dist/browser/response.d.ts +14 -14
  13. package/dist/browser/response.js +42 -42
  14. package/dist/browser/room-client.d.ts +2 -2
  15. package/dist/browser/room-client.js +2 -2
  16. package/dist/browser/secrets-client.d.ts +2 -2
  17. package/dist/browser/secrets-client.js +11 -11
  18. package/dist/browser/storage-client.d.ts +2 -2
  19. package/dist/browser/tool-content-type.d.ts +13 -0
  20. package/dist/browser/tool-content-type.js +68 -0
  21. package/dist/esm/agent-client.d.ts +12 -25
  22. package/dist/esm/agent-client.js +63 -43
  23. package/dist/esm/agent.d.ts +14 -34
  24. package/dist/esm/agent.js +67 -73
  25. package/dist/esm/database-client.js +3 -3
  26. package/dist/esm/index.d.ts +1 -0
  27. package/dist/esm/index.js +1 -0
  28. package/dist/esm/meshagent-client.d.ts +8 -1
  29. package/dist/esm/meshagent-client.js +18 -6
  30. package/dist/esm/queues-client.js +2 -2
  31. package/dist/esm/response.d.ts +14 -14
  32. package/dist/esm/response.js +34 -34
  33. package/dist/esm/room-client.d.ts +2 -2
  34. package/dist/esm/room-client.js +3 -3
  35. package/dist/esm/secrets-client.d.ts +2 -2
  36. package/dist/esm/secrets-client.js +12 -12
  37. package/dist/esm/storage-client.d.ts +2 -2
  38. package/dist/esm/tool-content-type.d.ts +13 -0
  39. package/dist/esm/tool-content-type.js +64 -0
  40. package/dist/node/agent-client.d.ts +12 -25
  41. package/dist/node/agent-client.js +64 -45
  42. package/dist/node/agent.d.ts +14 -34
  43. package/dist/node/agent.js +67 -75
  44. package/dist/node/database-client.js +2 -2
  45. package/dist/node/index.d.ts +1 -0
  46. package/dist/node/index.js +1 -0
  47. package/dist/node/meshagent-client.d.ts +8 -1
  48. package/dist/node/meshagent-client.js +18 -6
  49. package/dist/node/queues-client.js +1 -1
  50. package/dist/node/response.d.ts +14 -14
  51. package/dist/node/response.js +42 -42
  52. package/dist/node/room-client.d.ts +2 -2
  53. package/dist/node/room-client.js +2 -2
  54. package/dist/node/secrets-client.d.ts +2 -2
  55. package/dist/node/secrets-client.js +11 -11
  56. package/dist/node/storage-client.d.ts +2 -2
  57. package/dist/node/tool-content-type.d.ts +13 -0
  58. package/dist/node/tool-content-type.js +68 -0
  59. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { RoomClient } from "./room-client";
2
- import { FileResponse } from "./response";
2
+ import { FileContent } from "./response";
3
3
  export interface SecretInfo {
4
4
  id: string;
5
5
  name: string;
@@ -22,7 +22,7 @@ export declare class SecretsClient {
22
22
  getSecret({ secretId, delegatedTo, }: {
23
23
  secretId: string;
24
24
  delegatedTo?: string;
25
- }): Promise<FileResponse | null>;
25
+ }): Promise<FileContent | null>;
26
26
  listSecrets(): Promise<SecretInfo[]>;
27
27
  deleteSecret({ secretId, delegatedTo, }: {
28
28
  secretId: string;
@@ -1,4 +1,4 @@
1
- import { EmptyResponse, FileResponse, JsonResponse } from "./response";
1
+ import { EmptyContent, FileContent, JsonContent } from "./response";
2
2
  export class SecretsClient {
3
3
  constructor({ room }) {
4
4
  this.client = room;
@@ -16,10 +16,10 @@ export class SecretsClient {
16
16
  if (forIdentity)
17
17
  req.for_identity = forIdentity;
18
18
  const response = await this.client.sendRequest("secrets.set_secret", req, data);
19
- if (response instanceof EmptyResponse || response instanceof JsonResponse) {
19
+ if (response instanceof EmptyContent || response instanceof JsonContent) {
20
20
  return;
21
21
  }
22
- throw new Error("Invalid response received, expected EmptyResponse or JsonResponse");
22
+ throw new Error("Invalid response received, expected EmptyContent or JsonContent");
23
23
  }
24
24
  async getSecret({ secretId, delegatedTo, }) {
25
25
  const req = {
@@ -28,18 +28,18 @@ export class SecretsClient {
28
28
  if (delegatedTo)
29
29
  req.delegated_to = delegatedTo;
30
30
  const response = await this.client.sendRequest("secrets.get_secret", req);
31
- if (response instanceof EmptyResponse) {
31
+ if (response instanceof EmptyContent) {
32
32
  return null;
33
33
  }
34
- if (response instanceof FileResponse) {
34
+ if (response instanceof FileContent) {
35
35
  return response;
36
36
  }
37
- throw new Error("Invalid response received, expected FileResponse or EmptyResponse");
37
+ throw new Error("Invalid response received, expected FileContent or EmptyContent");
38
38
  }
39
39
  async listSecrets() {
40
40
  const response = await this.client.sendRequest("secrets.list_secrets", {});
41
- if (!(response instanceof JsonResponse)) {
42
- throw new Error("Invalid response received, expected JsonResponse");
41
+ if (!(response instanceof JsonContent)) {
42
+ throw new Error("Invalid response received, expected JsonContent");
43
43
  }
44
44
  const secrets = Array.isArray(response.json?.secrets) ? response.json.secrets : [];
45
45
  return secrets.map((item) => ({
@@ -56,10 +56,10 @@ export class SecretsClient {
56
56
  if (delegatedTo)
57
57
  req.delegated_to = delegatedTo;
58
58
  const response = await this.client.sendRequest("secrets.delete_secret", req);
59
- if (response instanceof EmptyResponse || response instanceof JsonResponse) {
59
+ if (response instanceof EmptyContent || response instanceof JsonContent) {
60
60
  return;
61
61
  }
62
- throw new Error("Invalid response received, expected EmptyResponse or JsonResponse");
62
+ throw new Error("Invalid response received, expected EmptyContent or JsonContent");
63
63
  }
64
64
  async deleteRequestedSecret({ url, type, delegatedTo, }) {
65
65
  const req = {
@@ -69,9 +69,9 @@ export class SecretsClient {
69
69
  if (delegatedTo)
70
70
  req.delegated_to = delegatedTo;
71
71
  const response = await this.client.sendRequest("secrets.delete_requested_secret", req);
72
- if (response instanceof EmptyResponse || response instanceof JsonResponse) {
72
+ if (response instanceof EmptyContent || response instanceof JsonContent) {
73
73
  return;
74
74
  }
75
- throw new Error("Invalid response received, expected EmptyResponse or JsonResponse");
75
+ throw new Error("Invalid response received, expected EmptyContent or JsonContent");
76
76
  }
77
77
  }
@@ -1,6 +1,6 @@
1
1
  import { RoomClient } from "./room-client";
2
2
  import { RoomEvent } from "./room-event";
3
- import { FileResponse } from "./response";
3
+ import { FileContent } from "./response";
4
4
  import { EventEmitter } from "./event-emitter";
5
5
  export declare class FileHandle {
6
6
  id: number;
@@ -32,7 +32,7 @@ export declare class StorageClient extends EventEmitter<RoomEvent> {
32
32
  exists(path: string): Promise<boolean>;
33
33
  write(handle: FileHandle, bytes: Uint8Array): Promise<void>;
34
34
  close(handle: FileHandle): Promise<void>;
35
- download(path: string): Promise<FileResponse>;
35
+ download(path: string): Promise<FileContent>;
36
36
  downloadUrl(path: string): Promise<string>;
37
37
  }
38
38
  export {};
@@ -0,0 +1,13 @@
1
+ export type ToolContentType = "json" | "text" | "file" | "link" | "empty";
2
+ export declare class ToolContentSpec {
3
+ readonly types: ToolContentType[];
4
+ readonly stream: boolean;
5
+ readonly schema?: Record<string, unknown>;
6
+ constructor({ types, stream, schema, }: {
7
+ types: ToolContentType[];
8
+ stream?: boolean;
9
+ schema?: Record<string, unknown>;
10
+ });
11
+ toJson(): Record<string, unknown>;
12
+ static fromJson(value: unknown): ToolContentSpec | undefined;
13
+ }
@@ -0,0 +1,64 @@
1
+ const SUPPORTED_TOOL_CONTENT_TYPES = new Set([
2
+ "json",
3
+ "text",
4
+ "file",
5
+ "link",
6
+ "empty",
7
+ ]);
8
+ function isRecord(value) {
9
+ return typeof value === "object" && value !== null;
10
+ }
11
+ export class ToolContentSpec {
12
+ constructor({ types, stream = false, schema, }) {
13
+ if (!Array.isArray(types) || types.length === 0) {
14
+ throw new Error("ToolContentSpec.types must contain at least one supported type");
15
+ }
16
+ for (const type of types) {
17
+ if (!SUPPORTED_TOOL_CONTENT_TYPES.has(type)) {
18
+ throw new Error(`Unsupported tool content type: ${String(type)}`);
19
+ }
20
+ }
21
+ this.types = [...types];
22
+ this.stream = stream;
23
+ this.schema = schema;
24
+ }
25
+ toJson() {
26
+ const value = {
27
+ types: [...this.types],
28
+ stream: this.stream,
29
+ };
30
+ if (this.schema !== undefined) {
31
+ value["schema"] = this.schema;
32
+ }
33
+ return value;
34
+ }
35
+ static fromJson(value) {
36
+ if (value === null || value === undefined) {
37
+ return undefined;
38
+ }
39
+ if (!isRecord(value)) {
40
+ throw new Error("ToolContentSpec must be a JSON object");
41
+ }
42
+ const rawTypes = value["types"];
43
+ if (!Array.isArray(rawTypes) || rawTypes.length === 0) {
44
+ throw new Error("ToolContentSpec.types must be a non-empty array");
45
+ }
46
+ const types = rawTypes.map((item) => {
47
+ if (typeof item !== "string") {
48
+ throw new Error("ToolContentSpec.types values must be strings");
49
+ }
50
+ if (!SUPPORTED_TOOL_CONTENT_TYPES.has(item)) {
51
+ throw new Error(`Unsupported tool content type: ${item}`);
52
+ }
53
+ return item;
54
+ });
55
+ const rawStream = value["stream"];
56
+ const stream = typeof rawStream === "boolean" ? rawStream : false;
57
+ const rawSchema = value["schema"];
58
+ if (rawSchema !== undefined && !isRecord(rawSchema)) {
59
+ throw new Error("ToolContentSpec.schema must be an object when provided");
60
+ }
61
+ const schema = rawSchema;
62
+ return new ToolContentSpec({ types, stream, schema });
63
+ }
64
+ }
@@ -1,44 +1,31 @@
1
1
  import { RoomClient } from "./room-client";
2
- import { Response } from "./response";
3
- export declare class AgentDescription {
4
- readonly name: string;
5
- readonly title: string;
6
- readonly description: string;
7
- readonly outputSchema?: Record<string, any>;
8
- readonly inputSchema?: Record<string, any>;
9
- readonly labels: string[];
10
- readonly supportsTools: boolean;
11
- constructor({ name, title, description, outputSchema, inputSchema, labels, supportsTools, }: {
12
- name: string;
13
- title: string;
14
- description: string;
15
- outputSchema?: Record<string, any>;
16
- inputSchema?: Record<string, any>;
17
- labels?: string[];
18
- supportsTools: boolean;
19
- });
20
- toJson(): Record<string, any>;
21
- static fromJson(a: Record<string, any>): AgentDescription;
22
- }
2
+ import { Content } from "./response";
3
+ import { ToolContentSpec } from "./tool-content-type";
23
4
  export declare class ToolDescription {
24
5
  title: string;
25
6
  name: string;
26
7
  description: string;
27
- inputSchema: Record<string, any>;
8
+ inputSpec?: ToolContentSpec;
9
+ outputSpec?: ToolContentSpec;
28
10
  defs?: Record<string, any>;
29
11
  thumbnailUrl?: string;
30
12
  pricing?: string;
31
13
  supportsContext?: boolean;
32
- constructor({ title, name, description, inputSchema, thumbnailUrl, defs, pricing, supportsContext }: {
14
+ constructor({ title, name, description, inputSchema, inputSpec, outputSpec, outputSchema, thumbnailUrl, defs, pricing, supportsContext }: {
33
15
  title: string;
34
16
  name: string;
35
17
  description: string;
36
- inputSchema: Record<string, any>;
18
+ inputSchema?: Record<string, any>;
19
+ inputSpec?: ToolContentSpec;
20
+ outputSpec?: ToolContentSpec;
21
+ outputSchema?: Record<string, any>;
37
22
  thumbnailUrl?: string;
38
23
  defs?: Record<string, any>;
39
24
  pricing?: string;
40
25
  supportsContext?: boolean;
41
26
  });
27
+ get inputSchema(): Record<string, any> | undefined;
28
+ get outputSchema(): Record<string, any> | undefined;
42
29
  }
43
30
  export declare class ToolkitDescription {
44
31
  readonly title: string;
@@ -87,5 +74,5 @@ export declare class AgentsClient {
87
74
  toolkit: string;
88
75
  tool: string;
89
76
  arguments: Record<string, any>;
90
- }): Promise<Response>;
77
+ }): Promise<Content>;
91
78
  }
@@ -1,55 +1,57 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AgentsClient = exports.ToolkitConfiguration = exports.ToolkitDescription = exports.ToolDescription = exports.AgentDescription = void 0;
4
- class AgentDescription {
5
- constructor({ name, title, description, outputSchema, inputSchema, labels, supportsTools, }) {
6
- this.name = name;
7
- this.title = title;
8
- this.description = description;
9
- this.outputSchema = outputSchema;
10
- this.inputSchema = inputSchema;
11
- this.labels = Array.isArray(labels) ? labels : [];
12
- this.supportsTools = supportsTools ?? false;
13
- }
14
- toJson() {
15
- return {
16
- name: this.name,
17
- title: this.title,
18
- description: this.description,
19
- input_schema: this.inputSchema,
20
- output_schema: this.outputSchema,
21
- labels: this.labels,
22
- supports_tools: this.supportsTools,
23
- };
24
- }
25
- static fromJson(a) {
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
- supportsTools: a["supports_tools"] === true,
37
- labels,
38
- });
39
- }
40
- }
41
- exports.AgentDescription = AgentDescription;
3
+ exports.AgentsClient = exports.ToolkitConfiguration = exports.ToolkitDescription = exports.ToolDescription = void 0;
4
+ const tool_content_type_1 = require("./tool-content-type");
42
5
  class ToolDescription {
43
- constructor({ title, name, description, inputSchema, thumbnailUrl, defs, pricing, supportsContext }) {
6
+ constructor({ title, name, description, inputSchema, inputSpec, outputSpec, outputSchema, thumbnailUrl, defs, pricing, supportsContext }) {
44
7
  this.title = title;
45
8
  this.name = name;
46
9
  this.description = description;
47
- this.inputSchema = inputSchema;
10
+ if (inputSpec !== undefined && inputSchema !== undefined) {
11
+ this.inputSpec = new tool_content_type_1.ToolContentSpec({
12
+ types: [...inputSpec.types],
13
+ stream: inputSpec.stream,
14
+ schema: inputSchema,
15
+ });
16
+ }
17
+ else if (inputSpec !== undefined) {
18
+ this.inputSpec = inputSpec;
19
+ }
20
+ else if (inputSchema !== undefined) {
21
+ this.inputSpec = new tool_content_type_1.ToolContentSpec({
22
+ types: ["json"],
23
+ stream: false,
24
+ schema: inputSchema,
25
+ });
26
+ }
27
+ if (outputSpec !== undefined && outputSchema !== undefined) {
28
+ this.outputSpec = new tool_content_type_1.ToolContentSpec({
29
+ types: [...outputSpec.types],
30
+ stream: outputSpec.stream,
31
+ schema: outputSchema,
32
+ });
33
+ }
34
+ else if (outputSpec !== undefined) {
35
+ this.outputSpec = outputSpec;
36
+ }
37
+ else if (outputSchema !== undefined) {
38
+ this.outputSpec = new tool_content_type_1.ToolContentSpec({
39
+ types: ["json"],
40
+ stream: false,
41
+ schema: outputSchema,
42
+ });
43
+ }
48
44
  this.thumbnailUrl = thumbnailUrl;
49
45
  this.defs = defs;
50
46
  this.pricing = pricing;
51
47
  this.supportsContext = supportsContext ?? false;
52
48
  }
49
+ get inputSchema() {
50
+ return this.inputSpec?.schema;
51
+ }
52
+ get outputSchema() {
53
+ return this.outputSpec?.schema;
54
+ }
53
55
  }
54
56
  exports.ToolDescription = ToolDescription;
55
57
  class ToolkitDescription {
@@ -78,9 +80,12 @@ class ToolkitDescription {
78
80
  name: tool.name,
79
81
  title: tool.title,
80
82
  description: tool.description,
81
- input_schema: tool.inputSchema,
83
+ input_spec: tool.inputSpec?.toJson(),
84
+ output_spec: tool.outputSpec?.toJson(),
82
85
  thumbnail_url: tool.thumbnailUrl,
83
86
  defs: tool.defs,
87
+ pricing: tool.pricing,
88
+ supports_context: tool.supportsContext,
84
89
  })),
85
90
  };
86
91
  }
@@ -99,10 +104,13 @@ class ToolkitDescription {
99
104
  name: tool["name"],
100
105
  description: tool["description"],
101
106
  inputSchema: tool["input_schema"],
107
+ inputSpec: tool_content_type_1.ToolContentSpec.fromJson(tool["input_spec"]),
108
+ outputSchema: tool["output_schema"],
109
+ outputSpec: tool_content_type_1.ToolContentSpec.fromJson(tool["output_spec"]),
102
110
  thumbnailUrl: tool["thumbnail_url"],
103
111
  defs: tool["defs"],
104
112
  pricing: tool["pricing"],
105
- supportsContext: tool["supportsContext"],
113
+ supportsContext: tool["supports_context"] ?? tool["supportsContext"],
106
114
  }));
107
115
  }
108
116
  }
@@ -115,10 +123,13 @@ class ToolkitDescription {
115
123
  name: toolName,
116
124
  description: tool["description"],
117
125
  inputSchema: tool["input_schema"],
126
+ inputSpec: tool_content_type_1.ToolContentSpec.fromJson(tool["input_spec"]),
127
+ outputSchema: tool["output_schema"],
128
+ outputSpec: tool_content_type_1.ToolContentSpec.fromJson(tool["output_spec"]),
118
129
  thumbnailUrl: tool["thumbnail_url"],
119
130
  defs: tool["defs"],
120
131
  pricing: tool["pricing"],
121
- supportsContext: tool["supportsContext"],
132
+ supportsContext: tool["supports_context"] ?? tool["supportsContext"],
122
133
  }));
123
134
  }
124
135
  }
@@ -185,7 +196,15 @@ class AgentsClient {
185
196
  return toolkits;
186
197
  }
187
198
  async invokeTool(params) {
188
- return await this.client.sendRequest("agent.invoke_tool", params);
199
+ const request = {
200
+ toolkit: params.toolkit,
201
+ tool: params.tool,
202
+ arguments: {
203
+ type: "json",
204
+ json: params.arguments,
205
+ },
206
+ };
207
+ return await this.client.sendRequest("agent.invoke_tool", request);
189
208
  }
190
209
  }
191
210
  exports.AgentsClient = AgentsClient;
@@ -1,47 +1,27 @@
1
1
  import { RoomClient } from "./room-client";
2
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 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 inputSchema: Record<string, any>;
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: Record<string, any>;
16
+ inputSchema?: Record<string, any>;
17
+ inputSpec?: ToolContentSpec;
18
+ outputSpec?: ToolContentSpec;
19
+ outputSchema?: Record<string, any>;
42
20
  thumbnailUrl?: string;
43
21
  });
44
- abstract execute(arguments_: Record<string, any>): Promise<Response>;
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<Response>;
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(context: TaskContext, arguments_: Record<string, any>): Promise<Record<string, any>>;
79
+ abstract ask(arguments_: Record<string, any>): Promise<Record<string, any>>;
100
80
  }
@@ -1,85 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RemoteTaskRunner = exports.RemoteToolkit = exports.Toolkit = exports.Tool = exports.TaskContext = exports.AgentChatContext = void 0;
3
+ exports.RemoteTaskRunner = exports.RemoteToolkit = exports.Toolkit = exports.Tool = void 0;
4
4
  const response_1 = require("./response");
5
+ const tool_content_type_1 = require("./tool-content-type");
5
6
  const utils_1 = require("./utils");
6
- class AgentChatContext {
7
- constructor({ messages, systemRole = "system" }) {
8
- this.messages = messages ? [...messages] : [];
9
- this.systemRole = systemRole;
10
- }
11
- appendRules(rules) {
12
- let systemMessage = this.messages.find((m) => m["role"] === this.systemRole);
13
- if (!systemMessage) {
14
- systemMessage = { role: this.systemRole, content: "" };
15
- this.messages.push(systemMessage);
16
- }
17
- const plan = `
18
- Rules:
19
- -${rules.join("\n-")}
20
- `;
21
- systemMessage["content"] += plan;
22
- }
23
- appendUserMessage(message) {
24
- this.messages.push({ role: "user", content: message });
25
- }
26
- appendUserImage(url) {
27
- this.messages.push({
28
- role: "user",
29
- content: [
30
- {
31
- type: "image_url",
32
- image_url: { url: url, detail: "auto" },
33
- },
34
- ],
35
- });
36
- }
37
- copy() {
38
- const cloned = JSON.parse(JSON.stringify(this.messages));
39
- return new AgentChatContext({
40
- messages: cloned,
41
- systemRole: this.systemRole,
42
- });
43
- }
44
- toJson() {
45
- return {
46
- messages: this.messages,
47
- system_role: this.systemRole,
48
- };
49
- }
50
- static fromJson(json) {
51
- return new AgentChatContext({
52
- messages: json["messages"],
53
- systemRole: json["system_role"] || "system",
54
- });
55
- }
56
- }
57
- exports.AgentChatContext = AgentChatContext;
58
- class TaskContext {
59
- constructor({ chat, jwt, api_url }) {
60
- this._jwt = jwt;
61
- this._chat = chat;
62
- this._apiUrl = api_url;
63
- }
64
- get chat() {
65
- return this._chat;
66
- }
67
- get jwt() {
68
- return this._jwt;
69
- }
70
- get api_url() {
71
- return this._apiUrl;
72
- }
73
- }
74
- exports.TaskContext = TaskContext;
75
7
  class Tool {
76
- constructor({ name, description, title, inputSchema, thumbnailUrl }) {
8
+ constructor({ name, description, title, inputSchema, inputSpec, outputSpec, outputSchema, thumbnailUrl }) {
77
9
  this.name = name;
78
10
  this.description = description;
79
11
  this.title = title;
80
- this.inputSchema = inputSchema;
12
+ if (inputSpec !== undefined && inputSchema !== undefined) {
13
+ this.inputSpec = new tool_content_type_1.ToolContentSpec({
14
+ types: [...inputSpec.types],
15
+ stream: inputSpec.stream,
16
+ schema: inputSchema,
17
+ });
18
+ }
19
+ else if (inputSpec !== undefined) {
20
+ this.inputSpec = inputSpec;
21
+ }
22
+ else if (inputSchema !== undefined) {
23
+ this.inputSpec = new tool_content_type_1.ToolContentSpec({
24
+ types: ["json"],
25
+ stream: false,
26
+ schema: inputSchema,
27
+ });
28
+ }
29
+ if (outputSpec !== undefined && outputSchema !== undefined) {
30
+ this.outputSpec = new tool_content_type_1.ToolContentSpec({
31
+ types: [...outputSpec.types],
32
+ stream: outputSpec.stream,
33
+ schema: outputSchema,
34
+ });
35
+ }
36
+ else if (outputSpec !== undefined) {
37
+ this.outputSpec = outputSpec;
38
+ }
39
+ else if (outputSchema !== undefined) {
40
+ this.outputSpec = new tool_content_type_1.ToolContentSpec({
41
+ types: ["json"],
42
+ stream: false,
43
+ schema: outputSchema,
44
+ });
45
+ }
81
46
  this.thumbnailUrl = thumbnailUrl;
82
47
  }
48
+ get inputSchema() {
49
+ return this.inputSpec?.schema;
50
+ }
51
+ get outputSchema() {
52
+ return this.outputSpec?.schema;
53
+ }
83
54
  }
84
55
  exports.Tool = Tool;
85
56
  class Toolkit {
@@ -100,7 +71,8 @@ class Toolkit {
100
71
  json[tool.name] = {
101
72
  description: tool.description,
102
73
  title: tool.title,
103
- input_schema: tool.inputSchema,
74
+ input_spec: tool.inputSpec?.toJson(),
75
+ output_spec: tool.outputSpec?.toJson(),
104
76
  thumbnail_url: tool.thumbnailUrl,
105
77
  };
106
78
  }
@@ -150,12 +122,32 @@ class RemoteToolkit extends Toolkit {
150
122
  try {
151
123
  const [message, _] = (0, utils_1.unpackMessage)(data);
152
124
  const toolName = message["name"];
153
- const args = message["arguments"];
125
+ const rawArguments = message["arguments"];
126
+ let args;
127
+ if (rawArguments &&
128
+ typeof rawArguments === "object" &&
129
+ !Array.isArray(rawArguments) &&
130
+ "type" in rawArguments) {
131
+ const content = rawArguments;
132
+ const contentType = content["type"];
133
+ if (contentType === "json") {
134
+ args = content["json"] ?? {};
135
+ }
136
+ else if (contentType === "empty") {
137
+ args = {};
138
+ }
139
+ else {
140
+ throw new Error(`tool '${toolName}' requires JSON object input, received content type '${String(contentType)}'`);
141
+ }
142
+ }
143
+ else {
144
+ args = rawArguments ?? {};
145
+ }
154
146
  const response = await this.execute(toolName, args);
155
147
  await this.client.protocol.send("agent.tool_call_response", response.pack(), messageId);
156
148
  }
157
149
  catch (e) {
158
- const err = new response_1.ErrorResponse({ text: String(e) });
150
+ const err = new response_1.ErrorContent({ text: String(e) });
159
151
  await this.client.protocol.send("agent.tool_call_response", err.pack(), messageId);
160
152
  }
161
153
  }
@@ -69,7 +69,7 @@ class DatabaseClient {
69
69
  params,
70
70
  };
71
71
  const response = await this.room.sendRequest("database.sql", payload);
72
- if (response instanceof response_1.JsonResponse) {
72
+ if (response instanceof response_1.JsonContent) {
73
73
  if (response?.json?.results) {
74
74
  return response.json.results;
75
75
  }
@@ -100,7 +100,7 @@ class DatabaseClient {
100
100
  payload.vector = vector;
101
101
  }
102
102
  const response = await this.room.sendRequest("database.search", payload);
103
- if (response instanceof response_1.JsonResponse) {
103
+ if (response instanceof response_1.JsonContent) {
104
104
  if (response?.json?.results) {
105
105
  return response.json.results;
106
106
  }
@@ -26,4 +26,5 @@ export * from './stream-controller';
26
26
  export * from './sync-client';
27
27
  export * from './api_keys';
28
28
  export * from './helpers';
29
+ export * from './tool-content-type';
29
30
  export * from './utils';