@dreamlake/dreamlake-cli 0.117.0 → 0.118.1
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/api/agent.d.ts +1 -0
- package/dist/api/file-multipart.d.ts +6 -0
- package/dist/api/file-multipart.js +34 -0
- package/dist/api/file-source.d.ts +30 -0
- package/dist/api/file-source.js +165 -0
- package/dist/api/file-workspace.d.ts +79 -0
- package/dist/api/file-workspace.js +142 -0
- package/dist/api/index.d.ts +60 -1
- package/dist/api/index.js +8 -2
- package/dist/api/native-experiments.d.ts +25 -0
- package/dist/api/native-experiments.js +49 -4
- package/dist/api/sessions.d.ts +6 -0
- package/dist/cli/agents/chat.d.ts +21 -0
- package/dist/cli/agents/chat.js +126 -0
- package/dist/cli/agents/index.js +3 -1
- package/dist/cli/experiments/index.js +4 -0
- package/dist/cli/experiments/management.d.ts +16 -0
- package/dist/cli/experiments/management.js +82 -0
- package/dist/cli/experiments/transfer/adapter.d.ts +86 -0
- package/dist/cli/experiments/transfer/adapter.js +637 -0
- package/dist/cli/experiments/transfer/context.d.ts +13 -0
- package/dist/cli/experiments/transfer/context.js +20 -0
- package/dist/cli/experiments/transfer/download.d.ts +24 -0
- package/dist/cli/experiments/transfer/download.js +516 -0
- package/dist/cli/experiments/transfer/index.d.ts +2 -0
- package/dist/cli/experiments/transfer/index.js +38 -0
- package/dist/cli/experiments/transfer/local/safe-path.d.ts +29 -0
- package/dist/cli/experiments/transfer/local/safe-path.js +106 -0
- package/dist/cli/experiments/transfer/local/storage.d.ts +125 -0
- package/dist/cli/experiments/transfer/local/storage.js +432 -0
- package/dist/cli/experiments/transfer/transport.d.ts +7 -0
- package/dist/cli/experiments/transfer/transport.js +31 -0
- package/dist/cli/experiments/transfer/types.d.ts +48 -0
- package/dist/cli/experiments/transfer/types.js +1 -0
- package/dist/cli/experiments/transfer/upload.d.ts +58 -0
- package/dist/cli/experiments/transfer/upload.js +665 -0
- package/dist/cli/experiments/transfer/util/ansi.d.ts +24 -0
- package/dist/cli/experiments/transfer/util/ansi.js +70 -0
- package/dist/cli/experiments/transfer/util/glob.d.ts +4 -0
- package/dist/cli/experiments/transfer/util/glob.js +39 -0
- package/dist/cli/experiments/transfer/util/json.d.ts +6 -0
- package/dist/cli/experiments/transfer/util/json.js +58 -0
- package/dist/cli/experiments/transfer/util/pool.d.ts +5 -0
- package/dist/cli/experiments/transfer/util/pool.js +21 -0
- package/dist/cli/help-examples.generated.js +17 -0
- package/dist/cli/library/discover.d.ts +4 -2
- package/dist/cli/library/discover.js +5 -3
- package/dist/cli/sessions/control.js +2 -28
- package/dist/cli/sessions/runner/native-result.d.ts +34 -0
- package/dist/cli/sessions/runner/native-result.js +101 -0
- package/dist/cli/sessions/runner/serve.js +45 -2
- package/dist/cli/source/files.d.ts +2 -0
- package/dist/cli/source/files.js +39 -0
- package/dist/cli/source/index.js +2 -0
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +9 -9
package/dist/api/agent.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type Transport } from "./client.js";
|
|
|
4
4
|
import type { PageContentSnapshot } from "./browser.js";
|
|
5
5
|
export type { PageContentSnapshot } from "./browser.js";
|
|
6
6
|
export type TurnCapabilities = {
|
|
7
|
+
personalExtensions?: 1;
|
|
7
8
|
layoutActions?: 1;
|
|
8
9
|
sessionControl?: 1;
|
|
9
10
|
notesWrite?: 1;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface FileMultipart {
|
|
2
|
+
body: ReadableStream<Uint8Array>;
|
|
3
|
+
contentType: string;
|
|
4
|
+
}
|
|
5
|
+
/** Preserve filenames and stream file-backed Blobs directly (Bun drops them inside composite Blobs). */
|
|
6
|
+
export declare function fileMultipart(fields: Record<string, string>, file: Blob, filename: string, contentType?: string): FileMultipart;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
/** Preserve filenames and stream file-backed Blobs directly (Bun drops them inside composite Blobs). */
|
|
3
|
+
export function fileMultipart(fields, file, filename, contentType = file.type || 'application/octet-stream') {
|
|
4
|
+
const boundary = `dreamlake-${randomUUID()}`;
|
|
5
|
+
let head = '';
|
|
6
|
+
for (const [name, value] of Object.entries(fields))
|
|
7
|
+
head += `--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`;
|
|
8
|
+
const encoded = encodeURIComponent(filename).replace(/['()*]/g, c => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
9
|
+
head += `--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="file"; filename*=UTF-8''${encoded}\r\nContent-Type: ${contentType}\r\n\r\n`;
|
|
10
|
+
const encoder = new TextEncoder();
|
|
11
|
+
async function* chunks() {
|
|
12
|
+
yield encoder.encode(head);
|
|
13
|
+
for await (const chunk of file.stream())
|
|
14
|
+
yield chunk;
|
|
15
|
+
yield encoder.encode(`\r\n--${boundary}--\r\n`);
|
|
16
|
+
}
|
|
17
|
+
const iterator = chunks();
|
|
18
|
+
const body = new ReadableStream({
|
|
19
|
+
async pull(controller) {
|
|
20
|
+
try {
|
|
21
|
+
const next = await iterator.next();
|
|
22
|
+
if (next.done)
|
|
23
|
+
controller.close();
|
|
24
|
+
else
|
|
25
|
+
controller.enqueue(next.value);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
controller.error(error);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
async cancel() { await iterator.return(undefined); },
|
|
32
|
+
});
|
|
33
|
+
return { body, contentType: `multipart/form-data; boundary=${boundary}` };
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Transport } from "./client.js";
|
|
2
|
+
import { type FileAdapter } from "./file-workspace.js";
|
|
3
|
+
/** Managed Source workspace only. External layers are asset inputs, not writable workspace files. */
|
|
4
|
+
export declare class SourceFileAdapter implements FileAdapter {
|
|
5
|
+
readonly api: Transport;
|
|
6
|
+
readonly signal: AbortSignal;
|
|
7
|
+
readonly transport: typeof fetch;
|
|
8
|
+
readonly base: string;
|
|
9
|
+
constructor(api: Transport, namespace: string, sourceId: string, signal: AbortSignal, transport?: typeof fetch);
|
|
10
|
+
list(path: string, cursor?: string): Promise<{
|
|
11
|
+
entries: {
|
|
12
|
+
path: string;
|
|
13
|
+
kind: "file" | "directory";
|
|
14
|
+
size: number | null;
|
|
15
|
+
revision: null;
|
|
16
|
+
}[];
|
|
17
|
+
nextCursor: string | null;
|
|
18
|
+
}>;
|
|
19
|
+
private requestStorage;
|
|
20
|
+
read(path: string): Promise<{
|
|
21
|
+
path: string;
|
|
22
|
+
content: string;
|
|
23
|
+
revision: string;
|
|
24
|
+
}>;
|
|
25
|
+
write(path: string, content: string, expectedRevision: string | null): Promise<{
|
|
26
|
+
path: string;
|
|
27
|
+
content: string;
|
|
28
|
+
revision: string;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { FileError, MAX_TEXT_BYTES, boundedText, canonicalPath, } from "./file-workspace.js";
|
|
3
|
+
const etag = (value) => !!value &&
|
|
4
|
+
/^"[\x21\x23-\x7e\x80-\xff]+"$/.test(value) &&
|
|
5
|
+
value.length <= 1024;
|
|
6
|
+
/** Managed Source workspace only. External layers are asset inputs, not writable workspace files. */
|
|
7
|
+
export class SourceFileAdapter {
|
|
8
|
+
api;
|
|
9
|
+
signal;
|
|
10
|
+
transport;
|
|
11
|
+
base;
|
|
12
|
+
constructor(api, namespace, sourceId, signal, transport = fetch) {
|
|
13
|
+
this.api = api;
|
|
14
|
+
this.signal = signal;
|
|
15
|
+
this.transport = transport;
|
|
16
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(namespace) ||
|
|
17
|
+
!/^[a-fA-F0-9]{24}$/.test(sourceId))
|
|
18
|
+
throw new FileError("file_endpoint_invalid");
|
|
19
|
+
this.base = `/namespaces/${encodeURIComponent(namespace)}/sources/${sourceId}`;
|
|
20
|
+
}
|
|
21
|
+
async list(path, cursor) {
|
|
22
|
+
canonicalPath(path, true);
|
|
23
|
+
const page = await this.api.request("GET", this.base + "/browse", {
|
|
24
|
+
query: { path, cursor, limit: 10 },
|
|
25
|
+
signal: this.signal,
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
entries: page.entries
|
|
29
|
+
.filter((e) => e.origin.kind === "dreamlake-storage")
|
|
30
|
+
.map((e) => ({
|
|
31
|
+
path: e.path,
|
|
32
|
+
kind: e.kind,
|
|
33
|
+
size: e.size,
|
|
34
|
+
revision: null,
|
|
35
|
+
})),
|
|
36
|
+
nextCursor: page.nextCursor,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async requestStorage(url, headers = {}, body) {
|
|
40
|
+
// Only route-minted capabilities reach here; model input never supplies a URL or credential.
|
|
41
|
+
const target = new URL(url);
|
|
42
|
+
if (target.protocol !== "https:" ||
|
|
43
|
+
target.username ||
|
|
44
|
+
target.password ||
|
|
45
|
+
Object.keys(headers).some((k) => /^(authorization|cookie)$/i.test(k)))
|
|
46
|
+
throw new FileError("file_capability_invalid");
|
|
47
|
+
try {
|
|
48
|
+
return await this.transport(url, {
|
|
49
|
+
method: body === undefined ? "GET" : "PUT",
|
|
50
|
+
headers,
|
|
51
|
+
body,
|
|
52
|
+
redirect: "error",
|
|
53
|
+
signal: AbortSignal.any([this.signal, AbortSignal.timeout(30000)]),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw new FileError(body === undefined ? "file_read_failed" : "file_write_unconfirmed");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async read(path) {
|
|
61
|
+
canonicalPath(path);
|
|
62
|
+
const cap = await this.api.request("POST", this.base + "/managed-read-capabilities", {
|
|
63
|
+
json: { path },
|
|
64
|
+
signal: this.signal,
|
|
65
|
+
});
|
|
66
|
+
if (cap.method !== "GET")
|
|
67
|
+
throw new FileError("file_capability_invalid");
|
|
68
|
+
const response = await this.requestStorage(cap.url, cap.allowedHeaders);
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
await response.body?.cancel();
|
|
71
|
+
throw new FileError(response.status === 404 ? "file_not_found" : "file_read_failed");
|
|
72
|
+
}
|
|
73
|
+
if (!response.body)
|
|
74
|
+
throw new FileError("file_read_failed");
|
|
75
|
+
const reader = response.body.getReader(), chunks = [];
|
|
76
|
+
let size = 0;
|
|
77
|
+
try {
|
|
78
|
+
for (;;) {
|
|
79
|
+
const item = await reader.read();
|
|
80
|
+
if (item.done)
|
|
81
|
+
break;
|
|
82
|
+
size += item.value.length;
|
|
83
|
+
if (size > MAX_TEXT_BYTES)
|
|
84
|
+
throw new FileError("file_text_too_large_or_binary");
|
|
85
|
+
chunks.push(item.value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await reader.cancel().catch(() => undefined);
|
|
90
|
+
reader.releaseLock();
|
|
91
|
+
}
|
|
92
|
+
let content;
|
|
93
|
+
try {
|
|
94
|
+
content = new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks));
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
throw new FileError("file_text_too_large_or_binary");
|
|
98
|
+
}
|
|
99
|
+
boundedText(content);
|
|
100
|
+
const revision = response.headers.get("etag");
|
|
101
|
+
if (!etag(revision))
|
|
102
|
+
throw new FileError("file_revision_unavailable");
|
|
103
|
+
// Fresh route authorization after the storage read: do not return bytes after access was revoked.
|
|
104
|
+
await this.api.request("POST", this.base + "/managed-read-capabilities", {
|
|
105
|
+
json: { path },
|
|
106
|
+
signal: this.signal,
|
|
107
|
+
});
|
|
108
|
+
return { path, content, revision };
|
|
109
|
+
}
|
|
110
|
+
async write(path, content, expectedRevision) {
|
|
111
|
+
canonicalPath(path);
|
|
112
|
+
boundedText(content);
|
|
113
|
+
if (expectedRevision !== null && !etag(expectedRevision))
|
|
114
|
+
throw new FileError("file_revision_invalid");
|
|
115
|
+
const precondition = expectedRevision === null
|
|
116
|
+
? { "if-none-match": "*" }
|
|
117
|
+
: { "if-match": expectedRevision };
|
|
118
|
+
const size = Buffer.byteLength(content);
|
|
119
|
+
const plan = await this.api.request("POST", this.base + "/upload-authorizations", {
|
|
120
|
+
json: {
|
|
121
|
+
files: [
|
|
122
|
+
{
|
|
123
|
+
relativePath: path,
|
|
124
|
+
size,
|
|
125
|
+
mediaType: "text/plain; charset=utf-8",
|
|
126
|
+
...(expectedRevision === null
|
|
127
|
+
? { ifNoneMatch: "*" }
|
|
128
|
+
: { ifMatch: expectedRevision }),
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
signal: this.signal,
|
|
133
|
+
});
|
|
134
|
+
const file = plan.files?.[0];
|
|
135
|
+
if (plan.mode !== "s3-presigned-batch" ||
|
|
136
|
+
plan.files.length !== 1 ||
|
|
137
|
+
file.relativePath !== path ||
|
|
138
|
+
file.canonicalPath !== path ||
|
|
139
|
+
file.size !== size ||
|
|
140
|
+
file.transfer.kind !== "single-put")
|
|
141
|
+
throw new FileError("file_capability_invalid");
|
|
142
|
+
const put = file.transfer.put;
|
|
143
|
+
const headers = Object.fromEntries(Object.entries(put.headers).map(([k, v]) => [k.toLowerCase(), v]));
|
|
144
|
+
if (Object.entries(precondition).some(([k, v]) => headers[k] !== v) ||
|
|
145
|
+
("if-match" in headers && "if-none-match" in headers))
|
|
146
|
+
throw new FileError("file_precondition_missing");
|
|
147
|
+
const response = await this.requestStorage(put.url, put.headers, content);
|
|
148
|
+
await response.body?.cancel();
|
|
149
|
+
if (response.status === 409 || response.status === 412)
|
|
150
|
+
throw new FileError("file_revision_conflict");
|
|
151
|
+
if (!response.ok)
|
|
152
|
+
throw new FileError("file_write_unconfirmed");
|
|
153
|
+
// Read back through the managed layer; never verify against an external fallback.
|
|
154
|
+
try {
|
|
155
|
+
const result = await this.read(path);
|
|
156
|
+
if (createHash("sha256").update(result.content).digest("hex") !==
|
|
157
|
+
createHash("sha256").update(content).digest("hex"))
|
|
158
|
+
throw new FileError("file_write_unconfirmed");
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
throw new FileError("file_write_unconfirmed");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Endpoint-independent file operations. An endpoint is supplied by the host, never inferred from a prompt. */
|
|
2
|
+
export declare const MAX_TEXT_BYTES: number;
|
|
3
|
+
export declare class FileError extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
constructor(code: string);
|
|
6
|
+
}
|
|
7
|
+
export interface FileEntry {
|
|
8
|
+
path: string;
|
|
9
|
+
kind: "file" | "directory";
|
|
10
|
+
size: number | null;
|
|
11
|
+
revision: string | null;
|
|
12
|
+
}
|
|
13
|
+
export interface TextFile {
|
|
14
|
+
path: string;
|
|
15
|
+
content: string;
|
|
16
|
+
revision: string;
|
|
17
|
+
}
|
|
18
|
+
export interface FileAdapter {
|
|
19
|
+
list(path: string, cursor?: string): Promise<{
|
|
20
|
+
entries: FileEntry[];
|
|
21
|
+
nextCursor: string | null;
|
|
22
|
+
}>;
|
|
23
|
+
read(path: string): Promise<TextFile>;
|
|
24
|
+
/** null means create-only. An opaque revision means compare-and-swap; never an unconditional overwrite. */
|
|
25
|
+
write(path: string, content: string, expectedRevision: string | null): Promise<TextFile>;
|
|
26
|
+
}
|
|
27
|
+
export declare function canonicalPath(path: string, root?: boolean): string;
|
|
28
|
+
export declare function boundedText(content: string): string;
|
|
29
|
+
/** Prefix is a containment boundary, not an authority grant. Adapters must authorize every call. */
|
|
30
|
+
export declare class FileWorkspace {
|
|
31
|
+
readonly adapter: FileAdapter;
|
|
32
|
+
readonly prefix: string;
|
|
33
|
+
constructor(adapter: FileAdapter, prefix?: string);
|
|
34
|
+
private resolve;
|
|
35
|
+
private relative;
|
|
36
|
+
list(path?: string, cursor?: string): Promise<{
|
|
37
|
+
entries: {
|
|
38
|
+
path: string;
|
|
39
|
+
kind: "file" | "directory";
|
|
40
|
+
size: number | null;
|
|
41
|
+
revision: string | null;
|
|
42
|
+
}[];
|
|
43
|
+
nextCursor: string | null;
|
|
44
|
+
}>;
|
|
45
|
+
read(path: string): Promise<{
|
|
46
|
+
path: string;
|
|
47
|
+
content: string;
|
|
48
|
+
revision: string;
|
|
49
|
+
}>;
|
|
50
|
+
write(path: string, content: string, expectedRevision: string | null): Promise<{
|
|
51
|
+
path: string;
|
|
52
|
+
content: string;
|
|
53
|
+
revision: string;
|
|
54
|
+
}>;
|
|
55
|
+
replace(path: string, oldText: string, newText: string, expectedRevision: string): Promise<{
|
|
56
|
+
path: string;
|
|
57
|
+
content: string;
|
|
58
|
+
revision: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
/** Browser-session cache adapter. Each instance is isolated; no durable persistence is claimed. */
|
|
62
|
+
export declare class MemoryFileAdapter implements FileAdapter {
|
|
63
|
+
private files;
|
|
64
|
+
private revision;
|
|
65
|
+
list(path: string, cursor?: string): Promise<{
|
|
66
|
+
entries: FileEntry[];
|
|
67
|
+
nextCursor: null;
|
|
68
|
+
}>;
|
|
69
|
+
read(path: string): Promise<{
|
|
70
|
+
path: string;
|
|
71
|
+
content: string;
|
|
72
|
+
revision: string;
|
|
73
|
+
}>;
|
|
74
|
+
write(path: string, content: string, expectedRevision: string | null): Promise<{
|
|
75
|
+
path: string;
|
|
76
|
+
content: string;
|
|
77
|
+
revision: string;
|
|
78
|
+
}>;
|
|
79
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** Endpoint-independent file operations. An endpoint is supplied by the host, never inferred from a prompt. */
|
|
2
|
+
export const MAX_TEXT_BYTES = 256 * 1024;
|
|
3
|
+
export class FileError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
constructor(code) {
|
|
6
|
+
super(code);
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function canonicalPath(path, root = false) {
|
|
11
|
+
if (typeof path !== "string" ||
|
|
12
|
+
(!root && !path) ||
|
|
13
|
+
path.startsWith("/") ||
|
|
14
|
+
path.endsWith("/") ||
|
|
15
|
+
/[\\\u0000-\u001f\u007f-\u009f]/.test(path) ||
|
|
16
|
+
new TextEncoder().encode(path).length > 1024 ||
|
|
17
|
+
path
|
|
18
|
+
.split("/")
|
|
19
|
+
.some((s) => (!s && !!path) ||
|
|
20
|
+
s === "." ||
|
|
21
|
+
s === ".." ||
|
|
22
|
+
new TextEncoder().encode(s).length > 255))
|
|
23
|
+
throw new FileError("file_path_invalid");
|
|
24
|
+
return path;
|
|
25
|
+
}
|
|
26
|
+
export function boundedText(content) {
|
|
27
|
+
if (typeof content !== "string" ||
|
|
28
|
+
content.includes("\0") ||
|
|
29
|
+
new TextEncoder().encode(content).length > MAX_TEXT_BYTES)
|
|
30
|
+
throw new FileError("file_text_too_large_or_binary");
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
/** Prefix is a containment boundary, not an authority grant. Adapters must authorize every call. */
|
|
34
|
+
export class FileWorkspace {
|
|
35
|
+
adapter;
|
|
36
|
+
prefix;
|
|
37
|
+
constructor(adapter, prefix = "") {
|
|
38
|
+
this.adapter = adapter;
|
|
39
|
+
this.prefix = prefix;
|
|
40
|
+
canonicalPath(prefix, true);
|
|
41
|
+
}
|
|
42
|
+
resolve(path, root = false) {
|
|
43
|
+
canonicalPath(path, root);
|
|
44
|
+
return this.prefix ? this.prefix + (path ? "/" + path : "") : path;
|
|
45
|
+
}
|
|
46
|
+
relative(path) {
|
|
47
|
+
canonicalPath(path, true);
|
|
48
|
+
if (!this.prefix)
|
|
49
|
+
return path;
|
|
50
|
+
if (path === this.prefix)
|
|
51
|
+
return "";
|
|
52
|
+
if (!path.startsWith(this.prefix + "/"))
|
|
53
|
+
throw new FileError("file_endpoint_outside_prefix");
|
|
54
|
+
return path.slice(this.prefix.length + 1);
|
|
55
|
+
}
|
|
56
|
+
async list(path = "", cursor) {
|
|
57
|
+
const result = await this.adapter.list(this.resolve(path, true), cursor);
|
|
58
|
+
return {
|
|
59
|
+
entries: result.entries.map((e) => ({
|
|
60
|
+
...e,
|
|
61
|
+
path: this.relative(e.path),
|
|
62
|
+
})),
|
|
63
|
+
nextCursor: result.nextCursor,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async read(path) {
|
|
67
|
+
const result = await this.adapter.read(this.resolve(path));
|
|
68
|
+
if (this.relative(result.path) !== path)
|
|
69
|
+
throw new FileError("file_endpoint_path_mismatch");
|
|
70
|
+
boundedText(result.content);
|
|
71
|
+
return { ...result, path };
|
|
72
|
+
}
|
|
73
|
+
async write(path, content, expectedRevision) {
|
|
74
|
+
boundedText(content);
|
|
75
|
+
if (expectedRevision !== null &&
|
|
76
|
+
(typeof expectedRevision !== "string" || !expectedRevision))
|
|
77
|
+
throw new FileError("file_revision_required");
|
|
78
|
+
const result = await this.adapter.write(this.resolve(path), content, expectedRevision);
|
|
79
|
+
if (this.relative(result.path) !== path)
|
|
80
|
+
throw new FileError("file_endpoint_path_mismatch");
|
|
81
|
+
return { ...result, path };
|
|
82
|
+
}
|
|
83
|
+
async replace(path, oldText, newText, expectedRevision) {
|
|
84
|
+
if (!oldText)
|
|
85
|
+
throw new FileError("file_replace_empty_match");
|
|
86
|
+
const file = await this.read(path);
|
|
87
|
+
if (file.revision !== expectedRevision)
|
|
88
|
+
throw new FileError("file_revision_conflict");
|
|
89
|
+
const at = file.content.indexOf(oldText);
|
|
90
|
+
if (at < 0 || file.content.indexOf(oldText, at + 1) >= 0)
|
|
91
|
+
throw new FileError("file_replace_match_not_unique");
|
|
92
|
+
return this.write(path, file.content.slice(0, at) +
|
|
93
|
+
newText +
|
|
94
|
+
file.content.slice(at + oldText.length), expectedRevision);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Browser-session cache adapter. Each instance is isolated; no durable persistence is claimed. */
|
|
98
|
+
export class MemoryFileAdapter {
|
|
99
|
+
files = new Map();
|
|
100
|
+
revision = 0;
|
|
101
|
+
async list(path, cursor) {
|
|
102
|
+
canonicalPath(path, true);
|
|
103
|
+
if (cursor)
|
|
104
|
+
throw new FileError("file_cursor_invalid");
|
|
105
|
+
const prefix = path ? path + "/" : "", entries = new Map();
|
|
106
|
+
for (const [key, value] of this.files)
|
|
107
|
+
if (key.startsWith(prefix)) {
|
|
108
|
+
const tail = key.slice(prefix.length), child = prefix + tail.split("/")[0];
|
|
109
|
+
entries.set(child, tail.includes("/")
|
|
110
|
+
? { path: child, kind: "directory", size: null, revision: null }
|
|
111
|
+
: {
|
|
112
|
+
path: key,
|
|
113
|
+
kind: "file",
|
|
114
|
+
size: new TextEncoder().encode(value.content).length,
|
|
115
|
+
revision: value.revision,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
entries: [...entries.values()].sort((a, b) => a.path.localeCompare(b.path)),
|
|
120
|
+
nextCursor: null,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async read(path) {
|
|
124
|
+
canonicalPath(path);
|
|
125
|
+
const file = this.files.get(path);
|
|
126
|
+
if (!file)
|
|
127
|
+
throw new FileError("file_not_found");
|
|
128
|
+
return { ...file };
|
|
129
|
+
}
|
|
130
|
+
async write(path, content, expectedRevision) {
|
|
131
|
+
canonicalPath(path);
|
|
132
|
+
boundedText(content);
|
|
133
|
+
if ((this.files.get(path)?.revision ?? null) !== expectedRevision)
|
|
134
|
+
throw new FileError("file_revision_conflict");
|
|
135
|
+
for (const key of this.files.keys())
|
|
136
|
+
if (key.startsWith(path + "/") || path.startsWith(key + "/"))
|
|
137
|
+
throw new FileError("file_directory_conflict");
|
|
138
|
+
const file = { path, content, revision: `memory:${++this.revision}` };
|
|
139
|
+
this.files.set(path, file);
|
|
140
|
+
return { ...file };
|
|
141
|
+
}
|
|
142
|
+
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { FileWorkspace } from "./file-workspace.js";
|
|
2
|
+
export * from "./file-workspace.js";
|
|
3
|
+
export * from "./file-source.js";
|
|
1
4
|
export * from './apps.js';
|
|
2
5
|
export * from './lakeshore-connections.js';
|
|
3
6
|
export * from "./open-resources.js";
|
|
@@ -31,7 +34,7 @@ export * from "./memos.js";
|
|
|
31
34
|
export * from "./agent.js";
|
|
32
35
|
export * from "./skills.js";
|
|
33
36
|
/** TypeScript operations use an explicit transport; importing does not execute CLI startup. */
|
|
34
|
-
export declare function createApi(transport: Transport): {
|
|
37
|
+
export declare function createApi(transport: Transport, storageFetch?: typeof fetch): {
|
|
35
38
|
transport: Transport;
|
|
36
39
|
apps: (namespace: string) => {
|
|
37
40
|
list: () => Promise<import("./apps.js").AppCatalog>;
|
|
@@ -343,6 +346,28 @@ export declare function createApi(transport: Transport): {
|
|
|
343
346
|
signal?: AbortSignal;
|
|
344
347
|
}) => Promise<Response>;
|
|
345
348
|
};
|
|
349
|
+
writers: {
|
|
350
|
+
list: (query?: {
|
|
351
|
+
limit?: number;
|
|
352
|
+
cursor?: string;
|
|
353
|
+
}) => Promise<unknown>;
|
|
354
|
+
get: (id: string) => Promise<unknown>;
|
|
355
|
+
create: (idempotencyKey: string, runId?: string) => Promise<unknown>;
|
|
356
|
+
rotate: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
|
|
357
|
+
retire: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
|
|
358
|
+
};
|
|
359
|
+
jobs: {
|
|
360
|
+
submit: (input: import("./execution.js").RunInput) => Promise<unknown>;
|
|
361
|
+
list: (query?: {
|
|
362
|
+
limit?: number;
|
|
363
|
+
cursor?: string;
|
|
364
|
+
}) => Promise<unknown>;
|
|
365
|
+
summary: (id: string) => Promise<unknown>;
|
|
366
|
+
cancel: (id: string) => Promise<unknown>;
|
|
367
|
+
logs: (id: string, query?: {
|
|
368
|
+
cursor?: string;
|
|
369
|
+
}) => Promise<unknown>;
|
|
370
|
+
};
|
|
346
371
|
setStatus: (id: string, status: import("./native-experiments.js").NativeRunStatus) => Promise<unknown>;
|
|
347
372
|
};
|
|
348
373
|
machine: {
|
|
@@ -1089,6 +1114,12 @@ export declare function createApi(transport: Transport): {
|
|
|
1089
1114
|
filesPresign: (name: string, paths: string[], ttlSeconds?: number) => Promise<unknown>;
|
|
1090
1115
|
register: (name: string, input: import("./common.js").JsonObject) => Promise<unknown>;
|
|
1091
1116
|
};
|
|
1117
|
+
files: (endpoint: {
|
|
1118
|
+
kind: "source";
|
|
1119
|
+
namespace: string;
|
|
1120
|
+
sourceId: string;
|
|
1121
|
+
prefix: string;
|
|
1122
|
+
}, signal?: AbortSignal) => FileWorkspace;
|
|
1092
1123
|
sources: (namespace: string) => {
|
|
1093
1124
|
list: (query?: {
|
|
1094
1125
|
cursor?: string;
|
|
@@ -1642,6 +1673,28 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1642
1673
|
signal?: AbortSignal;
|
|
1643
1674
|
}) => Promise<Response>;
|
|
1644
1675
|
};
|
|
1676
|
+
writers: {
|
|
1677
|
+
list: (query?: {
|
|
1678
|
+
limit?: number;
|
|
1679
|
+
cursor?: string;
|
|
1680
|
+
}) => Promise<unknown>;
|
|
1681
|
+
get: (id: string) => Promise<unknown>;
|
|
1682
|
+
create: (idempotencyKey: string, runId?: string) => Promise<unknown>;
|
|
1683
|
+
rotate: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
|
|
1684
|
+
retire: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
|
|
1685
|
+
};
|
|
1686
|
+
jobs: {
|
|
1687
|
+
submit: (input: import("./execution.js").RunInput) => Promise<unknown>;
|
|
1688
|
+
list: (query?: {
|
|
1689
|
+
limit?: number;
|
|
1690
|
+
cursor?: string;
|
|
1691
|
+
}) => Promise<unknown>;
|
|
1692
|
+
summary: (id: string) => Promise<unknown>;
|
|
1693
|
+
cancel: (id: string) => Promise<unknown>;
|
|
1694
|
+
logs: (id: string, query?: {
|
|
1695
|
+
cursor?: string;
|
|
1696
|
+
}) => Promise<unknown>;
|
|
1697
|
+
};
|
|
1645
1698
|
setStatus: (id: string, status: import("./native-experiments.js").NativeRunStatus) => Promise<unknown>;
|
|
1646
1699
|
};
|
|
1647
1700
|
machine: {
|
|
@@ -2388,6 +2441,12 @@ export declare function createClient(options: ClientOptions): {
|
|
|
2388
2441
|
filesPresign: (name: string, paths: string[], ttlSeconds?: number) => Promise<unknown>;
|
|
2389
2442
|
register: (name: string, input: import("./common.js").JsonObject) => Promise<unknown>;
|
|
2390
2443
|
};
|
|
2444
|
+
files: (endpoint: {
|
|
2445
|
+
kind: "source";
|
|
2446
|
+
namespace: string;
|
|
2447
|
+
sourceId: string;
|
|
2448
|
+
prefix: string;
|
|
2449
|
+
}, signal?: AbortSignal) => FileWorkspace;
|
|
2391
2450
|
sources: (namespace: string) => {
|
|
2392
2451
|
list: (query?: {
|
|
2393
2452
|
cursor?: string;
|
package/dist/api/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { FileWorkspace } from "./file-workspace.js";
|
|
2
|
+
import { SourceFileAdapter } from "./file-source.js";
|
|
3
|
+
export * from "./file-workspace.js";
|
|
4
|
+
export * from "./file-source.js";
|
|
1
5
|
import { appsApi } from './apps.js';
|
|
2
6
|
export * from './apps.js';
|
|
3
7
|
import { lakeshoreConnectionsApi } from './lakeshore-connections.js';
|
|
@@ -61,7 +65,7 @@ export * from "./memos.js";
|
|
|
61
65
|
export * from "./agent.js";
|
|
62
66
|
export * from "./skills.js";
|
|
63
67
|
/** TypeScript operations use an explicit transport; importing does not execute CLI startup. */
|
|
64
|
-
export function createApi(transport) {
|
|
68
|
+
export function createApi(transport, storageFetch = fetch) {
|
|
65
69
|
const memos = memosFacade(transport);
|
|
66
70
|
return {
|
|
67
71
|
transport,
|
|
@@ -97,6 +101,8 @@ export function createApi(transport) {
|
|
|
97
101
|
workflows: (namespace) => workflowsApi(transport, namespace),
|
|
98
102
|
runnables: (namespace) => runnablesApi(transport, namespace),
|
|
99
103
|
libraries: (namespace) => librariesApi(transport, namespace),
|
|
104
|
+
files: (endpoint, signal = new AbortController().signal) => { if (endpoint.kind !== 'source')
|
|
105
|
+
throw new Error('file_endpoint_invalid'); return new FileWorkspace(new SourceFileAdapter(transport, endpoint.namespace, endpoint.sourceId, signal, storageFetch), endpoint.prefix); },
|
|
100
106
|
sources: (namespace) => sourcesApi(transport, namespace),
|
|
101
107
|
runs: (namespace) => runsApi(transport, namespace),
|
|
102
108
|
providers: (namespace) => providersApi(transport, namespace),
|
|
@@ -109,7 +115,7 @@ export function createApi(transport) {
|
|
|
109
115
|
export function createClient(options) {
|
|
110
116
|
const transport = createTransport(options);
|
|
111
117
|
return {
|
|
112
|
-
...createApi(transport),
|
|
118
|
+
...createApi(transport, options.fetch ?? fetch),
|
|
113
119
|
agent: agentApi(transport, options),
|
|
114
120
|
jobs: (namespace) => JobsApi.create(options.remote, options.token, namespace, options.fetch),
|
|
115
121
|
get infra() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type FileMultipart } from "./file-multipart.js";
|
|
1
2
|
import { type Transport } from "./client.js";
|
|
2
3
|
import { type Query } from "./common.js";
|
|
3
4
|
export interface NativeExperimentRun {
|
|
@@ -94,6 +95,8 @@ export declare function nativeLogQuery(query?: NativeLogQuery): Query;
|
|
|
94
95
|
* The multipart body of a file upload. Text fields precede the file part: the server reads
|
|
95
96
|
* only the fields received before the file, and verifies `sizeBytes` and `checksum` against it.
|
|
96
97
|
*/
|
|
98
|
+
export declare function nativeFileMultipart(upload: NativeFileUpload): Promise<FileMultipart>;
|
|
99
|
+
/** @deprecated Prefer nativeFileMultipart for filenames containing quotes. Kept for source compatibility. */
|
|
97
100
|
export declare function nativeFileForm(upload: NativeFileUpload): Promise<FormData>;
|
|
98
101
|
export declare function nativeExperimentsApi(t: Transport, namespace: string, project: string): {
|
|
99
102
|
status: () => Promise<unknown>;
|
|
@@ -284,5 +287,27 @@ export declare function nativeExperimentsApi(t: Transport, namespace: string, pr
|
|
|
284
287
|
signal?: AbortSignal;
|
|
285
288
|
}) => Promise<Response>;
|
|
286
289
|
};
|
|
290
|
+
writers: {
|
|
291
|
+
list: (query?: {
|
|
292
|
+
limit?: number;
|
|
293
|
+
cursor?: string;
|
|
294
|
+
}) => Promise<unknown>;
|
|
295
|
+
get: (id: string) => Promise<unknown>;
|
|
296
|
+
create: (idempotencyKey: string, runId?: string) => Promise<unknown>;
|
|
297
|
+
rotate: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
|
|
298
|
+
retire: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
|
|
299
|
+
};
|
|
300
|
+
jobs: {
|
|
301
|
+
submit: (input: import("./execution.js").RunInput) => Promise<unknown>;
|
|
302
|
+
list: (query?: {
|
|
303
|
+
limit?: number;
|
|
304
|
+
cursor?: string;
|
|
305
|
+
}) => Promise<unknown>;
|
|
306
|
+
summary: (id: string) => Promise<unknown>;
|
|
307
|
+
cancel: (id: string) => Promise<unknown>;
|
|
308
|
+
logs: (id: string, query?: {
|
|
309
|
+
cursor?: string;
|
|
310
|
+
}) => Promise<unknown>;
|
|
311
|
+
};
|
|
287
312
|
setStatus: (id: string, status: NativeRunStatus) => Promise<unknown>;
|
|
288
313
|
};
|