agent-recall-mcp 3.5.2 → 3.5.4
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 +254 -143
- package/dist/build-server.d.ts +28 -0
- package/dist/build-server.d.ts.map +1 -0
- package/dist/build-server.js +55 -0
- package/dist/build-server.js.map +1 -0
- package/dist/http/activity.d.ts +60 -0
- package/dist/http/activity.d.ts.map +1 -0
- package/dist/http/activity.js +254 -0
- package/dist/http/activity.js.map +1 -0
- package/dist/http/alerts.d.ts +84 -0
- package/dist/http/alerts.d.ts.map +1 -0
- package/dist/http/alerts.js +213 -0
- package/dist/http/alerts.js.map +1 -0
- package/dist/http/cli.d.ts +3 -0
- package/dist/http/cli.d.ts.map +1 -0
- package/dist/http/cli.js +515 -0
- package/dist/http/cli.js.map +1 -0
- package/dist/http/export-tar.d.ts +23 -0
- package/dist/http/export-tar.d.ts.map +1 -0
- package/dist/http/export-tar.js +264 -0
- package/dist/http/export-tar.js.map +1 -0
- package/dist/http/federation.d.ts +45 -0
- package/dist/http/federation.d.ts.map +1 -0
- package/dist/http/federation.js +185 -0
- package/dist/http/federation.js.map +1 -0
- package/dist/http/film/film.css +80 -0
- package/dist/http/film/film.js +446 -0
- package/dist/http/film/human.jpg +0 -0
- package/dist/http/film/m0.jpg +0 -0
- package/dist/http/film/m2.jpg +0 -0
- package/dist/http/film/m3.jpg +0 -0
- package/dist/http/film/wrong.jpg +0 -0
- package/dist/http/film.d.ts +16 -0
- package/dist/http/film.d.ts.map +1 -0
- package/dist/http/film.js +119 -0
- package/dist/http/film.js.map +1 -0
- package/dist/http/home/cabinet.svg +1 -0
- package/dist/http/home/drawer-project.svg +1 -0
- package/dist/http/home/drawer-rules.svg +1 -0
- package/dist/http/home/drawer-you.svg +1 -0
- package/dist/http/home/fig1.svg +242 -0
- package/dist/http/home/fig2-1.svg +61 -0
- package/dist/http/home/fig2-2.svg +92 -0
- package/dist/http/home/fig3.svg +1 -0
- package/dist/http/home/home.css +509 -0
- package/dist/http/home/home.html +517 -0
- package/dist/http/home/icons.svg +15 -0
- package/dist/http/home.d.ts +23 -0
- package/dist/http/home.d.ts.map +1 -0
- package/dist/http/home.js +295 -0
- package/dist/http/home.js.map +1 -0
- package/dist/http/identities.d.ts +29 -0
- package/dist/http/identities.d.ts.map +1 -0
- package/dist/http/identities.js +91 -0
- package/dist/http/identities.js.map +1 -0
- package/dist/http/import-memory.d.ts +161 -0
- package/dist/http/import-memory.d.ts.map +1 -0
- package/dist/http/import-memory.js +718 -0
- package/dist/http/import-memory.js.map +1 -0
- package/dist/http/jsonfile.d.ts +6 -0
- package/dist/http/jsonfile.d.ts.map +1 -0
- package/dist/http/jsonfile.js +60 -0
- package/dist/http/jsonfile.js.map +1 -0
- package/dist/http/legal/PRIVACY.md +70 -0
- package/dist/http/legal.d.ts +10 -0
- package/dist/http/legal.d.ts.map +1 -0
- package/dist/http/legal.js +35 -0
- package/dist/http/legal.js.map +1 -0
- package/dist/http/limits.d.ts +59 -0
- package/dist/http/limits.d.ts.map +1 -0
- package/dist/http/limits.js +163 -0
- package/dist/http/limits.js.map +1 -0
- package/dist/http/markdown-lite.d.ts +2 -0
- package/dist/http/markdown-lite.d.ts.map +1 -0
- package/dist/http/markdown-lite.js +86 -0
- package/dist/http/markdown-lite.js.map +1 -0
- package/dist/http/multipart.d.ts +43 -0
- package/dist/http/multipart.d.ts.map +1 -0
- package/dist/http/multipart.js +152 -0
- package/dist/http/multipart.js.map +1 -0
- package/dist/http/oauth-app.d.ts +75 -0
- package/dist/http/oauth-app.d.ts.map +1 -0
- package/dist/http/oauth-app.js +259 -0
- package/dist/http/oauth-app.js.map +1 -0
- package/dist/http/oauth-config.d.ts +46 -0
- package/dist/http/oauth-config.d.ts.map +1 -0
- package/dist/http/oauth-config.js +122 -0
- package/dist/http/oauth-config.js.map +1 -0
- package/dist/http/oauth-pages.d.ts +40 -0
- package/dist/http/oauth-pages.d.ts.map +1 -0
- package/dist/http/oauth-pages.js +97 -0
- package/dist/http/oauth-pages.js.map +1 -0
- package/dist/http/oauth-provider.d.ts +124 -0
- package/dist/http/oauth-provider.d.ts.map +1 -0
- package/dist/http/oauth-provider.js +486 -0
- package/dist/http/oauth-provider.js.map +1 -0
- package/dist/http/oauth-store.d.ts +128 -0
- package/dist/http/oauth-store.d.ts.map +1 -0
- package/dist/http/oauth-store.js +317 -0
- package/dist/http/oauth-store.js.map +1 -0
- package/dist/http/redirect-policy.d.ts +16 -0
- package/dist/http/redirect-policy.d.ts.map +1 -0
- package/dist/http/redirect-policy.js +83 -0
- package/dist/http/redirect-policy.js.map +1 -0
- package/dist/http/review-pages.d.ts +39 -0
- package/dist/http/review-pages.d.ts.map +1 -0
- package/dist/http/review-pages.js +78 -0
- package/dist/http/review-pages.js.map +1 -0
- package/dist/http/review.d.ts +36 -0
- package/dist/http/review.d.ts.map +1 -0
- package/dist/http/review.js +220 -0
- package/dist/http/review.js.map +1 -0
- package/dist/http/serve.d.ts +58 -0
- package/dist/http/serve.d.ts.map +1 -0
- package/dist/http/serve.js +324 -0
- package/dist/http/serve.js.map +1 -0
- package/dist/http/site-pages.d.ts +110 -0
- package/dist/http/site-pages.d.ts.map +1 -0
- package/dist/http/site-pages.js +630 -0
- package/dist/http/site-pages.js.map +1 -0
- package/dist/http/site-theme.d.ts +13 -0
- package/dist/http/site-theme.d.ts.map +1 -0
- package/dist/http/site-theme.js +22 -0
- package/dist/http/site-theme.js.map +1 -0
- package/dist/http/site.d.ts +52 -0
- package/dist/http/site.d.ts.map +1 -0
- package/dist/http/site.js +353 -0
- package/dist/http/site.js.map +1 -0
- package/dist/http/stats.d.ts +139 -0
- package/dist/http/stats.d.ts.map +1 -0
- package/dist/http/stats.js +599 -0
- package/dist/http/stats.js.map +1 -0
- package/dist/http/tar-import.d.ts +69 -0
- package/dist/http/tar-import.d.ts.map +1 -0
- package/dist/http/tar-import.js +234 -0
- package/dist/http/tar-import.js.map +1 -0
- package/dist/http/tenant-paths.d.ts +14 -0
- package/dist/http/tenant-paths.d.ts.map +1 -0
- package/dist/http/tenant-paths.js +42 -0
- package/dist/http/tenant-paths.js.map +1 -0
- package/dist/http/tokens.d.ts +32 -0
- package/dist/http/tokens.d.ts.map +1 -0
- package/dist/http/tokens.js +137 -0
- package/dist/http/tokens.js.map +1 -0
- package/dist/http/trial.d.ts +55 -0
- package/dist/http/trial.d.ts.map +1 -0
- package/dist/http/trial.js +218 -0
- package/dist/http/trial.js.map +1 -0
- package/dist/http/web-session.d.ts +108 -0
- package/dist/http/web-session.d.ts.map +1 -0
- package/dist/http/web-session.js +267 -0
- package/dist/http/web-session.js.map +1 -0
- package/dist/index.js +12 -65
- package/dist/index.js.map +1 -1
- package/dist/lib/ambient-capture.d.ts.map +1 -1
- package/dist/lib/ambient-capture.js +4 -1
- package/dist/lib/ambient-capture.js.map +1 -1
- package/dist/lib/bookkeeping.d.ts +26 -0
- package/dist/lib/bookkeeping.d.ts.map +1 -0
- package/dist/lib/bookkeeping.js +31 -0
- package/dist/lib/bookkeeping.js.map +1 -0
- package/dist/lib/hosted-redact.d.ts +17 -0
- package/dist/lib/hosted-redact.d.ts.map +1 -0
- package/dist/lib/hosted-redact.js +57 -0
- package/dist/lib/hosted-redact.js.map +1 -0
- package/dist/lib/lifecycle-exit.d.ts +5 -13
- package/dist/lib/lifecycle-exit.d.ts.map +1 -1
- package/dist/lib/lifecycle-exit.js +38 -16
- package/dist/lib/lifecycle-exit.js.map +1 -1
- package/dist/server.d.ts +3 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -3
- package/dist/server.js.map +1 -1
- package/dist/tools/annotations.d.ts +65 -0
- package/dist/tools/annotations.d.ts.map +1 -0
- package/dist/tools/annotations.js +4 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/check-action.d.ts.map +1 -1
- package/dist/tools/check-action.js +2 -0
- package/dist/tools/check-action.js.map +1 -1
- package/dist/tools/check.d.ts.map +1 -1
- package/dist/tools/check.js +6 -2
- package/dist/tools/check.js.map +1 -1
- package/dist/tools/digest.d.ts.map +1 -1
- package/dist/tools/digest.js +2 -0
- package/dist/tools/digest.js.map +1 -1
- package/dist/tools/pipeline-close.d.ts.map +1 -1
- package/dist/tools/pipeline-close.js +2 -0
- package/dist/tools/pipeline-close.js.map +1 -1
- package/dist/tools/pipeline-current.d.ts.map +1 -1
- package/dist/tools/pipeline-current.js +2 -0
- package/dist/tools/pipeline-current.js.map +1 -1
- package/dist/tools/pipeline-list.d.ts.map +1 -1
- package/dist/tools/pipeline-list.js +2 -0
- package/dist/tools/pipeline-list.js.map +1 -1
- package/dist/tools/pipeline-open.d.ts.map +1 -1
- package/dist/tools/pipeline-open.js +2 -0
- package/dist/tools/pipeline-open.js.map +1 -1
- package/dist/tools/pipeline-show.d.ts.map +1 -1
- package/dist/tools/pipeline-show.js +2 -0
- package/dist/tools/pipeline-show.js.map +1 -1
- package/dist/tools/recall.d.ts.map +1 -1
- package/dist/tools/recall.js +4 -1
- package/dist/tools/recall.js.map +1 -1
- package/dist/tools/register-rule.d.ts.map +1 -1
- package/dist/tools/register-rule.js +2 -0
- package/dist/tools/register-rule.js.map +1 -1
- package/dist/tools/remember.d.ts.map +1 -1
- package/dist/tools/remember.js +10 -1
- package/dist/tools/remember.js.map +1 -1
- package/dist/tools/session-end.d.ts +15 -0
- package/dist/tools/session-end.d.ts.map +1 -1
- package/dist/tools/session-end.js +13 -1
- package/dist/tools/session-end.js.map +1 -1
- package/dist/tools/session-start.d.ts +6 -1
- package/dist/tools/session-start.d.ts.map +1 -1
- package/dist/tools/session-start.js +24 -212
- package/dist/tools/session-start.js.map +1 -1
- package/package.json +11 -8
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* multipart.ts — a small STREAMING multipart/form-data reader, no dependency.
|
|
3
|
+
*
|
|
4
|
+
* It exists for one form: POST /connect/import (a few short text fields, then one file).
|
|
5
|
+
* It is deliberately strict instead of lenient:
|
|
6
|
+
* - the body must start with the first delimiter; a preamble is refused;
|
|
7
|
+
* - the header block of a part is capped (4 KiB), the number of parts is capped (8);
|
|
8
|
+
* - only `Content-Disposition: form-data; name="…"` is understood; nothing else is trusted
|
|
9
|
+
* (a filename is never used for anything);
|
|
10
|
+
* - part data goes to the handlers chunk by chunk and is never held whole: memory use is
|
|
11
|
+
* one incoming chunk plus a delimiter-length tail;
|
|
12
|
+
* - handlers are awaited, so a slow consumer slows the upload down (backpressure);
|
|
13
|
+
* - a body that ends before the closing delimiter is an error (a cut-off upload is never
|
|
14
|
+
* "complete"), and so is anything after the closing delimiter's line.
|
|
15
|
+
*/
|
|
16
|
+
export declare class MultipartError extends Error {
|
|
17
|
+
}
|
|
18
|
+
export interface PartInfo {
|
|
19
|
+
name: string;
|
|
20
|
+
filename?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface PartHandlers {
|
|
23
|
+
start(part: PartInfo): Promise<void> | void;
|
|
24
|
+
data(chunk: Buffer): Promise<void> | void;
|
|
25
|
+
end(): Promise<void> | void;
|
|
26
|
+
}
|
|
27
|
+
/** RFC 2046 boundary characters, at most 70. */
|
|
28
|
+
export declare const BOUNDARY_RE: RegExp;
|
|
29
|
+
/** The boundary of a `multipart/form-data` content type, or null. */
|
|
30
|
+
export declare function boundaryOf(contentType: string | undefined): string | null;
|
|
31
|
+
export declare class MultipartParser {
|
|
32
|
+
private readonly h;
|
|
33
|
+
private readonly delim;
|
|
34
|
+
private buf;
|
|
35
|
+
private state;
|
|
36
|
+
private inPart;
|
|
37
|
+
private parts;
|
|
38
|
+
constructor(boundary: string, h: PartHandlers);
|
|
39
|
+
write(chunk: Buffer): Promise<void>;
|
|
40
|
+
/** The body ended: it must have ended with the closing delimiter. */
|
|
41
|
+
finish(): void;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=multipart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/http/multipart.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,qBAAa,cAAe,SAAQ,KAAK;CAAG;AAE5C,MAAM,WAAW,QAAQ;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE;AAE7D,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1C,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC7B;AAID,gDAAgD;AAChD,eAAO,MAAM,WAAW,QAA8D,CAAC;AAEvF,qEAAqE;AACrE,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAKzE;AAID,qBAAa,eAAe;IAOI,OAAO,CAAC,QAAQ,CAAC,CAAC;IANhD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,GAAG,CAA2B;IACtC,OAAO,CAAC,KAAK,CAAiB;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAK;gBAEN,QAAQ,EAAE,MAAM,EAAmB,CAAC,EAAE,YAAY;IAMxD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoEzC,qEAAqE;IACrE,MAAM,IAAI,IAAI;CAGf"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* multipart.ts — a small STREAMING multipart/form-data reader, no dependency.
|
|
3
|
+
*
|
|
4
|
+
* It exists for one form: POST /connect/import (a few short text fields, then one file).
|
|
5
|
+
* It is deliberately strict instead of lenient:
|
|
6
|
+
* - the body must start with the first delimiter; a preamble is refused;
|
|
7
|
+
* - the header block of a part is capped (4 KiB), the number of parts is capped (8);
|
|
8
|
+
* - only `Content-Disposition: form-data; name="…"` is understood; nothing else is trusted
|
|
9
|
+
* (a filename is never used for anything);
|
|
10
|
+
* - part data goes to the handlers chunk by chunk and is never held whole: memory use is
|
|
11
|
+
* one incoming chunk plus a delimiter-length tail;
|
|
12
|
+
* - handlers are awaited, so a slow consumer slows the upload down (backpressure);
|
|
13
|
+
* - a body that ends before the closing delimiter is an error (a cut-off upload is never
|
|
14
|
+
* "complete"), and so is anything after the closing delimiter's line.
|
|
15
|
+
*/
|
|
16
|
+
export class MultipartError extends Error {
|
|
17
|
+
}
|
|
18
|
+
const MAX_HEADER_BYTES = 4096;
|
|
19
|
+
const MAX_PARTS = 8;
|
|
20
|
+
/** RFC 2046 boundary characters, at most 70. */
|
|
21
|
+
export const BOUNDARY_RE = /^[0-9A-Za-z'()+_,\-./:=? ]{1,69}[0-9A-Za-z'()+_,\-./:=?]$/;
|
|
22
|
+
/** The boundary of a `multipart/form-data` content type, or null. */
|
|
23
|
+
export function boundaryOf(contentType) {
|
|
24
|
+
if (!contentType || contentType.length > 200)
|
|
25
|
+
return null;
|
|
26
|
+
const m = /^multipart\/form-data\s*;\s*boundary=(?:"([^"]+)"|([^\s;"]+))\s*$/i.exec(contentType);
|
|
27
|
+
const b = m?.[1] ?? m?.[2];
|
|
28
|
+
return b !== undefined && BOUNDARY_RE.test(b) ? b : null;
|
|
29
|
+
}
|
|
30
|
+
export class MultipartParser {
|
|
31
|
+
h;
|
|
32
|
+
delim;
|
|
33
|
+
buf = Buffer.alloc(0);
|
|
34
|
+
state = "body";
|
|
35
|
+
inPart = false;
|
|
36
|
+
parts = 0;
|
|
37
|
+
constructor(boundary, h) {
|
|
38
|
+
this.h = h;
|
|
39
|
+
// The first delimiter has no CRLF before it; a virtual one keeps a single search rule.
|
|
40
|
+
this.delim = Buffer.from("\r\n--" + boundary, "latin1");
|
|
41
|
+
this.buf = Buffer.from("\r\n", "latin1");
|
|
42
|
+
}
|
|
43
|
+
async write(chunk) {
|
|
44
|
+
if (this.state === "done") {
|
|
45
|
+
// Only the epilogue (the line ending after the closing delimiter) may follow.
|
|
46
|
+
if (chunk.some((b) => b !== 0x0d && b !== 0x0a && b !== 0x20 && b !== 0x09))
|
|
47
|
+
throw new MultipartError("data after the closing boundary");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.buf = this.buf.length === 0 ? chunk : Buffer.concat([this.buf, chunk]);
|
|
51
|
+
for (;;) {
|
|
52
|
+
if (this.state === "body") {
|
|
53
|
+
const i = this.buf.indexOf(this.delim);
|
|
54
|
+
if (i >= 0) {
|
|
55
|
+
if (this.inPart) {
|
|
56
|
+
if (i > 0)
|
|
57
|
+
await this.h.data(this.buf.subarray(0, i));
|
|
58
|
+
this.inPart = false;
|
|
59
|
+
await this.h.end();
|
|
60
|
+
}
|
|
61
|
+
else if (i > 0 && this.parts === 0 && i !== 0) {
|
|
62
|
+
// Bytes before the very first delimiter (beyond the virtual CRLF) are a preamble.
|
|
63
|
+
throw new MultipartError("unexpected data before the first boundary");
|
|
64
|
+
}
|
|
65
|
+
this.buf = this.buf.subarray(i + this.delim.length);
|
|
66
|
+
this.state = "after";
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!this.inPart) {
|
|
70
|
+
// Before the first delimiter nothing but its own bytes is allowed.
|
|
71
|
+
if (this.parts === 0 && !this.delim.subarray(0, Math.min(this.buf.length, this.delim.length)).equals(this.buf.subarray(0, Math.min(this.buf.length, this.delim.length)))) {
|
|
72
|
+
throw new MultipartError("unexpected data before the first boundary");
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const keep = this.delim.length - 1;
|
|
77
|
+
if (this.buf.length > keep) {
|
|
78
|
+
await this.h.data(this.buf.subarray(0, this.buf.length - keep));
|
|
79
|
+
this.buf = this.buf.subarray(this.buf.length - keep);
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (this.state === "after") {
|
|
84
|
+
if (this.buf.length < 2)
|
|
85
|
+
return;
|
|
86
|
+
const two = this.buf.subarray(0, 2).toString("latin1");
|
|
87
|
+
if (two === "--") {
|
|
88
|
+
this.state = "done";
|
|
89
|
+
const rest = this.buf.subarray(2);
|
|
90
|
+
this.buf = Buffer.alloc(0);
|
|
91
|
+
if (rest.some((b) => b !== 0x0d && b !== 0x0a && b !== 0x20 && b !== 0x09))
|
|
92
|
+
throw new MultipartError("data after the closing boundary");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (two !== "\r\n")
|
|
96
|
+
throw new MultipartError("malformed boundary line");
|
|
97
|
+
this.buf = this.buf.subarray(2);
|
|
98
|
+
this.state = "headers";
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
// headers
|
|
102
|
+
const j = this.buf.indexOf("\r\n\r\n");
|
|
103
|
+
if (j < 0) {
|
|
104
|
+
if (this.buf.length > MAX_HEADER_BYTES)
|
|
105
|
+
throw new MultipartError("part headers too large");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (j > MAX_HEADER_BYTES)
|
|
109
|
+
throw new MultipartError("part headers too large");
|
|
110
|
+
if (++this.parts > MAX_PARTS)
|
|
111
|
+
throw new MultipartError("too many form parts");
|
|
112
|
+
const info = parseHeaders(this.buf.subarray(0, j).toString("latin1"));
|
|
113
|
+
this.buf = this.buf.subarray(j + 4);
|
|
114
|
+
this.state = "body";
|
|
115
|
+
this.inPart = true;
|
|
116
|
+
await this.h.start(info);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** The body ended: it must have ended with the closing delimiter. */
|
|
120
|
+
finish() {
|
|
121
|
+
if (this.state !== "done")
|
|
122
|
+
throw new MultipartError("the upload ended before its closing boundary (cut off?)");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function parseHeaders(block) {
|
|
126
|
+
let name;
|
|
127
|
+
let filename;
|
|
128
|
+
let sawDisposition = false;
|
|
129
|
+
for (const line of block.split("\r\n")) {
|
|
130
|
+
const i = line.indexOf(":");
|
|
131
|
+
if (i <= 0)
|
|
132
|
+
throw new MultipartError("malformed part header");
|
|
133
|
+
if (line.slice(0, i).trim().toLowerCase() !== "content-disposition")
|
|
134
|
+
continue;
|
|
135
|
+
if (sawDisposition)
|
|
136
|
+
throw new MultipartError("duplicate content-disposition");
|
|
137
|
+
sawDisposition = true;
|
|
138
|
+
const v = line.slice(i + 1);
|
|
139
|
+
if (!/^\s*form-data\s*;/i.test(v))
|
|
140
|
+
throw new MultipartError("not a form-data part");
|
|
141
|
+
for (const m of v.matchAll(/;\s*(name|filename)\s*=\s*"([^"\\\r\n]*)"/gi)) {
|
|
142
|
+
if (m[1].toLowerCase() === "name")
|
|
143
|
+
name = m[2];
|
|
144
|
+
else
|
|
145
|
+
filename = m[2];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (name === undefined || name.length > 64)
|
|
149
|
+
throw new MultipartError("part without a name");
|
|
150
|
+
return { name, filename };
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=multipart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart.js","sourceRoot":"","sources":["../../src/http/multipart.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAU5C,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,gDAAgD;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG,2DAA2D,CAAC;AAEvF,qEAAqE;AACrE,MAAM,UAAU,UAAU,CAAC,WAA+B;IACxD,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,GAAG;QAAE,OAAO,IAAI,CAAC;IAC1D,MAAM,CAAC,GAAG,oEAAoE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjG,MAAM,CAAC,GAAG,CAAC,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GAAG,EAAE;QAAE,MAAM,IAAI,cAAc,CAAC,qBAAqB,CAAC,CAAC;IAC5F,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oauth-app.ts — the Express app that serves the OAuth routes of the hosted server.
|
|
3
|
+
* serve.ts hands matching requests (see `owns`) to it; /mcp stays on the plain
|
|
4
|
+
* node:http path. Routes:
|
|
5
|
+
*
|
|
6
|
+
* /.well-known/oauth-protected-resource[/mcp], /.well-known/oauth-authorization-server
|
|
7
|
+
* POST /register GET|POST /authorize POST /authorize/start GET /authorize/callback/{github,google}
|
|
8
|
+
* POST /token POST /revoke
|
|
9
|
+
* /review* the owner approves or rejects their own staged corrections (review.ts)
|
|
10
|
+
* /connect* the signed-in dashboard: ID, connect an agent, disconnect, download (site.ts)
|
|
11
|
+
*/
|
|
12
|
+
import type * as http from "node:http";
|
|
13
|
+
import { type OAuthConfig } from "./oauth-config.js";
|
|
14
|
+
import { type ProviderUrls } from "./federation.js";
|
|
15
|
+
import { type ImportTesting } from "./site.js";
|
|
16
|
+
import type { ActivityStore } from "./activity.js";
|
|
17
|
+
import { type SiteCtx } from "./site-pages.js";
|
|
18
|
+
export interface LoginLimits {
|
|
19
|
+
/** /authorize/start and /authorize/callback hits per client IP per window (each route has its own bucket). */
|
|
20
|
+
perIp: number;
|
|
21
|
+
/** Hits per route overall per window; only requests carrying a live request id / state spend it. */
|
|
22
|
+
global: number;
|
|
23
|
+
windowMs: number;
|
|
24
|
+
}
|
|
25
|
+
export declare const DEFAULT_LOGIN_LIMITS: LoginLimits;
|
|
26
|
+
export interface OAuthOptions {
|
|
27
|
+
config: OAuthConfig;
|
|
28
|
+
dataDir: string;
|
|
29
|
+
log: (line: string) => void;
|
|
30
|
+
/** Test seam: clock used for every OAuth expiry. Default Date.now. */
|
|
31
|
+
now?: () => number;
|
|
32
|
+
loginLimits?: LoginLimits;
|
|
33
|
+
/** Test seams: point the provider endpoints at mocks (still https, or http on localhost only). */
|
|
34
|
+
providerUrls?: ProviderUrls;
|
|
35
|
+
fetchImpl?: typeof fetch;
|
|
36
|
+
providerTimeoutMs?: number;
|
|
37
|
+
/** Test seam: cap on live sign-in requests. */
|
|
38
|
+
maxPending?: number;
|
|
39
|
+
/** Test seam: cap on live sign-in requests per client address. */
|
|
40
|
+
maxPendingPerKey?: number;
|
|
41
|
+
/** Per-agent activity log (read by the dashboard). */
|
|
42
|
+
activity?: ActivityStore;
|
|
43
|
+
/** Storage quota per user in bytes, shown on the dashboard; 0 or undefined = none shown. */
|
|
44
|
+
quotaBytes?: number;
|
|
45
|
+
/** Called after a user's tenant directory was changed by the website (an import), so cached usage figures are dropped. */
|
|
46
|
+
onTenantChanged?: (uid: string) => void;
|
|
47
|
+
/** Test seams for the memory import: limits and hooks. */
|
|
48
|
+
importTesting?: ImportTesting;
|
|
49
|
+
/** A federated account signed in (MCP sign-in or website). Must not throw. */
|
|
50
|
+
onSignIn?: (uid: string) => void;
|
|
51
|
+
/** An OAuth route failed with an internal (5xx) error; the response is still answered generically here. Must not throw. */
|
|
52
|
+
onInternalError?: (res: http.ServerResponse, err: unknown) => void;
|
|
53
|
+
}
|
|
54
|
+
export interface OAuthRuntime {
|
|
55
|
+
/** Does this path belong to the OAuth routes? */
|
|
56
|
+
owns(pathname: string): boolean;
|
|
57
|
+
handle(req: http.IncomingMessage, res: http.ServerResponse): void;
|
|
58
|
+
/** aro_ access token → uid, or null. Throws TokenStoreUnavailableError if an operator file is unreadable. */
|
|
59
|
+
resolveAccess(token: string): string | null;
|
|
60
|
+
/** Like resolveAccess, plus the id of the grant behind the token. */
|
|
61
|
+
resolveAccessGrant(token: string): {
|
|
62
|
+
uid: string;
|
|
63
|
+
grantId: string;
|
|
64
|
+
} | null;
|
|
65
|
+
resourceMetadataUrl: string;
|
|
66
|
+
/** What the website needs to know about this server. */
|
|
67
|
+
site: SiteCtx;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Rate-limit key for a client IP. IPv4 as is; IPv4-mapped IPv6 -> the IPv4; any other IPv6 collapses to its /64
|
|
71
|
+
* (one subscriber can cycle through 2^64 addresses, so per-address buckets would never fill).
|
|
72
|
+
*/
|
|
73
|
+
export declare function ipKey(ip: string | undefined): string;
|
|
74
|
+
export declare function createOAuth(opts: OAuthOptions): OAuthRuntime;
|
|
75
|
+
//# sourceMappingURL=oauth-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-app.d.ts","sourceRoot":"","sources":["../../src/http/oauth-app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AAIvC,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKvE,OAAO,EAAqC,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAKvF,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAuD,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEpG,MAAM,WAAW,WAAW;IAC1B,8GAA8G;IAC9G,KAAK,EAAE,MAAM,CAAC;IACd,oGAAoG;IACpG,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,oBAAoB,EAAE,WAAkE,CAAC;AAEtG,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,kGAAkG;IAClG,YAAY,CAAC,E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G,MAAM,CAYpD;AA4BD,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAqL5D"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import * as net from "node:net";
|
|
2
|
+
import express from "express";
|
|
3
|
+
import { mcpAuthRouter } from "@modelcontextprotocol/sdk/server/auth/router.js";
|
|
4
|
+
import { OAuthConfigError } from "./oauth-config.js";
|
|
5
|
+
import { listTokens } from "./tokens.js";
|
|
6
|
+
import { RESERVED_UID_RE } from "./identities.js";
|
|
7
|
+
import { OAuthStore } from "./oauth-store.js";
|
|
8
|
+
import { FederatedOAuthProvider, OAUTH_SCOPE } from "./oauth-provider.js";
|
|
9
|
+
import { Federation, DEFAULT_PROVIDER_URLS } from "./federation.js";
|
|
10
|
+
import { errorPage, pageHeaders } from "./oauth-pages.js";
|
|
11
|
+
import { REVIEW_PATHS, mountReview, sendReview } from "./review.js";
|
|
12
|
+
import { reviewMessagePage, reviewSignInPage } from "./review-pages.js";
|
|
13
|
+
import { WebSession } from "./web-session.js";
|
|
14
|
+
import { mountSite } from "./site.js";
|
|
15
|
+
import { connectSignInPage, messagePage, DEFAULT_PRIVACY_URL } from "./site-pages.js";
|
|
16
|
+
export const DEFAULT_LOGIN_LIMITS = { perIp: 10, global: 300, windowMs: 10 * 60 * 1000 };
|
|
17
|
+
/**
|
|
18
|
+
* gh-/gg- uids belong to federated accounts. An active static token for such a uid
|
|
19
|
+
* (from before the prefix was reserved) would let the matching GitHub/Google user sign
|
|
20
|
+
* straight into that tenant, so OAuth refuses to start until the operator resolves it.
|
|
21
|
+
*/
|
|
22
|
+
function assertNoReservedStaticUids(dataDir) {
|
|
23
|
+
const clash = listTokens(dataDir).filter((t) => !t.revoked_at && RESERVED_UID_RE.test(t.uid));
|
|
24
|
+
if (clash.length === 0)
|
|
25
|
+
return;
|
|
26
|
+
const list = clash.map((t) => `${t.id} (uid ${t.uid})`).join(", ");
|
|
27
|
+
throw new OAuthConfigError(`OAuth cannot start: static token(s) ${list} use a uid with the reserved gh-/gg- prefix, which belongs to GitHub/Google sign-ins. ` +
|
|
28
|
+
"Revoke them (token revoke <id>) and issue a token for a plain uid, then start again.");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Rate-limit key for a client IP. IPv4 as is; IPv4-mapped IPv6 -> the IPv4; any other IPv6 collapses to its /64
|
|
32
|
+
* (one subscriber can cycle through 2^64 addresses, so per-address buckets would never fill).
|
|
33
|
+
*/
|
|
34
|
+
export function ipKey(ip) {
|
|
35
|
+
if (!ip)
|
|
36
|
+
return "unknown";
|
|
37
|
+
const bare = ip.split("%")[0];
|
|
38
|
+
const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/i.exec(bare);
|
|
39
|
+
if (mapped)
|
|
40
|
+
return mapped[1];
|
|
41
|
+
if (net.isIPv4(bare))
|
|
42
|
+
return bare;
|
|
43
|
+
if (!net.isIPv6(bare))
|
|
44
|
+
return "invalid"; // a spoofed non-IP value must not mint a fresh bucket
|
|
45
|
+
let [head, tail] = bare.split("::");
|
|
46
|
+
const h = head ? head.split(":") : [];
|
|
47
|
+
const t = tail !== undefined && tail !== "" ? tail.split(":") : [];
|
|
48
|
+
const groups = tail === undefined ? h : [...h, ...Array(Math.max(0, 8 - h.length - t.length)).fill("0"), ...t];
|
|
49
|
+
return groups.slice(0, 4).map((g) => g.toLowerCase().padStart(4, "0")).join(":") + "::/64";
|
|
50
|
+
}
|
|
51
|
+
/** Fixed-window counter per key, with a bounded key table. */
|
|
52
|
+
class WindowCounter {
|
|
53
|
+
limit;
|
|
54
|
+
windowMs;
|
|
55
|
+
now;
|
|
56
|
+
m = new Map();
|
|
57
|
+
constructor(limit, windowMs, now) {
|
|
58
|
+
this.limit = limit;
|
|
59
|
+
this.windowMs = windowMs;
|
|
60
|
+
this.now = now;
|
|
61
|
+
}
|
|
62
|
+
/** Records one hit; returns seconds to wait when over the limit, else 0. */
|
|
63
|
+
hit(key) {
|
|
64
|
+
const t = this.now();
|
|
65
|
+
if (this.m.size > 10_000)
|
|
66
|
+
for (const [k, v] of this.m)
|
|
67
|
+
if (v.reset <= t)
|
|
68
|
+
this.m.delete(k);
|
|
69
|
+
let e = this.m.get(key);
|
|
70
|
+
if (!e || e.reset <= t) {
|
|
71
|
+
e = { n: 0, reset: t + this.windowMs };
|
|
72
|
+
this.m.set(key, e);
|
|
73
|
+
}
|
|
74
|
+
e.n++;
|
|
75
|
+
return e.n > this.limit ? Math.max(1, Math.ceil((e.reset - t) / 1000)) : 0;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const EXACT_PATHS = new Set(["/register", "/authorize", "/authorize/start", "/token", "/revoke"]);
|
|
79
|
+
/** The dashboard routes (site.ts). */
|
|
80
|
+
const SITE_PATHS = new Set(["/connect", "/connect/start", "/connect/disconnect", "/connect/download", "/connect/import", "/connect/logout"]);
|
|
81
|
+
const FIFTEEN_MIN = 15 * 60 * 1000;
|
|
82
|
+
export function createOAuth(opts) {
|
|
83
|
+
const { config, log } = opts;
|
|
84
|
+
const now = opts.now ?? Date.now;
|
|
85
|
+
const limits = opts.loginLimits ?? DEFAULT_LOGIN_LIMITS;
|
|
86
|
+
assertNoReservedStaticUids(opts.dataDir);
|
|
87
|
+
const store = new OAuthStore(opts.dataDir, now);
|
|
88
|
+
const federation = new Federation(config, opts.providerUrls ?? DEFAULT_PROVIDER_URLS, opts.fetchImpl, now, opts.providerTimeoutMs);
|
|
89
|
+
const provider = new FederatedOAuthProvider({
|
|
90
|
+
config, dataDir: opts.dataDir, store, log, now,
|
|
91
|
+
maxPending: opts.maxPending,
|
|
92
|
+
maxPendingPerKey: opts.maxPendingPerKey,
|
|
93
|
+
keyOf: (req) => ipKey(req.ip),
|
|
94
|
+
federation,
|
|
95
|
+
onSignIn: opts.onSignIn,
|
|
96
|
+
});
|
|
97
|
+
const site = { base: config.publicUrl.origin, privacyUrl: config.privacyUrl?.href ?? DEFAULT_PRIVACY_URL, hosted: true };
|
|
98
|
+
const pages = {
|
|
99
|
+
signIn: (surface, v) => (surface === "review" ? reviewSignInPage(v) : connectSignInPage(site, v)),
|
|
100
|
+
message: (surface, title, msg) => surface === "review"
|
|
101
|
+
? reviewMessagePage(title, msg)
|
|
102
|
+
: messagePage(site, title, msg, surface === "connect" ? { href: "/connect", label: "Back to the connect page" } : { href: "/", label: "Back to AgentRecall" }),
|
|
103
|
+
};
|
|
104
|
+
// The review page and the /connect dashboard share one browser sign-in and session, and the provider callback URL (told apart by state).
|
|
105
|
+
const review = new WebSession({ config, dataDir: opts.dataDir, federation, log, now, pages, onSignIn: opts.onSignIn });
|
|
106
|
+
const siteStartIp = new WindowCounter(limits.perIp, limits.windowMs, now);
|
|
107
|
+
const reviewStartIp = new WindowCounter(limits.perIp, limits.windowMs, now);
|
|
108
|
+
// Its own global budget, so review sign-ins (no client registration needed) cannot starve MCP sign-ins.
|
|
109
|
+
const reviewCallbackGlobal = new WindowCounter(limits.global, limits.windowMs, now);
|
|
110
|
+
const startIp = new WindowCounter(limits.perIp, limits.windowMs, now);
|
|
111
|
+
const callbackIp = new WindowCounter(limits.perIp, limits.windowMs, now);
|
|
112
|
+
const startGlobal = new WindowCounter(limits.global, limits.windowMs, now);
|
|
113
|
+
const callbackGlobal = new WindowCounter(limits.global, limits.windowMs, now);
|
|
114
|
+
const tooMany = (res, wait) => res.status(429).set(pageHeaders()).set("retry-after", String(wait))
|
|
115
|
+
.send(errorPage("Too many sign-in attempts. Please wait a few minutes and try again."));
|
|
116
|
+
const send = (res, r) => {
|
|
117
|
+
if (r.kind === "redirect") {
|
|
118
|
+
res.set({ "cache-control": "no-store", "referrer-policy": "no-referrer" });
|
|
119
|
+
if (r.clearCookieFor)
|
|
120
|
+
res.set("set-cookie", provider.cookieHeader(r.clearCookieFor, null));
|
|
121
|
+
res.redirect(302, r.location);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
if (r.clearCookieFor)
|
|
125
|
+
res.set("set-cookie", provider.cookieHeader(r.clearCookieFor, null));
|
|
126
|
+
res.status(r.status).set(pageHeaders(r.csp)).send(r.html);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const resourceMetadataUrl = new URL("/.well-known/oauth-protected-resource/mcp", config.publicUrl).href;
|
|
130
|
+
const app = express();
|
|
131
|
+
app.disable("x-powered-by");
|
|
132
|
+
if (config.trustProxy)
|
|
133
|
+
app.set("trust proxy", 1);
|
|
134
|
+
let warnedForwarded = false;
|
|
135
|
+
app.use((req, _res, next) => {
|
|
136
|
+
if (!config.trustProxy && !warnedForwarded && req.headers["x-forwarded-for"] !== undefined) {
|
|
137
|
+
warnedForwarded = true;
|
|
138
|
+
log("[oauth] WARNING: X-Forwarded-For seen but AR_TRUST_PROXY is off; every user shares the proxy's IP for rate limits. Set AR_TRUST_PROXY=1 behind a reverse proxy.");
|
|
139
|
+
}
|
|
140
|
+
next();
|
|
141
|
+
});
|
|
142
|
+
// RFC 9728 also allows the un-suffixed PRM URL; serve the same document there.
|
|
143
|
+
app.use((req, _res, next) => {
|
|
144
|
+
if (req.path === "/.well-known/oauth-protected-resource")
|
|
145
|
+
req.url = "/.well-known/oauth-protected-resource/mcp";
|
|
146
|
+
next();
|
|
147
|
+
});
|
|
148
|
+
// The user picked a provider on the sign-in page.
|
|
149
|
+
app.post("/authorize/start", (req, res, next) => {
|
|
150
|
+
const wait = startIp.hit(ipKey(req.ip));
|
|
151
|
+
if (wait > 0)
|
|
152
|
+
return void tooMany(res, wait);
|
|
153
|
+
next();
|
|
154
|
+
}, express.urlencoded({ extended: false, limit: "8kb" }), (req, res, next) => {
|
|
155
|
+
try {
|
|
156
|
+
const b = (req.body ?? {});
|
|
157
|
+
// Garbage request ids cost the sender's IP bucket only, never the global budget.
|
|
158
|
+
// Only requests that can still reach a provider spend the global budget (3 starts per request id).
|
|
159
|
+
if (provider.canStart(b.request_id)) {
|
|
160
|
+
const wait = startGlobal.hit("*");
|
|
161
|
+
if (wait > 0)
|
|
162
|
+
return void tooMany(res, wait);
|
|
163
|
+
}
|
|
164
|
+
send(res, provider.start({ requestId: b.request_id, provider: b.provider, cookies: req.headers.cookie }));
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
next(err);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
// The provider sends the browser back here with ?code&state (or ?error).
|
|
171
|
+
app.get("/authorize/callback/:provider", (req, res, next) => {
|
|
172
|
+
const wait = callbackIp.hit(ipKey(req.ip));
|
|
173
|
+
if (wait > 0)
|
|
174
|
+
return void tooMany(res, wait);
|
|
175
|
+
next();
|
|
176
|
+
}, async (req, res, next) => {
|
|
177
|
+
try {
|
|
178
|
+
const q = req.query;
|
|
179
|
+
if (review.hasState(q.state)) {
|
|
180
|
+
const wait = reviewCallbackGlobal.hit("*");
|
|
181
|
+
if (wait > 0)
|
|
182
|
+
return void tooMany(res, wait);
|
|
183
|
+
return void sendReview(res, await review.callback({
|
|
184
|
+
provider: String(req.params.provider), state: q.state, code: q.code, error: q.error, cookies: req.headers.cookie,
|
|
185
|
+
}), provider.formOrigins);
|
|
186
|
+
}
|
|
187
|
+
if (provider.hasState(q.state)) {
|
|
188
|
+
const wait = callbackGlobal.hit("*");
|
|
189
|
+
if (wait > 0)
|
|
190
|
+
return void tooMany(res, wait);
|
|
191
|
+
}
|
|
192
|
+
send(res, await provider.callback({
|
|
193
|
+
provider: String(req.params.provider), state: q.state, code: q.code, error: q.error, cookies: req.headers.cookie,
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
next(err);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
mountReview(app, {
|
|
201
|
+
flow: review, config, dataDir: opts.dataDir, log, formOrigins: provider.formOrigins,
|
|
202
|
+
limitStart: (req) => reviewStartIp.hit(ipKey(req.ip)),
|
|
203
|
+
});
|
|
204
|
+
mountSite(app, {
|
|
205
|
+
flow: review, store, config, dataDir: opts.dataDir, quotaBytes: opts.quotaBytes ?? 0, activity: opts.activity, ctx: site, log, now, onTenantChanged: opts.onTenantChanged, importTesting: opts.importTesting, formOrigins: provider.formOrigins,
|
|
206
|
+
limitStart: (req) => siteStartIp.hit(ipKey(req.ip)),
|
|
207
|
+
});
|
|
208
|
+
app.use(mcpAuthRouter({
|
|
209
|
+
provider,
|
|
210
|
+
issuerUrl: config.publicUrl,
|
|
211
|
+
resourceServerUrl: config.resourceUrl,
|
|
212
|
+
scopesSupported: [OAUTH_SCOPE],
|
|
213
|
+
resourceName: "AgentRecall",
|
|
214
|
+
// The SDK's per-IP defaults (token 50 / 15 min) would starve everyone behind claude.ai's few egress IPs.
|
|
215
|
+
authorizationOptions: { rateLimit: { windowMs: FIFTEEN_MIN, limit: 300, max: 300 } },
|
|
216
|
+
tokenOptions: { rateLimit: { windowMs: FIFTEEN_MIN, limit: 600, max: 600 } },
|
|
217
|
+
revocationOptions: { rateLimit: { windowMs: FIFTEEN_MIN, limit: 600, max: 600 } },
|
|
218
|
+
clientRegistrationOptions: { rateLimit: { windowMs: 60 * 60 * 1000, limit: 20, max: 20 } },
|
|
219
|
+
}));
|
|
220
|
+
app.use((_req, res) => {
|
|
221
|
+
res.status(404).json({ error: "not_found", error_description: "no such OAuth route" });
|
|
222
|
+
});
|
|
223
|
+
// Generic on purpose: never echo err.message / stack (bodies may carry credentials).
|
|
224
|
+
app.use((err, _req, res, _next) => {
|
|
225
|
+
const status = typeof err?.status === "number" ? err.status : 500;
|
|
226
|
+
const client = status >= 400 && status < 500;
|
|
227
|
+
log(`[oauth] request failed status=${client ? status : 500} kind=${err?.name ?? "unknown"}`);
|
|
228
|
+
if (!client) {
|
|
229
|
+
try {
|
|
230
|
+
opts.onInternalError?.(res, err);
|
|
231
|
+
}
|
|
232
|
+
catch { /* reporting never changes the answer */ }
|
|
233
|
+
}
|
|
234
|
+
if (res.headersSent)
|
|
235
|
+
return;
|
|
236
|
+
res.status(client ? status : 500).json(client
|
|
237
|
+
? { error: "invalid_request", error_description: "The request could not be processed." }
|
|
238
|
+
: { error: "server_error", error_description: "Internal Server Error" });
|
|
239
|
+
});
|
|
240
|
+
return {
|
|
241
|
+
owns(pathname) {
|
|
242
|
+
const p = pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
|
|
243
|
+
return EXACT_PATHS.has(p) || REVIEW_PATHS.has(p) || SITE_PATHS.has(p) || pathname.startsWith("/connect/") || pathname.startsWith("/.well-known/oauth-") || pathname.startsWith("/authorize/callback/");
|
|
244
|
+
},
|
|
245
|
+
handle(req, res) {
|
|
246
|
+
app(req, res);
|
|
247
|
+
},
|
|
248
|
+
resolveAccess(token) {
|
|
249
|
+
return this.resolveAccessGrant(token)?.uid ?? null;
|
|
250
|
+
},
|
|
251
|
+
resolveAccessGrant(token) {
|
|
252
|
+
const r = store.resolveAccess(token);
|
|
253
|
+
return r && r.resource === config.resourceUrl.href ? { uid: r.uid, grantId: r.grantId } : null;
|
|
254
|
+
},
|
|
255
|
+
resourceMetadataUrl,
|
|
256
|
+
site,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=oauth-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-app.js","sourceRoot":"","sources":["../../src/http/oauth-app.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAoB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAA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QACzM,CAAC;QACD,MAAM,CAAC,GAAG,EAAE,GAAG;YACb,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAChB,CAAC;QACD,aAAa,CAAC,KAAa;YACzB,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC;QACrD,CAAC;QACD,kBAAkB,CAAC,KAAa;YAC9B,MAAM,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACjG,CAAC;QACD,mBAAmB;QACnB,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oauth-config.ts — OAuth is OFF unless a public URL AND at least one federated
|
|
3
|
+
* login provider are configured; then the server is its own OAuth authorization
|
|
4
|
+
* server and users sign in with GitHub and/or Google. AgentRecall never sees or
|
|
5
|
+
* stores a password.
|
|
6
|
+
*
|
|
7
|
+
* AR_PUBLIC_URL / --public-url public origin = OAuth issuer (https, except localhost)
|
|
8
|
+
* AR_OAUTH_GITHUB_CLIENT_ID / _SECRET GitHub OAuth app (callback: <public>/authorize/callback/github)
|
|
9
|
+
* AR_OAUTH_GOOGLE_CLIENT_ID / _SECRET Google OAuth client (callback: <public>/authorize/callback/google)
|
|
10
|
+
* AR_OAUTH_REDIRECT_ALLOW extra allowed client redirect URI prefixes, comma-separated
|
|
11
|
+
* AR_OAUTH_SIGNUP=invite|open invite (default): only accounts linked with `identity link` may sign in
|
|
12
|
+
* AR_PRIVACY_URL optional https link to the privacy policy, shown on the sign-in page
|
|
13
|
+
* AR_TRUST_PROXY=1|true|yes|on trust ONE proxy hop for the client IP (0|false|no|off or empty = no)
|
|
14
|
+
*
|
|
15
|
+
* Nothing configured → null (server == v1). Anything half-configured (a lone
|
|
16
|
+
* id or secret, a public URL without a provider, a provider without a public
|
|
17
|
+
* URL) throws: fail closed instead of silently running without OAuth.
|
|
18
|
+
*/
|
|
19
|
+
export declare class OAuthConfigError extends Error {
|
|
20
|
+
}
|
|
21
|
+
export type ProviderName = "github" | "google";
|
|
22
|
+
export declare const PROVIDER_NAMES: readonly ProviderName[];
|
|
23
|
+
export interface ProviderCreds {
|
|
24
|
+
clientId: string;
|
|
25
|
+
clientSecret: string;
|
|
26
|
+
}
|
|
27
|
+
export interface OAuthConfig {
|
|
28
|
+
/** Issuer / public origin, e.g. https://agentrecallx.com */
|
|
29
|
+
publicUrl: URL;
|
|
30
|
+
/** Protected resource: <public>/mcp. Tokens are audience-bound to it. */
|
|
31
|
+
resourceUrl: URL;
|
|
32
|
+
providers: Partial<Record<ProviderName, ProviderCreds>>;
|
|
33
|
+
redirectAllow: string[];
|
|
34
|
+
trustProxy: boolean;
|
|
35
|
+
/** invite: only operator-linked accounts may sign in (no tenant is created for anyone else). */
|
|
36
|
+
signup: SignupMode;
|
|
37
|
+
/** AR_PRIVACY_URL: the operator's privacy policy, linked from the sign-in page (https only). */
|
|
38
|
+
privacyUrl?: URL;
|
|
39
|
+
}
|
|
40
|
+
export type SignupMode = "invite" | "open";
|
|
41
|
+
export interface OAuthConfigInput {
|
|
42
|
+
publicUrl?: string;
|
|
43
|
+
}
|
|
44
|
+
export declare function parseOrigin(name: string, raw: string): URL;
|
|
45
|
+
export declare function loadOAuthConfig(flags?: OAuthConfigInput, env?: NodeJS.ProcessEnv): OAuthConfig | null;
|
|
46
|
+
//# sourceMappingURL=oauth-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-config.d.ts","sourceRoot":"","sources":["../../src/http/oauth-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC/C,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAAyB,CAAC;AAE5E,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,4DAA4D;IAC5D,SAAS,EAAE,GAAG,CAAC;IACf,yEAAyE;IACzE,WAAW,EAAE,GAAG,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC;IACxD,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,OAAO,CAAC;IACpB,gGAAgG;IAChG,MAAM,EAAE,UAAU,CAAC;IACnB,gGAAgG;IAChG,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB;AAgBD,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAaD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAe1D;AAoBD,wBAAgB,eAAe,CAAC,KAAK,GAAE,gBAAqB,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,WAAW,GAAG,IAAI,CAiCtH"}
|