@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
@@ -42,4 +42,5 @@ __exportStar(require("./stream-controller"), exports);
42
42
  __exportStar(require("./sync-client"), exports);
43
43
  __exportStar(require("./api_keys"), exports);
44
44
  __exportStar(require("./helpers"), exports);
45
+ __exportStar(require("./tool-content-type"), exports);
45
46
  __exportStar(require("./utils"), exports);
@@ -30,6 +30,7 @@ export interface RoomInfo {
30
30
  id: string;
31
31
  name: string;
32
32
  metadata: Record<string, unknown>;
33
+ annotations: Record<string, string>;
33
34
  }
34
35
  export interface ProjectRoomGrant {
35
36
  room: RoomInfo;
@@ -79,6 +80,7 @@ export interface ServiceMetadata {
79
80
  }
80
81
  export interface ContainerSpec {
81
82
  command?: string | null;
83
+ working_dir?: string | null;
82
84
  image: string;
83
85
  environment?: EnvironmentVariable[] | null;
84
86
  secrets?: string[];
@@ -137,6 +139,7 @@ export interface ServiceSpec {
137
139
  export interface Mailbox {
138
140
  address: string;
139
141
  room: string;
142
+ roomId?: string;
140
143
  queue: string;
141
144
  }
142
145
  export interface Balance {
@@ -322,10 +325,14 @@ export declare class Meshagent {
322
325
  name: string;
323
326
  ifNotExists?: boolean;
324
327
  metadata?: Record<string, unknown>;
328
+ annotations?: Record<string, string>;
325
329
  permissions?: Record<string, ApiScope>;
326
330
  }): Promise<RoomInfo>;
327
331
  getRoom(projectId: string, name: string): Promise<RoomInfo>;
328
- updateRoom(projectId: string, roomId: string, name: string): Promise<void>;
332
+ updateRoom(projectId: string, roomId: string, name: string, options?: {
333
+ metadata?: Record<string, unknown>;
334
+ annotations?: Record<string, string>;
335
+ }): Promise<void>;
329
336
  deleteRoom(projectId: string, roomId: string): Promise<void>;
330
337
  connectRoom(projectId: string, room: string): Promise<RoomConnectionInfo>;
331
338
  createRoomGrant(params: {
@@ -176,7 +176,7 @@ class Meshagent {
176
176
  if (!data || typeof data !== "object") {
177
177
  throw new requirement_1.RoomException("Invalid room payload");
178
178
  }
179
- const { id, name, metadata } = data;
179
+ const { id, name, metadata, annotations } = data;
180
180
  if (typeof id !== "string" || typeof name !== "string") {
181
181
  throw new requirement_1.RoomException("Invalid room payload: missing id or name");
182
182
  }
@@ -184,6 +184,7 @@ class Meshagent {
184
184
  id,
185
185
  name,
186
186
  metadata: metadata && typeof metadata === "object" ? metadata : {},
187
+ annotations: annotations && typeof annotations === "object" ? annotations : {},
187
188
  };
188
189
  }
189
190
  parseProjectRoomGrant(data) {
@@ -710,11 +711,14 @@ class Meshagent {
710
711
  if (!item || typeof item !== "object") {
711
712
  throw new requirement_1.RoomException("Invalid mailbox payload");
712
713
  }
713
- const { address, room, queue } = item;
714
+ const { address, room, room_id, queue } = item;
714
715
  if (typeof address !== "string" || typeof room !== "string" || typeof queue !== "string") {
715
716
  throw new requirement_1.RoomException("Invalid mailbox payload: missing fields");
716
717
  }
717
- return { address, room, queue };
718
+ if (room_id !== undefined && typeof room_id !== "string") {
719
+ throw new requirement_1.RoomException("Invalid mailbox payload: invalid room_id");
720
+ }
721
+ return { address, room, roomId: room_id, queue };
718
722
  });
719
723
  }
720
724
  async deleteMailbox(projectId, address) {
@@ -839,11 +843,12 @@ class Meshagent {
839
843
  return secrets.map((item) => this.parseSecret(item));
840
844
  }
841
845
  async createRoom(params) {
842
- const { projectId, name, ifNotExists = false, metadata, permissions } = params;
846
+ const { projectId, name, ifNotExists = false, metadata, annotations, permissions } = params;
843
847
  const payload = {
844
848
  name,
845
849
  if_not_exists: Boolean(ifNotExists),
846
850
  metadata,
851
+ annotations,
847
852
  };
848
853
  if (permissions) {
849
854
  const serialized = {};
@@ -865,10 +870,17 @@ class Meshagent {
865
870
  });
866
871
  return this.parseRoom(data);
867
872
  }
868
- async updateRoom(projectId, roomId, name) {
873
+ async updateRoom(projectId, roomId, name, options = {}) {
874
+ const payload = { name };
875
+ if (options.metadata !== undefined) {
876
+ payload["metadata"] = options.metadata;
877
+ }
878
+ if (options.annotations !== undefined) {
879
+ payload["annotations"] = options.annotations;
880
+ }
869
881
  await this.request(`/accounts/projects/${projectId}/rooms/${roomId}`, {
870
882
  method: "PUT",
871
- json: { name },
883
+ json: payload,
872
884
  action: "update room",
873
885
  responseType: "void",
874
886
  });
@@ -36,7 +36,7 @@ class QueuesClient {
36
36
  create,
37
37
  wait,
38
38
  });
39
- if (response instanceof response_1.EmptyResponse) {
39
+ if (response instanceof response_1.EmptyContent) {
40
40
  return null;
41
41
  }
42
42
  else {
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshagent/meshagent",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "Meshagent Client",
5
5
  "homepage": "https://github.com/meshagent/meshagent-ts",
6
6
  "scripts": {