@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,458 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Deployments surface, provider-agnostic.
|
|
3
|
+
*
|
|
4
|
+
* Every route in `backend/ws/deployments/` goes through here, and nothing here
|
|
5
|
+
* mentions Vercel. The service resolves which connected accounts can serve the
|
|
6
|
+
* current project, assembles the adapter context (account + decoded credential
|
|
7
|
+
* + binding), and hands the call on.
|
|
8
|
+
*
|
|
9
|
+
* The credential is decoded HERE and dies here. No function in this file
|
|
10
|
+
* returns it, and the shapes the routes serialise (`DeploySource`,
|
|
11
|
+
* `Deployment`) have nowhere to put it.
|
|
12
|
+
*
|
|
13
|
+
* Outward-facing actions go through `runAction`, which is the single place that
|
|
14
|
+
* checks a capability before calling a provider. A route that called
|
|
15
|
+
* `adapter.promote` directly would work for Vercel and crash for the first
|
|
16
|
+
* provider that does not have one.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
deployBindingQueries,
|
|
21
|
+
integrationAccountQueries,
|
|
22
|
+
parseDeployConfig,
|
|
23
|
+
type IntegrationAccountRow
|
|
24
|
+
} from '$backend/database/queries';
|
|
25
|
+
import { getProvider } from '$backend/integrations';
|
|
26
|
+
import type {
|
|
27
|
+
BuildLogBundle,
|
|
28
|
+
DeployAction,
|
|
29
|
+
DeployActionResult,
|
|
30
|
+
DeployBindingConfig,
|
|
31
|
+
Deployment,
|
|
32
|
+
DeploymentDetail,
|
|
33
|
+
DeploymentDraft,
|
|
34
|
+
DeploymentPage,
|
|
35
|
+
DeployProjectStatus,
|
|
36
|
+
DeploySource,
|
|
37
|
+
DeployTarget,
|
|
38
|
+
NewProjectDraft
|
|
39
|
+
} from '$shared/types/deployments';
|
|
40
|
+
import { getDeployAdapter } from './registry';
|
|
41
|
+
import {
|
|
42
|
+
readDeployBinding,
|
|
43
|
+
resolveDeployBinding,
|
|
44
|
+
suggestTargets,
|
|
45
|
+
toDeployBindingInfo
|
|
46
|
+
} from './bindings';
|
|
47
|
+
import type {
|
|
48
|
+
AdapterDeployInfo,
|
|
49
|
+
DeployContext,
|
|
50
|
+
DeploymentQuery,
|
|
51
|
+
DeployProviderAdapter,
|
|
52
|
+
RepositoryAccess
|
|
53
|
+
} from './types';
|
|
54
|
+
import { debug } from '$shared/utils/logger';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Accounts that can serve deployments here.
|
|
58
|
+
*
|
|
59
|
+
* Three filters, in order of what they mean: the account offers `deployments`,
|
|
60
|
+
* it is switched on, and there is code registered that knows how to talk to it.
|
|
61
|
+
* The third is why a provider declaring the capability before its adapter
|
|
62
|
+
* exists is harmless — it simply does not appear.
|
|
63
|
+
*/
|
|
64
|
+
function accountsFor(projectId: string): { account: IntegrationAccountRow; adapter: DeployProviderAdapter }[] {
|
|
65
|
+
return integrationAccountQueries
|
|
66
|
+
.getAll()
|
|
67
|
+
.filter((account) => account.is_enabled === 1)
|
|
68
|
+
.filter((account) => integrationAccountQueries.capabilitiesOf(account).includes('deployments'))
|
|
69
|
+
// A project-bound account belongs to that project alone; a null binding
|
|
70
|
+
// means "available everywhere". Same rule the webhook gateway uses.
|
|
71
|
+
.filter((account) => account.project_id === null || account.project_id === projectId)
|
|
72
|
+
.flatMap((account) => {
|
|
73
|
+
const adapter = getDeployAdapter(account.provider);
|
|
74
|
+
return adapter ? [{ account, adapter }] : [];
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const deployService = {
|
|
79
|
+
/**
|
|
80
|
+
* Every source the panel can show, with its binding already resolved.
|
|
81
|
+
*
|
|
82
|
+
* Detection runs here, which is why this is async: opening the panel on a
|
|
83
|
+
* project that has never been bound is the moment we have both the account
|
|
84
|
+
* and the working tree in hand, and asking the user to bind manually at that
|
|
85
|
+
* point would be asking them to retype a file already in their repository.
|
|
86
|
+
*/
|
|
87
|
+
async listSources(projectId: string, projectRoot: string): Promise<DeploySource[]> {
|
|
88
|
+
const sources: DeploySource[] = [];
|
|
89
|
+
|
|
90
|
+
for (const { account, adapter } of accountsFor(projectId)) {
|
|
91
|
+
const provider = getProvider(account.provider);
|
|
92
|
+
const credentials = integrationAccountQueries.credentialsOf(account);
|
|
93
|
+
|
|
94
|
+
let binding = readDeployBinding(projectId, account.id);
|
|
95
|
+
if (!binding) {
|
|
96
|
+
try {
|
|
97
|
+
binding = await resolveDeployBinding(adapter, account, projectId, projectRoot);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
debug.warn('deployments', `Binding detection failed for ${account.provider}:`, error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Only offered when there is nothing bound yet. Listing every project
|
|
104
|
+
// in every team is several requests, and spending them to populate a
|
|
105
|
+
// picker nobody opened is the kind of cost that shows up as a rate
|
|
106
|
+
// limit during someone else's build.
|
|
107
|
+
const suggested = binding
|
|
108
|
+
? []
|
|
109
|
+
: await suggestTargets(adapter, { projectId, account, credentials }, projectRoot).catch((error) => {
|
|
110
|
+
debug.warn('deployments', 'Could not list deploy targets:', error);
|
|
111
|
+
return [] as DeployTarget[];
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
sources.push({
|
|
115
|
+
accountId: account.id,
|
|
116
|
+
provider: account.provider,
|
|
117
|
+
providerName: provider?.name ?? account.provider,
|
|
118
|
+
label: account.label,
|
|
119
|
+
// Resolved once per source: every view that wants to say whose
|
|
120
|
+
// account this is would otherwise ask again.
|
|
121
|
+
viewer: adapter.viewer
|
|
122
|
+
? await adapter.viewer({ projectId, account, credentials }).catch(() => null)
|
|
123
|
+
: null,
|
|
124
|
+
capabilities: adapter.capabilities,
|
|
125
|
+
binding: toDeployBindingInfo(binding),
|
|
126
|
+
suggestedTargets: suggested,
|
|
127
|
+
status: account.status,
|
|
128
|
+
statusDetail: account.status_detail
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return sources;
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Adapter + context for one account, or a clear error.
|
|
137
|
+
*
|
|
138
|
+
* "Not bound" is separated from "not connected" because they need different
|
|
139
|
+
* answers: one is a project picker, the other is a connect dialog.
|
|
140
|
+
*/
|
|
141
|
+
require(projectId: string, accountId: string): { adapter: DeployProviderAdapter; context: DeployContext } {
|
|
142
|
+
const account = integrationAccountQueries.getById(accountId);
|
|
143
|
+
if (!account) throw new Error('That integration account is no longer connected');
|
|
144
|
+
if (account.is_enabled !== 1) {
|
|
145
|
+
throw new Error(`${account.label} is switched off in Settings → Integrations`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const adapter = getDeployAdapter(account.provider);
|
|
149
|
+
if (!adapter) throw new Error(`No deployment provider is registered for ${account.provider}`);
|
|
150
|
+
|
|
151
|
+
const binding = readDeployBinding(projectId, account.id);
|
|
152
|
+
if (!binding) {
|
|
153
|
+
throw new Error('This project is not pointed at a deployment project yet — pick one first.');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
adapter,
|
|
158
|
+
context: {
|
|
159
|
+
projectId,
|
|
160
|
+
account,
|
|
161
|
+
credentials: integrationAccountQueries.credentialsOf(account),
|
|
162
|
+
binding
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
/** Targets for the picker, listed on demand rather than with every source. */
|
|
168
|
+
async listTargets(projectId: string, accountId: string, projectRoot: string): Promise<DeployTarget[]> {
|
|
169
|
+
const account = integrationAccountQueries.getById(accountId);
|
|
170
|
+
if (!account) throw new Error('That integration account is no longer connected');
|
|
171
|
+
|
|
172
|
+
const adapter = getDeployAdapter(account.provider);
|
|
173
|
+
if (!adapter) throw new Error(`No deployment provider is registered for ${account.provider}`);
|
|
174
|
+
|
|
175
|
+
return suggestTargets(
|
|
176
|
+
adapter,
|
|
177
|
+
{ projectId, account, credentials: integrationAccountQueries.credentialsOf(account) },
|
|
178
|
+
projectRoot
|
|
179
|
+
);
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
list(projectId: string, accountId: string, query: DeploymentQuery): Promise<DeploymentPage> {
|
|
183
|
+
const { adapter, context } = this.require(projectId, accountId);
|
|
184
|
+
return adapter.list(context, query);
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
get(projectId: string, accountId: string, id: string): Promise<DeploymentDetail> {
|
|
188
|
+
const { adapter, context } = this.require(projectId, accountId);
|
|
189
|
+
return adapter.get(context, id);
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
currentProduction(projectId: string, accountId: string): Promise<Deployment | null> {
|
|
193
|
+
const { adapter, context } = this.require(projectId, accountId);
|
|
194
|
+
if (!adapter.currentProduction) return Promise.resolve(null);
|
|
195
|
+
return adapter.currentProduction(context);
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
fetchLogs(projectId: string, accountId: string, id: string): Promise<BuildLogBundle> {
|
|
199
|
+
const { adapter, context } = this.require(projectId, accountId);
|
|
200
|
+
if (!adapter.capabilities.logs || !adapter.fetchLogs) {
|
|
201
|
+
throw new Error(`${context.account.label} does not expose build logs`);
|
|
202
|
+
}
|
|
203
|
+
return adapter.fetchLogs(context, id);
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Run one outward-facing action.
|
|
208
|
+
*
|
|
209
|
+
* The capability check lives here rather than in the route so every entry
|
|
210
|
+
* point inherits it, and the error names the provider rather than the
|
|
211
|
+
* method: "Coolify cannot promote a deployment" is actionable, while
|
|
212
|
+
* "adapter.promote is not a function" is a bug report.
|
|
213
|
+
*/
|
|
214
|
+
async runAction(
|
|
215
|
+
projectId: string,
|
|
216
|
+
accountId: string,
|
|
217
|
+
action: DeployAction,
|
|
218
|
+
id: string
|
|
219
|
+
): Promise<DeployActionResult> {
|
|
220
|
+
const { adapter, context } = this.require(projectId, accountId);
|
|
221
|
+
const label = context.account.label;
|
|
222
|
+
|
|
223
|
+
switch (action) {
|
|
224
|
+
case 'redeploy': {
|
|
225
|
+
if (!adapter.capabilities.redeploy || !adapter.redeploy) {
|
|
226
|
+
throw new Error(`${label} cannot redeploy a build`);
|
|
227
|
+
}
|
|
228
|
+
const result = await adapter.redeploy(context, id);
|
|
229
|
+
return { action, status: 'done', deploymentId: result.deploymentId, message: result.message };
|
|
230
|
+
}
|
|
231
|
+
case 'cancel': {
|
|
232
|
+
if (!adapter.capabilities.cancel || !adapter.cancel) {
|
|
233
|
+
throw new Error(`${label} cannot cancel a build`);
|
|
234
|
+
}
|
|
235
|
+
const result = await adapter.cancel(context, id);
|
|
236
|
+
return { action, status: 'done', deploymentId: null, message: result.message };
|
|
237
|
+
}
|
|
238
|
+
case 'rollback': {
|
|
239
|
+
if (!adapter.capabilities.rollback || !adapter.rollback) {
|
|
240
|
+
throw new Error(`${label} cannot roll back a deployment`);
|
|
241
|
+
}
|
|
242
|
+
const result = await adapter.rollback(context, id);
|
|
243
|
+
return { action, status: result.status, deploymentId: null, message: result.message };
|
|
244
|
+
}
|
|
245
|
+
case 'promote': {
|
|
246
|
+
if (!adapter.capabilities.promote || !adapter.promote) {
|
|
247
|
+
throw new Error(`${label} cannot promote a deployment`);
|
|
248
|
+
}
|
|
249
|
+
const result = await adapter.promote(context, id);
|
|
250
|
+
return { action, status: result.status, deploymentId: null, message: result.message };
|
|
251
|
+
}
|
|
252
|
+
case 'delete': {
|
|
253
|
+
if (!adapter.capabilities.deleteDeployment || !adapter.deleteDeployment) {
|
|
254
|
+
throw new Error(`${label} cannot delete a deployment`);
|
|
255
|
+
}
|
|
256
|
+
const result = await adapter.deleteDeployment(context, id);
|
|
257
|
+
return { action, status: 'done', deploymentId: null, message: result.message };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
/** Project-level state, including a traffic move still in flight. */
|
|
263
|
+
async projectStatus(projectId: string, accountId: string): Promise<DeployProjectStatus> {
|
|
264
|
+
const { adapter, context } = this.require(projectId, accountId);
|
|
265
|
+
if (!adapter.projectStatus) return { paused: false, aliasRequest: null };
|
|
266
|
+
return adapter.projectStatus(context);
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
/** What the deploy dialog needs before it opens. */
|
|
270
|
+
deployInfo(projectId: string, accountId: string): Promise<AdapterDeployInfo> {
|
|
271
|
+
const { adapter, context } = this.require(projectId, accountId);
|
|
272
|
+
if (!adapter.capabilities.createDeployment || !adapter.deployInfo) {
|
|
273
|
+
return Promise.resolve({
|
|
274
|
+
gitRepo: null,
|
|
275
|
+
productionBranch: null,
|
|
276
|
+
canDeploy: false,
|
|
277
|
+
reason: `${context.account.label} cannot start a build from here.`
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return adapter.deployInfo(context);
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Start a new build.
|
|
285
|
+
*
|
|
286
|
+
* Kept out of `runAction` because it does not act on an existing deployment
|
|
287
|
+
* — it takes a branch and an environment, and the one thing a project that
|
|
288
|
+
* has never been deployed does not have is a deployment to act on.
|
|
289
|
+
*/
|
|
290
|
+
async createDeployment(
|
|
291
|
+
projectId: string,
|
|
292
|
+
accountId: string,
|
|
293
|
+
draft: DeploymentDraft
|
|
294
|
+
): Promise<DeployActionResult> {
|
|
295
|
+
const { adapter, context } = this.require(projectId, accountId);
|
|
296
|
+
if (!adapter.capabilities.createDeployment || !adapter.createDeployment) {
|
|
297
|
+
throw new Error(`${context.account.label} cannot start a build`);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const ref = draft.ref.trim();
|
|
301
|
+
if (!ref) throw new Error('Pick a branch to build from');
|
|
302
|
+
|
|
303
|
+
const result = await adapter.createDeployment(context, { ref, production: draft.production });
|
|
304
|
+
return {
|
|
305
|
+
action: 'redeploy',
|
|
306
|
+
status: 'done',
|
|
307
|
+
deploymentId: result.deploymentId,
|
|
308
|
+
message: result.message
|
|
309
|
+
};
|
|
310
|
+
},
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Create a remote project and point this one at it.
|
|
314
|
+
*
|
|
315
|
+
* Binding straight away is the point: a user who just created a project for
|
|
316
|
+
* this repository has already answered "which project is this", and making
|
|
317
|
+
* them answer it again in a picker is the setup step that makes an
|
|
318
|
+
* integration feel like homework.
|
|
319
|
+
*/
|
|
320
|
+
async createProject(
|
|
321
|
+
projectId: string,
|
|
322
|
+
accountId: string,
|
|
323
|
+
draft: NewProjectDraft
|
|
324
|
+
): Promise<DeployTarget> {
|
|
325
|
+
const account = integrationAccountQueries.getById(accountId);
|
|
326
|
+
if (!account) throw new Error('That integration account is no longer connected');
|
|
327
|
+
|
|
328
|
+
const adapter = getDeployAdapter(account.provider);
|
|
329
|
+
if (!adapter) throw new Error(`No deployment provider is registered for ${account.provider}`);
|
|
330
|
+
if (!adapter.capabilities.createProject || !adapter.createProject) {
|
|
331
|
+
throw new Error(`${account.label} cannot create a project`);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const name = draft.name.trim();
|
|
335
|
+
if (!name) throw new Error('Give the project a name');
|
|
336
|
+
|
|
337
|
+
const credentials = integrationAccountQueries.credentialsOf(account);
|
|
338
|
+
const target = await adapter.createProject({ projectId, account, credentials }, { ...draft, name });
|
|
339
|
+
|
|
340
|
+
deployBindingQueries.upsert({
|
|
341
|
+
projectId,
|
|
342
|
+
accountId,
|
|
343
|
+
locator: target.id,
|
|
344
|
+
displayName: target.name,
|
|
345
|
+
teamId: target.teamId,
|
|
346
|
+
detected: false,
|
|
347
|
+
config: parseDeployConfig(deployBindingQueries.get(projectId, accountId)?.config_json ?? null)
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
return target;
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
/** Whether a repository could be attached, and what to do when it cannot. */
|
|
354
|
+
async repositoryAccess(projectId: string, accountId: string, gitRepo: string): Promise<RepositoryAccess> {
|
|
355
|
+
const account = integrationAccountQueries.getById(accountId);
|
|
356
|
+
if (!account) throw new Error('That integration account is no longer connected');
|
|
357
|
+
|
|
358
|
+
const adapter = getDeployAdapter(account.provider);
|
|
359
|
+
// UNBOUND on purpose: this reads a property of the account, and the
|
|
360
|
+
// new-project form needs the answer before any project exists to bind to.
|
|
361
|
+
if (!adapter?.capabilities.connectRepository || !adapter.repositoryAccess) {
|
|
362
|
+
return {
|
|
363
|
+
state: 'blocked',
|
|
364
|
+
reason: `${account.label} cannot attach a repository to a project.`,
|
|
365
|
+
actionUrl: null
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return adapter.repositoryAccess(
|
|
370
|
+
{ projectId, account, credentials: integrationAccountQueries.credentialsOf(account) },
|
|
371
|
+
gitRepo
|
|
372
|
+
);
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Attach a git repository to the bound remote project.
|
|
377
|
+
*
|
|
378
|
+
* The way out of the one dead end this surface has: a remote project with no
|
|
379
|
+
* repository cannot be built from at all, and previously the only answer was
|
|
380
|
+
* "go to the provider's dashboard".
|
|
381
|
+
*/
|
|
382
|
+
async connectRepository(
|
|
383
|
+
projectId: string,
|
|
384
|
+
accountId: string,
|
|
385
|
+
repo: { gitRepo: string; gitProvider: string }
|
|
386
|
+
): Promise<void> {
|
|
387
|
+
const { adapter, context } = this.require(projectId, accountId);
|
|
388
|
+
if (!adapter.capabilities.connectRepository || !adapter.connectRepository) {
|
|
389
|
+
throw new Error(`${context.account.label} cannot attach a repository to an existing project`);
|
|
390
|
+
}
|
|
391
|
+
if (!repo.gitRepo.trim()) throw new Error('Name the repository to connect');
|
|
392
|
+
|
|
393
|
+
await adapter.connectRepository(context, {
|
|
394
|
+
gitRepo: repo.gitRepo.trim(),
|
|
395
|
+
gitProvider: repo.gitProvider || 'github'
|
|
396
|
+
});
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
/** Point this project at a different remote project. */
|
|
400
|
+
async setBinding(
|
|
401
|
+
projectId: string,
|
|
402
|
+
accountId: string,
|
|
403
|
+
locator: string,
|
|
404
|
+
teamId: string | null
|
|
405
|
+
): Promise<void> {
|
|
406
|
+
const account = integrationAccountQueries.getById(accountId);
|
|
407
|
+
if (!account) throw new Error('That integration account is no longer connected');
|
|
408
|
+
|
|
409
|
+
const adapter = getDeployAdapter(account.provider);
|
|
410
|
+
if (!adapter) throw new Error(`No deployment provider is registered for ${account.provider}`);
|
|
411
|
+
|
|
412
|
+
const credentials = integrationAccountQueries.credentialsOf(account);
|
|
413
|
+
const described = await adapter
|
|
414
|
+
.describeTarget({ projectId, account, credentials }, locator, teamId)
|
|
415
|
+
.catch(() => null);
|
|
416
|
+
|
|
417
|
+
const existing = deployBindingQueries.get(projectId, accountId);
|
|
418
|
+
deployBindingQueries.upsert({
|
|
419
|
+
projectId,
|
|
420
|
+
accountId,
|
|
421
|
+
locator,
|
|
422
|
+
displayName: described?.name ?? locator,
|
|
423
|
+
teamId,
|
|
424
|
+
// Chosen, not detected — the distinction is what lets the binding bar
|
|
425
|
+
// say "from your linked project" only when that is actually true.
|
|
426
|
+
detected: false,
|
|
427
|
+
config: parseDeployConfig(existing?.config_json ?? null)
|
|
428
|
+
});
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
setConfig(projectId: string, accountId: string, config: DeployBindingConfig): void {
|
|
432
|
+
if (!deployBindingQueries.get(projectId, accountId)) {
|
|
433
|
+
throw new Error('This project is not pointed at a deployment project yet');
|
|
434
|
+
}
|
|
435
|
+
deployBindingQueries.setConfig(projectId, accountId, config);
|
|
436
|
+
},
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Health for the hub.
|
|
440
|
+
*
|
|
441
|
+
* Returns null when this account has nothing to say — a Vercel account with
|
|
442
|
+
* `deployments` switched off — so the hub falls back to the MCP probe rather
|
|
443
|
+
* than reporting a state this surface never measured.
|
|
444
|
+
*/
|
|
445
|
+
async probe(accountId: string, projectId: string | null) {
|
|
446
|
+
const account = integrationAccountQueries.getById(accountId);
|
|
447
|
+
if (!account) return null;
|
|
448
|
+
if (!integrationAccountQueries.capabilitiesOf(account).includes('deployments')) return null;
|
|
449
|
+
|
|
450
|
+
const adapter = getDeployAdapter(account.provider);
|
|
451
|
+
if (!adapter) return null;
|
|
452
|
+
|
|
453
|
+
const credentials = integrationAccountQueries.credentialsOf(account);
|
|
454
|
+
const binding = projectId ? readDeployBinding(projectId, accountId) : null;
|
|
455
|
+
|
|
456
|
+
return adapter.probe({ projectId: projectId ?? '', account, credentials }, binding);
|
|
457
|
+
}
|
|
458
|
+
};
|