@dreamlake/dreamlake-cli 0.117.0 → 0.118.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/dist/api/file-multipart.d.ts +6 -0
- package/dist/api/file-multipart.js +11 -0
- package/dist/api/index.d.ts +44 -0
- package/dist/api/native-experiments.d.ts +25 -0
- package/dist/api/native-experiments.js +49 -3
- 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 +12 -0
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
/** Native transfer adapter; source algorithms ported from ml-dash-cli 0.4.1 (MIT). */
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { createWriteStream, existsSync, linkSync, openAsBlob, renameSync, statSync, unlinkSync, readFileSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { Readable, Transform } from 'node:stream';
|
|
6
|
+
import { pipeline } from 'node:stream/promises';
|
|
7
|
+
import { bold, green, red, yellow } from './util/ansi.js';
|
|
8
|
+
import { fnmatch, hasWildcard } from './util/glob.js';
|
|
9
|
+
import { context, ManagementError } from './context.js';
|
|
10
|
+
import { call, isNativeMetricName, json, nativeError, validName } from './transport.js';
|
|
11
|
+
import { fileMultipart } from '../../../api/file-multipart.js';
|
|
12
|
+
const RUN_KEY = /^[A-Za-z0-9_-]{1,128}$/;
|
|
13
|
+
const LEVELS = ['info', 'warn', 'error', 'debug', 'fatal'];
|
|
14
|
+
/** Native per-request limits; larger --batch-size values are split, never truncated. */
|
|
15
|
+
const MAX_BATCH = 1000;
|
|
16
|
+
const runsBase = (ns, project) => `/native-experiments/ns/${encodeURIComponent(ns)}/projects/${encodeURIComponent(project)}`;
|
|
17
|
+
const chunks = (items, size) => Array.from({ length: Math.ceil(items.length / size) }, (_, i) => items.slice(i * size, (i + 1) * size));
|
|
18
|
+
function refuse(args, names, why) {
|
|
19
|
+
const given = names.find(k => args[k] !== undefined && args[k] !== false);
|
|
20
|
+
if (given)
|
|
21
|
+
throw nativeError('NATIVE_OPTION_UNSUPPORTED', `--${given.replace(/_/g, '-')} is not supported for native experiments.`, why);
|
|
22
|
+
}
|
|
23
|
+
function nativeContext(args) {
|
|
24
|
+
refuse(args, ['dash_url'], 'Native mode uses the DreamLake login and server; remove --dash-url.');
|
|
25
|
+
return context(args);
|
|
26
|
+
}
|
|
27
|
+
/** `ns/project/<run path>[/topic…]` split into namespace, project and the remaining path segments. */
|
|
28
|
+
function trackTarget(raw, minParts, usage) {
|
|
29
|
+
const parts = raw.replace(/^\/+|\/+$/g, '').split('/');
|
|
30
|
+
if (parts.length < minParts || parts.some(p => !p))
|
|
31
|
+
throw nativeError('NATIVE_INVALID_PATH', `Path must be ${usage}.`, 'Give namespace/project, the run (with its folders) and, for track data, the topic.');
|
|
32
|
+
return { namespace: parts[0], project: parts[1], segments: parts.slice(2) };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The run a track path names, and the topic after it. With native folders every split point is
|
|
36
|
+
* looked up by path (as the old CLI tried each split); a path that names more than one run is
|
|
37
|
+
* reported as ambiguous instead of picking one. Without folders the run is the third segment.
|
|
38
|
+
*/
|
|
39
|
+
async function resolveTrackRun(c, ns, project, segments, topicRequired) {
|
|
40
|
+
const base = runsBase(ns, project);
|
|
41
|
+
const caps = (await json(c, `${base}/status`)).capabilities ?? [];
|
|
42
|
+
if (!caps.includes('run-paths')) {
|
|
43
|
+
if (!RUN_KEY.test(segments[0]))
|
|
44
|
+
throw nativeError('NATIVE_INVALID_RUN_KEY', `'${segments[0]}' is not a native run key.`, 'Run keys contain 1-128 letters, digits, underscores or hyphens.');
|
|
45
|
+
if (!topicRequired && segments.length > 1)
|
|
46
|
+
throw nativeError('NATIVE_INVALID_PATH', 'This server has no native folders: give namespace/project/run.', 'Pass the topic with --topic-filter.');
|
|
47
|
+
return { run: await runByKey(c, ns, project, segments[0]), topic: segments.slice(1).join('/') };
|
|
48
|
+
}
|
|
49
|
+
const found = [];
|
|
50
|
+
const last = topicRequired ? segments.length - 1 : segments.length;
|
|
51
|
+
for (let k = topicRequired ? 1 : last; k <= last; k++) {
|
|
52
|
+
const at = segments.slice(0, k);
|
|
53
|
+
if (!at.every(validName))
|
|
54
|
+
continue;
|
|
55
|
+
try {
|
|
56
|
+
const value = await json(c, `${base}/by-path/${at.map(encodeURIComponent).join('/')}`);
|
|
57
|
+
if (value.kind === 'run')
|
|
58
|
+
found.push({ run: value.experiment, topic: segments.slice(k).join('/'), at: at.join('/') });
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
if (!has(e, 'NATIVE_HTTP_404') && !has(e, 'NATIVE_PATH_NOT_FOUND'))
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!found.length)
|
|
66
|
+
throw nativeError('NATIVE_RUN_NOT_FOUND', `No run found at ${ns}/${project}/${segments.join('/')}.`, 'Check the run path (folders and name).');
|
|
67
|
+
if (found.length > 1)
|
|
68
|
+
throw nativeError('NATIVE_PATH_AMBIGUOUS', `The path names more than one run: ${found.map(f => `${f.at} (topic ${f.topic})`).join(', ')}.`, 'Rename the run or folder so that the run and the topic can be told apart.');
|
|
69
|
+
return { run: found[0].run, topic: found[0].topic };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Runs of a project (archived included), page by page until the server reports no next page.
|
|
73
|
+
* `stop` ends the scan early. A repeated cursor is a server paging fault and stops it.
|
|
74
|
+
*/
|
|
75
|
+
async function eachRun(c, ns, project, stop = () => false) {
|
|
76
|
+
const runs = [];
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
for (let cursor = null;;) {
|
|
79
|
+
const value = await json(c, `${runsBase(ns, project)}/runs?limit=100&includeArchived=true${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''}`);
|
|
80
|
+
if (!Array.isArray(value.runs))
|
|
81
|
+
throw nativeError('NATIVE_INVALID_RESPONSE', 'Invalid run list.', 'Check matching server versions.');
|
|
82
|
+
for (const run of value.runs) {
|
|
83
|
+
runs.push(run);
|
|
84
|
+
if (stop(run))
|
|
85
|
+
return runs;
|
|
86
|
+
}
|
|
87
|
+
if (!value.nextCursor)
|
|
88
|
+
return runs;
|
|
89
|
+
if (typeof value.nextCursor !== 'string' || seen.has(value.nextCursor))
|
|
90
|
+
throw nativeError('NATIVE_CURSOR_LOOP', 'The server repeated a run cursor.', 'Retry after the server paging issue is resolved.');
|
|
91
|
+
seen.add(value.nextCursor);
|
|
92
|
+
cursor = value.nextCursor;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** The run with this key, without creating one (the old CLI required an existing experiment). Keys are unique per project. */
|
|
96
|
+
async function runByKey(c, ns, project, key) {
|
|
97
|
+
const found = (await eachRun(c, ns, project, run => run.name === key)).find(run => run.name === key);
|
|
98
|
+
if (!found)
|
|
99
|
+
throw nativeError('NATIVE_RUN_NOT_FOUND', `Run '${key}' was not found in ${ns}/${project}.`, 'Create it with dl experiments runs create, or check the key.');
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
102
|
+
/** Stream a response into `output` through a sibling temp file; `replace` keeps the old CLI's overwrite. */
|
|
103
|
+
async function saveResponse(response, output, replace) {
|
|
104
|
+
if (!response.body)
|
|
105
|
+
throw nativeError('NATIVE_INVALID_RESPONSE', 'Empty response body.', 'Retry the download.');
|
|
106
|
+
const temp = path.join(path.dirname(output), `.DreamLake-download-${process.pid}-${randomUUID()}`);
|
|
107
|
+
const hash = createHash('sha256');
|
|
108
|
+
let bytes = 0;
|
|
109
|
+
try {
|
|
110
|
+
await pipeline(Readable.fromWeb(response.body), new Transform({ transform(chunk, _e, done) { hash.update(chunk); bytes += chunk.length; done(null, chunk); } }), createWriteStream(temp, { flags: 'wx', mode: 0o600 }));
|
|
111
|
+
if (statSync(temp).size !== bytes)
|
|
112
|
+
throw nativeError('NATIVE_WRITE_INCOMPLETE', 'The download was not fully written.', 'Retry the download.');
|
|
113
|
+
if (replace)
|
|
114
|
+
renameSync(temp, output);
|
|
115
|
+
else
|
|
116
|
+
linkSync(temp, output);
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
try {
|
|
120
|
+
unlinkSync(temp);
|
|
121
|
+
}
|
|
122
|
+
catch { /* renamed or never created */ }
|
|
123
|
+
}
|
|
124
|
+
return { bytes, checksum: hash.digest('hex') };
|
|
125
|
+
}
|
|
126
|
+
// ── canonical DreamLake projects ────────────────────────────────────────────
|
|
127
|
+
const projectRoute = (ns, project) => `/namespaces/${encodeURIComponent(ns)}/projects/${encodeURIComponent(project)}`;
|
|
128
|
+
/** The caller's personal namespace (what the old CLI's `me.username` named). */
|
|
129
|
+
async function personalNamespace(c) {
|
|
130
|
+
const me = await json(c, '/auth/me');
|
|
131
|
+
const slug = me.namespace?.slug ?? me.user?.namespace?.slug;
|
|
132
|
+
if (typeof slug !== 'string' || !slug)
|
|
133
|
+
throw nativeError('NATIVE_NAMESPACE_UNKNOWN', 'Your DreamLake account has no personal namespace.', 'Pass namespace/project explicitly.');
|
|
134
|
+
return slug;
|
|
135
|
+
}
|
|
136
|
+
const has = (e, code) => e instanceof ManagementError && e.code === code;
|
|
137
|
+
/**
|
|
138
|
+
* Make sure a canonical DreamLake project exists, creating it PRIVATE when it does not, as the old
|
|
139
|
+
* uploader's upsert did. A readable project is used as is; a slug held by a project the caller cannot
|
|
140
|
+
* see is reported, never taken over; a missing namespace is never created. Auth, network and other
|
|
141
|
+
* errors propagate unchanged, so only a real "not found" leads to a create.
|
|
142
|
+
*/
|
|
143
|
+
export async function ensureProject(c, ns, project, description) {
|
|
144
|
+
try {
|
|
145
|
+
return { created: false, project: await json(c, projectRoute(ns, project)) };
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
if (!has(e, 'NATIVE_HTTP_404'))
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const created = await json(c, `/namespaces/${encodeURIComponent(ns)}/projects`, 'POST', { name: project, slug: project, visibility: 'private', ...(description !== undefined ? { description } : {}) });
|
|
153
|
+
return { created: true, project: created };
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
if (has(e, 'NATIVE_HTTP_409')) {
|
|
157
|
+
// Created meanwhile by someone whose project we can read is fine; a hidden one is not ours to use.
|
|
158
|
+
try {
|
|
159
|
+
return { created: false, project: await json(c, projectRoute(ns, project)) };
|
|
160
|
+
}
|
|
161
|
+
catch (again) {
|
|
162
|
+
if (!has(again, 'NATIVE_HTTP_404'))
|
|
163
|
+
throw again;
|
|
164
|
+
}
|
|
165
|
+
throw nativeError('NATIVE_PROJECT_INACCESSIBLE', `Project '${ns}/${project}' exists but you cannot access it.`, 'Ask its owner for access, or choose another project name. Nothing was created.');
|
|
166
|
+
}
|
|
167
|
+
if (has(e, 'NATIVE_HTTP_404'))
|
|
168
|
+
throw nativeError('NATIVE_NAMESPACE_NOT_FOUND', `Namespace '${ns}' does not exist.`, 'Namespaces and organizations are not created automatically; check the name.');
|
|
169
|
+
if (has(e, 'NATIVE_HTTP_403'))
|
|
170
|
+
throw nativeError('NATIVE_PROJECT_CREATE_FORBIDDEN', `You cannot create projects in '${ns}'.`, 'Ask a namespace owner for project create permission, or create the project there first.');
|
|
171
|
+
throw e;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// ── upload adapter ──────────────────────────────────────────────────────────
|
|
175
|
+
export { validName };
|
|
176
|
+
/** `namespace/project/folders…/run`; a legacy two-part `project/run` is in the personal namespace (the old CLI's default). */
|
|
177
|
+
function parsePrefix(prefix, personal) {
|
|
178
|
+
const parts = prefix.replace(/^\/+|\/+$/g, '').split('/');
|
|
179
|
+
if (parts.some(p => !p) || parts.length < 2)
|
|
180
|
+
return null;
|
|
181
|
+
const full = parts.length === 2 ? (personal ? [personal, ...parts] : null) : parts;
|
|
182
|
+
if (!full)
|
|
183
|
+
return null;
|
|
184
|
+
return { ns: full[0], project: full[1], folders: full.slice(2, -1), name: full[full.length - 1] };
|
|
185
|
+
}
|
|
186
|
+
const segmentsPath = (segments) => segments.map(encodeURIComponent).join('/');
|
|
187
|
+
/** RemoteClient's upload surface over native REST. Run IDs map to their project route. */
|
|
188
|
+
class NativeUploadClient {
|
|
189
|
+
c;
|
|
190
|
+
bases = new Map();
|
|
191
|
+
/** Capabilities per `namespace/project`, read in the preflight (after the project exists). */
|
|
192
|
+
caps = new Map();
|
|
193
|
+
personal = null;
|
|
194
|
+
constructor(c) {
|
|
195
|
+
this.c = c;
|
|
196
|
+
}
|
|
197
|
+
run(id) {
|
|
198
|
+
const base = this.bases.get(id);
|
|
199
|
+
if (!base)
|
|
200
|
+
throw new Error(`unknown native run ${id}`);
|
|
201
|
+
return `${base}/runs/${id}`;
|
|
202
|
+
}
|
|
203
|
+
async createOrUpdateExperiment(args) {
|
|
204
|
+
const target = parsePrefix(args.prefix ?? '', this.personal);
|
|
205
|
+
// The prefix is the run's DreamLake location (checked against --target or the declared prefix in the preflight).
|
|
206
|
+
if (!target || target.name !== args.name)
|
|
207
|
+
throw new Error(`prefix '${args.prefix}' does not name run '${args.name}'`);
|
|
208
|
+
// Protection is applied by protectExperiment once every part is written: a protected run takes no data.
|
|
209
|
+
const caps = this.caps.get(`${target.ns}/${target.project}`) ?? [];
|
|
210
|
+
const body = {};
|
|
211
|
+
const bindrs = args.bindrs ?? [];
|
|
212
|
+
// A string clears or sets ('' clears); null means "not recorded" and leaves the run as it is.
|
|
213
|
+
if (typeof args.description === 'string')
|
|
214
|
+
body.description = args.description;
|
|
215
|
+
if (Array.isArray(args.tags))
|
|
216
|
+
body.tags = args.tags;
|
|
217
|
+
if (args.metadata && Object.keys(args.metadata).length)
|
|
218
|
+
body.metadata = args.metadata;
|
|
219
|
+
if (bindrs.length)
|
|
220
|
+
body.bindrs = bindrs;
|
|
221
|
+
const base = runsBase(target.ns, target.project);
|
|
222
|
+
const value = caps.includes('run-paths')
|
|
223
|
+
? await json(this.c, `${base}/run-paths/${segmentsPath([...target.folders, target.name])}`, 'PUT', body)
|
|
224
|
+
: await json(this.c, `${base}/runs/${encodeURIComponent(target.name)}`, 'PUT', body);
|
|
225
|
+
this.bases.set(String(value.experiment?.id), base);
|
|
226
|
+
// The run's bindrs are found or created and attached with the create; a name missing from the answer is a failed run.
|
|
227
|
+
const attached = new Set(Array.isArray(value.bindrs) ? value.bindrs.map((b) => b?.name) : []);
|
|
228
|
+
const missing = [...new Set(bindrs.map(name => name.trim()))].filter(name => !attached.has(name));
|
|
229
|
+
if (missing.length)
|
|
230
|
+
throw new Error(`the server did not confirm the run's bindrs ${JSON.stringify(missing)}`);
|
|
231
|
+
return value;
|
|
232
|
+
}
|
|
233
|
+
/** `write_protected`: a person's protection, set last (PATCH `writeProtected: true`), after all data was written. */
|
|
234
|
+
async protectExperiment(id) {
|
|
235
|
+
const value = await json(this.c, this.run(id), 'PATCH', { writeProtected: true });
|
|
236
|
+
if (value.experiment?.writeProtected !== true)
|
|
237
|
+
throw new Error('the server did not confirm the run\'s write protection');
|
|
238
|
+
}
|
|
239
|
+
async setParameters(id, data) {
|
|
240
|
+
return json(this.c, `${this.run(id)}/parameters`, 'POST', { data });
|
|
241
|
+
}
|
|
242
|
+
async createLogEntries(id, logs) {
|
|
243
|
+
for (const batch of chunks(logs, MAX_BATCH))
|
|
244
|
+
await json(this.c, `${this.run(id)}/logs`, 'POST', { entries: batch });
|
|
245
|
+
return { count: logs.length };
|
|
246
|
+
}
|
|
247
|
+
async appendBatchToMetric(id, name, points) {
|
|
248
|
+
for (const batch of chunks(points, MAX_BATCH))
|
|
249
|
+
await json(this.c, `${this.run(id)}/metrics/${encodeURIComponent(name)}`, 'POST', { dataPoints: batch });
|
|
250
|
+
return { count: points.length };
|
|
251
|
+
}
|
|
252
|
+
async uploadFile(args) {
|
|
253
|
+
const blob = await openAsBlob(args.filePath, { type: args.contentType || 'application/octet-stream' });
|
|
254
|
+
const hash = createHash('sha256');
|
|
255
|
+
for await (const chunk of blob.stream())
|
|
256
|
+
hash.update(chunk);
|
|
257
|
+
const fields = { sizeBytes: String(blob.size), checksum: hash.digest('hex'),
|
|
258
|
+
prefix: '/' + (args.prefix ?? '').replace(/^\/+/, '') };
|
|
259
|
+
if (args.description)
|
|
260
|
+
fields.description = args.description;
|
|
261
|
+
if (args.tags?.length)
|
|
262
|
+
fields.tags = args.tags.join(',');
|
|
263
|
+
if (args.metadata)
|
|
264
|
+
fields.metadata = JSON.stringify(args.metadata);
|
|
265
|
+
const form = fileMultipart(fields, blob, args.filename);
|
|
266
|
+
const value = await json(this.c, `${this.run(args.experimentId)}/files`, 'POST', undefined, form);
|
|
267
|
+
// The file's bindrs go on the file just stored, by its new id; a failed attach fails the file (and the run).
|
|
268
|
+
if (args.bindrs?.length) {
|
|
269
|
+
const id = value.id ?? value.file?.id;
|
|
270
|
+
if (typeof id !== 'string' || !/^[0-9a-f]{24}$/.test(id))
|
|
271
|
+
throw new Error('the server returned no file id to attach its bindrs to');
|
|
272
|
+
for (const name of new Set(args.bindrs.map(b => b.trim()))) {
|
|
273
|
+
const done = await json(this.c, `${this.run(args.experimentId)}/bindrs`, 'POST', { name, item: { kind: 'file', id } });
|
|
274
|
+
if (done.bindr?.name !== name)
|
|
275
|
+
throw new Error(`the server did not confirm bindr '${name}' on file ${args.filename}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return value;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Every reason an experiment would reach native storage incompletely, for all experiments, before
|
|
283
|
+
* any run data is written. Static checks first; then each target project is made to exist (created
|
|
284
|
+
* private where allowed, as the old uploader did) so its capabilities can be read; then folders,
|
|
285
|
+
* names and run metadata are checked against them. A refusal there can leave a new empty project.
|
|
286
|
+
*/
|
|
287
|
+
async function preflight(client, storage, items, skipLogs, skipMetrics) {
|
|
288
|
+
const problems = [];
|
|
289
|
+
if (items.some(i => i.fullPrefix.replace(/^\/+|\/+$/g, '').split('/').length === 2))
|
|
290
|
+
client.personal = await personalNamespace(client.c);
|
|
291
|
+
const targets = new Map();
|
|
292
|
+
const wants = { bindrs: [], protection: [] };
|
|
293
|
+
const needs = [];
|
|
294
|
+
for (const { info, validation, fullPrefix, targetProject } of items) {
|
|
295
|
+
const name = `${info.project}/${info.experiment}`;
|
|
296
|
+
const target = parsePrefix(fullPrefix, client.personal);
|
|
297
|
+
if (!target) {
|
|
298
|
+
problems.push(`${name}: '${fullPrefix}' is not namespace/project/[folders/]run.`);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
// From --target or a declared prefix, the project and run must agree with it. From the storage path alone,
|
|
302
|
+
// the path is the location (its second segment is the project; deeper segments are folders).
|
|
303
|
+
const fromStorage = !info.declaredPrefix && fullPrefix === info.storagePrefix;
|
|
304
|
+
if (target.name !== info.experiment || !fromStorage && target.project !== targetProject)
|
|
305
|
+
problems.push(`${name}: prefix '${fullPrefix}' does not name project '${targetProject}' and run '${info.experiment}'.`);
|
|
306
|
+
for (const segment of [...target.folders, target.name])
|
|
307
|
+
if (!validName(segment))
|
|
308
|
+
problems.push(`${name}: '${segment}' is not a valid native folder or run name.`);
|
|
309
|
+
const meta = validation.metadata ?? {};
|
|
310
|
+
const runBindrs = Array.isArray(meta.bindrs) ? meta.bindrs : [];
|
|
311
|
+
let fileBindrs = false;
|
|
312
|
+
try {
|
|
313
|
+
fileBindrs = storage.listFiles(info.storagePrefix).some(f => (f.bindrs ?? []).length > 0);
|
|
314
|
+
}
|
|
315
|
+
catch { /* reported by the file upload */ }
|
|
316
|
+
for (const b of runBindrs)
|
|
317
|
+
if (typeof b !== 'string' || !b.trim() || b.trim().length > 120)
|
|
318
|
+
problems.push(`${name}: bindr ${JSON.stringify(b)} is not a valid name (1-120 characters).`);
|
|
319
|
+
if (new Set(runBindrs.map((b) => String(b).trim())).size > 32)
|
|
320
|
+
problems.push(`${name}: a run takes at most 32 bindrs.`);
|
|
321
|
+
if (runBindrs.length || fileBindrs)
|
|
322
|
+
wants.bindrs.push(name);
|
|
323
|
+
if (meta.write_protected === true)
|
|
324
|
+
wants.protection.push(name);
|
|
325
|
+
if (!skipMetrics)
|
|
326
|
+
for (const metric of info.metrics) {
|
|
327
|
+
if (!isNativeMetricName(metric.name)) {
|
|
328
|
+
problems.push(`${name}: metric '${metric.name}' is not a native metric name (1-256 characters, no '/', not '.' or '..').`);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (storage.readMetricPoints(metric).points.some(p => !p || typeof p !== 'object' || Array.isArray(p)))
|
|
332
|
+
problems.push(`${name}: metric '${metric.name}' has non-object points, which native metrics do not store.`);
|
|
333
|
+
}
|
|
334
|
+
if (!skipLogs && info.hasLogs) {
|
|
335
|
+
let bad = 0;
|
|
336
|
+
// Lines without `message` stay skipped with a warning, as before; uploaded entries need what the native API requires.
|
|
337
|
+
for (const line of readFileSync(path.join(info.dir, 'logs', 'logs.jsonl'), 'utf8').split('\n')) {
|
|
338
|
+
if (!line.trim())
|
|
339
|
+
continue;
|
|
340
|
+
let entry;
|
|
341
|
+
try {
|
|
342
|
+
entry = JSON.parse(line);
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (!entry || typeof entry !== 'object' || !('message' in entry))
|
|
348
|
+
continue;
|
|
349
|
+
if (typeof entry.message !== 'string' || typeof entry.timestamp !== 'string' || !Number.isFinite(Date.parse(entry.timestamp)) ||
|
|
350
|
+
entry.level !== undefined && !LEVELS.includes(entry.level))
|
|
351
|
+
bad++;
|
|
352
|
+
}
|
|
353
|
+
if (bad)
|
|
354
|
+
problems.push(`${name}: ${bad} log entr${bad === 1 ? 'y needs' : 'ies need'} a string message, an ISO timestamp and a native level.`);
|
|
355
|
+
}
|
|
356
|
+
const key = `${target.ns}/${target.project}`;
|
|
357
|
+
targets.set(key, { ns: target.ns, project: target.project });
|
|
358
|
+
needs.push({ name, key, folders: target.folders, runName: target.name,
|
|
359
|
+
metadata: !!(meta.metadata && typeof meta.metadata === 'object' && Object.keys(meta.metadata).length) });
|
|
360
|
+
}
|
|
361
|
+
if (problems.length)
|
|
362
|
+
return problems;
|
|
363
|
+
// Before any project, run or byte is written: the server must list run protection and run bindrs in its operation schema.
|
|
364
|
+
if (wants.bindrs.length || wants.protection.length) {
|
|
365
|
+
const schema = await operationSchema(client.c);
|
|
366
|
+
if (wants.protection.length && !supportsRunProtection(schema))
|
|
367
|
+
problems.push(`write_protected (${wants.protection.join(', ')}) needs a server whose native operation schema lists run protection (runs.update writeProtected); this one does not.`);
|
|
368
|
+
if (wants.bindrs.length && !supportsRunBindrs(schema))
|
|
369
|
+
problems.push(`bindrs (${wants.bindrs.join(', ')}) need a server whose native operation schema lists run bindrs (POST runs/:runId/bindrs); this one does not.`);
|
|
370
|
+
if (problems.length)
|
|
371
|
+
return problems;
|
|
372
|
+
}
|
|
373
|
+
for (const [key, t] of targets) {
|
|
374
|
+
await ensureProject(client.c, t.ns, t.project);
|
|
375
|
+
client.caps.set(key, (await json(client.c, `${runsBase(t.ns, t.project)}/status`)).capabilities ?? []);
|
|
376
|
+
}
|
|
377
|
+
for (const n of needs) {
|
|
378
|
+
const caps = client.caps.get(n.key);
|
|
379
|
+
if (!caps.includes('run-paths')) {
|
|
380
|
+
if (n.folders.length)
|
|
381
|
+
problems.push(`${n.name}: folders (${n.folders.join('/')}) need a server with native folders (run-paths).`);
|
|
382
|
+
else if (!RUN_KEY.test(n.runName))
|
|
383
|
+
problems.push(`${n.name}: the name '${n.runName}' needs a server with native folders (run-paths).`);
|
|
384
|
+
}
|
|
385
|
+
if (n.metadata && !caps.includes('run-metadata-dict') && !caps.includes('run-paths'))
|
|
386
|
+
problems.push(`${n.name}: run metadata needs a newer server (run-metadata-dict).`);
|
|
387
|
+
}
|
|
388
|
+
return problems;
|
|
389
|
+
}
|
|
390
|
+
/** The server's native-1 operation schema (`GET /native-experiments/schema?version=1`), or null when it has none. */
|
|
391
|
+
async function operationSchema(c) {
|
|
392
|
+
try {
|
|
393
|
+
const value = await json(c, '/native-experiments/schema?version=1');
|
|
394
|
+
return value.protocolVersion === 'native-1' && Array.isArray(value.operations) ? value.operations : null;
|
|
395
|
+
}
|
|
396
|
+
catch (e) {
|
|
397
|
+
if (has(e, 'NATIVE_HTTP_404'))
|
|
398
|
+
return null;
|
|
399
|
+
throw e;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const supportsRunProtection = (ops) => !!ops?.some(op => op?.id === 'runs.update' && op.method === 'PATCH' && op.input?.properties?.body?.properties?.writeProtected);
|
|
403
|
+
const supportsRunBindrs = (ops) => !!ops?.some(op => op?.method === 'POST' && typeof op.path === 'string' && /\/runs\/:runId\/bindrs$/.test(op.path));
|
|
404
|
+
/** The upload pipeline's native target: its client, state identity and pre-write check. */
|
|
405
|
+
export function nativeUploadTarget(args) {
|
|
406
|
+
const c = nativeContext(args);
|
|
407
|
+
const client = new NativeUploadClient(c);
|
|
408
|
+
return { client, server: c.url, stateIdentity: `native:${c.url}:target:${String(args.target ?? "declared")}`,
|
|
409
|
+
preflight: (storage, items, skipLogs, skipMetrics) => preflight(client, storage, items, skipLogs, skipMetrics) };
|
|
410
|
+
}
|
|
411
|
+
// ── download adapter ────────────────────────────────────────────────────────
|
|
412
|
+
/** RemoteClient's download surface over native REST, for one DreamLake project. */
|
|
413
|
+
class NativeDownloadClient {
|
|
414
|
+
c;
|
|
415
|
+
fileRuns = new Map();
|
|
416
|
+
bindrSupport = new Map();
|
|
417
|
+
/** The project route of each discovered run: a glob may select runs of several projects. */
|
|
418
|
+
bases = new Map();
|
|
419
|
+
constructor(c) {
|
|
420
|
+
this.c = c;
|
|
421
|
+
}
|
|
422
|
+
run(id) {
|
|
423
|
+
const base = this.bases.get(id);
|
|
424
|
+
if (!base)
|
|
425
|
+
throw new Error(`native run ${id} was not discovered`);
|
|
426
|
+
return `${base}/runs/${encodeURIComponent(id)}`;
|
|
427
|
+
}
|
|
428
|
+
async getParameters(id) {
|
|
429
|
+
try {
|
|
430
|
+
const value = (await json(this.c, `${this.run(id)}/parameters`)).parameters;
|
|
431
|
+
const data = value && typeof value === 'object' && value.data && typeof value.data === 'object' ? value.data : value;
|
|
432
|
+
return data && typeof data === 'object' && !Array.isArray(data) ? data : {};
|
|
433
|
+
}
|
|
434
|
+
catch (e) {
|
|
435
|
+
if (e instanceof ManagementError && (e.code === 'NATIVE_PARAMETERS_NOT_FOUND' || e.code === 'NATIVE_HTTP_404'))
|
|
436
|
+
return {};
|
|
437
|
+
throw e;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async queryLogs(id, opts = {}) {
|
|
441
|
+
const q = new URLSearchParams({ limit: String(Math.min(opts.limit ?? MAX_BATCH, MAX_BATCH)), cursor: String(opts.offset ?? 0) });
|
|
442
|
+
if (opts.orderBy)
|
|
443
|
+
q.set('orderBy', opts.orderBy);
|
|
444
|
+
if (opts.order)
|
|
445
|
+
q.set('order', opts.order);
|
|
446
|
+
const value = await json(this.c, `${this.run(id)}/logs?${q}`);
|
|
447
|
+
return { logs: value.logs ?? [], hasMore: value.hasMore === true };
|
|
448
|
+
}
|
|
449
|
+
async listMetrics(id) { return (await json(this.c, `${this.run(id)}/metrics`)).metrics ?? []; }
|
|
450
|
+
/** Native metrics have no chunk index: the pipeline reads them by index pages instead. */
|
|
451
|
+
async getMetricStats() { throw new Error('native metrics are read by index pages'); }
|
|
452
|
+
async downloadMetricChunk() { throw new Error('native metrics are read by index pages'); }
|
|
453
|
+
async getMetricData(id, name, opts = {}) {
|
|
454
|
+
if (opts.bufferOnly)
|
|
455
|
+
throw new Error('native metrics are read by index pages');
|
|
456
|
+
const q = new URLSearchParams({ limit: String(Math.min(opts.limit ?? MAX_BATCH, MAX_BATCH)), cursor: String(opts.startIndex ?? 0) });
|
|
457
|
+
const value = await json(this.c, `${this.run(id)}/metrics/${encodeURIComponent(name)}?${q}`);
|
|
458
|
+
return { data: (value.rows ?? []).map((row) => ({ data: row })), hasMore: value.nextCursor != null };
|
|
459
|
+
}
|
|
460
|
+
/** Native file listing is one response: the first page holds every file. */
|
|
461
|
+
async listFiles(id, _limit = 500, offset = 0) {
|
|
462
|
+
if (offset > 0)
|
|
463
|
+
return { files: [], hasMore: false };
|
|
464
|
+
const files = (await json(this.c, `${this.run(id)}/files`)).files ?? [];
|
|
465
|
+
for (const f of files)
|
|
466
|
+
this.fileRuns.set(String(f.id), id);
|
|
467
|
+
const out = [];
|
|
468
|
+
for (const f of files)
|
|
469
|
+
out.push({ id: f.id, name: f.filename, pPath: f.prefix ?? f.path ?? '', description: f.description ?? null,
|
|
470
|
+
tags: f.tags ?? [], metadata: f.metadata ?? null,
|
|
471
|
+
bindrs: await this.bindrs(id, 'file', String(f.id)),
|
|
472
|
+
physicalFile: { filename: f.filename, checksum: f.checksum, contentType: f.contentType, sizeBytes: f.sizeBytes } });
|
|
473
|
+
return { files: out, hasMore: false };
|
|
474
|
+
}
|
|
475
|
+
async bindrs(id, itemKind, itemId) {
|
|
476
|
+
const base = this.bases.get(id);
|
|
477
|
+
if (!this.bindrSupport.has(base))
|
|
478
|
+
this.bindrSupport.set(base, json(this.c, `${base}/status`).then(value => (value.capabilities ?? []).includes('run-bindrs')));
|
|
479
|
+
if (!await this.bindrSupport.get(base))
|
|
480
|
+
return [];
|
|
481
|
+
const query = itemKind ? `?itemKind=${encodeURIComponent(itemKind)}&itemId=${encodeURIComponent(itemId)}` : '';
|
|
482
|
+
const value = await json(this.c, `${this.run(id)}/bindrs${query}`);
|
|
483
|
+
if (!Array.isArray(value.bindrs) || value.bindrs.some((b) => typeof b?.name !== 'string'))
|
|
484
|
+
throw nativeError('NATIVE_INVALID_RESPONSE', 'Invalid run Bindr list.', 'Check matching server versions.');
|
|
485
|
+
return value.bindrs.map((b) => b.name);
|
|
486
|
+
}
|
|
487
|
+
async downloadFileStreaming(fileId, destPath) {
|
|
488
|
+
const runId = this.fileRuns.get(fileId);
|
|
489
|
+
if (!runId)
|
|
490
|
+
throw new Error(`file ${fileId} was not listed`);
|
|
491
|
+
const response = await call(this.c, `${this.run(runId)}/files/${encodeURIComponent(fileId)}/download`);
|
|
492
|
+
if (!response.body)
|
|
493
|
+
throw new Error('empty download body');
|
|
494
|
+
await pipeline(Readable.fromWeb(response.body), createWriteStream(destPath));
|
|
495
|
+
return destPath;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/** A run's place under its project: its folder path and name (`path`), or its key at the root. */
|
|
499
|
+
const runPath = (run) => String(run.path ?? run.name);
|
|
500
|
+
/** `-p` beyond namespace/project: a glob over run paths, else an exact run or a folder's whole subtree. */
|
|
501
|
+
function pathSelector(rest) {
|
|
502
|
+
if (!rest)
|
|
503
|
+
return () => true;
|
|
504
|
+
if (hasWildcard(rest))
|
|
505
|
+
return (p) => fnmatch(p, rest);
|
|
506
|
+
return (p) => p === rest || p.startsWith(`${rest}/`);
|
|
507
|
+
}
|
|
508
|
+
function projectSelector(raw, what) {
|
|
509
|
+
const parts = raw.replace(/^\/+|\/+$/g, '').split('/');
|
|
510
|
+
const [ns, project] = parts;
|
|
511
|
+
if (!ns || !project)
|
|
512
|
+
throw nativeError('NATIVE_INVALID_PATH', `--project must be namespace/project[/folder…], ${what}.`, 'Native runs live in a DreamLake project.');
|
|
513
|
+
return { ns, project, rest: parts.slice(2).join('/') || undefined };
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* The canonical projects a `namespace/project` selector names. Exact names are used as given (an
|
|
517
|
+
* unreadable one fails with its own error). A glob fans out over what the caller can read: your
|
|
518
|
+
* personal namespace and your organizations, and each namespace's readable-project catalog, every
|
|
519
|
+
* page. A project you cannot see is never listed, so it is never matched.
|
|
520
|
+
*/
|
|
521
|
+
async function selectedProjects(c, ns, project) {
|
|
522
|
+
let namespaces = [ns];
|
|
523
|
+
if (hasWildcard(ns)) {
|
|
524
|
+
const mine = await personalNamespace(c).catch(() => null);
|
|
525
|
+
const orgs = await json(c, '/graphql', 'POST', { query: 'query MlDashNativeGlobOrgs { myOrganizations { slug } }' });
|
|
526
|
+
const slugs = [...(mine ? [mine] : []), ...(orgs.data?.myOrganizations ?? []).map(o => o.slug)];
|
|
527
|
+
namespaces = [...new Set(slugs)].filter(slug => fnmatch(slug, ns));
|
|
528
|
+
}
|
|
529
|
+
if (!hasWildcard(project))
|
|
530
|
+
return namespaces.map(n => ({ ns: n, project }));
|
|
531
|
+
const out = [];
|
|
532
|
+
for (const n of namespaces) {
|
|
533
|
+
for (let page = 1;; page++) {
|
|
534
|
+
const value = await json(c, `/namespaces/${encodeURIComponent(n)}/projects?page=${page}&pageSize=200`);
|
|
535
|
+
for (const p of value.projects ?? [])
|
|
536
|
+
if (fnmatch(String(p.slug), project))
|
|
537
|
+
out.push({ ns: n, project: String(p.slug) });
|
|
538
|
+
if (!value.projects?.length || !Number.isSafeInteger(Number(value.totalPages)) || page >= Number(value.totalPages))
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return out;
|
|
543
|
+
}
|
|
544
|
+
/** The download pipeline's native source: `-p namespace/project[/folder…|/glob]` (globs anywhere), every page of runs. */
|
|
545
|
+
export function nativeDownloadSource(args) {
|
|
546
|
+
const { ns, project, rest } = projectSelector(String(args.project ?? ''), 'optionally followed by a run, folder or glob');
|
|
547
|
+
const c = nativeContext(args);
|
|
548
|
+
const client = new NativeDownloadClient(c);
|
|
549
|
+
const selected = pathSelector(rest);
|
|
550
|
+
return {
|
|
551
|
+
client,
|
|
552
|
+
stateIdentity: `native:${c.url}:source:${String(args.project)}`,
|
|
553
|
+
async discover(experiment) {
|
|
554
|
+
const found = [];
|
|
555
|
+
for (const target of await selectedProjects(c, ns, project)) {
|
|
556
|
+
const base = runsBase(target.ns, target.project);
|
|
557
|
+
for (const run of await eachRun(c, target.ns, target.project)) {
|
|
558
|
+
if (!selected(runPath(run)) || experiment !== undefined && run.name !== experiment)
|
|
559
|
+
continue;
|
|
560
|
+
client.bases.set(String(run.id), base);
|
|
561
|
+
found.push({ project: target.project, experiment: run.name, experimentId: run.id, owner: target.ns, prefix: `${target.ns}/${target.project}/${runPath(run)}`,
|
|
562
|
+
description: run.description ?? null, tags: run.tags ?? [], metadata: run.metadata ?? null,
|
|
563
|
+
bindrs: await client.bindrs(String(run.id)), writeProtected: run.writeProtected === true,
|
|
564
|
+
metricNames: [], fileCount: 0, status: run.status ?? 'RUNNING', countsUnknown: true });
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return found;
|
|
568
|
+
},
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
export function reportNativeError(e) {
|
|
572
|
+
if (e instanceof ManagementError)
|
|
573
|
+
console.error(`${red('Error:')} ${e.code}: ${e.message}\n${e.remediation}`);
|
|
574
|
+
else
|
|
575
|
+
console.error(`${red('Error:')} The native request did not complete; a write outcome may be unknown.`);
|
|
576
|
+
return 1;
|
|
577
|
+
}
|
|
578
|
+
// ── tracks ──────────────────────────────────────────────────────────────────
|
|
579
|
+
/** `upload --tracks FILE --remote-path ns/project/run/topic --backend native` */
|
|
580
|
+
export async function uploadTrackNative(args) {
|
|
581
|
+
const c = nativeContext(args);
|
|
582
|
+
const t = trackTarget(String(args.remote_path ?? ''), 4, "'namespace/project/run/topic'");
|
|
583
|
+
const local = String(args.tracks);
|
|
584
|
+
if (!existsSync(local))
|
|
585
|
+
throw nativeError('NATIVE_FILE_UNREADABLE', `File not found: ${local}`, 'Choose a readable JSONL file.');
|
|
586
|
+
const { run, topic } = await resolveTrackRun(c, t.namespace, t.project, t.segments, true);
|
|
587
|
+
const entries = [];
|
|
588
|
+
readFileSync(local, 'utf8').split('\n').forEach((line, i) => {
|
|
589
|
+
if (!line.trim())
|
|
590
|
+
return;
|
|
591
|
+
try {
|
|
592
|
+
const entry = JSON.parse(line);
|
|
593
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry) || typeof entry.timestamp !== 'number') {
|
|
594
|
+
console.log(`${yellow('Warning:')} Line ${i + 1} has no numeric timestamp, skipping`);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
entries.push(entry);
|
|
598
|
+
}
|
|
599
|
+
catch (e) {
|
|
600
|
+
console.log(`${yellow('Warning:')} Line ${i + 1} invalid JSON: ${e.message}`);
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
if (!entries.length)
|
|
604
|
+
throw nativeError('NATIVE_TRACK_EMPTY', 'No valid entries found in the file.', 'Each JSONL line needs a numeric timestamp.');
|
|
605
|
+
console.log(bold('Uploading track data (native)...'));
|
|
606
|
+
const route = `${runsBase(t.namespace, t.project)}/runs/${run.id}/tracks/${encodeURIComponent(topic)}/append_batch`;
|
|
607
|
+
let total = 0;
|
|
608
|
+
for (const batch of chunks(entries, 1000)) {
|
|
609
|
+
await json(c, route, 'POST', { entries: batch });
|
|
610
|
+
total += batch.length;
|
|
611
|
+
console.log(` Uploaded ${total}/${entries.length} entries`);
|
|
612
|
+
}
|
|
613
|
+
console.log(`\n${green('✓ Track data uploaded successfully')}\n Total entries: ${total}\n Topic: ${topic}\n Run: ${t.namespace}/${t.project}/${runPath(run)} (${run.id})`);
|
|
614
|
+
return 0;
|
|
615
|
+
}
|
|
616
|
+
/** `download --tracks ns/project/run/topic [--format F] [-o FILE] --backend native` */
|
|
617
|
+
export async function downloadTrackNative(args) {
|
|
618
|
+
const c = nativeContext(args);
|
|
619
|
+
const t = trackTarget(String(args.tracks), 4, "'namespace/project/run/topic'");
|
|
620
|
+
const format = typeof args.format === 'string' ? args.format : 'jsonl';
|
|
621
|
+
const { run, topic: name } = await resolveTrackRun(c, t.namespace, t.project, t.segments, true);
|
|
622
|
+
const output = path.resolve(typeof args.output === 'string' ? args.output : `${name.replace(/\//g, '_')}.${format}`);
|
|
623
|
+
// A trailing '/' in the topic selects every track under it (mcap only), as the server documents.
|
|
624
|
+
const topic = encodeURIComponent(name + (String(args.tracks).endsWith('/') ? '/' : ''));
|
|
625
|
+
const response = await call(c, `${runsBase(t.namespace, t.project)}/runs/${run.id}/tracks/${topic}/data?format=${encodeURIComponent(format)}`);
|
|
626
|
+
const { bytes } = await saveResponse(response, output, true);
|
|
627
|
+
console.log(`${green('✓ Track data downloaded successfully')}\n Output: ${output}\n Size: ${bytes} bytes\n Format: ${format}`);
|
|
628
|
+
return 0;
|
|
629
|
+
}
|
|
630
|
+
export async function runNativeTransfer(work) {
|
|
631
|
+
try {
|
|
632
|
+
return await work();
|
|
633
|
+
}
|
|
634
|
+
catch (e) {
|
|
635
|
+
return reportNativeError(e);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Transport } from '../../../api/client.js';
|
|
2
|
+
import type { ParsedArgs } from './types.js';
|
|
3
|
+
export declare class ManagementError extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly remediation: string;
|
|
6
|
+
readonly retryable: boolean;
|
|
7
|
+
constructor(code: string, message: string, remediation: string, retryable?: boolean);
|
|
8
|
+
}
|
|
9
|
+
export interface Context {
|
|
10
|
+
url: string;
|
|
11
|
+
transport: Transport;
|
|
12
|
+
}
|
|
13
|
+
export declare function context(_args: ParsedArgs): Context;
|