@concord-ai/concord-mcp 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/cli/commands/adapters.js +12 -1
- package/dist/cli/commands/adapters.js.map +1 -1
- package/dist/cli/commands/cloud-codex.d.ts +14 -0
- package/dist/cli/commands/cloud-codex.js +148 -0
- package/dist/cli/commands/cloud-codex.js.map +1 -0
- package/dist/cli/commands/cloud-hooks.d.ts +11 -0
- package/dist/cli/commands/cloud-hooks.js +121 -0
- package/dist/cli/commands/cloud-hooks.js.map +1 -0
- package/dist/cli/commands/cloud-inbox.d.ts +49 -0
- package/dist/cli/commands/cloud-inbox.js +167 -0
- package/dist/cli/commands/cloud-inbox.js.map +1 -0
- package/dist/cli/commands/cloud-views.d.ts +11 -0
- package/dist/cli/commands/cloud-views.js +92 -0
- package/dist/cli/commands/cloud-views.js.map +1 -0
- package/dist/cli/commands/cloud.d.ts +41 -0
- package/dist/cli/commands/cloud.js +226 -0
- package/dist/cli/commands/cloud.js.map +1 -0
- package/dist/cli/commands/export.js +7 -0
- package/dist/cli/commands/export.js.map +1 -1
- package/dist/cli/commands/hook.js +39 -19
- package/dist/cli/commands/hook.js.map +1 -1
- package/dist/cli/commands/inbox.js +129 -57
- package/dist/cli/commands/inbox.js.map +1 -1
- package/dist/cli/commands/session-start-message.d.ts +8 -0
- package/dist/cli/commands/session-start-message.js +21 -0
- package/dist/cli/commands/session-start-message.js.map +1 -0
- package/dist/cli/commands/status.js +4 -2
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/tasks.js +4 -2
- package/dist/cli/commands/tasks.js.map +1 -1
- package/dist/cli/commands/who.js +4 -2
- package/dist/cli/commands/who.js.map +1 -1
- package/dist/cli/index.js +16 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cloud/browser-login.d.ts +27 -0
- package/dist/cloud/browser-login.js +115 -0
- package/dist/cloud/browser-login.js.map +1 -0
- package/dist/cloud/client.d.ts +68 -0
- package/dist/cloud/client.js +114 -0
- package/dist/cloud/client.js.map +1 -0
- package/dist/cloud/http-transport.d.ts +18 -0
- package/dist/cloud/http-transport.js +40 -0
- package/dist/cloud/http-transport.js.map +1 -0
- package/dist/cloud/proxy.d.ts +56 -0
- package/dist/cloud/proxy.js +162 -0
- package/dist/cloud/proxy.js.map +1 -0
- package/dist/cloud/runtime.d.ts +152 -0
- package/dist/cloud/runtime.js +332 -0
- package/dist/cloud/runtime.js.map +1 -0
- package/dist/cloud/settings.d.ts +62 -0
- package/dist/cloud/settings.js +162 -0
- package/dist/cloud/settings.js.map +1 -0
- package/dist/cloud/tokens.d.ts +20 -0
- package/dist/cloud/tokens.js +87 -0
- package/dist/cloud/tokens.js.map +1 -0
- package/dist/config/paths.d.ts +13 -0
- package/dist/config/paths.js +40 -0
- package/dist/config/paths.js.map +1 -1
- package/dist/domain/harness-config.d.ts +1 -1
- package/dist/domain/harness-config.js +18 -1
- package/dist/domain/harness-config.js.map +1 -1
- package/dist/domain/identity.js +1 -0
- package/dist/domain/identity.js.map +1 -1
- package/dist/domain/project-key.d.ts +23 -0
- package/dist/domain/project-key.js +109 -0
- package/dist/domain/project-key.js.map +1 -0
- package/dist/domain/pull-inbox.d.ts +12 -0
- package/dist/domain/pull-inbox.js +14 -1
- package/dist/domain/pull-inbox.js.map +1 -1
- package/dist/domain/schemas.d.ts +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/install/adapters/index.js +55 -13
- package/dist/install/adapters/index.js.map +1 -1
- package/dist/install/goose-config.d.ts +4 -0
- package/dist/install/goose-config.js +90 -0
- package/dist/install/goose-config.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -1
- package/plugin/concord-relay/scripts/watch-inbox.sh +11 -0
- package/plugin/cursor/concord-relay/cursor-hook.mjs +19 -3
- package/plugin/gemini/concord-relay/hooks/session-register.mjs +3 -2
- package/plugin/spawn-command.mjs +74 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { assertKeySafeUrl } from './client.js';
|
|
4
|
+
import { requestTokens } from './tokens.js';
|
|
5
|
+
/** How long to wait for the browser before giving up. */
|
|
6
|
+
const WAIT_MS = 5 * 60_000;
|
|
7
|
+
const base64url = (bytes) => bytes.toString('base64url');
|
|
8
|
+
/** Waits on this machine for the web page to hand over the code. */
|
|
9
|
+
function listenForCode() {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
let settle;
|
|
12
|
+
const server = createServer((request, response) => {
|
|
13
|
+
const url = new URL(request.url ?? '/', 'http://127.0.0.1');
|
|
14
|
+
if (url.pathname !== '/callback') {
|
|
15
|
+
response.writeHead(404).end();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const code = url.searchParams.get('code') ?? undefined;
|
|
19
|
+
const error = url.searchParams.get('error') ?? undefined;
|
|
20
|
+
response
|
|
21
|
+
.writeHead(200, { 'content-type': 'text/html; charset=utf-8' })
|
|
22
|
+
.end(`<!doctype html><title>Concord</title><p>${error === undefined
|
|
23
|
+
? 'Signed in. You can close this tab.'
|
|
24
|
+
: 'Sign-in was not completed.'}</p>`);
|
|
25
|
+
settle?.({
|
|
26
|
+
...(code === undefined ? {} : { code }),
|
|
27
|
+
...(error === undefined ? {} : { error }),
|
|
28
|
+
state: url.searchParams.get('state') ?? '',
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
server.on('error', reject);
|
|
32
|
+
server.listen(0, '127.0.0.1', () => {
|
|
33
|
+
const address = server.address();
|
|
34
|
+
if (address === null || typeof address === 'string') {
|
|
35
|
+
reject(new Error('Could not listen for the sign-in on this machine.'));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
resolve({
|
|
39
|
+
port: address.port,
|
|
40
|
+
code: (state) => new Promise((done, fail) => {
|
|
41
|
+
const timer = setTimeout(() => {
|
|
42
|
+
finish();
|
|
43
|
+
fail(new Error('Timed out waiting for the browser; run `concord cloud login` again.'));
|
|
44
|
+
}, WAIT_MS);
|
|
45
|
+
const finish = () => {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
settle = undefined;
|
|
48
|
+
server.closeAllConnections();
|
|
49
|
+
server.close();
|
|
50
|
+
};
|
|
51
|
+
settle = (outcome) => {
|
|
52
|
+
// Anything not carrying this login's state is someone else's.
|
|
53
|
+
if (outcome.state !== state)
|
|
54
|
+
return;
|
|
55
|
+
finish();
|
|
56
|
+
if (outcome.code !== undefined)
|
|
57
|
+
done(outcome.code);
|
|
58
|
+
else
|
|
59
|
+
fail(new Error(`Sign-in was not completed (${outcome.error ?? 'no code'}).`));
|
|
60
|
+
};
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export async function browserLogin(login, options, deps) {
|
|
67
|
+
// The API names these; whatever it names is opened and posted to, so only
|
|
68
|
+
// https is accepted, as for anywhere a credential goes.
|
|
69
|
+
assertKeySafeUrl(login.authorizationEndpoint);
|
|
70
|
+
assertKeySafeUrl(login.tokenEndpoint);
|
|
71
|
+
const verifier = base64url(randomBytes(32));
|
|
72
|
+
const nonce = base64url(randomBytes(24));
|
|
73
|
+
const listener = options.paste ? undefined : await listenForCode();
|
|
74
|
+
const state = `${listener === undefined ? 'paste' : String(listener.port)}.${nonce}`;
|
|
75
|
+
const authorize = new URL(login.authorizationEndpoint);
|
|
76
|
+
for (const [name, value] of Object.entries({
|
|
77
|
+
response_type: 'code',
|
|
78
|
+
client_id: login.clientId,
|
|
79
|
+
redirect_uri: login.redirectUri,
|
|
80
|
+
code_challenge: base64url(createHash('sha256').update(verifier).digest()),
|
|
81
|
+
code_challenge_method: 'S256',
|
|
82
|
+
state,
|
|
83
|
+
scope: 'email',
|
|
84
|
+
})) {
|
|
85
|
+
authorize.searchParams.set(name, value);
|
|
86
|
+
}
|
|
87
|
+
deps.print(`Sign in to Concord Cloud in your browser:\n ${authorize.toString()}`);
|
|
88
|
+
let code;
|
|
89
|
+
if (listener === undefined) {
|
|
90
|
+
deps.print('Then paste the code the page shows:');
|
|
91
|
+
code = (await deps.readLine()).trim();
|
|
92
|
+
if (code === '')
|
|
93
|
+
throw new Error('No code was entered.');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Waiting starts first, so the listener's timeout and cleanup are in place
|
|
97
|
+
// whatever opening the browser does. A browser that fails to open is no
|
|
98
|
+
// failure: the link is printed above, for the person to open themselves.
|
|
99
|
+
const arrived = listener.code(state);
|
|
100
|
+
try {
|
|
101
|
+
deps.openUrl(authorize.toString());
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
deps.print('Could not open a browser; open the link above yourself.');
|
|
105
|
+
}
|
|
106
|
+
code = await arrived;
|
|
107
|
+
}
|
|
108
|
+
return requestTokens({ clientId: login.clientId, tokenEndpoint: login.tokenEndpoint }, {
|
|
109
|
+
grant_type: 'authorization_code',
|
|
110
|
+
code,
|
|
111
|
+
redirect_uri: login.redirectUri,
|
|
112
|
+
code_verifier: verifier,
|
|
113
|
+
}, deps.fetch);
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=browser-login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-login.js","sourceRoot":"","sources":["../../src/cloud/browser-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAA6B,MAAM,aAAa,CAAC;AAE1E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA0B5C,yDAAyD;AACzD,MAAM,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC;AAE3B,MAAM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EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,gDAAgD,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACnF,IAAI,IAAY,CAAC;IACjB,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;QAClD,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACtC,IAAI,IAAI,KAAK,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC3D,CAAC;SAAM,CAAC;QACN,2EAA2E;QAC3E,wEAAwE;QACxE,yEAAyE;QACzE,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACxE,CAAC;QACD,IAAI,GAAG,MAAM,OAAO,CAAC;IACvB,CAAC;IAED,OAAO,aAAa,CAClB,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE,EAChE;QACE,UAAU,EAAE,oBAAoB;QAChC,IAAI;QACJ,YAAY,EAAE,KAAK,CAAC,WAAW;QAC/B,aAAa,EAAE,QAAQ;KACxB,EACD,IAAI,CAAC,KAAK,CACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The few Concord Cloud calls cloud mode needs before it can rely on the API:
|
|
4
|
+
* what the API supports, and whether a key works.
|
|
5
|
+
*/
|
|
6
|
+
/** The API version this runtime speaks. Bumped only on incompatible change. */
|
|
7
|
+
export declare const SUPPORTED_API_VERSION = 1;
|
|
8
|
+
/**
|
|
9
|
+
* Capabilities cloud mode relies on. Checked by name rather than by version, so
|
|
10
|
+
* an API that gains capabilities never breaks an older runtime.
|
|
11
|
+
*/
|
|
12
|
+
export declare const REQUIRED_CAPABILITIES: readonly ["projects", "agents-per-machine", "claims-check", "receiver-lease", "message-drain-wait"];
|
|
13
|
+
declare const cliLoginSchema: z.ZodObject<{
|
|
14
|
+
authorizationEndpoint: z.ZodURL;
|
|
15
|
+
tokenEndpoint: z.ZodURL;
|
|
16
|
+
clientId: z.ZodString;
|
|
17
|
+
redirectUri: z.ZodURL;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/** How this API signs a person in from the CLI, when it offers browser login. */
|
|
20
|
+
export type CliLogin = z.infer<typeof cliLoginSchema>;
|
|
21
|
+
declare const metaSchema: z.ZodObject<{
|
|
22
|
+
apiVersion: z.ZodNumber;
|
|
23
|
+
capabilities: z.ZodArray<z.ZodString>;
|
|
24
|
+
mcp: z.ZodObject<{
|
|
25
|
+
endpoint: z.ZodString;
|
|
26
|
+
tools: z.ZodArray<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
cliLogin: z.ZodOptional<z.ZodObject<{
|
|
29
|
+
authorizationEndpoint: z.ZodURL;
|
|
30
|
+
tokenEndpoint: z.ZodURL;
|
|
31
|
+
clientId: z.ZodString;
|
|
32
|
+
redirectUri: z.ZodURL;
|
|
33
|
+
}, z.core.$strip>>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
export type CloudMeta = z.infer<typeof metaSchema>;
|
|
36
|
+
export type Fetch = (input: string, init?: RequestInit) => Promise<Response>;
|
|
37
|
+
/** How long any of these calls may take: a cold Cloud Run start is the slow case. */
|
|
38
|
+
export declare const TIMEOUT_MS = 15000;
|
|
39
|
+
/** Whether two API URLs name the same API: spelling aside, the same endpoint. */
|
|
40
|
+
export declare function sameApi(first: string, second: string): boolean;
|
|
41
|
+
/** A path on an API, however its URL is spelled. */
|
|
42
|
+
export declare function url(apiUrl: string, path: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Refuses to send a key anywhere but https, or plain http to this machine for
|
|
45
|
+
* local development: anyone on the path of a remote http request could read it.
|
|
46
|
+
*/
|
|
47
|
+
export declare function assertKeySafeUrl(apiUrl: string): void;
|
|
48
|
+
/** A server's error body, as one short line. */
|
|
49
|
+
export declare function errorDetail(response: Response): Promise<string>;
|
|
50
|
+
/** `GET /v1/meta` — public, so it answers before any key is trusted. */
|
|
51
|
+
export declare function fetchMeta(apiUrl: string, fetchImpl?: Fetch): Promise<CloudMeta>;
|
|
52
|
+
/** Why this runtime cannot use an API, or null when it can. */
|
|
53
|
+
export declare function incompatibility(meta: CloudMeta): string | null;
|
|
54
|
+
/** Whether a key is accepted: one cheap authenticated read. */
|
|
55
|
+
export declare function checkKey(apiUrl: string, bearer: string, fetchImpl?: Fetch): Promise<'ok' | 'rejected'>;
|
|
56
|
+
export interface MachineRegistration {
|
|
57
|
+
readonly machineKey: string;
|
|
58
|
+
readonly name: string;
|
|
59
|
+
readonly hostname: string;
|
|
60
|
+
readonly platform: string;
|
|
61
|
+
readonly runtimeVersion: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `POST /v1/machines` — registers this machine, idempotently by key. The cloud
|
|
65
|
+
* refuses calls naming a machine it has not registered, so login does this.
|
|
66
|
+
*/
|
|
67
|
+
export declare function registerMachine(apiUrl: string, apiKey: string, machine: MachineRegistration, fetchImpl?: Fetch): Promise<'ok' | 'rejected'>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The few Concord Cloud calls cloud mode needs before it can rely on the API:
|
|
4
|
+
* what the API supports, and whether a key works.
|
|
5
|
+
*/
|
|
6
|
+
/** The API version this runtime speaks. Bumped only on incompatible change. */
|
|
7
|
+
export const SUPPORTED_API_VERSION = 1;
|
|
8
|
+
/**
|
|
9
|
+
* Capabilities cloud mode relies on. Checked by name rather than by version, so
|
|
10
|
+
* an API that gains capabilities never breaks an older runtime.
|
|
11
|
+
*/
|
|
12
|
+
export const REQUIRED_CAPABILITIES = [
|
|
13
|
+
'projects',
|
|
14
|
+
'agents-per-machine',
|
|
15
|
+
'claims-check',
|
|
16
|
+
'receiver-lease',
|
|
17
|
+
'message-drain-wait',
|
|
18
|
+
];
|
|
19
|
+
const cliLoginSchema = z.object({
|
|
20
|
+
authorizationEndpoint: z.url(),
|
|
21
|
+
tokenEndpoint: z.url(),
|
|
22
|
+
clientId: z.string().min(1),
|
|
23
|
+
redirectUri: z.url(),
|
|
24
|
+
});
|
|
25
|
+
const metaSchema = z.object({
|
|
26
|
+
apiVersion: z.number().int(),
|
|
27
|
+
capabilities: z.array(z.string()),
|
|
28
|
+
mcp: z.object({ endpoint: z.string(), tools: z.array(z.string()) }),
|
|
29
|
+
cliLogin: cliLoginSchema.optional(),
|
|
30
|
+
});
|
|
31
|
+
/** How long any of these calls may take: a cold Cloud Run start is the slow case. */
|
|
32
|
+
export const TIMEOUT_MS = 15_000;
|
|
33
|
+
/** Whether two API URLs name the same API: spelling aside, the same endpoint. */
|
|
34
|
+
export function sameApi(first, second) {
|
|
35
|
+
const normal = (apiUrl) => new URL(apiUrl).href.replace(/\/+$/, '');
|
|
36
|
+
return normal(first) === normal(second);
|
|
37
|
+
}
|
|
38
|
+
/** A path on an API, however its URL is spelled. */
|
|
39
|
+
export function url(apiUrl, path) {
|
|
40
|
+
return `${apiUrl.replace(/\/+$/, '')}${path}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Refuses to send a key anywhere but https, or plain http to this machine for
|
|
44
|
+
* local development: anyone on the path of a remote http request could read it.
|
|
45
|
+
*/
|
|
46
|
+
export function assertKeySafeUrl(apiUrl) {
|
|
47
|
+
const { protocol, hostname } = new URL(apiUrl);
|
|
48
|
+
const loopback = ['localhost', '127.0.0.1', '[::1]'].includes(hostname);
|
|
49
|
+
if (protocol !== 'https:' && !(protocol === 'http:' && loopback)) {
|
|
50
|
+
throw new Error(`${apiUrl} is not https; Concord sends an API key only over https.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** A server's error body, as one short line. */
|
|
54
|
+
export async function errorDetail(response) {
|
|
55
|
+
return (await response.text()).replace(/\s+/g, ' ').trim().slice(0, 200);
|
|
56
|
+
}
|
|
57
|
+
/** `GET /v1/meta` — public, so it answers before any key is trusted. */
|
|
58
|
+
export async function fetchMeta(apiUrl, fetchImpl = fetch) {
|
|
59
|
+
const response = await fetchImpl(url(apiUrl, '/v1/meta'), {
|
|
60
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
61
|
+
});
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw new Error(`${apiUrl} answered ${String(response.status)} to /v1/meta; is it Concord Cloud?`);
|
|
64
|
+
}
|
|
65
|
+
const raw = await response.json();
|
|
66
|
+
const parsed = metaSchema.safeParse(raw);
|
|
67
|
+
if (!parsed.success) {
|
|
68
|
+
throw new Error(`${apiUrl} does not describe itself as Concord Cloud does.`);
|
|
69
|
+
}
|
|
70
|
+
return parsed.data;
|
|
71
|
+
}
|
|
72
|
+
/** Why this runtime cannot use an API, or null when it can. */
|
|
73
|
+
export function incompatibility(meta) {
|
|
74
|
+
if (meta.apiVersion !== SUPPORTED_API_VERSION) {
|
|
75
|
+
return (`the API speaks version ${String(meta.apiVersion)}, this runtime version ` +
|
|
76
|
+
`${String(SUPPORTED_API_VERSION)}; update @concord-ai/concord-mcp`);
|
|
77
|
+
}
|
|
78
|
+
const missing = REQUIRED_CAPABILITIES.filter((name) => !meta.capabilities.includes(name));
|
|
79
|
+
return missing.length === 0 ? null : `the API lacks ${missing.join(', ')}`;
|
|
80
|
+
}
|
|
81
|
+
/** Whether a key is accepted: one cheap authenticated read. */
|
|
82
|
+
export async function checkKey(apiUrl, bearer, fetchImpl = fetch) {
|
|
83
|
+
assertKeySafeUrl(apiUrl);
|
|
84
|
+
const response = await fetchImpl(url(apiUrl, '/v1/machines'), {
|
|
85
|
+
headers: { Authorization: `Bearer ${bearer}` },
|
|
86
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
87
|
+
});
|
|
88
|
+
if (response.status === 401 || response.status === 403)
|
|
89
|
+
return 'rejected';
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
throw new Error(`${apiUrl} answered ${String(response.status)} while checking the key.`);
|
|
92
|
+
}
|
|
93
|
+
return 'ok';
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* `POST /v1/machines` — registers this machine, idempotently by key. The cloud
|
|
97
|
+
* refuses calls naming a machine it has not registered, so login does this.
|
|
98
|
+
*/
|
|
99
|
+
export async function registerMachine(apiUrl, apiKey, machine, fetchImpl = fetch) {
|
|
100
|
+
assertKeySafeUrl(apiUrl);
|
|
101
|
+
const response = await fetchImpl(url(apiUrl, '/v1/machines'), {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
|
|
104
|
+
body: JSON.stringify(machine),
|
|
105
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
106
|
+
});
|
|
107
|
+
if (response.status === 401)
|
|
108
|
+
return 'rejected';
|
|
109
|
+
if (!response.ok) {
|
|
110
|
+
throw new Error(`${apiUrl} answered ${String(response.status)} registering this machine: ${await errorDetail(response)}`);
|
|
111
|
+
}
|
|
112
|
+
return 'ok';
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/cloud/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC;;;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O,UAAU,CAAC;IAC1E,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,aAAa,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAUD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAc,EACd,MAAc,EACd,OAA4B,EAC5B,YAAmB,KAAK;IAExB,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE;QAC5D,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAClF,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC;KACxC,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,UAAU,CAAC;IAC/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,aAAa,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,8BAA8B,MAAM,WAAW,CAAC,QAAQ,CAAC,EAAE,CACzG,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FetchLike, Transport, TransportSendOptions } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
2
|
+
import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The SDK's Streamable HTTP client transport, as a `Transport`. Delegation
|
|
5
|
+
* rather than a cast: the SDK types its `sessionId` as `string | undefined`,
|
|
6
|
+
* which `exactOptionalPropertyTypes` will not accept for `sessionId?: string`.
|
|
7
|
+
*/
|
|
8
|
+
export declare class HttpClientTransport implements Transport {
|
|
9
|
+
#private;
|
|
10
|
+
onclose: NonNullable<Transport['onclose']>;
|
|
11
|
+
onerror: NonNullable<Transport['onerror']>;
|
|
12
|
+
onmessage: NonNullable<Transport['onmessage']>;
|
|
13
|
+
constructor(url: URL, headers: Record<string, string>, fetchImpl?: FetchLike);
|
|
14
|
+
setProtocolVersion(version: string): void;
|
|
15
|
+
start(): Promise<void>;
|
|
16
|
+
send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
2
|
+
/**
|
|
3
|
+
* The SDK's Streamable HTTP client transport, as a `Transport`. Delegation
|
|
4
|
+
* rather than a cast: the SDK types its `sessionId` as `string | undefined`,
|
|
5
|
+
* which `exactOptionalPropertyTypes` will not accept for `sessionId?: string`.
|
|
6
|
+
*/
|
|
7
|
+
export class HttpClientTransport {
|
|
8
|
+
#inner;
|
|
9
|
+
onclose = () => undefined;
|
|
10
|
+
onerror = () => undefined;
|
|
11
|
+
onmessage = () => undefined;
|
|
12
|
+
constructor(url, headers, fetchImpl) {
|
|
13
|
+
this.#inner = new StreamableHTTPClientTransport(url, {
|
|
14
|
+
requestInit: { headers },
|
|
15
|
+
...(fetchImpl === undefined ? {} : { fetch: fetchImpl }),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
setProtocolVersion(version) {
|
|
19
|
+
this.#inner.setProtocolVersion(version);
|
|
20
|
+
}
|
|
21
|
+
async start() {
|
|
22
|
+
this.#inner.onclose = () => {
|
|
23
|
+
this.onclose();
|
|
24
|
+
};
|
|
25
|
+
this.#inner.onerror = (error) => {
|
|
26
|
+
this.onerror(error);
|
|
27
|
+
};
|
|
28
|
+
this.#inner.onmessage = (message) => {
|
|
29
|
+
this.onmessage(message);
|
|
30
|
+
};
|
|
31
|
+
await this.#inner.start();
|
|
32
|
+
}
|
|
33
|
+
async send(message, options) {
|
|
34
|
+
await this.#inner.send(message, options);
|
|
35
|
+
}
|
|
36
|
+
async close() {
|
|
37
|
+
await this.#inner.close();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=http-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-transport.js","sourceRoot":"","sources":["../../src/cloud/http-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAQnG;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IACrB,MAAM,CAAgC;IAE/C,OAAO,GAAsC,GAAG,EAAE,CAAC,SAAS,CAAC;IAC7D,OAAO,GAAsC,GAAG,EAAE,CAAC,SAAS,CAAC;IAC7D,SAAS,GAAwC,GAAG,EAAE,CAAC,SAAS,CAAC;IAEjE,YAAY,GAAQ,EAAE,OAA+B,EAAE,SAAqB;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAI,6BAA6B,CAAC,GAAG,EAAE;YACnD,WAAW,EAAE,EAAE,OAAO,EAAE;YACxB,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;SACzD,CAAC,CAAC;IACL,CAAC;IAED,kBAAkB,CAAC,OAAe;QAChC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE;YACzB,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE;YAC9B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,OAAuB,EAAE,EAAE;YAClD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC,CAAC;QACF,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAuB,EAAE,OAA8B;QAChE,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import type { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import type { AgentIdentity } from '../domain/identity.js';
|
|
6
|
+
import { type Bearer } from './tokens.js';
|
|
7
|
+
/**
|
|
8
|
+
* Cloud mode for the MCP server: in a linked repository, `concord-mcp` forwards
|
|
9
|
+
* the workflow tools to Concord Cloud instead of answering from SQLite.
|
|
10
|
+
*
|
|
11
|
+
* A proxy rather than pointing the harness at the cloud URL, because only this
|
|
12
|
+
* process can see the session: it stamps the session's own agent onto every
|
|
13
|
+
* write, as the local server does, so a model cannot act as a peer. It also
|
|
14
|
+
* keeps the API key out of committed MCP config, and sends file paths relative
|
|
15
|
+
* to the repository, the only form the cloud accepts.
|
|
16
|
+
*
|
|
17
|
+
* Proxied calls are not recorded by this package's telemetry: they are not
|
|
18
|
+
* local operations, and Concord Cloud records its own usage.
|
|
19
|
+
*/
|
|
20
|
+
export interface CloudSession {
|
|
21
|
+
readonly apiUrl: string;
|
|
22
|
+
/** A current bearer token, refreshed as needed; see `cloud/tokens.ts`. */
|
|
23
|
+
readonly bearer: Bearer;
|
|
24
|
+
readonly machineKey: string;
|
|
25
|
+
readonly projectKey: string;
|
|
26
|
+
/** The primary checkout, which holds the link. */
|
|
27
|
+
readonly repoRoot: string;
|
|
28
|
+
/** The checkout this session works in: a linked worktree's own root. */
|
|
29
|
+
readonly checkoutRoot: string;
|
|
30
|
+
readonly identity: AgentIdentity | undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The cloud session for a repository: undefined when it is not linked, so
|
|
34
|
+
* Concord stays local. A link this machine cannot use is an error rather than a
|
|
35
|
+
* silent fall back to local state, which no other agent would see.
|
|
36
|
+
*/
|
|
37
|
+
export declare function cloudSessionFor(repoRoot: string, env: NodeJS.ProcessEnv, identity: AgentIdentity | undefined, checkoutRoot?: string): CloudSession | undefined;
|
|
38
|
+
declare const toolArguments: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
39
|
+
type ToolArguments = z.infer<typeof toolArguments>;
|
|
40
|
+
/**
|
|
41
|
+
* An absolute path inside the checkout this session works in, or the primary
|
|
42
|
+
* one, made relative; anything else as given. Tried as written and resolved,
|
|
43
|
+
* so a path through a symlink (`/tmp` on macOS) still matches.
|
|
44
|
+
*/
|
|
45
|
+
export declare function repoRelative(session: Pick<CloudSession, 'repoRoot' | 'checkoutRoot'>, path: string): string;
|
|
46
|
+
/** A tool call's arguments as the cloud should receive them. */
|
|
47
|
+
export declare function forwardedArguments(tool: string, args: ToolArguments, session: Pick<CloudSession, 'identity' | 'repoRoot' | 'checkoutRoot'>): ToolArguments;
|
|
48
|
+
/** Opens an MCP client session with the cloud's `/mcp`, as this repository and machine. */
|
|
49
|
+
export declare function connectCloud(session: CloudSession, fetchImpl?: FetchLike): Promise<Client>;
|
|
50
|
+
/**
|
|
51
|
+
* The stdio-facing server for cloud mode. It connects lazily, on the first
|
|
52
|
+
* request, and again after a failure, so a cold or briefly unreachable API
|
|
53
|
+
* costs one failed call rather than the whole session.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createCloudProxyServer(session: CloudSession, connect: () => Promise<Client>): McpServer;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, relative, sep } from 'node:path';
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { CONCORD_SERVER_INSTRUCTIONS } from '../install/instructions.js';
|
|
8
|
+
import { VERSION } from '../version.js';
|
|
9
|
+
import { HttpClientTransport } from './http-transport.js';
|
|
10
|
+
import { bearerFor } from './tokens.js';
|
|
11
|
+
import { assertKeySafeUrl, sameApi } from './client.js';
|
|
12
|
+
import { readCredentials, readLink, readMachineKey } from './settings.js';
|
|
13
|
+
/**
|
|
14
|
+
* The cloud session for a repository: undefined when it is not linked, so
|
|
15
|
+
* Concord stays local. A link this machine cannot use is an error rather than a
|
|
16
|
+
* silent fall back to local state, which no other agent would see.
|
|
17
|
+
*/
|
|
18
|
+
export function cloudSessionFor(repoRoot, env, identity, checkoutRoot = repoRoot) {
|
|
19
|
+
const link = readLink(repoRoot);
|
|
20
|
+
if (link === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
const credentials = readCredentials(env);
|
|
23
|
+
const machineKey = readMachineKey(env);
|
|
24
|
+
if (credentials === undefined || machineKey === undefined) {
|
|
25
|
+
throw new Error(`${repoRoot} is linked to Concord Cloud, but this machine is not logged in. ` +
|
|
26
|
+
'Run `concord cloud login`, or `concord cloud unlink` to work locally.');
|
|
27
|
+
}
|
|
28
|
+
if (!sameApi(credentials.apiUrl, link.apiUrl)) {
|
|
29
|
+
throw new Error(`${repoRoot} is linked to ${link.apiUrl}, but this machine is logged in to ` +
|
|
30
|
+
`${credentials.apiUrl}. Log in to the linked API, or link again.`);
|
|
31
|
+
}
|
|
32
|
+
assertKeySafeUrl(credentials.apiUrl);
|
|
33
|
+
return {
|
|
34
|
+
apiUrl: credentials.apiUrl,
|
|
35
|
+
bearer: bearerFor(env, credentials.apiUrl, fetch),
|
|
36
|
+
machineKey,
|
|
37
|
+
projectKey: link.projectKey,
|
|
38
|
+
repoRoot,
|
|
39
|
+
checkoutRoot,
|
|
40
|
+
identity,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The tools that act as an agent, and so act as this session's. */
|
|
44
|
+
const WRITE_TOOLS = new Set(['start_work', 'update_work', 'transfer_work', 'finish_work']);
|
|
45
|
+
const toolArguments = z.record(z.string(), z.json());
|
|
46
|
+
/** `path` relative to `root`, or undefined when it is not inside it. */
|
|
47
|
+
function inside(root, path) {
|
|
48
|
+
const within = relative(root, path);
|
|
49
|
+
if (within === '' || within === '..' || within.startsWith(`..${sep}`) || isAbsolute(within)) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return within.split(sep).join('/');
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* An absolute path inside the checkout this session works in, or the primary
|
|
56
|
+
* one, made relative; anything else as given. Tried as written and resolved,
|
|
57
|
+
* so a path through a symlink (`/tmp` on macOS) still matches.
|
|
58
|
+
*/
|
|
59
|
+
export function repoRelative(session, path) {
|
|
60
|
+
if (!isAbsolute(path))
|
|
61
|
+
return path;
|
|
62
|
+
const candidates = existsSync(path) ? [path, realpathSync(path)] : [path];
|
|
63
|
+
for (const root of [session.checkoutRoot, session.repoRoot]) {
|
|
64
|
+
for (const candidate of candidates) {
|
|
65
|
+
const within = inside(root, candidate);
|
|
66
|
+
if (within !== undefined)
|
|
67
|
+
return within;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return path;
|
|
71
|
+
}
|
|
72
|
+
/** A tool call's arguments as the cloud should receive them. */
|
|
73
|
+
export function forwardedArguments(tool, args, session) {
|
|
74
|
+
const forwarded = {};
|
|
75
|
+
for (const [name, value] of Object.entries(args)) {
|
|
76
|
+
forwarded[name] =
|
|
77
|
+
name.endsWith('files') && Array.isArray(value)
|
|
78
|
+
? value.map((item) => (typeof item === 'string' ? repoRelative(session, item) : item))
|
|
79
|
+
: value;
|
|
80
|
+
}
|
|
81
|
+
// The session is the authority, as `resolveActorId` makes it locally.
|
|
82
|
+
const identity = session.identity;
|
|
83
|
+
if (identity !== undefined && WRITE_TOOLS.has(tool)) {
|
|
84
|
+
forwarded['agent_id'] = identity.agentId;
|
|
85
|
+
if (tool === 'start_work')
|
|
86
|
+
forwarded['kind'] = identity.kind;
|
|
87
|
+
}
|
|
88
|
+
return forwarded;
|
|
89
|
+
}
|
|
90
|
+
/** Opens an MCP client session with the cloud's `/mcp`, as this repository and machine. */
|
|
91
|
+
export async function connectCloud(session, fetchImpl) {
|
|
92
|
+
const transport = new HttpClientTransport(new URL(`${session.apiUrl.replace(/\/+$/, '')}/mcp`), {
|
|
93
|
+
'x-concord-project': session.projectKey,
|
|
94
|
+
'x-concord-machine': session.machineKey,
|
|
95
|
+
},
|
|
96
|
+
// The token is fetched per request, so a long session is never sent with
|
|
97
|
+
// one that has expired since it connected.
|
|
98
|
+
async (input, init) => {
|
|
99
|
+
const headers = new Headers(init?.headers);
|
|
100
|
+
headers.set('Authorization', `Bearer ${await session.bearer()}`);
|
|
101
|
+
return (fetchImpl ?? fetch)(input, { ...init, headers });
|
|
102
|
+
});
|
|
103
|
+
const client = new Client({ name: 'concord-mcp', version: VERSION });
|
|
104
|
+
await client.connect(transport);
|
|
105
|
+
return client;
|
|
106
|
+
}
|
|
107
|
+
function failure(reason) {
|
|
108
|
+
return {
|
|
109
|
+
isError: true,
|
|
110
|
+
content: [{ type: 'text', text: `Concord Cloud could not be reached: ${reason}` }],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The stdio-facing server for cloud mode. It connects lazily, on the first
|
|
115
|
+
* request, and again after a failure, so a cold or briefly unreachable API
|
|
116
|
+
* costs one failed call rather than the whole session.
|
|
117
|
+
*/
|
|
118
|
+
export function createCloudProxyServer(session, connect) {
|
|
119
|
+
const server = new McpServer({ name: 'concord-mcp', version: VERSION }, { instructions: CONCORD_SERVER_INSTRUCTIONS, capabilities: { tools: {} } });
|
|
120
|
+
// One client, shared; dropped whenever a connection or a call through it
|
|
121
|
+
// fails, so the next call connects afresh instead of reusing a broken one.
|
|
122
|
+
// A tool's own error comes back as a result, never as a failure here.
|
|
123
|
+
let pending;
|
|
124
|
+
const forget = (attempt) => {
|
|
125
|
+
if (pending === attempt)
|
|
126
|
+
pending = undefined;
|
|
127
|
+
};
|
|
128
|
+
const cloud = () => {
|
|
129
|
+
if (pending === undefined) {
|
|
130
|
+
const attempt = connect();
|
|
131
|
+
pending = attempt;
|
|
132
|
+
attempt.catch(() => {
|
|
133
|
+
forget(attempt);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return pending;
|
|
137
|
+
};
|
|
138
|
+
server.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
139
|
+
const attempt = cloud();
|
|
140
|
+
try {
|
|
141
|
+
return await (await attempt).listTools();
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
forget(attempt);
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
server.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
149
|
+
const attempt = cloud();
|
|
150
|
+
try {
|
|
151
|
+
const { name } = request.params;
|
|
152
|
+
const args = toolArguments.parse(request.params.arguments ?? {});
|
|
153
|
+
return await (await attempt).callTool({ name, arguments: forwardedArguments(name, args, session) });
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
forget(attempt);
|
|
157
|
+
return failure(error instanceof Error ? error.message : String(error));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return server;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/cloud/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAe,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AA6B1E;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAgB,EAChB,GAAsB,EACtB,QAAmC,EACnC,eAAuB,QAAQ;IAE/B,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAEzC,MAAM,WAAW,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,UAAU,GAA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