@openartifactsai/server-sdk 0.0.0-stage → 0.23.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/bin/frame-host.d.ts +2 -0
- package/bin/frame-host.js +47 -0
- package/package.json +124 -4
- package/src/child.d.ts +37 -0
- package/src/child.js +64 -0
- package/src/connectors/connectors.d.ts +101 -0
- package/src/connectors/connectors.js +256 -0
- package/src/connectors/daemon-connectors.d.ts +34 -0
- package/src/connectors/daemon-connectors.js +73 -0
- package/src/connectors/index.d.ts +7 -0
- package/src/connectors/index.js +7 -0
- package/src/connectors/mcp-client.d.ts +157 -0
- package/src/connectors/mcp-client.js +483 -0
- package/src/daemon.d.ts +119 -0
- package/src/daemon.js +301 -0
- package/src/frame/access.d.ts +69 -0
- package/src/frame/access.js +168 -0
- package/src/frame/client/comments.css +1 -0
- package/src/frame/client/comments.js +58 -0
- package/src/frame/client/imports.d.ts +6 -0
- package/src/frame/client/imports.js +112 -0
- package/src/frame/client/mcp-shell.js +345 -0
- package/src/frame/client/mcp.js +253 -0
- package/src/frame/client/runtime.js +1363 -0
- package/src/frame/client/sample.js +762 -0
- package/src/frame/client/shell.css +51 -0
- package/src/frame/client/shell.html +29 -0
- package/src/frame/client/shell.js +1417 -0
- package/src/frame/comments.d.ts +102 -0
- package/src/frame/comments.js +379 -0
- package/src/frame/core.d.ts +313 -0
- package/src/frame/core.js +1757 -0
- package/src/frame/db.d.ts +162 -0
- package/src/frame/db.js +604 -0
- package/src/frame/declaration.d.ts +30 -0
- package/src/frame/declaration.js +60 -0
- package/src/frame/env.d.ts +262 -0
- package/src/frame/env.js +13 -0
- package/src/frame/files.d.ts +130 -0
- package/src/frame/files.js +472 -0
- package/src/frame/index.d.ts +35 -0
- package/src/frame/index.js +33 -0
- package/src/frame/local.d.ts +126 -0
- package/src/frame/local.js +612 -0
- package/src/frame/mcp-relay.d.ts +79 -0
- package/src/frame/mcp-relay.js +191 -0
- package/src/frame/page-api.d.ts +48 -0
- package/src/frame/page-api.js +1 -0
- package/src/frame/page-comments.d.ts +109 -0
- package/src/frame/page-comments.js +1 -0
- package/src/frame/page-db.d.ts +88 -0
- package/src/frame/page-db.js +1 -0
- package/src/frame/page-imports.d.ts +2 -0
- package/src/frame/page-imports.js +2 -0
- package/src/frame/page-services.d.ts +124 -0
- package/src/frame/page-services.js +1 -0
- package/src/frame/page-values.d.ts +90 -0
- package/src/frame/page-values.js +1 -0
- package/src/frame/sample-relay.d.ts +42 -0
- package/src/frame/sample-relay.js +186 -0
- package/src/frame/snapshot-action.d.ts +18 -0
- package/src/frame/snapshot-action.js +82 -0
- package/src/frame/wire.d.ts +198 -0
- package/src/frame/wire.js +21 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +17 -0
- package/src/lan.d.ts +75 -0
- package/src/lan.js +200 -0
- package/src/legacy-env.d.ts +7 -0
- package/src/legacy-env.js +14 -0
- package/src/serve.d.ts +375 -0
- package/src/serve.js +811 -0
- package/src/snapshot.d.ts +41 -0
- package/src/snapshot.js +224 -0
- package/src/type-package.d.ts +48 -0
- package/src/type-package.js +114 -0
- package/src/ws.d.ts +50 -0
- package/src/ws.js +203 -0
- package/src/zip.d.ts +197 -0
- package/src/zip.js +662 -0
package/src/zip.d.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zip files, the plain kind (no Zip64), with Node built-ins only: reading one (the central directory, an entry's
|
|
3
|
+
* bytes), writing one (an artifact folder's archive, a type package), and unpacking one that may come from anyone
|
|
4
|
+
* into a folder, with every rule checked before a byte is written. Shared by the type server (`archive`, imports),
|
|
5
|
+
* frame-host (`/__open-artifacts/archive`) and the daemon (`types pack`, `types install`, `import`, the archives of
|
|
6
|
+
* static types), so one archive shape and one set of path rules hold everywhere.
|
|
7
|
+
*
|
|
8
|
+
* The archive of an artifact folder holds one folder, named as the artifact folder is, with what makes the artifact:
|
|
9
|
+
* `project/` (or `db/`), `_blobs/`, `comments.json`, `history/` and `.artifact.json`. Left out is what belongs to this
|
|
10
|
+
* computer or to nobody: the agent channel (`_agent/`: inbox, waiting, view context), dot files (a server's state and
|
|
11
|
+
* log, share links, temp files of atomic writes), `node_modules`, `.git` and the OS's `.DS_Store` / `Thumbs.db`.
|
|
12
|
+
* Symbolic links are not followed. At most 65 535 files and 4 GiB, checked before the first byte goes out. Names are
|
|
13
|
+
* UTF-8 (flag bit 11), Unix permissions ride in the external attributes, and each file is deflated unless it is a
|
|
14
|
+
* format that is compressed already or deflate would not shrink it.
|
|
15
|
+
*/
|
|
16
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
17
|
+
/** A file that is not a zip (`not_zip`), or a zip whose parts do not hold together (`damaged`). */
|
|
18
|
+
export declare class ZipError extends Error {
|
|
19
|
+
readonly code: 'not_zip' | 'damaged';
|
|
20
|
+
constructor(code: 'not_zip' | 'damaged', message: string);
|
|
21
|
+
}
|
|
22
|
+
/** One entry of the central directory, as the zip states it (sizes and attributes may lie). */
|
|
23
|
+
export interface ZipEntry {
|
|
24
|
+
/** The name, decoded as UTF-8. */
|
|
25
|
+
name: string;
|
|
26
|
+
/** "Version made by": the high byte is the host system (3 = Unix, 0 = MS-DOS). */
|
|
27
|
+
madeBy: number;
|
|
28
|
+
/** General purpose flags (bit 0: encrypted, bit 6: strong encryption, bit 11: UTF-8 names). */
|
|
29
|
+
flags: number;
|
|
30
|
+
/** 0 stored, 8 deflated. */
|
|
31
|
+
method: number;
|
|
32
|
+
crc: number;
|
|
33
|
+
/** Bytes in the zip. */
|
|
34
|
+
packedSize: number;
|
|
35
|
+
/** Bytes once unpacked, as declared. */
|
|
36
|
+
size: number;
|
|
37
|
+
/** External attributes; on a Unix host the high 16 bits are the file's `st_mode`. */
|
|
38
|
+
externalAttributes: number;
|
|
39
|
+
/** Offset of the entry's local header. */
|
|
40
|
+
localOffset: number;
|
|
41
|
+
}
|
|
42
|
+
/** The end of central directory record: where the directory starts and how many entries it claims. */
|
|
43
|
+
export interface ZipDirectory {
|
|
44
|
+
entries: ZipEntry[];
|
|
45
|
+
/** Entries the end record claims (may be more than were readable). */
|
|
46
|
+
declared: number;
|
|
47
|
+
/** Offset of the central directory, which is where the entries' data must end. */
|
|
48
|
+
directoryOffset: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The central directory. Reading stops at the first record that is not one (the end record's count is in
|
|
52
|
+
* `declared`, so a strict caller can see a short directory). Throws `not_zip` when there is no end record.
|
|
53
|
+
*/
|
|
54
|
+
export declare function zipEntries(bytes: Uint8Array): ZipDirectory;
|
|
55
|
+
/** Where an entry's packed data sits, read from its local header: the data and the name the local header gives. Throws `damaged` when the local header is missing. */
|
|
56
|
+
export declare function entryBytes(bytes: Uint8Array, entry: ZipEntry): {
|
|
57
|
+
data: Buffer;
|
|
58
|
+
start: number;
|
|
59
|
+
localName: string;
|
|
60
|
+
localMethod: number;
|
|
61
|
+
localFlags: number;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* An entry's bytes, unpacked: stored data is copied, anything else is inflated, never past `maxBytes`
|
|
65
|
+
* (throws a `RangeError` when stored or inflated data would grow past it).
|
|
66
|
+
*/
|
|
67
|
+
export declare function unpackEntry(bytes: Uint8Array, entry: ZipEntry, maxBytes: number): Promise<Buffer>;
|
|
68
|
+
/** {@link unpackEntry}, synchronously. */
|
|
69
|
+
export declare function unpackEntrySync(bytes: Uint8Array, entry: ZipEntry, maxBytes: number): Buffer;
|
|
70
|
+
/**
|
|
71
|
+
* Every name of the zip with a reader of its bytes, unpacked on demand and never past `maxEntryBytes`. A name given
|
|
72
|
+
* twice keeps its last entry. Throws `not_zip`; a reader throws `damaged` when its entry's data is missing.
|
|
73
|
+
*/
|
|
74
|
+
export declare function readZip(bytes: Uint8Array, maxEntryBytes: number): Map<string, () => Buffer>;
|
|
75
|
+
/**
|
|
76
|
+
* Whether a path under the artifact folder (forward slashes, no leading slash) is one {@link archiveEntries} would
|
|
77
|
+
* put in the zip, by name alone. The export and the import share it, so what one leaves out the other refuses.
|
|
78
|
+
*/
|
|
79
|
+
export declare function archiveKeeps(path: string): boolean;
|
|
80
|
+
/** One file of the zip. */
|
|
81
|
+
export interface ArchiveEntry {
|
|
82
|
+
/** The path inside the zip: `<folder>/<path under root>`, with forward slashes. */
|
|
83
|
+
name: string;
|
|
84
|
+
file: string;
|
|
85
|
+
size: number;
|
|
86
|
+
mode: number;
|
|
87
|
+
mtime: Date;
|
|
88
|
+
}
|
|
89
|
+
/** A folder over plain zip's limits. */
|
|
90
|
+
export declare class ArchiveTooLarge extends Error {
|
|
91
|
+
readonly code = "TOO_LARGE";
|
|
92
|
+
}
|
|
93
|
+
/** The files to zip, sorted by path. `skip`: absolute paths to leave out too (the zip itself, written inside the folder). */
|
|
94
|
+
export declare function archiveEntries(root: string, skip?: string[]): Promise<ArchiveEntry[]>;
|
|
95
|
+
/** CRC-32 of bytes. */
|
|
96
|
+
export declare function crc32(bytes: Uint8Array): number;
|
|
97
|
+
/**
|
|
98
|
+
* Writes the zip of `entries` through `write`, one file at a time: its local
|
|
99
|
+
* header and data, then the central directory. A file gone since the listing
|
|
100
|
+
* is left out. Resolves with the number of bytes written.
|
|
101
|
+
*/
|
|
102
|
+
export declare function writeZip(entries: ArchiveEntry[], write: (chunk: Buffer) => Promise<void>): Promise<{
|
|
103
|
+
bytes: number;
|
|
104
|
+
files: number;
|
|
105
|
+
}>;
|
|
106
|
+
/** `<folder>-<yyyy-mm-dd>.zip`: a day's backup beside the last one, not over it. */
|
|
107
|
+
export declare function archiveFileName(root: string, now?: Date): string;
|
|
108
|
+
/**
|
|
109
|
+
* Writes the folder's zip to `out` (through a temp file beside it, so a
|
|
110
|
+
* failure leaves no half zip). `out` may be inside the folder: it is never
|
|
111
|
+
* zipped into itself.
|
|
112
|
+
*/
|
|
113
|
+
export declare function writeArchive(root: string, out: string): Promise<{
|
|
114
|
+
file: string;
|
|
115
|
+
files: number;
|
|
116
|
+
bytes: number;
|
|
117
|
+
}>;
|
|
118
|
+
/** `attachment` with the file's name: plain ASCII in `filename`, the real name in `filename*`. */
|
|
119
|
+
export declare function attachmentHeader(name: string): string;
|
|
120
|
+
/**
|
|
121
|
+
* Answers `GET|HEAD /__open-artifacts/archive`: the folder's zip, streamed as
|
|
122
|
+
* it is written (no length: each file is deflated on the way). `HEAD` lists
|
|
123
|
+
* the files only, so a folder over plain zip's limits answers 413 before
|
|
124
|
+
* anything is zipped. A connection that closes stops the zipping.
|
|
125
|
+
*/
|
|
126
|
+
export declare function sendArchive(req: IncomingMessage, res: ServerResponse, root: string): Promise<void>;
|
|
127
|
+
/** Why a zip is refused: `invalid` (its shape or a name, 400) or `too_large` (a limit, 413). */
|
|
128
|
+
export declare class ZipRefusal extends Error {
|
|
129
|
+
readonly code: 'invalid' | 'too_large';
|
|
130
|
+
readonly status: 400 | 413;
|
|
131
|
+
constructor(code: 'invalid' | 'too_large', message: string);
|
|
132
|
+
}
|
|
133
|
+
/** What {@link checkZip} takes from a zip. */
|
|
134
|
+
export interface ZipRules {
|
|
135
|
+
/** What the zip is, in messages: `a type package`. */
|
|
136
|
+
noun: string;
|
|
137
|
+
/** Files, at most; the directory's declared count is checked before it is walked. */
|
|
138
|
+
maxFiles: number;
|
|
139
|
+
/** Unpacked bytes of all files together, at most. */
|
|
140
|
+
maxBytes: number;
|
|
141
|
+
/** Unpacked bytes of one file, at most, unless `fileLimit` is given. */
|
|
142
|
+
maxFileBytes: number;
|
|
143
|
+
/** Folder entries (`name/`) are taken and skipped; otherwise one is refused. */
|
|
144
|
+
folders?: boolean;
|
|
145
|
+
/** Unpacked bytes of one file, at most, by its path under the top folder; when given it replaces `maxFileBytes`. */
|
|
146
|
+
fileLimit?: (path: string) => number;
|
|
147
|
+
/**
|
|
148
|
+
* What the caller demands of a file beyond the built-in checks: called for each file entry once its name has passed
|
|
149
|
+
* them, with its path under the top folder. A string refuses the zip (`invalid`, that string its message); null takes
|
|
150
|
+
* the file.
|
|
151
|
+
*/
|
|
152
|
+
accept?: (entry: ZipEntry, path: string) => string | null;
|
|
153
|
+
}
|
|
154
|
+
/** One file of a checked zip: its path under the top folder and the permissions it is written with. */
|
|
155
|
+
export interface CheckedZipFile {
|
|
156
|
+
entry: ZipEntry;
|
|
157
|
+
path: string;
|
|
158
|
+
mode: number;
|
|
159
|
+
}
|
|
160
|
+
/** Whether an entry was made on a Unix host and its mode says a regular file (not a folder, link, device or no kind at all). */
|
|
161
|
+
export declare function isUnixRegularFile(entry: ZipEntry): boolean;
|
|
162
|
+
/** How a name compares on a disk that ignores case and Unicode normalization. */
|
|
163
|
+
export declare const foldedName: (path: string) => string;
|
|
164
|
+
/**
|
|
165
|
+
* Every entry of a zip checked, before a byte is unpacked: no encryption, stored or deflated only; plain files (and,
|
|
166
|
+
* with `folders`, folder entries) only, so no symbolic link or device (by the Unix mode in the external attributes);
|
|
167
|
+
* no NUL, backslash, absolute path, `..`, empty or `.` step; all under one top folder; no name twice once case and
|
|
168
|
+
* Unicode normalization are ignored, and no name both a file and a folder; local headers that match the directory;
|
|
169
|
+
* and the declared sizes within `rules` (which {@link unpackZip} holds them to while inflating), each file's against
|
|
170
|
+
* `rules.fileLimit` of its path when given, else `rules.maxFileBytes`. A file whose name passes the built-in checks is
|
|
171
|
+
* then put to `rules.accept`, when given, before the duplicate and size checks; a string it returns is thrown as an
|
|
172
|
+
* `invalid` refusal. Throws {@link ZipRefusal}.
|
|
173
|
+
*/
|
|
174
|
+
export declare function checkZip(bytes: Uint8Array, rules: ZipRules): {
|
|
175
|
+
top: string;
|
|
176
|
+
files: CheckedZipFile[];
|
|
177
|
+
};
|
|
178
|
+
/** One checked file's bytes: inflated never past its declared size, which must be its real size, with its CRC holding. */
|
|
179
|
+
export declare function unpackZipFile(bytes: Uint8Array, item: CheckedZipFile): Promise<Buffer>;
|
|
180
|
+
/** Writes a new file, refusing one that exists and never following a symbolic link. */
|
|
181
|
+
export declare function writeNewFile(file: string, data: Uint8Array, mode?: number): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Unpacks a checked zip into a new temporary folder beside `dest` (named `.<dest>.<random>.unpack`, so a type root's
|
|
184
|
+
* scan skips it), counting the bytes actually inflated against `maxBytes`, and returns that folder. The caller checks
|
|
185
|
+
* what was unpacked and renames it into place; on a failure here the temporary folder is removed.
|
|
186
|
+
*/
|
|
187
|
+
export declare function unpackZip(bytes: Uint8Array, files: readonly CheckedZipFile[], dest: string, maxBytes: number): Promise<{
|
|
188
|
+
temp: string;
|
|
189
|
+
files: number;
|
|
190
|
+
bytes: number;
|
|
191
|
+
}>;
|
|
192
|
+
/** Moves a checked, unpacked folder into place; refuses when `dest` exists by then. */
|
|
193
|
+
export declare function moveIntoPlace(temp: string, dest: string): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* The zip of a folder's files as bytes (`types pack`): `entries` named `<folder>/<path>`, already chosen by the caller.
|
|
196
|
+
*/
|
|
197
|
+
export declare function zipBytes(entries: ArchiveEntry[]): Promise<Buffer>;
|