@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,18 +1,18 @@
1
- export interface Response {
1
+ export interface Content {
2
2
  pack(): Uint8Array;
3
3
  }
4
- export declare class LinkResponse implements Response {
4
+ export declare class LinkContent implements Content {
5
5
  url: string;
6
6
  name: string;
7
7
  constructor({ url, name }: {
8
8
  url: string;
9
9
  name: string;
10
10
  });
11
- static unpack(header: Record<string, any>, payload: Uint8Array): LinkResponse;
11
+ static unpack(header: Record<string, any>, _payload: Uint8Array): LinkContent;
12
12
  pack(): Uint8Array;
13
13
  toString(): string;
14
14
  }
15
- export declare class FileResponse implements Response {
15
+ export declare class FileContent implements Content {
16
16
  data: Uint8Array;
17
17
  name: string;
18
18
  mimeType: string;
@@ -21,40 +21,40 @@ export declare class FileResponse implements Response {
21
21
  name: string;
22
22
  mimeType: string;
23
23
  });
24
- static unpack(header: Record<string, any>, payload: Uint8Array): FileResponse;
24
+ static unpack(header: Record<string, any>, payload: Uint8Array): FileContent;
25
25
  pack(): Uint8Array;
26
26
  toString(): string;
27
27
  }
28
- export declare class TextResponse implements Response {
28
+ export declare class TextContent implements Content {
29
29
  text: string;
30
30
  constructor({ text }: {
31
31
  text: string;
32
32
  });
33
- static unpack(header: Record<string, any>, payload: Uint8Array): TextResponse;
33
+ static unpack(header: Record<string, any>, _payload: Uint8Array): TextContent;
34
34
  pack(): Uint8Array;
35
35
  toString(): string;
36
36
  }
37
- export declare class JsonResponse implements Response {
37
+ export declare class JsonContent implements Content {
38
38
  json: Record<string, any>;
39
39
  constructor({ json }: {
40
40
  json: Record<string, any>;
41
41
  });
42
- static unpack(header: Record<string, any>, payload: Uint8Array): JsonResponse;
42
+ static unpack(header: Record<string, any>, _payload: Uint8Array): JsonContent;
43
43
  pack(): Uint8Array;
44
44
  toString(): string;
45
45
  }
46
- export declare class ErrorResponse implements Response {
46
+ export declare class ErrorContent implements Content {
47
47
  text: string;
48
48
  constructor({ text }: {
49
49
  text: string;
50
50
  });
51
- static unpack(header: Record<string, any>, payload: Uint8Array): ErrorResponse;
51
+ static unpack(header: Record<string, any>, _payload: Uint8Array): ErrorContent;
52
52
  pack(): Uint8Array;
53
53
  toString(): string;
54
54
  }
55
- export declare class EmptyResponse implements Response {
56
- static unpack(header: Record<string, any>, payload: Uint8Array): EmptyResponse;
55
+ export declare class EmptyContent implements Content {
56
+ static unpack(_header: Record<string, any>, _payload: Uint8Array): EmptyContent;
57
57
  pack(): Uint8Array;
58
58
  toString(): string;
59
59
  }
60
- export declare function unpackResponse(data: Uint8Array): Response;
60
+ export declare function unpackContent(data: Uint8Array): Content;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmptyResponse = exports.ErrorResponse = exports.JsonResponse = exports.TextResponse = exports.FileResponse = exports.LinkResponse = void 0;
4
- exports.unpackResponse = unpackResponse;
3
+ exports.EmptyContent = exports.ErrorContent = exports.JsonContent = exports.TextContent = exports.FileContent = exports.LinkContent = void 0;
4
+ exports.unpackContent = unpackContent;
5
5
  const utils_1 = require("./utils");
6
- class LinkResponse {
6
+ class LinkContent {
7
7
  constructor({ url, name }) {
8
8
  this.url = url;
9
9
  this.name = name;
10
10
  }
11
- static unpack(header, payload) {
12
- return new LinkResponse({
11
+ static unpack(header, _payload) {
12
+ return new LinkContent({
13
13
  url: header["url"],
14
14
  name: header["name"],
15
15
  });
@@ -22,18 +22,18 @@ class LinkResponse {
22
22
  });
23
23
  }
24
24
  toString() {
25
- return `LinkResponse (${this.name}): ${this.url}`;
25
+ return `LinkContent (${this.name}): ${this.url}`;
26
26
  }
27
27
  }
28
- exports.LinkResponse = LinkResponse;
29
- class FileResponse {
28
+ exports.LinkContent = LinkContent;
29
+ class FileContent {
30
30
  constructor({ data, name, mimeType }) {
31
31
  this.data = data;
32
32
  this.name = name;
33
33
  this.mimeType = mimeType;
34
34
  }
35
35
  static unpack(header, payload) {
36
- return new FileResponse({
36
+ return new FileContent({
37
37
  data: payload,
38
38
  name: header["name"],
39
39
  mimeType: header["mime_type"],
@@ -47,16 +47,16 @@ class FileResponse {
47
47
  }, this.data);
48
48
  }
49
49
  toString() {
50
- return `FileResponse (${this.name}): ${this.mimeType}`;
50
+ return `FileContent (${this.name}): ${this.mimeType}`;
51
51
  }
52
52
  }
53
- exports.FileResponse = FileResponse;
54
- class TextResponse {
53
+ exports.FileContent = FileContent;
54
+ class TextContent {
55
55
  constructor({ text }) {
56
56
  this.text = text;
57
57
  }
58
- static unpack(header, payload) {
59
- return new TextResponse({
58
+ static unpack(header, _payload) {
59
+ return new TextContent({
60
60
  text: header["text"],
61
61
  });
62
62
  }
@@ -67,16 +67,16 @@ class TextResponse {
67
67
  });
68
68
  }
69
69
  toString() {
70
- return `TextResponse: ${this.text}`;
70
+ return `TextContent: ${this.text}`;
71
71
  }
72
72
  }
73
- exports.TextResponse = TextResponse;
74
- class JsonResponse {
73
+ exports.TextContent = TextContent;
74
+ class JsonContent {
75
75
  constructor({ json }) {
76
76
  this.json = json;
77
77
  }
78
- static unpack(header, payload) {
79
- return new JsonResponse({ json: header["json"] });
78
+ static unpack(header, _payload) {
79
+ return new JsonContent({ json: header["json"] });
80
80
  }
81
81
  pack() {
82
82
  return (0, utils_1.packMessage)({
@@ -85,16 +85,16 @@ class JsonResponse {
85
85
  });
86
86
  }
87
87
  toString() {
88
- return `JsonResponse: ${JSON.stringify(this.json)}`;
88
+ return `JsonContent: ${JSON.stringify(this.json)}`;
89
89
  }
90
90
  }
91
- exports.JsonResponse = JsonResponse;
92
- class ErrorResponse {
91
+ exports.JsonContent = JsonContent;
92
+ class ErrorContent {
93
93
  constructor({ text }) {
94
94
  this.text = text;
95
95
  }
96
- static unpack(header, payload) {
97
- return new ErrorResponse({ text: header["text"] });
96
+ static unpack(header, _payload) {
97
+ return new ErrorContent({ text: header["text"] });
98
98
  }
99
99
  pack() {
100
100
  return (0, utils_1.packMessage)({
@@ -103,36 +103,36 @@ class ErrorResponse {
103
103
  });
104
104
  }
105
105
  toString() {
106
- return `ErrorResponse: ${this.text}`;
106
+ return `ErrorContent: ${this.text}`;
107
107
  }
108
108
  }
109
- exports.ErrorResponse = ErrorResponse;
110
- class EmptyResponse {
111
- static unpack(header, payload) {
112
- return new EmptyResponse();
109
+ exports.ErrorContent = ErrorContent;
110
+ class EmptyContent {
111
+ static unpack(_header, _payload) {
112
+ return new EmptyContent();
113
113
  }
114
114
  pack() {
115
115
  return (0, utils_1.packMessage)({ type: "empty" });
116
116
  }
117
117
  toString() {
118
- return `EmptyResponse`;
118
+ return `EmptyContent`;
119
119
  }
120
120
  }
121
- exports.EmptyResponse = EmptyResponse;
122
- const _responseTypes = {
123
- empty: EmptyResponse.unpack,
124
- error: ErrorResponse.unpack,
125
- file: FileResponse.unpack,
126
- json: JsonResponse.unpack,
127
- link: LinkResponse.unpack,
128
- text: TextResponse.unpack,
121
+ exports.EmptyContent = EmptyContent;
122
+ const _contentTypes = {
123
+ empty: EmptyContent.unpack,
124
+ error: ErrorContent.unpack,
125
+ file: FileContent.unpack,
126
+ json: JsonContent.unpack,
127
+ link: LinkContent.unpack,
128
+ text: TextContent.unpack,
129
129
  };
130
- function unpackResponse(data) {
130
+ function unpackContent(data) {
131
131
  const header = JSON.parse((0, utils_1.splitMessageHeader)(data));
132
132
  const payload = (0, utils_1.splitMessagePayload)(data);
133
133
  const typeKey = header["type"];
134
- if (!_responseTypes[typeKey]) {
135
- throw new Error(`Unknown response type: ${typeKey}`);
134
+ if (!_contentTypes[typeKey]) {
135
+ throw new Error(`Unknown content type: ${typeKey}`);
136
136
  }
137
- return _responseTypes[typeKey](header, payload);
137
+ return _contentTypes[typeKey](header, payload);
138
138
  }
@@ -9,7 +9,7 @@ import { DatabaseClient } from "./database-client";
9
9
  import { AgentsClient } from "./agent-client";
10
10
  import { SecretsClient } from "./secrets-client";
11
11
  import { RoomEvent } from "./room-event";
12
- import { Response } from "./response";
12
+ import { Content } from "./response";
13
13
  interface RequestHeader {
14
14
  [key: string]: any;
15
15
  }
@@ -37,7 +37,7 @@ export declare class RoomClient {
37
37
  onError?: (error: Error) => void;
38
38
  }): Promise<void>;
39
39
  dispose(): void;
40
- sendRequest(type: string, request: RequestHeader, data?: Uint8Array): Promise<Response>;
40
+ sendRequest(type: string, request: RequestHeader, data?: Uint8Array): Promise<Content>;
41
41
  private _handleResponse;
42
42
  private _handleRoomReady;
43
43
  private _onParticipantInit;
@@ -66,7 +66,7 @@ class RoomClient {
66
66
  console.error("No data in response");
67
67
  return;
68
68
  }
69
- const response = (0, response_1.unpackResponse)(data);
69
+ const response = (0, response_1.unpackContent)(data);
70
70
  console.log("GOT RESPONSE", response);
71
71
  if (!response) {
72
72
  console.error("No response");
@@ -75,7 +75,7 @@ class RoomClient {
75
75
  if (this._pendingRequests.has(messageId)) {
76
76
  const pr = this._pendingRequests.get(messageId);
77
77
  this._pendingRequests.delete(messageId);
78
- if (response instanceof response_1.ErrorResponse) {
78
+ if (response instanceof response_1.ErrorContent) {
79
79
  pr.reject(new Error(response.text));
80
80
  }
81
81
  else {
@@ -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;
@@ -19,10 +19,10 @@ class SecretsClient {
19
19
  if (forIdentity)
20
20
  req.for_identity = forIdentity;
21
21
  const response = await this.client.sendRequest("secrets.set_secret", req, data);
22
- if (response instanceof response_1.EmptyResponse || response instanceof response_1.JsonResponse) {
22
+ if (response instanceof response_1.EmptyContent || response instanceof response_1.JsonContent) {
23
23
  return;
24
24
  }
25
- throw new Error("Invalid response received, expected EmptyResponse or JsonResponse");
25
+ throw new Error("Invalid response received, expected EmptyContent or JsonContent");
26
26
  }
27
27
  async getSecret({ secretId, delegatedTo, }) {
28
28
  const req = {
@@ -31,18 +31,18 @@ class SecretsClient {
31
31
  if (delegatedTo)
32
32
  req.delegated_to = delegatedTo;
33
33
  const response = await this.client.sendRequest("secrets.get_secret", req);
34
- if (response instanceof response_1.EmptyResponse) {
34
+ if (response instanceof response_1.EmptyContent) {
35
35
  return null;
36
36
  }
37
- if (response instanceof response_1.FileResponse) {
37
+ if (response instanceof response_1.FileContent) {
38
38
  return response;
39
39
  }
40
- throw new Error("Invalid response received, expected FileResponse or EmptyResponse");
40
+ throw new Error("Invalid response received, expected FileContent or EmptyContent");
41
41
  }
42
42
  async listSecrets() {
43
43
  const response = await this.client.sendRequest("secrets.list_secrets", {});
44
- if (!(response instanceof response_1.JsonResponse)) {
45
- throw new Error("Invalid response received, expected JsonResponse");
44
+ if (!(response instanceof response_1.JsonContent)) {
45
+ throw new Error("Invalid response received, expected JsonContent");
46
46
  }
47
47
  const secrets = Array.isArray(response.json?.secrets) ? response.json.secrets : [];
48
48
  return secrets.map((item) => ({
@@ -59,10 +59,10 @@ class SecretsClient {
59
59
  if (delegatedTo)
60
60
  req.delegated_to = delegatedTo;
61
61
  const response = await this.client.sendRequest("secrets.delete_secret", req);
62
- if (response instanceof response_1.EmptyResponse || response instanceof response_1.JsonResponse) {
62
+ if (response instanceof response_1.EmptyContent || response instanceof response_1.JsonContent) {
63
63
  return;
64
64
  }
65
- throw new Error("Invalid response received, expected EmptyResponse or JsonResponse");
65
+ throw new Error("Invalid response received, expected EmptyContent or JsonContent");
66
66
  }
67
67
  async deleteRequestedSecret({ url, type, delegatedTo, }) {
68
68
  const req = {
@@ -72,10 +72,10 @@ class SecretsClient {
72
72
  if (delegatedTo)
73
73
  req.delegated_to = delegatedTo;
74
74
  const response = await this.client.sendRequest("secrets.delete_requested_secret", req);
75
- if (response instanceof response_1.EmptyResponse || response instanceof response_1.JsonResponse) {
75
+ if (response instanceof response_1.EmptyContent || response instanceof response_1.JsonContent) {
76
76
  return;
77
77
  }
78
- throw new Error("Invalid response received, expected EmptyResponse or JsonResponse");
78
+ throw new Error("Invalid response received, expected EmptyContent or JsonContent");
79
79
  }
80
80
  }
81
81
  exports.SecretsClient = SecretsClient;
@@ -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,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolContentSpec = void 0;
4
+ const SUPPORTED_TOOL_CONTENT_TYPES = new Set([
5
+ "json",
6
+ "text",
7
+ "file",
8
+ "link",
9
+ "empty",
10
+ ]);
11
+ function isRecord(value) {
12
+ return typeof value === "object" && value !== null;
13
+ }
14
+ class ToolContentSpec {
15
+ constructor({ types, stream = false, schema, }) {
16
+ if (!Array.isArray(types) || types.length === 0) {
17
+ throw new Error("ToolContentSpec.types must contain at least one supported type");
18
+ }
19
+ for (const type of types) {
20
+ if (!SUPPORTED_TOOL_CONTENT_TYPES.has(type)) {
21
+ throw new Error(`Unsupported tool content type: ${String(type)}`);
22
+ }
23
+ }
24
+ this.types = [...types];
25
+ this.stream = stream;
26
+ this.schema = schema;
27
+ }
28
+ toJson() {
29
+ const value = {
30
+ types: [...this.types],
31
+ stream: this.stream,
32
+ };
33
+ if (this.schema !== undefined) {
34
+ value["schema"] = this.schema;
35
+ }
36
+ return value;
37
+ }
38
+ static fromJson(value) {
39
+ if (value === null || value === undefined) {
40
+ return undefined;
41
+ }
42
+ if (!isRecord(value)) {
43
+ throw new Error("ToolContentSpec must be a JSON object");
44
+ }
45
+ const rawTypes = value["types"];
46
+ if (!Array.isArray(rawTypes) || rawTypes.length === 0) {
47
+ throw new Error("ToolContentSpec.types must be a non-empty array");
48
+ }
49
+ const types = rawTypes.map((item) => {
50
+ if (typeof item !== "string") {
51
+ throw new Error("ToolContentSpec.types values must be strings");
52
+ }
53
+ if (!SUPPORTED_TOOL_CONTENT_TYPES.has(item)) {
54
+ throw new Error(`Unsupported tool content type: ${item}`);
55
+ }
56
+ return item;
57
+ });
58
+ const rawStream = value["stream"];
59
+ const stream = typeof rawStream === "boolean" ? rawStream : false;
60
+ const rawSchema = value["schema"];
61
+ if (rawSchema !== undefined && !isRecord(rawSchema)) {
62
+ throw new Error("ToolContentSpec.schema must be an object when provided");
63
+ }
64
+ const schema = rawSchema;
65
+ return new ToolContentSpec({ types, stream, schema });
66
+ }
67
+ }
68
+ exports.ToolContentSpec = ToolContentSpec;
@@ -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,51 +1,54 @@
1
- export class AgentDescription {
2
- constructor({ name, title, description, outputSchema, inputSchema, labels, supportsTools, }) {
3
- this.name = name;
4
- this.title = title;
5
- this.description = description;
6
- this.outputSchema = outputSchema;
7
- this.inputSchema = inputSchema;
8
- this.labels = Array.isArray(labels) ? labels : [];
9
- this.supportsTools = supportsTools ?? false;
10
- }
11
- toJson() {
12
- return {
13
- name: this.name,
14
- title: this.title,
15
- description: this.description,
16
- input_schema: this.inputSchema,
17
- output_schema: this.outputSchema,
18
- labels: this.labels,
19
- supports_tools: this.supportsTools,
20
- };
21
- }
22
- static fromJson(a) {
23
- let labels = [];
24
- if (Array.isArray(a["labels"])) {
25
- labels = a["labels"].filter((item) => typeof item === "string");
26
- }
27
- return new AgentDescription({
28
- name: a["name"],
29
- title: a["title"] ?? "",
30
- description: a["description"] ?? "",
31
- inputSchema: a["input_schema"] ?? undefined,
32
- outputSchema: a["output_schema"] ?? undefined,
33
- supportsTools: a["supports_tools"] === true,
34
- labels,
35
- });
36
- }
37
- }
1
+ import { ToolContentSpec } from "./tool-content-type";
38
2
  export class ToolDescription {
39
- constructor({ title, name, description, inputSchema, thumbnailUrl, defs, pricing, supportsContext }) {
3
+ constructor({ title, name, description, inputSchema, inputSpec, outputSpec, outputSchema, thumbnailUrl, defs, pricing, supportsContext }) {
40
4
  this.title = title;
41
5
  this.name = name;
42
6
  this.description = description;
43
- this.inputSchema = inputSchema;
7
+ if (inputSpec !== undefined && inputSchema !== undefined) {
8
+ this.inputSpec = new ToolContentSpec({
9
+ types: [...inputSpec.types],
10
+ stream: inputSpec.stream,
11
+ schema: inputSchema,
12
+ });
13
+ }
14
+ else if (inputSpec !== undefined) {
15
+ this.inputSpec = inputSpec;
16
+ }
17
+ else if (inputSchema !== undefined) {
18
+ this.inputSpec = new ToolContentSpec({
19
+ types: ["json"],
20
+ stream: false,
21
+ schema: inputSchema,
22
+ });
23
+ }
24
+ if (outputSpec !== undefined && outputSchema !== undefined) {
25
+ this.outputSpec = new ToolContentSpec({
26
+ types: [...outputSpec.types],
27
+ stream: outputSpec.stream,
28
+ schema: outputSchema,
29
+ });
30
+ }
31
+ else if (outputSpec !== undefined) {
32
+ this.outputSpec = outputSpec;
33
+ }
34
+ else if (outputSchema !== undefined) {
35
+ this.outputSpec = new ToolContentSpec({
36
+ types: ["json"],
37
+ stream: false,
38
+ schema: outputSchema,
39
+ });
40
+ }
44
41
  this.thumbnailUrl = thumbnailUrl;
45
42
  this.defs = defs;
46
43
  this.pricing = pricing;
47
44
  this.supportsContext = supportsContext ?? false;
48
45
  }
46
+ get inputSchema() {
47
+ return this.inputSpec?.schema;
48
+ }
49
+ get outputSchema() {
50
+ return this.outputSpec?.schema;
51
+ }
49
52
  }
50
53
  export class ToolkitDescription {
51
54
  constructor({ title, name, description, tools, thumbnailUrl, participantId }) {
@@ -73,9 +76,12 @@ export class ToolkitDescription {
73
76
  name: tool.name,
74
77
  title: tool.title,
75
78
  description: tool.description,
76
- input_schema: tool.inputSchema,
79
+ input_spec: tool.inputSpec?.toJson(),
80
+ output_spec: tool.outputSpec?.toJson(),
77
81
  thumbnail_url: tool.thumbnailUrl,
78
82
  defs: tool.defs,
83
+ pricing: tool.pricing,
84
+ supports_context: tool.supportsContext,
79
85
  })),
80
86
  };
81
87
  }
@@ -94,10 +100,13 @@ export class ToolkitDescription {
94
100
  name: tool["name"],
95
101
  description: tool["description"],
96
102
  inputSchema: tool["input_schema"],
103
+ inputSpec: ToolContentSpec.fromJson(tool["input_spec"]),
104
+ outputSchema: tool["output_schema"],
105
+ outputSpec: ToolContentSpec.fromJson(tool["output_spec"]),
97
106
  thumbnailUrl: tool["thumbnail_url"],
98
107
  defs: tool["defs"],
99
108
  pricing: tool["pricing"],
100
- supportsContext: tool["supportsContext"],
109
+ supportsContext: tool["supports_context"] ?? tool["supportsContext"],
101
110
  }));
102
111
  }
103
112
  }
@@ -110,10 +119,13 @@ export class ToolkitDescription {
110
119
  name: toolName,
111
120
  description: tool["description"],
112
121
  inputSchema: tool["input_schema"],
122
+ inputSpec: ToolContentSpec.fromJson(tool["input_spec"]),
123
+ outputSchema: tool["output_schema"],
124
+ outputSpec: ToolContentSpec.fromJson(tool["output_spec"]),
113
125
  thumbnailUrl: tool["thumbnail_url"],
114
126
  defs: tool["defs"],
115
127
  pricing: tool["pricing"],
116
- supportsContext: tool["supportsContext"],
128
+ supportsContext: tool["supports_context"] ?? tool["supportsContext"],
117
129
  }));
118
130
  }
119
131
  }
@@ -178,6 +190,14 @@ export class AgentsClient {
178
190
  return toolkits;
179
191
  }
180
192
  async invokeTool(params) {
181
- return await this.client.sendRequest("agent.invoke_tool", params);
193
+ const request = {
194
+ toolkit: params.toolkit,
195
+ tool: params.tool,
196
+ arguments: {
197
+ type: "json",
198
+ json: params.arguments,
199
+ },
200
+ };
201
+ return await this.client.sendRequest("agent.invoke_tool", request);
182
202
  }
183
203
  }