@heyditto/cli 2.4.1 → 2.5.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/README.md +93 -0
- package/dist/agents/launch.d.ts +6 -0
- package/dist/agents/launch.js +13 -1
- package/dist/agents/launch.js.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/teleport/api.d.ts +139 -0
- package/dist/teleport/api.js +61 -0
- package/dist/teleport/api.js.map +1 -0
- package/dist/teleport/bundle.d.ts +35 -0
- package/dist/teleport/bundle.js +102 -0
- package/dist/teleport/bundle.js.map +1 -0
- package/dist/teleport/chunks.d.ts +13 -0
- package/dist/teleport/chunks.js +57 -0
- package/dist/teleport/chunks.js.map +1 -0
- package/dist/teleport/commands.d.ts +76 -0
- package/dist/teleport/commands.js +492 -0
- package/dist/teleport/commands.js.map +1 -0
- package/dist/teleport/discover.d.ts +13 -0
- package/dist/teleport/discover.js +64 -0
- package/dist/teleport/discover.js.map +1 -0
- package/dist/teleport/git.d.ts +18 -0
- package/dist/teleport/git.js +41 -0
- package/dist/teleport/git.js.map +1 -0
- package/dist/teleport/harness.d.ts +29 -0
- package/dist/teleport/harness.js +121 -0
- package/dist/teleport/harness.js.map +1 -0
- package/dist/teleport/offload.d.ts +32 -0
- package/dist/teleport/offload.js +83 -0
- package/dist/teleport/offload.js.map +1 -0
- package/dist/teleport/pull.d.ts +12 -0
- package/dist/teleport/pull.js +118 -0
- package/dist/teleport/pull.js.map +1 -0
- package/dist/teleport/push.d.ts +49 -0
- package/dist/teleport/push.js +261 -0
- package/dist/teleport/push.js.map +1 -0
- package/dist/teleport/restore.d.ts +16 -0
- package/dist/teleport/restore.js +163 -0
- package/dist/teleport/restore.js.map +1 -0
- package/dist/teleport/storage.d.ts +53 -0
- package/dist/teleport/storage.js +43 -0
- package/dist/teleport/storage.js.map +1 -0
- package/dist/teleport/types.d.ts +100 -0
- package/dist/teleport/types.js +85 -0
- package/dist/teleport/types.js.map +1 -0
- package/dist/teleport/worktree.d.ts +28 -0
- package/dist/teleport/worktree.js +120 -0
- package/dist/teleport/worktree.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RepoHead, RepoManifest, RepoRemote } from "./types.js";
|
|
2
|
+
export interface RepoState {
|
|
3
|
+
remotes: RepoRemote[];
|
|
4
|
+
head: RepoHead;
|
|
5
|
+
/** Local branch and tag names (the bundle carries their objects). */
|
|
6
|
+
branches: string[];
|
|
7
|
+
tags: string[];
|
|
8
|
+
stashes: string[];
|
|
9
|
+
/** Branch → "<remote>/<branch>" for branches that track a remote. */
|
|
10
|
+
branchUpstreams: Record<string, string>;
|
|
11
|
+
/** "<remote>/<branch>" → remote-tracking ref sha, for every upstream referenced above or by HEAD. */
|
|
12
|
+
upstreamTips: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
/** Reads remotes, HEAD, branches, tags and stashes of a repository. */
|
|
15
|
+
export declare function readRepoState(repoDir: string): RepoState;
|
|
16
|
+
export interface BundleResult {
|
|
17
|
+
file: string;
|
|
18
|
+
kind: "full" | "thin";
|
|
19
|
+
bytes: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Writes a git bundle of every branch and tag. When `basisShas` are all known
|
|
23
|
+
* locally the bundle is thin (only objects newer than the previous
|
|
24
|
+
* generation); otherwise a full bundle is produced. An empty repository (no
|
|
25
|
+
* commits) yields no bundle.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createBundle(repoDir: string, outFile: string, basisShas?: string[], extraRefs?: string[]): Promise<BundleResult | null>;
|
|
28
|
+
/** `git bundle verify`; `repoDir` supplies prerequisites for thin bundles. */
|
|
29
|
+
export declare function verifyBundle(file: string, repoDir: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Commits a thin bundle may assume present: the previous generation's head.
|
|
32
|
+
* The manifest records branch names only, so the head sha is the one durable
|
|
33
|
+
* basis; objects on branches not reachable from it are simply re-sent.
|
|
34
|
+
*/
|
|
35
|
+
export declare function basisFromPrevious(prev: RepoManifest | undefined): string[];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { git, gitOrThrow } from "./git.js";
|
|
3
|
+
/** Reads remotes, HEAD, branches, tags and stashes of a repository. */
|
|
4
|
+
export function readRepoState(repoDir) {
|
|
5
|
+
const remotes = [];
|
|
6
|
+
for (const line of gitOrThrow(["remote", "-v"], repoDir).split("\n")) {
|
|
7
|
+
const m = /^(\S+)\s+(\S+)\s+\(fetch\)$/.exec(line.trim());
|
|
8
|
+
if (m)
|
|
9
|
+
remotes.push({ name: m[1], url: m[2] });
|
|
10
|
+
}
|
|
11
|
+
const headRes = git(["rev-parse", "HEAD"], repoDir);
|
|
12
|
+
const sha = headRes.ok ? headRes.stdout.trim() : "";
|
|
13
|
+
const branchRes = git(["symbolic-ref", "--quiet", "--short", "HEAD"], repoDir);
|
|
14
|
+
const branch = branchRes.ok ? branchRes.stdout.trim() : undefined;
|
|
15
|
+
const upstreamRes = branch ? git(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"], repoDir) : undefined;
|
|
16
|
+
const upstream = upstreamRes?.ok ? upstreamRes.stdout.trim() : undefined;
|
|
17
|
+
const branches = [];
|
|
18
|
+
const tags = [];
|
|
19
|
+
/** Branch → "<remote>/<branch>" for every local branch that tracks a remote. */
|
|
20
|
+
const branchUpstreams = {};
|
|
21
|
+
const refsOut = git(["for-each-ref", "--format=%(refname)%09%(upstream:short)", "refs/heads", "refs/tags"], repoDir);
|
|
22
|
+
if (refsOut.ok) {
|
|
23
|
+
for (const line of refsOut.stdout.split("\n")) {
|
|
24
|
+
const [refRaw, upstreamRaw = ""] = line.split("\t");
|
|
25
|
+
const ref = refRaw.trim();
|
|
26
|
+
if (!ref)
|
|
27
|
+
continue;
|
|
28
|
+
if (ref.startsWith("refs/heads/")) {
|
|
29
|
+
const name = ref.slice("refs/heads/".length);
|
|
30
|
+
branches.push(name);
|
|
31
|
+
const up = upstreamRaw.trim();
|
|
32
|
+
if (up)
|
|
33
|
+
branchUpstreams[name] = up;
|
|
34
|
+
}
|
|
35
|
+
else if (ref.startsWith("refs/tags/"))
|
|
36
|
+
tags.push(ref.slice("refs/tags/".length));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const stashRes = git(["stash", "list", "--format=%H"], repoDir);
|
|
40
|
+
const stashes = stashRes.ok ? stashRes.stdout.split("\n").map((s) => s.trim()).filter(Boolean) : [];
|
|
41
|
+
const head = { sha };
|
|
42
|
+
if (branch)
|
|
43
|
+
head.branch = branch;
|
|
44
|
+
if (upstream)
|
|
45
|
+
head.upstream = upstream;
|
|
46
|
+
// Real remote-tracking tips, so a restore never has to guess where the
|
|
47
|
+
// remote was (guessing would hide unpushed commits from offload).
|
|
48
|
+
const upstreamTips = {};
|
|
49
|
+
for (const up of new Set([...(upstream ? [upstream] : []), ...Object.values(branchUpstreams)])) {
|
|
50
|
+
const tipRes = git(["rev-parse", "--verify", `refs/remotes/${up}`], repoDir);
|
|
51
|
+
if (tipRes.ok)
|
|
52
|
+
upstreamTips[up] = tipRes.stdout.trim();
|
|
53
|
+
}
|
|
54
|
+
return { remotes, head, branches, tags, stashes, branchUpstreams, upstreamTips };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Writes a git bundle of every branch and tag. When `basisShas` are all known
|
|
58
|
+
* locally the bundle is thin (only objects newer than the previous
|
|
59
|
+
* generation); otherwise a full bundle is produced. An empty repository (no
|
|
60
|
+
* commits) yields no bundle.
|
|
61
|
+
*/
|
|
62
|
+
export async function createBundle(repoDir, outFile, basisShas = [], extraRefs = []) {
|
|
63
|
+
if (!git(["rev-parse", "--verify", "HEAD"], repoDir).ok)
|
|
64
|
+
return null;
|
|
65
|
+
const known = basisShas.filter((sha) => git(["cat-file", "-e", `${sha}^{commit}`], repoDir).ok);
|
|
66
|
+
const thin = basisShas.length > 0 && known.length === basisShas.length;
|
|
67
|
+
// Remote-tracking refs ride along so upstream tips restore with their objects
|
|
68
|
+
// even when the branch has diverged from them.
|
|
69
|
+
const refs = extraRefs.filter((r) => git(["rev-parse", "--verify", r], repoDir).ok);
|
|
70
|
+
const fullArgs = ["bundle", "create", outFile, "--branches", "--tags", "HEAD", ...refs];
|
|
71
|
+
const args = [...fullArgs];
|
|
72
|
+
if (thin)
|
|
73
|
+
for (const sha of known)
|
|
74
|
+
args.push(`^${sha}`);
|
|
75
|
+
const res = git(args, repoDir);
|
|
76
|
+
if (!res.ok) {
|
|
77
|
+
if (thin && /empty bundle|Refusing to create empty bundle/i.test(res.stderr)) {
|
|
78
|
+
return null; // nothing new since the basis generation
|
|
79
|
+
}
|
|
80
|
+
if (thin) {
|
|
81
|
+
// basis mismatch of some kind: fall back to a full bundle rather than fail the push
|
|
82
|
+
gitOrThrow(fullArgs, repoDir);
|
|
83
|
+
return { file: outFile, kind: "full", bytes: (await stat(outFile)).size };
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`git bundle create failed in ${repoDir}: ${res.stderr.trim()}`);
|
|
86
|
+
}
|
|
87
|
+
return { file: outFile, kind: thin ? "thin" : "full", bytes: (await stat(outFile)).size };
|
|
88
|
+
}
|
|
89
|
+
/** `git bundle verify`; `repoDir` supplies prerequisites for thin bundles. */
|
|
90
|
+
export function verifyBundle(file, repoDir) {
|
|
91
|
+
return git(["bundle", "verify", file], repoDir).ok;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Commits a thin bundle may assume present: the previous generation's head.
|
|
95
|
+
* The manifest records branch names only, so the head sha is the one durable
|
|
96
|
+
* basis; objects on branches not reachable from it are simply re-sent.
|
|
97
|
+
*/
|
|
98
|
+
export function basisFromPrevious(prev) {
|
|
99
|
+
const sha = prev?.head?.sha;
|
|
100
|
+
return sha ? [sha] : [];
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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,IAAI,IAAI,EAAE,CAAC;YACT,oFAAoF;YACpF,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC9B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,+BAA+B,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5F,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,OAAe;IACxD,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;AACrD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAA8B;IAC9D,MAAM,GAAG,GAAG,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC;IAC5B,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ChunkRef } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Splits a file into content-addressed chunks of at most CHUNK_BYTES. Returns
|
|
4
|
+
* one ChunkRef per chunk in order; the caller uploads by sha256 and records the
|
|
5
|
+
* sequence in the manifest so the file can be reassembled.
|
|
6
|
+
*/
|
|
7
|
+
export declare function chunkFile(file: string): Promise<ChunkRef[]>;
|
|
8
|
+
/** Reads chunk N of a file (N-th CHUNK_BYTES window). */
|
|
9
|
+
export declare function readChunk(file: string, index: number): Promise<Buffer>;
|
|
10
|
+
export declare function sha256(buf: Buffer): string;
|
|
11
|
+
export declare function sha256String(text: string): string;
|
|
12
|
+
/** Total distinct bytes across a set of chunk refs, deduped by sha256. */
|
|
13
|
+
export declare function dedupedBytes(refs: ChunkRef[]): number;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import { open } from "node:fs/promises";
|
|
4
|
+
import { CHUNK_BYTES } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Splits a file into content-addressed chunks of at most CHUNK_BYTES. Returns
|
|
7
|
+
* one ChunkRef per chunk in order; the caller uploads by sha256 and records the
|
|
8
|
+
* sequence in the manifest so the file can be reassembled.
|
|
9
|
+
*/
|
|
10
|
+
export async function chunkFile(file) {
|
|
11
|
+
const refs = [];
|
|
12
|
+
const stream = createReadStream(file, { highWaterMark: CHUNK_BYTES });
|
|
13
|
+
let carry = Buffer.alloc(0);
|
|
14
|
+
const flush = (buf) => {
|
|
15
|
+
refs.push({ sha256: sha256(buf), size: buf.length });
|
|
16
|
+
};
|
|
17
|
+
for await (const piece of stream) {
|
|
18
|
+
const buf = Buffer.from(piece);
|
|
19
|
+
carry = carry.length === 0 ? buf : Buffer.concat([carry, buf]);
|
|
20
|
+
while (carry.length >= CHUNK_BYTES) {
|
|
21
|
+
flush(Buffer.from(carry.subarray(0, CHUNK_BYTES)));
|
|
22
|
+
carry = Buffer.from(carry.subarray(CHUNK_BYTES));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (carry.length > 0 || refs.length === 0)
|
|
26
|
+
flush(carry);
|
|
27
|
+
return refs;
|
|
28
|
+
}
|
|
29
|
+
/** Reads chunk N of a file (N-th CHUNK_BYTES window). */
|
|
30
|
+
export async function readChunk(file, index) {
|
|
31
|
+
const fh = await open(file, "r");
|
|
32
|
+
try {
|
|
33
|
+
const buf = Buffer.alloc(CHUNK_BYTES);
|
|
34
|
+
const { bytesRead } = await fh.read(buf, 0, CHUNK_BYTES, index * CHUNK_BYTES);
|
|
35
|
+
return buf.subarray(0, bytesRead);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
await fh.close();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function sha256(buf) {
|
|
42
|
+
return createHash("sha256").update(buf).digest("hex");
|
|
43
|
+
}
|
|
44
|
+
export function sha256String(text) {
|
|
45
|
+
return createHash("sha256").update(text).digest("hex");
|
|
46
|
+
}
|
|
47
|
+
/** Total distinct bytes across a set of chunk refs, deduped by sha256. */
|
|
48
|
+
export function dedupedBytes(refs) {
|
|
49
|
+
const seen = new Map();
|
|
50
|
+
for (const r of refs)
|
|
51
|
+
seen.set(r.sha256, r.size);
|
|
52
|
+
let total = 0;
|
|
53
|
+
for (const size of seen.values())
|
|
54
|
+
total += size;
|
|
55
|
+
return total;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=chunks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.js","sourceRoot":"","sources":["../../src/teleport/chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAiB,MAAM,YAAY,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAY;IAC1C,MAAM,IAAI,GAAe,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,CAAC;IACtE,IAAI,KAAK,GAAW,MAAM,CAAC,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,EAAE,CAAC,EAAE,WAAW,EAAE,KAAK,GAAG,WAAW,CAAC,CAAC;QAC9E,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IACpC,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,GAAW;IAChC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,YAAY,CAAC,IAAgB;IAC3C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,IAAI;QAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE;QAAE,KAAK,IAAI,IAAI,CAAC;IAChD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { type InferenceEndpoint } from "../api.js";
|
|
3
|
+
import { pushCapsule } from "../teleport/push.js";
|
|
4
|
+
interface OutputOptions {
|
|
5
|
+
output?: string;
|
|
6
|
+
json?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface PushOptions extends OutputOptions {
|
|
9
|
+
name?: string;
|
|
10
|
+
mirror?: string;
|
|
11
|
+
includeIgnored?: string[];
|
|
12
|
+
dryRun?: boolean;
|
|
13
|
+
session?: string;
|
|
14
|
+
harness?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function cmdTeleportPush(pathArg: string | undefined, options: PushOptions): Promise<void>;
|
|
17
|
+
/** The JSON shape of a push: capsule identity plus the PushOutput fields. */
|
|
18
|
+
export type PushSummary = {
|
|
19
|
+
capsuleId: string;
|
|
20
|
+
name: string;
|
|
21
|
+
} & Awaited<ReturnType<typeof pushCapsule>>;
|
|
22
|
+
interface PullOptions extends OutputOptions {
|
|
23
|
+
capsule?: string;
|
|
24
|
+
generation?: string;
|
|
25
|
+
into?: string;
|
|
26
|
+
restoreHarness?: boolean;
|
|
27
|
+
resume?: boolean;
|
|
28
|
+
/** With --resume: print the launch plan instead of starting the harness. */
|
|
29
|
+
dryRun?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function cmdTeleportPull(nameArg: string | undefined, pathArg: string | undefined, options: PullOptions): Promise<void>;
|
|
32
|
+
export declare function cmdTeleportList(options: OutputOptions): Promise<void>;
|
|
33
|
+
export declare function cmdTeleportStatus(ref: string, options: OutputOptions): Promise<void>;
|
|
34
|
+
export declare function cmdTeleportVerify(ref: string, options: OutputOptions): Promise<void>;
|
|
35
|
+
export declare function cmdTeleportGenerations(ref: string, options: OutputOptions): Promise<void>;
|
|
36
|
+
export declare function cmdTeleportTargets(options: OutputOptions): Promise<void>;
|
|
37
|
+
export declare function cmdTeleportRm(ref: string, options: OutputOptions & {
|
|
38
|
+
yes?: boolean;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
interface TeleportOptions extends PushOptions {
|
|
41
|
+
cloud?: boolean;
|
|
42
|
+
endpoint?: string;
|
|
43
|
+
prompt?: string;
|
|
44
|
+
}
|
|
45
|
+
/** The bare `heyditto teleport` command: push the current dir, optionally launch a cloud session. */
|
|
46
|
+
export declare function cmdTeleport(pathArg: string | undefined, options: TeleportOptions): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Turns `--endpoint <id|slug|name>` into the endpoint the backend expects by
|
|
49
|
+
* UUID. Omitted: the user's only endpoint when exactly one exists, otherwise
|
|
50
|
+
* the backend's default. Unknown values list what is available.
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveEndpoint(option: string | undefined): Promise<InferenceEndpoint | undefined>;
|
|
53
|
+
export declare function cmdOffload(pathArg: string | undefined, options: {
|
|
54
|
+
yes?: boolean;
|
|
55
|
+
allowUnpushed?: boolean;
|
|
56
|
+
name?: string;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
interface StorageAddOptions extends OutputOptions {
|
|
59
|
+
name?: string;
|
|
60
|
+
endpoint?: string;
|
|
61
|
+
region?: string;
|
|
62
|
+
bucket?: string;
|
|
63
|
+
accessKey?: string;
|
|
64
|
+
secretKey?: string;
|
|
65
|
+
default?: boolean;
|
|
66
|
+
/** commander maps --no-mirror to mirror=false */
|
|
67
|
+
mirror?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export declare function cmdStorageAdd(options: StorageAddOptions): Promise<void>;
|
|
70
|
+
export declare function cmdStorageList(options: OutputOptions): Promise<void>;
|
|
71
|
+
/** `<bucket>` is a friendly name or an id. */
|
|
72
|
+
export declare function cmdStorageTest(ref: string, options: OutputOptions): Promise<void>;
|
|
73
|
+
export declare function cmdStorageRemove(ref: string): Promise<void>;
|
|
74
|
+
export declare function cmdStorageMirror(ref: string, targetsArg: string): Promise<void>;
|
|
75
|
+
export declare function registerTeleportCommands(program: Command, addExamples: (c: Command, ex: string) => Command): void;
|
|
76
|
+
export {};
|