@mastra/connect 0.4.0 → 0.5.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/channels.d.ts +40 -32
- package/dist/channels.d.ts.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.cjs +99 -91
- 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 +99 -91
- package/dist/index.js.map +1 -1
- package/dist/providers/channel-provider.d.ts +45 -17
- package/dist/providers/channel-provider.d.ts.map +1 -1
- package/dist/providers/channels.d.ts +1 -1
- package/dist/providers/channels.d.ts.map +1 -1
- package/package.json +8 -22
package/dist/channels.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ChannelProvider } from '@mastra/core/channels';
|
|
2
2
|
import type { ConnectClientOptions } from './client.js';
|
|
3
3
|
import type { DiscordReservedProviderOption, SlackReservedProviderOption, TelegramReservedProviderOption } from './providers/channels.js';
|
|
4
|
+
type ApiRoute = ReturnType<ChannelProvider['getRoutes']>[number];
|
|
4
5
|
/**
|
|
5
6
|
* `providerOptions` fields that `channels()` refuses to forward to a
|
|
6
7
|
* `ChannelProvider` constructor. Marking them `never` here makes the compiler
|
|
@@ -33,9 +34,9 @@ export type DiscordChannelsProviderOptions = Record<string, unknown> & {
|
|
|
33
34
|
export interface ChannelsIntegrationOptions<ProviderOptions = Record<string, unknown>> {
|
|
34
35
|
/** Pin a specific connection id (bypasses single-active-connection resolution). */
|
|
35
36
|
connectionId?: string;
|
|
36
|
-
/** Exclude this provider entirely
|
|
37
|
+
/** Exclude this provider entirely — no instance is constructed and no routes are mounted. */
|
|
37
38
|
disabled?: boolean;
|
|
38
|
-
/** Provider-specific options merged into the
|
|
39
|
+
/** Provider-specific options merged into the first argument of `ChannelProviderRegistration.create()`. */
|
|
39
40
|
providerOptions?: ProviderOptions;
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
@@ -60,56 +61,63 @@ export interface ChannelsOptions {
|
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* The result of resolving a project's connections into a
|
|
63
|
-
* `ChannelProvider` map
|
|
64
|
+
* `ChannelProvider` map: integrations with an active connection, keyed by
|
|
65
|
+
* integrationId.
|
|
64
66
|
*/
|
|
65
67
|
export type ResolvedChannels = Record<string, ChannelProvider>;
|
|
66
68
|
/**
|
|
67
|
-
* Callback context passed to
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
69
|
+
* Callback context passed to the resolver when invoked with a runtime
|
|
70
|
+
* context. Mirrors `@mastra/core`'s `ChannelsResolverContext` — Mastra passes
|
|
71
|
+
* `{ mastra }` from `resolveChannels()`; the resolver currently doesn't vary
|
|
72
|
+
* output by context.
|
|
71
73
|
*/
|
|
72
74
|
export interface ChannelsResolverContext {
|
|
73
75
|
requestContext?: unknown;
|
|
74
76
|
mastra?: unknown;
|
|
75
77
|
}
|
|
76
78
|
/**
|
|
77
|
-
* The value
|
|
79
|
+
* The value `channels()` resolves to. Satisfies `@mastra/core`'s
|
|
80
|
+
* `ChannelsResolver` contract, so it can be handed to
|
|
81
|
+
* `new Mastra({ channels })` directly:
|
|
78
82
|
*
|
|
79
|
-
* -
|
|
80
|
-
*
|
|
81
|
-
* `
|
|
82
|
-
* -
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* `
|
|
87
|
-
* so the constructed Mastra instance will not pick up newly-added
|
|
88
|
-
* connections or rotated credentials without a restart. These handles are
|
|
89
|
-
* for standalone/test usage where the resolver is being called directly —
|
|
90
|
-
* not for the Mastra-registered snapshot.
|
|
83
|
+
* - Callable — returns the current `Record<string, ChannelProvider>` of
|
|
84
|
+
* integrations with an active connection. Mastra invokes it via
|
|
85
|
+
* `resolveChannels()`; the TTL cache makes repeat calls cheap.
|
|
86
|
+
* - `getRoutes()` — the union of routes for every non-disabled channel,
|
|
87
|
+
* available synchronously so Mastra can mount them at construction. Routes
|
|
88
|
+
* exist before (and after) their integration has an active connection.
|
|
89
|
+
* - Handles — `invalidate()` / `refresh()` / `disconnect()` control the
|
|
90
|
+
* resolver's private cache; `refresh()` forces a platform fetch now.
|
|
91
91
|
*/
|
|
92
|
-
export interface ChannelsResolver
|
|
93
|
-
/**
|
|
92
|
+
export interface ChannelsResolver {
|
|
93
|
+
/** Returns the current provider map for integrations with an active connection. */
|
|
94
94
|
(context?: ChannelsResolverContext): Promise<ResolvedChannels>;
|
|
95
|
+
/** Union of API routes for every non-disabled channel integration. */
|
|
96
|
+
getRoutes(): ApiRoute[];
|
|
95
97
|
/** Drops the cached snapshot; the next resolution fetches fresh from the platform. */
|
|
96
98
|
invalidate(): void;
|
|
97
|
-
/** Fetches
|
|
99
|
+
/** Fetches connections from the platform now and updates the cache. Rejects if the platform fetch fails. */
|
|
98
100
|
refresh(): Promise<ResolvedChannels>;
|
|
99
101
|
/** Clears the cached snapshot. Reserved for symmetry with `tools()`; currently a no-op beyond invalidation. */
|
|
100
102
|
disconnect(): Promise<void>;
|
|
101
103
|
}
|
|
102
104
|
/**
|
|
103
|
-
* Returns a live channels resolver over the project's Platform connections
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
105
|
+
* Returns a live channels resolver over the project's Platform connections,
|
|
106
|
+
* ready to hand to `new Mastra({ channels: await channels({...}) })`.
|
|
107
|
+
*
|
|
108
|
+
* Provider instances for every channel-capable integration (Slack, Telegram,
|
|
109
|
+
* Discord) are constructed once, up front and credential-less, so their
|
|
110
|
+
* webhook/OAuth routes can mount at Mastra construction. Each resolution
|
|
111
|
+
* fetches the project's connections and late-binds credentials into the live
|
|
112
|
+
* instances: integrations with an active connection appear in the resolved
|
|
113
|
+
* map, others don't — so connecting a new channel on the platform takes
|
|
114
|
+
* effect without redeploying the app.
|
|
107
115
|
*
|
|
108
116
|
* Configuration errors (missing project id, bad ttlMs, malformed integration
|
|
109
|
-
* id)
|
|
110
|
-
* problems
|
|
111
|
-
* are downgraded to warn-and-skip so one
|
|
112
|
-
* whole map.
|
|
117
|
+
* id) reject at call time so they surface at startup. Actionable
|
|
118
|
+
* per-integration problems (provider construction failure, needs re-auth,
|
|
119
|
+
* ambiguity, credential sync failure) are downgraded to warn-and-skip so one
|
|
120
|
+
* bad integration never takes down the whole map.
|
|
113
121
|
*
|
|
114
122
|
* @example
|
|
115
123
|
* ```ts
|
|
@@ -122,6 +130,6 @@ export interface ChannelsResolver extends PromiseLike<ResolvedChannels> {
|
|
|
122
130
|
* });
|
|
123
131
|
* ```
|
|
124
132
|
*/
|
|
125
|
-
export declare function channels(options?: ChannelsOptions): ChannelsResolver
|
|
133
|
+
export declare function channels(options?: ChannelsOptions): Promise<ChannelsResolver>;
|
|
126
134
|
export {};
|
|
127
135
|
//# sourceMappingURL=channels.d.ts.map
|
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,
|
|
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,8BAA8B,EAC/B,MAAM,yBAAyB,CAAC;AAIjC,KAAK,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;;;;GAiBG;AACH,KAAK,qBAAqB,CAAC,QAAQ,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oBAAoB,CAAC,CAe/G;AAED,KAAK,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAErD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC7D,gIAAgI;IAChI,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,EAAE,GAAG,SAAS,CAAC,CAAC;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;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,CAoFxB"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type MastraConnectErrorCode = 'missing_access_token' | 'missing_project_id' | 'missing_connection_id' | 'invalid_options' | 'connection_not_found' | 'unauthorized' | 'proxy_error' | 'unsupported_credential_type' | 'platform_error';
|
|
1
|
+
export type MastraConnectErrorCode = 'missing_access_token' | 'missing_project_id' | 'missing_connection_id' | 'invalid_options' | 'connection_not_found' | 'unauthorized' | 'proxy_error' | 'unsupported_credential_type' | 'no_active_connection' | 'platform_error';
|
|
2
2
|
export declare class MastraConnectError extends Error {
|
|
3
3
|
readonly code: MastraConnectErrorCode;
|
|
4
4
|
readonly status?: number;
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAC9B,sBAAsB,GACtB,oBAAoB,GACpB,uBAAuB,GACvB,iBAAiB,GACjB,sBAAsB,GACtB,cAAc,GACd,aAAa,GACb,6BAA6B,GAC7B,gBAAgB,CAAC;AAIrB,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,YAAY,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,EAMxG;CACF;AAcD;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,CAuBrE"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAC9B,sBAAsB,GACtB,oBAAoB,GACpB,uBAAuB,GACvB,iBAAiB,GACjB,sBAAsB,GACtB,cAAc,GACd,aAAa,GACb,6BAA6B,GAC7B,sBAAsB,GACtB,gBAAgB,CAAC;AAIrB,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,YAAY,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,EAMxG;CACF;AAcD;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,CAuBrE"}
|
package/dist/index.cjs
CHANGED
|
@@ -347,14 +347,12 @@ async function proxyRequestWithResponse(client, connectionId, options) {
|
|
|
347
347
|
function credentialToken$1(credential) {
|
|
348
348
|
return credential.type === "oauth2" ? credential.accessToken : credential.apiKey;
|
|
349
349
|
}
|
|
350
|
-
function missingPeerError(integrationId, packageName, error) {
|
|
351
|
-
return new MastraConnectError("invalid_options", `channels() cannot build '${integrationId}' provider: install '${packageName}' as a dependency of your app (${error instanceof Error ? error.message : String(error)}).`);
|
|
352
|
-
}
|
|
353
350
|
const RESERVED_OPTION_KEYS = {
|
|
354
351
|
slack: [
|
|
355
352
|
"baseUrl",
|
|
356
353
|
"refreshToken",
|
|
357
354
|
"token",
|
|
355
|
+
"tokenResolver",
|
|
358
356
|
"encryptionKey"
|
|
359
357
|
],
|
|
360
358
|
telegram: [
|
|
@@ -384,61 +382,53 @@ function stripReservedOptions(integrationId, options) {
|
|
|
384
382
|
const CHANNELS$1 = [
|
|
385
383
|
{
|
|
386
384
|
integrationId: "slack",
|
|
387
|
-
async
|
|
388
|
-
const
|
|
389
|
-
let mod;
|
|
390
|
-
try {
|
|
391
|
-
mod = await import("@mastra/slack");
|
|
392
|
-
} catch (error) {
|
|
393
|
-
throw missingPeerError("slack", "@mastra/slack", error);
|
|
394
|
-
}
|
|
385
|
+
async create(options, runtime) {
|
|
386
|
+
const mod = await import("@mastra/slack");
|
|
395
387
|
const safeOptions = stripReservedOptions("slack", options);
|
|
396
|
-
|
|
397
|
-
|
|
388
|
+
const tokenResolver = async () => {
|
|
389
|
+
return credentialToken$1(await runtime.getCredential());
|
|
390
|
+
};
|
|
391
|
+
return { provider: new mod.SlackProvider({
|
|
392
|
+
tokenResolver,
|
|
398
393
|
...safeOptions ?? {}
|
|
399
|
-
});
|
|
394
|
+
}) };
|
|
400
395
|
}
|
|
401
396
|
},
|
|
402
397
|
{
|
|
403
398
|
integrationId: "telegram",
|
|
404
|
-
async
|
|
405
|
-
const
|
|
406
|
-
let mod;
|
|
407
|
-
try {
|
|
408
|
-
mod = await import("@mastra/telegram");
|
|
409
|
-
} catch (error) {
|
|
410
|
-
throw missingPeerError("telegram", "@mastra/telegram", error);
|
|
411
|
-
}
|
|
399
|
+
async create(options, runtime) {
|
|
400
|
+
const mod = await import("@mastra/telegram");
|
|
412
401
|
const safeOptions = stripReservedOptions("telegram", options);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
402
|
+
const provider = new mod.TelegramProvider({ ...safeOptions ?? {} });
|
|
403
|
+
return {
|
|
404
|
+
provider,
|
|
405
|
+
async sync() {
|
|
406
|
+
const botToken = credentialToken$1(await runtime.getCredential());
|
|
407
|
+
await provider.configure?.({ botToken });
|
|
408
|
+
}
|
|
409
|
+
};
|
|
417
410
|
}
|
|
418
411
|
},
|
|
419
412
|
{
|
|
420
413
|
integrationId: "discord",
|
|
421
|
-
async
|
|
422
|
-
const
|
|
423
|
-
const
|
|
424
|
-
const
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
},
|
|
440
|
-
...rest
|
|
441
|
-
});
|
|
414
|
+
async create(options, runtime) {
|
|
415
|
+
const mod = await import("@mastra/discord");
|
|
416
|
+
const { applicationId: optionsAppId, publicKey: optionsPublicKey, ...rest } = options ?? {};
|
|
417
|
+
const safeOptions = stripReservedOptions("discord", rest);
|
|
418
|
+
const provider = new mod.DiscordProvider({ ...safeOptions ?? {} });
|
|
419
|
+
return {
|
|
420
|
+
provider,
|
|
421
|
+
async sync() {
|
|
422
|
+
const botToken = credentialToken$1(await runtime.getCredential());
|
|
423
|
+
const metadata = (await runtime.getConnectionContext())?.metadata ?? {};
|
|
424
|
+
const applicationId = optionsAppId ?? (typeof metadata.applicationId === "string" ? metadata.applicationId : void 0) ?? (typeof metadata.application_id === "string" ? metadata.application_id : void 0);
|
|
425
|
+
const publicKey = optionsPublicKey ?? (typeof metadata.publicKey === "string" ? metadata.publicKey : void 0) ?? (typeof metadata.public_key === "string" ? metadata.public_key : void 0);
|
|
426
|
+
const credentials = { botToken };
|
|
427
|
+
if (applicationId) credentials.applicationId = applicationId;
|
|
428
|
+
if (publicKey) credentials.publicKey = publicKey;
|
|
429
|
+
await provider.configure?.(credentials);
|
|
430
|
+
}
|
|
431
|
+
};
|
|
442
432
|
}
|
|
443
433
|
}
|
|
444
434
|
];
|
|
@@ -66154,16 +66144,22 @@ const DEFAULT_TTL_MS = 3e4;
|
|
|
66154
66144
|
/** Minimum wait after a failed platform fetch before another background revalidation. */
|
|
66155
66145
|
const FAILURE_COOLDOWN_MS = 3e4;
|
|
66156
66146
|
/**
|
|
66157
|
-
* Returns a live channels resolver over the project's Platform connections
|
|
66158
|
-
*
|
|
66159
|
-
*
|
|
66160
|
-
*
|
|
66147
|
+
* Returns a live channels resolver over the project's Platform connections,
|
|
66148
|
+
* ready to hand to `new Mastra({ channels: await channels({...}) })`.
|
|
66149
|
+
*
|
|
66150
|
+
* Provider instances for every channel-capable integration (Slack, Telegram,
|
|
66151
|
+
* Discord) are constructed once, up front and credential-less, so their
|
|
66152
|
+
* webhook/OAuth routes can mount at Mastra construction. Each resolution
|
|
66153
|
+
* fetches the project's connections and late-binds credentials into the live
|
|
66154
|
+
* instances: integrations with an active connection appear in the resolved
|
|
66155
|
+
* map, others don't — so connecting a new channel on the platform takes
|
|
66156
|
+
* effect without redeploying the app.
|
|
66161
66157
|
*
|
|
66162
66158
|
* Configuration errors (missing project id, bad ttlMs, malformed integration
|
|
66163
|
-
* id)
|
|
66164
|
-
* problems
|
|
66165
|
-
* are downgraded to warn-and-skip so one
|
|
66166
|
-
* whole map.
|
|
66159
|
+
* id) reject at call time so they surface at startup. Actionable
|
|
66160
|
+
* per-integration problems (provider construction failure, needs re-auth,
|
|
66161
|
+
* ambiguity, credential sync failure) are downgraded to warn-and-skip so one
|
|
66162
|
+
* bad integration never takes down the whole map.
|
|
66167
66163
|
*
|
|
66168
66164
|
* @example
|
|
66169
66165
|
* ```ts
|
|
@@ -66176,13 +66172,48 @@ const FAILURE_COOLDOWN_MS = 3e4;
|
|
|
66176
66172
|
* });
|
|
66177
66173
|
* ```
|
|
66178
66174
|
*/
|
|
66179
|
-
function channels(options = {}) {
|
|
66175
|
+
async function channels(options = {}) {
|
|
66180
66176
|
const projectId = options.projectId?.trim() || process.env.MASTRA_PROJECT_ID?.trim();
|
|
66181
66177
|
if (!projectId) throw new MastraConnectError("missing_project_id", "Missing project id: set MASTRA_PROJECT_ID or pass projectId.");
|
|
66182
66178
|
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.`);
|
|
66183
66179
|
validateIntegrationOverrides(options.integrations);
|
|
66184
66180
|
const ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
66185
66181
|
const client = resolveClient(options.client);
|
|
66182
|
+
const states = [];
|
|
66183
|
+
for (const registration of CHANNELS) {
|
|
66184
|
+
const overrides = options.integrations?.[registration.integrationId] ?? {};
|
|
66185
|
+
if (overrides.disabled) continue;
|
|
66186
|
+
const state = {
|
|
66187
|
+
registration,
|
|
66188
|
+
instance: void 0,
|
|
66189
|
+
connectionId: void 0
|
|
66190
|
+
};
|
|
66191
|
+
const runtime = {
|
|
66192
|
+
client,
|
|
66193
|
+
getConnectionId: () => state.connectionId,
|
|
66194
|
+
getCredential: async () => {
|
|
66195
|
+
const connectionId = state.connectionId;
|
|
66196
|
+
if (!connectionId) throw new MastraConnectError("no_active_connection", `No active ${registration.integrationId} connection for project ${projectId}. Connect one on the platform, then retry.`);
|
|
66197
|
+
return getCredential(client, connectionId);
|
|
66198
|
+
},
|
|
66199
|
+
getConnectionContext: async () => {
|
|
66200
|
+
const connectionId = state.connectionId;
|
|
66201
|
+
if (!connectionId) return void 0;
|
|
66202
|
+
try {
|
|
66203
|
+
return await getConnectionContext(client, connectionId);
|
|
66204
|
+
} catch {
|
|
66205
|
+
return;
|
|
66206
|
+
}
|
|
66207
|
+
}
|
|
66208
|
+
};
|
|
66209
|
+
try {
|
|
66210
|
+
state.instance = await registration.create(overrides.providerOptions ?? {}, runtime);
|
|
66211
|
+
} catch (error) {
|
|
66212
|
+
console.warn(`[@mastra/connect] Skipping ${registration.integrationId} channel: ${error instanceof Error ? error.message : String(error)}`);
|
|
66213
|
+
continue;
|
|
66214
|
+
}
|
|
66215
|
+
states.push(state);
|
|
66216
|
+
}
|
|
66186
66217
|
let cache;
|
|
66187
66218
|
let inflight;
|
|
66188
66219
|
let lastFailureAt;
|
|
@@ -66196,17 +66227,20 @@ function channels(options = {}) {
|
|
|
66196
66227
|
}
|
|
66197
66228
|
const byIntegrationId = groupByIntegrationId(connections);
|
|
66198
66229
|
const providers = {};
|
|
66199
|
-
for (const
|
|
66200
|
-
const integrationId = registration.integrationId;
|
|
66230
|
+
for (const state of states) {
|
|
66231
|
+
const integrationId = state.registration.integrationId;
|
|
66201
66232
|
const overrides = options.integrations?.[integrationId] ?? {};
|
|
66202
|
-
if (overrides.disabled) continue;
|
|
66203
66233
|
const candidates = byIntegrationId.get(integrationId) ?? [];
|
|
66204
|
-
|
|
66205
|
-
|
|
66234
|
+
const connectionId = candidates.length === 0 ? void 0 : selectChannelConnection(integrationId, overrides.connectionId, candidates);
|
|
66235
|
+
state.connectionId = connectionId;
|
|
66206
66236
|
if (!connectionId) continue;
|
|
66207
|
-
|
|
66208
|
-
|
|
66209
|
-
|
|
66237
|
+
if (state.instance.sync) try {
|
|
66238
|
+
await state.instance.sync();
|
|
66239
|
+
} catch (error) {
|
|
66240
|
+
console.warn(`[@mastra/connect] Skipping ${integrationId} channel: ${error instanceof Error ? error.message : String(error)}`);
|
|
66241
|
+
continue;
|
|
66242
|
+
}
|
|
66243
|
+
providers[integrationId] = state.instance.provider;
|
|
66210
66244
|
}
|
|
66211
66245
|
lastFailureAt = void 0;
|
|
66212
66246
|
return providers;
|
|
@@ -66241,6 +66275,7 @@ function channels(options = {}) {
|
|
|
66241
66275
|
return refresh();
|
|
66242
66276
|
};
|
|
66243
66277
|
const invocable = ((_context) => resolve());
|
|
66278
|
+
invocable.getRoutes = () => states.flatMap((state) => state.instance.provider.getRoutes());
|
|
66244
66279
|
invocable.invalidate = () => {
|
|
66245
66280
|
cache = void 0;
|
|
66246
66281
|
};
|
|
@@ -66248,35 +66283,8 @@ function channels(options = {}) {
|
|
|
66248
66283
|
invocable.disconnect = async () => {
|
|
66249
66284
|
cache = void 0;
|
|
66250
66285
|
};
|
|
66251
|
-
invocable.then = ((onfulfilled, onrejected) => resolve().then(onfulfilled, onrejected));
|
|
66252
66286
|
return invocable;
|
|
66253
66287
|
}
|
|
66254
|
-
async function buildProvider(registration, connectionId, overrides, client) {
|
|
66255
|
-
let credential;
|
|
66256
|
-
try {
|
|
66257
|
-
credential = await getCredential(client, connectionId);
|
|
66258
|
-
} catch (error) {
|
|
66259
|
-
console.warn(`[@mastra/connect] Skipping ${registration.integrationId} channel: ${error instanceof Error ? error.message : String(error)}`);
|
|
66260
|
-
return;
|
|
66261
|
-
}
|
|
66262
|
-
let context = {
|
|
66263
|
-
connectionId,
|
|
66264
|
-
client
|
|
66265
|
-
};
|
|
66266
|
-
try {
|
|
66267
|
-
context = {
|
|
66268
|
-
connectionId,
|
|
66269
|
-
client,
|
|
66270
|
-
context: await getConnectionContext(client, connectionId)
|
|
66271
|
-
};
|
|
66272
|
-
} catch {}
|
|
66273
|
-
try {
|
|
66274
|
-
return await registration.build(credential, overrides.providerOptions ?? {}, context);
|
|
66275
|
-
} catch (error) {
|
|
66276
|
-
console.warn(`[@mastra/connect] Skipping ${registration.integrationId} channel: ${error instanceof Error ? error.message : String(error)}`);
|
|
66277
|
-
return;
|
|
66278
|
-
}
|
|
66279
|
-
}
|
|
66280
66288
|
/**
|
|
66281
66289
|
* Selects the connection `channels()` should use for one provider.
|
|
66282
66290
|
*
|