@mastra/connect 0.3.1-alpha.0 → 0.4.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.
@@ -0,0 +1,32 @@
1
+ import type { ChannelProvider } from '@mastra/core/channels';
2
+ import type { ConnectionCredential, ConnectionContext, ResolvedClient } from '../client.js';
3
+ /**
4
+ * Extra inputs a channel contributor may need beyond the raw credential:
5
+ * durable non-secret metadata that lives on the platform connection (e.g.
6
+ * Discord's `applicationId` + `publicKey`), and a resolved client for
7
+ * follow-up lookups when necessary.
8
+ */
9
+ export interface ChannelBuildContext {
10
+ connectionId: string;
11
+ context?: ConnectionContext;
12
+ client: ResolvedClient;
13
+ }
14
+ /**
15
+ * Registers one channel-capable provider with `channels()`. An `integrationId`
16
+ * matches the project connection and `build()` materializes a Mastra
17
+ * `ChannelProvider` from the credential (plus per-integration
18
+ * `providerOptions`). Ambiguity is handled at the resolver level (`channels()`
19
+ * warns and picks the first active connection when more than one is present)
20
+ * so registrations stay minimal.
21
+ */
22
+ export interface ChannelProviderRegistration<Options = Record<string, unknown>> {
23
+ /** Platform catalog id used to match project connections (e.g. 'slack', 'telegram', 'discord'). */
24
+ integrationId: string;
25
+ /**
26
+ * Build a Mastra `ChannelProvider` from a resolved credential. Peer packages
27
+ * are imported inside `build()` with `await import()` so they stay optional
28
+ * at install time.
29
+ */
30
+ build(credential: ConnectionCredential, options?: Options, context?: ChannelBuildContext): Promise<ChannelProvider>;
31
+ }
32
+ //# sourceMappingURL=channel-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel-provider.d.ts","sourceRoot":"","sources":["../../src/providers/channel-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE5F;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,2BAA2B,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5E,mGAAmG;IACnG,aAAa,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,KAAK,CAAC,UAAU,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CACrH"}
@@ -0,0 +1,30 @@
1
+ import type { ChannelProviderRegistration } from './channel-provider.js';
2
+ /**
3
+ * Fields on `providerOptions` that `channels()` refuses to forward to a
4
+ * `ChannelProvider` constructor. Two categories:
5
+ *
6
+ * - **Credentials.** The whole point of `channels()` is that the credential
7
+ * comes from the platform connection. Passing another `refreshToken` /
8
+ * `botToken` via `providerOptions` would silently override the connection
9
+ * (and thereby bypass rotation, revocation, and auditing).
10
+ * - **Framework-managed.** `baseUrl` is derived from the Mastra server config
11
+ * so webhook URLs match the actually-bound host. Overriding it from user code
12
+ * is a foot-gun (mismatched OAuth redirect URIs, dropped webhook deliveries).
13
+ * `encryptionKey` is a process-wide at-rest secret sourced from
14
+ * `MASTRA_ENCRYPTION_KEY`; letting `providerOptions` override it per
15
+ * integration would fragment the encryption boundary.
16
+ *
17
+ * Anything on this list is stripped with a warning; the rest of
18
+ * `providerOptions` (handlers, streaming, commands, handlers, threadContext,
19
+ * inlineMedia, etc.) is forwarded to the provider constructor unchanged.
20
+ */
21
+ declare const SLACK_RESERVED_KEYS: readonly ['baseUrl', 'refreshToken', 'token', 'encryptionKey'];
22
+ declare const TELEGRAM_RESERVED_KEYS: readonly ['baseUrl', 'apiBaseUrl', 'botToken', 'encryptionKey'];
23
+ declare const DISCORD_RESERVED_KEYS: readonly ['baseUrl', 'encryptionKey'];
24
+ /** Reserved (credential + framework-managed) `providerOptions` keys per integration. */
25
+ export type SlackReservedProviderOption = (typeof SLACK_RESERVED_KEYS)[number];
26
+ export type TelegramReservedProviderOption = (typeof TELEGRAM_RESERVED_KEYS)[number];
27
+ export type DiscordReservedProviderOption = (typeof DISCORD_RESERVED_KEYS)[number];
28
+ export declare const CHANNELS: readonly ChannelProviderRegistration[];
29
+ export {};
30
+ //# sourceMappingURL=channels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channels.d.ts","sourceRoot":"","sources":["../../src/providers/channels.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAczE;;;;;;;;;;;;;;;;;;GAkBG;AACH,QAAA,MAAM,mBAAmB,YAAI,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,eAAe,CAAU,CAAC;AAC3F,QAAA,MAAM,sBAAsB,YAAI,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,CAAU,CAAC;AAC/F,QAAA,MAAM,qBAAqB,YAAI,SAAS,EAAE,eAAe,CAAU,CAAC;AAEpE,wFAAwF;AACxF,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/E,MAAM,MAAM,8BAA8B,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrF,MAAM,MAAM,6BAA6B,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAuKnF,eAAO,MAAM,QAAQ,EAAE,SAAS,2BAA2B,EAAoD,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { ToolsInput } from '@mastra/core/agent';
2
+ import type { ChannelProviderRegistration } from './providers/channel-provider.js';
2
3
  import type { ProviderToolsOptions } from './toolset.js';
3
4
  interface ProviderRegistrationBase {
4
5
  /** Platform catalog id used to match project connections. */
@@ -20,7 +21,19 @@ export type ProviderRegistration = ProxyProviderRegistration | McpProviderRegist
20
21
  * Providers with checked-in HTTP toolsets. MCP-backed providers are discovered
21
22
  * from the Platform integration catalog at runtime.
22
23
  */
24
+ export declare const TOOLS: readonly ProviderRegistration[];
25
+ /**
26
+ * @deprecated Use `TOOLS`. This alias is retained for one release cycle so
27
+ * downstream consumers keep working; it will be removed in the next minor.
28
+ */
23
29
  export declare const PROVIDERS: readonly ProviderRegistration[];
24
30
  export declare function findRegistration(integrationId: string): ProviderRegistration | undefined;
31
+ /**
32
+ * Channel-capable providers with a hand-maintained `channels()` registration.
33
+ * The launch ships three (Slack, Telegram, Discord); the provider generator
34
+ * grows to cover new entries when a fourth lands.
35
+ */
36
+ export declare const CHANNELS: readonly ChannelProviderRegistration[];
37
+ export declare function findChannelRegistration(integrationId: string): ChannelProviderRegistration | undefined;
25
38
  export {};
26
39
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD,UAAU,wBAAwB;IAChC,6DAA6D;IAC7D,aAAa,EAAE,MAAM,CAAC;IACtB,+FAA+F;IAC/F,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,sEAAsE;AACtE,MAAM,WAAW,yBAA0B,SAAQ,wBAAwB;IACzE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,UAAU,CAAC;CAC7D;AAED,iFAAiF;AACjF,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACvE,SAAS,EAAE,KAAK,CAAC;CAClB;AAED,MAAM,MAAM,oBAAoB,GAAG,yBAAyB,GAAG,uBAAuB,CAAC;AAEvF;;;GAGG;AACH,e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client.js';
2
+ /** Identifies one provider's connection-resolution inputs. */
3
+ export interface ConnectionRequest {
4
+ integrationId: string;
5
+ /** Fallback connection-id environment variable when more than one active connection exists. */
6
+ envVar: string;
7
+ /** Pinned connection id from per-integration options. */
8
+ connectionId?: string;
9
+ }
10
+ export declare function validateIntegrationOverrides(integrations: Record<string, unknown> | undefined): void;
11
+ export declare function connectionIdEnvVar(integrationId: string): string;
12
+ export declare function groupByIntegrationId(connections: ProjectConnection[]): Map<string, ProjectConnection[]>;
13
+ /**
14
+ * Resolves the connection to use for one provider, per the contract:
15
+ * option/env var wins; else a single active connection; anything else
16
+ * (ambiguity, needs_reauth, no usable candidate) warns and skips so one bad
17
+ * integration never takes down the whole resolution. A needs_reauth
18
+ * connection is never silently mapped.
19
+ */
20
+ export declare function resolveConnection(request: ConnectionRequest, candidates: ProjectConnection[]): string | undefined;
21
+ //# sourceMappingURL=resolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../src/resolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,+FAA+F;IAC/F,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAID,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI,CASpG;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,iBAAiB,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAQvG;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,iBAAiB,EAAE,GAAG,MAAM,GAAG,SAAS,CAoCjH"}
@@ -0,0 +1,66 @@
1
+ import type { ConnectClientOptions } from './client.js';
2
+ export interface ToolsIntegrationOptions {
3
+ /** Pin a specific connection id (bypasses env-var fallback and single-active-connection resolution). */
4
+ connectionId?: string;
5
+ /** Restrict the returned toolset to these tool keys. Unknown names throw at build time. */
6
+ allowTools?: string[];
7
+ /**
8
+ * MCP tool keys that may run without tool approval. Every other discovered
9
+ * MCP tool requires approval, whatever the server's annotations claim, since
10
+ * a remote catalog cannot be trusted to classify its own tools. An unknown
11
+ * name skips the provider with a warning, so a typo never widens access.
12
+ */
13
+ autoApproveTools?: string[];
14
+ /** Exclude this provider entirely, even if a connection exists. */
15
+ disabled?: boolean;
16
+ }
17
+ export interface ToolsOptions {
18
+ /** Platform project whose connections to discover. Falls back to MASTRA_PROJECT_ID. */
19
+ projectId?: string;
20
+ /** Optional per-provider overrides keyed by integrationId. */
21
+ integrations?: Record<string, ToolsIntegrationOptions>;
22
+ client?: ConnectClientOptions;
23
+ /** How long a resolved snapshot stays fresh, in milliseconds. Default 30_000. `0` revalidates every resolution. */
24
+ ttlMs?: number;
25
+ }
26
+ type ResolvedToolsRecord = Record<string, {
27
+ id: string;
28
+ }>;
29
+ /**
30
+ * Live tool resolver returned by `tools()`. Pass it straight to an agent's
31
+ * dynamic `tools` argument: Mastra calls it per generate/stream, so project
32
+ * integrations attached or detached on the platform are reflected without
33
+ * restarting the server. Call it directly (`await tools()`) when you need the
34
+ * current flat tool record.
35
+ */
36
+ export interface ToolsResolver {
37
+ (ctx?: {
38
+ requestContext?: unknown;
39
+ mastra?: unknown;
40
+ }): Promise<ResolvedToolsRecord>;
41
+ /** Drops the cached snapshot; the next resolution fetches fresh from the platform. */
42
+ invalidate(): void;
43
+ /** Fetches tools from the platform now and updates the cache. Rejects if the platform fetch fails. */
44
+ refresh(): Promise<ResolvedToolsRecord>;
45
+ /** Closes MCP transports owned by this resolver and clears its cached snapshot. */
46
+ disconnect(): Promise<void>;
47
+ }
48
+ /**
49
+ * Returns a live toolset resolver over the project's Platform connections.
50
+ * HTTP providers are loaded from the shipped `TOOLS` registry. MCP providers
51
+ * are discovered from the Platform integration catalog. Tools from every supported
52
+ * provider with a matching project connection are merged into one flat record
53
+ * (matched by `integrationId`). The resolver serves a cached snapshot,
54
+ * revalidating from the platform every `ttlMs`, so integrations attached
55
+ * to (or detached from) the project are picked up (or dropped) without a
56
+ * restart.
57
+ *
58
+ * Configuration errors (missing project id, bad ttlMs, malformed integration id)
59
+ * throw here — at call time — so they surface at startup.
60
+ * Expected provider absence is silently skipped. Actionable per-integration
61
+ * problems during resolution (needs re-auth or ambiguity) are downgraded to
62
+ * warn-and-skip so one bad integration never takes down the whole toolset.
63
+ */
64
+ export declare function tools(options?: ToolsOptions): ToolsResolver;
65
+ export {};
66
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAA8D,MAAM,aAAa,CAAC;AAapH,MAAM,WAAW,uBAAuB;IACtC,wGAAwG;IACxG,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2FAA2F;IAC3F,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;IACvD,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,mHAAmH;IACnH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID,KAAK,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE1D;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACrF,sFAAsF;IACtF,UAAU,IAAI,IAAI,CAAC;IACnB,sGAAsG;IACtG,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACxC,mFAAmF;IACnF,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAYD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,aAAa,CAkI/D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/connect",
3
- "version": "0.3.1-alpha.0",
3
+ "version": "0.4.0-alpha.0",
4
4
  "description": "Use Mastra platform integration connections as agent toolsets",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -45,8 +45,22 @@
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@mastra/core": ">=1.68.0-0 <2.0.0-0",
48
+ "@mastra/discord": ">=1.0.0-0 <2.0.0-0",
49
+ "@mastra/slack": ">=1.0.0-0 <2.0.0-0",
50
+ "@mastra/telegram": ">=0.1.0-0 <1.0.0-0",
48
51
  "zod": ">=3.0.0 || >=4.0.0"
49
52
  },
53
+ "peerDependenciesMeta": {
54
+ "@mastra/discord": {
55
+ "optional": true
56
+ },
57
+ "@mastra/slack": {
58
+ "optional": true
59
+ },
60
+ "@mastra/telegram": {
61
+ "optional": true
62
+ }
63
+ },
50
64
  "devDependencies": {
51
65
  "prettier": "3.9.5",
52
66
  "ts-morph": "^27.0.2",
@@ -55,12 +69,15 @@
55
69
  "typescript": "^7.0.2",
56
70
  "vitest": "4.1.11",
57
71
  "zod": "^4.6.4",
58
- "@internal/types-builder": "0.0.110",
59
- "@mastra/core": "1.70.0-alpha.0",
60
- "@internal/lint": "0.0.135"
72
+ "@internal/lint": "0.0.136",
73
+ "@internal/types-builder": "0.0.111",
74
+ "@mastra/core": "1.71.0-alpha.1",
75
+ "@mastra/slack": "1.6.4",
76
+ "@mastra/discord": "1.1.0-alpha.0",
77
+ "@mastra/telegram": "0.1.3-alpha.0"
61
78
  },
62
79
  "dependencies": {
63
- "@mastra/mcp": "^2.1.0-alpha.0"
80
+ "@mastra/mcp": "^2.1.0"
64
81
  },
65
82
  "scripts": {
66
83
  "add-provider": "tsx scripts/add-provider.ts",
@@ -72,6 +89,6 @@
72
89
  "list-providers": "tsx scripts/list-providers.ts",
73
90
  "remove-provider": "tsx scripts/remove-provider.ts",
74
91
  "sync-templates": "tsx scripts/sync-templates.ts",
75
- "test": "vitest run"
92
+ "test": "vitest run && tsc --noEmit"
76
93
  }
77
94
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=connect.test-d.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect.test-d.d.ts","sourceRoot":"","sources":["../src/connect.test-d.ts"],"names":[],"mappings":""}