@mastra/connect 1.0.4-alpha.0 → 1.1.0-alpha.2
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.
- package/dist/channels.d.ts.map +1 -1
- package/dist/client.d.ts +6 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +325 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +325 -28
- package/dist/index.js.map +1 -1
- package/dist/providers/channels.d.ts +3 -4
- package/dist/providers/channels.d.ts.map +1 -1
- package/dist/providers/fireflies/tools/get-transcript.d.ts +4 -4
- package/dist/providers/fireflies/tools/get-transcript.d.ts.map +1 -1
- package/dist/providers/google-drive/tools/create-folder.d.ts.map +1 -1
- package/dist/providers/google-drive/tools/export-file.d.ts +32 -0
- package/dist/providers/google-drive/tools/export-file.d.ts.map +1 -0
- package/dist/providers/google-drive/tools/list-revisions.d.ts +44 -0
- package/dist/providers/google-drive/tools/list-revisions.d.ts.map +1 -0
- package/dist/providers/google-drive/tools/move-file.d.ts.map +1 -1
- package/dist/providers/google-drive/tools/upload-document.d.ts.map +1 -1
- package/dist/providers/google-drive/tools.d.ts.map +1 -1
- package/dist/tools.d.ts +16 -1
- package/dist/tools.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/channels.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels.d.ts","sourceRoot":"","sources":["../src/channels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,KAAK,EAAE,oBAAoB,EAAqB,MAAM,aAAa,CAAC;AAI3E,OAAO,KAAK,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,2BAA2B,EAC3B,8BAA8B,EAC/B,MAAM,yBAAyB,CAAC;AAIjC,KAAK,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,WA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;;;;;GA4BG;AACH,wBAAsB,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAmMvF"}
|
package/dist/client.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export interface ConnectClientOptions {
|
|
|
9
9
|
accessToken?: string;
|
|
10
10
|
/** Organization id. Falls back to MASTRA_ORG_ID; the x-organization-id header is omitted when absent. */
|
|
11
11
|
orgId?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Project id, sent as the x-mastra-project-id header so the platform can
|
|
14
|
+
* attribute proxy activity to this project. Falls back to MASTRA_PROJECT_ID;
|
|
15
|
+
* the header is omitted when absent.
|
|
16
|
+
*/
|
|
17
|
+
projectId?: string;
|
|
12
18
|
/**
|
|
13
19
|
* Integrations service base URL. Falls back to MASTRA_INTEGRATIONS_API_URL,
|
|
14
20
|
* then the regional default from MASTRA_PLATFORM_REGION ('us' | 'eu'),
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,0GAA0G;IAC1G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yGAAyG;IACzG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4FAA4F;IAC5F,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;CACrB;AA2BD,wBAAgB,aAAa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I,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AA8DD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,wBAAsB,YAAY,CAChC,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,OAAO,CAAC,CAElB;AAED,kFAAkF;AAClF,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAiGxB"}
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@ let _mastra_mcp = require("@mastra/mcp");
|
|
|
3
3
|
let zod = require("zod");
|
|
4
4
|
let _mastra_core_observability = require("@mastra/core/observability");
|
|
5
5
|
let _mastra_core_tools = require("@mastra/core/tools");
|
|
6
|
+
let crypto = require("crypto");
|
|
6
7
|
//#region src/errors.ts
|
|
7
8
|
const MAX_DETAIL_LENGTH = 2e3;
|
|
8
9
|
var MastraConnectError = class extends Error {
|
|
@@ -245,6 +246,8 @@ function resolveClient(options) {
|
|
|
245
246
|
};
|
|
246
247
|
const orgId = options?.orgId?.trim() || process.env.MASTRA_ORG_ID?.trim();
|
|
247
248
|
if (orgId) headers["x-organization-id"] = orgId;
|
|
249
|
+
const projectId = options?.projectId?.trim() || process.env.MASTRA_PROJECT_ID?.trim();
|
|
250
|
+
if (projectId) headers["x-mastra-project-id"] = projectId;
|
|
248
251
|
return {
|
|
249
252
|
baseUrl,
|
|
250
253
|
headers,
|
|
@@ -1027,7 +1030,6 @@ const CHANNELS$1 = [
|
|
|
1027
1030
|
integrationId: "microsoft-teams",
|
|
1028
1031
|
async create(options, runtime) {
|
|
1029
1032
|
const mod = await import("@mastra/teams");
|
|
1030
|
-
if (!process.env.MASTRA_ENCRYPTION_KEY) throw new MastraConnectError("invalid_options", "Microsoft Teams channel: MASTRA_ENCRYPTION_KEY is not set. The Teams install store persists per-agent bot secrets and requires an at-rest encryption key (a 32-byte value, base64-encoded).");
|
|
1031
1033
|
const safeOptions = stripReservedOptions("microsoft-teams", options);
|
|
1032
1034
|
const tokenResolver = async (scope) => {
|
|
1033
1035
|
const fresh = await runtime.getCredential();
|
|
@@ -1036,10 +1038,22 @@ const CHANNELS$1 = [
|
|
|
1036
1038
|
if (!token) throw new MastraConnectError("no_active_connection", `Teams connection ${runtime.getConnectionId()} has no Dev Portal token on its credential. Reconnect with an integration that requests the ${mod.TEAMS_DEV_PORTAL_SCOPE} scope.`);
|
|
1037
1039
|
return token;
|
|
1038
1040
|
};
|
|
1039
|
-
|
|
1041
|
+
const config = {
|
|
1040
1042
|
tokenResolver,
|
|
1041
1043
|
...safeOptions ?? {}
|
|
1042
|
-
}
|
|
1044
|
+
};
|
|
1045
|
+
const usingDerivedKey = !process.env.MASTRA_ENCRYPTION_KEY;
|
|
1046
|
+
if (usingDerivedKey) config.encryptionKey = Buffer.from((0, crypto.hkdfSync)("sha256", runtime.client.accessToken, "mastra-connect", "microsoft-teams-install-store", 32)).toString("base64");
|
|
1047
|
+
let warnedDerivedKey = false;
|
|
1048
|
+
return {
|
|
1049
|
+
provider: new mod.TeamsProvider(config),
|
|
1050
|
+
async sync() {
|
|
1051
|
+
if (usingDerivedKey && !warnedDerivedKey) {
|
|
1052
|
+
warnedDerivedKey = true;
|
|
1053
|
+
console.warn("[@mastra/connect] MASTRA_ENCRYPTION_KEY is not set: encrypting the Microsoft Teams install store with a key derived from the platform access token. Set MASTRA_ENCRYPTION_KEY to use a dedicated key — otherwise rotating the platform access token makes stored bot credentials unreadable (disconnect and reconnect the channel to re-provision).");
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1043
1057
|
}
|
|
1044
1058
|
}
|
|
1045
1059
|
];
|
|
@@ -7874,10 +7888,15 @@ const SentenceSchema = zod.z.object({
|
|
|
7874
7888
|
speaker_name: zod.z.string().nullish(),
|
|
7875
7889
|
speaker_id: zod.z.string().nullish(),
|
|
7876
7890
|
raw_text: zod.z.string().nullish(),
|
|
7877
|
-
start_time: zod.z.
|
|
7878
|
-
end_time: zod.z.
|
|
7891
|
+
start_time: zod.z.number().nullish(),
|
|
7892
|
+
end_time: zod.z.number().nullish(),
|
|
7879
7893
|
text: zod.z.string().nullish()
|
|
7880
7894
|
});
|
|
7895
|
+
const ProviderSentenceSchema = SentenceSchema.extend({
|
|
7896
|
+
speaker_id: zod.z.union([zod.z.string(), zod.z.number()]).nullish(),
|
|
7897
|
+
start_time: zod.z.union([zod.z.number(), zod.z.string()]).nullish(),
|
|
7898
|
+
end_time: zod.z.union([zod.z.number(), zod.z.string()]).nullish()
|
|
7899
|
+
});
|
|
7881
7900
|
const SummarySectionSchema = zod.z.object({
|
|
7882
7901
|
title: zod.z.string().nullish(),
|
|
7883
7902
|
content: zod.z.string().nullish()
|
|
@@ -7944,7 +7963,7 @@ const AnalyticsSchema = zod.z.object({
|
|
|
7944
7963
|
const TranscriptSchema = zod.z.object({
|
|
7945
7964
|
id: zod.z.string().nullish(),
|
|
7946
7965
|
title: zod.z.string().nullish(),
|
|
7947
|
-
sentences: zod.z.array(
|
|
7966
|
+
sentences: zod.z.array(ProviderSentenceSchema).nullish(),
|
|
7948
7967
|
summary: ProviderSummarySchema$1.nullable().optional(),
|
|
7949
7968
|
speakers: zod.z.array(SpeakerSchema).nullish(),
|
|
7950
7969
|
meeting_info: MeetingInfoSchema.nullable().optional(),
|
|
@@ -7972,6 +7991,22 @@ const getTranscriptOutputSchema = zod.z.object({
|
|
|
7972
7991
|
function normalizeActionItems$1(actionItems) {
|
|
7973
7992
|
return Array.isArray(actionItems) ? actionItems.join("\n") : actionItems;
|
|
7974
7993
|
}
|
|
7994
|
+
function toFiniteNumber(value) {
|
|
7995
|
+
if (value == null) return void 0;
|
|
7996
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
7997
|
+
const trimmed = value.trim();
|
|
7998
|
+
if (trimmed === "") return void 0;
|
|
7999
|
+
const parsed = Number(trimmed);
|
|
8000
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
8001
|
+
}
|
|
8002
|
+
function normalizeSentence(sentence) {
|
|
8003
|
+
return {
|
|
8004
|
+
...sentence,
|
|
8005
|
+
speaker_id: sentence.speaker_id != null ? String(sentence.speaker_id) : sentence.speaker_id,
|
|
8006
|
+
start_time: toFiniteNumber(sentence.start_time),
|
|
8007
|
+
end_time: toFiniteNumber(sentence.end_time)
|
|
8008
|
+
};
|
|
8009
|
+
}
|
|
7975
8010
|
function getTranscriptTool(proxy) {
|
|
7976
8011
|
return (0, _mastra_core_tools.createTool)({
|
|
7977
8012
|
id: "fireflies_get_transcript",
|
|
@@ -8077,7 +8112,7 @@ function getTranscriptTool(proxy) {
|
|
|
8077
8112
|
return {
|
|
8078
8113
|
id: transcript.id ?? void 0,
|
|
8079
8114
|
title: transcript.title ?? void 0,
|
|
8080
|
-
sentences: transcript.sentences
|
|
8115
|
+
sentences: transcript.sentences ? transcript.sentences.map(normalizeSentence) : void 0,
|
|
8081
8116
|
summary: transcript.summary ? {
|
|
8082
8117
|
...transcript.summary,
|
|
8083
8118
|
action_items: transcript.summary.action_items != null ? normalizeActionItems$1(transcript.summary.action_items) : transcript.summary.action_items
|
|
@@ -19806,11 +19841,11 @@ function insertTextTool(proxy) {
|
|
|
19806
19841
|
}
|
|
19807
19842
|
//#endregion
|
|
19808
19843
|
//#region src/providers/google-docs/tools/list-revisions.ts
|
|
19809
|
-
const listRevisionsInputSchema = zod.z.object({
|
|
19844
|
+
const listRevisionsInputSchema$1 = zod.z.object({
|
|
19810
19845
|
documentId: zod.z.string().describe("Google Docs document ID. Example: \"1Kj3d86Z-Sfd56YP4dImQ-ggMRyP2QZ_BRO33zOO224c\""),
|
|
19811
19846
|
pageToken: zod.z.string().optional().describe("Pagination token from the previous response. Omit for the first page.")
|
|
19812
19847
|
});
|
|
19813
|
-
const LastModifyingUserSchema = zod.z.object({
|
|
19848
|
+
const LastModifyingUserSchema$1 = zod.z.object({
|
|
19814
19849
|
kind: zod.z.string().optional(),
|
|
19815
19850
|
displayName: zod.z.string().optional(),
|
|
19816
19851
|
photoLink: zod.z.string().optional(),
|
|
@@ -19818,27 +19853,27 @@ const LastModifyingUserSchema = zod.z.object({
|
|
|
19818
19853
|
permissionId: zod.z.string().optional(),
|
|
19819
19854
|
emailAddress: zod.z.string().optional()
|
|
19820
19855
|
});
|
|
19821
|
-
const RevisionSchema = zod.z.object({
|
|
19856
|
+
const RevisionSchema$1 = zod.z.object({
|
|
19822
19857
|
id: zod.z.string(),
|
|
19823
19858
|
modifiedTime: zod.z.string().optional(),
|
|
19824
|
-
lastModifyingUser: LastModifyingUserSchema.optional(),
|
|
19859
|
+
lastModifyingUser: LastModifyingUserSchema$1.optional(),
|
|
19825
19860
|
keepForever: zod.z.boolean().optional(),
|
|
19826
19861
|
published: zod.z.boolean().optional()
|
|
19827
19862
|
});
|
|
19828
|
-
const listRevisionsOutputSchema = zod.z.object({
|
|
19829
|
-
revisions: zod.z.array(RevisionSchema),
|
|
19863
|
+
const listRevisionsOutputSchema$1 = zod.z.object({
|
|
19864
|
+
revisions: zod.z.array(RevisionSchema$1),
|
|
19830
19865
|
nextPageToken: zod.z.string().optional()
|
|
19831
19866
|
});
|
|
19832
|
-
const DriveRevisionsResponseSchema = zod.z.object({
|
|
19867
|
+
const DriveRevisionsResponseSchema$1 = zod.z.object({
|
|
19833
19868
|
nextPageToken: zod.z.string().optional(),
|
|
19834
19869
|
revisions: zod.z.array(zod.z.unknown()).optional()
|
|
19835
19870
|
});
|
|
19836
|
-
function listRevisionsTool(proxy) {
|
|
19871
|
+
function listRevisionsTool$1(proxy) {
|
|
19837
19872
|
return (0, _mastra_core_tools.createTool)({
|
|
19838
19873
|
id: "google_docs_list_revisions",
|
|
19839
19874
|
description: "List the revision history for a Google Doc.",
|
|
19840
|
-
inputSchema: listRevisionsInputSchema,
|
|
19841
|
-
outputSchema: listRevisionsOutputSchema,
|
|
19875
|
+
inputSchema: listRevisionsInputSchema$1,
|
|
19876
|
+
outputSchema: listRevisionsOutputSchema$1,
|
|
19842
19877
|
execute: async (input, { requestContext }) => {
|
|
19843
19878
|
const platformProxy = proxy.withRequestContext(requestContext);
|
|
19844
19879
|
const response = await platformProxy.get({
|
|
@@ -19851,7 +19886,7 @@ function listRevisionsTool(proxy) {
|
|
|
19851
19886
|
baseUrlOverride: "https://www.googleapis.com",
|
|
19852
19887
|
retries: 3
|
|
19853
19888
|
});
|
|
19854
|
-
const parsedResponse = DriveRevisionsResponseSchema.safeParse(response.data);
|
|
19889
|
+
const parsedResponse = DriveRevisionsResponseSchema$1.safeParse(response.data);
|
|
19855
19890
|
if (!parsedResponse.success) throw new platformProxy.ActionError({
|
|
19856
19891
|
type: "invalid_response",
|
|
19857
19892
|
message: "Invalid response from Google Drive API"
|
|
@@ -19859,7 +19894,7 @@ function listRevisionsTool(proxy) {
|
|
|
19859
19894
|
const rawRevisions = parsedResponse.data.revisions ?? [];
|
|
19860
19895
|
const revisions = [];
|
|
19861
19896
|
for (const rawRevision of rawRevisions) {
|
|
19862
|
-
const parsedRevision = RevisionSchema.safeParse(rawRevision);
|
|
19897
|
+
const parsedRevision = RevisionSchema$1.safeParse(rawRevision);
|
|
19863
19898
|
if (parsedRevision.success) revisions.push(parsedRevision.data);
|
|
19864
19899
|
}
|
|
19865
19900
|
return {
|
|
@@ -20755,7 +20790,7 @@ function createGoogleDocsTools(options) {
|
|
|
20755
20790
|
google_docs_insert_table_row: insertTableRowTool$1(platformProxy),
|
|
20756
20791
|
google_docs_insert_table: insertTableTool(platformProxy),
|
|
20757
20792
|
google_docs_insert_text: insertTextTool(platformProxy),
|
|
20758
|
-
google_docs_list_revisions: listRevisionsTool(platformProxy),
|
|
20793
|
+
google_docs_list_revisions: listRevisionsTool$1(platformProxy),
|
|
20759
20794
|
google_docs_merge_table_cells: mergeTableCellsTool(platformProxy),
|
|
20760
20795
|
google_docs_pin_table_header_rows: pinTableHeaderRowsTool(platformProxy),
|
|
20761
20796
|
google_docs_replace_all_text: replaceAllTextTool(platformProxy),
|
|
@@ -20909,7 +20944,10 @@ function createFolderTool(proxy) {
|
|
|
20909
20944
|
if (input.parentId) requestBody["parents"] = [input.parentId];
|
|
20910
20945
|
const response = await platformProxy.post({
|
|
20911
20946
|
endpoint: "/drive/v3/files",
|
|
20912
|
-
params: {
|
|
20947
|
+
params: {
|
|
20948
|
+
supportsAllDrives: "true",
|
|
20949
|
+
fields: "id,name,mimeType,createdTime,parents"
|
|
20950
|
+
},
|
|
20913
20951
|
data: requestBody,
|
|
20914
20952
|
retries: 3
|
|
20915
20953
|
});
|
|
@@ -21108,6 +21146,56 @@ function emptyTrashTool(proxy) {
|
|
|
21108
21146
|
});
|
|
21109
21147
|
}
|
|
21110
21148
|
//#endregion
|
|
21149
|
+
//#region src/providers/google-drive/tools/export-file.ts
|
|
21150
|
+
const exportFileInputSchema = zod.z.object({
|
|
21151
|
+
fileId: zod.z.string().describe("The ID of the Google Workspace file to export (Doc, Sheet, Slide, etc.). Example: \"1Kj3d86Z-Sfd56YP4dImQ-ggMRyP2QZ_BRO33zOO224c\""),
|
|
21152
|
+
mimeType: zod.z.enum([
|
|
21153
|
+
"application/pdf",
|
|
21154
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
21155
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
21156
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
21157
|
+
"text/html",
|
|
21158
|
+
"text/plain",
|
|
21159
|
+
"text/csv",
|
|
21160
|
+
"application/rtf",
|
|
21161
|
+
"application/epub+zip"
|
|
21162
|
+
]).describe("The target MIME type for the export.")
|
|
21163
|
+
});
|
|
21164
|
+
const exportFileOutputSchema = zod.z.object({
|
|
21165
|
+
fileId: zod.z.string(),
|
|
21166
|
+
mimeType: zod.z.string(),
|
|
21167
|
+
data: zod.z.string().describe("The exported file encoded as a base64 string."),
|
|
21168
|
+
size: zod.z.number().describe("The size of the exported data in bytes.")
|
|
21169
|
+
});
|
|
21170
|
+
function exportFileTool(proxy) {
|
|
21171
|
+
return (0, _mastra_core_tools.createTool)({
|
|
21172
|
+
id: "google_drive_export_file",
|
|
21173
|
+
description: "Export a Google Workspace file (Doc, Sheet, Slide, etc.) to the specified MIME type.",
|
|
21174
|
+
inputSchema: exportFileInputSchema,
|
|
21175
|
+
outputSchema: exportFileOutputSchema,
|
|
21176
|
+
execute: async (input, { requestContext }) => {
|
|
21177
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
21178
|
+
const rawData = (await platformProxy.get({
|
|
21179
|
+
endpoint: `/drive/v3/files/${encodeURIComponent(input.fileId)}/export`,
|
|
21180
|
+
params: { mimeType: input.mimeType },
|
|
21181
|
+
responseType: "arraybuffer",
|
|
21182
|
+
retries: 3
|
|
21183
|
+
})).data;
|
|
21184
|
+
if (typeof rawData !== "object" || rawData === null) throw new platformProxy.ActionError({
|
|
21185
|
+
type: "invalid_response",
|
|
21186
|
+
message: "Expected binary response from export API."
|
|
21187
|
+
});
|
|
21188
|
+
const buffer = Buffer.isBuffer(rawData) ? rawData : Buffer.from(rawData);
|
|
21189
|
+
return {
|
|
21190
|
+
fileId: input.fileId,
|
|
21191
|
+
mimeType: input.mimeType,
|
|
21192
|
+
data: buffer.toString("base64"),
|
|
21193
|
+
size: buffer.length
|
|
21194
|
+
};
|
|
21195
|
+
}
|
|
21196
|
+
});
|
|
21197
|
+
}
|
|
21198
|
+
//#endregion
|
|
21111
21199
|
//#region src/providers/google-drive/tools/find-file.ts
|
|
21112
21200
|
const findFileInputSchema = zod.z.object({
|
|
21113
21201
|
query: zod.z.string().optional().describe("Search query string. Uses Google Drive search query syntax. Example: \"name contains 'report'\" or \"mimeType = 'application/pdf'\". If not provided, returns all files."),
|
|
@@ -21933,6 +22021,70 @@ function listPermissionsTool(proxy) {
|
|
|
21933
22021
|
});
|
|
21934
22022
|
}
|
|
21935
22023
|
//#endregion
|
|
22024
|
+
//#region src/providers/google-drive/tools/list-revisions.ts
|
|
22025
|
+
const listRevisionsInputSchema = zod.z.object({
|
|
22026
|
+
fileId: zod.z.string().describe("The Drive file ID. Example: \"1Kj3d86Z-Sfd56YP4dImQ-ggMRyP2QZ_BRO33zOO224c\""),
|
|
22027
|
+
pageToken: zod.z.string().optional().describe("Pagination token from the previous response. Omit for the first page.")
|
|
22028
|
+
});
|
|
22029
|
+
const LastModifyingUserSchema = zod.z.object({
|
|
22030
|
+
kind: zod.z.string().optional(),
|
|
22031
|
+
displayName: zod.z.string().optional(),
|
|
22032
|
+
photoLink: zod.z.string().optional(),
|
|
22033
|
+
me: zod.z.boolean().optional(),
|
|
22034
|
+
permissionId: zod.z.string().optional(),
|
|
22035
|
+
emailAddress: zod.z.string().optional()
|
|
22036
|
+
});
|
|
22037
|
+
const RevisionSchema = zod.z.object({
|
|
22038
|
+
id: zod.z.string(),
|
|
22039
|
+
modifiedTime: zod.z.string().optional(),
|
|
22040
|
+
lastModifyingUser: LastModifyingUserSchema.optional(),
|
|
22041
|
+
keepForever: zod.z.boolean().optional(),
|
|
22042
|
+
published: zod.z.boolean().optional()
|
|
22043
|
+
});
|
|
22044
|
+
const listRevisionsOutputSchema = zod.z.object({
|
|
22045
|
+
revisions: zod.z.array(RevisionSchema),
|
|
22046
|
+
nextPageToken: zod.z.string().optional()
|
|
22047
|
+
});
|
|
22048
|
+
const DriveRevisionsResponseSchema = zod.z.object({
|
|
22049
|
+
nextPageToken: zod.z.string().optional(),
|
|
22050
|
+
revisions: zod.z.array(zod.z.unknown()).optional()
|
|
22051
|
+
});
|
|
22052
|
+
function listRevisionsTool(proxy) {
|
|
22053
|
+
return (0, _mastra_core_tools.createTool)({
|
|
22054
|
+
id: "google_drive_list_revisions",
|
|
22055
|
+
description: "List the revision history for a Drive file.",
|
|
22056
|
+
inputSchema: listRevisionsInputSchema,
|
|
22057
|
+
outputSchema: listRevisionsOutputSchema,
|
|
22058
|
+
execute: async (input, { requestContext }) => {
|
|
22059
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
22060
|
+
const response = await platformProxy.get({
|
|
22061
|
+
endpoint: `/drive/v3/files/${encodeURIComponent(input.fileId)}/revisions`,
|
|
22062
|
+
params: {
|
|
22063
|
+
fields: "nextPageToken,revisions(id,modifiedTime,lastModifyingUser,keepForever,published)",
|
|
22064
|
+
pageSize: "100",
|
|
22065
|
+
...input.pageToken !== void 0 && { pageToken: input.pageToken }
|
|
22066
|
+
},
|
|
22067
|
+
retries: 3
|
|
22068
|
+
});
|
|
22069
|
+
const parsedResponse = DriveRevisionsResponseSchema.safeParse(response.data);
|
|
22070
|
+
if (!parsedResponse.success) throw new platformProxy.ActionError({
|
|
22071
|
+
type: "invalid_response",
|
|
22072
|
+
message: "Invalid response from Google Drive API"
|
|
22073
|
+
});
|
|
22074
|
+
const rawRevisions = parsedResponse.data.revisions ?? [];
|
|
22075
|
+
const revisions = [];
|
|
22076
|
+
for (const rawRevision of rawRevisions) {
|
|
22077
|
+
const parsedRevision = RevisionSchema.safeParse(rawRevision);
|
|
22078
|
+
if (parsedRevision.success) revisions.push(parsedRevision.data);
|
|
22079
|
+
}
|
|
22080
|
+
return {
|
|
22081
|
+
revisions,
|
|
22082
|
+
...parsedResponse.data.nextPageToken !== void 0 && { nextPageToken: parsedResponse.data.nextPageToken }
|
|
22083
|
+
};
|
|
22084
|
+
}
|
|
22085
|
+
});
|
|
22086
|
+
}
|
|
22087
|
+
//#endregion
|
|
21936
22088
|
//#region src/providers/google-drive/tools/move-file.ts
|
|
21937
22089
|
const moveFileInputSchema = zod.z.object({
|
|
21938
22090
|
fileId: zod.z.string().describe("The ID of the file to move. Example: \"1mD3ukEAmRqo8u0RF_Cr6IJl9f_uWTYH03vesDhB5Svw\""),
|
|
@@ -21958,6 +22110,7 @@ function moveFileTool(proxy) {
|
|
|
21958
22110
|
params: {
|
|
21959
22111
|
addParents: input.toFolderId,
|
|
21960
22112
|
removeParents: input.fromFolderId,
|
|
22113
|
+
supportsAllDrives: "true",
|
|
21961
22114
|
fields: "id,name,mimeType,parents"
|
|
21962
22115
|
},
|
|
21963
22116
|
retries: 3
|
|
@@ -22307,7 +22460,10 @@ function uploadDocumentTool(proxy) {
|
|
|
22307
22460
|
if (input.folderId) metadataBody["parents"] = [input.folderId];
|
|
22308
22461
|
const createResponse = await platformProxy.post({
|
|
22309
22462
|
endpoint: "/drive/v3/files",
|
|
22310
|
-
params: {
|
|
22463
|
+
params: {
|
|
22464
|
+
supportsAllDrives: "true",
|
|
22465
|
+
fields: "id,name,mimeType,webViewLink,webContentLink"
|
|
22466
|
+
},
|
|
22311
22467
|
data: metadataBody,
|
|
22312
22468
|
retries: 3
|
|
22313
22469
|
});
|
|
@@ -22322,6 +22478,7 @@ function uploadDocumentTool(proxy) {
|
|
|
22322
22478
|
endpoint: `/upload/drive/v3/files/${fileId}`,
|
|
22323
22479
|
params: {
|
|
22324
22480
|
uploadType: "media",
|
|
22481
|
+
supportsAllDrives: "true",
|
|
22325
22482
|
fields: "id,name,mimeType,webViewLink,webContentLink"
|
|
22326
22483
|
},
|
|
22327
22484
|
headers: { "Content-Type": input.mimeType },
|
|
@@ -22332,6 +22489,7 @@ function uploadDocumentTool(proxy) {
|
|
|
22332
22489
|
const status = error?.response?.status;
|
|
22333
22490
|
if (typeof status === "number" && status >= 400 && status < 500) await platformProxy.delete({
|
|
22334
22491
|
endpoint: `/drive/v3/files/${fileId}`,
|
|
22492
|
+
params: { supportsAllDrives: "true" },
|
|
22335
22493
|
retries: 3
|
|
22336
22494
|
}).catch(() => void 0);
|
|
22337
22495
|
throw error;
|
|
@@ -22368,6 +22526,7 @@ function createGoogleDriveTools(options) {
|
|
|
22368
22526
|
google_drive_delete_permission: deletePermissionTool(platformProxy),
|
|
22369
22527
|
google_drive_delete_shared_drive: deleteSharedDriveTool(platformProxy),
|
|
22370
22528
|
google_drive_empty_trash: emptyTrashTool(platformProxy),
|
|
22529
|
+
google_drive_export_file: exportFileTool(platformProxy),
|
|
22371
22530
|
google_drive_find_file: findFileTool(platformProxy),
|
|
22372
22531
|
google_drive_find_folder: findFolderTool(platformProxy),
|
|
22373
22532
|
google_drive_get_about: getAboutTool(platformProxy),
|
|
@@ -22382,6 +22541,7 @@ function createGoogleDriveTools(options) {
|
|
|
22382
22541
|
google_drive_list_drives: listDrivesTool(platformProxy),
|
|
22383
22542
|
google_drive_list_files_non_unified: listFilesNonUnifiedTool(platformProxy),
|
|
22384
22543
|
google_drive_list_permissions: listPermissionsTool(platformProxy),
|
|
22544
|
+
google_drive_list_revisions: listRevisionsTool(platformProxy),
|
|
22385
22545
|
google_drive_move_file: moveFileTool(platformProxy),
|
|
22386
22546
|
google_drive_unhide_shared_drive: unhideSharedDriveTool(platformProxy),
|
|
22387
22547
|
google_drive_update_comment: updateCommentTool$2(platformProxy),
|
|
@@ -75089,13 +75249,23 @@ let nextResolverId = 0;
|
|
|
75089
75249
|
* Expected provider absence is silently skipped. Actionable per-integration
|
|
75090
75250
|
* problems during resolution (needs re-auth or ambiguity) are downgraded to
|
|
75091
75251
|
* warn-and-skip so one bad integration never takes down the whole toolset.
|
|
75252
|
+
*
|
|
75253
|
+
* Pass a callback instead of an options object to vary options per request
|
|
75254
|
+
* (see {@link ToolsOptionsInput}). With the callback form, configuration
|
|
75255
|
+
* validation runs at the first resolution that produces a given options
|
|
75256
|
+
* value — still failing loudly — instead of at call time.
|
|
75092
75257
|
*/
|
|
75093
75258
|
function tools(options = {}) {
|
|
75259
|
+
if (typeof options === "function") return dynamicTools(options);
|
|
75094
75260
|
const projectId = options.projectId?.trim() || process.env.MASTRA_PROJECT_ID?.trim();
|
|
75095
75261
|
if (!projectId) throw new MastraConnectError("missing_project_id", "Missing project id: set MASTRA_PROJECT_ID or pass projectId.");
|
|
75096
75262
|
if (options.ttlMs !== void 0 && (!Number.isFinite(options.ttlMs) || options.ttlMs < 0)) throw new MastraConnectError("invalid_options", `Invalid ttlMs (${options.ttlMs}): expected a finite number of milliseconds >= 0.`);
|
|
75097
75263
|
const ttlMs = options.ttlMs ?? DEFAULT_TTL_MS$1;
|
|
75098
|
-
const
|
|
75264
|
+
const clientOptions = {
|
|
75265
|
+
...options.client,
|
|
75266
|
+
projectId
|
|
75267
|
+
};
|
|
75268
|
+
const client = resolveClient(clientOptions);
|
|
75099
75269
|
const resolverId = ++nextResolverId;
|
|
75100
75270
|
const mcpClients = /* @__PURE__ */ new Map();
|
|
75101
75271
|
const normalizedProviders = normalizeProviderOverrides(options.providers);
|
|
@@ -75143,7 +75313,7 @@ function tools(options = {}) {
|
|
|
75143
75313
|
if (!inflight) inflight = (async () => {
|
|
75144
75314
|
try {
|
|
75145
75315
|
const { connections, catalog, catalogAvailable } = await loadSnapshotInputs();
|
|
75146
|
-
const snapshot = await mapTools(connections, buildRequests(normalizedProviders, catalog, catalogAvailable), options, client, mcpClients, resolverId);
|
|
75316
|
+
const snapshot = await mapTools(connections, buildRequests(normalizedProviders, catalog, catalogAvailable), options, clientOptions, client, mcpClients, resolverId);
|
|
75147
75317
|
cache = {
|
|
75148
75318
|
snapshot,
|
|
75149
75319
|
fetchedAt: Date.now()
|
|
@@ -75194,6 +75364,130 @@ function tools(options = {}) {
|
|
|
75194
75364
|
return resolver;
|
|
75195
75365
|
}
|
|
75196
75366
|
/**
|
|
75367
|
+
* Most distinct options values a callback-form resolver keeps live caches
|
|
75368
|
+
* (and MCP clients) for at once. Callbacks are expected to produce a small,
|
|
75369
|
+
* closed set of option shapes (one per role, say); the cap exists so a
|
|
75370
|
+
* callback that accidentally derives options from unbounded per-request data
|
|
75371
|
+
* cannot leak an MCP client per request. Eviction is least-recently-used and
|
|
75372
|
+
* disconnects the evicted variant's transports.
|
|
75373
|
+
*/
|
|
75374
|
+
const MAX_OPTION_VARIANTS = 32;
|
|
75375
|
+
/**
|
|
75376
|
+
* Builds the callback-form resolver: each resolution invokes `getOptions`
|
|
75377
|
+
* with the request context, then delegates to a memoized static resolver for
|
|
75378
|
+
* that options value, so every distinct options value gets its own snapshot
|
|
75379
|
+
* cache with the normal TTL / stale-while-revalidate semantics. Options
|
|
75380
|
+
* validation happens when a value is first seen (inside `tools()`), so
|
|
75381
|
+
* configuration errors fail that resolution loudly instead of being
|
|
75382
|
+
* swallowed.
|
|
75383
|
+
*/
|
|
75384
|
+
function dynamicTools(getOptions) {
|
|
75385
|
+
const variants = /* @__PURE__ */ new Map();
|
|
75386
|
+
let closing;
|
|
75387
|
+
const disconnectEvicted = (entry) => {
|
|
75388
|
+
entry.resolver.disconnect().catch((error) => {
|
|
75389
|
+
console.warn(`[@mastra/connect] Failed to disconnect evicted tools variant: ${error instanceof Error ? error.message : String(error)}`);
|
|
75390
|
+
});
|
|
75391
|
+
};
|
|
75392
|
+
const releaseVariant = (entry) => {
|
|
75393
|
+
entry.inUse -= 1;
|
|
75394
|
+
if (entry.evicted && entry.inUse === 0) disconnectEvicted(entry);
|
|
75395
|
+
};
|
|
75396
|
+
const acquireVariant = async (ctx) => {
|
|
75397
|
+
if (closing) await closing;
|
|
75398
|
+
const options = await getOptions(ctx);
|
|
75399
|
+
if (closing) await closing;
|
|
75400
|
+
if (typeof options !== "object" || options === null || Array.isArray(options)) throw new MastraConnectError("invalid_options", `The tools() options callback must return a ToolsOptions object, got ${options === null ? "null" : Array.isArray(options) ? "an array" : typeof options}.`);
|
|
75401
|
+
const key = hashOptions(options);
|
|
75402
|
+
const existing = variants.get(key);
|
|
75403
|
+
if (existing) {
|
|
75404
|
+
variants.delete(key);
|
|
75405
|
+
variants.set(key, existing);
|
|
75406
|
+
existing.inUse += 1;
|
|
75407
|
+
return existing;
|
|
75408
|
+
}
|
|
75409
|
+
const entry = {
|
|
75410
|
+
resolver: tools(options),
|
|
75411
|
+
inUse: 1,
|
|
75412
|
+
evicted: false
|
|
75413
|
+
};
|
|
75414
|
+
variants.set(key, entry);
|
|
75415
|
+
if (variants.size > MAX_OPTION_VARIANTS) {
|
|
75416
|
+
const [oldestKey, oldest] = variants.entries().next().value;
|
|
75417
|
+
variants.delete(oldestKey);
|
|
75418
|
+
console.warn(`[@mastra/connect] tools() options callback produced more than ${MAX_OPTION_VARIANTS} distinct options values; evicting the least recently used variant. Derive options from a small, closed set of inputs (e.g. roles), not per-request data.`);
|
|
75419
|
+
oldest.evicted = true;
|
|
75420
|
+
if (oldest.inUse === 0) disconnectEvicted(oldest);
|
|
75421
|
+
}
|
|
75422
|
+
return entry;
|
|
75423
|
+
};
|
|
75424
|
+
const resolve = async (ctx) => {
|
|
75425
|
+
const entry = await acquireVariant(ctx);
|
|
75426
|
+
try {
|
|
75427
|
+
return await entry.resolver(ctx);
|
|
75428
|
+
} finally {
|
|
75429
|
+
releaseVariant(entry);
|
|
75430
|
+
}
|
|
75431
|
+
};
|
|
75432
|
+
const resolver = Object.assign(resolve, {
|
|
75433
|
+
refresh: async () => {
|
|
75434
|
+
const entry = await acquireVariant(void 0);
|
|
75435
|
+
try {
|
|
75436
|
+
return await entry.resolver.refresh();
|
|
75437
|
+
} finally {
|
|
75438
|
+
releaseVariant(entry);
|
|
75439
|
+
}
|
|
75440
|
+
},
|
|
75441
|
+
disconnect: () => {
|
|
75442
|
+
closing ??= (async () => {
|
|
75443
|
+
try {
|
|
75444
|
+
const all = Array.from(variants.values());
|
|
75445
|
+
variants.clear();
|
|
75446
|
+
await Promise.allSettled(all.map((entry) => entry.resolver.disconnect()));
|
|
75447
|
+
} finally {
|
|
75448
|
+
closing = void 0;
|
|
75449
|
+
}
|
|
75450
|
+
})();
|
|
75451
|
+
return closing;
|
|
75452
|
+
},
|
|
75453
|
+
with: (extra) => withExtraTools(resolver, extra)
|
|
75454
|
+
});
|
|
75455
|
+
return resolver;
|
|
75456
|
+
}
|
|
75457
|
+
/** Identity registry for non-serializable option values (e.g. a custom `client.fetch`). */
|
|
75458
|
+
const functionIdentity = /* @__PURE__ */ new WeakMap();
|
|
75459
|
+
let nextFunctionIdentity = 0;
|
|
75460
|
+
/**
|
|
75461
|
+
* Stable key for an options value: JSON with sorted object keys, so two
|
|
75462
|
+
* callbacks returning structurally equal options share one cached variant.
|
|
75463
|
+
* Functions (and other non-plain values) hash by identity — the same
|
|
75464
|
+
* instance maps to the same key, two different instances to different keys —
|
|
75465
|
+
* which is the safe direction: at worst a duplicate cache entry, never a
|
|
75466
|
+
* false merge of different configurations.
|
|
75467
|
+
*/
|
|
75468
|
+
function hashOptions(options) {
|
|
75469
|
+
const byIdentity = (value) => {
|
|
75470
|
+
let id = functionIdentity.get(value);
|
|
75471
|
+
if (id === void 0) {
|
|
75472
|
+
id = ++nextFunctionIdentity;
|
|
75473
|
+
functionIdentity.set(value, id);
|
|
75474
|
+
}
|
|
75475
|
+
return `__identity_${id}__`;
|
|
75476
|
+
};
|
|
75477
|
+
const encode = (value) => {
|
|
75478
|
+
if (value === void 0) return "__undefined__";
|
|
75479
|
+
if (typeof value === "function") return byIdentity(value);
|
|
75480
|
+
if (Array.isArray(value)) return value.map(encode);
|
|
75481
|
+
if (typeof value === "object" && value !== null) {
|
|
75482
|
+
const proto = Object.getPrototypeOf(value);
|
|
75483
|
+
if (proto !== Object.prototype && proto !== null) return byIdentity(value);
|
|
75484
|
+
return Object.fromEntries(Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([entryKey, entryValue]) => [entryKey, encode(entryValue)]));
|
|
75485
|
+
}
|
|
75486
|
+
return value;
|
|
75487
|
+
};
|
|
75488
|
+
return JSON.stringify(encode(options));
|
|
75489
|
+
}
|
|
75490
|
+
/**
|
|
75197
75491
|
* Builds the resolver `.with()` returns: resolutions merge the base
|
|
75198
75492
|
* resolver's tools with `extra` (extra wins on key collision), cache handles
|
|
75199
75493
|
* delegate to the base, and further `.with()` calls chain.
|
|
@@ -75324,7 +75618,7 @@ function buildRequests(providers, catalog, catalogAvailable) {
|
|
|
75324
75618
|
return requests;
|
|
75325
75619
|
}
|
|
75326
75620
|
/** Maps one platform connection list snapshot to a flat tool record without allowing ambiguous tool ownership. */
|
|
75327
|
-
async function mapTools(connections, requests, options, client, mcpClients, resolverId) {
|
|
75621
|
+
async function mapTools(connections, requests, options, clientOptions, client, mcpClients, resolverId) {
|
|
75328
75622
|
const byIntegrationId = groupByIntegrationId(connections);
|
|
75329
75623
|
const activeMcpKeys = /* @__PURE__ */ new Set();
|
|
75330
75624
|
const result = {};
|
|
@@ -75357,7 +75651,7 @@ async function mapTools(connections, requests, options, client, mcpClients, reso
|
|
|
75357
75651
|
} else {
|
|
75358
75652
|
providerTools = request.registration.createTools({
|
|
75359
75653
|
connectionId: resolution.connectionId,
|
|
75360
|
-
client:
|
|
75654
|
+
client: clientOptions,
|
|
75361
75655
|
...providerFilterOptions(request.options)
|
|
75362
75656
|
});
|
|
75363
75657
|
applyProxyRequireApproval(providerTools, integrationId, request.options.requireApproval);
|
|
@@ -75380,7 +75674,7 @@ async function mapTools(connections, requests, options, client, mcpClients, reso
|
|
|
75380
75674
|
connections: resolution.connections,
|
|
75381
75675
|
allowTools: request.options.allowTools,
|
|
75382
75676
|
disallowTools: request.options.disallowTools,
|
|
75383
|
-
client:
|
|
75677
|
+
client: clientOptions
|
|
75384
75678
|
});
|
|
75385
75679
|
applyProxyRequireApproval(providerTools, integrationId, request.options.requireApproval, [listConnectionsToolKey(integrationId)]);
|
|
75386
75680
|
}
|
|
@@ -75582,7 +75876,10 @@ async function channels(options = {}) {
|
|
|
75582
75876
|
const unknownChannelIds = Object.keys(providerOverrides).filter((integrationId) => !knownChannelIds.has(integrationId) && !providerOverrides[integrationId]?.disabled);
|
|
75583
75877
|
if (unknownChannelIds.length > 0) throw new MastraConnectError("invalid_options", `Unknown channel${unknownChannelIds.length > 1 ? "s" : ""} in the providers option: ${unknownChannelIds.map((id) => `'${id}'`).join(", ")}. Known channels: ${[...knownChannelIds].join(", ")}.`);
|
|
75584
75878
|
const ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
75585
|
-
const client = resolveClient(
|
|
75879
|
+
const client = resolveClient({
|
|
75880
|
+
...options.client,
|
|
75881
|
+
projectId
|
|
75882
|
+
});
|
|
75586
75883
|
const states = [];
|
|
75587
75884
|
for (const registration of CHANNELS) {
|
|
75588
75885
|
if (only !== void 0 && !only.has(registration.integrationId)) continue;
|