@mastra/connect 1.1.0 → 1.2.0-alpha.1
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/client.d.ts +29 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/connect-prompt-tool.d.ts +58 -0
- package/dist/connect-prompt-tool.d.ts.map +1 -0
- package/dist/index.cjs +252 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +252 -38
- package/dist/index.js.map +1 -1
- package/dist/runtime/platform-proxy.d.ts +4 -0
- package/dist/runtime/platform-proxy.d.ts.map +1 -1
- package/dist/tools.d.ts +11 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/user-connect-page.d.ts +5 -3
- package/dist/user-connect-page.d.ts.map +1 -1
- package/dist/user-connect-routes.d.ts +8 -4
- package/dist/user-connect-routes.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/client.d.ts
CHANGED
|
@@ -74,6 +74,10 @@ export type ProjectConnection = z.infer<typeof connectionSchema>;
|
|
|
74
74
|
*/
|
|
75
75
|
export declare const catalogAuthFieldSchema: z.ZodObject<{
|
|
76
76
|
name: z.ZodString;
|
|
77
|
+
target: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
78
|
+
credentials: "credentials";
|
|
79
|
+
params: "params";
|
|
80
|
+
}>>>;
|
|
77
81
|
label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
78
82
|
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
79
83
|
placeholder: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -92,6 +96,10 @@ export declare const integrationCatalogEntrySchema: z.ZodObject<{
|
|
|
92
96
|
authType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
93
97
|
authFields: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
94
98
|
name: z.ZodString;
|
|
99
|
+
target: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
100
|
+
credentials: "credentials";
|
|
101
|
+
params: "params";
|
|
102
|
+
}>>>;
|
|
95
103
|
label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
96
104
|
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
97
105
|
placeholder: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -101,6 +109,10 @@ export declare const integrationCatalogEntrySchema: z.ZodObject<{
|
|
|
101
109
|
}, z.core.$strip>>>>;
|
|
102
110
|
}, z.core.$strip>;
|
|
103
111
|
export type IntegrationCatalogEntry = z.infer<typeof integrationCatalogEntrySchema>;
|
|
112
|
+
declare const projectIntegrationSettingsResponseSchema: z.ZodObject<{
|
|
113
|
+
endUserProviders: z.ZodNullable<z.ZodArray<z.ZodString>>;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
export type ProjectIntegrationSettings = z.infer<typeof projectIntegrationSettingsResponseSchema>;
|
|
104
116
|
/**
|
|
105
117
|
* Secondary access token minted by the vendor alongside the primary oauth2
|
|
106
118
|
* credential (e.g. `devPortalAccessToken` on Microsoft Teams connections).
|
|
@@ -138,6 +150,7 @@ export declare const connectionContextSchema: z.ZodObject<{
|
|
|
138
150
|
export type ConnectionContext = z.infer<typeof connectionContextSchema>;
|
|
139
151
|
export declare function listProjectConnections(client: ResolvedClient, projectId: string): Promise<ProjectConnection[]>;
|
|
140
152
|
export declare function listIntegrations(client: ResolvedClient): Promise<IntegrationCatalogEntry[]>;
|
|
153
|
+
export declare function getProjectIntegrationSettings(client: ResolvedClient, projectId: string): Promise<ProjectIntegrationSettings>;
|
|
141
154
|
export declare function getConnectionContext(client: ResolvedClient, connectionId: string): Promise<ConnectionContext>;
|
|
142
155
|
export declare function getCredential(client: ResolvedClient, connectionId: string): Promise<ConnectionCredential>;
|
|
143
156
|
type ProxyQueryPrimitive = string | number | boolean;
|
|
@@ -168,8 +181,8 @@ export declare function proxyRequestWithResponse(client: ResolvedClient, connect
|
|
|
168
181
|
export declare const connectSessionSchema: z.ZodObject<{
|
|
169
182
|
connectionId: z.ZodString;
|
|
170
183
|
integrationId: z.ZodString;
|
|
171
|
-
connectUrl: z.ZodString
|
|
172
|
-
sessionToken: z.ZodString
|
|
184
|
+
connectUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
185
|
+
sessionToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
173
186
|
expiresAt: z.ZodString;
|
|
174
187
|
}, z.core.$strip>;
|
|
175
188
|
export type ConnectSession = z.infer<typeof connectSessionSchema>;
|
|
@@ -179,6 +192,20 @@ export type ConnectSession = z.infer<typeof connectSessionSchema>;
|
|
|
179
192
|
* end user; an unscoped client creates a global connection.
|
|
180
193
|
*/
|
|
181
194
|
export declare function createProjectConnectSession(client: ResolvedClient, projectId: string, integrationId: string): Promise<ConnectSession>;
|
|
195
|
+
export declare const connectUrlSchema: z.ZodObject<{
|
|
196
|
+
connectUrl: z.ZodString;
|
|
197
|
+
expiresAt: z.ZodString;
|
|
198
|
+
}, z.core.$strip>;
|
|
199
|
+
export type ConnectUrl = z.infer<typeof connectUrlSchema>;
|
|
200
|
+
/**
|
|
201
|
+
* Fetches the vendor connect link for a pending resource-scoped connection
|
|
202
|
+
* from the platform's launch gate. The platform serves it only while the
|
|
203
|
+
* session is pending and unexpired, and only when the client's
|
|
204
|
+
* `x-mastra-resource-id` assertion matches the row — any mismatch is a 404,
|
|
205
|
+
* which surfaces here as `connection_not_found`. This is how the browser's
|
|
206
|
+
* popup enters OAuth: the link itself never reaches browser-visible state.
|
|
207
|
+
*/
|
|
208
|
+
export declare function getConnectUrl(client: ResolvedClient, connectionId: string): Promise<ConnectUrl>;
|
|
182
209
|
/** Disconnects a connection. The platform tears down the vendor side asynchronously. */
|
|
183
210
|
export declare function disconnectConnection(client: ResolvedClient, connectionId: string): Promise<void>;
|
|
184
211
|
export {};
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 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iB/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,cAAc,CAAC,CAuBzB;AAED,eAAO,MAAM,gBAAgB;;;iBAG3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBrG;AAED,wFAAwF;AACxF,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOtG"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { IntegrationCatalogEntry, ProjectConnection } from './client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Record key of the built-in connect-prompt tool. Reserved: a provider tool
|
|
4
|
+
* resolving to the same key is a hard error, same as any duplicate.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CONNECT_PROMPT_TOOL_KEY = "request_connection";
|
|
7
|
+
/** One connectable provider in a connect-prompt payload. */
|
|
8
|
+
export interface ConnectPromptProvider {
|
|
9
|
+
id: string;
|
|
10
|
+
displayName: string | null;
|
|
11
|
+
logoUrl: string | null;
|
|
12
|
+
authType: string | null;
|
|
13
|
+
/** Fields the UI must collect before starting headless authorization. */
|
|
14
|
+
authFields: NonNullable<IntegrationCatalogEntry['authFields']> | null;
|
|
15
|
+
/** Whether a usable (active) connection already serves this provider for the caller. */
|
|
16
|
+
connected: boolean;
|
|
17
|
+
/** Which connection serves it when connected: the caller's own wins over a global one. */
|
|
18
|
+
scope: 'global' | 'user' | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Structured output of the connect-prompt tool. Chat UIs detect
|
|
22
|
+
* `type: 'connect-prompt'` and render the providers as a connect card; the
|
|
23
|
+
* card drives the mounted `userConnectRoutes()` flow (session → launch gate →
|
|
24
|
+
* status polling), so the tool itself never creates sessions or handles URLs.
|
|
25
|
+
*/
|
|
26
|
+
export interface ConnectPromptPayload {
|
|
27
|
+
type: 'connect-prompt';
|
|
28
|
+
/** Echoed when the agent asked for one specific provider and it is connectable. */
|
|
29
|
+
requestedProvider?: string;
|
|
30
|
+
providers: ConnectPromptProvider[];
|
|
31
|
+
}
|
|
32
|
+
export interface ConnectPromptInputs {
|
|
33
|
+
catalog: IntegrationCatalogEntry[];
|
|
34
|
+
connections: ProjectConnection[];
|
|
35
|
+
/** Effective code or project allowlist; undefined means the full catalog. */
|
|
36
|
+
allowlist: Set<string> | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Builds the built-in tool that lets an agent prompt the end user to connect
|
|
40
|
+
* a provider account mid-conversation. Only added to resource-scoped
|
|
41
|
+
* resolutions: without an end-user identity there is nobody to scope a new
|
|
42
|
+
* connection to.
|
|
43
|
+
*
|
|
44
|
+
* The connectable set respects the effective project policy: an explicit
|
|
45
|
+
* `tools({ providers })` allowlist wins, otherwise the project's provider
|
|
46
|
+
* configuration is loaded from Mastra Platform.
|
|
47
|
+
*
|
|
48
|
+
* `loadInputs` is called per tool invocation so provider policy and connection state are fresh —
|
|
49
|
+
* after the user connects through the rendered card, the agent can call the
|
|
50
|
+
* tool again and see `connected: true` without waiting out the snapshot TTL.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildConnectPromptTool({ loadInputs, resourceId, }: {
|
|
53
|
+
loadInputs: () => Promise<ConnectPromptInputs>;
|
|
54
|
+
resourceId: string;
|
|
55
|
+
}): import("@mastra/core/tools").Tool<{
|
|
56
|
+
provider?: string | undefined;
|
|
57
|
+
}, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "request_connection", unknown>;
|
|
58
|
+
//# sourceMappingURL=connect-prompt-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-prompt-tool.d.ts","sourceRoot":"","sources":["../src/connect-prompt-tool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAE5D,4DAA4D;AAC5D,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,yEAAyE;IACzE,UAAU,EAAE,WAAW,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC;IACtE,wFAAwF;IACxF,SAAS,EAAE,OAAO,CAAC;IACnB,0FAA0F;IAC1F,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,gBAAgB,CAAC;IACvB,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,qBAAqB,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,uBAAuB,EAAE,CAAC;IACnC,WAAW,EAAE,iBAAiB,EAAE,CAAC;IACjC,6EAA6E;IAC7E,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;CACpC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,UAAU,EACV,UAAU,GACX,EAAE;IACD,UAAU,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB;;2IAkDA"}
|
package/dist/index.cjs
CHANGED
|
@@ -373,6 +373,13 @@ const connectionListSchema = zod.z.object({ connections: zod.z.array(connectionS
|
|
|
373
373
|
*/
|
|
374
374
|
const catalogAuthFieldSchema = zod.z.object({
|
|
375
375
|
name: zod.z.string(),
|
|
376
|
+
/**
|
|
377
|
+
* Where the value goes in a headless auth call: `credentials` are
|
|
378
|
+
* exchanged with the provider (API keys, passwords), `params` configure
|
|
379
|
+
* the flow (e.g. an MCP server URL). Absent on older platforms; clients
|
|
380
|
+
* treat missing as `credentials`.
|
|
381
|
+
*/
|
|
382
|
+
target: zod.z.enum(["credentials", "params"]).nullish(),
|
|
376
383
|
label: zod.z.string().nullish(),
|
|
377
384
|
description: zod.z.string().nullish(),
|
|
378
385
|
placeholder: zod.z.string().nullish(),
|
|
@@ -389,6 +396,9 @@ const integrationCatalogEntrySchema = zod.z.object({
|
|
|
389
396
|
authFields: zod.z.array(catalogAuthFieldSchema).nullish()
|
|
390
397
|
});
|
|
391
398
|
const integrationCatalogResponseSchema = zod.z.object({ integrations: zod.z.array(integrationCatalogEntrySchema) });
|
|
399
|
+
const projectIntegrationSettingsResponseSchema = zod.z.object({
|
|
400
|
+
/** Null inherits the full public catalog; an empty array explicitly disables end-user connections. */
|
|
401
|
+
endUserProviders: zod.z.array(zod.z.string()).nullable() });
|
|
392
402
|
/**
|
|
393
403
|
* Secondary access token minted by the vendor alongside the primary oauth2
|
|
394
404
|
* credential (e.g. `devPortalAccessToken` on Microsoft Teams connections).
|
|
@@ -440,6 +450,14 @@ async function listIntegrations(client) {
|
|
|
440
450
|
if (!parsed.success) throw new MastraConnectError("platform_error", "Platform returned an unexpected integration catalog shape.");
|
|
441
451
|
return parsed.data.integrations;
|
|
442
452
|
}
|
|
453
|
+
async function getProjectIntegrationSettings(client, projectId) {
|
|
454
|
+
const response = await platformFetch(client, `/v2/projects/${encodeURIComponent(projectId)}/integration-settings`);
|
|
455
|
+
if (response.status === 404) throw new MastraConnectError("platform_error", `Integration settings were not found for project ${projectId}.`, { status: 404 });
|
|
456
|
+
if (!response.ok) await throwPlatformError(response, `retrieving integration settings for project ${projectId}`);
|
|
457
|
+
const parsed = projectIntegrationSettingsResponseSchema.safeParse(await parsePlatformJson(response, `retrieving integration settings for project ${projectId}`));
|
|
458
|
+
if (!parsed.success) throw new MastraConnectError("platform_error", `Platform returned an unexpected integration settings shape for project ${projectId}.`);
|
|
459
|
+
return parsed.data;
|
|
460
|
+
}
|
|
443
461
|
async function getConnectionContext(client, connectionId) {
|
|
444
462
|
const response = await platformFetch(client, `/v2/connections/${encodeURIComponent(connectionId)}/context`);
|
|
445
463
|
if (!response.ok) await throwPlatformError(response, `retrieving context for connection ${connectionId}`);
|
|
@@ -584,8 +602,19 @@ async function proxyRequestWithResponse(client, connectionId, options) {
|
|
|
584
602
|
const connectSessionSchema = zod.z.object({
|
|
585
603
|
connectionId: zod.z.string(),
|
|
586
604
|
integrationId: zod.z.string(),
|
|
587
|
-
|
|
588
|
-
|
|
605
|
+
/**
|
|
606
|
+
* Vendor connect link. The platform nulls this for resource-scoped
|
|
607
|
+
* sessions: their link is a bearer capability served only by the launch
|
|
608
|
+
* gate (`getConnectUrl`) under a matching resource assertion, so it never
|
|
609
|
+
* appears in a creation response that could reach a browser.
|
|
610
|
+
*/
|
|
611
|
+
connectUrl: zod.z.string().nullish(),
|
|
612
|
+
/**
|
|
613
|
+
* Nango connect session token. Nulled by the platform for resource-scoped
|
|
614
|
+
* sessions for the same reason as `connectUrl`: the token alone can open
|
|
615
|
+
* the vendor Connect UI, so it is an equivalent launch capability.
|
|
616
|
+
*/
|
|
617
|
+
sessionToken: zod.z.string().nullish(),
|
|
589
618
|
expiresAt: zod.z.string()
|
|
590
619
|
});
|
|
591
620
|
/**
|
|
@@ -604,12 +633,89 @@ async function createProjectConnectSession(client, projectId, integrationId) {
|
|
|
604
633
|
if (!parsed.success) throw new MastraConnectError("platform_error", `Platform returned an unexpected connect-session shape for ${integrationId}.`);
|
|
605
634
|
return parsed.data;
|
|
606
635
|
}
|
|
636
|
+
const connectUrlSchema = zod.z.object({
|
|
637
|
+
connectUrl: zod.z.string(),
|
|
638
|
+
expiresAt: zod.z.string()
|
|
639
|
+
});
|
|
640
|
+
/**
|
|
641
|
+
* Fetches the vendor connect link for a pending resource-scoped connection
|
|
642
|
+
* from the platform's launch gate. The platform serves it only while the
|
|
643
|
+
* session is pending and unexpired, and only when the client's
|
|
644
|
+
* `x-mastra-resource-id` assertion matches the row — any mismatch is a 404,
|
|
645
|
+
* which surfaces here as `connection_not_found`. This is how the browser's
|
|
646
|
+
* popup enters OAuth: the link itself never reaches browser-visible state.
|
|
647
|
+
*/
|
|
648
|
+
async function getConnectUrl(client, connectionId) {
|
|
649
|
+
const response = await platformFetch(client, `/v2/connections/${encodeURIComponent(connectionId)}/connect-url`);
|
|
650
|
+
if (response.status === 404) throw new MastraConnectError("connection_not_found", `No launchable connect session found for connection ${connectionId}.`);
|
|
651
|
+
if (!response.ok) await throwPlatformError(response, `fetching the connect URL for ${connectionId}`);
|
|
652
|
+
const parsed = connectUrlSchema.safeParse(await parsePlatformJson(response, `fetching the connect URL for ${connectionId}`));
|
|
653
|
+
if (!parsed.success) throw new MastraConnectError("platform_error", `Platform returned an unexpected connect-url shape for ${connectionId}.`);
|
|
654
|
+
return parsed.data;
|
|
655
|
+
}
|
|
607
656
|
/** Disconnects a connection. The platform tears down the vendor side asynchronously. */
|
|
608
657
|
async function disconnectConnection(client, connectionId) {
|
|
609
658
|
const response = await platformFetch(client, `/v2/connections/${encodeURIComponent(connectionId)}`, { method: "DELETE" });
|
|
610
659
|
if (!response.ok) await throwPlatformError(response, `disconnecting connection ${connectionId}`);
|
|
611
660
|
}
|
|
612
661
|
//#endregion
|
|
662
|
+
//#region src/connect-prompt-tool.ts
|
|
663
|
+
/**
|
|
664
|
+
* Record key of the built-in connect-prompt tool. Reserved: a provider tool
|
|
665
|
+
* resolving to the same key is a hard error, same as any duplicate.
|
|
666
|
+
*/
|
|
667
|
+
const CONNECT_PROMPT_TOOL_KEY = "request_connection";
|
|
668
|
+
/**
|
|
669
|
+
* Builds the built-in tool that lets an agent prompt the end user to connect
|
|
670
|
+
* a provider account mid-conversation. Only added to resource-scoped
|
|
671
|
+
* resolutions: without an end-user identity there is nobody to scope a new
|
|
672
|
+
* connection to.
|
|
673
|
+
*
|
|
674
|
+
* The connectable set respects the effective project policy: an explicit
|
|
675
|
+
* `tools({ providers })` allowlist wins, otherwise the project's provider
|
|
676
|
+
* configuration is loaded from Mastra Platform.
|
|
677
|
+
*
|
|
678
|
+
* `loadInputs` is called per tool invocation so provider policy and connection state are fresh —
|
|
679
|
+
* after the user connects through the rendered card, the agent can call the
|
|
680
|
+
* tool again and see `connected: true` without waiting out the snapshot TTL.
|
|
681
|
+
*/
|
|
682
|
+
function buildConnectPromptTool({ loadInputs, resourceId }) {
|
|
683
|
+
return (0, _mastra_core_tools.createTool)({
|
|
684
|
+
id: CONNECT_PROMPT_TOOL_KEY,
|
|
685
|
+
description: "Ask the current user to connect a provider account (e.g. Linear, Slack). Call this when a task needs a provider whose tools are unavailable because no account is connected, or when the user asks to connect one. The result renders as a connect prompt in the UI — tell the user to use it, and do not fabricate links. Pass `provider` to request one specific provider; omit it to list everything the user can connect.",
|
|
686
|
+
inputSchema: zod.z.object({ provider: zod.z.string().optional().describe("Provider id to request (e.g. \"linear\"). Omit to list all connectable providers.") }),
|
|
687
|
+
execute: async (input) => {
|
|
688
|
+
const { catalog, connections, allowlist } = await loadInputs();
|
|
689
|
+
const allow = allowlist === void 0 ? void 0 : new Set(Array.from(allowlist, (id) => id.toLowerCase()));
|
|
690
|
+
const connectable = catalog.filter((entry) => allow === void 0 || allow.has(entry.id.toLowerCase()));
|
|
691
|
+
const toProvider = (entry) => {
|
|
692
|
+
const usable = connections.filter((connection) => connection.integrationId.toLowerCase() === entry.id.toLowerCase() && connection.status === "active");
|
|
693
|
+
const own = usable.some((connection) => connection.resourceId === resourceId);
|
|
694
|
+
return {
|
|
695
|
+
id: entry.id,
|
|
696
|
+
displayName: entry.displayName ?? null,
|
|
697
|
+
logoUrl: entry.logoUrl ?? null,
|
|
698
|
+
authType: entry.authType ?? null,
|
|
699
|
+
authFields: entry.authFields ?? null,
|
|
700
|
+
connected: usable.length > 0,
|
|
701
|
+
scope: own ? "user" : usable.length > 0 ? "global" : null
|
|
702
|
+
};
|
|
703
|
+
};
|
|
704
|
+
const requestedId = input.provider?.toLowerCase();
|
|
705
|
+
const requested = requestedId === void 0 ? void 0 : connectable.find((entry) => entry.id.toLowerCase() === requestedId);
|
|
706
|
+
if (requested) return {
|
|
707
|
+
type: "connect-prompt",
|
|
708
|
+
requestedProvider: requested.id,
|
|
709
|
+
providers: [toProvider(requested)]
|
|
710
|
+
};
|
|
711
|
+
return {
|
|
712
|
+
type: "connect-prompt",
|
|
713
|
+
providers: connectable.map(toProvider)
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
//#endregion
|
|
613
719
|
//#region src/toolset.ts
|
|
614
720
|
/**
|
|
615
721
|
* Compiles a tool-filter entry containing `*` wildcards into an anchored
|
|
@@ -1230,6 +1336,7 @@ function createPlatformProxy(context) {
|
|
|
1230
1336
|
};
|
|
1231
1337
|
};
|
|
1232
1338
|
return {
|
|
1339
|
+
proxy: (config) => callProxy(config.method ?? "GET", context, config),
|
|
1233
1340
|
get: bind("GET"),
|
|
1234
1341
|
post: bind("POST"),
|
|
1235
1342
|
put: bind("PUT"),
|
|
@@ -75352,6 +75459,7 @@ function sharedStateKey(projectId, ttlMs, options) {
|
|
|
75352
75459
|
allowTools: options.allowTools,
|
|
75353
75460
|
disallowTools: options.disallowTools,
|
|
75354
75461
|
requireApproval: options.requireApproval,
|
|
75462
|
+
connectPrompt: options.connectPrompt,
|
|
75355
75463
|
client: {
|
|
75356
75464
|
baseUrl: options.client?.baseUrl,
|
|
75357
75465
|
orgId: options.client?.orgId,
|
|
@@ -75488,6 +75596,18 @@ async function loadSnapshotInputs(state, client) {
|
|
|
75488
75596
|
catalogAvailable: false
|
|
75489
75597
|
};
|
|
75490
75598
|
}
|
|
75599
|
+
/** Loads fresh prompt inputs and resolves project policy only when code did not provide an allowlist. */
|
|
75600
|
+
async function loadConnectPromptInputs(state, client) {
|
|
75601
|
+
const codeAllowlist = state.normalizedProviders.only;
|
|
75602
|
+
const [inputs, settings] = await Promise.all([loadSnapshotInputs(state, client), codeAllowlist === void 0 ? getProjectIntegrationSettings(client, state.projectId) : Promise.resolve(void 0)]);
|
|
75603
|
+
const projectProviders = settings?.endUserProviders;
|
|
75604
|
+
const allowlist = codeAllowlist ?? (projectProviders === null || projectProviders === void 0 ? void 0 : new Set(projectProviders));
|
|
75605
|
+
return {
|
|
75606
|
+
catalog: inputs.catalog,
|
|
75607
|
+
connections: inputs.connections,
|
|
75608
|
+
allowlist
|
|
75609
|
+
};
|
|
75610
|
+
}
|
|
75491
75611
|
/**
|
|
75492
75612
|
* Fetches a fresh snapshot for one scope, deduplicating concurrent calls per
|
|
75493
75613
|
* scope. Rejects on failure. A refresh requested while the state is closing
|
|
@@ -75506,6 +75626,14 @@ function refreshScope(state, scope) {
|
|
|
75506
75626
|
...scope.resourceId === void 0 ? {} : { resourceId: scope.resourceId }
|
|
75507
75627
|
};
|
|
75508
75628
|
const { record, mcpKeys } = await mapTools(connections, requests, state.options, clientOptions, scope.client, state.mcpClients, state.resolverId);
|
|
75629
|
+
if (scope.resourceId !== void 0 && state.options.connectPrompt !== false) {
|
|
75630
|
+
if (record["request_connection"]) throw new MastraConnectConfigError(`Tool key '${CONNECT_PROMPT_TOOL_KEY}' is reserved for the built-in connect-prompt tool; a provider resolved a tool with the same key. Disable it with connectPrompt: false or exclude the conflicting provider tool.`);
|
|
75631
|
+
const client = scope.client;
|
|
75632
|
+
record[CONNECT_PROMPT_TOOL_KEY] = buildConnectPromptTool({
|
|
75633
|
+
loadInputs: () => loadConnectPromptInputs(state, client),
|
|
75634
|
+
resourceId: scope.resourceId
|
|
75635
|
+
});
|
|
75636
|
+
}
|
|
75509
75637
|
scope.cache = {
|
|
75510
75638
|
snapshot: record,
|
|
75511
75639
|
fetchedAt: Date.now(),
|
|
@@ -75610,6 +75738,7 @@ function tools(options = {}) {
|
|
|
75610
75738
|
rejectRemovedAutoApproveTools(providerOverrides);
|
|
75611
75739
|
if (options.allowTools !== void 0 && options.disallowTools !== void 0) throw new MastraConnectError("invalid_options", "Top-level allowTools and disallowTools are mutually exclusive; set at most one.");
|
|
75612
75740
|
if (options.requireApproval !== void 0 && typeof options.requireApproval !== "boolean" && !(Array.isArray(options.requireApproval) && options.requireApproval.every((name) => typeof name === "string"))) throw new MastraConnectError("invalid_options", "Top-level requireApproval must be a boolean or an array of tool keys.");
|
|
75741
|
+
if (options.connectPrompt !== void 0 && typeof options.connectPrompt !== "boolean") throw new MastraConnectError("invalid_options", `Invalid connectPrompt: expected a boolean, got ${typeof options.connectPrompt}.`);
|
|
75613
75742
|
const state = acquireSharedState(projectId, ttlMs, options, normalizedProviders);
|
|
75614
75743
|
const validateDynamicResourceId = (raw) => raw === void 0 || raw === null ? void 0 : validateResourceId(raw);
|
|
75615
75744
|
const resolve = (ctx) => {
|
|
@@ -76519,14 +76648,18 @@ function renderConnectPage(params) {
|
|
|
76519
76648
|
return res.json();
|
|
76520
76649
|
})
|
|
76521
76650
|
.then(function (session) {
|
|
76651
|
+
// The popup enters OAuth through the launch gate (same-origin,
|
|
76652
|
+
// authenticated) rather than a raw vendor link: the server re-checks
|
|
76653
|
+
// that this browser's identity owns the pending session immediately
|
|
76654
|
+
// before redirecting into the provider's consent screen.
|
|
76522
76655
|
if (popup && !popup.closed) {
|
|
76523
|
-
popup.location = session.
|
|
76656
|
+
popup.location = session.launchUrl;
|
|
76524
76657
|
setStatus('Finish authorizing in the popup…', false);
|
|
76525
76658
|
} else {
|
|
76526
76659
|
// Popup blocked: offer a manual link instead of auto-navigating away.
|
|
76527
76660
|
status.textContent = '';
|
|
76528
76661
|
var link = document.createElement('a');
|
|
76529
|
-
link.href = session.
|
|
76662
|
+
link.href = session.launchUrl;
|
|
76530
76663
|
link.target = '_blank';
|
|
76531
76664
|
link.rel = 'noopener';
|
|
76532
76665
|
link.textContent = 'Popup blocked — click here to authorize';
|
|
@@ -76554,6 +76687,7 @@ const RESERVED_PROVIDER_IDS = /* @__PURE__ */ new Set([
|
|
|
76554
76687
|
"sessions"
|
|
76555
76688
|
]);
|
|
76556
76689
|
const NO_STORE = "no-store, private";
|
|
76690
|
+
const PROJECT_PROVIDER_POLICY_TTL_MS = 3e4;
|
|
76557
76691
|
function errorResponse(c, error) {
|
|
76558
76692
|
c.header("cache-control", NO_STORE);
|
|
76559
76693
|
return c.json({ error: {
|
|
@@ -76563,8 +76697,10 @@ function errorResponse(c, error) {
|
|
|
76563
76697
|
}
|
|
76564
76698
|
/**
|
|
76565
76699
|
* Maps a platform-call failure to a safe end-user response. Platform detail
|
|
76566
|
-
* strings
|
|
76567
|
-
* surface, and the details describe the developer's platform account.
|
|
76700
|
+
* strings do not reach the end user — this is an unauthenticated-adjacent
|
|
76701
|
+
* surface, and the details describe the developer's platform account. The one
|
|
76702
|
+
* exception is 409 conflicts, whose details describe the caller's own
|
|
76703
|
+
* connection state and are authored by the platform for display.
|
|
76568
76704
|
*/
|
|
76569
76705
|
function toRouteError(error) {
|
|
76570
76706
|
if (error instanceof MastraConnectError) {
|
|
@@ -76578,6 +76714,16 @@ function toRouteError(error) {
|
|
|
76578
76714
|
code: "misconfigured",
|
|
76579
76715
|
message: "Connect routes are not configured correctly."
|
|
76580
76716
|
};
|
|
76717
|
+
if (error.status === 409) return {
|
|
76718
|
+
status: 409,
|
|
76719
|
+
code: "conflict",
|
|
76720
|
+
message: error.detail ?? "The request conflicts with the current state of this connection."
|
|
76721
|
+
};
|
|
76722
|
+
if (error.status === 429) return {
|
|
76723
|
+
status: 429,
|
|
76724
|
+
code: "rate_limited",
|
|
76725
|
+
message: "Too many requests. Try again shortly."
|
|
76726
|
+
};
|
|
76581
76727
|
return {
|
|
76582
76728
|
status: 502,
|
|
76583
76729
|
code: "platform_error",
|
|
@@ -76665,18 +76811,44 @@ function connectionScope(connection) {
|
|
|
76665
76811
|
* ```
|
|
76666
76812
|
*/
|
|
76667
76813
|
function userConnectRoutes(options) {
|
|
76668
|
-
if (!Array.isArray(options.providers) || options.providers.length === 0) throw new MastraConnectError("invalid_options", "
|
|
76669
|
-
const providers = options.providers
|
|
76814
|
+
if (options.providers !== void 0 && (!Array.isArray(options.providers) || options.providers.length === 0)) throw new MastraConnectError("invalid_options", "Invalid providers: pass a non-empty allowlist, or omit the option to use the project provider configuration.");
|
|
76815
|
+
const providers = options.providers?.map((provider) => {
|
|
76670
76816
|
const id = typeof provider === "string" ? provider.trim().toLowerCase() : "";
|
|
76671
76817
|
if (!id) throw new MastraConnectError("invalid_options", "Invalid provider id in userConnectRoutes providers allowlist.");
|
|
76672
76818
|
if (RESERVED_PROVIDER_IDS.has(id) || id.includes("/")) throw new MastraConnectError("invalid_options", `Invalid provider id '${id}': reserved route segment.`);
|
|
76673
76819
|
return id;
|
|
76674
76820
|
});
|
|
76675
|
-
|
|
76821
|
+
/** Explicit code configuration wins without reading project settings from the platform. */
|
|
76822
|
+
const codeAllowlist = providers === void 0 ? void 0 : new Set(providers);
|
|
76676
76823
|
const basePath = options.basePath ?? "/connect";
|
|
76677
76824
|
if (!basePath.startsWith("/") || basePath.endsWith("/") || basePath.includes(":") || basePath.includes("*")) throw new MastraConnectError("invalid_options", `Invalid basePath '${basePath}': expected an absolute path without a trailing slash or route parameters.`);
|
|
76678
76825
|
const projectId = options.projectId?.trim() || process.env.MASTRA_PROJECT_ID?.trim();
|
|
76679
76826
|
if (!projectId) throw new MastraConnectError("missing_project_id", "Missing project id: set MASTRA_PROJECT_ID or pass projectId.");
|
|
76827
|
+
let cachedProjectPolicy;
|
|
76828
|
+
let projectPolicyInflight;
|
|
76829
|
+
/** Lazily loads project policy, sharing one short-lived snapshot across end-user requests and status polling. */
|
|
76830
|
+
const resolveProviderPolicy = (client) => {
|
|
76831
|
+
if (providers !== void 0) return Promise.resolve({
|
|
76832
|
+
providers,
|
|
76833
|
+
allowlist: codeAllowlist
|
|
76834
|
+
});
|
|
76835
|
+
if (cachedProjectPolicy && Date.now() - cachedProjectPolicy.fetchedAt < PROJECT_PROVIDER_POLICY_TTL_MS) return Promise.resolve(cachedProjectPolicy.policy);
|
|
76836
|
+
if (!projectPolicyInflight) projectPolicyInflight = getProjectIntegrationSettings(client, projectId).then((settings) => {
|
|
76837
|
+
const configured = settings.endUserProviders?.map((provider) => provider.toLowerCase());
|
|
76838
|
+
const policy = {
|
|
76839
|
+
providers: configured,
|
|
76840
|
+
allowlist: configured === void 0 ? void 0 : new Set(configured)
|
|
76841
|
+
};
|
|
76842
|
+
cachedProjectPolicy = {
|
|
76843
|
+
policy,
|
|
76844
|
+
fetchedAt: Date.now()
|
|
76845
|
+
};
|
|
76846
|
+
return policy;
|
|
76847
|
+
}).finally(() => {
|
|
76848
|
+
projectPolicyInflight = void 0;
|
|
76849
|
+
});
|
|
76850
|
+
return projectPolicyInflight;
|
|
76851
|
+
};
|
|
76680
76852
|
if (options.client?.resourceId !== void 0) throw new MastraConnectError("invalid_options", "userConnectRoutes derives the resource key per request; do not set client.resourceId.");
|
|
76681
76853
|
if (options.resourceId !== void 0 && typeof options.resourceId !== "function") throw new MastraConnectError("invalid_options", "Invalid resourceId: userConnectRoutes expects a callback deriving the key per request.");
|
|
76682
76854
|
const allowedOrigins = options.returnTo?.allowedOrigins ?? [];
|
|
@@ -76728,13 +76900,20 @@ function userConnectRoutes(options) {
|
|
|
76728
76900
|
return errorResponse(c, toRouteError(error));
|
|
76729
76901
|
}
|
|
76730
76902
|
};
|
|
76731
|
-
/**
|
|
76732
|
-
|
|
76733
|
-
|
|
76734
|
-
|
|
76735
|
-
|
|
76903
|
+
/**
|
|
76904
|
+
* Lists the caller's visible connections (global + own, scoped by the
|
|
76905
|
+
* platform via the resource header). Deliberately NOT filtered to the
|
|
76906
|
+
* provider policy: the allowlist gates what end users can newly connect,
|
|
76907
|
+
* not what already exists — agents keep resolving tools from existing
|
|
76908
|
+
* connections, and narrowing the allowlist must not hide (or orphan) a
|
|
76909
|
+
* user's own rows, which they still need to see and disconnect.
|
|
76910
|
+
*/
|
|
76911
|
+
const listVisibleConnections = async (client) => listProjectConnections(client, projectId);
|
|
76912
|
+
const providerParam = (c, policy) => {
|
|
76736
76913
|
const provider = String(c.req.param("provider") ?? "").trim().toLowerCase();
|
|
76737
|
-
|
|
76914
|
+
if (!provider || RESERVED_PROVIDER_IDS.has(provider) || provider.includes("/")) return null;
|
|
76915
|
+
if (policy.allowlist !== void 0 && !policy.allowlist.has(provider)) return null;
|
|
76916
|
+
return provider;
|
|
76738
76917
|
};
|
|
76739
76918
|
const notFound = (c, code, message) => errorResponse(c, {
|
|
76740
76919
|
status: 404,
|
|
@@ -76747,18 +76926,19 @@ function userConnectRoutes(options) {
|
|
|
76747
76926
|
method: "GET",
|
|
76748
76927
|
requiresAuth: true,
|
|
76749
76928
|
handler: gated(async (c, client) => {
|
|
76750
|
-
const catalog = await listIntegrations(client);
|
|
76929
|
+
const [catalog, policy] = await Promise.all([listIntegrations(client), resolveProviderPolicy(client)]);
|
|
76930
|
+
const toListed = (entry) => ({
|
|
76931
|
+
id: entry.id,
|
|
76932
|
+
displayName: entry.displayName ?? null,
|
|
76933
|
+
logoUrl: entry.logoUrl ?? null,
|
|
76934
|
+
authType: entry.authType ?? null,
|
|
76935
|
+
authFields: entry.authFields ?? null
|
|
76936
|
+
});
|
|
76937
|
+
if (policy.providers === void 0) return c.json({ providers: catalog.map(toListed) });
|
|
76751
76938
|
const byId = new Map(catalog.map((entry) => [entry.id.toLowerCase(), entry]));
|
|
76752
|
-
const visible = providers.flatMap((id) => {
|
|
76939
|
+
const visible = policy.providers.flatMap((id) => {
|
|
76753
76940
|
const entry = byId.get(id);
|
|
76754
|
-
|
|
76755
|
-
return [{
|
|
76756
|
-
id: entry.id,
|
|
76757
|
-
displayName: entry.displayName ?? null,
|
|
76758
|
-
logoUrl: entry.logoUrl ?? null,
|
|
76759
|
-
authType: entry.authType ?? null,
|
|
76760
|
-
authFields: entry.authFields ?? null
|
|
76761
|
-
}];
|
|
76941
|
+
return entry ? [toListed(entry)] : [];
|
|
76762
76942
|
});
|
|
76763
76943
|
return c.json({ providers: visible });
|
|
76764
76944
|
})
|
|
@@ -76768,14 +76948,20 @@ function userConnectRoutes(options) {
|
|
|
76768
76948
|
method: "GET",
|
|
76769
76949
|
requiresAuth: true,
|
|
76770
76950
|
handler: gated(async (c, client) => {
|
|
76771
|
-
const connections = await listVisibleConnections(client);
|
|
76772
|
-
|
|
76773
|
-
|
|
76774
|
-
|
|
76775
|
-
|
|
76776
|
-
|
|
76777
|
-
|
|
76778
|
-
|
|
76951
|
+
const [connections, catalog] = await Promise.all([listVisibleConnections(client), listIntegrations(client).catch(() => [])]);
|
|
76952
|
+
const catalogById = new Map(catalog.map((entry) => [entry.id.toLowerCase(), entry]));
|
|
76953
|
+
return c.json({ connections: connections.map((connection) => {
|
|
76954
|
+
const entry = catalogById.get(connection.integrationId.toLowerCase());
|
|
76955
|
+
return {
|
|
76956
|
+
id: connection.id,
|
|
76957
|
+
integrationId: connection.integrationId,
|
|
76958
|
+
displayName: entry?.displayName ?? null,
|
|
76959
|
+
logoUrl: entry?.logoUrl ?? null,
|
|
76960
|
+
status: connection.status,
|
|
76961
|
+
accountLabel: connection.accountLabel ?? null,
|
|
76962
|
+
scope: connectionScope(connection)
|
|
76963
|
+
};
|
|
76964
|
+
}) });
|
|
76779
76965
|
})
|
|
76780
76966
|
},
|
|
76781
76967
|
{
|
|
@@ -76810,19 +76996,46 @@ function userConnectRoutes(options) {
|
|
|
76810
76996
|
return c.body(null, 204);
|
|
76811
76997
|
})
|
|
76812
76998
|
},
|
|
76999
|
+
{
|
|
77000
|
+
path: `${basePath}/connections/:id/launch`,
|
|
77001
|
+
method: "GET",
|
|
77002
|
+
requiresAuth: true,
|
|
77003
|
+
handler: gated(async (c, client) => {
|
|
77004
|
+
const id = String(c.req.param("id") ?? "");
|
|
77005
|
+
if (!id) return notFound(c, "connection_not_found", "Connection not found.");
|
|
77006
|
+
const { connectUrl, expiresAt } = await getConnectUrl(client, id);
|
|
77007
|
+
c.header("Cache-Control", "no-store");
|
|
77008
|
+
if ((c.req.header("accept") ?? "").includes("application/json")) {
|
|
77009
|
+
let sessionToken = null;
|
|
77010
|
+
try {
|
|
77011
|
+
sessionToken = new URL(connectUrl).searchParams.get("session_token");
|
|
77012
|
+
} catch {
|
|
77013
|
+
sessionToken = null;
|
|
77014
|
+
}
|
|
77015
|
+
return c.json({
|
|
77016
|
+
sessionToken,
|
|
77017
|
+
expiresAt
|
|
77018
|
+
});
|
|
77019
|
+
}
|
|
77020
|
+
return c.redirect(connectUrl, 302);
|
|
77021
|
+
})
|
|
77022
|
+
},
|
|
76813
77023
|
{
|
|
76814
77024
|
path: `${basePath}/:provider/sessions`,
|
|
76815
77025
|
method: "POST",
|
|
76816
77026
|
requiresAuth: true,
|
|
76817
77027
|
handler: gated(async (c, client) => {
|
|
76818
|
-
const
|
|
77028
|
+
const policy = await resolveProviderPolicy(client);
|
|
77029
|
+
const provider = providerParam(c, policy);
|
|
76819
77030
|
if (!provider) return notFound(c, "provider_not_found", "Provider not available.");
|
|
77031
|
+
if (policy.allowlist === void 0) {
|
|
77032
|
+
if (!(await listIntegrations(client)).some((entry) => entry.id.toLowerCase() === provider)) return notFound(c, "provider_not_found", "Provider not available.");
|
|
77033
|
+
}
|
|
76820
77034
|
const session = await createProjectConnectSession(client, projectId, provider);
|
|
76821
77035
|
return c.json({
|
|
76822
77036
|
connectionId: session.connectionId,
|
|
76823
77037
|
integrationId: session.integrationId,
|
|
76824
|
-
|
|
76825
|
-
sessionToken: session.sessionToken,
|
|
77038
|
+
launchUrl: `${basePath}/connections/${encodeURIComponent(session.connectionId)}/launch`,
|
|
76826
77039
|
expiresAt: session.expiresAt
|
|
76827
77040
|
}, 201);
|
|
76828
77041
|
})
|
|
@@ -76832,7 +77045,8 @@ function userConnectRoutes(options) {
|
|
|
76832
77045
|
method: "GET",
|
|
76833
77046
|
requiresAuth: true,
|
|
76834
77047
|
handler: gated(async (c, client) => {
|
|
76835
|
-
const
|
|
77048
|
+
const policy = await resolveProviderPolicy(client);
|
|
77049
|
+
const provider = providerParam(c, policy);
|
|
76836
77050
|
if (!provider) return notFound(c, "provider_not_found", "Provider not available.");
|
|
76837
77051
|
const returnTo = validateReturnTo(c.req.query("returnTo") ?? void 0, allowedOrigins);
|
|
76838
77052
|
if (!returnTo.ok) return errorResponse(c, {
|
|
@@ -76867,6 +77081,7 @@ function userConnectRoutes(options) {
|
|
|
76867
77081
|
}
|
|
76868
77082
|
//#endregion
|
|
76869
77083
|
exports.CHANNELS = CHANNELS;
|
|
77084
|
+
exports.CONNECT_PROMPT_TOOL_KEY = CONNECT_PROMPT_TOOL_KEY;
|
|
76870
77085
|
exports.MastraConnectError = MastraConnectError;
|
|
76871
77086
|
exports.PROVIDERS = PROVIDERS;
|
|
76872
77087
|
exports.channels = channels;
|