@superforge/infra 0.1.0 → 0.2.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 +50 -33
- package/output/agents.d.ts +50 -69
- package/output/agents.js +120 -85
- package/output/choose.d.ts +3 -1
- package/output/choose.js +20 -13
- package/output/client.d.ts +10 -9
- package/output/client.js +85 -106
- package/output/contract/agents.d.ts +203 -0
- package/output/contract/agents.js +94 -0
- package/output/contract/comments.d.ts +101 -0
- package/output/contract/comments.js +66 -0
- package/output/contract/errors.d.ts +123 -0
- package/output/contract/errors.js +61 -0
- package/output/contract/index.d.ts +6 -0
- package/output/contract/index.js +11 -0
- package/output/contract/login.d.ts +152 -0
- package/output/contract/login.js +93 -0
- package/output/contract/people.d.ts +9 -0
- package/output/contract/people.js +16 -0
- package/output/contract/project.d.ts +38 -0
- package/output/contract/project.js +36 -0
- package/output/index.d.ts +4 -4
- package/output/index.js +10 -6
- package/output/infra.d.ts +44 -58
- package/output/primitives.d.ts +0 -8
- package/output/primitives.js +0 -7
- package/output/stand-in.d.ts +18 -16
- package/output/stand-in.js +74 -39
- package/output/version.d.ts +4 -0
- package/output/version.js +10 -0
- package/package.json +5 -1
- package/output/answers.d.ts +0 -154
- package/output/answers.js +0 -153
- package/output/comments.d.ts +0 -37
- package/output/comments.js +0 -58
package/output/client.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
+
import { type AppPaths } from "./contract/index.js";
|
|
1
2
|
import type { Infra } from "./infra.js";
|
|
2
|
-
/**
|
|
3
|
-
* Infra's API, which a project's keys call. A server can be pointed at
|
|
4
|
-
* another Infra with `INFRA_URL` (choose.ts).
|
|
5
|
-
*/
|
|
3
|
+
/** Infra's API, which a project's keys call */
|
|
6
4
|
export declare const INFRA_URL = "https://infra.superforge.studio/v1";
|
|
7
5
|
/**
|
|
8
6
|
* Infra, called over HTTP with a project's key: a secret key in a build, a
|
|
9
7
|
* test key in a dev server. No call is retried, since none is safe to send
|
|
10
8
|
* twice (a second start sends a second email, a second verify finds the
|
|
11
|
-
* code spent, and a comment sent again is kept twice); the
|
|
12
|
-
* again instead. `
|
|
9
|
+
* code spent, and a comment sent again is kept twice); the person asks
|
|
10
|
+
* again instead. `url` is Infra's own, but for Infra's tests and a dev
|
|
11
|
+
* server working on Infra; `send` is `fetch`, or a test's own; `paths` is
|
|
12
|
+
* where the app answers Claude's login, when not `APP_PATHS`.
|
|
13
13
|
*
|
|
14
|
+
* Every call says which release of the package made it (`Infra-Client`).
|
|
14
15
|
* Every answer is logged with its call and status, and a refusal with its
|
|
15
|
-
*
|
|
16
|
-
* it (Infra's README, "Errors"), so an app's logs say why a call failed.
|
|
16
|
+
* reason and Infra's message, so an app's logs say why a call failed.
|
|
17
17
|
*/
|
|
18
|
-
export declare function infraClient({ key, url, send }: {
|
|
18
|
+
export declare function infraClient({ key, url, send, paths }: {
|
|
19
19
|
key: string;
|
|
20
20
|
url?: string;
|
|
21
21
|
send?: typeof fetch;
|
|
22
|
+
paths?: AppPaths;
|
|
22
23
|
}): Infra;
|
package/output/client.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { checkToken, infraKeys, passOAuth } from "./agents.js";
|
|
2
|
+
import { APP_PATHS, agent_connections, agent_ended, agent_redirect, agent_refused, agent_request, CLIENT_HEADER, comment_refused, infra_failure, infra_project, kept_comment, start_refused, started_login, verified_login, verify_refused } from "./contract/index.js";
|
|
3
3
|
import { SECOND } from "./primitives.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* another Infra with `INFRA_URL` (choose.ts).
|
|
7
|
-
*/
|
|
4
|
+
import { CLIENT } from "./version.js";
|
|
5
|
+
/** Infra's API, which a project's keys call */
|
|
8
6
|
export const INFRA_URL = "https://infra.superforge.studio/v1";
|
|
9
7
|
// How long a call waits for Infra's answer. Starting a login waits on
|
|
10
8
|
// Infra sending the email, which takes a second or two.
|
|
@@ -13,25 +11,29 @@ const TIMEOUT = 15 * SECOND;
|
|
|
13
11
|
* Infra, called over HTTP with a project's key: a secret key in a build, a
|
|
14
12
|
* test key in a dev server. No call is retried, since none is safe to send
|
|
15
13
|
* twice (a second start sends a second email, a second verify finds the
|
|
16
|
-
* code spent, and a comment sent again is kept twice); the
|
|
17
|
-
* again instead. `
|
|
14
|
+
* code spent, and a comment sent again is kept twice); the person asks
|
|
15
|
+
* again instead. `url` is Infra's own, but for Infra's tests and a dev
|
|
16
|
+
* server working on Infra; `send` is `fetch`, or a test's own; `paths` is
|
|
17
|
+
* where the app answers Claude's login, when not `APP_PATHS`.
|
|
18
18
|
*
|
|
19
|
+
* Every call says which release of the package made it (`Infra-Client`).
|
|
19
20
|
* Every answer is logged with its call and status, and a refusal with its
|
|
20
|
-
*
|
|
21
|
-
* it (Infra's README, "Errors"), so an app's logs say why a call failed.
|
|
21
|
+
* reason and Infra's message, so an app's logs say why a call failed.
|
|
22
22
|
*/
|
|
23
|
-
export function infraClient({ key, url = INFRA_URL, send = fetch }) {
|
|
23
|
+
export function infraClient({ key, url = INFRA_URL, send = fetch, paths = APP_PATHS }) {
|
|
24
24
|
// One call: its status and its JSON, or why there's none, which is
|
|
25
25
|
// logged
|
|
26
26
|
async function ask(method, call, body) {
|
|
27
|
+
const headers = {
|
|
28
|
+
Authorization: `Bearer ${key}`,
|
|
29
|
+
[CLIENT_HEADER]: CLIENT
|
|
30
|
+
};
|
|
31
|
+
if (body !== undefined) {
|
|
32
|
+
headers["Content-Type"] = "application/json";
|
|
33
|
+
}
|
|
27
34
|
const response = await send(`${url}${call}`, {
|
|
28
35
|
method,
|
|
29
|
-
headers
|
|
30
|
-
? { Authorization: `Bearer ${key}` }
|
|
31
|
-
: {
|
|
32
|
-
Authorization: `Bearer ${key}`,
|
|
33
|
-
"Content-Type": "application/json"
|
|
34
|
-
},
|
|
36
|
+
headers,
|
|
35
37
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
36
38
|
signal: AbortSignal.timeout(TIMEOUT)
|
|
37
39
|
}).catch((error) => {
|
|
@@ -39,7 +41,7 @@ export function infraClient({ key, url = INFRA_URL, send = fetch }) {
|
|
|
39
41
|
return null;
|
|
40
42
|
});
|
|
41
43
|
if (response === null) {
|
|
42
|
-
return unavailable(`Infra didn't answer ${call} at ${url}. It may be down
|
|
44
|
+
return unavailable(`Infra didn't answer ${call} at ${url}. It may be down; trying again in a few minutes may work.`);
|
|
43
45
|
}
|
|
44
46
|
const json = await response.json().catch((error) => {
|
|
45
47
|
console.error("Infra answered without JSON", {
|
|
@@ -50,15 +52,15 @@ export function infraClient({ key, url = INFRA_URL, send = fetch }) {
|
|
|
50
52
|
return undefined;
|
|
51
53
|
});
|
|
52
54
|
if (json === undefined) {
|
|
53
|
-
return unavailable(`Infra answered ${call} with ${response.status} and no JSON, which usually means it's down
|
|
55
|
+
return unavailable(`Infra answered ${call} with ${response.status} and no JSON, which usually means it's down. Trying again in a few minutes may work.`);
|
|
54
56
|
}
|
|
55
|
-
const
|
|
56
|
-
if (response.status >= 400 &&
|
|
57
|
+
const failure = infra_failure.safeParse(json);
|
|
58
|
+
if (response.status >= 400 && failure.success) {
|
|
57
59
|
console.info("Infra refused a call", {
|
|
58
60
|
call,
|
|
59
61
|
status: response.status,
|
|
60
|
-
|
|
61
|
-
message:
|
|
62
|
+
reason: failure.data.error.reason,
|
|
63
|
+
message: failure.data.error.message
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
66
|
else {
|
|
@@ -66,28 +68,27 @@ export function infraClient({ key, url = INFRA_URL, send = fetch }) {
|
|
|
66
68
|
}
|
|
67
69
|
return { ok: true, data: { status: response.status, json } };
|
|
68
70
|
}
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
//
|
|
71
|
+
// An answer read with `schema` when it's `status`, else as one of the
|
|
72
|
+
// call's `refused`, else as one the client can't act on: unavailable,
|
|
73
|
+
// in Infra's own words
|
|
72
74
|
async function answered(asked, call, expected, refused) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
const answer = await asked;
|
|
76
|
+
if (!answer.ok) {
|
|
77
|
+
return answer;
|
|
75
78
|
}
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
const parsed = expected.schema.safeParse(
|
|
79
|
+
const { status, json } = answer.data;
|
|
80
|
+
if (status === expected.status) {
|
|
81
|
+
const parsed = expected.schema.safeParse(json);
|
|
79
82
|
return parsed.success
|
|
80
83
|
? { ok: true, data: parsed.data }
|
|
81
|
-
: unreadable(call, answer);
|
|
84
|
+
: unreadable(call, answer.data);
|
|
82
85
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return parsed.
|
|
86
|
-
? { ok: false, error: parsed.data }
|
|
87
|
-
: unexpected(call, answer);
|
|
86
|
+
const parsed = refused?.safeParse(json);
|
|
87
|
+
if (parsed?.success) {
|
|
88
|
+
return { ok: false, error: parsed.data };
|
|
88
89
|
}
|
|
89
90
|
else {
|
|
90
|
-
return unexpected(call, answer);
|
|
91
|
+
return unexpected(call, answer.data);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
// Claude's login (agents.ts): Infra's public keys, fetched once and
|
|
@@ -95,33 +96,28 @@ export function infraClient({ key, url = INFRA_URL, send = fetch }) {
|
|
|
95
96
|
// is, which every token must be for, asked once
|
|
96
97
|
const keys = infraKeys(url);
|
|
97
98
|
let project;
|
|
98
|
-
|
|
99
|
+
function projectOf() {
|
|
99
100
|
const call = "/project";
|
|
100
|
-
return answered(
|
|
101
|
+
return answered(ask("GET", call), call, {
|
|
101
102
|
status: 200,
|
|
102
103
|
schema: infra_project
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
|
-
// A call about Claude's requests and connections: its answer, or why
|
|
106
|
-
// Infra refused it, or that it couldn't be asked
|
|
107
|
-
async function agents(method, call, schema, body) {
|
|
108
|
-
return answered(await ask(method, call, body), call, { status: 200, schema }, agent_refused);
|
|
109
|
-
}
|
|
110
106
|
return {
|
|
111
107
|
project() {
|
|
112
108
|
return projectOf();
|
|
113
109
|
},
|
|
114
|
-
|
|
110
|
+
startLogin(request) {
|
|
115
111
|
const call = "/login/start";
|
|
116
|
-
return answered(
|
|
112
|
+
return answered(ask("POST", call, request), call, { status: 200, schema: started_login }, start_refused);
|
|
117
113
|
},
|
|
118
|
-
|
|
114
|
+
verifyLogin(proof) {
|
|
119
115
|
const call = "/login/verify";
|
|
120
|
-
return answered(
|
|
116
|
+
return answered(ask("POST", call, proof), call, { status: 200, schema: verified_login }, verify_refused);
|
|
121
117
|
},
|
|
122
118
|
async fileComment(comment) {
|
|
123
119
|
const call = "/comments";
|
|
124
|
-
const filed = await answered(
|
|
120
|
+
const filed = await answered(ask("POST", call, comment), call, { status: 201, schema: kept_comment }, comment_refused);
|
|
125
121
|
if (!filed.ok && filed.error.reason !== "unavailable") {
|
|
126
122
|
// What the app sent is wrong, which only a change to it
|
|
127
123
|
// fixes
|
|
@@ -132,44 +128,46 @@ export function infraClient({ key, url = INFRA_URL, send = fetch }) {
|
|
|
132
128
|
}
|
|
133
129
|
return filed;
|
|
134
130
|
},
|
|
135
|
-
passOAuth(request,
|
|
136
|
-
return
|
|
131
|
+
passOAuth(request, call, origin) {
|
|
132
|
+
return passOAuth({ url, key, send, paths, request, call, origin });
|
|
137
133
|
},
|
|
138
134
|
async agentRequest(request_id) {
|
|
139
|
-
const
|
|
135
|
+
const call = `/agents/requests/${request_id}`;
|
|
136
|
+
const asked = await answered(ask("GET", call), call, { status: 200, schema: agent_request }, agent_refused);
|
|
140
137
|
return asked.ok ? { ok: true, data: asked.data.request } : asked;
|
|
141
138
|
},
|
|
142
139
|
allowAgent(request_id, allowed) {
|
|
143
|
-
|
|
140
|
+
const call = `/agents/requests/${request_id}/allow`;
|
|
141
|
+
return answered(ask("POST", call, allowed), call, { status: 200, schema: agent_redirect }, agent_refused);
|
|
144
142
|
},
|
|
145
143
|
denyAgent(request_id) {
|
|
146
|
-
|
|
144
|
+
const call = `/agents/requests/${request_id}/deny`;
|
|
145
|
+
return answered(ask("POST", call, {}), call, { status: 200, schema: agent_redirect }, agent_refused);
|
|
147
146
|
},
|
|
148
|
-
async agentConnections(
|
|
149
|
-
const
|
|
150
|
-
const listed = await
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
147
|
+
async agentConnections(user_id) {
|
|
148
|
+
const call = `/agents/connections?${new URLSearchParams({ user_id })}`;
|
|
149
|
+
const listed = await answered(ask("GET", call), call, {
|
|
150
|
+
status: 200,
|
|
151
|
+
schema: agent_connections
|
|
152
|
+
});
|
|
153
|
+
return listed.ok
|
|
154
|
+
? { ok: true, data: listed.data.connections }
|
|
155
|
+
: listed;
|
|
157
156
|
},
|
|
158
157
|
async endAgentConnection(connection_id) {
|
|
159
|
-
const
|
|
158
|
+
const call = `/agents/connections/${connection_id}`;
|
|
159
|
+
const ended = await answered(ask("DELETE", call), call, { status: 200, schema: agent_ended }, agent_refused);
|
|
160
160
|
return ended.ok ? { ok: true, data: null } : ended;
|
|
161
161
|
},
|
|
162
|
-
async endAgentConnections(
|
|
163
|
-
const
|
|
164
|
-
const ended = await
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return { ok: false, error: asUnavailable(ended.error) };
|
|
170
|
-
}
|
|
162
|
+
async endAgentConnections(user_id) {
|
|
163
|
+
const call = `/agents/connections?${new URLSearchParams({ user_id })}`;
|
|
164
|
+
const ended = await answered(ask("DELETE", call), call, {
|
|
165
|
+
status: 200,
|
|
166
|
+
schema: agent_ended
|
|
167
|
+
});
|
|
168
|
+
return ended.ok ? { ok: true, data: ended.data.ended } : ended;
|
|
171
169
|
},
|
|
172
|
-
async checkAgentToken(token,
|
|
170
|
+
async checkAgentToken(token, expected) {
|
|
173
171
|
project ??= projectOf();
|
|
174
172
|
const known = await project;
|
|
175
173
|
if (!known.ok) {
|
|
@@ -181,7 +179,7 @@ export function infraClient({ key, url = INFRA_URL, send = fetch }) {
|
|
|
181
179
|
}
|
|
182
180
|
else {
|
|
183
181
|
return await checkToken(keys, token, {
|
|
184
|
-
|
|
182
|
+
...expected,
|
|
185
183
|
project: known.data.project.id,
|
|
186
184
|
mode: known.data.mode
|
|
187
185
|
});
|
|
@@ -193,42 +191,23 @@ export function infraClient({ key, url = INFRA_URL, send = fetch }) {
|
|
|
193
191
|
function unavailable(message) {
|
|
194
192
|
return { ok: false, error: { reason: "unavailable", message } };
|
|
195
193
|
}
|
|
196
|
-
// A refusal
|
|
197
|
-
//
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return refused;
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
return { reason: "unavailable", message: refused.message };
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
// An answer the client doesn't expect: a key Infra refused (401, which an
|
|
207
|
-
// owner fixes in Railway), a body this app sent wrong (400 `invalid`, a
|
|
208
|
-
// bug), or an error Infra added after this version of the package. Logged
|
|
209
|
-
// with what it said, and unavailable, with Infra's own words for why when
|
|
210
|
-
// it gave them, which an app shows its team.
|
|
194
|
+
// A refusal the app has no branch for: a key Infra refused (401, which an
|
|
195
|
+
// owner fixes in Railway) or a body this app sent wrong (400 `invalid`, a
|
|
196
|
+
// bug). Logged, and unavailable, in Infra's own words, which an app shows
|
|
197
|
+
// its team.
|
|
211
198
|
function unexpected(call, answer) {
|
|
212
|
-
|
|
213
|
-
const error = refusal.success ? refusal.data.error : null;
|
|
214
|
-
const said = refusal.success ? refusal.data.message : undefined;
|
|
215
|
-
console.error("Infra answered what the client doesn't expect", {
|
|
199
|
+
console.error("Infra refused a call the app can't act on", {
|
|
216
200
|
call,
|
|
217
201
|
status: answer.status,
|
|
218
202
|
answer: answer.json
|
|
219
203
|
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return unavailable(`Infra refused this app's key${error === null ? "" : ` (${error})`}. Make a secret key on superforge.studio, in the project's Settings, and paste it into INFRA_SECRET_KEY on the app's service in Railway.`);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
return unavailable(`Infra answered ${call} with ${answer.status}${error === null ? "" : ` ${error}`}, which this version of @superforge/infra doesn't know. Ask Claude to update @superforge/infra in the app.`);
|
|
228
|
-
}
|
|
204
|
+
const failure = infra_failure.safeParse(answer.json);
|
|
205
|
+
return unavailable(failure.success
|
|
206
|
+
? failure.data.error.message
|
|
207
|
+
: `Infra answered ${call} with ${answer.status}, in a shape this version of @superforge/infra can't read. Ask Claude to update @superforge/infra in the app.`);
|
|
229
208
|
}
|
|
230
|
-
// A success the client can't read: Infra
|
|
231
|
-
//
|
|
209
|
+
// A success the client can't read: Infra answers a shape this release of
|
|
210
|
+
// the package doesn't know
|
|
232
211
|
function unreadable(call, answer) {
|
|
233
212
|
console.error("Infra answered in a shape the client can't read", {
|
|
234
213
|
call,
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** What someone on the app's team lets Claude do through its MCP */
|
|
3
|
+
export declare const AGENT_SCOPES: readonly ["read", "act"];
|
|
4
|
+
export declare const agent_scope: z.ZodEnum<{
|
|
5
|
+
read: "read";
|
|
6
|
+
act: "act";
|
|
7
|
+
}>;
|
|
8
|
+
export type AgentScope = z.infer<typeof agent_scope>;
|
|
9
|
+
/**
|
|
10
|
+
* The header the app's server sends Claude's OAuth calls on with: where
|
|
11
|
+
* Claude reached the app, `https://vmdsystem.com`, its tokens' issuer.
|
|
12
|
+
* Only a header can carry it, since the call's body and query are Claude's.
|
|
13
|
+
*/
|
|
14
|
+
export declare const APP_ORIGIN_HEADER = "App-Origin";
|
|
15
|
+
/**
|
|
16
|
+
* Where the app answers Claude's login, which its OAuth metadata names and
|
|
17
|
+
* its authorize call sends the browser to: its OAuth calls (`/oauth`, then
|
|
18
|
+
* `/authorize`, `/token`, `/register` and `/revoke`), and its Allow page
|
|
19
|
+
* (`/connect`, then the request's ID). An app with others gives its own to
|
|
20
|
+
* `chooseInfra`; Infra keeps none.
|
|
21
|
+
*/
|
|
22
|
+
export type AppPaths = {
|
|
23
|
+
oauth: string;
|
|
24
|
+
allow: string;
|
|
25
|
+
};
|
|
26
|
+
export declare const APP_PATHS: AppPaths;
|
|
27
|
+
/** The OAuth calls Claude makes, which the app passes on */
|
|
28
|
+
export declare const OAUTH_CALLS: readonly ["authorize", "token", "register", "revoke"];
|
|
29
|
+
export type OAuthCall = (typeof OAUTH_CALLS)[number];
|
|
30
|
+
/**
|
|
31
|
+
* What `GET /v1/agents/oauth/authorize` answers the app: the request Claude
|
|
32
|
+
* made, for the browser to go to the app's Allow page with, or where it
|
|
33
|
+
* goes back to Claude with an error
|
|
34
|
+
*/
|
|
35
|
+
export declare const agent_authorized: z.ZodUnion<readonly [z.ZodObject<{
|
|
36
|
+
request: z.ZodObject<{
|
|
37
|
+
id: z.ZodUUID;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
40
|
+
redirect_to: z.ZodURL;
|
|
41
|
+
}, z.core.$strip>]>;
|
|
42
|
+
/** Why authorize sends nothing back to Claude: answered as plain words */
|
|
43
|
+
export declare const authorize_refused: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
|
|
44
|
+
error: z.ZodObject<{
|
|
45
|
+
reason: z.ZodLiteral<"unknown-client">;
|
|
46
|
+
message: z.ZodString;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
49
|
+
reason: "unknown-client";
|
|
50
|
+
message: string;
|
|
51
|
+
}, {
|
|
52
|
+
error: {
|
|
53
|
+
reason: "unknown-client";
|
|
54
|
+
message: string;
|
|
55
|
+
};
|
|
56
|
+
}>>, z.ZodPipe<z.ZodObject<{
|
|
57
|
+
error: z.ZodObject<{
|
|
58
|
+
reason: z.ZodLiteral<"unknown-origin">;
|
|
59
|
+
message: z.ZodString;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
62
|
+
reason: "unknown-origin";
|
|
63
|
+
message: string;
|
|
64
|
+
}, {
|
|
65
|
+
error: {
|
|
66
|
+
reason: "unknown-origin";
|
|
67
|
+
message: string;
|
|
68
|
+
};
|
|
69
|
+
}>>, z.ZodPipe<z.ZodObject<{
|
|
70
|
+
error: z.ZodObject<{
|
|
71
|
+
reason: z.ZodLiteral<"invalid">;
|
|
72
|
+
message: z.ZodString;
|
|
73
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
74
|
+
path: z.ZodString;
|
|
75
|
+
message: z.ZodString;
|
|
76
|
+
}, z.core.$strip>>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
79
|
+
reason: "invalid";
|
|
80
|
+
message: string;
|
|
81
|
+
issues: {
|
|
82
|
+
path: string;
|
|
83
|
+
message: string;
|
|
84
|
+
}[];
|
|
85
|
+
}, {
|
|
86
|
+
error: {
|
|
87
|
+
reason: "invalid";
|
|
88
|
+
message: string;
|
|
89
|
+
issues: {
|
|
90
|
+
path: string;
|
|
91
|
+
message: string;
|
|
92
|
+
}[];
|
|
93
|
+
};
|
|
94
|
+
}>>]>;
|
|
95
|
+
/** `GET /v1/agents/requests/:request_id`: what the Allow page shows */
|
|
96
|
+
export declare const agent_request: z.ZodObject<{
|
|
97
|
+
request: z.ZodObject<{
|
|
98
|
+
id: z.ZodString;
|
|
99
|
+
client_name: z.ZodString;
|
|
100
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
101
|
+
read: "read";
|
|
102
|
+
act: "act";
|
|
103
|
+
}>>;
|
|
104
|
+
resource: z.ZodString;
|
|
105
|
+
expires_at: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
export type AgentRequest = z.output<typeof agent_request>["request"];
|
|
109
|
+
/** `POST /v1/agents/requests/:request_id/allow`: who allowed what */
|
|
110
|
+
export declare const agent_allow: z.ZodObject<{
|
|
111
|
+
user_id: z.ZodString;
|
|
112
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
113
|
+
read: "read";
|
|
114
|
+
act: "act";
|
|
115
|
+
}>>;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
export type AgentAllow = z.input<typeof agent_allow>;
|
|
118
|
+
/** What allowing or denying answers: where the browser goes back to Claude */
|
|
119
|
+
export declare const agent_redirect: z.ZodObject<{
|
|
120
|
+
redirect_to: z.ZodURL;
|
|
121
|
+
}, z.core.$strip>;
|
|
122
|
+
/** `GET` and `DELETE /v1/agents/connections?user_id=…`: whose */
|
|
123
|
+
export declare const connections_query: z.ZodObject<{
|
|
124
|
+
user_id: z.ZodString;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
/** One of Claude's connections, as the app's Connected list shows it */
|
|
127
|
+
export declare const agent_connection: z.ZodObject<{
|
|
128
|
+
id: z.ZodString;
|
|
129
|
+
user_id: z.ZodString;
|
|
130
|
+
client_name: z.ZodString;
|
|
131
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
132
|
+
read: "read";
|
|
133
|
+
act: "act";
|
|
134
|
+
}>>;
|
|
135
|
+
resource: z.ZodString;
|
|
136
|
+
last_used_at: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
137
|
+
created_at: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
138
|
+
}, z.core.$strip>;
|
|
139
|
+
export type AgentConnection = z.output<typeof agent_connection>;
|
|
140
|
+
/** `GET /v1/agents/connections?user_id=…`: theirs, oldest first */
|
|
141
|
+
export declare const agent_connections: z.ZodObject<{
|
|
142
|
+
connections: z.ZodArray<z.ZodObject<{
|
|
143
|
+
id: z.ZodString;
|
|
144
|
+
user_id: z.ZodString;
|
|
145
|
+
client_name: z.ZodString;
|
|
146
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
147
|
+
read: "read";
|
|
148
|
+
act: "act";
|
|
149
|
+
}>>;
|
|
150
|
+
resource: z.ZodString;
|
|
151
|
+
last_used_at: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
152
|
+
created_at: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
153
|
+
}, z.core.$strip>>;
|
|
154
|
+
}, z.core.$strip>;
|
|
155
|
+
/** What ending connections answers: how many it ended */
|
|
156
|
+
export declare const agent_ended: z.ZodObject<{
|
|
157
|
+
ended: z.ZodNumber;
|
|
158
|
+
}, z.core.$strip>;
|
|
159
|
+
/** Why Infra refused a call about a request or a connection */
|
|
160
|
+
export declare const agent_refused: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
|
|
161
|
+
error: z.ZodObject<{
|
|
162
|
+
reason: z.ZodLiteral<"not-found">;
|
|
163
|
+
message: z.ZodString;
|
|
164
|
+
}, z.core.$strip>;
|
|
165
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
166
|
+
reason: "not-found";
|
|
167
|
+
message: string;
|
|
168
|
+
}, {
|
|
169
|
+
error: {
|
|
170
|
+
reason: "not-found";
|
|
171
|
+
message: string;
|
|
172
|
+
};
|
|
173
|
+
}>>, z.ZodPipe<z.ZodObject<{
|
|
174
|
+
error: z.ZodObject<{
|
|
175
|
+
reason: z.ZodLiteral<"not-asked">;
|
|
176
|
+
message: z.ZodString;
|
|
177
|
+
}, z.core.$strip>;
|
|
178
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
179
|
+
reason: "not-asked";
|
|
180
|
+
message: string;
|
|
181
|
+
}, {
|
|
182
|
+
error: {
|
|
183
|
+
reason: "not-asked";
|
|
184
|
+
message: string;
|
|
185
|
+
};
|
|
186
|
+
}>>]>;
|
|
187
|
+
export type AgentRefused = z.output<typeof agent_refused>;
|
|
188
|
+
/**
|
|
189
|
+
* What an access token Infra signs says, beyond its issuer (the app's
|
|
190
|
+
* origin), audience (the address it's for), and expiry: whom Claude acts as
|
|
191
|
+
* (`sub`, the app's user ID), what they allowed (`scope`, space-separated),
|
|
192
|
+
* the project and mode, and the connection it's from
|
|
193
|
+
*/
|
|
194
|
+
export declare const agent_claims: z.ZodObject<{
|
|
195
|
+
sub: z.ZodString;
|
|
196
|
+
scope: z.ZodString;
|
|
197
|
+
project: z.ZodString;
|
|
198
|
+
mode: z.ZodEnum<{
|
|
199
|
+
live: "live";
|
|
200
|
+
test: "test";
|
|
201
|
+
}>;
|
|
202
|
+
connection: z.ZodString;
|
|
203
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { invalid_refusal, not_found_refusal, refusal } from "./errors.js";
|
|
3
|
+
import { user_id } from "./people.js";
|
|
4
|
+
import { key_mode } from "./project.js";
|
|
5
|
+
// Claude logging in to an app's own MCP, through Infra, under
|
|
6
|
+
// `/v1/agents`: Infra is the OAuth server every app shares, so the app
|
|
7
|
+
// never builds one. Claude only ever talks to the app; the app's server
|
|
8
|
+
// passes its OAuth calls on to `/v1/agents/oauth/*`, its Allow page and
|
|
9
|
+
// account page call the rest, and it checks the tokens Infra signs with
|
|
10
|
+
// Infra's public keys, without calling Infra. Infra's README, "Claude",
|
|
11
|
+
// has the flow.
|
|
12
|
+
/** What someone on the app's team lets Claude do through its MCP */
|
|
13
|
+
export const AGENT_SCOPES = ["read", "act"];
|
|
14
|
+
export const agent_scope = z.enum(AGENT_SCOPES);
|
|
15
|
+
/**
|
|
16
|
+
* The header the app's server sends Claude's OAuth calls on with: where
|
|
17
|
+
* Claude reached the app, `https://vmdsystem.com`, its tokens' issuer.
|
|
18
|
+
* Only a header can carry it, since the call's body and query are Claude's.
|
|
19
|
+
*/
|
|
20
|
+
export const APP_ORIGIN_HEADER = "App-Origin";
|
|
21
|
+
export const APP_PATHS = { oauth: "/oauth", allow: "/connect" };
|
|
22
|
+
/** The OAuth calls Claude makes, which the app passes on */
|
|
23
|
+
export const OAUTH_CALLS = ["authorize", "token", "register", "revoke"];
|
|
24
|
+
/**
|
|
25
|
+
* What `GET /v1/agents/oauth/authorize` answers the app: the request Claude
|
|
26
|
+
* made, for the browser to go to the app's Allow page with, or where it
|
|
27
|
+
* goes back to Claude with an error
|
|
28
|
+
*/
|
|
29
|
+
export const agent_authorized = z.union([
|
|
30
|
+
z.object({ request: z.object({ id: z.uuid() }) }),
|
|
31
|
+
z.object({ redirect_to: z.url() })
|
|
32
|
+
]);
|
|
33
|
+
/** Why authorize sends nothing back to Claude: answered as plain words */
|
|
34
|
+
export const authorize_refused = z.union([
|
|
35
|
+
refusal("unknown-client", {}),
|
|
36
|
+
refusal("unknown-origin", {}),
|
|
37
|
+
invalid_refusal
|
|
38
|
+
]);
|
|
39
|
+
/** `GET /v1/agents/requests/:request_id`: what the Allow page shows */
|
|
40
|
+
export const agent_request = z.object({
|
|
41
|
+
request: z.object({
|
|
42
|
+
id: z.string(),
|
|
43
|
+
client_name: z.string(),
|
|
44
|
+
scopes: z.array(agent_scope),
|
|
45
|
+
// The address Claude asked to use, which its tokens are good for:
|
|
46
|
+
// the app's MCP
|
|
47
|
+
resource: z.string(),
|
|
48
|
+
expires_at: z.iso.datetime().transform((value) => new Date(value))
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
/** `POST /v1/agents/requests/:request_id/allow`: who allowed what */
|
|
52
|
+
export const agent_allow = z.object({
|
|
53
|
+
user_id,
|
|
54
|
+
scopes: z.array(agent_scope).min(1)
|
|
55
|
+
});
|
|
56
|
+
/** What allowing or denying answers: where the browser goes back to Claude */
|
|
57
|
+
export const agent_redirect = z.object({ redirect_to: z.url() });
|
|
58
|
+
/** `GET` and `DELETE /v1/agents/connections?user_id=…`: whose */
|
|
59
|
+
export const connections_query = z.object({ user_id });
|
|
60
|
+
/** One of Claude's connections, as the app's Connected list shows it */
|
|
61
|
+
export const agent_connection = z.object({
|
|
62
|
+
id: z.string(),
|
|
63
|
+
user_id: z.string(),
|
|
64
|
+
client_name: z.string(),
|
|
65
|
+
scopes: z.array(agent_scope),
|
|
66
|
+
resource: z.string(),
|
|
67
|
+
// When Claude last refreshed it, to within about ten minutes
|
|
68
|
+
last_used_at: z.iso.datetime().transform((value) => new Date(value)),
|
|
69
|
+
created_at: z.iso.datetime().transform((value) => new Date(value))
|
|
70
|
+
});
|
|
71
|
+
/** `GET /v1/agents/connections?user_id=…`: theirs, oldest first */
|
|
72
|
+
export const agent_connections = z.object({
|
|
73
|
+
connections: z.array(agent_connection)
|
|
74
|
+
});
|
|
75
|
+
/** What ending connections answers: how many it ended */
|
|
76
|
+
export const agent_ended = z.object({ ended: z.number().int() });
|
|
77
|
+
/** Why Infra refused a call about a request or a connection */
|
|
78
|
+
export const agent_refused = z.union([
|
|
79
|
+
not_found_refusal,
|
|
80
|
+
refusal("not-asked", {})
|
|
81
|
+
]);
|
|
82
|
+
/**
|
|
83
|
+
* What an access token Infra signs says, beyond its issuer (the app's
|
|
84
|
+
* origin), audience (the address it's for), and expiry: whom Claude acts as
|
|
85
|
+
* (`sub`, the app's user ID), what they allowed (`scope`, space-separated),
|
|
86
|
+
* the project and mode, and the connection it's from
|
|
87
|
+
*/
|
|
88
|
+
export const agent_claims = z.object({
|
|
89
|
+
sub: z.string(),
|
|
90
|
+
scope: z.string(),
|
|
91
|
+
project: z.string(),
|
|
92
|
+
mode: key_mode,
|
|
93
|
+
connection: z.string()
|
|
94
|
+
});
|