@meshagent/meshagent 0.41.2 → 0.41.5

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 (62) hide show
  1. package/CHANGELOG.md +9 -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/index.d.ts +2 -0
  9. package/dist/browser/index.js +2 -0
  10. package/dist/browser/oauth-scopes.d.ts +2 -0
  11. package/dist/browser/oauth-scopes.js +21 -0
  12. package/dist/browser/participant-token.d.ts +1 -3
  13. package/dist/browser/participant-token.js +2 -3
  14. package/dist/browser/room-client.d.ts +16 -0
  15. package/dist/browser/room-client.js +69 -0
  16. package/dist/browser/storage-client.d.ts +3 -1
  17. package/dist/browser/storage-client.js +5 -2
  18. package/dist/browser/tool-content-type.d.ts +1 -1
  19. package/dist/browser/tool-content-type.js +3 -2
  20. package/dist/browser/toolkit-config.d.ts +84 -0
  21. package/dist/browser/toolkit-config.js +415 -0
  22. package/dist/esm/agent-client.d.ts +10 -0
  23. package/dist/esm/agent-client.js +36 -1
  24. package/dist/esm/agent.d.ts +109 -14
  25. package/dist/esm/agent.js +533 -68
  26. package/dist/esm/datasets-client.d.ts +70 -0
  27. package/dist/esm/datasets-client.js +79 -0
  28. package/dist/esm/index.d.ts +2 -0
  29. package/dist/esm/index.js +2 -0
  30. package/dist/esm/oauth-scopes.d.ts +2 -0
  31. package/dist/esm/oauth-scopes.js +21 -0
  32. package/dist/esm/participant-token.d.ts +1 -3
  33. package/dist/esm/participant-token.js +2 -3
  34. package/dist/esm/room-client.d.ts +16 -0
  35. package/dist/esm/room-client.js +69 -0
  36. package/dist/esm/storage-client.d.ts +3 -1
  37. package/dist/esm/storage-client.js +5 -2
  38. package/dist/esm/tool-content-type.d.ts +1 -1
  39. package/dist/esm/tool-content-type.js +3 -2
  40. package/dist/esm/toolkit-config.d.ts +84 -0
  41. package/dist/esm/toolkit-config.js +415 -0
  42. package/dist/node/agent-client.d.ts +10 -0
  43. package/dist/node/agent-client.js +36 -1
  44. package/dist/node/agent.d.ts +109 -14
  45. package/dist/node/agent.js +533 -68
  46. package/dist/node/datasets-client.d.ts +70 -0
  47. package/dist/node/datasets-client.js +79 -0
  48. package/dist/node/index.d.ts +2 -0
  49. package/dist/node/index.js +2 -0
  50. package/dist/node/oauth-scopes.d.ts +2 -0
  51. package/dist/node/oauth-scopes.js +21 -0
  52. package/dist/node/participant-token.d.ts +1 -3
  53. package/dist/node/participant-token.js +2 -3
  54. package/dist/node/room-client.d.ts +16 -0
  55. package/dist/node/room-client.js +69 -0
  56. package/dist/node/storage-client.d.ts +3 -1
  57. package/dist/node/storage-client.js +5 -2
  58. package/dist/node/tool-content-type.d.ts +1 -1
  59. package/dist/node/tool-content-type.js +3 -2
  60. package/dist/node/toolkit-config.d.ts +84 -0
  61. package/dist/node/toolkit-config.js +415 -0
  62. 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
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshagent/meshagent",
3
- "version": "0.41.2",
3
+ "version": "0.41.5",
4
4
  "description": "Meshagent Client",
5
5
  "homepage": "https://github.com/meshagent/meshagent-ts",
6
6
  "scripts": {