patchwork-os 1.2.0-beta.3.canary.905 → 1.2.0-beta.3.canary.906
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/dist/attachmentResponse.d.ts +17 -0
- package/dist/attachmentResponse.js +23 -0
- package/dist/attachmentResponse.js.map +1 -0
- package/dist/governance/untrustedContent.d.ts +9 -0
- package/dist/governance/untrustedContent.js +20 -2
- package/dist/governance/untrustedContent.js.map +1 -1
- package/dist/inboxRoutes.js +5 -7
- package/dist/inboxRoutes.js.map +1 -1
- package/dist/recipeOrchestration.js +7 -0
- package/dist/recipeOrchestration.js.map +1 -1
- package/dist/recipeRoutes.js +20 -0
- package/dist/recipeRoutes.js.map +1 -1
- package/dist/recipes/agentExecutor.d.ts +10 -0
- package/dist/recipes/agentExecutor.js +12 -1
- package/dist/recipes/agentExecutor.js.map +1 -1
- package/dist/recipes/chainedRunner.d.ts +13 -0
- package/dist/recipes/chainedRunner.js +48 -7
- package/dist/recipes/chainedRunner.js.map +1 -1
- package/dist/recipes/fileInputs.d.ts +85 -0
- package/dist/recipes/fileInputs.js +157 -0
- package/dist/recipes/fileInputs.js.map +1 -0
- package/dist/recipes/schemaGenerator.js +2 -2
- package/dist/recipes/schemaGenerator.js.map +1 -1
- package/dist/recipes/textInputs.d.ts +10 -4
- package/dist/recipes/textInputs.js +15 -9
- package/dist/recipes/textInputs.js.map +1 -1
- package/dist/recipes/triggerVars.d.ts +4 -3
- package/dist/recipes/triggerVars.js +2 -1
- package/dist/recipes/triggerVars.js.map +1 -1
- package/dist/recipes/validation.js +31 -3
- package/dist/recipes/validation.js.map +1 -1
- package/dist/recipes/yamlRunner.d.ts +6 -0
- package/dist/recipes/yamlRunner.js +58 -8
- package/dist/recipes/yamlRunner.js.map +1 -1
- package/dist/schemas/recipe.v1.json +2 -2
- package/dist/server.js +6 -0
- package/dist/server.js.map +1 -1
- package/dist/uploadStore.d.ts +106 -0
- package/dist/uploadStore.js +434 -0
- package/dist/uploadStore.js.map +1 -0
- package/dist/uploadsRoutes.d.ts +25 -0
- package/dist/uploadsRoutes.js +136 -0
- package/dist/uploadsRoutes.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace uploads — documents a user hands the runtime (notes, a receipt
|
|
3
|
+
* PDF, a photo) so a recipe can work over them with a `type: file` input
|
|
4
|
+
* (`src/recipes/fileInputs.ts`). HTTP surface: `src/uploadsRoutes.ts`.
|
|
5
|
+
*
|
|
6
|
+
* A plain directory, `patchworkPath("uploads")`. The NAME and the BYTES both
|
|
7
|
+
* arrive from the network, so every rule below is a refusal:
|
|
8
|
+
*
|
|
9
|
+
* - **Names.** A stored name is a plain file name: ASCII letters, digits,
|
|
10
|
+
* space and `. _ -`, starting with a letter or digit, at most 128 chars,
|
|
11
|
+
* with an allowed extension. A client name carrying a separator, `..`, a
|
|
12
|
+
* leading dot or a control character is REFUSED (that is an attempt, not
|
|
13
|
+
* a typo); any other character outside the set is replaced with `_`, so
|
|
14
|
+
* "receipt (1).pdf" uploads as "receipt _1_.pdf".
|
|
15
|
+
* - **Never through a symlink.** The directory itself must not be a symlink;
|
|
16
|
+
* an entry is listed, served, resolved or deleted only when `lstat` says it
|
|
17
|
+
* is a regular file; a write never replaces an existing entry (it is
|
|
18
|
+
* linked into place, which fails rather than clobbers).
|
|
19
|
+
* - **Atomic, private writes.** Bytes go to a `0o600` temp file in the same
|
|
20
|
+
* directory, then are hard-linked to the final name.
|
|
21
|
+
* - **Caps refuse, never truncate.** 10 MB per file, 200 MB per workspace.
|
|
22
|
+
* - **Types by extension AND content.** txt, md, csv, json, pdf, png,
|
|
23
|
+
* jpg/jpeg, webp. Binary types must start with their magic bytes; text
|
|
24
|
+
* types must be valid UTF-8 with no NUL and must not open as HTML/SVG/XML.
|
|
25
|
+
* Everything else — html, svg, scripts, executables — is refused.
|
|
26
|
+
* - **A collision gets a numeric suffix** (`notes-1.txt`), never an
|
|
27
|
+
* overwrite.
|
|
28
|
+
*/
|
|
29
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
30
|
+
import { closeSync, constants as fsConstants, fstatSync, lstatSync, openSync, readFileSync, } from "node:fs";
|
|
31
|
+
import { link, lstat, mkdir, open, readdir, unlink } from "node:fs/promises";
|
|
32
|
+
import path from "node:path";
|
|
33
|
+
import { patchworkPath } from "./patchworkHome.js";
|
|
34
|
+
/** Per-file cap. */
|
|
35
|
+
export const UPLOAD_MAX_FILE_BYTES = 10 * 1024 * 1024;
|
|
36
|
+
/** Per-workspace cap over every stored upload. */
|
|
37
|
+
export const UPLOAD_MAX_TOTAL_BYTES = 200 * 1024 * 1024;
|
|
38
|
+
/** Longest stored name. */
|
|
39
|
+
const MAX_NAME_LENGTH = 128;
|
|
40
|
+
/** The uploads directory. Read per call — `PATCHWORK_HOME` may change. */
|
|
41
|
+
export function uploadsDir() {
|
|
42
|
+
return patchworkPath("uploads");
|
|
43
|
+
}
|
|
44
|
+
const startsWith = (magic) => (b) => b.length >= magic.length && magic.every((m, i) => b[i] === m);
|
|
45
|
+
const PDF_MAGIC = startsWith([0x25, 0x50, 0x44, 0x46, 0x2d]); // %PDF-
|
|
46
|
+
const PNG_MAGIC = startsWith([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
47
|
+
const JPG_MAGIC = startsWith([0xff, 0xd8, 0xff]);
|
|
48
|
+
const WEBP_MAGIC = (b) => b.length >= 12 &&
|
|
49
|
+
b.toString("latin1", 0, 4) === "RIFF" &&
|
|
50
|
+
b.toString("latin1", 8, 12) === "WEBP";
|
|
51
|
+
/** Markup a browser would render, if the text ever reached one as a page. */
|
|
52
|
+
const MARKUP_OPENING = /^(?:<!doctype\s+html|<html|<svg|<\?xml|<head|<body|<script)/i;
|
|
53
|
+
function decodeUtf8Strict(b) {
|
|
54
|
+
try {
|
|
55
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(b);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const TEXT_SNIFF = (b) => {
|
|
62
|
+
if (b.includes(0))
|
|
63
|
+
return false;
|
|
64
|
+
const text = decodeUtf8Strict(b);
|
|
65
|
+
if (text === null)
|
|
66
|
+
return false;
|
|
67
|
+
return !MARKUP_OPENING.test(text.replace(/^/, "").trimStart());
|
|
68
|
+
};
|
|
69
|
+
const JSON_SNIFF = (b) => {
|
|
70
|
+
if (!TEXT_SNIFF(b))
|
|
71
|
+
return false;
|
|
72
|
+
try {
|
|
73
|
+
JSON.parse((decodeUtf8Strict(b) ?? "").replace(/^/, ""));
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const UPLOAD_TYPES = {
|
|
81
|
+
txt: { contentType: "text/plain; charset=utf-8", sniff: TEXT_SNIFF },
|
|
82
|
+
md: { contentType: "text/markdown; charset=utf-8", sniff: TEXT_SNIFF },
|
|
83
|
+
csv: { contentType: "text/csv; charset=utf-8", sniff: TEXT_SNIFF },
|
|
84
|
+
json: { contentType: "application/json", sniff: JSON_SNIFF },
|
|
85
|
+
pdf: { contentType: "application/pdf", sniff: PDF_MAGIC },
|
|
86
|
+
png: { contentType: "image/png", sniff: PNG_MAGIC },
|
|
87
|
+
jpg: { contentType: "image/jpeg", sniff: JPG_MAGIC },
|
|
88
|
+
jpeg: { contentType: "image/jpeg", sniff: JPG_MAGIC },
|
|
89
|
+
webp: { contentType: "image/webp", sniff: WEBP_MAGIC },
|
|
90
|
+
};
|
|
91
|
+
/** The allowed extensions, for messages. */
|
|
92
|
+
export const UPLOAD_EXTENSIONS = Object.keys(UPLOAD_TYPES);
|
|
93
|
+
function extensionOf(name) {
|
|
94
|
+
const dot = name.lastIndexOf(".");
|
|
95
|
+
return dot <= 0 ? "" : name.slice(dot + 1).toLowerCase();
|
|
96
|
+
}
|
|
97
|
+
function typeOf(name) {
|
|
98
|
+
const ext = extensionOf(name);
|
|
99
|
+
return Object.hasOwn(UPLOAD_TYPES, ext) ? UPLOAD_TYPES[ext] : undefined;
|
|
100
|
+
}
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// Names
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
const NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._ -]*$/;
|
|
105
|
+
// Device names Windows will not let a file have, whatever the extension.
|
|
106
|
+
const WINDOWS_RESERVED = /^(?:con|prn|aux|nul|com\d|lpt\d)(?:\.|$)/i;
|
|
107
|
+
/**
|
|
108
|
+
* Why `name` is not a valid STORED upload name, or null when it is. Strict —
|
|
109
|
+
* no sanitising — because this is what a run input value and a URL segment
|
|
110
|
+
* are held to: a name that would need changing is not the name of an upload.
|
|
111
|
+
*/
|
|
112
|
+
export function uploadNameError(name) {
|
|
113
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
114
|
+
return "must be a non-empty file name";
|
|
115
|
+
}
|
|
116
|
+
if (name.length > MAX_NAME_LENGTH) {
|
|
117
|
+
return `must be at most ${MAX_NAME_LENGTH} characters`;
|
|
118
|
+
}
|
|
119
|
+
if (!NAME_RE.test(name)) {
|
|
120
|
+
return "must be a plain file name: letters, digits, spaces and . _ - only, starting with a letter or digit";
|
|
121
|
+
}
|
|
122
|
+
if (name.includes(".."))
|
|
123
|
+
return 'must not contain ".."';
|
|
124
|
+
if (/[ .]$/.test(name))
|
|
125
|
+
return "must not end with a space or a dot";
|
|
126
|
+
if (WINDOWS_RESERVED.test(name))
|
|
127
|
+
return "is a reserved device name";
|
|
128
|
+
if (!typeOf(name)) {
|
|
129
|
+
return `must end in one of: ${UPLOAD_EXTENSIONS.map((e) => `.${e}`).join(", ")}`;
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
function fail(status, code, error) {
|
|
134
|
+
return { ok: false, status, code, error };
|
|
135
|
+
}
|
|
136
|
+
// C0, DEL and C1 — never part of a name.
|
|
137
|
+
const CONTROL_RE = /[\u0000-\u001F\u007F-\u009F]/u;
|
|
138
|
+
/**
|
|
139
|
+
* Turn a client-supplied file name into a stored one. Refuses outright what
|
|
140
|
+
* can only be an attempt — a separator, `..`, a leading dot, a control
|
|
141
|
+
* character — and replaces any other character outside the stored-name set
|
|
142
|
+
* with `_`.
|
|
143
|
+
*/
|
|
144
|
+
export function sanitizeUploadName(raw) {
|
|
145
|
+
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
146
|
+
return fail(400, "upload_name_missing", "A file name is required");
|
|
147
|
+
}
|
|
148
|
+
if (raw.includes("/") ||
|
|
149
|
+
raw.includes("\\") ||
|
|
150
|
+
raw.includes("..") ||
|
|
151
|
+
raw.startsWith(".") ||
|
|
152
|
+
CONTROL_RE.test(raw)) {
|
|
153
|
+
return fail(400, "upload_name_invalid", "The file name must be a plain name — no path separators, no '..', no leading dot and no control characters");
|
|
154
|
+
}
|
|
155
|
+
const name = raw
|
|
156
|
+
.normalize("NFC")
|
|
157
|
+
.trim()
|
|
158
|
+
.replace(/[^A-Za-z0-9._ -]/g, "_");
|
|
159
|
+
const reason = uploadNameError(name);
|
|
160
|
+
if (reason) {
|
|
161
|
+
// The extension is the most common reason, and it is a TYPE refusal.
|
|
162
|
+
if (!typeOf(name)) {
|
|
163
|
+
return fail(415, "upload_type_refused", `This file type is not accepted. Allowed: ${UPLOAD_EXTENSIONS.map((e) => `.${e}`).join(", ")}`);
|
|
164
|
+
}
|
|
165
|
+
return fail(400, "upload_name_invalid", `The file name ${reason}`);
|
|
166
|
+
}
|
|
167
|
+
return { ok: true, name };
|
|
168
|
+
}
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
// Directory
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
/**
|
|
173
|
+
* Create the uploads directory (0o700) if needed, and refuse to use it when
|
|
174
|
+
* it is anything but a real directory — a symlinked uploads dir would turn
|
|
175
|
+
* every write into a write somewhere else.
|
|
176
|
+
*/
|
|
177
|
+
async function ensureDir() {
|
|
178
|
+
const dir = uploadsDir();
|
|
179
|
+
await mkdir(path.dirname(dir), { recursive: true });
|
|
180
|
+
try {
|
|
181
|
+
await mkdir(dir, { mode: 0o700 });
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
if (err.code !== "EEXIST")
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
187
|
+
const st = await lstat(dir);
|
|
188
|
+
if (!st.isDirectory() || st.isSymbolicLink()) {
|
|
189
|
+
return fail(500, "upload_store_unavailable", "The uploads directory is not a plain directory");
|
|
190
|
+
}
|
|
191
|
+
return dir;
|
|
192
|
+
}
|
|
193
|
+
function dirIsUsable(dir) {
|
|
194
|
+
try {
|
|
195
|
+
const st = lstatSync(dir);
|
|
196
|
+
return st.isDirectory() && !st.isSymbolicLink();
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function sha256Of(bytes) {
|
|
203
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* sha256 by (name, inode, size, mtime). A listing would otherwise re-hash up to
|
|
207
|
+
* 200 MB on every poll; any change to the file changes the key.
|
|
208
|
+
*/
|
|
209
|
+
const hashCache = new Map();
|
|
210
|
+
async function entryFor(dir, name) {
|
|
211
|
+
const full = path.join(dir, name);
|
|
212
|
+
const st = await lstat(full).catch(() => null);
|
|
213
|
+
if (!st?.isFile())
|
|
214
|
+
return null;
|
|
215
|
+
const key = `${name}\u0000${st.ino}\u0000${st.size}\u0000${st.mtimeMs}`;
|
|
216
|
+
let sha = hashCache.get(key);
|
|
217
|
+
if (!sha) {
|
|
218
|
+
const bytes = await readFileNoFollow(full);
|
|
219
|
+
if (!bytes)
|
|
220
|
+
return null;
|
|
221
|
+
sha = sha256Of(bytes);
|
|
222
|
+
hashCache.set(key, sha);
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
name,
|
|
226
|
+
size: st.size,
|
|
227
|
+
sha256: sha,
|
|
228
|
+
contentType: typeOf(name)?.contentType ?? "application/octet-stream",
|
|
229
|
+
uploadedAt: st.mtime.toISOString(),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/** Read a regular file without following a symlink at the last component. */
|
|
233
|
+
async function readFileNoFollow(full) {
|
|
234
|
+
const flags = fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0);
|
|
235
|
+
let fh;
|
|
236
|
+
try {
|
|
237
|
+
fh = await open(full, flags);
|
|
238
|
+
const st = await fh.stat();
|
|
239
|
+
if (!st.isFile())
|
|
240
|
+
return null;
|
|
241
|
+
return await fh.readFile();
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
await fh?.close().catch(() => { });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/** Every stored upload, newest first. A missing directory lists as empty. */
|
|
251
|
+
export async function listUploads() {
|
|
252
|
+
const dir = uploadsDir();
|
|
253
|
+
if (!dirIsUsable(dir))
|
|
254
|
+
return [];
|
|
255
|
+
const out = [];
|
|
256
|
+
for (const name of await readdir(dir)) {
|
|
257
|
+
if (uploadNameError(name) !== null)
|
|
258
|
+
continue;
|
|
259
|
+
const entry = await entryFor(dir, name);
|
|
260
|
+
if (entry)
|
|
261
|
+
out.push(entry);
|
|
262
|
+
}
|
|
263
|
+
out.sort((a, b) => b.uploadedAt.localeCompare(a.uploadedAt));
|
|
264
|
+
return out;
|
|
265
|
+
}
|
|
266
|
+
async function totalBytes(dir) {
|
|
267
|
+
let total = 0;
|
|
268
|
+
for (const name of await readdir(dir)) {
|
|
269
|
+
const st = await lstat(path.join(dir, name)).catch(() => null);
|
|
270
|
+
// Everything in the directory counts, temp files included: the cap is
|
|
271
|
+
// about the disk, not about what the listing shows.
|
|
272
|
+
if (st?.isFile())
|
|
273
|
+
total += st.size;
|
|
274
|
+
}
|
|
275
|
+
return total;
|
|
276
|
+
}
|
|
277
|
+
function withSuffix(name, n) {
|
|
278
|
+
if (n === 0)
|
|
279
|
+
return name;
|
|
280
|
+
const dot = name.lastIndexOf(".");
|
|
281
|
+
return `${name.slice(0, dot)}-${n}${name.slice(dot)}`;
|
|
282
|
+
}
|
|
283
|
+
// One save at a time per process, so two concurrent uploads cannot both pass
|
|
284
|
+
// the total-size check against the same starting total.
|
|
285
|
+
let saveChain = Promise.resolve();
|
|
286
|
+
/** Validate and store one upload. */
|
|
287
|
+
export function saveUpload(rawName, bytes, opts = {}) {
|
|
288
|
+
const run = saveChain.then(() => saveUploadNow(rawName, bytes, opts));
|
|
289
|
+
saveChain = run.catch(() => { });
|
|
290
|
+
return run;
|
|
291
|
+
}
|
|
292
|
+
async function saveUploadNow(rawName, bytes, opts) {
|
|
293
|
+
const maxFile = opts.maxFileBytes ?? UPLOAD_MAX_FILE_BYTES;
|
|
294
|
+
const maxTotal = opts.maxTotalBytes ?? UPLOAD_MAX_TOTAL_BYTES;
|
|
295
|
+
const named = sanitizeUploadName(rawName);
|
|
296
|
+
if (!named.ok)
|
|
297
|
+
return named;
|
|
298
|
+
const type = typeOf(named.name);
|
|
299
|
+
if (!type) {
|
|
300
|
+
return fail(415, "upload_type_refused", "This file type is not accepted");
|
|
301
|
+
}
|
|
302
|
+
if (bytes.length === 0) {
|
|
303
|
+
return fail(400, "upload_empty", "The upload is empty");
|
|
304
|
+
}
|
|
305
|
+
if (bytes.length > maxFile) {
|
|
306
|
+
return fail(413, "upload_too_large", `The file is larger than the ${maxFile}-byte limit`);
|
|
307
|
+
}
|
|
308
|
+
if (!type.sniff(bytes)) {
|
|
309
|
+
return fail(415, "upload_content_mismatch", `The file's content is not a valid .${extensionOf(named.name)} file`);
|
|
310
|
+
}
|
|
311
|
+
const dir = await ensureDir();
|
|
312
|
+
if (typeof dir !== "string")
|
|
313
|
+
return dir;
|
|
314
|
+
const used = await totalBytes(dir);
|
|
315
|
+
if (used + bytes.length > maxTotal) {
|
|
316
|
+
return fail(413, "upload_quota_exceeded", `Uploads are limited to ${maxTotal} bytes per workspace (${used} in use); delete an upload first`);
|
|
317
|
+
}
|
|
318
|
+
const temp = path.join(dir, `.upload-${randomBytes(8).toString("hex")}.partial`);
|
|
319
|
+
const fh = await open(temp, "wx", 0o600);
|
|
320
|
+
try {
|
|
321
|
+
await fh.writeFile(bytes);
|
|
322
|
+
await fh.sync();
|
|
323
|
+
}
|
|
324
|
+
finally {
|
|
325
|
+
await fh.close();
|
|
326
|
+
}
|
|
327
|
+
try {
|
|
328
|
+
for (let n = 0; n < 1000; n++) {
|
|
329
|
+
const candidate = withSuffix(named.name, n);
|
|
330
|
+
if (uploadNameError(candidate) !== null)
|
|
331
|
+
break;
|
|
332
|
+
try {
|
|
333
|
+
// link() never replaces an existing entry — file, dir or symlink —
|
|
334
|
+
// so the collision check and the write are one atomic step.
|
|
335
|
+
await link(temp, path.join(dir, candidate));
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
if (err.code === "EEXIST")
|
|
339
|
+
continue;
|
|
340
|
+
throw err;
|
|
341
|
+
}
|
|
342
|
+
const entry = await entryFor(dir, candidate);
|
|
343
|
+
if (!entry)
|
|
344
|
+
break;
|
|
345
|
+
return {
|
|
346
|
+
ok: true,
|
|
347
|
+
upload: entry,
|
|
348
|
+
...(candidate !== rawName && { renamedFrom: rawName }),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
return fail(409, "upload_name_invalid", "Could not find a free name for this upload");
|
|
352
|
+
}
|
|
353
|
+
finally {
|
|
354
|
+
await unlink(temp).catch(() => { });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/** Read one upload for download. */
|
|
358
|
+
export async function readUpload(name) {
|
|
359
|
+
if (uploadNameError(name) !== null) {
|
|
360
|
+
return fail(400, "upload_name_invalid", "Invalid upload name");
|
|
361
|
+
}
|
|
362
|
+
const dir = uploadsDir();
|
|
363
|
+
if (!dirIsUsable(dir))
|
|
364
|
+
return fail(404, "upload_not_found", "Not found");
|
|
365
|
+
const full = path.join(dir, name);
|
|
366
|
+
const st = await lstat(full).catch(() => null);
|
|
367
|
+
if (!st?.isFile())
|
|
368
|
+
return fail(404, "upload_not_found", "Not found");
|
|
369
|
+
const bytes = await readFileNoFollow(full);
|
|
370
|
+
if (!bytes)
|
|
371
|
+
return fail(404, "upload_not_found", "Not found");
|
|
372
|
+
const entry = await entryFor(dir, name);
|
|
373
|
+
if (!entry)
|
|
374
|
+
return fail(404, "upload_not_found", "Not found");
|
|
375
|
+
return { ok: true, bytes, entry };
|
|
376
|
+
}
|
|
377
|
+
/** Delete one upload. A symlink or directory is never touched. */
|
|
378
|
+
export async function deleteUpload(name) {
|
|
379
|
+
if (uploadNameError(name) !== null) {
|
|
380
|
+
return fail(400, "upload_name_invalid", "Invalid upload name");
|
|
381
|
+
}
|
|
382
|
+
const dir = uploadsDir();
|
|
383
|
+
if (!dirIsUsable(dir))
|
|
384
|
+
return fail(404, "upload_not_found", "Not found");
|
|
385
|
+
const full = path.join(dir, name);
|
|
386
|
+
const st = await lstat(full).catch(() => null);
|
|
387
|
+
if (!st?.isFile())
|
|
388
|
+
return fail(404, "upload_not_found", "Not found");
|
|
389
|
+
await unlink(full);
|
|
390
|
+
return { ok: true };
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* The absolute path of an existing upload, for a `type: file` run input.
|
|
394
|
+
* Synchronous because the run routes validate synchronously. Refuses anything
|
|
395
|
+
* that is not a strict upload name of a regular file in a real uploads dir.
|
|
396
|
+
*/
|
|
397
|
+
export function resolveUploadPath(name) {
|
|
398
|
+
const reason = uploadNameError(name);
|
|
399
|
+
if (reason)
|
|
400
|
+
return { ok: false, error: `is not an upload name: it ${reason}` };
|
|
401
|
+
const dir = uploadsDir();
|
|
402
|
+
if (!dirIsUsable(dir)) {
|
|
403
|
+
return { ok: false, error: `names no upload ("${name}" does not exist)` };
|
|
404
|
+
}
|
|
405
|
+
const full = path.join(dir, name);
|
|
406
|
+
let fd;
|
|
407
|
+
try {
|
|
408
|
+
const st = lstatSync(full);
|
|
409
|
+
if (!st.isFile()) {
|
|
410
|
+
return { ok: false, error: `names no upload ("${name}" does not exist)` };
|
|
411
|
+
}
|
|
412
|
+
fd = openSync(full, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0));
|
|
413
|
+
const fst = fstatSync(fd);
|
|
414
|
+
if (!fst.isFile()) {
|
|
415
|
+
return { ok: false, error: `names no upload ("${name}" does not exist)` };
|
|
416
|
+
}
|
|
417
|
+
const bytes = readFileSync(fd);
|
|
418
|
+
return {
|
|
419
|
+
ok: true,
|
|
420
|
+
name: name,
|
|
421
|
+
path: full,
|
|
422
|
+
size: fst.size,
|
|
423
|
+
sha256: sha256Of(bytes),
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
catch {
|
|
427
|
+
return { ok: false, error: `names no upload ("${name}" does not exist)` };
|
|
428
|
+
}
|
|
429
|
+
finally {
|
|
430
|
+
if (fd !== undefined)
|
|
431
|
+
closeSync(fd);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
//# sourceMappingURL=uploadStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadStore.js","sourceRoot":"","sources":["../src/uploadStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,SAAS,EACT,SAAS,IAAI,WAAW,EACxB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,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,CAAC,CAAC;QAC1E,MAAM,GAAG,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;YAClB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,qBAAqB,IAAI,mBAAmB,EAAE,CAAC;QAC5E,CAAC;QACD,MAAM,KAAK,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;QAC/B,OAAO;YACL,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,IAAc;YACpB,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC;SACxB,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,qBAAqB,IAAI,mBAAmB,EAAE,CAAC;IAC5E,CAAC;YAAS,CAAC;QACT,IAAI,EAAE,KAAK,SAAS;YAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace upload routes. Mounted after the Bearer gate in server.ts, like
|
|
3
|
+
* `tryHandleInboxRoute`; the storage rules live in `src/uploadStore.ts`.
|
|
4
|
+
*
|
|
5
|
+
* POST /uploads raw body; name in `X-Upload-Filename`
|
|
6
|
+
* (percent-encoded UTF-8). 201 → `{ ok, upload,
|
|
7
|
+
* renamedFrom? }`. The stored name may differ: a
|
|
8
|
+
* collision gets `-1`, `-2`…, and characters outside
|
|
9
|
+
* the name set become `_`.
|
|
10
|
+
* GET /uploads `{ uploads: [{ name, size, sha256, contentType,
|
|
11
|
+
* uploadedAt }] }`, newest first.
|
|
12
|
+
* GET /uploads/:name the bytes, always as an attachment with a generic
|
|
13
|
+
* `application/octet-stream` type — never rendered.
|
|
14
|
+
* DELETE /uploads/:name `{ ok: true }`.
|
|
15
|
+
*
|
|
16
|
+
* Errors are `{ ok: false, error, code }` with the status from the store
|
|
17
|
+
* (400 name, 413 size/quota, 415 type/content, 404 missing).
|
|
18
|
+
*
|
|
19
|
+
* The request's own `Content-Type` is not trusted for anything: the type is
|
|
20
|
+
* decided by the name's extension and checked against the bytes.
|
|
21
|
+
*/
|
|
22
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
23
|
+
/** Header carrying the client's file name (percent-encoded UTF-8). */
|
|
24
|
+
export declare const UPLOAD_FILENAME_HEADER = "x-upload-filename";
|
|
25
|
+
export declare function tryHandleUploadsRoute(req: IncomingMessage, res: ServerResponse, parsedUrl: URL): boolean;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace upload routes. Mounted after the Bearer gate in server.ts, like
|
|
3
|
+
* `tryHandleInboxRoute`; the storage rules live in `src/uploadStore.ts`.
|
|
4
|
+
*
|
|
5
|
+
* POST /uploads raw body; name in `X-Upload-Filename`
|
|
6
|
+
* (percent-encoded UTF-8). 201 → `{ ok, upload,
|
|
7
|
+
* renamedFrom? }`. The stored name may differ: a
|
|
8
|
+
* collision gets `-1`, `-2`…, and characters outside
|
|
9
|
+
* the name set become `_`.
|
|
10
|
+
* GET /uploads `{ uploads: [{ name, size, sha256, contentType,
|
|
11
|
+
* uploadedAt }] }`, newest first.
|
|
12
|
+
* GET /uploads/:name the bytes, always as an attachment with a generic
|
|
13
|
+
* `application/octet-stream` type — never rendered.
|
|
14
|
+
* DELETE /uploads/:name `{ ok: true }`.
|
|
15
|
+
*
|
|
16
|
+
* Errors are `{ ok: false, error, code }` with the status from the store
|
|
17
|
+
* (400 name, 413 size/quota, 415 type/content, 404 missing).
|
|
18
|
+
*
|
|
19
|
+
* The request's own `Content-Type` is not trusted for anything: the type is
|
|
20
|
+
* decided by the name's extension and checked against the bytes.
|
|
21
|
+
*/
|
|
22
|
+
import { sendAttachment } from "./attachmentResponse.js";
|
|
23
|
+
import { respond500 } from "./httpErrorResponse.js";
|
|
24
|
+
import { readBodyWithCap } from "./recipeRoutes.js";
|
|
25
|
+
import { deleteUpload, listUploads, readUpload, saveUpload, UPLOAD_MAX_FILE_BYTES, } from "./uploadStore.js";
|
|
26
|
+
/** Header carrying the client's file name (percent-encoded UTF-8). */
|
|
27
|
+
export const UPLOAD_FILENAME_HEADER = "x-upload-filename";
|
|
28
|
+
function sendJson(res, status, body) {
|
|
29
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
30
|
+
res.end(JSON.stringify(body));
|
|
31
|
+
}
|
|
32
|
+
function sendFailure(res, f) {
|
|
33
|
+
sendJson(res, f.status, { ok: false, error: f.error, code: f.code });
|
|
34
|
+
}
|
|
35
|
+
function decodeSegment(raw) {
|
|
36
|
+
try {
|
|
37
|
+
return decodeURIComponent(raw);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function tryHandleUploadsRoute(req, res, parsedUrl) {
|
|
44
|
+
const pathname = parsedUrl.pathname;
|
|
45
|
+
if (pathname === "/uploads" && req.method === "GET") {
|
|
46
|
+
void (async () => {
|
|
47
|
+
try {
|
|
48
|
+
sendJson(res, 200, { uploads: await listUploads() });
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
respond500(res, err);
|
|
52
|
+
}
|
|
53
|
+
})();
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (pathname === "/uploads" && req.method === "POST") {
|
|
57
|
+
void (async () => {
|
|
58
|
+
try {
|
|
59
|
+
const header = req.headers?.[UPLOAD_FILENAME_HEADER];
|
|
60
|
+
const rawHeader = Array.isArray(header) ? header[0] : header;
|
|
61
|
+
// Read (and drain) the body before answering anything, so a refused
|
|
62
|
+
// upload still gets a clean response rather than a reset socket.
|
|
63
|
+
const read = await readBodyWithCap(req, UPLOAD_MAX_FILE_BYTES);
|
|
64
|
+
if (!read.ok) {
|
|
65
|
+
sendJson(res, 413, {
|
|
66
|
+
ok: false,
|
|
67
|
+
error: `The file is larger than the ${UPLOAD_MAX_FILE_BYTES}-byte limit`,
|
|
68
|
+
code: "upload_too_large",
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (typeof rawHeader !== "string" || rawHeader.length === 0) {
|
|
73
|
+
sendJson(res, 400, {
|
|
74
|
+
ok: false,
|
|
75
|
+
error: `A file name is required in the ${UPLOAD_FILENAME_HEADER} header`,
|
|
76
|
+
code: "upload_name_missing",
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const name = decodeSegment(rawHeader);
|
|
81
|
+
if (name === null) {
|
|
82
|
+
sendJson(res, 400, {
|
|
83
|
+
ok: false,
|
|
84
|
+
error: "The file name is not valid percent-encoded UTF-8",
|
|
85
|
+
code: "upload_name_invalid",
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const saved = await saveUpload(name, read.bytes);
|
|
90
|
+
if (!saved.ok) {
|
|
91
|
+
sendFailure(res, saved);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
sendJson(res, 201, saved);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
respond500(res, err);
|
|
98
|
+
}
|
|
99
|
+
})();
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
const match = pathname?.match(/^\/uploads\/([^/]+)$/);
|
|
103
|
+
if (match && (req.method === "GET" || req.method === "DELETE")) {
|
|
104
|
+
const name = decodeSegment(match[1] ?? "") ?? "";
|
|
105
|
+
void (async () => {
|
|
106
|
+
try {
|
|
107
|
+
if (req.method === "DELETE") {
|
|
108
|
+
const r = await deleteUpload(name);
|
|
109
|
+
if (!r.ok)
|
|
110
|
+
sendFailure(res, r);
|
|
111
|
+
else
|
|
112
|
+
sendJson(res, 200, { ok: true });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const r = await readUpload(name);
|
|
116
|
+
if (!r.ok) {
|
|
117
|
+
sendFailure(res, r);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// A generic type, whatever the file is: a download is never rendered,
|
|
121
|
+
// and the dashboard proxy streams this type through byte for byte.
|
|
122
|
+
sendAttachment(res, {
|
|
123
|
+
name: r.entry.name,
|
|
124
|
+
bytes: r.bytes,
|
|
125
|
+
contentType: "application/octet-stream",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
respond500(res, err);
|
|
130
|
+
}
|
|
131
|
+
})();
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=uploadsRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadsRoutes.js","sourceRoot":"","sources":["../src/uploadsRoutes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACL,YAAY,EACZ,WAAW,EACX,UAAU,EACV,UAAU,EACV,qBAAqB,GAEtB,MAAM,kBAAkB,CAAC;AAE1B,sEAAsE;AACtE,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAE1D,SAAS,QAAQ,CAAC,GAAmB,EAAE,MAAc,EAAE,IAAa;IAClE,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC9D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,WAAW,CAAC,GAAmB,EAAE,CAAgB;IACxD,QAAQ,CAAC,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CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "patchwork-os",
|
|
3
|
-
"version": "1.2.0-beta.3.canary.
|
|
3
|
+
"version": "1.2.0-beta.3.canary.906",
|
|
4
4
|
"description": "Your personal AI runtime, local-first. Patchwork OS gives any AI model a consistent set of tools, YAML recipes, a delegation policy with approval queue, and a durable trace memory — all on your machine, all under your policy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|