@dreamlake/dreamlake-cli 0.120.0 → 0.121.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.
@@ -2656,3 +2656,5 @@ export { lineRange, focusedRead, InvalidLineRange } from "./memo-reading.js";
2656
2656
  export type { HostMovePreview, HostMoveRequest, HostMoveReceipt, HostMoveRetainedSessions, HostMoveRetainedRuns } from "./host-moves.js";
2657
2657
  export * from "./project-access.js";
2658
2658
  export * from "./project-audience.js";
2659
+ export { publishSourceVisualization, prepareVisualization, visualizationConfig } from './source-visualization.js';
2660
+ export type { VisualizationFile } from "./source-visualization.js";
package/dist/api/index.js CHANGED
@@ -147,3 +147,4 @@ export * from "./memo-facade.js";
147
147
  export { lineRange, focusedRead, InvalidLineRange } from "./memo-reading.js";
148
148
  export * from "./project-access.js";
149
149
  export * from "./project-audience.js";
150
+ export { publishSourceVisualization, prepareVisualization, visualizationConfig } from './source-visualization.js';
@@ -0,0 +1,31 @@
1
+ export interface VisualizationApi {
2
+ request<T>(method: 'GET' | 'POST', path: string, options?: {
3
+ json?: unknown;
4
+ signal?: AbortSignal;
5
+ }): Promise<T>;
6
+ }
7
+ export interface VisualizationFile {
8
+ path: string;
9
+ bytes: Uint8Array;
10
+ }
11
+ export declare function prepareVisualization(files: readonly VisualizationFile[], entry?: string): {
12
+ files: {
13
+ path: string;
14
+ bytes: Uint8Array<ArrayBuffer>;
15
+ }[];
16
+ prefix: string;
17
+ entry: string;
18
+ };
19
+ export declare function visualizationConfig(text: string, entry: string): string;
20
+ /** Upload a new code generation before publishing the guarded .dreamrc pointer. Never creates an Artifact. */
21
+ export declare function publishSourceVisualization(api: VisualizationApi, namespace: string, sourceId: string, files: readonly VisualizationFile[], options?: {
22
+ entry?: string;
23
+ transport?: typeof fetch;
24
+ signal?: AbortSignal;
25
+ }): Promise<{
26
+ namespace: string;
27
+ sourceId: string;
28
+ entry: string;
29
+ files: number;
30
+ url: string;
31
+ }>;
@@ -0,0 +1,87 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { parseDocument, isMap } from 'yaml';
3
+ import { SourceFileAdapter } from './file-source.js';
4
+ import { FileError, canonicalPath } from './file-workspace.js';
5
+ export function prepareVisualization(files, entry = 'index.html') {
6
+ canonicalPath(entry);
7
+ if (!/\.html?$/.test(entry) || /[%?#]/.test(entry))
8
+ throw new Error('Entry must be a relative HTML path');
9
+ if (!files.length || files.length > 1000)
10
+ throw new Error('Visualization requires 1–1000 files');
11
+ let total = 0;
12
+ const names = new Set();
13
+ // Copy supplied bytes so callers cannot mutate an upload after its digest is computed.
14
+ const snapshot = files.map(file => {
15
+ canonicalPath(file.path);
16
+ if (/[%?#]/.test(file.path) || file.path.startsWith('_dreamlake/') || names.has(file.path) || !(file.bytes instanceof Uint8Array))
17
+ throw new Error('Invalid visualization asset');
18
+ names.add(file.path);
19
+ total += file.bytes.byteLength;
20
+ if (file.bytes.byteLength > 32 * 1024 * 1024 || total > 128 * 1024 * 1024)
21
+ throw new Error('Visualization exceeds asset or bundle limit');
22
+ return { path: file.path, bytes: new Uint8Array(file.bytes) };
23
+ }).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
24
+ if (!names.has(entry))
25
+ throw new Error('Visualization entry is missing');
26
+ const digest = createHash('sha256');
27
+ for (const file of snapshot)
28
+ digest.update(JSON.stringify([file.path, createHash('sha256').update(file.bytes).digest('hex')]));
29
+ return { files: snapshot, prefix: '.dreamlake/visualization/' + digest.digest('hex'), entry };
30
+ }
31
+ export function visualizationConfig(text, entry) {
32
+ const doc = parseDocument(text);
33
+ if (doc.errors.length || (doc.contents !== null && !isMap(doc.contents)))
34
+ throw new Error('Existing .dreamrc must be a YAML mapping');
35
+ doc.set('visualize', { type: 'custom', entry });
36
+ return doc.toString();
37
+ }
38
+ /** Upload a new code generation before publishing the guarded .dreamrc pointer. Never creates an Artifact. */
39
+ export async function publishSourceVisualization(api, namespace, sourceId, files, options = {}) {
40
+ const bundle = prepareVisualization(files, options.entry);
41
+ const signal = options.signal ?? AbortSignal.timeout(120000), transport = options.transport ?? fetch;
42
+ const adapter = new SourceFileAdapter(api, namespace, sourceId, signal, transport);
43
+ const detail = await api.request('GET', adapter.base, { signal });
44
+ if (typeof detail.name !== 'string' || !detail.name)
45
+ throw new Error('Source detail has no name');
46
+ let text = '', revision = null;
47
+ try {
48
+ const baseline = await adapter.read('.dreamrc');
49
+ text = baseline.content;
50
+ revision = baseline.revision;
51
+ }
52
+ catch (e) {
53
+ if (!(e instanceof FileError) || e.code !== 'file_not_found')
54
+ throw e;
55
+ // Do not silently replace external configuration. The caller can materialize it in the managed layer first.
56
+ const page = await api.request('GET', adapter.base + '/landing', { signal });
57
+ if (page.dreamrc.state !== 'absent')
58
+ throw new Error('An external .dreamrc exists or is unavailable. Copy its resolved contents to the managed .dreamrc before publishing.');
59
+ }
60
+ const entry = bundle.prefix + '/' + bundle.entry;
61
+ const content = visualizationConfig(text, entry);
62
+ // Detect unsupported servers before uploading any files.
63
+ await api.request('POST', adapter.base + '/visualization-session', { json: { entry }, signal });
64
+ const plan = await api.request('POST', adapter.base + '/upload-authorizations', { json: {
65
+ targetPrefix: bundle.prefix, files: bundle.files.map(f => ({ relativePath: f.path, size: f.bytes.length })),
66
+ }, signal });
67
+ if (plan.mode !== 's3-presigned-batch' || plan.files?.length !== bundle.files.length)
68
+ throw new Error('Invalid upload plan');
69
+ // Validate every authorization before sending the first byte.
70
+ for (let i = 0; i < bundle.files.length; i++) {
71
+ const f = bundle.files[i], granted = plan.files[i];
72
+ if (granted.relativePath !== f.path || granted.canonicalPath !== bundle.prefix + '/' + f.path || granted.size !== f.bytes.length || granted.transfer?.kind !== 'single-put')
73
+ throw new Error('Invalid asset authorization');
74
+ const url = new URL(granted.transfer.put.url);
75
+ if (url.protocol !== 'https:' || url.username || url.password || Object.keys(granted.transfer.put.headers ?? {}).some(k => /^(authorization|cookie)$/i.test(k)))
76
+ throw new Error('Unsafe upload capability');
77
+ }
78
+ for (let i = 0; i < bundle.files.length; i++) {
79
+ const put = plan.files[i].transfer.put;
80
+ const response = await transport(put.url, { method: 'PUT', headers: put.headers, body: new Uint8Array(bundle.files[i].bytes), redirect: 'error', signal });
81
+ await response.body?.cancel();
82
+ if (!response.ok)
83
+ throw new Error('Visualization upload failed; .dreamrc was not changed');
84
+ }
85
+ await adapter.write('.dreamrc', content, revision);
86
+ return { namespace, sourceId, entry, files: bundle.files.length, url: `https://dreamlake.ai/${encodeURIComponent(namespace)}/sources/${encodeURIComponent(detail.name)}?view=visualize` };
87
+ }
@@ -273,6 +273,7 @@ export const helpExamples = {
273
273
  "source files read": "dl source files read --source my-workspace --prefix workspaces/v1/demo --path scene/manifest.json --json",
274
274
  "source files list": "dl source files list --source my-workspace --prefix workspaces/v1/demo --path '' --json",
275
275
  "source files replace": "dl source files replace --source my-workspace --prefix workspaces/v1/demo --path scene/manifest.json --old-file ./old.txt --new-file ./new.txt --revision '\"etag-from-read\"' --json",
276
+ "source visualization push": "dl source visualization push ./dist --source my-data --namespace my-team",
276
277
  "vault cloud import": "# No --file: list standard candidate paths without opening their contents.\ndl vault cloud import --provider aws -p alice/aws/dev\n# Explicit selections: preview names, sizes and profile metadata, without upload.\ndl vault cloud import --provider aws -p alice/aws/dev \\\n --file \"$HOME/.aws/config\" --file \"$HOME/.aws/credentials\"\n# Repeat the selection with --apply to upload.\ndl vault cloud import --provider aws -p alice/aws/dev \\\n --file \"$HOME/.aws/config\" --file \"$HOME/.aws/credentials\" --apply\ndl vault cloud import --provider gcp -p alice/gcp/dev \\\n --file /private/config/service-account.json --apply",
277
278
  "vault cloud restore": "# Preview checks metadata and destination without retrieving the secret.\ndl vault cloud restore -n alice/aws/dev/credentials \\\n --to '~/.aws/credentials'\n# Write only after explicit --apply; existing files additionally need --overwrite.\ndl vault cloud restore -n alice/aws/dev/credentials \\\n --to '~/.aws/credentials' --apply",
278
279
  "vault add": "# Keep a 90-day registry token for exactly as long as the registry honors it.\npbpaste | dl vault add -p alice -n cli/npm/access-token --stdin --expires-in 90d --env NPM_TOKEN\n# An exact UTC timestamp works the same way.\npbpaste | dl vault add -p alice -n cli/npm/access-token --stdin --expires-at 2027-01-24T00:00:00Z\n# Replace a value and clear its expiry, pinning the current revision.\npbpaste | dl vault add -p alice -n cli/npm/access-token --stdin --if-match 2 --no-expiry",
@@ -1,3 +1,4 @@
1
+ import { registerSourceVisualization } from './visualization.js';
1
2
  import { registerSourceFiles } from "./files.js";
2
3
  import { collectionList } from "../collection-list.js";
3
4
  // `dl source ...` — read data out of connected sources (S3 and Hugging
@@ -1338,6 +1339,7 @@ export function registerSourceCommand(program) {
1338
1339
  .option("-o, --output <dir>", "output directory (default: current directory)")
1339
1340
  .option("-r, --recursive", "download every file under <path>")
1340
1341
  .action(async (pathArg, opts) => process.exit(await runSourceDownload(pathArg, opts)));
1342
+ registerSourceVisualization(source);
1341
1343
  registerSourceFiles(source);
1342
1344
  registerSourceWriteCommands(source);
1343
1345
  registerSourceUploadCommand(source);
@@ -0,0 +1,9 @@
1
+ /** Local filesystem preparation belongs to the CLI, not the transport-only SDK. */
2
+ export declare function collectVisualization(directory: string, entry?: string): Promise<{
3
+ files: {
4
+ path: string;
5
+ bytes: Uint8Array<ArrayBuffer>;
6
+ }[];
7
+ prefix: string;
8
+ entry: string;
9
+ }>;
@@ -0,0 +1,31 @@
1
+ import { lstat, readdir, readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { prepareVisualization } from '../../api/source-visualization.js';
4
+ /** Local filesystem preparation belongs to the CLI, not the transport-only SDK. */
5
+ export async function collectVisualization(directory, entry = 'index.html') {
6
+ const files = [];
7
+ let total = 0;
8
+ async function walk(relative) {
9
+ const full = join(directory, relative), info = await lstat(full);
10
+ if (info.isSymbolicLink())
11
+ throw new Error('Visualization symlinks are not supported');
12
+ if (info.isDirectory()) {
13
+ for (const name of (await readdir(full)).sort())
14
+ await walk(relative ? relative + '/' + name : name);
15
+ return;
16
+ }
17
+ if (!info.isFile())
18
+ throw new Error('Visualization must contain regular files');
19
+ if (info.size > 32 * 1024 * 1024 || files.length >= 1000 || info.size + total > 128 * 1024 * 1024)
20
+ throw new Error('Visualization exceeds asset, bundle, or file count limit');
21
+ const bytes = await readFile(full);
22
+ total += bytes.length;
23
+ if (bytes.length > 32 * 1024 * 1024 || total > 128 * 1024 * 1024)
24
+ throw new Error('Visualization changed while reading');
25
+ files.push({ path: relative, bytes });
26
+ }
27
+ if (!(await lstat(directory)).isDirectory())
28
+ throw new Error('Supply a static build directory');
29
+ await walk('');
30
+ return prepareVisualization(files, entry);
31
+ }
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerSourceVisualization(source: Command): void;
@@ -0,0 +1,31 @@
1
+ import { collectVisualization } from './visualization-files.js';
2
+ import { publishSourceVisualization } from '../../api/source-visualization.js';
3
+ import { requestJson } from '../client.js';
4
+ import { emitJson, fail } from '../helpers.js';
5
+ import { ctx, resolveSource } from './index.js';
6
+ export function registerSourceVisualization(source) {
7
+ source.command('visualization').description('publish Source-owned custom visualization code').command('push')
8
+ .argument('<directory>', 'static build directory; build with relative asset URLs')
9
+ .requiredOption('--source <name>', 'Source name').option('--namespace <slug>', 'namespace')
10
+ .option('--entry <path>', 'HTML entry relative to the build directory', 'index.html').option('--json', 'emit JSON')
11
+ .action(async (directory, options) => {
12
+ try {
13
+ const c = await ctx(options.namespace);
14
+ if (!c) {
15
+ process.exitCode = 1;
16
+ return;
17
+ }
18
+ const source = await resolveSource(c, options.source);
19
+ const bundle = await collectVisualization(directory, options.entry);
20
+ const result = await publishSourceVisualization({ request: (method, path, opts = {}) => requestJson(c.remote, path, { ...opts, method, token: c.token }) }, c.ns, source.id, bundle.files, { entry: options.entry });
21
+ if (options.json)
22
+ emitJson(result);
23
+ else
24
+ process.stdout.write(`Published ${result.files} files\n${result.url}\n`);
25
+ }
26
+ catch (e) {
27
+ process.exitCode = 1;
28
+ fail(e instanceof Error ? e.message : 'Visualization publication failed');
29
+ }
30
+ });
31
+ }
@@ -1 +1 @@
1
- export declare const VERSION = "0.120.0";
1
+ export declare const VERSION = "0.121.0";
@@ -6,4 +6,4 @@
6
6
  // value means a binary that re-installs the same version forever.
7
7
  //
8
8
  // Editing this by hand does nothing for a release; bump package.json.
9
- export const VERSION = "0.120.0";
9
+ export const VERSION = "0.121.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamlake/dreamlake-cli",
3
- "version": "0.120.0",
3
+ "version": "0.121.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dreamlake-ai/dreamlake-cli.git"
@@ -37,13 +37,13 @@
37
37
  "node": ">=18"
38
38
  },
39
39
  "optionalDependencies": {
40
- "@dreamlake/dreamlake-cli-darwin-arm64": "0.120.0",
41
- "@dreamlake/dreamlake-cli-darwin-x64": "0.120.0",
42
- "@dreamlake/dreamlake-cli-linux-x64": "0.120.0",
43
- "@dreamlake/dreamlake-cli-linux-arm64": "0.120.0",
44
- "@dreamlake/dreamlake-cli-linux-x64-musl": "0.120.0",
45
- "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.120.0",
46
- "@dreamlake/dreamlake-cli-win32-x64": "0.120.0",
47
- "@dreamlake/dreamlake-cli-win32-arm64": "0.120.0"
40
+ "@dreamlake/dreamlake-cli-darwin-arm64": "0.121.0",
41
+ "@dreamlake/dreamlake-cli-darwin-x64": "0.121.0",
42
+ "@dreamlake/dreamlake-cli-linux-x64": "0.121.0",
43
+ "@dreamlake/dreamlake-cli-linux-arm64": "0.121.0",
44
+ "@dreamlake/dreamlake-cli-linux-x64-musl": "0.121.0",
45
+ "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.121.0",
46
+ "@dreamlake/dreamlake-cli-win32-x64": "0.121.0",
47
+ "@dreamlake/dreamlake-cli-win32-arm64": "0.121.0"
48
48
  }
49
49
  }