@dreamlake/dreamlake-cli 0.105.1 → 0.107.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.
@@ -1,5 +1,5 @@
1
1
  import type { Command } from "commander";
2
- type Action = "list" | "create" | "archive" | "restore" | "log" | "trash-list" | "delete" | "trash-restore";
2
+ type Action = "list" | "archive" | "restore" | "log" | "trash-list" | "delete" | "trash-restore";
3
3
  interface Options {
4
4
  namespace: string;
5
5
  project: string;
@@ -7,6 +7,8 @@ interface Options {
7
7
  limit?: string;
8
8
  cursor?: string;
9
9
  level?: string;
10
+ includeArchived?: boolean;
11
+ folder?: string;
10
12
  }
11
13
  export declare function runNativeExperiment(action: Action, opts: Options, subject?: string, message?: string): Promise<number>;
12
14
  export declare function registerNativeExperimentCommands(parent: Command): void;
@@ -1,8 +1,8 @@
1
1
  import { HttpError, requestJson } from "../client.js";
2
2
  import { resolveRemote, resolveToken } from "../config.js";
3
3
  import { emitJson, fail } from "../helpers.js";
4
+ import { registerNativeRunDataCommands, runNativeProject } from "./native-run-data.js";
4
5
  const id = /^[0-9a-f]{24}$/;
5
- const key = /^[A-Za-z0-9_-]{1,128}$/;
6
6
  export async function runNativeExperiment(action, opts, subject, message) {
7
7
  try {
8
8
  const token = resolveToken();
@@ -16,20 +16,17 @@ export async function runNativeExperiment(action, opts, subject, message) {
16
16
  const limit = opts.limit === undefined ? 50 : Number(opts.limit);
17
17
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100 ||
18
18
  opts.limit !== undefined && !/^[1-9][0-9]*$/.test(opts.limit) ||
19
- opts.cursor !== undefined && !id.test(opts.cursor))
20
- throw new Error("Invalid list limit or cursor.");
19
+ opts.cursor !== undefined && !id.test(opts.cursor) ||
20
+ opts.folder !== undefined && opts.folder !== "root" && !id.test(opts.folder))
21
+ throw new Error("Invalid list limit, cursor or folder.");
21
22
  emitJson(await requestJson(remote, `${base}/${action === "trash-list" ? "trash" : "runs"}`, { token, query: { limit,
22
- ...(opts.cursor ? { cursor: opts.cursor } : {}) }, redirect: "error" }));
23
+ ...(opts.cursor ? { cursor: opts.cursor } : {}), ...(action === "list" && opts.includeArchived ? { includeArchived: "true" } : {}),
24
+ ...(action === "list" && opts.folder !== undefined ? { folderId: opts.folder } : {}) }, redirect: "error" }));
23
25
  return 0;
24
26
  }
25
- if (!subject || !(action === "create" ? key : id).test(subject))
26
- throw new Error(action === "create"
27
- ? "Run key must contain 1-128 letters, digits, underscores or hyphens."
28
- : "Run ID must be a DreamLake native Experiment ID.");
29
- if (action === "create") {
30
- emitJson(await requestJson(remote, `${base}/runs/${encodeURIComponent(subject)}`, { token, method: "PUT", redirect: "error" }));
31
- }
32
- else if (action === "delete" || action === "trash-restore") {
27
+ if (!subject || !id.test(subject))
28
+ throw new Error("Run ID must be a DreamLake native Experiment ID.");
29
+ if (action === "delete" || action === "trash-restore") {
33
30
  emitJson(await requestJson(remote, `${base}/runs/${subject}${action === "trash-restore" ? "/restore" : ""}`, {
34
31
  token, method: action === "delete" ? "DELETE" : "POST", redirect: "error"
35
32
  }));
@@ -63,11 +60,20 @@ export function registerNativeExperimentCommands(parent) {
63
60
  .requiredOption("--project <slug>", "DreamLake project")
64
61
  .option("--json", "emit structured errors (success is JSON)");
65
62
  common(runs.command("list").description("list active native runs"))
63
+ .option("--include-archived", "also list archived runs")
64
+ .option("--folder <folder-id|root>", "only the runs in this folder")
66
65
  .option("--limit <count>", "page size, 1-100")
67
66
  .option("--cursor <id>", "nextCursor from the previous page")
68
67
  .action(async (opts) => { process.exitCode = await runNativeExperiment("list", opts); });
69
- common(runs.command("create").description("create an idempotent native run by key").argument("<key>"))
70
- .action(async (subject, opts) => { process.exitCode = await runNativeExperiment("create", opts, subject); });
68
+ // ml-dash's `Experiment(prefix=...)`: a root key, or `folder/.../name` (folders created as needed), with the run's
69
+ // description, tags, metadata and protection written with it in one transaction.
70
+ common(runs.command("create").description("create-or-get a native run by key or folder path").argument("<key-or-path>"))
71
+ .option("--description <text>", "run description")
72
+ .option("--tags <list>", "comma-separated run tags")
73
+ .option("--metadata <file|->", "run metadata: a JSON object from a file or stdin")
74
+ .option("--write-protected", "create the run write-protected (a person's action; never unprotects an existing run)")
75
+ .option("--bindrs <names>", "comma-separated bindr names to attach the run to (created if missing)")
76
+ .action(async (subject, opts) => { process.exitCode = await runNativeProject("create", opts, [subject]); });
71
77
  for (const action of ["archive", "restore"])
72
78
  common(runs.command(action).description(`${action} a native run`).argument("<run-id>"))
73
79
  .action(async (subject, opts) => { process.exitCode = await runNativeExperiment(action, opts, subject); });
@@ -85,4 +91,5 @@ export function registerNativeExperimentCommands(parent) {
85
91
  .action(async (subject, message, opts) => {
86
92
  process.exitCode = await runNativeExperiment("log", opts, subject, message);
87
93
  });
94
+ registerNativeRunDataCommands(runs, common);
88
95
  }
@@ -0,0 +1,51 @@
1
+ import type { Command } from "commander";
2
+ export interface RunDataOptions {
3
+ namespace: string;
4
+ project: string;
5
+ json?: boolean;
6
+ limit?: string;
7
+ cursor?: string;
8
+ data?: string;
9
+ level?: string;
10
+ startTime?: string;
11
+ endTime?: string;
12
+ search?: string;
13
+ orderBy?: string;
14
+ order?: string;
15
+ prefix?: string;
16
+ tags?: string;
17
+ description?: string;
18
+ metadata?: string;
19
+ contentType?: string;
20
+ name?: string;
21
+ out?: string;
22
+ topic?: string;
23
+ format?: string;
24
+ start?: string;
25
+ end?: string;
26
+ columns?: string;
27
+ writeProtected?: boolean;
28
+ folder?: string;
29
+ parent?: string;
30
+ runs?: string;
31
+ folders?: string;
32
+ bindrs?: string;
33
+ bindr?: string;
34
+ bindrId?: string;
35
+ itemKind?: string;
36
+ itemId?: string;
37
+ charts?: string;
38
+ }
39
+ export type RunDataAction = "show" | "update" | "status" | "params-get" | "params-set" | "params-delete" | "metrics-list" | "metrics-rows" | "metrics-append" | "metrics-stats" | "metrics-metadata" | "logs-read" | "logs-append" | "files-list" | "files-get" | "files-upload" | "files-download" | "files-update" | "files-delete" | "tracks-list" | "tracks-create" | "tracks-append" | "tracks-read" | "files-media" | "dashboard" | "bindrs-list" | "bindrs-attach" | "bindrs-detach";
40
+ /** Run one action; success is always JSON on stdout, errors follow `--json`. */
41
+ export declare function runNativeRunData(action: RunDataAction, opts: RunDataOptions, args: string[]): Promise<number>;
42
+ export type NativeProjectAction = "create" | "move" | "protect" | "unprotect" | "purge" | "folders-list" | "folders-create" | "folders-show" | "folders-move" | "folders-resolve" | "folders-operate" | "folders-operation" | "batch" | "pfiles-list" | "pfiles-upload" | "pfiles-show" | "pfiles-text" | "pfiles-download" | "pfiles-media" | "pfiles-replace" | "pfiles-update" | "pfiles-delete";
43
+ /**
44
+ * Runs and folders of the project (protocol 6): create-or-get by key or path, with the run's description, tags,
45
+ * metadata and protection written with it; a person's move/rename, protection and purge; folders and their
46
+ * operations; batch trash/purge. The DreamLake login is the person's: the server refuses people-only actions
47
+ * to any other session, and the CLI has no other.
48
+ */
49
+ export declare function runNativeProject(action: NativeProjectAction, opts: RunDataOptions, args: string[]): Promise<number>;
50
+ /** `experiments runs show|status|params|metrics|logs|files`. */
51
+ export declare function registerNativeRunDataCommands(runs: Command, common: (command: Command) => Command): void;