@meshagent/meshagent 0.41.4 → 0.41.6

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 (65) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/browser/agent-client.d.ts +10 -0
  3. package/dist/browser/agent-client.js +36 -1
  4. package/dist/browser/agent.d.ts +109 -14
  5. package/dist/browser/agent.js +533 -68
  6. package/dist/browser/datasets-client.d.ts +70 -0
  7. package/dist/browser/datasets-client.js +79 -0
  8. package/dist/browser/entrypoint.d.ts +1464 -1426
  9. package/dist/browser/index.d.ts +2 -0
  10. package/dist/browser/index.js +2 -0
  11. package/dist/browser/oauth-scopes.d.ts +2 -0
  12. package/dist/browser/oauth-scopes.js +21 -0
  13. package/dist/browser/participant-token.d.ts +1 -3
  14. package/dist/browser/participant-token.js +2 -3
  15. package/dist/browser/room-client.d.ts +16 -0
  16. package/dist/browser/room-client.js +69 -0
  17. package/dist/browser/storage-client.d.ts +3 -1
  18. package/dist/browser/storage-client.js +5 -2
  19. package/dist/browser/tool-content-type.d.ts +1 -1
  20. package/dist/browser/tool-content-type.js +3 -2
  21. package/dist/browser/toolkit-config.d.ts +84 -0
  22. package/dist/browser/toolkit-config.js +415 -0
  23. package/dist/esm/agent-client.d.ts +10 -0
  24. package/dist/esm/agent-client.js +36 -1
  25. package/dist/esm/agent.d.ts +109 -14
  26. package/dist/esm/agent.js +533 -68
  27. package/dist/esm/datasets-client.d.ts +70 -0
  28. package/dist/esm/datasets-client.js +79 -0
  29. package/dist/esm/entrypoint.d.ts +1464 -1426
  30. package/dist/esm/index.d.ts +2 -0
  31. package/dist/esm/index.js +2 -0
  32. package/dist/esm/oauth-scopes.d.ts +2 -0
  33. package/dist/esm/oauth-scopes.js +21 -0
  34. package/dist/esm/participant-token.d.ts +1 -3
  35. package/dist/esm/participant-token.js +2 -3
  36. package/dist/esm/room-client.d.ts +16 -0
  37. package/dist/esm/room-client.js +69 -0
  38. package/dist/esm/storage-client.d.ts +3 -1
  39. package/dist/esm/storage-client.js +5 -2
  40. package/dist/esm/tool-content-type.d.ts +1 -1
  41. package/dist/esm/tool-content-type.js +3 -2
  42. package/dist/esm/toolkit-config.d.ts +84 -0
  43. package/dist/esm/toolkit-config.js +415 -0
  44. package/dist/node/agent-client.d.ts +10 -0
  45. package/dist/node/agent-client.js +36 -1
  46. package/dist/node/agent.d.ts +109 -14
  47. package/dist/node/agent.js +533 -68
  48. package/dist/node/datasets-client.d.ts +70 -0
  49. package/dist/node/datasets-client.js +79 -0
  50. package/dist/node/entrypoint.d.ts +1464 -1426
  51. package/dist/node/index.d.ts +2 -0
  52. package/dist/node/index.js +2 -0
  53. package/dist/node/oauth-scopes.d.ts +2 -0
  54. package/dist/node/oauth-scopes.js +21 -0
  55. package/dist/node/participant-token.d.ts +1 -3
  56. package/dist/node/participant-token.js +2 -3
  57. package/dist/node/room-client.d.ts +16 -0
  58. package/dist/node/room-client.js +69 -0
  59. package/dist/node/storage-client.d.ts +3 -1
  60. package/dist/node/storage-client.js +5 -2
  61. package/dist/node/tool-content-type.d.ts +1 -1
  62. package/dist/node/tool-content-type.js +3 -2
  63. package/dist/node/toolkit-config.d.ts +84 -0
  64. package/dist/node/toolkit-config.js +415 -0
  65. package/package.json +1 -1
@@ -0,0 +1,415 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenAIConnectors = exports.Connector = exports.MCPServer = exports.MCPHeader = void 0;
4
+ exports.mcpConnectorsFromRoomServices = mcpConnectorsFromRoomServices;
5
+ class MCPHeader {
6
+ constructor({ name, value }) {
7
+ this.name = name;
8
+ this.value = value;
9
+ }
10
+ static fromJson(json) {
11
+ return new MCPHeader({
12
+ name: String(json["name"]),
13
+ value: String(json["value"]),
14
+ });
15
+ }
16
+ toJson() {
17
+ return {
18
+ name: this.name,
19
+ value: this.value,
20
+ };
21
+ }
22
+ }
23
+ exports.MCPHeader = MCPHeader;
24
+ function isRecord(value) {
25
+ return typeof value === "object" && value !== null && !Array.isArray(value);
26
+ }
27
+ function parseMcpHeaders(value) {
28
+ if (value == null) {
29
+ return undefined;
30
+ }
31
+ if (Array.isArray(value)) {
32
+ return value.map((entry) => {
33
+ if (!isRecord(entry)) {
34
+ throw new Error("MCPServer.headers entries must be JSON objects");
35
+ }
36
+ return MCPHeader.fromJson(entry);
37
+ });
38
+ }
39
+ if (isRecord(value)) {
40
+ return Object.entries(value).map(([name, headerValue]) => new MCPHeader({
41
+ name,
42
+ value: String(headerValue),
43
+ }));
44
+ }
45
+ throw new Error("MCPServer.headers must be a header list or object");
46
+ }
47
+ class MCPServer {
48
+ constructor({ serverLabel, authorization, serverUrl, allowedTools, headers, requireApproval, alwaysRequireApproval, neverRequireApproval, openaiConnectorId, }) {
49
+ this.serverLabel = serverLabel;
50
+ this.authorization = authorization ?? undefined;
51
+ this.serverUrl = serverUrl ?? undefined;
52
+ this.allowedTools = allowedTools ?? undefined;
53
+ this.headers = headers ?? undefined;
54
+ this.requireApproval = requireApproval ?? undefined;
55
+ this.alwaysRequireApproval = alwaysRequireApproval ?? undefined;
56
+ this.neverRequireApproval = neverRequireApproval ?? undefined;
57
+ this.openaiConnectorId = openaiConnectorId ?? undefined;
58
+ }
59
+ static fromJson(json) {
60
+ const serverLabel = json["server_label"];
61
+ if (typeof serverLabel !== "string") {
62
+ throw new Error("MCPServer requires server_label");
63
+ }
64
+ const requireApproval = json["require_approval"];
65
+ if (requireApproval != null && requireApproval !== "always" && requireApproval !== "never") {
66
+ throw new Error("MCPServer.require_approval must be always or never");
67
+ }
68
+ return new MCPServer({
69
+ serverLabel,
70
+ authorization: typeof json["authorization"] === "string" ? json["authorization"] : undefined,
71
+ serverUrl: typeof json["server_url"] === "string" ? json["server_url"] : undefined,
72
+ allowedTools: Array.isArray(json["allowed_tools"])
73
+ ? json["allowed_tools"].map(String)
74
+ : undefined,
75
+ headers: parseMcpHeaders(json["headers"]),
76
+ requireApproval,
77
+ alwaysRequireApproval: Array.isArray(json["always_require_approval"])
78
+ ? json["always_require_approval"].map(String)
79
+ : undefined,
80
+ neverRequireApproval: Array.isArray(json["never_require_approval"])
81
+ ? json["never_require_approval"].map(String)
82
+ : undefined,
83
+ openaiConnectorId: typeof json["openai_connector_id"] === "string"
84
+ ? json["openai_connector_id"]
85
+ : (typeof json["openaiConnectorId"] === "string" ? json["openaiConnectorId"] : undefined),
86
+ });
87
+ }
88
+ static fromJsonString(data) {
89
+ const parsed = JSON.parse(data);
90
+ if (!isRecord(parsed)) {
91
+ throw new Error("MCPServer JSON must be an object");
92
+ }
93
+ return MCPServer.fromJson(parsed);
94
+ }
95
+ toJson() {
96
+ const json = {
97
+ server_label: this.serverLabel,
98
+ server_url: this.serverUrl ?? null,
99
+ };
100
+ if (this.authorization !== undefined) {
101
+ json["authorization"] = this.authorization;
102
+ }
103
+ if (this.allowedTools !== undefined) {
104
+ json["allowed_tools"] = this.allowedTools;
105
+ }
106
+ if (this.headers !== undefined) {
107
+ json["headers"] = this.headers.map((header) => header.toJson());
108
+ }
109
+ if (this.requireApproval !== undefined) {
110
+ json["require_approval"] = this.requireApproval;
111
+ }
112
+ if (this.alwaysRequireApproval !== undefined) {
113
+ json["always_require_approval"] = this.alwaysRequireApproval;
114
+ }
115
+ if (this.neverRequireApproval !== undefined) {
116
+ json["never_require_approval"] = this.neverRequireApproval;
117
+ }
118
+ if (this.openaiConnectorId !== undefined) {
119
+ json["openai_connector_id"] = this.openaiConnectorId;
120
+ }
121
+ return json;
122
+ }
123
+ toJsonString() {
124
+ return JSON.stringify(this.toJson());
125
+ }
126
+ copyWith({ serverLabel, authorization, serverUrl, allowedTools, headers, requireApproval, alwaysRequireApproval, neverRequireApproval, openaiConnectorId, }) {
127
+ return new MCPServer({
128
+ serverLabel: serverLabel ?? this.serverLabel,
129
+ authorization: authorization ?? this.authorization,
130
+ serverUrl: serverUrl ?? this.serverUrl,
131
+ allowedTools: allowedTools ?? this.allowedTools,
132
+ headers: headers ?? this.headers,
133
+ requireApproval: requireApproval ?? this.requireApproval,
134
+ alwaysRequireApproval: alwaysRequireApproval ?? this.alwaysRequireApproval,
135
+ neverRequireApproval: neverRequireApproval ?? this.neverRequireApproval,
136
+ openaiConnectorId: openaiConnectorId ?? this.openaiConnectorId,
137
+ });
138
+ }
139
+ }
140
+ exports.MCPServer = MCPServer;
141
+ class Connector {
142
+ constructor({ name, server, oauth, }) {
143
+ this.name = name;
144
+ this.server = server;
145
+ this.oauth = oauth ?? undefined;
146
+ }
147
+ static oauthClientSecretIdFromHeaders(server) {
148
+ for (const header of server.headers ?? []) {
149
+ if (header.name === "Meshagent-OAuth-Client-Secret-Id") {
150
+ const value = header.value.trim();
151
+ if (value.length > 0) {
152
+ return value;
153
+ }
154
+ }
155
+ }
156
+ return null;
157
+ }
158
+ static buildConnectorRef({ server, oauth, }) {
159
+ const clientSecretId = Connector.oauthClientSecretIdFromHeaders(server);
160
+ const serverUrl = server.serverUrl;
161
+ const hasServerUrl = serverUrl != null && serverUrl.trim().length > 0;
162
+ const requiresOAuth = oauth != null || server.openaiConnectorId != null || clientSecretId != null;
163
+ if (!requiresOAuth) {
164
+ return null;
165
+ }
166
+ if (server.openaiConnectorId == null && clientSecretId == null && !hasServerUrl) {
167
+ return null;
168
+ }
169
+ return {
170
+ openaiConnectorId: server.openaiConnectorId ?? null,
171
+ serverUrl: hasServerUrl ? serverUrl.trim() : null,
172
+ clientSecretId,
173
+ };
174
+ }
175
+ buildConnectorRef() {
176
+ return Connector.buildConnectorRef({ server: this.server, oauth: this.oauth });
177
+ }
178
+ async isConnected(room, agentName) {
179
+ const connector = this.buildConnectorRef();
180
+ if (connector == null && this.oauth == null) {
181
+ return true;
182
+ }
183
+ const token = await room.secrets.getOfflineOAuthToken({
184
+ connector,
185
+ oauth: this.oauth,
186
+ delegatedTo: agentName,
187
+ });
188
+ return token != null;
189
+ }
190
+ async authenticate(client, agent, redirectUri) {
191
+ const connector = this.buildConnectorRef();
192
+ if (connector == null && this.oauth == null) {
193
+ return null;
194
+ }
195
+ const localParticipant = client.localParticipant;
196
+ if (localParticipant == null) {
197
+ throw new Error("Connector.authenticate requires a local participant");
198
+ }
199
+ const agentName = agent.getAttribute("name");
200
+ return await client.secrets.requestOAuthToken({
201
+ fromParticipantId: localParticipant.id,
202
+ connector,
203
+ oauth: this.oauth,
204
+ redirectUri,
205
+ delegateTo: agentName == null ? null : String(agentName),
206
+ });
207
+ }
208
+ }
209
+ exports.Connector = Connector;
210
+ function headersFromEndpointSpec(headers) {
211
+ if (headers == null || Object.keys(headers).length === 0) {
212
+ return undefined;
213
+ }
214
+ return Object.entries(headers).map(([name, value]) => new MCPHeader({ name, value }));
215
+ }
216
+ function normalizeEndpointPath(path) {
217
+ return path.startsWith("/") ? path : `/${path}`;
218
+ }
219
+ function bracketIpv6Host(host) {
220
+ return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
221
+ }
222
+ function roomServiceMcpServerUrl({ service, port, endpoint, }) {
223
+ const endpointPath = normalizeEndpointPath(endpoint.path);
224
+ const portValue = typeof port.num === "number" ? port.num : null;
225
+ if (service.external == null) {
226
+ if (portValue == null) {
227
+ return `http://localhost${endpointPath}`;
228
+ }
229
+ return `http://localhost:${portValue}${endpointPath}`;
230
+ }
231
+ const externalUrl = service.external.url;
232
+ if (externalUrl.length === 0) {
233
+ return null;
234
+ }
235
+ let baseUrl;
236
+ try {
237
+ baseUrl = new URL(externalUrl.includes("://") ? externalUrl : `https://${externalUrl}`);
238
+ }
239
+ catch {
240
+ return null;
241
+ }
242
+ if (baseUrl.hostname.length === 0) {
243
+ return null;
244
+ }
245
+ const normalizedBasePath = baseUrl.pathname.endsWith("/")
246
+ ? baseUrl.pathname.slice(0, -1)
247
+ : baseUrl.pathname;
248
+ const joinedPath = normalizedBasePath.length === 0 || normalizedBasePath === "/"
249
+ ? endpointPath
250
+ : `${normalizedBasePath}${endpointPath}`;
251
+ if (portValue == null) {
252
+ baseUrl.pathname = joinedPath;
253
+ return baseUrl.toString();
254
+ }
255
+ const userInfo = baseUrl.username.length > 0
256
+ ? `${baseUrl.username}${baseUrl.password.length > 0 ? `:${baseUrl.password}` : ""}@`
257
+ : "";
258
+ const query = baseUrl.search;
259
+ const fragment = baseUrl.hash;
260
+ return `${baseUrl.protocol}//${userInfo}${bracketIpv6Host(baseUrl.hostname)}:${portValue}${joinedPath}${query}${fragment}`;
261
+ }
262
+ function mcpConnectorsFromRoomServices({ services, agentName, }) {
263
+ const connectors = [];
264
+ for (const service of services) {
265
+ const filter = service.metadata.annotations?.["meshagent.agent.filter"];
266
+ if (filter != null && filter !== agentName) {
267
+ continue;
268
+ }
269
+ for (const port of service.ports ?? []) {
270
+ for (const endpoint of port.endpoints ?? []) {
271
+ const mcp = endpoint.mcp;
272
+ if (mcp == null) {
273
+ continue;
274
+ }
275
+ connectors.push(new Connector({
276
+ name: mcp.label,
277
+ server: new MCPServer({
278
+ serverLabel: mcp.label,
279
+ serverUrl: roomServiceMcpServerUrl({ service, port, endpoint }),
280
+ headers: headersFromEndpointSpec(mcp.headers),
281
+ requireApproval: mcp.require_approval,
282
+ openaiConnectorId: mcp.openai_connector_id,
283
+ }),
284
+ oauth: mcp.oauth,
285
+ }));
286
+ }
287
+ }
288
+ }
289
+ return connectors;
290
+ }
291
+ function getEnvValue(name) {
292
+ if (typeof process === "undefined") {
293
+ return "";
294
+ }
295
+ return process.env?.[name] ?? "";
296
+ }
297
+ class OpenAIConnectors {
298
+ }
299
+ exports.OpenAIConnectors = OpenAIConnectors;
300
+ OpenAIConnectors.dropbox = new Connector({
301
+ name: "Dropbox",
302
+ server: new MCPServer({ serverLabel: "Dropbox", openaiConnectorId: "connector_dropbox" }),
303
+ oauth: {
304
+ client_id: getEnvValue("DROPBOX_CONNECTOR_OAUTH_CLIENT_ID"),
305
+ client_secret: "CLIENT_SECRET",
306
+ authorization_endpoint: "https://www.dropbox.com/oauth2/authorize",
307
+ token_endpoint: "https://api.dropbox.com/oauth2/token",
308
+ no_pkce: true,
309
+ scopes: ["files.metadata.read", "account_info.read", "files.content.read"],
310
+ },
311
+ });
312
+ OpenAIConnectors.gmail = new Connector({
313
+ name: "Gmail",
314
+ server: new MCPServer({ serverLabel: "Gmail", openaiConnectorId: "connector_gmail" }),
315
+ oauth: {
316
+ client_id: getEnvValue("GOOGLE_CONNECTOR_OAUTH_CLIENT_ID"),
317
+ authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
318
+ token_endpoint: "https://oauth2.googleapis.com/token",
319
+ no_pkce: false,
320
+ scopes: [
321
+ "https://www.googleapis.com/auth/gmail.modify",
322
+ "https://www.googleapis.com/auth/userinfo.email",
323
+ "https://www.googleapis.com/auth/userinfo.profile",
324
+ ],
325
+ },
326
+ });
327
+ OpenAIConnectors.googleCalendar = new Connector({
328
+ name: "Google Calendar",
329
+ server: new MCPServer({ serverLabel: "Google_Calendar", openaiConnectorId: "connector_googlecalendar" }),
330
+ oauth: {
331
+ client_id: getEnvValue("GOOGLE_CONNECTOR_OAUTH_CLIENT_ID"),
332
+ authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
333
+ token_endpoint: "https://oauth2.googleapis.com/token",
334
+ no_pkce: false,
335
+ scopes: [
336
+ "https://www.googleapis.com/auth/userinfo.email",
337
+ "https://www.googleapis.com/auth/userinfo.profile",
338
+ "https://www.googleapis.com/auth/calendar.events",
339
+ ],
340
+ },
341
+ });
342
+ OpenAIConnectors.googleDrive = new Connector({
343
+ name: "Google Drive",
344
+ server: new MCPServer({ serverLabel: "Google_Drive", openaiConnectorId: "connector_googledrive" }),
345
+ oauth: {
346
+ client_id: "CLIENT_ID",
347
+ client_secret: getEnvValue("GOOGLE_CONNECTOR_OAUTH_CLIENT_ID"),
348
+ authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
349
+ token_endpoint: "https://oauth2.googleapis.com/token",
350
+ no_pkce: false,
351
+ scopes: [
352
+ "https://www.googleapis.com/auth/userinfo.email",
353
+ "https://www.googleapis.com/auth/userinfo.profile",
354
+ "https://www.googleapis.com/auth/drive.readonly",
355
+ ],
356
+ },
357
+ });
358
+ OpenAIConnectors.microsoftTeams = new Connector({
359
+ name: "Microsoft Teams",
360
+ server: new MCPServer({ serverLabel: "Microsoft_Teams", openaiConnectorId: "connector_microsoftteams" }),
361
+ oauth: {
362
+ client_id: getEnvValue("MICROSOFT_CONNECTOR_OAUTH_CLIENT_ID"),
363
+ client_secret: "CLIENT_SECRET",
364
+ authorization_endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
365
+ token_endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
366
+ no_pkce: false,
367
+ scopes: ["User.Read", "Chat.Read", "ChannelMessage.Read.All"],
368
+ },
369
+ });
370
+ OpenAIConnectors.outlookCalendar = new Connector({
371
+ name: "Outlook Calendar",
372
+ server: new MCPServer({ serverLabel: "Outlook_Calendar", openaiConnectorId: "connector_outlookcalendar" }),
373
+ oauth: {
374
+ client_id: getEnvValue("MICROSOFT_CONNECTOR_OAUTH_CLIENT_ID"),
375
+ client_secret: "CLIENT_SECRET",
376
+ authorization_endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
377
+ token_endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
378
+ no_pkce: false,
379
+ scopes: ["Calendars.Read", "User.Read"],
380
+ },
381
+ });
382
+ OpenAIConnectors.outlookEmail = new Connector({
383
+ name: "Outlook Email",
384
+ server: new MCPServer({ serverLabel: "Outlook_Email", openaiConnectorId: "connector_outlookemail" }),
385
+ oauth: {
386
+ client_id: getEnvValue("MICROSOFT_CONNECTOR_OAUTH_CLIENT_ID"),
387
+ client_secret: "CLIENT_SECRET",
388
+ authorization_endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
389
+ token_endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
390
+ no_pkce: false,
391
+ scopes: ["User.Read", "Mail.Read"],
392
+ },
393
+ });
394
+ OpenAIConnectors.sharepoint = new Connector({
395
+ name: "Sharepoint",
396
+ server: new MCPServer({ serverLabel: "Sharepoint", openaiConnectorId: "connector_sharepoint" }),
397
+ oauth: {
398
+ client_id: getEnvValue("MICROSOFT_CONNECTOR_OAUTH_CLIENT_ID"),
399
+ client_secret: "CLIENT_SECRET",
400
+ authorization_endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
401
+ token_endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
402
+ no_pkce: false,
403
+ scopes: ["Sites.Read.All", "Files.Read.All", "User.Read"],
404
+ },
405
+ });
406
+ OpenAIConnectors.all = [
407
+ OpenAIConnectors.dropbox,
408
+ OpenAIConnectors.gmail,
409
+ OpenAIConnectors.googleCalendar,
410
+ OpenAIConnectors.googleDrive,
411
+ OpenAIConnectors.microsoftTeams,
412
+ OpenAIConnectors.sharepoint,
413
+ OpenAIConnectors.outlookEmail,
414
+ OpenAIConnectors.outlookCalendar,
415
+ ];
@@ -1,5 +1,6 @@
1
1
  import { RoomClient } from "./room-client";
2
2
  import type { Content } from "./response";
3
+ import { ToolInput, type ToolCallOutput } from "./agent";
3
4
  import { ToolContentSpec } from "./tool-content-type";
4
5
  export declare class ToolDescription {
5
6
  title: string;
@@ -56,9 +57,18 @@ export declare class AgentsClient {
56
57
  participantName?: string;
57
58
  timeout?: number;
58
59
  }): Promise<ToolkitDescription[]>;
60
+ invokeTool(params: {
61
+ toolkit: string;
62
+ tool: string;
63
+ input: ToolInput;
64
+ participantId?: string;
65
+ onBehalfOfId?: string;
66
+ }): Promise<ToolCallOutput>;
59
67
  invokeTool(params: {
60
68
  toolkit: string;
61
69
  tool: string;
62
70
  arguments: Record<string, any>;
71
+ participantId?: string;
72
+ onBehalfOfId?: string;
63
73
  }): Promise<Content>;
64
74
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AgentsClient = exports.ToolkitDescription = exports.ToolDescription = void 0;
4
+ const agent_1 = require("./agent");
4
5
  const tool_content_type_1 = require("./tool-content-type");
5
6
  class ToolDescription {
6
7
  constructor({ title, name, description, inputSchema, inputSpec, outputSpec, outputSchema, defs }) {
@@ -139,7 +140,41 @@ class AgentsClient {
139
140
  return await this.client.listToolkits(params);
140
141
  }
141
142
  async invokeTool(params) {
142
- return await this.client.invoke(params);
143
+ if (params.input === undefined) {
144
+ return await this.client.invoke({
145
+ toolkit: params.toolkit,
146
+ tool: params.tool,
147
+ arguments: params.arguments ?? {},
148
+ participantId: params.participantId,
149
+ onBehalfOfId: params.onBehalfOfId,
150
+ });
151
+ }
152
+ if (params.input instanceof agent_1.ToolContentInput) {
153
+ const output = await this.client.invokeToolCall({
154
+ toolkit: params.toolkit,
155
+ tool: params.tool,
156
+ input: params.input.content,
157
+ participantId: params.participantId,
158
+ onBehalfOfId: params.onBehalfOfId,
159
+ });
160
+ return output.kind === "content"
161
+ ? new agent_1.ToolContentOutput(output.content)
162
+ : new agent_1.ToolStreamOutput(output.stream, { inputClosed: output.inputClosed });
163
+ }
164
+ if (params.input instanceof agent_1.ToolStreamInput) {
165
+ const output = await this.client.invokeToolCall({
166
+ toolkit: params.toolkit,
167
+ tool: params.tool,
168
+ input: params.input.stream,
169
+ streamInput: true,
170
+ participantId: params.participantId,
171
+ onBehalfOfId: params.onBehalfOfId,
172
+ });
173
+ return output.kind === "content"
174
+ ? new agent_1.ToolContentOutput(output.content)
175
+ : new agent_1.ToolStreamOutput(output.stream, { inputClosed: output.inputClosed });
176
+ }
177
+ throw new Error("invokeTool input must be ToolContentInput or ToolStreamInput");
143
178
  }
144
179
  }
145
180
  exports.AgentsClient = AgentsClient;
@@ -1,42 +1,137 @@
1
1
  import { RoomClient } from "./room-client";
2
2
  import { RequiredToolkit } from "./requirement";
3
3
  import { type Content } from "./response";
4
+ import { RoomServerException } from "./room-server-client";
4
5
  import { ToolContentSpec } from "./tool-content-type";
5
- export declare abstract class Tool {
6
+ import { Participant } from "./participant";
7
+ export type ValidationMode = "full" | "contentTypes" | "none";
8
+ export declare class InvalidToolDataException extends RoomServerException {
9
+ constructor(message: string);
10
+ }
11
+ export declare class ToolContext {
12
+ readonly caller?: Participant;
13
+ readonly onBehalfOf?: Participant;
14
+ constructor({ caller, onBehalfOf }?: {
15
+ caller?: Participant;
16
+ onBehalfOf?: Participant;
17
+ });
18
+ }
19
+ export declare class RoomToolContext extends ToolContext {
20
+ readonly room: RoomClient;
21
+ constructor({ room, caller, onBehalfOf }: {
22
+ room: RoomClient;
23
+ caller?: Participant;
24
+ onBehalfOf?: Participant;
25
+ });
26
+ }
27
+ export declare abstract class ToolInput {
28
+ }
29
+ export declare class ToolContentInput extends ToolInput {
30
+ readonly content: Content;
31
+ constructor(content: Content);
32
+ }
33
+ export declare class ToolStreamInput extends ToolInput {
34
+ readonly stream: AsyncIterable<Content>;
35
+ constructor(stream: AsyncIterable<Content>);
36
+ }
37
+ export declare abstract class ToolCallOutput {
38
+ }
39
+ export declare class ToolContentOutput extends ToolCallOutput {
40
+ readonly content: Content;
41
+ constructor(content: Content);
42
+ }
43
+ export declare class ToolStreamOutput extends ToolCallOutput {
44
+ readonly stream: AsyncIterable<Content>;
45
+ readonly inputClosed?: Promise<void>;
46
+ constructor(stream: AsyncIterable<Content>, { inputClosed }?: {
47
+ inputClosed?: Promise<void>;
48
+ });
49
+ }
50
+ export declare abstract class BaseTool {
6
51
  readonly name: string;
7
- readonly description: string;
8
- readonly title: string;
52
+ readonly description?: string;
53
+ readonly title?: string;
54
+ readonly inputSchema?: Record<string, any>;
9
55
  readonly inputSpec?: ToolContentSpec;
10
56
  readonly outputSpec?: ToolContentSpec;
11
- constructor({ name, description, title, inputSchema, inputSpec, outputSpec, outputSchema }: {
57
+ readonly outputSchema?: Record<string, any>;
58
+ readonly defs?: Record<string, any>;
59
+ constructor({ name, description, title, inputSchema, inputSpec, outputSpec, outputSchema, defs }: {
12
60
  name: string;
13
- description: string;
14
- title: string;
61
+ description?: string;
62
+ title?: string;
63
+ inputSchema?: Record<string, any>;
64
+ inputSpec?: ToolContentSpec;
65
+ outputSpec?: ToolContentSpec;
66
+ outputSchema?: Record<string, any>;
67
+ defs?: Record<string, any>;
68
+ });
69
+ }
70
+ export declare abstract class FunctionTool extends BaseTool {
71
+ abstract execute(context: ToolContext, arguments_: Record<string, any>): Promise<Content>;
72
+ executeStream(context: ToolContext, arguments_: Record<string, any>): AsyncIterable<Content>;
73
+ }
74
+ export declare abstract class ContentTool extends BaseTool {
75
+ abstract execute(context: ToolContext, input: ToolInput): Promise<ToolCallOutput>;
76
+ }
77
+ export declare abstract class Tool extends BaseTool {
78
+ constructor(params: {
79
+ name: string;
80
+ description?: string;
81
+ title?: string;
15
82
  inputSchema?: Record<string, any>;
16
83
  inputSpec?: ToolContentSpec;
17
84
  outputSpec?: ToolContentSpec;
18
85
  outputSchema?: Record<string, any>;
86
+ defs?: Record<string, any>;
19
87
  });
20
- get inputSchema(): Record<string, any> | undefined;
21
- get outputSchema(): Record<string, any> | undefined;
22
88
  abstract execute(arguments_: Record<string, any>): Promise<Content>;
23
89
  }
24
90
  export declare class Toolkit {
25
91
  readonly name: string;
26
- readonly title: string;
27
- readonly description: string;
28
- readonly tools: Tool[];
92
+ readonly title?: string;
93
+ readonly description?: string;
94
+ readonly tools: BaseTool[];
29
95
  readonly rules: string[];
30
- constructor({ name, title, description, tools, rules }: {
96
+ readonly validationMode: ValidationMode;
97
+ constructor({ name, title, description, tools, rules, validationMode }: {
31
98
  name: string;
32
99
  title?: string;
33
100
  description?: string;
34
- tools: Tool[];
101
+ tools: BaseTool[];
35
102
  rules?: string[];
103
+ validationMode?: ValidationMode;
36
104
  });
37
- getTool(name: string): Tool;
105
+ getTool(name: string): BaseTool;
38
106
  getTools(): Record<string, any>;
39
107
  execute(name: string, args: Record<string, any>): Promise<Content>;
108
+ execute(context: ToolContext, name: string, input: ToolInput): Promise<ToolCallOutput>;
109
+ private executeTool;
110
+ private decodeFunctionToolArguments;
111
+ private get shouldValidateContentTypes();
112
+ private get shouldValidateSchema();
113
+ resolveInputSpec(tool: BaseTool): ToolContentSpec | undefined;
114
+ resolveOutputSpec(tool: BaseTool): ToolContentSpec | undefined;
115
+ validateStreamMode({ tool, direction, spec, stream }: {
116
+ tool: BaseTool;
117
+ direction: "input" | "output";
118
+ spec?: ToolContentSpec;
119
+ stream: boolean;
120
+ }): void;
121
+ validateContentType({ tool, direction, spec, content }: {
122
+ tool: BaseTool;
123
+ direction: "input" | "output";
124
+ spec?: ToolContentSpec;
125
+ content: Content;
126
+ }): void;
127
+ validateSchema({ tool, direction, content, schema }: {
128
+ tool: BaseTool;
129
+ direction: "input" | "output";
130
+ content: Content;
131
+ schema?: Record<string, any>;
132
+ }): void;
133
+ validateInputContent(tool: BaseTool, content: Content): void;
134
+ validateOutputContent(tool: BaseTool, content: Content): void;
40
135
  }
41
136
  export declare class HostedToolkit {
42
137
  readonly toolkit: Toolkit;