@stage-labs/metro 0.1.0-beta.50 → 0.1.0-beta.52

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.
Files changed (51) hide show
  1. package/dist/api.js +8 -142
  2. package/dist/cli.js +27 -131
  3. package/dist/control.js +5 -104
  4. package/dist/plugin.js +2 -4
  5. package/dist/runtime.js +18 -72
  6. package/dist/serve.js +3 -2
  7. package/dist/tail.js +7 -8
  8. package/dist/update.js +13 -1
  9. package/package.json +1 -1
  10. package/runtime/node_modules/@metro-labs/mcp/package.json +1 -2
  11. package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-api.ts +3 -35
  12. package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-connector-api.ts +7 -22
  13. package/runtime/node_modules/@metro-labs/mcp/src/daemon/api-http.ts +4 -54
  14. package/runtime/node_modules/@metro-labs/mcp/src/daemon/attach-serve.ts +1 -2
  15. package/runtime/node_modules/@metro-labs/mcp/src/daemon/boot.ts +29 -208
  16. package/runtime/node_modules/@metro-labs/mcp/src/daemon/connector-api.ts +0 -4
  17. package/runtime/node_modules/@metro-labs/mcp/src/daemon/local-mode.ts +2 -37
  18. package/runtime/node_modules/@metro-labs/mcp/src/daemon/paths.ts +0 -3
  19. package/runtime/node_modules/@metro-labs/mcp/src/daemon/relay.ts +4 -6
  20. package/runtime/node_modules/@metro-labs/mcp/src/daemon/session-apis.ts +3 -14
  21. package/runtime/node_modules/@metro-labs/mcp/src/daemon/session.ts +0 -81
  22. package/runtime/node_modules/@metro-labs/mcp/src/daemon/siwe-routes.ts +2 -2
  23. package/runtime/node_modules/@metro-labs/mcp/src/daemon/update-api.ts +119 -0
  24. package/runtime/node_modules/@metro-labs/mcp/src/daemon/vault-api.ts +42 -12
  25. package/runtime/node_modules/@metro-labs/mcp/src/db/account-attach.ts +1 -73
  26. package/runtime/node_modules/@metro-labs/mcp/src/db/agent-admin.ts +1 -172
  27. package/runtime/node_modules/@metro-labs/mcp/src/db/client.ts +0 -5
  28. package/runtime/node_modules/@metro-labs/mcp/src/db/connector-relay.ts +2 -89
  29. package/runtime/node_modules/@metro-labs/mcp/src/db/connectors.ts +3 -262
  30. package/runtime/node_modules/@metro-labs/mcp/src/db/local-connectors.ts +1 -1
  31. package/runtime/node_modules/@metro-labs/mcp/src/db/materialize.ts +2 -140
  32. package/runtime/node_modules/@metro-labs/mcp/src/db/schema.ts +1 -89
  33. package/runtime/node_modules/@metro-labs/mcp/src/db/users.ts +14 -41
  34. package/runtime/node_modules/@metro-labs/mcp/src/db/vault.ts +5 -5
  35. package/runtime/node_modules/@metro-labs/whatsapp/package.json +0 -2
  36. package/runtime/runtime.json +1 -1
  37. package/dist/prompt.js +0 -61
  38. package/dist/store.js +0 -93
  39. package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-import.ts +0 -76
  40. package/runtime/node_modules/@metro-labs/mcp/src/daemon/agent-pair.ts +0 -20
  41. package/runtime/node_modules/@metro-labs/mcp/src/daemon/cli-pair-api.ts +0 -141
  42. package/runtime/node_modules/@metro-labs/mcp/src/daemon/import-api.ts +0 -68
  43. package/runtime/node_modules/@metro-labs/mcp/src/daemon/pair-codes.ts +0 -58
  44. package/runtime/node_modules/@metro-labs/mcp/src/daemon/project-api.ts +0 -214
  45. package/runtime/node_modules/@metro-labs/mcp/src/daemon/run-api.ts +0 -139
  46. package/runtime/node_modules/@metro-labs/mcp/src/daemon/runtime-source.ts +0 -105
  47. package/runtime/node_modules/@metro-labs/mcp/src/db/agent-connectors.ts +0 -143
  48. package/runtime/node_modules/@metro-labs/mcp/src/db/projects.ts +0 -309
  49. package/runtime/node_modules/@metro-labs/mcp/src/db/runtime-admin.ts +0 -24
  50. package/runtime/node_modules/@metro-labs/mcp/src/db/runtimes.ts +0 -105
  51. package/runtime/node_modules/@metro-labs/mcp/src/db/whatsapp-login.ts +0 -18
@@ -1,14 +1,6 @@
1
1
  import { randomBytes } from 'node:crypto';
2
- import { and, asc, eq, inArray } from 'drizzle-orm';
3
2
  import { ApiError } from '../daemon/api-error.js';
4
- import { getDb } from './client.js';
5
- import { registerKey, rotateAgentKey, unregisterAgentKey } from './key-map.js';
6
- import { AGENT_NAME_RE, newId, parseId } from './ids.js';
7
- import { agents, stations } from './schema.js';
8
- import { isUniqueViolation } from './users.js';
9
- import { projectIdOrThrow } from './projects.js';
10
-
11
- const KEY_ATTEMPTS = 5;
3
+ import { AGENT_NAME_RE } from './ids.js';
12
4
 
13
5
  export class AgentAdminError extends ApiError {}
14
6
 
@@ -49,166 +41,3 @@ export function normalizeAgentName(raw: unknown): string {
49
41
  export function newApiKey(): string {
50
42
  return `mk_${randomBytes(32).toString('base64url')}`;
51
43
  }
52
-
53
- const agentPin = (): string => process.env.METRO_AGENT?.trim() ?? '';
54
-
55
- export function servesEveryAgent(): boolean {
56
- return agentPin() === '';
57
- }
58
-
59
- export function daemonServesAgent(id: string): boolean {
60
- const pin = agentPin();
61
- return pin === '' || pin === id;
62
- }
63
-
64
- interface AgentRow {
65
- id: string;
66
- name: string;
67
- projectId: string;
68
- }
69
-
70
- interface KeyRow {
71
- agentId: string;
72
- key: string | null;
73
- }
74
-
75
- export function toAgentSummaries(
76
- rows: AgentRow[],
77
- keyRows: KeyRow[],
78
- ): AgentSummary[] {
79
- return rows.map((r) => ({
80
- id: r.id,
81
- name: r.name,
82
- owned: true,
83
- key: keyRows.find((k) => k.agentId === r.id)?.key ?? null,
84
- }));
85
- }
86
-
87
- async function selectKeyRows(ids: string[]): Promise<KeyRow[]> {
88
- if (ids.length === 0) return [];
89
- return getDb()
90
- .select({ agentId: agents.id, key: agents.key })
91
- .from(agents)
92
- .where(inArray(agents.id, ids));
93
- }
94
-
95
- export async function listAgentsForUser(
96
- subject: string,
97
- project: string,
98
- ): Promise<AgentSummary[]> {
99
- const projectId = await projectIdOrThrow(subject, project);
100
- const rows = await getDb()
101
- .select({ id: agents.id, name: agents.name, projectId: agents.projectId })
102
- .from(agents)
103
- .where(eq(agents.projectId, projectId))
104
- .orderBy(asc(agents.name), asc(agents.id));
105
- if (rows.length === 0) return [];
106
- const keyRows = await selectKeyRows(rows.map((r) => r.id));
107
- return toAgentSummaries(rows, keyRows);
108
- }
109
-
110
- async function insertAgent(
111
- projectId: string,
112
- name: string,
113
- key: string,
114
- ): Promise<string> {
115
- const inserted = await getDb()
116
- .insert(agents)
117
- .values({ id: newId(), name, projectId, key })
118
- .returning({ id: agents.id });
119
- const id = inserted[0]?.id;
120
- if (id === undefined)
121
- throw new AgentAdminError('agent insert returned no id', 500);
122
- return id;
123
- }
124
-
125
- export async function createAgentForUser(
126
- subject: string,
127
- project: string,
128
- rawName: string,
129
- ): Promise<CreatedAgent> {
130
- const name = normalizeAgentName(rawName);
131
- const key = newApiKey();
132
- const id = await insertAgent(await projectIdOrThrow(subject, project), name, key);
133
- if (servesEveryAgent()) registerKey(key, id);
134
- return { id, name, key };
135
- }
136
-
137
- export function parseAgentId(raw: string): string | null {
138
- return parseId(raw);
139
- }
140
-
141
- interface Deletable {
142
- agent: DeletedAgent;
143
- projectId: string;
144
- }
145
-
146
- export async function ownedAgentOrThrow(
147
- subject: string,
148
- id: string,
149
- ): Promise<Deletable> {
150
- const rows = await getDb().select().from(agents).where(eq(agents.id, id));
151
- const row = rows[0];
152
- const missing = new AgentAdminError('no such agent', 404);
153
- if (!row) throw missing;
154
- try {
155
- await projectIdOrThrow(subject, row.projectId);
156
- } catch {
157
- throw missing;
158
- }
159
- return { agent: { id: row.id, name: row.name }, projectId: row.projectId };
160
- }
161
-
162
- async function writeNewKey(id: string, projectId: string): Promise<string> {
163
- for (let attempt = 0; attempt < KEY_ATTEMPTS; attempt += 1) {
164
- const key = newApiKey();
165
- try {
166
- const changed = await getDb()
167
- .update(agents)
168
- .set({ key })
169
- .where(and(eq(agents.id, id), eq(agents.projectId, projectId)))
170
- .returning({ id: agents.id });
171
- if (changed.length === 0)
172
- throw new AgentAdminError('no such agent', 404);
173
- return key;
174
- } catch (err) {
175
- if (!isUniqueViolation(err)) throw err;
176
- }
177
- }
178
- throw new AgentAdminError('could not allocate a free api key', 500);
179
- }
180
-
181
- export async function resetAgentKeyForUser(
182
- subject: string,
183
- id: string,
184
- ): Promise<ResetAgentKey> {
185
- const { agent, projectId } = await ownedAgentOrThrow(subject, id);
186
- const key = await writeNewKey(agent.id, projectId);
187
- rotateAgentKey(agent.id, daemonServesAgent(agent.id) ? key : null);
188
- return { id: agent.id, name: agent.name, key };
189
- }
190
-
191
- export async function deleteAgentForUser(
192
- subject: string,
193
- id: string,
194
- ): Promise<DeletedAgent> {
195
- const { agent, projectId } = await ownedAgentOrThrow(subject, id);
196
- await getDb().transaction(async (tx) => {
197
- const attached = await tx
198
- .select({ id: stations.id })
199
- .from(stations)
200
- .where(eq(stations.agentId, id));
201
- if (attached.length > 0)
202
- throw new AgentAdminError(
203
- `agent '${agent.name}' still has ${attached.length} station account(s) attached — an operator must remove them first`,
204
- 409,
205
- );
206
- const gone = await tx
207
- .delete(agents)
208
- .where(and(eq(agents.id, id), eq(agents.projectId, projectId)))
209
- .returning({ id: agents.id });
210
- if (gone.length === 0) throw new AgentAdminError('no such agent', 404);
211
- });
212
- unregisterAgentKey(id);
213
- return agent;
214
- }
@@ -30,8 +30,3 @@ export function getDb(): Db {
30
30
  return db;
31
31
  }
32
32
 
33
- export async function closeDb(): Promise<void> {
34
- if (sql) await sql.end({ timeout: 5 });
35
- sql = null;
36
- db = null;
37
- }
@@ -1,22 +1,10 @@
1
- import { and, eq } from 'drizzle-orm';
2
- import { oauthExpired, refreshOAuth } from '../daemon/connector-oauth.js';
3
- import {
4
- parseConnectorUrl,
5
- type ConnectorAuth,
6
- type OAuthAuth,
7
- } from '../daemon/connector-verify.js';
8
- import { errMsg, log } from '../daemon/log.js';
9
- import { readConfig, type ConnectorConfig } from './connector-config.js';
10
- import { getDb } from './client.js';
11
- import { agentConnectors, connectors } from './schema.js';
1
+ import type { ConnectorAuth, OAuthAuth } from '../daemon/connector-verify.js';
12
2
 
13
3
  export type RelayTarget =
14
4
  | { kind: 'ok'; url: string; headers: Record<string, string> }
15
5
  | { kind: 'missing' }
16
6
  | { kind: 'signin' };
17
7
 
18
- type ConnectorRow = typeof connectors.$inferSelect;
19
-
20
8
  export const bearerHeaders = (token: string): Record<string, string> => ({
21
9
  Authorization: `Bearer ${token}`,
22
10
  });
@@ -25,54 +13,10 @@ export function staleUsable(auth: OAuthAuth, now = Date.now()): boolean {
25
13
  return auth.expiresAt === undefined || auth.expiresAt > now;
26
14
  }
27
15
 
28
- function headerAuthHeaders(
29
- auth: ConnectorAuth,
30
- ): Record<string, string> | null {
16
+ function headerAuthHeaders(auth: ConnectorAuth): Record<string, string> | null {
31
17
  return auth.kind === 'header' ? { [auth.name]: auth.value } : null;
32
18
  }
33
19
 
34
- async function memberRow(
35
- agentId: string,
36
- connectorId: string,
37
- ): Promise<ConnectorRow | undefined> {
38
- const rows = await getDb()
39
- .select({ connector: connectors })
40
- .from(agentConnectors)
41
- .innerJoin(connectors, eq(agentConnectors.connectorId, connectors.id))
42
- .where(
43
- and(
44
- eq(agentConnectors.agentId, agentId),
45
- eq(agentConnectors.connectorId, connectorId),
46
- ),
47
- );
48
- return rows[0]?.connector;
49
- }
50
-
51
- const inflight = new Map<string, Promise<OAuthAuth>>();
52
-
53
- function refreshOnce(
54
- row: ConnectorRow,
55
- config: ConnectorConfig,
56
- auth: OAuthAuth,
57
- ): Promise<OAuthAuth> {
58
- const running = inflight.get(row.id);
59
- if (running !== undefined) return running;
60
- const resource = parseConnectorUrl(row.url).toString();
61
- const job = refreshOAuth(auth, resource)
62
- .then(async (fresh) => {
63
- await getDb()
64
- .update(connectors)
65
- .set({ config: { ...config, auth: fresh } })
66
- .where(eq(connectors.id, row.id));
67
- return fresh;
68
- })
69
- .finally(() => {
70
- inflight.delete(row.id);
71
- });
72
- inflight.set(row.id, job);
73
- return job;
74
- }
75
-
76
20
  export function unrefreshedTarget(
77
21
  url: string,
78
22
  auth: OAuthAuth,
@@ -85,23 +29,6 @@ export function unrefreshedTarget(
85
29
  return { kind: 'ok', url, headers: {} };
86
30
  }
87
31
 
88
- async function oauthTarget(
89
- row: ConnectorRow,
90
- config: ConnectorConfig,
91
- auth: OAuthAuth,
92
- force: boolean,
93
- ): Promise<RelayTarget> {
94
- if (!force && !oauthExpired(auth))
95
- return { kind: 'ok', url: row.url, headers: bearerHeaders(auth.accessToken) };
96
- try {
97
- const fresh = await refreshOnce(row, config, auth);
98
- return { kind: 'ok', url: row.url, headers: bearerHeaders(fresh.accessToken) };
99
- } catch (err) {
100
- log.warn({ id: row.id, err: errMsg(err) }, 'relay: token refresh failed');
101
- return unrefreshedTarget(row.url, auth, force);
102
- }
103
- }
104
-
105
32
  export function fixedTarget(
106
33
  url: string,
107
34
  auth: Exclude<ConnectorAuth, OAuthAuth>,
@@ -110,17 +37,3 @@ export function fixedTarget(
110
37
  if (force) return { kind: 'signin' };
111
38
  return { kind: 'ok', url, headers: headerAuthHeaders(auth) ?? {} };
112
39
  }
113
-
114
- export async function relayTarget(
115
- agentId: string,
116
- connectorId: string,
117
- force: boolean,
118
- ): Promise<RelayTarget> {
119
- const row = await memberRow(agentId, connectorId);
120
- if (row === undefined) return { kind: 'missing' };
121
- parseConnectorUrl(row.url);
122
- const config = readConfig(row.config);
123
- const auth = config.auth;
124
- if (auth.kind === 'oauth') return oauthTarget(row, config, auth, force);
125
- return fixedTarget(row.url, auth, force);
126
- }
@@ -1,30 +1,6 @@
1
- import { assertRenameFreeOfClash } from './agent-connectors.js';
2
- import { projectIdOrThrow } from './projects.js';
3
- import { and, asc, eq, inArray } from 'drizzle-orm';
4
- import {
5
- connectorUrlText,
6
- ConnectorVerifyError,
7
- parseConnectorUrl,
8
- verifyRemoteMcp,
9
- type ConnectorAuth,
10
- type OAuthAuth,
11
- type VerifiedRecord,
12
- } from '../daemon/connector-verify.js';
13
- import { oauthExpired, refreshOAuth } from '../daemon/connector-oauth.js';
14
- import { advertisesOAuth } from '../daemon/oauth-discovery.js';
15
- import {
16
- ConnectorError,
17
- connectorAuth,
18
- connectorName,
19
- readConfig,
20
- signInState,
21
- stamp,
22
- type ConnectorConfig,
23
- type ConnectorSignIn,
24
- } from './connector-config.js';
25
- import { newId } from './ids.js';
26
- import { getDb } from './client.js';
27
- import { connectors, type ConnectorTransport } from './schema.js';
1
+ import type { ConnectorAuth, VerifiedRecord } from '../daemon/connector-verify.js';
2
+ import { readConfig, signInState, type ConnectorSignIn } from './connector-config.js';
3
+ import type { ConnectorTransport } from './schema.js';
28
4
 
29
5
  export interface Connector {
30
6
  id: string;
@@ -56,8 +32,6 @@ export interface DeletedConnector {
56
32
  name: string;
57
33
  }
58
34
 
59
- type ConnectorRow = typeof connectors.$inferSelect;
60
-
61
35
  export interface ConnectorLike {
62
36
  id: string;
63
37
  name: string;
@@ -84,71 +58,6 @@ export function connectorFromRow(row: ConnectorLike): Connector {
84
58
  };
85
59
  }
86
60
 
87
- const toConnector = (row: ConnectorRow): Connector => connectorFromRow(row);
88
-
89
- const missing = (): ConnectorError =>
90
- new ConnectorError('no such connector', 404);
91
-
92
- async function ownedConnectorOrThrow(
93
- subject: string,
94
- id: string,
95
- ): Promise<ConnectorRow> {
96
- const rows = await getDb()
97
- .select()
98
- .from(connectors)
99
- .where(eq(connectors.id, id));
100
- const row = rows[0];
101
- if (row === undefined) throw missing();
102
- try {
103
- await projectIdOrThrow(subject, row.projectId);
104
- } catch {
105
- throw missing();
106
- }
107
- return row;
108
- }
109
-
110
- async function saveConfig(
111
- row: ConnectorRow,
112
- config: ConnectorConfig,
113
- ): Promise<Connector> {
114
- const rows = await getDb()
115
- .update(connectors)
116
- .set({ config })
117
- .where(and(eq(connectors.id, row.id), eq(connectors.projectId, row.projectId)))
118
- .returning();
119
- const saved = rows[0];
120
- if (saved === undefined) throw missing();
121
- return toConnector(saved);
122
- }
123
-
124
- async function connectorRowsFor(
125
- subject: string,
126
- project: string,
127
- ): Promise<ConnectorRow[]> {
128
- const projectId = await projectIdOrThrow(subject, project);
129
- return getDb()
130
- .select()
131
- .from(connectors)
132
- .where(eq(connectors.projectId, projectId))
133
- .orderBy(asc(connectors.id));
134
- }
135
-
136
- export async function listConnectorsForUser(
137
- subject: string,
138
- project: string,
139
- ): Promise<Connector[]> {
140
- return (await connectorRowsFor(subject, project)).map(toConnector);
141
- }
142
-
143
- async function rowsByIds(ids: string[]): Promise<ConnectorRow[]> {
144
- if (ids.length === 0) return [];
145
- return getDb()
146
- .select()
147
- .from(connectors)
148
- .where(inArray(connectors.id, ids))
149
- .orderBy(asc(connectors.id));
150
- }
151
-
152
61
  export interface ConnectorSummary {
153
62
  id: string;
154
63
  name: string;
@@ -157,52 +66,6 @@ export interface ConnectorSummary {
157
66
  signIn: ConnectorSignIn;
158
67
  }
159
68
 
160
- export async function connectorSummariesByIds(ids: string[]): Promise<ConnectorSummary[]> {
161
- return (await rowsByIds(ids)).map((row) => ({
162
- id: row.id,
163
- name: row.name,
164
- url: row.url,
165
- transport: row.transport,
166
- signIn: signInState(readConfig(row.config)),
167
- }));
168
- }
169
-
170
- export async function connectorNamesByIds(
171
- ids: string[],
172
- ): Promise<{ id: string; name: string }[]> {
173
- return (await rowsByIds(ids)).map((row) => ({ id: row.id, name: row.name }));
174
- }
175
-
176
- export async function getConnectorForUser(
177
- subject: string,
178
- id: string,
179
- ): Promise<Connector> {
180
- return toConnector(await ownedConnectorOrThrow(subject, id));
181
- }
182
-
183
- async function insertConnector(
184
- projectId: string,
185
- name: string,
186
- url: URL,
187
- config: ConnectorConfig,
188
- ): Promise<Connector> {
189
- const rows = await getDb()
190
- .insert(connectors)
191
- .values({
192
- id: newId(),
193
- projectId,
194
- name,
195
- url: connectorUrlText(url),
196
- transport: 'http',
197
- config,
198
- })
199
- .returning();
200
- const row = rows[0];
201
- if (row === undefined)
202
- throw new ConnectorError('connector insert returned no row', 500);
203
- return toConnector(row);
204
- }
205
-
206
69
  export const UNVERIFIED = {
207
70
  at: '',
208
71
  server: '',
@@ -212,125 +75,3 @@ export const UNVERIFIED = {
212
75
  tools: 0,
213
76
  catalog: [],
214
77
  };
215
-
216
- export async function createPendingConnectorForUser(
217
- subject: string,
218
- project: string,
219
- input: { name: unknown; url: unknown },
220
- ): Promise<Connector> {
221
- const name = connectorName(input.name);
222
- const url = parseConnectorUrl(input.url);
223
- const projectId = await projectIdOrThrow(subject, project);
224
- return insertConnector(projectId, name, url, {
225
- auth: { kind: 'none' },
226
- createdAt: new Date().toISOString(),
227
- verified: UNVERIFIED,
228
- oauth: true,
229
- });
230
- }
231
-
232
- export async function createConnectorForUser(
233
- subject: string,
234
- project: string,
235
- input: ConnectorInput,
236
- ): Promise<Connector> {
237
- const name = connectorName(input.name);
238
- const url = parseConnectorUrl(input.url);
239
- const auth = connectorAuth(input.header, input.value);
240
- const projectId = await projectIdOrThrow(subject, project);
241
- const verified = stamp(await verifyRemoteMcp(url, auth));
242
- return insertConnector(projectId, name, url, {
243
- auth,
244
- createdAt: new Date().toISOString(),
245
- verified,
246
- oauth: await oauthCapable(url, auth),
247
- });
248
- }
249
-
250
- async function oauthCapable(url: URL, auth: ConnectorAuth): Promise<boolean> {
251
- if (auth.kind === 'oauth') return true;
252
- if (auth.kind === 'header') return false;
253
- return advertisesOAuth(url);
254
- }
255
-
256
- async function freshAuth(
257
- auth: ConnectorAuth,
258
- resource: string,
259
- ): Promise<ConnectorAuth> {
260
- if (auth.kind !== 'oauth' || !oauthExpired(auth)) return auth;
261
- return refreshOAuth(auth, resource);
262
- }
263
-
264
- export async function reconnectConnectorForUser(
265
- subject: string,
266
- id: string,
267
- auth: OAuthAuth,
268
- ): Promise<Connector> {
269
- const row = await ownedConnectorOrThrow(subject, id);
270
- const config = readConfig(row.config);
271
- const url = parseConnectorUrl(row.url);
272
- const verified = stamp(await verifyRemoteMcp(url, auth));
273
- return saveConfig(row, { ...config, auth, verified, oauth: true });
274
- }
275
-
276
- export async function disconnectConnectorForUser(
277
- subject: string,
278
- id: string,
279
- ): Promise<Connector> {
280
- const row = await ownedConnectorOrThrow(subject, id);
281
- const config = readConfig(row.config);
282
- if (config.auth.kind !== 'oauth')
283
- throw new ConnectorError('that connector is not signed in', 400);
284
- return saveConfig(row, { ...config, auth: { kind: 'none' }, oauth: true });
285
- }
286
-
287
- export async function verifyConnectorForUser(
288
- subject: string,
289
- id: string,
290
- ): Promise<ConnectorCheck> {
291
- const row = await ownedConnectorOrThrow(subject, id);
292
- const config = readConfig(row.config);
293
- try {
294
- const url = parseConnectorUrl(row.url);
295
- const auth = await freshAuth(config.auth, url.toString());
296
- const verified = stamp(await verifyRemoteMcp(url, auth));
297
- const oauth = config.oauth || (await oauthCapable(url, auth));
298
- await saveConfig(row, { ...config, auth, verified, oauth });
299
- return { id: row.id, name: row.name, ok: true, verified };
300
- } catch (err) {
301
- if (!(err instanceof ConnectorVerifyError)) throw err;
302
- return { id: row.id, name: row.name, ok: false, reason: err.message };
303
- }
304
- }
305
-
306
- export async function renameConnectorForUser(
307
- subject: string,
308
- id: string,
309
- raw: string,
310
- ): Promise<Connector> {
311
- const name = connectorName(raw);
312
- const row = await ownedConnectorOrThrow(subject, id);
313
- await assertRenameFreeOfClash(row.id, name);
314
- const rows = await getDb()
315
- .update(connectors)
316
- .set({ name })
317
- .where(and(eq(connectors.id, row.id), eq(connectors.projectId, row.projectId)))
318
- .returning();
319
- const saved = rows[0];
320
- if (saved === undefined) throw missing();
321
- return toConnector(saved);
322
- }
323
-
324
- export async function deleteConnectorForUser(
325
- subject: string,
326
- id: string,
327
- ): Promise<DeletedConnector> {
328
- const row = await ownedConnectorOrThrow(subject, id);
329
- const gone = await getDb()
330
- .delete(connectors)
331
- .where(eq(connectors.id, row.id))
332
- .returning({ id: connectors.id, name: connectors.name });
333
- const deleted = gone[0];
334
- if (deleted === undefined) throw missing();
335
- return deleted;
336
- }
@@ -35,7 +35,7 @@ import {
35
35
  type ConnectorSummary,
36
36
  type DeletedConnector,
37
37
  } from './connectors.js';
38
- import type { AgentConnectors } from './agent-connectors.js';
38
+ import type { AgentConnectors } from '../daemon/agent-connector-api.js';
39
39
  import { agentsDir } from './file-source.js';
40
40
  import {
41
41
  assertLocalOwner,