ovr 7.0.0-next.2 → 7.0.0-next.21
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/CHANGELOG.md +1157 -0
- package/dist/auth/client-source.d.ts +2 -2
- package/dist/auth/client-source.d.ts.map +1 -1
- package/dist/auth/client-source.js +2 -2
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +7 -4
- package/dist/auth/configure.d.ts +21 -8
- package/dist/auth/configure.d.ts.map +1 -1
- package/dist/auth/configure.js +172 -6
- package/dist/auth/index.d.ts +48 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +19 -0
- package/dist/auth/passkey.d.ts +14 -2
- package/dist/auth/passkey.d.ts.map +1 -1
- package/dist/auth/passkey.js +18 -5
- package/dist/auth/state.d.ts +6 -0
- package/dist/auth/state.d.ts.map +1 -1
- package/dist/auth/state.js +28 -5
- package/dist/auth/storage.d.ts +38 -0
- package/dist/auth/storage.d.ts.map +1 -1
- package/dist/auth/storage.js +60 -3
- package/dist/context/index.d.ts +4 -4
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +6 -3
- package/dist/form/index.d.ts +239 -31
- package/dist/form/index.d.ts.map +1 -1
- package/dist/form/index.js +657 -66
- package/dist/markdown/index.d.ts +6 -1
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +180 -9
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +154 -57
- package/dist/schema/index.d.ts +88 -19
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +32 -11
- package/dist/util/index.d.ts +12 -0
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +19 -0
- package/package.json +2 -1
- package/src/auth/client-source.ts +2 -2
- package/src/auth/client.ts +7 -4
- package/src/auth/configure.ts +189 -13
- package/src/auth/index.ts +44 -0
- package/src/auth/passkey.ts +25 -7
- package/src/auth/state.ts +32 -7
- package/src/auth/storage.ts +66 -3
- package/src/context/index.ts +14 -6
- package/src/form/index.ts +1174 -195
- package/src/markdown/index.ts +203 -12
- package/src/mcp/index.ts +205 -72
- package/src/schema/index.ts +195 -52
- package/src/util/index.ts +23 -0
package/dist/auth/passkey.js
CHANGED
|
@@ -75,7 +75,8 @@ export class Passkey {
|
|
|
75
75
|
props.children ?? [
|
|
76
76
|
route.Fields?.(),
|
|
77
77
|
jsx("button", {
|
|
78
|
-
children:
|
|
78
|
+
children: options.submit ??
|
|
79
|
+
(method === "register" ? "Create account" : "Log in"),
|
|
79
80
|
}),
|
|
80
81
|
],
|
|
81
82
|
// A supplied Issue component takes precedence over this accessible fallback.
|
|
@@ -155,8 +156,9 @@ export class Passkey {
|
|
|
155
156
|
throw new Issue("bootstrap binding");
|
|
156
157
|
// the same method as the form's, checked above
|
|
157
158
|
const register = expected.method === "register";
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
// an account that is signed in, or the new one the form was made for
|
|
160
|
+
const user = (register && expected.user) || bootstrap.user;
|
|
161
|
+
if (register && (!user || Codec.encode(user).length > 64))
|
|
160
162
|
throw new Issue("user");
|
|
161
163
|
const rp = new URL(auth.options.origin).hostname;
|
|
162
164
|
const ceremony = crypto.randomUUID();
|
|
@@ -168,7 +170,7 @@ export class Passkey {
|
|
|
168
170
|
action: bootstrap.action,
|
|
169
171
|
origin: bootstrap.origin,
|
|
170
172
|
expiration: Date.now() + 2 * Time.minute,
|
|
171
|
-
...(
|
|
173
|
+
...(user ? { user } : {}),
|
|
172
174
|
...(expected.fields ? { fields: expected.fields } : {}),
|
|
173
175
|
})) === false) {
|
|
174
176
|
return Issue.limited(c, 60);
|
|
@@ -181,11 +183,18 @@ export class Passkey {
|
|
|
181
183
|
challenge,
|
|
182
184
|
rp: { id: rp, name: rp },
|
|
183
185
|
user: {
|
|
184
|
-
id: Codec.Base64Url.encode(Codec.encode(
|
|
186
|
+
id: Codec.Base64Url.encode(Codec.encode(user)),
|
|
185
187
|
name: expected.name,
|
|
186
188
|
displayName: expected.name,
|
|
187
189
|
},
|
|
188
190
|
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
|
|
191
|
+
// an authenticator that holds one of the account's makes no other
|
|
192
|
+
...(expected.exclude?.length && {
|
|
193
|
+
excludeCredentials: expected.exclude.map((id) => ({
|
|
194
|
+
type: "public-key",
|
|
195
|
+
id,
|
|
196
|
+
})),
|
|
197
|
+
}),
|
|
189
198
|
authenticatorSelection: {
|
|
190
199
|
residentKey: "required",
|
|
191
200
|
requireResidentKey: true,
|
|
@@ -341,6 +350,10 @@ export class Passkey {
|
|
|
341
350
|
counter: data.counter,
|
|
342
351
|
eligible: Boolean(data.flags & 8),
|
|
343
352
|
backedUp: Boolean(data.flags & 16),
|
|
353
|
+
created: Date.now(),
|
|
354
|
+
origin: this.#auth.options.origin,
|
|
355
|
+
// what a person calls one they add
|
|
356
|
+
name: null,
|
|
344
357
|
};
|
|
345
358
|
}
|
|
346
359
|
/**
|
package/dist/auth/state.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ export declare class State {
|
|
|
25
25
|
browser(create?: boolean): string | undefined;
|
|
26
26
|
/** Read a non-expired, non-revoked session, renewing it while it is used. */
|
|
27
27
|
session(): Promise<ContextType.Session | null>;
|
|
28
|
+
/**
|
|
29
|
+
* @param within Milliseconds
|
|
30
|
+
* @returns `true` when the person signed in that recently, in this
|
|
31
|
+
* browser: what a session taken over later cannot say
|
|
32
|
+
*/
|
|
33
|
+
recent(within: number): Promise<boolean>;
|
|
28
34
|
/**
|
|
29
35
|
* Return to a local path after the next login, such as an agent's
|
|
30
36
|
* authorization request, or the page that sent the user to log in. Any
|
package/dist/auth/state.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/auth/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,IAAI,WAAW,EAAS,MAAM,qBAAqB,CAAC;AAEzE,OAAO,KAAK,E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AAQ,GAAG,KAAK,CAAC,CAAC;CACnE;AAED,yEAAyE;AACzE,qBAAa,KAAK;;IAQjB,+CAA+C;IAC/C,QAAQ,CAAC,OAAO;;;;;;;MAAC;IAEjB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EASnD;IAeD,oFAAoF;IACpF,OAAO,CAAC,MAAM,UAAQ,sBAQrB;IAiFD,6EAA6E;IAC7E,OAAO,wCAEN;IAKD;;;;OAIG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,oBAG1B;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,QAMpB;IAED;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,UAQtB;IA0BD,yEAAyE;IACnE,KAAK,CAAC,IAAI,EAAE,MAAM;;;;OAqBvB;IAED,kFAAkF;IAC5E,MAAM,kBAOX;CACD"}
|
package/dist/auth/state.js
CHANGED
|
@@ -92,8 +92,10 @@ export class State {
|
|
|
92
92
|
if (session &&
|
|
93
93
|
session.id === id &&
|
|
94
94
|
session.expiration > now &&
|
|
95
|
-
session.started + this.options.lifetime > now)
|
|
95
|
+
session.started + this.options.lifetime > now) {
|
|
96
|
+
this.#started = session.started;
|
|
96
97
|
return this.#renew(session, now);
|
|
98
|
+
}
|
|
97
99
|
this.#clear();
|
|
98
100
|
return null;
|
|
99
101
|
}
|
|
@@ -122,6 +124,17 @@ export class State {
|
|
|
122
124
|
session() {
|
|
123
125
|
return (this.#session ??= this.#read());
|
|
124
126
|
}
|
|
127
|
+
/** When the browser's session signed in, once it is read */
|
|
128
|
+
#started;
|
|
129
|
+
/**
|
|
130
|
+
* @param within Milliseconds
|
|
131
|
+
* @returns `true` when the person signed in that recently, in this
|
|
132
|
+
* browser: what a session taken over later cannot say
|
|
133
|
+
*/
|
|
134
|
+
async recent(within) {
|
|
135
|
+
await this.session();
|
|
136
|
+
return this.#started !== undefined && Date.now() - this.#started <= within;
|
|
137
|
+
}
|
|
125
138
|
/**
|
|
126
139
|
* Return to a local path after the next login, such as an agent's
|
|
127
140
|
* authorization request, or the page that sent the user to log in. Any
|
|
@@ -155,10 +168,20 @@ export class State {
|
|
|
155
168
|
* another host, short enough for a cookie
|
|
156
169
|
*/
|
|
157
170
|
static #local(path) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
path.length
|
|
171
|
+
if (!path.startsWith("/") ||
|
|
172
|
+
path.startsWith("//") ||
|
|
173
|
+
path.includes("\\") ||
|
|
174
|
+
path.length > 2048)
|
|
175
|
+
return false;
|
|
176
|
+
// as a browser reads it: it drops tabs and new lines, so `/\t/host` is
|
|
177
|
+
// `//host`, another site
|
|
178
|
+
const base = "https://local.invalid";
|
|
179
|
+
try {
|
|
180
|
+
return new URL(path, base).origin === base;
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
162
185
|
}
|
|
163
186
|
/** Replace the current session and issue a new signed, secure cookie. */
|
|
164
187
|
async login(user) {
|
package/dist/auth/storage.d.ts
CHANGED
|
@@ -76,6 +76,16 @@ export declare class Storage {
|
|
|
76
76
|
counter: Schema<number>;
|
|
77
77
|
eligible: Schema<boolean>;
|
|
78
78
|
backedUp: Schema<boolean>;
|
|
79
|
+
created: Schema<number>;
|
|
80
|
+
origin: Schema<string>;
|
|
81
|
+
name: Schema<string | null>;
|
|
82
|
+
}, {}>;
|
|
83
|
+
/** One-time sign-in links, by the hash of their token. */
|
|
84
|
+
static readonly links: Table<"auth_links", {
|
|
85
|
+
id: Schema<string>;
|
|
86
|
+
user: Schema<string>;
|
|
87
|
+
origin: Schema<string>;
|
|
88
|
+
expiration: Schema<number>;
|
|
79
89
|
}, {}>;
|
|
80
90
|
/** Revocable sessions. */
|
|
81
91
|
static readonly sessions: Table<"auth_sessions", {
|
|
@@ -117,6 +127,9 @@ export declare class Storage {
|
|
|
117
127
|
counter: Schema<number>;
|
|
118
128
|
eligible: Schema<boolean>;
|
|
119
129
|
backedUp: Schema<boolean>;
|
|
130
|
+
created: Schema<number>;
|
|
131
|
+
origin: Schema<string>;
|
|
132
|
+
name: Schema<string | null>;
|
|
120
133
|
}, {}>, Table<"auth_sessions", {
|
|
121
134
|
id: Schema<string>;
|
|
122
135
|
user: Schema<string>;
|
|
@@ -133,6 +146,11 @@ export declare class Storage {
|
|
|
133
146
|
challenge: Schema<string | null>;
|
|
134
147
|
family: Schema<string>;
|
|
135
148
|
expiration: Schema<number>;
|
|
149
|
+
}, {}>, Table<"auth_links", {
|
|
150
|
+
id: Schema<string>;
|
|
151
|
+
user: Schema<string>;
|
|
152
|
+
origin: Schema<string>;
|
|
153
|
+
expiration: Schema<number>;
|
|
136
154
|
}, {}>];
|
|
137
155
|
/**
|
|
138
156
|
* @param db Database containing the authentication tables
|
|
@@ -181,6 +199,26 @@ export declare class Storage {
|
|
|
181
199
|
readonly challenges: Storage.Challenges;
|
|
182
200
|
readonly sessions: Storage.Sessions;
|
|
183
201
|
readonly credentials: Storage.Credentials;
|
|
202
|
+
readonly links: {
|
|
203
|
+
/**
|
|
204
|
+
* @param token Link's token, stored by its hash
|
|
205
|
+
* @param link Who it signs in, where, and until when
|
|
206
|
+
*/
|
|
207
|
+
set: (token: string, link: {
|
|
208
|
+
user: string;
|
|
209
|
+
origin: string;
|
|
210
|
+
expiration: number;
|
|
211
|
+
}) => Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* Uses a link once: concurrent calls have one winner.
|
|
214
|
+
*
|
|
215
|
+
* @param token Link's token
|
|
216
|
+
* @param origin Origin it is opened at
|
|
217
|
+
* @returns The user it signs in, nothing when it is used, expired, or
|
|
218
|
+
* for another origin
|
|
219
|
+
*/
|
|
220
|
+
take: (token: string, origin: string) => Promise<string | undefined>;
|
|
221
|
+
};
|
|
184
222
|
/**
|
|
185
223
|
* Create the account and its first credential in one transaction.
|
|
186
224
|
*
|
|
@@ -1 +1 @@
|
|
|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,CAAC;QAiExD;;;;;;WAMG;QACH,MAAM,SAAe,MAAM,UAAU,MAAM;QAS3C;;;WAGG;QACH,GAAG,UAAgB,MAAM;MAOxB;IAyEF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAsCrC;IAEF,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAuBjC;IAEF,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,CAgCvC;IAEF,QAAQ,CAAC,KAAK;QACb;;;WAGG;QACH,GAAG,UACK,MAAM,QACP;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAA;SAAE;QAM3D;;;;;;;WAOG;QACH,IAAI,UAAgB,MAAM,UAAU,MAAM;MAWzC;IAEF;;;;;OAKG;IACH,QAAQ,CACP,MAAM,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,EAC/D,UAAU,EAAE,IAAI,CAAC,UAAU,iBAM3B;CACD"}
|
package/dist/auth/storage.js
CHANGED
|
@@ -15,6 +15,17 @@ export class Storage {
|
|
|
15
15
|
counter: Schema.number().int(),
|
|
16
16
|
eligible: Schema.boolean(),
|
|
17
17
|
backedUp: Schema.boolean(),
|
|
18
|
+
// what tells an account's passkeys apart
|
|
19
|
+
created: Schema.number().int(),
|
|
20
|
+
origin: Schema.string(),
|
|
21
|
+
name: Schema.string().nullable(),
|
|
22
|
+
});
|
|
23
|
+
/** One-time sign-in links, by the hash of their token. */
|
|
24
|
+
static links = new Table("auth_links", {
|
|
25
|
+
id: Schema.string(),
|
|
26
|
+
user: Schema.string(),
|
|
27
|
+
origin: Schema.string(),
|
|
28
|
+
expiration: Schema.number().int(),
|
|
18
29
|
});
|
|
19
30
|
/** Revocable sessions. */
|
|
20
31
|
static sessions = new Table("auth_sessions", {
|
|
@@ -64,7 +75,10 @@ export class Storage {
|
|
|
64
75
|
"publicKey" text NOT NULL,
|
|
65
76
|
counter bigint NOT NULL,
|
|
66
77
|
eligible boolean NOT NULL,
|
|
67
|
-
"backedUp" boolean NOT NULL
|
|
78
|
+
"backedUp" boolean NOT NULL,
|
|
79
|
+
created bigint NOT NULL,
|
|
80
|
+
origin text NOT NULL,
|
|
81
|
+
name text
|
|
68
82
|
);
|
|
69
83
|
CREATE INDEX auth_credentials_user ON auth_credentials ("user");
|
|
70
84
|
|
|
@@ -105,7 +119,16 @@ CREATE TABLE auth_tokens (
|
|
|
105
119
|
);
|
|
106
120
|
CREATE INDEX auth_tokens_family ON auth_tokens (family);
|
|
107
121
|
CREATE INDEX auth_tokens_user ON auth_tokens ("user");
|
|
108
|
-
CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration)
|
|
122
|
+
CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);
|
|
123
|
+
|
|
124
|
+
CREATE TABLE auth_links (
|
|
125
|
+
id text PRIMARY KEY,
|
|
126
|
+
"user" text NOT NULL,
|
|
127
|
+
origin text NOT NULL,
|
|
128
|
+
expiration bigint NOT NULL
|
|
129
|
+
);
|
|
130
|
+
CREATE INDEX auth_links_user ON auth_links ("user");
|
|
131
|
+
CREATE INDEX auth_links_expiration ON auth_links (expiration);`,
|
|
109
132
|
},
|
|
110
133
|
];
|
|
111
134
|
/** Tables whose rows belong to a user, and must reference the users table. */
|
|
@@ -113,6 +136,7 @@ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
|
|
|
113
136
|
Storage.credentials,
|
|
114
137
|
Storage.sessions,
|
|
115
138
|
Storage.tokens,
|
|
139
|
+
Storage.links,
|
|
116
140
|
];
|
|
117
141
|
static {
|
|
118
142
|
for (const table of [...Storage.owners, Storage.challenges])
|
|
@@ -151,7 +175,11 @@ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
|
|
|
151
175
|
if (Math.abs(now - this.#pruned) < Time.minute)
|
|
152
176
|
return;
|
|
153
177
|
this.#pruned = now;
|
|
154
|
-
const tables = [
|
|
178
|
+
const tables = [
|
|
179
|
+
Storage.challenges,
|
|
180
|
+
Storage.sessions,
|
|
181
|
+
Storage.links,
|
|
182
|
+
];
|
|
155
183
|
if (this.#oauth)
|
|
156
184
|
tables.push(Storage.tokens);
|
|
157
185
|
for (const table of tables)
|
|
@@ -395,6 +423,35 @@ CREATE INDEX auth_tokens_expiration ON auth_tokens (expiration);`,
|
|
|
395
423
|
return rows.length === 1;
|
|
396
424
|
},
|
|
397
425
|
};
|
|
426
|
+
links = {
|
|
427
|
+
/**
|
|
428
|
+
* @param token Link's token, stored by its hash
|
|
429
|
+
* @param link Who it signs in, where, and until when
|
|
430
|
+
*/
|
|
431
|
+
set: async (token, link) => {
|
|
432
|
+
await this.#prune();
|
|
433
|
+
await this.#db
|
|
434
|
+
.sql `INSERT INTO ${Storage.links} ${this.#db.sql.values(Storage.links, { ...link, id: await Storage.hash(token) })}`;
|
|
435
|
+
},
|
|
436
|
+
/**
|
|
437
|
+
* Uses a link once: concurrent calls have one winner.
|
|
438
|
+
*
|
|
439
|
+
* @param token Link's token
|
|
440
|
+
* @param origin Origin it is opened at
|
|
441
|
+
* @returns The user it signs in, nothing when it is used, expired, or
|
|
442
|
+
* for another origin
|
|
443
|
+
*/
|
|
444
|
+
take: async (token, origin) => {
|
|
445
|
+
const { columns } = Storage.links;
|
|
446
|
+
const [row] = await this.#db.sql `
|
|
447
|
+
DELETE FROM ${Storage.links}
|
|
448
|
+
WHERE ${columns.id} = ${await Storage.hash(token)}
|
|
449
|
+
AND ${columns.origin} = ${origin} AND ${columns.expiration} > ${Date.now()}
|
|
450
|
+
RETURNING *
|
|
451
|
+
`.parse(Storage.links);
|
|
452
|
+
return row?.user;
|
|
453
|
+
},
|
|
454
|
+
};
|
|
398
455
|
/**
|
|
399
456
|
* Create the account and its first credential in one transaction.
|
|
400
457
|
*
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { App } from "../app/index.js";
|
|
2
2
|
import { Cookie } from "../cookie/index.js";
|
|
3
3
|
import { type Field } from "../form/index.js";
|
|
4
|
+
import { Markdown, tools } from "../markdown/index.js";
|
|
4
5
|
import type { Middleware } from "../middleware/index.js";
|
|
5
6
|
import { Multipart } from "../multipart/index.js";
|
|
6
7
|
import { Route } from "../route/index.js";
|
|
@@ -12,15 +13,14 @@ import { type Util } from "../util/index.js";
|
|
|
12
13
|
*/
|
|
13
14
|
export declare const agent: WeakMap<Request, {
|
|
14
15
|
readonly session?: unknown;
|
|
16
|
+
/** The fields the tool call gave, which are all it updates */
|
|
17
|
+
readonly sent?: ReadonlySet<string>;
|
|
15
18
|
issues?: readonly {
|
|
16
19
|
readonly path: string;
|
|
17
20
|
readonly message: string;
|
|
18
21
|
}[];
|
|
19
22
|
/** The tool a form submits to and its arguments, so a page points to it */
|
|
20
|
-
readonly tool?:
|
|
21
|
-
name: string;
|
|
22
|
-
args: Record<string, string>;
|
|
23
|
-
} | undefined;
|
|
23
|
+
readonly tool?: Markdown.Options[typeof tools];
|
|
24
24
|
}>;
|
|
25
25
|
/** Properties to build the final `Response` with once middleware has run. */
|
|
26
26
|
declare class PreparedResponse {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,KAAK,EAA6B,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,K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@@ -238,7 +238,7 @@ export class Context {
|
|
|
238
238
|
// a body too large or not form data throws, for the handler to answer
|
|
239
239
|
const result = await form.parse(post
|
|
240
240
|
? this.multipart({ parts: form.parts, ...options })
|
|
241
|
-
: this.url.searchParams);
|
|
241
|
+
: this.url.searchParams, [], agent.get(this.req)?.sent);
|
|
242
242
|
/**
|
|
243
243
|
* Add the URL to return to with the encoded invalid state.
|
|
244
244
|
*
|
|
@@ -323,8 +323,11 @@ export class Context {
|
|
|
323
323
|
// something to stream
|
|
324
324
|
const [mime] = Header.shift(res.headers.get(Header.name.type));
|
|
325
325
|
if (!mime || mime === Mime.type.html) {
|
|
326
|
-
// pages are HTML for browsers and Markdown for agents that ask for
|
|
327
|
-
|
|
326
|
+
// pages are HTML for browsers and Markdown for agents that ask for
|
|
327
|
+
// it, but a file to download, such as a page to print, is HTML
|
|
328
|
+
// for both
|
|
329
|
+
if (!/^\s*attachment/i.test(res.headers.get("content-disposition") ?? "") &&
|
|
330
|
+
this.#markdown()) {
|
|
328
331
|
res.body = Markdown.stream(r, {
|
|
329
332
|
base: this.url,
|
|
330
333
|
[tools]: agent.get(this.req)?.tool,
|