@myrialabs/clopen 0.4.37 → 0.4.39
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/README.md +2 -2
- package/backend/auth/permissions.ts +39 -0
- package/backend/bootstrap.ts +16 -0
- package/backend/chat/stream-manager.ts +1 -1
- package/backend/database/crypto/envelope.test.ts +93 -0
- package/backend/database/crypto/envelope.ts +127 -0
- package/backend/database/crypto/index.ts +22 -0
- package/backend/database/crypto/master-key.ts +129 -0
- package/backend/database/crypto/secret-columns.ts +151 -0
- package/backend/database/migrations/071_create_notes_tables.ts +90 -0
- package/backend/database/migrations/072_encrypt_stored_secrets.ts +107 -0
- package/backend/database/migrations/073_create_integration_tables.ts +119 -0
- package/backend/database/migrations/074_create_work_tables.ts +94 -0
- package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
- package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
- package/backend/database/migrations/index.ts +49 -0
- package/backend/database/queries/db-client-connection-queries.ts +42 -12
- package/backend/database/queries/deploy-queries.ts +124 -0
- package/backend/database/queries/engine-queries.ts +23 -10
- package/backend/database/queries/graph-queries.ts +291 -247
- package/backend/database/queries/index.ts +10 -1
- package/backend/database/queries/integration-db-link-queries.ts +168 -0
- package/backend/database/queries/integration-queries.ts +325 -0
- package/backend/database/queries/mcp-server-queries.ts +38 -11
- package/backend/database/queries/note-queries.test.ts +190 -0
- package/backend/database/queries/note-queries.ts +269 -0
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/ssh-connection-queries.ts +19 -8
- package/backend/database/queries/work-queries.ts +210 -0
- package/backend/db-client/integrations/index.ts +37 -0
- package/backend/db-client/integrations/links.ts +533 -0
- package/backend/db-client/integrations/projector.test.ts +280 -0
- package/backend/db-client/integrations/projector.ts +256 -0
- package/backend/db-client/integrations/supabase-service.ts +266 -0
- package/backend/db-client/providers/registry.ts +27 -0
- package/backend/db-client/providers/supabase/adapter.ts +500 -0
- package/backend/db-client/providers/supabase/api-types.ts +92 -0
- package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
- package/backend/db-client/providers/supabase/client.ts +259 -0
- package/backend/db-client/providers/supabase/features.ts +502 -0
- package/backend/db-client/providers/supabase/local.test.ts +78 -0
- package/backend/db-client/providers/supabase/local.ts +137 -0
- package/backend/db-client/providers/types.ts +137 -0
- package/backend/deployments/bindings.test.ts +43 -0
- package/backend/deployments/bindings.ts +216 -0
- package/backend/deployments/index.ts +53 -0
- package/backend/deployments/log-streams.ts +214 -0
- package/backend/deployments/prompts.ts +70 -0
- package/backend/deployments/providers/vercel/adapter.ts +757 -0
- package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
- package/backend/deployments/providers/vercel/build-logs.ts +211 -0
- package/backend/deployments/providers/vercel/client.ts +203 -0
- package/backend/deployments/providers/vercel/list.test.ts +624 -0
- package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
- package/backend/deployments/providers/vercel/normalise.ts +113 -0
- package/backend/deployments/providers/vercel/types.ts +104 -0
- package/backend/deployments/registry.ts +27 -0
- package/backend/deployments/service.ts +458 -0
- package/backend/deployments/types.ts +278 -0
- package/backend/engine/docs/artifacts.md +22 -9
- package/backend/files/os-clipboard.test.ts +209 -0
- package/backend/files/os-clipboard.ts +567 -0
- package/backend/http/integration-hooks.ts +42 -0
- package/backend/http/notes-images.test.ts +228 -0
- package/backend/http/notes-images.ts +196 -0
- package/backend/index.ts +13 -0
- package/backend/integrations/accounts.ts +229 -0
- package/backend/integrations/health.ts +146 -0
- package/backend/integrations/index.ts +36 -0
- package/backend/integrations/projections/index.ts +0 -0
- package/backend/integrations/projections/mcp-projector.test.ts +204 -0
- package/backend/integrations/projections/mcp-projector.ts +163 -0
- package/backend/integrations/projections/types.ts +63 -0
- package/backend/integrations/registry/define.ts +38 -0
- package/backend/integrations/registry/index.ts +60 -0
- package/backend/integrations/registry/providers/context7.ts +44 -0
- package/backend/integrations/registry/providers/firecrawl.ts +41 -0
- package/backend/integrations/registry/providers/github.ts +78 -0
- package/backend/integrations/registry/providers/supabase.ts +61 -0
- package/backend/integrations/registry/providers/vercel.ts +46 -0
- package/backend/integrations/registry/types.ts +96 -0
- package/backend/integrations/webhooks/gateway.ts +160 -0
- package/backend/integrations/webhooks/verify.ts +65 -0
- package/backend/mcp/README.md +25 -3
- package/backend/mcp/external/config.ts +35 -1
- package/backend/mcp/index.ts +1 -1
- package/backend/mcp/internal/config.ts +1 -1
- package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
- package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
- package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
- package/backend/memory/README.md +57 -34
- package/backend/memory/compose.test.ts +3 -3
- package/backend/memory/compose.ts +6 -9
- package/backend/memory/config.ts +0 -5
- package/backend/memory/consolidate.ts +1 -2
- package/backend/memory/context.test.ts +8 -54
- package/backend/memory/context.ts +19 -25
- package/backend/memory/extract/episodic.ts +10 -12
- package/backend/memory/extract/index.ts +23 -52
- package/backend/memory/extract/scheduler.ts +3 -6
- package/backend/memory/index.ts +6 -5
- package/backend/memory/invalidate.ts +36 -48
- package/backend/memory/layout.ts +319 -130
- package/backend/memory/retention.ts +12 -42
- package/backend/memory/retrieval.eval.test.ts +2 -2
- package/backend/memory/retrieval.test.ts +228 -183
- package/backend/memory/retrieval.ts +22 -21
- package/backend/memory/revise.test.ts +62 -116
- package/backend/memory/revise.ts +0 -1
- package/backend/memory/view.ts +8 -5
- package/backend/notes/access.test.ts +82 -0
- package/backend/notes/access.ts +27 -0
- package/backend/notes/storage.test.ts +77 -0
- package/backend/notes/storage.ts +114 -0
- package/backend/permissions/service.ts +2 -2
- package/backend/profiles/service.ts +1 -1
- package/backend/projects/project-cleanup.ts +6 -0
- package/backend/snapshot/helpers.ts +35 -41
- package/backend/snapshot/snapshot-service.ts +90 -0
- package/backend/snapshot/turn-changes.test.ts +163 -0
- package/backend/snapshot/turn-changes.ts +131 -0
- package/backend/work/bindings.ts +124 -0
- package/backend/work/index.ts +42 -0
- package/backend/work/prompts.ts +150 -0
- package/backend/work/providers/github/actions-logs.ts +180 -0
- package/backend/work/providers/github/adapter.test.ts +88 -0
- package/backend/work/providers/github/adapter.ts +1255 -0
- package/backend/work/providers/github/client.ts +280 -0
- package/backend/work/providers/github/list-range.test.ts +158 -0
- package/backend/work/providers/github/token-kind.test.ts +42 -0
- package/backend/work/pull-requests.ts +242 -0
- package/backend/work/registry.ts +27 -0
- package/backend/work/service.ts +436 -0
- package/backend/work/start-work.test.ts +71 -0
- package/backend/work/start-work.ts +232 -0
- package/backend/work/types.ts +180 -0
- package/backend/ws/db-client/accounts.ts +225 -0
- package/backend/ws/db-client/connections.ts +34 -3
- package/backend/ws/db-client/context.ts +37 -0
- package/backend/ws/db-client/index.ts +20 -1
- package/backend/ws/db-client/supabase.ts +188 -0
- package/backend/ws/deployments/actions.ts +360 -0
- package/backend/ws/deployments/context.ts +43 -0
- package/backend/ws/deployments/crud.ts +152 -0
- package/backend/ws/deployments/index.ts +15 -0
- package/backend/ws/deployments/schemas.ts +183 -0
- package/backend/ws/files/clipboard.ts +78 -0
- package/backend/ws/files/index.ts +5 -0
- package/backend/ws/git/diff-budget.ts +70 -11
- package/backend/ws/index.ts +16 -2
- package/backend/ws/integrations/crud.ts +219 -0
- package/backend/ws/integrations/index.ts +22 -0
- package/backend/ws/mcp/crud.ts +25 -1
- package/backend/ws/memory/crud.ts +4 -16
- package/backend/ws/notes/index.ts +278 -0
- package/backend/ws/profiles/crud.ts +1 -1
- package/backend/ws/snapshot/changes.ts +279 -0
- package/backend/ws/snapshot/index.ts +4 -3
- package/backend/ws/work/actions.ts +206 -0
- package/backend/ws/work/context.ts +51 -0
- package/backend/ws/work/crud.ts +347 -0
- package/backend/ws/work/index.ts +17 -0
- package/backend/ws/work/pull-requests.ts +177 -0
- package/backend/ws/work/schemas.ts +226 -0
- package/dist/assets/{index-sJmS_CCm.js → index-BrF6nqld.js} +1 -1
- package/dist/assets/{index-Bik9TCBi.js → index-C8Gi-b6U.js} +1 -1
- package/dist/assets/main-Bd3gb79F.css +1 -0
- package/dist/assets/main-Bo1hD7mt.js +1191 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/tool-icons.ts +42 -0
- package/shared/types/database/schema.ts +41 -0
- package/shared/types/db-client/connection.ts +6 -0
- package/shared/types/db-client/index.ts +2 -0
- package/shared/types/db-client/integrations.ts +174 -0
- package/shared/types/db-client/supabase.ts +131 -0
- package/shared/types/deployments.ts +382 -0
- package/shared/types/integrations.ts +140 -0
- package/shared/types/memory.ts +34 -51
- package/shared/types/stores/settings.ts +8 -0
- package/shared/types/ui/components.ts +1 -1
- package/shared/types/work.ts +426 -0
- package/shared/utils/diff-calculator.test.ts +89 -0
- package/shared/utils/diff-calculator.ts +30 -65
- package/shared/utils/logger.ts +4 -0
- package/backend/memory/extract/languages.ts +0 -176
- package/backend/memory/extract/structural.test.ts +0 -215
- package/backend/memory/extract/structural.ts +0 -364
- package/backend/ws/snapshot/content.ts +0 -85
- package/dist/assets/main-DLqolBI2.css +0 -1
- package/dist/assets/main-Df1I3hnw.js +0 -1096
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account health, and the health of the secrets layer itself.
|
|
3
|
+
*
|
|
4
|
+
* Account health reuses the MCP probe rather than inventing a second notion of
|
|
5
|
+
* "is this connector working" — for an account whose only capability is agent
|
|
6
|
+
* tools, the probe against its projected row IS the answer.
|
|
7
|
+
*
|
|
8
|
+
* That answer runs out the moment a capability projects no MCP row. A GitHub
|
|
9
|
+
* account offering `work` has a credential that can be verified precisely —
|
|
10
|
+
* by calling the API it was issued for — but nothing for `probeServer()` to
|
|
11
|
+
* reach. So a surface may register its own probe for its providers, and the
|
|
12
|
+
* hub's status strip keeps meaning something for every account rather than
|
|
13
|
+
* reading "Nothing to probe yet" forever.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { probeServer, resolveServerRow } from '$backend/mcp';
|
|
17
|
+
import {
|
|
18
|
+
integrationAccountQueries,
|
|
19
|
+
integrationProjectionQueries,
|
|
20
|
+
mcpServerQueries
|
|
21
|
+
} from '$backend/database/queries';
|
|
22
|
+
import { getDatabase } from '$backend/database';
|
|
23
|
+
import { auditSecretColumns, getDecryptFailures, getMasterKey } from '$backend/database/crypto';
|
|
24
|
+
import type { IntegrationStatus, SecretsHealth } from '$shared/types/integrations';
|
|
25
|
+
import { integrationAccounts } from './accounts';
|
|
26
|
+
import { debug } from '$shared/utils/logger';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A probe contributed by a surface, keyed by provider id.
|
|
30
|
+
*
|
|
31
|
+
* Returning null means "this probe has nothing to say about this account" — for
|
|
32
|
+
* instance a GitHub account with `work` switched off — and the MCP path is
|
|
33
|
+
* used instead. That is what lets one account carry both kinds of capability
|
|
34
|
+
* without the two probes fighting over which one reports.
|
|
35
|
+
*/
|
|
36
|
+
export type AccountProbe = (
|
|
37
|
+
accountId: string,
|
|
38
|
+
projectId: string | null
|
|
39
|
+
) => Promise<{ status: IntegrationStatus; detail: string | null } | null>;
|
|
40
|
+
|
|
41
|
+
const providerProbes = new Map<string, AccountProbe>();
|
|
42
|
+
|
|
43
|
+
/** Register a provider-specific probe. Called at module load by the surface. */
|
|
44
|
+
export function registerAccountProbe(provider: string, probe: AccountProbe): void {
|
|
45
|
+
providerProbes.set(provider, probe);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Probe one account.
|
|
50
|
+
*
|
|
51
|
+
* An account with no projected MCP row has nothing probeable yet — its
|
|
52
|
+
* capabilities belong to surfaces that do not exist. That is reported as
|
|
53
|
+
* `unknown` rather than `ok`, because claiming health we never measured is the
|
|
54
|
+
* one answer worse than "not checked".
|
|
55
|
+
*/
|
|
56
|
+
export async function checkAccountHealth(accountId: string): Promise<{ status: IntegrationStatus; detail: string | null }> {
|
|
57
|
+
const account = integrationAccountQueries.getById(accountId);
|
|
58
|
+
if (!account) throw new Error('Integration account not found');
|
|
59
|
+
|
|
60
|
+
if (account.is_enabled !== 1) {
|
|
61
|
+
const result = { status: 'unknown' as const, detail: 'Disabled' };
|
|
62
|
+
integrationAccounts.setStatus(accountId, result.status, result.detail);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// A surface probe is the more specific answer when there is one: it talks to
|
|
67
|
+
// the API the credential was issued for, rather than to an MCP server that
|
|
68
|
+
// happens to accept the same token.
|
|
69
|
+
const providerProbe = providerProbes.get(account.provider);
|
|
70
|
+
if (providerProbe) {
|
|
71
|
+
try {
|
|
72
|
+
const result = await providerProbe(accountId, account.project_id);
|
|
73
|
+
if (result) {
|
|
74
|
+
integrationAccounts.setStatus(accountId, result.status, result.detail);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
79
|
+
debug.error('integrations', `Provider probe failed for account ${accountId}:`, error);
|
|
80
|
+
integrationAccounts.setStatus(accountId, 'error', detail);
|
|
81
|
+
return { status: 'error', detail };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const projection = integrationProjectionQueries
|
|
86
|
+
.getForAccount(accountId)
|
|
87
|
+
.find((row) => row.target_kind === 'mcp_server');
|
|
88
|
+
|
|
89
|
+
if (!projection) {
|
|
90
|
+
const result = { status: 'unknown' as const, detail: 'Nothing to probe yet' };
|
|
91
|
+
integrationAccounts.setStatus(accountId, result.status, result.detail);
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const row = mcpServerQueries.getById(Number(projection.target_id));
|
|
96
|
+
if (!row) {
|
|
97
|
+
const result = { status: 'error' as const, detail: 'Projected connector is missing' };
|
|
98
|
+
integrationAccounts.setStatus(accountId, result.status, result.detail);
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const health = await probeServer(resolveServerRow(row));
|
|
104
|
+
// The probe's `unreachable` and `local` states have no account-level
|
|
105
|
+
// meaning: one is an error and the other means "nothing to reach".
|
|
106
|
+
const status: IntegrationStatus =
|
|
107
|
+
health.state === 'ok' ? 'ok'
|
|
108
|
+
: health.state === 'needs_auth' ? 'needs_auth'
|
|
109
|
+
: health.state === 'needs_config' ? 'needs_config'
|
|
110
|
+
: health.state === 'local' ? 'unknown'
|
|
111
|
+
: 'error';
|
|
112
|
+
|
|
113
|
+
integrationAccounts.setStatus(accountId, status, health.message ?? null);
|
|
114
|
+
return { status, detail: health.message ?? null };
|
|
115
|
+
} catch (error) {
|
|
116
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
117
|
+
debug.error('integrations', `Health check failed for account ${accountId}:`, error);
|
|
118
|
+
integrationAccounts.setStatus(accountId, 'error', detail);
|
|
119
|
+
return { status: 'error', detail };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* State of secrets at rest, rendered by the hub as a banner.
|
|
125
|
+
*
|
|
126
|
+
* A non-zero failure count is almost always a database restored next to a
|
|
127
|
+
* freshly generated key. Surfacing the fingerprints is what turns that from
|
|
128
|
+
* "some credentials stopped working" into "you are missing key 3f9a1c22".
|
|
129
|
+
*/
|
|
130
|
+
export function getSecretsHealth(): SecretsHealth {
|
|
131
|
+
const { fingerprint, source } = getMasterKey();
|
|
132
|
+
const failures = getDecryptFailures();
|
|
133
|
+
|
|
134
|
+
const unsealedColumns = auditSecretColumns(getDatabase())
|
|
135
|
+
.filter((entry) => entry.unsealed > 0)
|
|
136
|
+
.map((entry) => ({ table: entry.table, column: entry.column, count: entry.unsealed }));
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
keySource: source,
|
|
140
|
+
keyFingerprint: fingerprint,
|
|
141
|
+
failureCount: failures.count,
|
|
142
|
+
lastFailureAt: failures.lastAt,
|
|
143
|
+
unknownKeyFingerprints: failures.fingerprints,
|
|
144
|
+
unsealedColumns
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Third-party integrations.
|
|
3
|
+
*
|
|
4
|
+
* A connected account is a CREDENTIAL WITH CAPABILITIES, stored once in
|
|
5
|
+
* `integration_accounts`. Rows on other surfaces are projections derived from
|
|
6
|
+
* it, and nothing downstream of a projection needs to know accounts exist.
|
|
7
|
+
*
|
|
8
|
+
* registry/ what Clopen can connect to, declared in code
|
|
9
|
+
* accounts.ts connect / reconfigure / disconnect
|
|
10
|
+
* projections/ the derived rows, and the adopt-and-release rules
|
|
11
|
+
* webhooks/ the signed inbound endpoint
|
|
12
|
+
* health.ts account health, and the health of secrets at rest
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
PROVIDERS,
|
|
17
|
+
getProvider,
|
|
18
|
+
listProviderInfo,
|
|
19
|
+
toProviderInfo,
|
|
20
|
+
defaultCapabilitiesOf,
|
|
21
|
+
defineProvider
|
|
22
|
+
} from './registry';
|
|
23
|
+
export type { IntegrationProvider, McpPreset, WebhookSpec } from './registry';
|
|
24
|
+
|
|
25
|
+
export { integrationAccounts, toAccountInfo } from './accounts';
|
|
26
|
+
export type { ConnectInput } from './accounts';
|
|
27
|
+
|
|
28
|
+
export { reproject, releaseAll, registerProjector, projectableCapabilities } from './projections';
|
|
29
|
+
export type { Projector, ProjectionContext, ProjectionResult } from './projections';
|
|
30
|
+
|
|
31
|
+
export { handleInboundDelivery, onWebhook, MAX_BODY_BYTES } from './webhooks/gateway';
|
|
32
|
+
export type { WebhookEvent, WebhookSubscriber } from './webhooks/gateway';
|
|
33
|
+
export { verifySignature } from './webhooks/verify';
|
|
34
|
+
|
|
35
|
+
export { checkAccountHealth, getSecretsHealth, registerAccountProbe } from './health';
|
|
36
|
+
export type { AccountProbe } from './health';
|
|
Binary file
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the agent-tools projection.
|
|
3
|
+
*
|
|
4
|
+
* The cases that matter are the ownership ones, because they are the ones that
|
|
5
|
+
* destroy something when they are wrong: adopting a hand-installed server must
|
|
6
|
+
* produce ONE entry rather than a sibling, and disconnecting must hand that
|
|
7
|
+
* server back with the credential the user had on it — not with ours, and not
|
|
8
|
+
* with an empty one.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'bun:test';
|
|
12
|
+
|
|
13
|
+
import { initializeDatabase, closeDatabase } from '$backend/database';
|
|
14
|
+
import { mcpServerQueries, integrationAccountQueries, integrationProjectionQueries } from '$backend/database/queries';
|
|
15
|
+
import { integrationAccounts } from '../accounts';
|
|
16
|
+
|
|
17
|
+
const FIRECRAWL_SLUG = 'firecrawl';
|
|
18
|
+
|
|
19
|
+
function parseEnv(slug: string): Record<string, string> {
|
|
20
|
+
const row = mcpServerQueries.getBySlug(slug);
|
|
21
|
+
if (!row) return {};
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(row.env) as Record<string, string>;
|
|
24
|
+
} catch {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function clearFixtures(): void {
|
|
30
|
+
for (const account of integrationAccountQueries.getAll()) {
|
|
31
|
+
integrationAccountQueries.remove(account.id);
|
|
32
|
+
}
|
|
33
|
+
const row = mcpServerQueries.getBySlug(FIRECRAWL_SLUG);
|
|
34
|
+
if (row) mcpServerQueries.remove(row.id);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
beforeAll(async () => {
|
|
38
|
+
await initializeDatabase();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
clearFixtures();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterAll(() => {
|
|
46
|
+
clearFixtures();
|
|
47
|
+
closeDatabase();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('agent-tools projection', () => {
|
|
51
|
+
it('creates a connector row and removes it on disconnect', () => {
|
|
52
|
+
const account = integrationAccounts.connect({
|
|
53
|
+
provider: 'firecrawl',
|
|
54
|
+
credentials: { apiKey: 'fc-first' }
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const row = mcpServerQueries.getBySlug(FIRECRAWL_SLUG);
|
|
58
|
+
expect(row).not.toBe(null);
|
|
59
|
+
expect(parseEnv(FIRECRAWL_SLUG).FIRECRAWL_API_KEY).toBe('fc-first');
|
|
60
|
+
expect(account.projections[0]?.adopted).toBe(false);
|
|
61
|
+
|
|
62
|
+
integrationAccounts.disconnect(account.id);
|
|
63
|
+
expect(mcpServerQueries.getBySlug(FIRECRAWL_SLUG)).toBe(null);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('adopts a hand-installed server instead of creating a sibling', () => {
|
|
67
|
+
mcpServerQueries.insert({
|
|
68
|
+
slug: FIRECRAWL_SLUG,
|
|
69
|
+
name: 'My Firecrawl',
|
|
70
|
+
transport: 'stdio',
|
|
71
|
+
command: 'npx',
|
|
72
|
+
args: ['-y', 'firecrawl-mcp'],
|
|
73
|
+
env: { FIRECRAWL_API_KEY: 'fc-mine', EXTRA: 'keep-me' },
|
|
74
|
+
source: 'custom'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const account = integrationAccounts.connect({
|
|
78
|
+
provider: 'firecrawl',
|
|
79
|
+
credentials: { apiKey: 'fc-account' }
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(mcpServerQueries.getBySource('custom').filter((row) => row.slug === FIRECRAWL_SLUG).length).toBe(1);
|
|
83
|
+
expect(account.projections[0]?.adopted).toBe(true);
|
|
84
|
+
|
|
85
|
+
const env = parseEnv(FIRECRAWL_SLUG);
|
|
86
|
+
expect(env.FIRECRAWL_API_KEY).toBe('fc-account');
|
|
87
|
+
// An env var the preset says nothing about is the user's, and adopting
|
|
88
|
+
// must not quietly drop it.
|
|
89
|
+
expect(env.EXTRA).toBe('keep-me');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('hands an adopted server back with the user credential on disconnect', () => {
|
|
93
|
+
mcpServerQueries.insert({
|
|
94
|
+
slug: FIRECRAWL_SLUG,
|
|
95
|
+
name: 'My Firecrawl',
|
|
96
|
+
transport: 'stdio',
|
|
97
|
+
command: 'npx',
|
|
98
|
+
args: ['-y', 'firecrawl-mcp'],
|
|
99
|
+
env: { FIRECRAWL_API_KEY: 'fc-mine' },
|
|
100
|
+
source: 'custom'
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const account = integrationAccounts.connect({
|
|
104
|
+
provider: 'firecrawl',
|
|
105
|
+
credentials: { apiKey: 'fc-account' }
|
|
106
|
+
});
|
|
107
|
+
integrationAccounts.disconnect(account.id);
|
|
108
|
+
|
|
109
|
+
const row = mcpServerQueries.getBySlug(FIRECRAWL_SLUG);
|
|
110
|
+
expect(row).not.toBe(null);
|
|
111
|
+
expect(parseEnv(FIRECRAWL_SLUG).FIRECRAWL_API_KEY).toBe('fc-mine');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('does not re-snapshot on re-projection, so release still restores the original', () => {
|
|
115
|
+
mcpServerQueries.insert({
|
|
116
|
+
slug: FIRECRAWL_SLUG,
|
|
117
|
+
name: 'My Firecrawl',
|
|
118
|
+
transport: 'stdio',
|
|
119
|
+
command: 'npx',
|
|
120
|
+
env: { FIRECRAWL_API_KEY: 'fc-mine' },
|
|
121
|
+
source: 'custom'
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const account = integrationAccounts.connect({
|
|
125
|
+
provider: 'firecrawl',
|
|
126
|
+
credentials: { apiKey: 'fc-account' }
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// A credential rotation re-projects. If that took a fresh snapshot it
|
|
130
|
+
// would capture OUR key, and release would "restore" a token we are about
|
|
131
|
+
// to delete.
|
|
132
|
+
integrationAccounts.updateCredentials(account.id, { apiKey: 'fc-rotated' });
|
|
133
|
+
expect(parseEnv(FIRECRAWL_SLUG).FIRECRAWL_API_KEY).toBe('fc-rotated');
|
|
134
|
+
|
|
135
|
+
integrationAccounts.disconnect(account.id);
|
|
136
|
+
expect(parseEnv(FIRECRAWL_SLUG).FIRECRAWL_API_KEY).toBe('fc-mine');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('releases the connector when the capability is turned off, and projects again when back on', () => {
|
|
140
|
+
const account = integrationAccounts.connect({
|
|
141
|
+
provider: 'firecrawl',
|
|
142
|
+
credentials: { apiKey: 'fc-toggle' }
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
integrationAccounts.setCapabilities(account.id, []);
|
|
146
|
+
expect(mcpServerQueries.getBySlug(FIRECRAWL_SLUG)).toBe(null);
|
|
147
|
+
expect(integrationProjectionQueries.getForAccount(account.id).length).toBe(0);
|
|
148
|
+
|
|
149
|
+
integrationAccounts.setCapabilities(account.id, ['agent-tools']);
|
|
150
|
+
expect(parseEnv(FIRECRAWL_SLUG).FIRECRAWL_API_KEY).toBe('fc-toggle');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('releases the connector while the account is disabled', () => {
|
|
154
|
+
const account = integrationAccounts.connect({
|
|
155
|
+
provider: 'firecrawl',
|
|
156
|
+
credentials: { apiKey: 'fc-disable' }
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
integrationAccounts.setEnabled(account.id, false);
|
|
160
|
+
expect(mcpServerQueries.getBySlug(FIRECRAWL_SLUG)).toBe(null);
|
|
161
|
+
|
|
162
|
+
integrationAccounts.setEnabled(account.id, true);
|
|
163
|
+
expect(mcpServerQueries.getBySlug(FIRECRAWL_SLUG)).not.toBe(null);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('refuses a second account that would fight over the same connector', () => {
|
|
167
|
+
integrationAccounts.connect({ provider: 'firecrawl', credentials: { apiKey: 'fc-one' } });
|
|
168
|
+
|
|
169
|
+
expect(() => integrationAccounts.connect({
|
|
170
|
+
provider: 'firecrawl',
|
|
171
|
+
label: 'Firecrawl (second org)',
|
|
172
|
+
credentials: { apiKey: 'fc-two' }
|
|
173
|
+
})).toThrow();
|
|
174
|
+
|
|
175
|
+
// The rejected account must not be left behind half-connected.
|
|
176
|
+
expect(integrationAccountQueries.getByProvider('firecrawl').length).toBe(1);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('rejects a connect that is missing a required credential', () => {
|
|
180
|
+
expect(() => integrationAccounts.connect({
|
|
181
|
+
provider: 'firecrawl',
|
|
182
|
+
credentials: {}
|
|
183
|
+
})).toThrow();
|
|
184
|
+
expect(mcpServerQueries.getBySlug(FIRECRAWL_SLUG)).toBe(null);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('stores the credential sealed and never returns it to the caller', () => {
|
|
188
|
+
const account = integrationAccounts.connect({
|
|
189
|
+
provider: 'context7',
|
|
190
|
+
credentials: { apiKey: 'ctx7sk-secret' }
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// The account DTO reports which fields are set, not what they are set to.
|
|
194
|
+
expect(account.configuredFields).toEqual(['apiKey']);
|
|
195
|
+
expect(JSON.stringify(account)).not.toContain('ctx7sk-secret');
|
|
196
|
+
|
|
197
|
+
const row = mcpServerQueries.getBySlug('context7');
|
|
198
|
+
expect(row).not.toBe(null);
|
|
199
|
+
expect(JSON.parse(row!.headers).CONTEXT7_API_KEY).toBe('ctx7sk-secret');
|
|
200
|
+
|
|
201
|
+
integrationAccounts.disconnect(account.id);
|
|
202
|
+
mcpServerQueries.getBySlug('context7') && mcpServerQueries.remove(mcpServerQueries.getBySlug('context7')!.id);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `agent-tools` projector: an account with agent tools owns one
|
|
3
|
+
* `mcp_servers` row.
|
|
4
|
+
*
|
|
5
|
+
* It returns a single-element list because the contract is plural, not because
|
|
6
|
+
* there is a second row coming: a preset names ONE slug, so an account either
|
|
7
|
+
* owns that row or owns nothing.
|
|
8
|
+
*
|
|
9
|
+
* Nothing downstream of this row knows accounts exist. `resolveServerRow()`,
|
|
10
|
+
* every per-engine config builder and the `/mcp/ext/<slug>` proxy read the row
|
|
11
|
+
* exactly as they read a hand-installed one — which is the whole point of
|
|
12
|
+
* keeping this layer off the path MCP config already flows through.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { mcpServerQueries, integrationProjectionQueries } from '$backend/database/queries';
|
|
16
|
+
import type { McpServerRow } from '$backend/database/queries';
|
|
17
|
+
import type { McpPreset } from '../registry';
|
|
18
|
+
import type { Projector, ProjectionContext, ProjectionResult } from './types';
|
|
19
|
+
import { debug } from '$shared/utils/logger';
|
|
20
|
+
|
|
21
|
+
/** Snapshot of the credential-bearing fields, taken before an adopted row is written. */
|
|
22
|
+
interface McpRestoreSnapshot {
|
|
23
|
+
env: Record<string, string>;
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parseMap(raw: string | null): Record<string, string> {
|
|
28
|
+
if (!raw) return {};
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(raw);
|
|
31
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
32
|
+
? (parsed as Record<string, string>)
|
|
33
|
+
: {};
|
|
34
|
+
} catch {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Map the stored credential onto the env vars the upstream server expects,
|
|
41
|
+
* keeping any keys already on the row.
|
|
42
|
+
*
|
|
43
|
+
* Merging rather than replacing matters for adoption: a user who installed this
|
|
44
|
+
* server by hand may have set env vars the preset says nothing about, and
|
|
45
|
+
* connecting an account must not silently drop them.
|
|
46
|
+
*/
|
|
47
|
+
function buildEnv(preset: McpPreset, credentials: Record<string, string>, existing: Record<string, string>): Record<string, string> {
|
|
48
|
+
const env = { ...existing, ...(preset.staticEnv ?? {}) };
|
|
49
|
+
for (const [field, variable] of Object.entries(preset.env ?? {})) {
|
|
50
|
+
const value = credentials[field];
|
|
51
|
+
if (value) env[variable] = value;
|
|
52
|
+
}
|
|
53
|
+
return env;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Same, for the remote path. `format` wraps the value, `Bearer {value}` being the usual case. */
|
|
57
|
+
function buildHeaders(preset: McpPreset, credentials: Record<string, string>, existing: Record<string, string>): Record<string, string> {
|
|
58
|
+
const headers = { ...existing, ...(preset.staticHeaders ?? {}) };
|
|
59
|
+
for (const [field, spec] of Object.entries(preset.headers ?? {})) {
|
|
60
|
+
const value = credentials[field];
|
|
61
|
+
if (!value) continue;
|
|
62
|
+
headers[spec.name] = spec.format ? spec.format.replace('{value}', value) : value;
|
|
63
|
+
}
|
|
64
|
+
return headers;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function presetOf(context: ProjectionContext): McpPreset {
|
|
68
|
+
const preset = context.provider.mcp;
|
|
69
|
+
if (!preset) {
|
|
70
|
+
throw new Error(`Provider "${context.provider.id}" offers agent tools but declares no MCP preset`);
|
|
71
|
+
}
|
|
72
|
+
return preset;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const mcpProjector: Projector = {
|
|
76
|
+
capability: 'agent-tools',
|
|
77
|
+
targetKind: 'mcp_server',
|
|
78
|
+
|
|
79
|
+
project(context: ProjectionContext): ProjectionResult[] {
|
|
80
|
+
const preset = presetOf(context);
|
|
81
|
+
const existing: McpServerRow | null = mcpServerQueries.getBySlug(preset.slug);
|
|
82
|
+
|
|
83
|
+
if (!existing) {
|
|
84
|
+
const row = mcpServerQueries.insert({
|
|
85
|
+
slug: preset.slug,
|
|
86
|
+
name: preset.name,
|
|
87
|
+
description: preset.description,
|
|
88
|
+
transport: preset.transport,
|
|
89
|
+
command: preset.command ?? null,
|
|
90
|
+
args: preset.args ?? [],
|
|
91
|
+
url: preset.url ?? null,
|
|
92
|
+
env: buildEnv(preset, context.credentials, {}),
|
|
93
|
+
headers: buildHeaders(preset, context.credentials, {}),
|
|
94
|
+
// Registry-installed vs hand-written is a provenance question about
|
|
95
|
+
// the CONFIG. Ownership by an account is a different question, and
|
|
96
|
+
// `integration_projections` is where it is answered — so this stays
|
|
97
|
+
// an ordinary custom row rather than needing a fourth source value.
|
|
98
|
+
source: 'custom'
|
|
99
|
+
});
|
|
100
|
+
return [{ targetKind: 'mcp_server', targetId: String(row.id), adopted: false, restore: null }];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ADOPT rather than create a sibling. A user who installed this server by
|
|
104
|
+
// hand before the provider existed must end up with ONE entry.
|
|
105
|
+
const targetId = String(existing.id);
|
|
106
|
+
const prior = integrationProjectionQueries.getByTarget('mcp_server', targetId);
|
|
107
|
+
|
|
108
|
+
if (prior && prior.account_id !== context.account.id) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`The "${preset.slug}" connector is already managed by another connected account. ` +
|
|
111
|
+
`Disconnect that one first.`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Re-projecting a row we already own must not re-snapshot it — the second
|
|
116
|
+
// snapshot would capture OUR credential, and release would then "restore"
|
|
117
|
+
// the user's row to the token we are about to delete.
|
|
118
|
+
const adopted = prior ? prior.adopted === 1 : true;
|
|
119
|
+
const restore = prior
|
|
120
|
+
? integrationProjectionQueries.restoreOf<McpRestoreSnapshot>(prior)
|
|
121
|
+
: ({ env: parseMap(existing.env), headers: parseMap(existing.headers) } satisfies McpRestoreSnapshot);
|
|
122
|
+
|
|
123
|
+
if (!prior) {
|
|
124
|
+
debug.log('integrations', `Adopting existing MCP server "${preset.slug}" for ${context.provider.id}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
mcpServerQueries.updateConfig(
|
|
128
|
+
existing.id,
|
|
129
|
+
buildEnv(preset, context.credentials, parseMap(existing.env)),
|
|
130
|
+
buildHeaders(preset, context.credentials, parseMap(existing.headers))
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
// Only a row we created gets its transport-level config rewritten. On an
|
|
134
|
+
// adopted row the user's command, args and URL are theirs, and a preset
|
|
135
|
+
// that thinks it knows better would break a working server.
|
|
136
|
+
if (!adopted) {
|
|
137
|
+
if (preset.transport === 'stdio' && preset.command) {
|
|
138
|
+
mcpServerQueries.updateCommand(existing.id, preset.command, preset.args ?? []);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return [{ targetKind: 'mcp_server', targetId, adopted, restore }];
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
release(context: ProjectionContext, targetId: string, adopted: boolean, restore: unknown | null): void {
|
|
146
|
+
const id = Number(targetId);
|
|
147
|
+
if (!Number.isFinite(id)) return;
|
|
148
|
+
|
|
149
|
+
if (!adopted) {
|
|
150
|
+
mcpServerQueries.remove(id);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// The row was the user's before it was ours. Put back exactly what we
|
|
155
|
+
// found, so what is left behind is their server, not a husk pointing at a
|
|
156
|
+
// credential that no longer exists.
|
|
157
|
+
const snapshot = (restore ?? { env: {}, headers: {} }) as McpRestoreSnapshot;
|
|
158
|
+
if (mcpServerQueries.getById(id)) {
|
|
159
|
+
mcpServerQueries.updateConfig(id, snapshot.env ?? {}, snapshot.headers ?? {});
|
|
160
|
+
debug.log('integrations', `Released adopted MCP server ${id} back to the user (${context.provider.id})`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Projector contract.
|
|
3
|
+
*
|
|
4
|
+
* A projection is a row on another surface DERIVED from an account. Surfaces
|
|
5
|
+
* never learn that accounts exist: they keep reading their own tables, and a
|
|
6
|
+
* projector is the only thing that writes an integration-owned row into them.
|
|
7
|
+
*
|
|
8
|
+
* One projector per capability — but ONLY for capabilities whose surface owns a
|
|
9
|
+
* table to write into. `agent-tools` writes an `mcp_servers` row, `database`
|
|
10
|
+
* writes `db_client_connections` ones, and `worktree-branching` and
|
|
11
|
+
* `notifications` are registered by the tasks that build those surfaces.
|
|
12
|
+
*
|
|
13
|
+
* A projector returns a LIST. Agent tools happens to produce exactly one row
|
|
14
|
+
* per account, but that is a fact about MCP presets rather than about
|
|
15
|
+
* projection: one database credential reaches every project the token can see,
|
|
16
|
+
* and the user picks as many of them as they want (see migration 077).
|
|
17
|
+
*
|
|
18
|
+
* `work` and `deployments` deliberately have NO projector. Work items are never copied into the
|
|
19
|
+
* database (see migration 074 for why), so there is no derived row to keep in
|
|
20
|
+
* step — the Issues & PRs surface registers an ADAPTER in
|
|
21
|
+
* `backend/work/registry.ts` and reads the account directly, and Deployments
|
|
22
|
+
* does the same in `backend/deployments/registry.ts`. A capability without a
|
|
23
|
+
* table is a capability without a projection.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { IntegrationCapability, IntegrationTargetKind } from '$shared/types/integrations';
|
|
27
|
+
import type { IntegrationAccountRow } from '$backend/database/queries';
|
|
28
|
+
import type { IntegrationProvider } from '../registry';
|
|
29
|
+
|
|
30
|
+
export interface ProjectionContext {
|
|
31
|
+
account: IntegrationAccountRow;
|
|
32
|
+
provider: IntegrationProvider;
|
|
33
|
+
/** Decoded credentials. Empty when the active key could not open them. */
|
|
34
|
+
credentials: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ProjectionResult {
|
|
38
|
+
targetKind: IntegrationTargetKind;
|
|
39
|
+
targetId: string;
|
|
40
|
+
/**
|
|
41
|
+
* True when the projection took over a row that already existed and was not
|
|
42
|
+
* created by us. Releasing an adopted row restores it instead of deleting it.
|
|
43
|
+
*/
|
|
44
|
+
adopted: boolean;
|
|
45
|
+
/** Snapshot of the adopted row, stored so release can put it back. */
|
|
46
|
+
restore: unknown | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface Projector {
|
|
50
|
+
capability: IntegrationCapability;
|
|
51
|
+
targetKind: IntegrationTargetKind;
|
|
52
|
+
/**
|
|
53
|
+
* Create or refresh every derived row this account should own right now.
|
|
54
|
+
*
|
|
55
|
+
* Called on connect, credential change and capability enable. Anything the
|
|
56
|
+
* account previously projected that is NOT in the returned list gets
|
|
57
|
+
* released, so removing a link and disabling a capability are the same
|
|
58
|
+
* operation as far as the pass is concerned.
|
|
59
|
+
*/
|
|
60
|
+
project(context: ProjectionContext): ProjectionResult[];
|
|
61
|
+
/** Remove one derived row, or hand an adopted one back untouched. */
|
|
62
|
+
release(context: ProjectionContext, targetId: string, adopted: boolean, restore: unknown | null): void;
|
|
63
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `defineProvider()` lives in its own module so a provider file can import it
|
|
3
|
+
* without importing the registry that imports the provider file. The cycle
|
|
4
|
+
* would resolve today thanks to hoisting, but it is the kind of thing that
|
|
5
|
+
* breaks silently the moment someone adds a top-level const to the registry.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { IntegrationProvider } from './types';
|
|
9
|
+
|
|
10
|
+
const SLUG_PATTERN = /^[a-z0-9-]+$/;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Validate a provider at module load.
|
|
14
|
+
*
|
|
15
|
+
* These are declaration mistakes, not runtime conditions, so failing loudly at
|
|
16
|
+
* import is right: a provider that claims `agent-tools` without a preset would
|
|
17
|
+
* otherwise present a working connect dialog that silently projects nothing.
|
|
18
|
+
*/
|
|
19
|
+
export function defineProvider(provider: IntegrationProvider): IntegrationProvider {
|
|
20
|
+
if (!SLUG_PATTERN.test(provider.id)) {
|
|
21
|
+
throw new Error(`Integration provider id "${provider.id}" must match ${SLUG_PATTERN}`);
|
|
22
|
+
}
|
|
23
|
+
if (provider.capabilities.includes('agent-tools') && !provider.mcp) {
|
|
24
|
+
throw new Error(`Integration provider "${provider.id}" offers agent-tools but declares no MCP preset`);
|
|
25
|
+
}
|
|
26
|
+
if (provider.mcp && !SLUG_PATTERN.test(provider.mcp.slug)) {
|
|
27
|
+
throw new Error(`Integration provider "${provider.id}" has an invalid MCP preset slug`);
|
|
28
|
+
}
|
|
29
|
+
if (provider.capabilities.includes('inbound-events') && !provider.webhook) {
|
|
30
|
+
throw new Error(`Integration provider "${provider.id}" accepts inbound events but declares no webhook spec`);
|
|
31
|
+
}
|
|
32
|
+
for (const capability of provider.defaultCapabilities ?? []) {
|
|
33
|
+
if (!provider.capabilities.includes(capability)) {
|
|
34
|
+
throw new Error(`Integration provider "${provider.id}" defaults to a capability it does not offer: ${capability}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return provider;
|
|
38
|
+
}
|