@agimon-ai/po-artifact 0.0.0-alpha.2 → 0.0.0-alpha.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/LICENSE +149 -21
- package/README.md +1 -1
- package/dist/apiContracts.cjs +10 -2
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/apiContracts.mjs +10 -2
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/{artifactFiles-Bo5Mhwq0.cjs → artifactFiles-BmBU9Olm.cjs} +138 -76
- package/dist/artifactFiles-BmBU9Olm.cjs.map +1 -0
- package/dist/{artifactFiles-B8w_HQXv.mjs → artifactFiles-DyIkevXc.mjs} +119 -57
- package/dist/artifactFiles-DyIkevXc.mjs.map +1 -0
- package/dist/artifactFiles.cjs +7 -1
- package/dist/artifactFiles.d.mts +14 -1
- package/dist/artifactFiles.d.mts.map +1 -1
- package/dist/artifactFiles.mjs +3 -1
- package/dist/artifacts-Bhobz1nK.mjs +38 -0
- package/dist/artifacts-Bhobz1nK.mjs.map +1 -0
- package/dist/artifacts-DG_b7DZH.cjs +85 -0
- package/dist/artifacts-DG_b7DZH.cjs.map +1 -0
- package/dist/artifacts-sIj4Xaeu.d.mts +32 -0
- package/dist/artifacts-sIj4Xaeu.d.mts.map +1 -0
- package/dist/extensions/native.mjs +640 -32
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +163 -44
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts +2 -2
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +161 -42
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +848 -136
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.d.mts +8 -19
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +20 -20
- package/dist/artifactFiles-B8w_HQXv.mjs.map +0 -1
- package/dist/artifactFiles-Bo5Mhwq0.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifactFiles-BmBU9Olm.cjs","names":["path","piAgentDirectory","ARTIFACT_DIRECTORY","ARTIFACT_CONTENT_TYPES","path","fs","constants","randomUUID"],"sources":["../src/services/artifactFiles/artifactPaths.ts","../src/services/artifactFiles/index.ts"],"sourcesContent":["import path from 'node:path';\n\nimport { piAgentDirectory } from '@agimon-ai/po-core/piSettings';\n\nimport { ARTIFACT_CONTENT_TYPES, ARTIFACT_DIRECTORY } from '../../constants/artifacts';\n\nexport class ArtifactAccessError extends Error {\n constructor(\n message: string,\n readonly status: 400 | 403 | 404 | 413,\n ) {\n super(message);\n }\n}\n\nexport function artifactRoot(sessionId: string, environment: Readonly<Record<string, string | undefined>>): string {\n if (!/^[a-zA-Z0-9_-]+$/u.test(sessionId)) throw new ArtifactAccessError('Invalid artifact session identity.', 400);\n return path.join(piAgentDirectory(environment, environment.HOME), ARTIFACT_DIRECTORY, sessionId);\n}\n\nexport function artifactMimeType(relativePath: string): string {\n return ARTIFACT_CONTENT_TYPES[path.extname(relativePath).toLowerCase()] ?? 'application/octet-stream';\n}\n","import { randomUUID } from 'node:crypto';\nimport { constants } from 'node:fs';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { WORKFLOW_ARTIFACT_DIRECTORY } from '../../constants/artifacts';\nimport type { ArtifactItem, ArtifactSnapshot, ArtifactWorkflowVisibility } from '../../types/artifacts';\nimport { ArtifactAccessError, artifactMimeType, artifactRoot } from './artifactPaths';\n\nexport { ArtifactAccessError, artifactMimeType, artifactRoot } from './artifactPaths';\n\nfunction inside(root: string, candidate: string): boolean {\n const relative = path.relative(root, candidate);\n return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);\n}\n\nfunction codeOf(error: unknown): string | undefined {\n return error instanceof Error && 'code' in error ? String(error.code) : undefined;\n}\n\n/** The owned directories must not redirect artifact access through a symlink. */\nasync function checkedRoot(root: string): Promise<string> {\n const base = path.dirname(root);\n for (const directory of [base, root]) {\n const stat = await fs.lstat(directory);\n if (!stat.isDirectory() || stat.isSymbolicLink())\n throw new ArtifactAccessError('The artifact folder is unavailable.', 403);\n }\n const realBase = await fs.realpath(base);\n const realRoot = await fs.realpath(root);\n if (!inside(realBase, realRoot))\n throw new ArtifactAccessError('The artifact folder is outside its storage directory.', 403);\n return realRoot;\n}\n\nexport async function ensureArtifactRoot(root: string): Promise<void> {\n await fs.mkdir(path.dirname(root), { recursive: true, mode: 0o700 });\n await fs.mkdir(root, { recursive: true, mode: 0o700 });\n await checkedRoot(root);\n}\n\n/** Open without following mutable ancestors. Node exposes no portable openat API. */\nasync function openContained(root: string, segments: string[]): Promise<fs.FileHandle> {\n if (process.platform === 'darwin') {\n // Darwin O_NOFOLLOW_ANY checks every component atomically. Do not combine it with O_NOFOLLOW.\n return fs.open(path.join(root, ...segments), constants.O_RDONLY | constants.O_NONBLOCK | 0x20000000);\n }\n if (process.platform !== 'linux') throw new ArtifactAccessError('Secure artifact reads require macOS or Linux.', 403);\n const flags = constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW;\n let directory = await fs.open(path.dirname(root), flags);\n try {\n for (const segment of [path.basename(root), ...segments.slice(0, -1)]) {\n const child = await fs.open(`/proc/self/fd/${directory.fd}/${segment}`, flags);\n await directory.close();\n directory = child;\n }\n return await fs.open(\n `/proc/self/fd/${directory.fd}/${segments.at(-1)!}`,\n constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK,\n );\n } finally {\n await directory.close();\n }\n}\n\nfunction artifactSegments(requested: string | undefined): string[] {\n if (\n !requested ||\n requested.includes('\\0') ||\n requested.includes('\\\\') ||\n path.isAbsolute(requested) ||\n requested.split('/').some((part) => part === '..' || part === '.' || part === '')\n )\n throw new ArtifactAccessError('Invalid artifact path.', 400);\n return requested.split('/');\n}\n\nfunction accessError(error: unknown, action: string): unknown {\n if (error instanceof ArtifactAccessError) return error;\n if (codeOf(error) === 'ENOENT' || codeOf(error) === 'ENOTDIR')\n return new ArtifactAccessError('The artifact no longer exists.', 404);\n if (codeOf(error) === 'EACCES' || codeOf(error) === 'EPERM' || codeOf(error) === 'ELOOP')\n return new ArtifactAccessError(`The artifact cannot be ${action}.`, 403);\n return error;\n}\n\n/** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */\nexport async function openArtifact(\n root: string,\n requested: string | undefined,\n workflowVisible?: ArtifactWorkflowVisibility,\n) {\n const segments = artifactSegments(requested);\n if (segments[0] === WORKFLOW_ARTIFACT_DIRECTORY && !workflowVisible?.(segments.slice(1).join('/'), 'file'))\n throw new ArtifactAccessError('This workflow file is private.', 403);\n try {\n const realRoot = await checkedRoot(root);\n const candidate = path.resolve(realRoot, requested!);\n if (!inside(realRoot, candidate))\n throw new ArtifactAccessError('The artifact is outside this session folder.', 403);\n let current = realRoot;\n for (let index = 0; index < segments.length; index += 1) {\n current = path.join(current, segments[index]!);\n const stat = await fs.lstat(current);\n if (stat.isSymbolicLink()) throw new ArtifactAccessError('Artifact symlinks cannot be read.', 403);\n if (index < segments.length - 1 ? !stat.isDirectory() : !stat.isFile())\n throw new ArtifactAccessError('The artifact is not a regular file.', 404);\n }\n const real = await fs.realpath(candidate);\n if (!inside(realRoot, real)) throw new ArtifactAccessError('The artifact is outside this session folder.', 403);\n const expected = await fs.lstat(real);\n const handle = await openContained(realRoot, segments);\n try {\n const stat = await handle.stat();\n if (!stat.isFile() || stat.dev !== expected.dev || stat.ino !== expected.ino)\n throw new ArtifactAccessError('The artifact changed while it was opened. Try again.', 403);\n return { handle, stat, path: requested!, mimeType: artifactMimeType(requested!) };\n } catch (error) {\n await handle.close();\n throw error;\n }\n } catch (error) {\n throw accessError(error, 'read');\n }\n}\n\n/** Bound allocation and read length even when the file grows after its metadata was read. */\nexport async function readArtifactBytes(handle: fs.FileHandle, size: number, offset = 0): Promise<Uint8Array> {\n const bytes = new Uint8Array(size);\n let read = 0;\n while (read < size) {\n const result = await handle.read(bytes, read, size - read, offset + read);\n if (result.bytesRead === 0) break;\n read += result.bytesRead;\n }\n return bytes.subarray(0, read);\n}\n\n/** Walk to the parent folder without following symlinks, creating missing folders on request. */\nasync function containedParent(realRoot: string, segments: string[], create: boolean): Promise<string> {\n let directory = realRoot;\n for (const segment of segments.slice(0, -1)) {\n directory = path.join(directory, segment);\n if (create)\n await fs.mkdir(directory, { mode: 0o700 }).catch((error: unknown) => {\n if (codeOf(error) !== 'EEXIST') throw error;\n });\n const stat = await fs.lstat(directory);\n if (stat.isSymbolicLink() || !stat.isDirectory())\n throw new ArtifactAccessError('The artifact folder is not a directory.', 403);\n }\n return directory;\n}\n\nasync function sameText(root: string, requested: string, bytes: Buffer): Promise<boolean> {\n try {\n const file = await openArtifact(root, requested);\n try {\n if (file.stat.size !== bytes.length) return false;\n return bytes.equals(await readArtifactBytes(file.handle, file.stat.size));\n } finally {\n await file.handle.close();\n }\n } catch (error) {\n if (error instanceof ArtifactAccessError) return false;\n throw error;\n }\n}\n\n/**\n * Publish text through a same-folder temp file and rename, skipping identical content so mtimes stay stable.\n * ponytail: best-effort same-user guards, not race-resistant. Linux checks ancestors with lstat only;\n * walk with openat-style /proc/self/fd handles like openContained if artifacts cross a trust boundary.\n */\nexport async function writeArtifactText(root: string, requested: string, text: string): Promise<void> {\n const segments = artifactSegments(requested);\n if (process.platform !== 'darwin' && process.platform !== 'linux')\n throw new ArtifactAccessError('Secure artifact writes require macOS or Linux.', 403);\n const bytes = Buffer.from(text, 'utf8');\n try {\n await ensureArtifactRoot(root);\n const directory = await containedParent(await checkedRoot(root), segments, true);\n if (await sameText(root, requested, bytes)) return;\n const temp = path.join(directory, `.${segments.at(-1)!}.${randomUUID()}.tmp`);\n // Darwin O_NOFOLLOW_ANY refuses a symlink in any component; O_EXCL refuses one at the leaf.\n const flags =\n constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (process.platform === 'darwin' ? 0x20000000 : 0);\n const handle = await fs.open(temp, flags, 0o600);\n try {\n await handle.writeFile(bytes);\n await handle.close();\n await fs.rename(temp, path.join(directory, segments.at(-1)!));\n } catch (error) {\n await handle.close().catch(() => undefined);\n await fs.unlink(temp).catch(() => undefined);\n throw error;\n }\n } catch (error) {\n throw accessError(error, 'written');\n }\n}\n\n/** Remove one file or one empty folder. A missing target is already removed; nothing is deleted recursively. */\nexport async function removeArtifact(root: string, requested: string): Promise<void> {\n const segments = artifactSegments(requested);\n try {\n const target = path.join(await containedParent(await checkedRoot(root), segments, false), segments.at(-1)!);\n const stat = await fs.lstat(target);\n if (stat.isFile()) await fs.unlink(target);\n else if (!stat.isDirectory()) throw new ArtifactAccessError('The artifact is not a file or folder.', 403);\n else\n await fs.rmdir(target).catch((error: unknown) => {\n if (codeOf(error) !== 'ENOTEMPTY' && codeOf(error) !== 'EEXIST') throw error;\n });\n } catch (error) {\n if (codeOf(error) === 'ENOENT') return;\n throw accessError(error, 'removed');\n }\n}\n/** Discover persisted session roots without admitting symlinked or malformed owners. */\nexport async function listArtifactSessions(\n environment: Readonly<Record<string, string | undefined>>,\n): Promise<readonly string[]> {\n const parent = path.dirname(artifactRoot('discovery', environment));\n try {\n const stat = await fs.lstat(parent);\n if (!stat.isDirectory() || stat.isSymbolicLink())\n throw new ArtifactAccessError('The artifact storage directory is unavailable.', 403);\n const entries = await fs.readdir(parent, { withFileTypes: true });\n return entries\n .filter((entry) => entry.isDirectory() && /^[a-zA-Z0-9_-]+$/u.test(entry.name))\n .map((entry) => entry.name);\n } catch (error) {\n if (codeOf(error) === 'ENOENT') return [];\n throw error;\n }\n}\n\nexport async function listArtifacts(\n root: string,\n workflowVisible?: ArtifactWorkflowVisibility,\n): Promise<ArtifactSnapshot> {\n const items: ArtifactItem[] = [];\n try {\n const realRoot = await checkedRoot(root);\n const visit = async (directory: string): Promise<void> => {\n for (const entry of await fs.readdir(directory, { withFileTypes: true })) {\n const location = path.join(directory, entry.name);\n const relativePath = path.relative(realRoot, location).split(path.sep).join('/');\n const segments = relativePath.split('/');\n if (\n segments[0] === WORKFLOW_ARTIFACT_DIRECTORY &&\n !workflowVisible?.(segments.slice(1).join('/'), entry.isDirectory() ? 'directory' : 'file')\n )\n continue;\n if (entry.isDirectory()) {\n // Recheck each directory rather than trusting a readdir entry across a rename.\n const stat = await fs.lstat(location);\n if (!stat.isDirectory() || stat.isSymbolicLink()) continue;\n const real = await fs.realpath(location);\n if (inside(realRoot, real)) await visit(real);\n } else if (entry.isFile()) {\n try {\n const file = await openArtifact(root, relativePath, workflowVisible);\n try {\n items.push({ path: relativePath, name: entry.name, size: file.stat.size, modifiedAt: file.stat.mtimeMs });\n } finally {\n await file.handle.close();\n }\n } catch (error) {\n if (error instanceof ArtifactAccessError && (error.status === 404 || error.status === 403)) continue;\n throw error;\n }\n }\n }\n };\n await visit(realRoot);\n items.sort(\n (left, right) =>\n right.modifiedAt - left.modifiedAt || (left.path < right.path ? -1 : left.path > right.path ? 1 : 0),\n );\n return { items };\n } catch (error) {\n if (codeOf(error) === 'ENOENT') return { items: [] };\n return { items: [], error: error instanceof Error ? error.message : 'The artifact folder could not be read.' };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAa,sBAAb,cAAyC,MAAM;CAGlC;CAFX,YACE,SACA,QACA;EACA,MAAM,OAAO;EAFJ,KAAA,SAAA;CAGX;AACF;AAEA,SAAgB,aAAa,WAAmB,aAAmE;CACjH,IAAI,CAAC,oBAAoB,KAAK,SAAS,GAAG,MAAM,IAAI,oBAAoB,sCAAsC,GAAG;CACjH,OAAOA,UAAAA,QAAK,MAAA,GAAKC,8BAAAA,iBAAAA,CAAiB,aAAa,YAAY,IAAI,GAAGC,kBAAAA,oBAAoB,SAAS;AACjG;AAEA,SAAgB,iBAAiB,cAA8B;CAC7D,OAAOC,kBAAAA,uBAAuBH,UAAAA,QAAK,QAAQ,YAAY,CAAC,CAAC,YAAY,MAAM;AAC7E;;;ACXA,SA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@ -1,38 +1,9 @@
|
|
|
1
|
+
import { n as ARTIFACT_CONTENT_TYPES, r as ARTIFACT_DIRECTORY } from "./artifacts-Bhobz1nK.mjs";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
1
3
|
import { constants } from "node:fs";
|
|
2
4
|
import fs from "node:fs/promises";
|
|
3
5
|
import path from "node:path";
|
|
4
6
|
import { piAgentDirectory } from "@agimon-ai/po-core/piSettings";
|
|
5
|
-
//#region src/constants/artifacts.ts
|
|
6
|
-
const ARTIFACT_DIRECTORY = "doom-artifacts";
|
|
7
|
-
const MAX_PREVIEW_BYTES = 1048576;
|
|
8
|
-
const MAX_CONTENT_BYTES = 26214400;
|
|
9
|
-
const ARTIFACT_REFRESH_MS = 2e3;
|
|
10
|
-
const ARTIFACT_CONTENT_TYPES = {
|
|
11
|
-
".avif": "image/avif",
|
|
12
|
-
".bmp": "image/bmp",
|
|
13
|
-
".gif": "image/gif",
|
|
14
|
-
".jpeg": "image/jpeg",
|
|
15
|
-
".jpg": "image/jpeg",
|
|
16
|
-
".png": "image/png",
|
|
17
|
-
".svg": "image/svg+xml",
|
|
18
|
-
".webp": "image/webp",
|
|
19
|
-
".ico": "image/vnd.microsoft.icon",
|
|
20
|
-
".mp3": "audio/mpeg",
|
|
21
|
-
".wav": "audio/wav",
|
|
22
|
-
".m4a": "audio/mp4",
|
|
23
|
-
".ogg": "audio/ogg",
|
|
24
|
-
".m4v": "video/mp4",
|
|
25
|
-
".mov": "video/quicktime",
|
|
26
|
-
".mp4": "video/mp4",
|
|
27
|
-
".webm": "video/webm",
|
|
28
|
-
".pdf": "application/pdf",
|
|
29
|
-
".md": "text/markdown; charset=utf-8",
|
|
30
|
-
".markdown": "text/markdown; charset=utf-8",
|
|
31
|
-
".txt": "text/plain; charset=utf-8",
|
|
32
|
-
".html": "text/html; charset=utf-8",
|
|
33
|
-
".htm": "text/html; charset=utf-8"
|
|
34
|
-
};
|
|
35
|
-
//#endregion
|
|
36
7
|
//#region src/services/artifactFiles/artifactPaths.ts
|
|
37
8
|
var ArtifactAccessError = class extends Error {
|
|
38
9
|
status;
|
|
@@ -97,15 +68,25 @@ async function openContained(root, segments) {
|
|
|
97
68
|
await directory.close();
|
|
98
69
|
}
|
|
99
70
|
}
|
|
100
|
-
|
|
101
|
-
async function openArtifact(root, requested) {
|
|
71
|
+
function artifactSegments(requested) {
|
|
102
72
|
if (!requested || requested.includes("\0") || requested.includes("\\") || path.isAbsolute(requested) || requested.split("/").some((part) => part === ".." || part === "." || part === "")) throw new ArtifactAccessError("Invalid artifact path.", 400);
|
|
73
|
+
return requested.split("/");
|
|
74
|
+
}
|
|
75
|
+
function accessError(error, action) {
|
|
76
|
+
if (error instanceof ArtifactAccessError) return error;
|
|
77
|
+
if (codeOf(error) === "ENOENT" || codeOf(error) === "ENOTDIR") return new ArtifactAccessError("The artifact no longer exists.", 404);
|
|
78
|
+
if (codeOf(error) === "EACCES" || codeOf(error) === "EPERM" || codeOf(error) === "ELOOP") return new ArtifactAccessError(`The artifact cannot be ${action}.`, 403);
|
|
79
|
+
return error;
|
|
80
|
+
}
|
|
81
|
+
/** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */
|
|
82
|
+
async function openArtifact(root, requested, workflowVisible) {
|
|
83
|
+
const segments = artifactSegments(requested);
|
|
84
|
+
if (segments[0] === "workflow" && !workflowVisible?.(segments.slice(1).join("/"), "file")) throw new ArtifactAccessError("This workflow file is private.", 403);
|
|
103
85
|
try {
|
|
104
86
|
const realRoot = await checkedRoot(root);
|
|
105
87
|
const candidate = path.resolve(realRoot, requested);
|
|
106
88
|
if (!inside(realRoot, candidate)) throw new ArtifactAccessError("The artifact is outside this session folder.", 403);
|
|
107
89
|
let current = realRoot;
|
|
108
|
-
const segments = requested.split("/");
|
|
109
90
|
for (let index = 0; index < segments.length; index += 1) {
|
|
110
91
|
current = path.join(current, segments[index]);
|
|
111
92
|
const stat = await fs.lstat(current);
|
|
@@ -130,10 +111,7 @@ async function openArtifact(root, requested) {
|
|
|
130
111
|
throw error;
|
|
131
112
|
}
|
|
132
113
|
} catch (error) {
|
|
133
|
-
|
|
134
|
-
if (codeOf(error) === "ENOENT" || codeOf(error) === "ENOTDIR") throw new ArtifactAccessError("The artifact no longer exists.", 404);
|
|
135
|
-
if (codeOf(error) === "EACCES" || codeOf(error) === "EPERM" || codeOf(error) === "ELOOP") throw new ArtifactAccessError("The artifact cannot be read.", 403);
|
|
136
|
-
throw error;
|
|
114
|
+
throw accessError(error, "read");
|
|
137
115
|
}
|
|
138
116
|
}
|
|
139
117
|
/** Bound allocation and read length even when the file grows after its metadata was read. */
|
|
@@ -147,36 +125,120 @@ async function readArtifactBytes(handle, size, offset = 0) {
|
|
|
147
125
|
}
|
|
148
126
|
return bytes.subarray(0, read);
|
|
149
127
|
}
|
|
150
|
-
|
|
128
|
+
/** Walk to the parent folder without following symlinks, creating missing folders on request. */
|
|
129
|
+
async function containedParent(realRoot, segments, create) {
|
|
130
|
+
let directory = realRoot;
|
|
131
|
+
for (const segment of segments.slice(0, -1)) {
|
|
132
|
+
directory = path.join(directory, segment);
|
|
133
|
+
if (create) await fs.mkdir(directory, { mode: 448 }).catch((error) => {
|
|
134
|
+
if (codeOf(error) !== "EEXIST") throw error;
|
|
135
|
+
});
|
|
136
|
+
const stat = await fs.lstat(directory);
|
|
137
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) throw new ArtifactAccessError("The artifact folder is not a directory.", 403);
|
|
138
|
+
}
|
|
139
|
+
return directory;
|
|
140
|
+
}
|
|
141
|
+
async function sameText(root, requested, bytes) {
|
|
142
|
+
try {
|
|
143
|
+
const file = await openArtifact(root, requested);
|
|
144
|
+
try {
|
|
145
|
+
if (file.stat.size !== bytes.length) return false;
|
|
146
|
+
return bytes.equals(await readArtifactBytes(file.handle, file.stat.size));
|
|
147
|
+
} finally {
|
|
148
|
+
await file.handle.close();
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error instanceof ArtifactAccessError) return false;
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Publish text through a same-folder temp file and rename, skipping identical content so mtimes stay stable.
|
|
157
|
+
* ponytail: best-effort same-user guards, not race-resistant. Linux checks ancestors with lstat only;
|
|
158
|
+
* walk with openat-style /proc/self/fd handles like openContained if artifacts cross a trust boundary.
|
|
159
|
+
*/
|
|
160
|
+
async function writeArtifactText(root, requested, text) {
|
|
161
|
+
const segments = artifactSegments(requested);
|
|
162
|
+
if (process.platform !== "darwin" && process.platform !== "linux") throw new ArtifactAccessError("Secure artifact writes require macOS or Linux.", 403);
|
|
163
|
+
const bytes = Buffer.from(text, "utf8");
|
|
164
|
+
try {
|
|
165
|
+
await ensureArtifactRoot(root);
|
|
166
|
+
const directory = await containedParent(await checkedRoot(root), segments, true);
|
|
167
|
+
if (await sameText(root, requested, bytes)) return;
|
|
168
|
+
const temp = path.join(directory, `.${segments.at(-1)}.${randomUUID()}.tmp`);
|
|
169
|
+
const flags = constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (process.platform === "darwin" ? 536870912 : 0);
|
|
170
|
+
const handle = await fs.open(temp, flags, 384);
|
|
171
|
+
try {
|
|
172
|
+
await handle.writeFile(bytes);
|
|
173
|
+
await handle.close();
|
|
174
|
+
await fs.rename(temp, path.join(directory, segments.at(-1)));
|
|
175
|
+
} catch (error) {
|
|
176
|
+
await handle.close().catch(() => void 0);
|
|
177
|
+
await fs.unlink(temp).catch(() => void 0);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
} catch (error) {
|
|
181
|
+
throw accessError(error, "written");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** Remove one file or one empty folder. A missing target is already removed; nothing is deleted recursively. */
|
|
185
|
+
async function removeArtifact(root, requested) {
|
|
186
|
+
const segments = artifactSegments(requested);
|
|
187
|
+
try {
|
|
188
|
+
const target = path.join(await containedParent(await checkedRoot(root), segments, false), segments.at(-1));
|
|
189
|
+
const stat = await fs.lstat(target);
|
|
190
|
+
if (stat.isFile()) await fs.unlink(target);
|
|
191
|
+
else if (!stat.isDirectory()) throw new ArtifactAccessError("The artifact is not a file or folder.", 403);
|
|
192
|
+
else await fs.rmdir(target).catch((error) => {
|
|
193
|
+
if (codeOf(error) !== "ENOTEMPTY" && codeOf(error) !== "EEXIST") throw error;
|
|
194
|
+
});
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (codeOf(error) === "ENOENT") return;
|
|
197
|
+
throw accessError(error, "removed");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Discover persisted session roots without admitting symlinked or malformed owners. */
|
|
201
|
+
async function listArtifactSessions(environment) {
|
|
202
|
+
const parent = path.dirname(artifactRoot("discovery", environment));
|
|
203
|
+
try {
|
|
204
|
+
const stat = await fs.lstat(parent);
|
|
205
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new ArtifactAccessError("The artifact storage directory is unavailable.", 403);
|
|
206
|
+
return (await fs.readdir(parent, { withFileTypes: true })).filter((entry) => entry.isDirectory() && /^[a-zA-Z0-9_-]+$/u.test(entry.name)).map((entry) => entry.name);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (codeOf(error) === "ENOENT") return [];
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function listArtifacts(root, workflowVisible) {
|
|
151
213
|
const items = [];
|
|
152
214
|
try {
|
|
153
215
|
const realRoot = await checkedRoot(root);
|
|
154
216
|
const visit = async (directory) => {
|
|
155
217
|
for (const entry of await fs.readdir(directory, { withFileTypes: true })) {
|
|
156
218
|
const location = path.join(directory, entry.name);
|
|
219
|
+
const relativePath = path.relative(realRoot, location).split(path.sep).join("/");
|
|
220
|
+
const segments = relativePath.split("/");
|
|
221
|
+
if (segments[0] === "workflow" && !workflowVisible?.(segments.slice(1).join("/"), entry.isDirectory() ? "directory" : "file")) continue;
|
|
157
222
|
if (entry.isDirectory()) {
|
|
158
223
|
const stat = await fs.lstat(location);
|
|
159
224
|
if (!stat.isDirectory() || stat.isSymbolicLink()) continue;
|
|
160
225
|
const real = await fs.realpath(location);
|
|
161
226
|
if (inside(realRoot, real)) await visit(real);
|
|
162
|
-
} else if (entry.isFile()) {
|
|
163
|
-
const
|
|
227
|
+
} else if (entry.isFile()) try {
|
|
228
|
+
const file = await openArtifact(root, relativePath, workflowVisible);
|
|
164
229
|
try {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
} finally {
|
|
174
|
-
await file.handle.close();
|
|
175
|
-
}
|
|
176
|
-
} catch (error) {
|
|
177
|
-
if (error instanceof ArtifactAccessError && (error.status === 404 || error.status === 403)) continue;
|
|
178
|
-
throw error;
|
|
230
|
+
items.push({
|
|
231
|
+
path: relativePath,
|
|
232
|
+
name: entry.name,
|
|
233
|
+
size: file.stat.size,
|
|
234
|
+
modifiedAt: file.stat.mtimeMs
|
|
235
|
+
});
|
|
236
|
+
} finally {
|
|
237
|
+
await file.handle.close();
|
|
179
238
|
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (error instanceof ArtifactAccessError && (error.status === 404 || error.status === 403)) continue;
|
|
241
|
+
throw error;
|
|
180
242
|
}
|
|
181
243
|
}
|
|
182
244
|
};
|
|
@@ -192,6 +254,6 @@ async function listArtifacts(root) {
|
|
|
192
254
|
}
|
|
193
255
|
}
|
|
194
256
|
//#endregion
|
|
195
|
-
export {
|
|
257
|
+
export { readArtifactBytes as a, ArtifactAccessError as c, openArtifact as i, artifactRoot as l, listArtifactSessions as n, removeArtifact as o, listArtifacts as r, writeArtifactText as s, ensureArtifactRoot as t };
|
|
196
258
|
|
|
197
|
-
//# sourceMappingURL=artifactFiles-
|
|
259
|
+
//# sourceMappingURL=artifactFiles-DyIkevXc.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifactFiles-DyIkevXc.mjs","names":[],"sources":["../src/services/artifactFiles/artifactPaths.ts","../src/services/artifactFiles/index.ts"],"sourcesContent":["import path from 'node:path';\n\nimport { piAgentDirectory } from '@agimon-ai/po-core/piSettings';\n\nimport { ARTIFACT_CONTENT_TYPES, ARTIFACT_DIRECTORY } from '../../constants/artifacts';\n\nexport class ArtifactAccessError extends Error {\n constructor(\n message: string,\n readonly status: 400 | 403 | 404 | 413,\n ) {\n super(message);\n }\n}\n\nexport function artifactRoot(sessionId: string, environment: Readonly<Record<string, string | undefined>>): string {\n if (!/^[a-zA-Z0-9_-]+$/u.test(sessionId)) throw new ArtifactAccessError('Invalid artifact session identity.', 400);\n return path.join(piAgentDirectory(environment, environment.HOME), ARTIFACT_DIRECTORY, sessionId);\n}\n\nexport function artifactMimeType(relativePath: string): string {\n return ARTIFACT_CONTENT_TYPES[path.extname(relativePath).toLowerCase()] ?? 'application/octet-stream';\n}\n","import { randomUUID } from 'node:crypto';\nimport { constants } from 'node:fs';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { WORKFLOW_ARTIFACT_DIRECTORY } from '../../constants/artifacts';\nimport type { ArtifactItem, ArtifactSnapshot, ArtifactWorkflowVisibility } from '../../types/artifacts';\nimport { ArtifactAccessError, artifactMimeType, artifactRoot } from './artifactPaths';\n\nexport { ArtifactAccessError, artifactMimeType, artifactRoot } from './artifactPaths';\n\nfunction inside(root: string, candidate: string): boolean {\n const relative = path.relative(root, candidate);\n return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);\n}\n\nfunction codeOf(error: unknown): string | undefined {\n return error instanceof Error && 'code' in error ? String(error.code) : undefined;\n}\n\n/** The owned directories must not redirect artifact access through a symlink. */\nasync function checkedRoot(root: string): Promise<string> {\n const base = path.dirname(root);\n for (const directory of [base, root]) {\n const stat = await fs.lstat(directory);\n if (!stat.isDirectory() || stat.isSymbolicLink())\n throw new ArtifactAccessError('The artifact folder is unavailable.', 403);\n }\n const realBase = await fs.realpath(base);\n const realRoot = await fs.realpath(root);\n if (!inside(realBase, realRoot))\n throw new ArtifactAccessError('The artifact folder is outside its storage directory.', 403);\n return realRoot;\n}\n\nexport async function ensureArtifactRoot(root: string): Promise<void> {\n await fs.mkdir(path.dirname(root), { recursive: true, mode: 0o700 });\n await fs.mkdir(root, { recursive: true, mode: 0o700 });\n await checkedRoot(root);\n}\n\n/** Open without following mutable ancestors. Node exposes no portable openat API. */\nasync function openContained(root: string, segments: string[]): Promise<fs.FileHandle> {\n if (process.platform === 'darwin') {\n // Darwin O_NOFOLLOW_ANY checks every component atomically. Do not combine it with O_NOFOLLOW.\n return fs.open(path.join(root, ...segments), constants.O_RDONLY | constants.O_NONBLOCK | 0x20000000);\n }\n if (process.platform !== 'linux') throw new ArtifactAccessError('Secure artifact reads require macOS or Linux.', 403);\n const flags = constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW;\n let directory = await fs.open(path.dirname(root), flags);\n try {\n for (const segment of [path.basename(root), ...segments.slice(0, -1)]) {\n const child = await fs.open(`/proc/self/fd/${directory.fd}/${segment}`, flags);\n await directory.close();\n directory = child;\n }\n return await fs.open(\n `/proc/self/fd/${directory.fd}/${segments.at(-1)!}`,\n constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK,\n );\n } finally {\n await directory.close();\n }\n}\n\nfunction artifactSegments(requested: string | undefined): string[] {\n if (\n !requested ||\n requested.includes('\\0') ||\n requested.includes('\\\\') ||\n path.isAbsolute(requested) ||\n requested.split('/').some((part) => part === '..' || part === '.' || part === '')\n )\n throw new ArtifactAccessError('Invalid artifact path.', 400);\n return requested.split('/');\n}\n\nfunction accessError(error: unknown, action: string): unknown {\n if (error instanceof ArtifactAccessError) return error;\n if (codeOf(error) === 'ENOENT' || codeOf(error) === 'ENOTDIR')\n return new ArtifactAccessError('The artifact no longer exists.', 404);\n if (codeOf(error) === 'EACCES' || codeOf(error) === 'EPERM' || codeOf(error) === 'ELOOP')\n return new ArtifactAccessError(`The artifact cannot be ${action}.`, 403);\n return error;\n}\n\n/** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */\nexport async function openArtifact(\n root: string,\n requested: string | undefined,\n workflowVisible?: ArtifactWorkflowVisibility,\n) {\n const segments = artifactSegments(requested);\n if (segments[0] === WORKFLOW_ARTIFACT_DIRECTORY && !workflowVisible?.(segments.slice(1).join('/'), 'file'))\n throw new ArtifactAccessError('This workflow file is private.', 403);\n try {\n const realRoot = await checkedRoot(root);\n const candidate = path.resolve(realRoot, requested!);\n if (!inside(realRoot, candidate))\n throw new ArtifactAccessError('The artifact is outside this session folder.', 403);\n let current = realRoot;\n for (let index = 0; index < segments.length; index += 1) {\n current = path.join(current, segments[index]!);\n const stat = await fs.lstat(current);\n if (stat.isSymbolicLink()) throw new ArtifactAccessError('Artifact symlinks cannot be read.', 403);\n if (index < segments.length - 1 ? !stat.isDirectory() : !stat.isFile())\n throw new ArtifactAccessError('The artifact is not a regular file.', 404);\n }\n const real = await fs.realpath(candidate);\n if (!inside(realRoot, real)) throw new ArtifactAccessError('The artifact is outside this session folder.', 403);\n const expected = await fs.lstat(real);\n const handle = await openContained(realRoot, segments);\n try {\n const stat = await handle.stat();\n if (!stat.isFile() || stat.dev !== expected.dev || stat.ino !== expected.ino)\n throw new ArtifactAccessError('The artifact changed while it was opened. Try again.', 403);\n return { handle, stat, path: requested!, mimeType: artifactMimeType(requested!) };\n } catch (error) {\n await handle.close();\n throw error;\n }\n } catch (error) {\n throw accessError(error, 'read');\n }\n}\n\n/** Bound allocation and read length even when the file grows after its metadata was read. */\nexport async function readArtifactBytes(handle: fs.FileHandle, size: number, offset = 0): Promise<Uint8Array> {\n const bytes = new Uint8Array(size);\n let read = 0;\n while (read < size) {\n const result = await handle.read(bytes, read, size - read, offset + read);\n if (result.bytesRead === 0) break;\n read += result.bytesRead;\n }\n return bytes.subarray(0, read);\n}\n\n/** Walk to the parent folder without following symlinks, creating missing folders on request. */\nasync function containedParent(realRoot: string, segments: string[], create: boolean): Promise<string> {\n let directory = realRoot;\n for (const segment of segments.slice(0, -1)) {\n directory = path.join(directory, segment);\n if (create)\n await fs.mkdir(directory, { mode: 0o700 }).catch((error: unknown) => {\n if (codeOf(error) !== 'EEXIST') throw error;\n });\n const stat = await fs.lstat(directory);\n if (stat.isSymbolicLink() || !stat.isDirectory())\n throw new ArtifactAccessError('The artifact folder is not a directory.', 403);\n }\n return directory;\n}\n\nasync function sameText(root: string, requested: string, bytes: Buffer): Promise<boolean> {\n try {\n const file = await openArtifact(root, requested);\n try {\n if (file.stat.size !== bytes.length) return false;\n return bytes.equals(await readArtifactBytes(file.handle, file.stat.size));\n } finally {\n await file.handle.close();\n }\n } catch (error) {\n if (error instanceof ArtifactAccessError) return false;\n throw error;\n }\n}\n\n/**\n * Publish text through a same-folder temp file and rename, skipping identical content so mtimes stay stable.\n * ponytail: best-effort same-user guards, not race-resistant. Linux checks ancestors with lstat only;\n * walk with openat-style /proc/self/fd handles like openContained if artifacts cross a trust boundary.\n */\nexport async function writeArtifactText(root: string, requested: string, text: string): Promise<void> {\n const segments = artifactSegments(requested);\n if (process.platform !== 'darwin' && process.platform !== 'linux')\n throw new ArtifactAccessError('Secure artifact writes require macOS or Linux.', 403);\n const bytes = Buffer.from(text, 'utf8');\n try {\n await ensureArtifactRoot(root);\n const directory = await containedParent(await checkedRoot(root), segments, true);\n if (await sameText(root, requested, bytes)) return;\n const temp = path.join(directory, `.${segments.at(-1)!}.${randomUUID()}.tmp`);\n // Darwin O_NOFOLLOW_ANY refuses a symlink in any component; O_EXCL refuses one at the leaf.\n const flags =\n constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (process.platform === 'darwin' ? 0x20000000 : 0);\n const handle = await fs.open(temp, flags, 0o600);\n try {\n await handle.writeFile(bytes);\n await handle.close();\n await fs.rename(temp, path.join(directory, segments.at(-1)!));\n } catch (error) {\n await handle.close().catch(() => undefined);\n await fs.unlink(temp).catch(() => undefined);\n throw error;\n }\n } catch (error) {\n throw accessError(error, 'written');\n }\n}\n\n/** Remove one file or one empty folder. A missing target is already removed; nothing is deleted recursively. */\nexport async function removeArtifact(root: string, requested: string): Promise<void> {\n const segments = artifactSegments(requested);\n try {\n const target = path.join(await containedParent(await checkedRoot(root), segments, false), segments.at(-1)!);\n const stat = await fs.lstat(target);\n if (stat.isFile()) await fs.unlink(target);\n else if (!stat.isDirectory()) throw new ArtifactAccessError('The artifact is not a file or folder.', 403);\n else\n await fs.rmdir(target).catch((error: unknown) => {\n if (codeOf(error) !== 'ENOTEMPTY' && codeOf(error) !== 'EEXIST') throw error;\n });\n } catch (error) {\n if (codeOf(error) === 'ENOENT') return;\n throw accessError(error, 'removed');\n }\n}\n/** Discover persisted session roots without admitting symlinked or malformed owners. */\nexport async function listArtifactSessions(\n environment: Readonly<Record<string, string | undefined>>,\n): Promise<readonly string[]> {\n const parent = path.dirname(artifactRoot('discovery', environment));\n try {\n const stat = await fs.lstat(parent);\n if (!stat.isDirectory() || stat.isSymbolicLink())\n throw new ArtifactAccessError('The artifact storage directory is unavailable.', 403);\n const entries = await fs.readdir(parent, { withFileTypes: true });\n return entries\n .filter((entry) => entry.isDirectory() && /^[a-zA-Z0-9_-]+$/u.test(entry.name))\n .map((entry) => entry.name);\n } catch (error) {\n if (codeOf(error) === 'ENOENT') return [];\n throw error;\n }\n}\n\nexport async function listArtifacts(\n root: string,\n workflowVisible?: ArtifactWorkflowVisibility,\n): Promise<ArtifactSnapshot> {\n const items: ArtifactItem[] = [];\n try {\n const realRoot = await checkedRoot(root);\n const visit = async (directory: string): Promise<void> => {\n for (const entry of await fs.readdir(directory, { withFileTypes: true })) {\n const location = path.join(directory, entry.name);\n const relativePath = path.relative(realRoot, location).split(path.sep).join('/');\n const segments = relativePath.split('/');\n if (\n segments[0] === WORKFLOW_ARTIFACT_DIRECTORY &&\n !workflowVisible?.(segments.slice(1).join('/'), entry.isDirectory() ? 'directory' : 'file')\n )\n continue;\n if (entry.isDirectory()) {\n // Recheck each directory rather than trusting a readdir entry across a rename.\n const stat = await fs.lstat(location);\n if (!stat.isDirectory() || stat.isSymbolicLink()) continue;\n const real = await fs.realpath(location);\n if (inside(realRoot, real)) await visit(real);\n } else if (entry.isFile()) {\n try {\n const file = await openArtifact(root, relativePath, workflowVisible);\n try {\n items.push({ path: relativePath, name: entry.name, size: file.stat.size, modifiedAt: file.stat.mtimeMs });\n } finally {\n await file.handle.close();\n }\n } catch (error) {\n if (error instanceof ArtifactAccessError && (error.status === 404 || error.status === 403)) continue;\n throw error;\n }\n }\n }\n };\n await visit(realRoot);\n items.sort(\n (left, right) =>\n right.modifiedAt - left.modifiedAt || (left.path < right.path ? -1 : left.path > right.path ? 1 : 0),\n );\n return { items };\n } catch (error) {\n if (codeOf(error) === 'ENOENT') return { items: [] };\n return { items: [], error: error instanceof Error ? error.message : 'The artifact folder could not be read.' };\n }\n}\n"],"mappings":";;;;;;;AAMA,IAAa,sBAAb,cAAyC,MAAM;CAGlC;CAFX,YACE,SACA,QACA;EACA,MAAM,OAAO;EAFJ,KAAA,SAAA;CAGX;AACF;AAEA,SAAgB,aAAa,WAAmB,aAAmE;CACjH,IAAI,CAAC,oBAAoB,KAAK,SAAS,GAAG,MAAM,IAAI,oBAAoB,sCAAsC,GAAG;CACjH,OAAO,KAAK,KAAK,iBAAiB,aAAa,YAAY,IAAI,GAAG,oBAAoB,SAAS;AACjG;AAEA,SAAgB,iBAAiB,cAA8B;CAC7D,OAAO,uBAAuB,KAAK,QAAQ,YAAY,CAAC,CAAC,YAAY,MAAM;AAC7E;;;ACXA,SAAS,OAAO,MAAc,WAA4B;CACxD,MAAM,WAAW,KAAK,SAAS,MAAM,SAAS;CAC9C,OAAO,aAAa,QAAQ,CAAC,SAAS,WAAW,KAAK,KAAK,KAAK,KAAK,CAAC,KAAK,WAAW,QAAQ;AAChG;AAEA,SAAS,OAAO,OAAoC;CAClD,OAAO,iBAAiB,SAAS,UAAU,QAAQ,OAAO,MAAM,IAAI,IAAI,KAAA;AAC1E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B;IACF,SAAS,OAAO;KACd,IAAI,iBAAiB,wBAAwB,MAAM,WAAW,OAAO,MAAM,WAAW,MAAM;KAC5F,MAAM;IACR;GAEJ;EACF;EACA,MAAM,MAAM,QAAQ;EACpB,MAAM,MACH,MAAM,UACL,MAAM,aAAa,KAAK,eAAe,KAAK,OAAO,MAAM,OAAO,KAAK,KAAK,OAAO,MAAM,OAAO,IAAI,EACtG;EACA,OAAO,EAAE,MAAM;CACjB,SAAS,OAAO;EACd,IAAI,OAAO,KAAK,MAAM,UAAU,OAAO,EAAE,OAAO,CAAC,EAAE;EACnD,OAAO;GAAE,OAAO,CAAC;GAAG,OAAO,iBAAiB,QAAQ,MAAM,UAAU;EAAyC;CAC/G;AACF"}
|
package/dist/artifactFiles.cjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_artifactFiles = require("./artifactFiles-
|
|
2
|
+
const require_artifactFiles = require("./artifactFiles-BmBU9Olm.cjs");
|
|
3
|
+
const require_artifacts = require("./artifacts-DG_b7DZH.cjs");
|
|
3
4
|
exports.ArtifactAccessError = require_artifactFiles.ArtifactAccessError;
|
|
5
|
+
exports.COMPACTION_ARTIFACT_DIRECTORY = require_artifacts.COMPACTION_ARTIFACT_DIRECTORY;
|
|
4
6
|
exports.artifactRoot = require_artifactFiles.artifactRoot;
|
|
7
|
+
exports.listArtifactSessions = require_artifactFiles.listArtifactSessions;
|
|
8
|
+
exports.listArtifacts = require_artifactFiles.listArtifacts;
|
|
5
9
|
exports.openArtifact = require_artifactFiles.openArtifact;
|
|
6
10
|
exports.readArtifactBytes = require_artifactFiles.readArtifactBytes;
|
|
11
|
+
exports.removeArtifact = require_artifactFiles.removeArtifact;
|
|
12
|
+
exports.writeArtifactText = require_artifactFiles.writeArtifactText;
|
package/dist/artifactFiles.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { a as ArtifactWorkflowVisibility, i as ArtifactSnapshot, s as COMPACTION_ARTIFACT_DIRECTORY } from "./artifacts-sIj4Xaeu.mjs";
|
|
1
2
|
import fs from "node:fs/promises";
|
|
2
3
|
//#region src/services/artifactFiles/artifactPaths.d.ts
|
|
3
4
|
export declare class ArtifactAccessError extends Error {
|
|
@@ -8,7 +9,7 @@ export declare function artifactRoot(sessionId: string, environment: Readonly<Re
|
|
|
8
9
|
//#endregion
|
|
9
10
|
//#region src/services/artifactFiles/index.d.ts
|
|
10
11
|
/** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */
|
|
11
|
-
export declare function openArtifact(root: string, requested: string | undefined): Promise<{
|
|
12
|
+
export declare function openArtifact(root: string, requested: string | undefined, workflowVisible?: ArtifactWorkflowVisibility): Promise<{
|
|
12
13
|
handle: fs.FileHandle;
|
|
13
14
|
stat: import("node:fs").Stats;
|
|
14
15
|
path: string;
|
|
@@ -16,5 +17,17 @@ export declare function openArtifact(root: string, requested: string | undefined
|
|
|
16
17
|
}>;
|
|
17
18
|
/** Bound allocation and read length even when the file grows after its metadata was read. */
|
|
18
19
|
export declare function readArtifactBytes(handle: fs.FileHandle, size: number, offset?: number): Promise<Uint8Array>;
|
|
20
|
+
/**
|
|
21
|
+
* Publish text through a same-folder temp file and rename, skipping identical content so mtimes stay stable.
|
|
22
|
+
* ponytail: best-effort same-user guards, not race-resistant. Linux checks ancestors with lstat only;
|
|
23
|
+
* walk with openat-style /proc/self/fd handles like openContained if artifacts cross a trust boundary.
|
|
24
|
+
*/
|
|
25
|
+
export declare function writeArtifactText(root: string, requested: string, text: string): Promise<void>;
|
|
26
|
+
/** Remove one file or one empty folder. A missing target is already removed; nothing is deleted recursively. */
|
|
27
|
+
export declare function removeArtifact(root: string, requested: string): Promise<void>;
|
|
28
|
+
/** Discover persisted session roots without admitting symlinked or malformed owners. */
|
|
29
|
+
export declare function listArtifactSessions(environment: Readonly<Record<string, string | undefined>>): Promise<readonly string[]>;
|
|
30
|
+
export declare function listArtifacts(root: string, workflowVisible?: ArtifactWorkflowVisibility): Promise<ArtifactSnapshot>;
|
|
19
31
|
//#endregion
|
|
32
|
+
export { COMPACTION_ARTIFACT_DIRECTORY };
|
|
20
33
|
//# sourceMappingURL=artifactFiles.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifactFiles.d.mts","names":[],"sources":["../src/services/artifactFiles/artifactPaths.ts","../src/services/artifactFiles/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"artifactFiles.d.mts","names":[],"sources":["../src/services/artifactFiles/artifactPaths.ts","../src/services/artifactFiles/index.ts"],"mappings":";;;qBAMa,4BAA4B;WAG5B;EAFX,YACE,iBACS;;wBAMG,aAAa,mBAAmB,aAAa,SAAS;;;;wBCwEhD,aACpB,cACA,+BACA,kBAAkB,6BAA0B;;;;;;;wBAqCxB,kBAAkB,QAAQ,GAAG,YAAY,cAAc,kBAAa,QAAQ;;;;;;wBA+C5E,kBAAkB,cAAc,mBAAmB,eAAe;;wBA6BlE,eAAe,cAAc,oBAAoB;;wBAiBjD,qBACpB,aAAa,SAAS,sCACrB;wBAgBmB,cACpB,cACA,kBAAkB,6BACjB,QAAQ"}
|
package/dist/artifactFiles.mjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { a as COMPACTION_ARTIFACT_DIRECTORY } from "./artifacts-Bhobz1nK.mjs";
|
|
2
|
+
import { a as readArtifactBytes, c as ArtifactAccessError, i as openArtifact, l as artifactRoot, n as listArtifactSessions, o as removeArtifact, r as listArtifacts, s as writeArtifactText } from "./artifactFiles-DyIkevXc.mjs";
|
|
3
|
+
export { ArtifactAccessError, COMPACTION_ARTIFACT_DIRECTORY, artifactRoot, listArtifactSessions, listArtifacts, openArtifact, readArtifactBytes, removeArtifact, writeArtifactText };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/constants/artifacts.ts
|
|
2
|
+
const ARTIFACT_DIRECTORY = "po-artifacts";
|
|
3
|
+
const ARTIFACTS_SERVICE = "po/artifacts";
|
|
4
|
+
const WORKFLOW_ARTIFACT_DIRECTORY = "workflow";
|
|
5
|
+
/** Autocompact mirrors compaction history here; the recent-artifacts card leaves it out. */
|
|
6
|
+
const COMPACTION_ARTIFACT_DIRECTORY = "compaction";
|
|
7
|
+
const MAX_PREVIEW_BYTES = 1048576;
|
|
8
|
+
const MAX_CONTENT_BYTES = 26214400;
|
|
9
|
+
const ARTIFACT_REFRESH_MS = 2e3;
|
|
10
|
+
const ARTIFACT_CONTENT_TYPES = {
|
|
11
|
+
".avif": "image/avif",
|
|
12
|
+
".bmp": "image/bmp",
|
|
13
|
+
".gif": "image/gif",
|
|
14
|
+
".jpeg": "image/jpeg",
|
|
15
|
+
".jpg": "image/jpeg",
|
|
16
|
+
".png": "image/png",
|
|
17
|
+
".svg": "image/svg+xml",
|
|
18
|
+
".webp": "image/webp",
|
|
19
|
+
".ico": "image/vnd.microsoft.icon",
|
|
20
|
+
".mp3": "audio/mpeg",
|
|
21
|
+
".wav": "audio/wav",
|
|
22
|
+
".m4a": "audio/mp4",
|
|
23
|
+
".ogg": "audio/ogg",
|
|
24
|
+
".m4v": "video/mp4",
|
|
25
|
+
".mov": "video/quicktime",
|
|
26
|
+
".mp4": "video/mp4",
|
|
27
|
+
".webm": "video/webm",
|
|
28
|
+
".pdf": "application/pdf",
|
|
29
|
+
".md": "text/markdown; charset=utf-8",
|
|
30
|
+
".markdown": "text/markdown; charset=utf-8",
|
|
31
|
+
".txt": "text/plain; charset=utf-8",
|
|
32
|
+
".html": "text/html; charset=utf-8",
|
|
33
|
+
".htm": "text/html; charset=utf-8"
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { COMPACTION_ARTIFACT_DIRECTORY as a, WORKFLOW_ARTIFACT_DIRECTORY as c, ARTIFACT_REFRESH_MS as i, ARTIFACT_CONTENT_TYPES as n, MAX_CONTENT_BYTES as o, ARTIFACT_DIRECTORY as r, MAX_PREVIEW_BYTES as s, ARTIFACTS_SERVICE as t };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=artifacts-Bhobz1nK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts-Bhobz1nK.mjs","names":[],"sources":["../src/constants/artifacts.ts"],"sourcesContent":["export const ARTIFACT_DIRECTORY = 'po-artifacts';\nexport const ARTIFACTS_SERVICE = 'po/artifacts';\nexport const WORKFLOW_ARTIFACT_DIRECTORY = 'workflow';\n/** Autocompact mirrors compaction history here; the recent-artifacts card leaves it out. */\nexport const COMPACTION_ARTIFACT_DIRECTORY = 'compaction';\nexport const MAX_PREVIEW_BYTES = 1024 * 1024;\nexport const MAX_CONTENT_BYTES = 25 * 1024 * 1024;\nexport const ARTIFACT_REFRESH_MS = 2000;\n\nexport const ARTIFACT_CONTENT_TYPES: Readonly<Record<string, string>> = {\n '.avif': 'image/avif',\n '.bmp': 'image/bmp',\n '.gif': 'image/gif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n '.ico': 'image/vnd.microsoft.icon',\n '.mp3': 'audio/mpeg',\n '.wav': 'audio/wav',\n '.m4a': 'audio/mp4',\n '.ogg': 'audio/ogg',\n '.m4v': 'video/mp4',\n '.mov': 'video/quicktime',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.pdf': 'application/pdf',\n '.md': 'text/markdown; charset=utf-8',\n '.markdown': 'text/markdown; charset=utf-8',\n '.txt': 'text/plain; charset=utf-8',\n '.html': 'text/html; charset=utf-8',\n '.htm': 'text/html; charset=utf-8',\n};\n"],"mappings":";AAAA,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AACjC,MAAa,8BAA8B;;AAE3C,MAAa,gCAAgC;AAC7C,MAAa,oBAAoB;AACjC,MAAa,oBAAoB;AACjC,MAAa,sBAAsB;AAEnC,MAAa,yBAA2D;CACtE,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,OAAO;CACP,aAAa;CACb,QAAQ;CACR,SAAS;CACT,QAAQ;AACV"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
//#region src/constants/artifacts.ts
|
|
2
|
+
const ARTIFACT_DIRECTORY = "po-artifacts";
|
|
3
|
+
const ARTIFACTS_SERVICE = "po/artifacts";
|
|
4
|
+
const WORKFLOW_ARTIFACT_DIRECTORY = "workflow";
|
|
5
|
+
/** Autocompact mirrors compaction history here; the recent-artifacts card leaves it out. */
|
|
6
|
+
const COMPACTION_ARTIFACT_DIRECTORY = "compaction";
|
|
7
|
+
const MAX_PREVIEW_BYTES = 1048576;
|
|
8
|
+
const MAX_CONTENT_BYTES = 26214400;
|
|
9
|
+
const ARTIFACT_REFRESH_MS = 2e3;
|
|
10
|
+
const ARTIFACT_CONTENT_TYPES = {
|
|
11
|
+
".avif": "image/avif",
|
|
12
|
+
".bmp": "image/bmp",
|
|
13
|
+
".gif": "image/gif",
|
|
14
|
+
".jpeg": "image/jpeg",
|
|
15
|
+
".jpg": "image/jpeg",
|
|
16
|
+
".png": "image/png",
|
|
17
|
+
".svg": "image/svg+xml",
|
|
18
|
+
".webp": "image/webp",
|
|
19
|
+
".ico": "image/vnd.microsoft.icon",
|
|
20
|
+
".mp3": "audio/mpeg",
|
|
21
|
+
".wav": "audio/wav",
|
|
22
|
+
".m4a": "audio/mp4",
|
|
23
|
+
".ogg": "audio/ogg",
|
|
24
|
+
".m4v": "video/mp4",
|
|
25
|
+
".mov": "video/quicktime",
|
|
26
|
+
".mp4": "video/mp4",
|
|
27
|
+
".webm": "video/webm",
|
|
28
|
+
".pdf": "application/pdf",
|
|
29
|
+
".md": "text/markdown; charset=utf-8",
|
|
30
|
+
".markdown": "text/markdown; charset=utf-8",
|
|
31
|
+
".txt": "text/plain; charset=utf-8",
|
|
32
|
+
".html": "text/html; charset=utf-8",
|
|
33
|
+
".htm": "text/html; charset=utf-8"
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
Object.defineProperty(exports, "ARTIFACTS_SERVICE", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function() {
|
|
39
|
+
return ARTIFACTS_SERVICE;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "ARTIFACT_CONTENT_TYPES", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function() {
|
|
45
|
+
return ARTIFACT_CONTENT_TYPES;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "ARTIFACT_DIRECTORY", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function() {
|
|
51
|
+
return ARTIFACT_DIRECTORY;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "ARTIFACT_REFRESH_MS", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function() {
|
|
57
|
+
return ARTIFACT_REFRESH_MS;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "COMPACTION_ARTIFACT_DIRECTORY", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function() {
|
|
63
|
+
return COMPACTION_ARTIFACT_DIRECTORY;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "MAX_CONTENT_BYTES", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function() {
|
|
69
|
+
return MAX_CONTENT_BYTES;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "MAX_PREVIEW_BYTES", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function() {
|
|
75
|
+
return MAX_PREVIEW_BYTES;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "WORKFLOW_ARTIFACT_DIRECTORY", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function() {
|
|
81
|
+
return WORKFLOW_ARTIFACT_DIRECTORY;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=artifacts-DG_b7DZH.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts-DG_b7DZH.cjs","names":[],"sources":["../src/constants/artifacts.ts"],"sourcesContent":["export const ARTIFACT_DIRECTORY = 'po-artifacts';\nexport const ARTIFACTS_SERVICE = 'po/artifacts';\nexport const WORKFLOW_ARTIFACT_DIRECTORY = 'workflow';\n/** Autocompact mirrors compaction history here; the recent-artifacts card leaves it out. */\nexport const COMPACTION_ARTIFACT_DIRECTORY = 'compaction';\nexport const MAX_PREVIEW_BYTES = 1024 * 1024;\nexport const MAX_CONTENT_BYTES = 25 * 1024 * 1024;\nexport const ARTIFACT_REFRESH_MS = 2000;\n\nexport const ARTIFACT_CONTENT_TYPES: Readonly<Record<string, string>> = {\n '.avif': 'image/avif',\n '.bmp': 'image/bmp',\n '.gif': 'image/gif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n '.ico': 'image/vnd.microsoft.icon',\n '.mp3': 'audio/mpeg',\n '.wav': 'audio/wav',\n '.m4a': 'audio/mp4',\n '.ogg': 'audio/ogg',\n '.m4v': 'video/mp4',\n '.mov': 'video/quicktime',\n '.mp4': 'video/mp4',\n '.webm': 'video/webm',\n '.pdf': 'application/pdf',\n '.md': 'text/markdown; charset=utf-8',\n '.markdown': 'text/markdown; charset=utf-8',\n '.txt': 'text/plain; charset=utf-8',\n '.html': 'text/html; charset=utf-8',\n '.htm': 'text/html; charset=utf-8',\n};\n"],"mappings":";AAAA,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AACjC,MAAa,8BAA8B;;AAE3C,MAAa,gCAAgC;AAC7C,MAAa,oBAAoB;AACjC,MAAa,oBAAoB;AACjC,MAAa,sBAAsB;AAEnC,MAAa,yBAA2D;CACtE,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,OAAO;CACP,aAAa;CACb,QAAQ;CACR,SAAS;CACT,QAAQ;AACV"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/constants/artifacts.d.ts
|
|
2
|
+
declare const ARTIFACTS_SERVICE = "po/artifacts";
|
|
3
|
+
/** Autocompact mirrors compaction history here; the recent-artifacts card leaves it out. */
|
|
4
|
+
declare const COMPACTION_ARTIFACT_DIRECTORY = "compaction";
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/types/artifacts.d.ts
|
|
7
|
+
type ArtifactScope = 'artifacts' | 'temporary';
|
|
8
|
+
/** Workflow owns the visibility of its reserved artifact subtree. */
|
|
9
|
+
type ArtifactWorkflowVisibility = (relativePath: string, kind: 'file' | 'directory') => boolean;
|
|
10
|
+
interface ArtifactItem {
|
|
11
|
+
/** Relative to the current session's artifact directory. */
|
|
12
|
+
path: string;
|
|
13
|
+
name: string;
|
|
14
|
+
size: number;
|
|
15
|
+
modifiedAt: number;
|
|
16
|
+
}
|
|
17
|
+
interface ArtifactSnapshot {
|
|
18
|
+
items: ArtifactItem[];
|
|
19
|
+
/** Host-admitted root used only to recognize session temporary-file references. */
|
|
20
|
+
temporaryRoot?: string;
|
|
21
|
+
error?: string;
|
|
22
|
+
}
|
|
23
|
+
interface ArtifactPreview {
|
|
24
|
+
path: string;
|
|
25
|
+
content: string;
|
|
26
|
+
mimeType: string;
|
|
27
|
+
unavailable?: boolean;
|
|
28
|
+
reason?: string;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ArtifactWorkflowVisibility as a, ArtifactSnapshot as i, ArtifactPreview as n, ARTIFACTS_SERVICE as o, ArtifactScope as r, COMPACTION_ARTIFACT_DIRECTORY as s, ArtifactItem as t };
|
|
32
|
+
//# sourceMappingURL=artifacts-sIj4Xaeu.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts-sIj4Xaeu.d.mts","names":[],"sources":["../src/constants/artifacts.ts","../src/types/artifacts.ts"],"mappings":";cACa;;cAGA;;;KCJD;;KAGA,8BAA8B,sBAAsB;UAE/C;;EAEf;EACA;EACA;EACA;;UAGe;EACf,OAAO;;EAEP;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA"}
|