@bytevion/cli 0.1.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/bin/run.js +7 -0
- package/dist/base.d.ts +20 -0
- package/dist/base.js +49 -0
- package/dist/commands/batch/list.d.ts +5 -0
- package/dist/commands/batch/list.js +22 -0
- package/dist/commands/batch/poll.d.ts +13 -0
- package/dist/commands/batch/poll.js +42 -0
- package/dist/commands/batch/submit.d.ts +13 -0
- package/dist/commands/batch/submit.js +74 -0
- package/dist/commands/doctor.d.ts +5 -0
- package/dist/commands/doctor.js +65 -0
- package/dist/commands/env.d.ts +10 -0
- package/dist/commands/env.js +35 -0
- package/dist/commands/init.d.ts +12 -0
- package/dist/commands/init.js +58 -0
- package/dist/commands/integrate.d.ts +20 -0
- package/dist/commands/integrate.js +133 -0
- package/dist/commands/keys/create.d.ts +11 -0
- package/dist/commands/keys/create.js +33 -0
- package/dist/commands/keys/list.d.ts +5 -0
- package/dist/commands/keys/list.js +21 -0
- package/dist/commands/keys/revoke.d.ts +11 -0
- package/dist/commands/keys/revoke.js +19 -0
- package/dist/commands/keys/rotate.d.ts +11 -0
- package/dist/commands/keys/rotate.js +24 -0
- package/dist/commands/login.d.ts +9 -0
- package/dist/commands/login.js +76 -0
- package/dist/commands/logout.d.ts +5 -0
- package/dist/commands/logout.js +24 -0
- package/dist/commands/opt/preset.d.ts +8 -0
- package/dist/commands/opt/preset.js +23 -0
- package/dist/commands/opt/set.d.ts +10 -0
- package/dist/commands/opt/set.js +22 -0
- package/dist/commands/opt/show.d.ts +5 -0
- package/dist/commands/opt/show.js +24 -0
- package/dist/commands/providers/add.d.ts +12 -0
- package/dist/commands/providers/add.js +40 -0
- package/dist/commands/providers/list.d.ts +5 -0
- package/dist/commands/providers/list.js +22 -0
- package/dist/commands/providers/rotate.d.ts +14 -0
- package/dist/commands/providers/rotate.js +28 -0
- package/dist/commands/providers/test.d.ts +11 -0
- package/dist/commands/providers/test.js +22 -0
- package/dist/commands/run.d.ts +13 -0
- package/dist/commands/run.js +32 -0
- package/dist/commands/sessions/index.d.ts +5 -0
- package/dist/commands/sessions/index.js +21 -0
- package/dist/commands/sessions/revoke.d.ts +8 -0
- package/dist/commands/sessions/revoke.js +19 -0
- package/dist/commands/stats.d.ts +5 -0
- package/dist/commands/stats.js +27 -0
- package/dist/commands/usage.d.ts +8 -0
- package/dist/commands/usage.js +32 -0
- package/dist/commands/whoami.d.ts +5 -0
- package/dist/commands/whoami.js +19 -0
- package/dist/lib/api.d.ts +40 -0
- package/dist/lib/api.js +147 -0
- package/dist/lib/config.d.ts +20 -0
- package/dist/lib/config.js +52 -0
- package/dist/lib/credentials.d.ts +5 -0
- package/dist/lib/credentials.js +50 -0
- package/dist/lib/errors.d.ts +7 -0
- package/dist/lib/errors.js +30 -0
- package/dist/lib/integrations.d.ts +23 -0
- package/dist/lib/integrations.js +145 -0
- package/dist/lib/output.d.ts +4 -0
- package/dist/lib/output.js +37 -0
- package/dist/lib/paths.d.ts +3 -0
- package/dist/lib/paths.js +19 -0
- package/dist/lib/shell.d.ts +4 -0
- package/dist/lib/shell.js +25 -0
- package/dist/lib/util.d.ts +4 -0
- package/dist/lib/util.js +101 -0
- package/oclif.manifest.json +1516 -0
- package/package.json +59 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_1 = require("../../base");
|
|
4
|
+
const output_1 = require("../../lib/output");
|
|
5
|
+
class KeysList extends base_1.BaseCommand {
|
|
6
|
+
static description = 'List the Byte API keys for the current org.';
|
|
7
|
+
async run() {
|
|
8
|
+
const { flags } = await this.parse(KeysList);
|
|
9
|
+
this.requireToken(flags);
|
|
10
|
+
const rows = await this.api(flags).keysList();
|
|
11
|
+
if (this.jsonEnabled())
|
|
12
|
+
return rows;
|
|
13
|
+
if (!rows.length) {
|
|
14
|
+
this.log('No keys yet. Create one with `byte keys create <name>`.');
|
|
15
|
+
return rows;
|
|
16
|
+
}
|
|
17
|
+
this.log((0, output_1.renderTable)(['ID', 'Name', 'Prefix', 'Preset', 'Active', 'Last used'], rows.map((k) => [k.id, k.name, k.key_prefix, k.preset ?? '-', k.active ? 'yes' : 'no', k.last_used_at ?? '-'])));
|
|
18
|
+
return rows;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = KeysList;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base';
|
|
2
|
+
export default class KeysRevoke extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/lib/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<unknown>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
class KeysRevoke extends base_1.BaseCommand {
|
|
6
|
+
static description = 'Revoke (delete) a Byte API key.';
|
|
7
|
+
static args = {
|
|
8
|
+
id: core_1.Args.integer({ description: 'Key id (see `byte keys list`)', required: true }),
|
|
9
|
+
};
|
|
10
|
+
async run() {
|
|
11
|
+
const { args, flags } = await this.parse(KeysRevoke);
|
|
12
|
+
this.requireToken(flags);
|
|
13
|
+
const res = await this.api(flags).keysRevoke(args.id);
|
|
14
|
+
if (!this.jsonEnabled())
|
|
15
|
+
this.log(`Revoked key ${args.id}.`);
|
|
16
|
+
return res;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = KeysRevoke;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base';
|
|
2
|
+
export default class KeysRotate extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/lib/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<unknown>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
class KeysRotate extends base_1.BaseCommand {
|
|
6
|
+
static description = 'Rotate a Byte API key: issue a new secret and invalidate the old one.';
|
|
7
|
+
static args = {
|
|
8
|
+
id: core_1.Args.integer({ description: 'Key id (see `byte keys list`)', required: true }),
|
|
9
|
+
};
|
|
10
|
+
async run() {
|
|
11
|
+
const { args, flags } = await this.parse(KeysRotate);
|
|
12
|
+
this.requireToken(flags);
|
|
13
|
+
const res = await this.api(flags).keysRotate(args.id);
|
|
14
|
+
if (!this.jsonEnabled()) {
|
|
15
|
+
this.log(`Rotated key ${args.id}. New secret (shown once):`);
|
|
16
|
+
this.log('');
|
|
17
|
+
this.log(` ${res.key}`);
|
|
18
|
+
this.log('');
|
|
19
|
+
this.log('Update any integration that used the old secret (e.g. re-run `byte integrate`).');
|
|
20
|
+
}
|
|
21
|
+
return res;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = KeysRotate;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseCommand } from '../base';
|
|
2
|
+
export default class Login extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
'no-browser': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
};
|
|
8
|
+
run(): Promise<unknown>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const node_os_1 = require("node:os");
|
|
5
|
+
const base_1 = require("../base");
|
|
6
|
+
const api_1 = require("../lib/api");
|
|
7
|
+
const config_1 = require("../lib/config");
|
|
8
|
+
const credentials_1 = require("../lib/credentials");
|
|
9
|
+
const errors_1 = require("../lib/errors");
|
|
10
|
+
const util_1 = require("../lib/util");
|
|
11
|
+
class Login extends base_1.BaseCommand {
|
|
12
|
+
static description = 'Sign in from this terminal by approving a device code in the dashboard.';
|
|
13
|
+
static examples = ['<%= config.bin %> login', '<%= config.bin %> login --no-browser'];
|
|
14
|
+
static flags = {
|
|
15
|
+
'no-browser': core_1.Flags.boolean({ description: 'Do not try to open the browser automatically' }),
|
|
16
|
+
};
|
|
17
|
+
async run() {
|
|
18
|
+
const { flags } = await this.parse(Login);
|
|
19
|
+
const profile = this.profileFrom(flags);
|
|
20
|
+
const base = this.baseUrlFrom(flags);
|
|
21
|
+
const api = new api_1.ByteApi(base);
|
|
22
|
+
const start = await api.deviceStart(`byte-cli@${(0, node_os_1.hostname)()}`);
|
|
23
|
+
const verifyUrl = start.verification_uri_complete || start.verification_uri;
|
|
24
|
+
this.log('');
|
|
25
|
+
this.log(' Approve this terminal in your browser:');
|
|
26
|
+
this.log(` ${verifyUrl}`);
|
|
27
|
+
this.log('');
|
|
28
|
+
this.log(` Verification code: ${start.user_code}`);
|
|
29
|
+
this.log('');
|
|
30
|
+
if (!flags['no-browser']) {
|
|
31
|
+
try {
|
|
32
|
+
await (0, util_1.openBrowser)(verifyUrl);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// user can open manually
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
let interval = (Number(start.interval) || 5) * 1000;
|
|
39
|
+
const deadline = Date.now() + (Number(start.expires_in) || 600) * 1000;
|
|
40
|
+
while (Date.now() < deadline) {
|
|
41
|
+
await (0, util_1.sleep)(interval);
|
|
42
|
+
try {
|
|
43
|
+
const tok = await api.deviceToken(start.device_code);
|
|
44
|
+
(0, credentials_1.setToken)(profile, tok.access_token);
|
|
45
|
+
(0, config_1.setProfile)(profile, {
|
|
46
|
+
base_url: base,
|
|
47
|
+
dashboard_url: (0, config_1.getProfile)(profile).dashboard_url || config_1.DEFAULT_DASHBOARD_URL,
|
|
48
|
+
org_id: tok.org?.id,
|
|
49
|
+
org_name: tok.org?.name,
|
|
50
|
+
email: tok.user?.email,
|
|
51
|
+
});
|
|
52
|
+
if (!this.jsonEnabled()) {
|
|
53
|
+
this.log(`Signed in as ${tok.user?.email} (org: ${tok.org?.name}).`);
|
|
54
|
+
this.log('Next: run `byte init` to add a provider key and create your Byte API key.');
|
|
55
|
+
}
|
|
56
|
+
return { status: 'signed_in', email: tok.user?.email, org: tok.org?.name, profile };
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
const code = err instanceof errors_1.ByteError ? err.code : '';
|
|
60
|
+
if (code === 'authorization_pending')
|
|
61
|
+
continue;
|
|
62
|
+
if (code === 'slow_down') {
|
|
63
|
+
interval += 5000;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (code === 'access_denied')
|
|
67
|
+
return this.error('Authorization was denied in the dashboard.', { exit: 3 });
|
|
68
|
+
if (code === 'expired_token')
|
|
69
|
+
return this.error('The code expired. Run `byte login` again.', { exit: 3 });
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return this.error('Login timed out. Run `byte login` again.', { exit: 3 });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.default = Login;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_1 = require("../base");
|
|
4
|
+
const credentials_1 = require("../lib/credentials");
|
|
5
|
+
class Logout extends base_1.BaseCommand {
|
|
6
|
+
static description = 'Sign out of this terminal and revoke the stored session token.';
|
|
7
|
+
async run() {
|
|
8
|
+
const { flags } = await this.parse(Logout);
|
|
9
|
+
const profile = this.profileFrom(flags);
|
|
10
|
+
if ((0, credentials_1.getToken)(profile)) {
|
|
11
|
+
try {
|
|
12
|
+
await this.api(flags).cliLogout();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// revoke is best effort; we always clear locally
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
(0, credentials_1.clearCredentials)(profile);
|
|
19
|
+
if (!this.jsonEnabled())
|
|
20
|
+
this.log(`Signed out of profile "${profile}".`);
|
|
21
|
+
return { status: 'signed_out', profile };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = Logout;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
class OptPreset extends base_1.BaseCommand {
|
|
6
|
+
static description = 'Apply an optimization preset for the whole org.';
|
|
7
|
+
static args = {
|
|
8
|
+
preset: core_1.Args.string({
|
|
9
|
+
description: 'Preset to apply',
|
|
10
|
+
required: true,
|
|
11
|
+
options: ['balanced', 'max_savings', 'lowest_latency', 'reliability_first'],
|
|
12
|
+
}),
|
|
13
|
+
};
|
|
14
|
+
async run() {
|
|
15
|
+
const { args, flags } = await this.parse(OptPreset);
|
|
16
|
+
this.requireToken(flags);
|
|
17
|
+
const res = await this.api(flags).optPatch({ default_mode: args.preset });
|
|
18
|
+
if (!this.jsonEnabled())
|
|
19
|
+
this.log(`Optimization preset set to "${args.preset}".`);
|
|
20
|
+
return res;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = OptPreset;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base';
|
|
2
|
+
export default class OptSet extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static args: {
|
|
6
|
+
flag: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
+
value: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
8
|
+
};
|
|
9
|
+
run(): Promise<unknown>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
class OptSet extends base_1.BaseCommand {
|
|
6
|
+
static description = 'Toggle a single optimization layer on or off. See field names with `byte opt show --json`.';
|
|
7
|
+
static examples = ['<%= config.bin %> opt set compression_enabled off', '<%= config.bin %> opt set response_cache_enabled on'];
|
|
8
|
+
static args = {
|
|
9
|
+
flag: core_1.Args.string({ description: 'Optimization field name', required: true }),
|
|
10
|
+
value: core_1.Args.string({ description: 'on or off', required: true, options: ['on', 'off', 'true', 'false'] }),
|
|
11
|
+
};
|
|
12
|
+
async run() {
|
|
13
|
+
const { args, flags } = await this.parse(OptSet);
|
|
14
|
+
this.requireToken(flags);
|
|
15
|
+
const enabled = args.value === 'on' || args.value === 'true';
|
|
16
|
+
const res = await this.api(flags).optPatch({ [args.flag]: enabled });
|
|
17
|
+
if (!this.jsonEnabled())
|
|
18
|
+
this.log(`Set ${args.flag} = ${enabled}.`);
|
|
19
|
+
return res;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = OptSet;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_1 = require("../../base");
|
|
4
|
+
class OptShow extends base_1.BaseCommand {
|
|
5
|
+
static description = 'Show the current optimization preset and layer states for the org.';
|
|
6
|
+
async run() {
|
|
7
|
+
const { flags } = await this.parse(OptShow);
|
|
8
|
+
this.requireToken(flags);
|
|
9
|
+
const res = await this.api(flags).optShow();
|
|
10
|
+
if (this.jsonEnabled())
|
|
11
|
+
return res;
|
|
12
|
+
const settings = res.settings ?? res;
|
|
13
|
+
this.log(`Preset (default_mode): ${settings.default_mode ?? '-'}`);
|
|
14
|
+
this.log(`Cache mode: ${settings.cache_mode ?? '-'}`);
|
|
15
|
+
const layers = Array.isArray(res.layers) ? res.layers : [];
|
|
16
|
+
if (layers.length) {
|
|
17
|
+
const enabled = layers.filter((l) => l.enabled).length;
|
|
18
|
+
this.log(`Layers enabled: ${enabled}/${layers.length}`);
|
|
19
|
+
}
|
|
20
|
+
this.log('Run with --json for the full settings object.');
|
|
21
|
+
return res;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = OptShow;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base';
|
|
2
|
+
export default class ProvidersAdd extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
'api-key': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
mode: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
label: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
'no-fetch': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<unknown>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
const util_1 = require("../../lib/util");
|
|
6
|
+
class ProvidersAdd extends base_1.BaseCommand {
|
|
7
|
+
static description = 'Add an upstream provider key (BYOK). Byte stores it encrypted and can auto-import models.';
|
|
8
|
+
static examples = ['<%= config.bin %> providers add', '<%= config.bin %> providers add --api-key sk-... --label "OpenAI prod"'];
|
|
9
|
+
static flags = {
|
|
10
|
+
'api-key': core_1.Flags.string({ description: 'Upstream provider API key', env: 'BYTE_PROVIDER_KEY' }),
|
|
11
|
+
mode: core_1.Flags.string({ description: 'Gateway mode for this provider', default: 'byte_auto' }),
|
|
12
|
+
label: core_1.Flags.string({ description: 'A label for this connection' }),
|
|
13
|
+
'no-fetch': core_1.Flags.boolean({ description: 'Skip auto-importing the provider model list' }),
|
|
14
|
+
};
|
|
15
|
+
async run() {
|
|
16
|
+
const { flags } = await this.parse(ProvidersAdd);
|
|
17
|
+
this.requireToken(flags);
|
|
18
|
+
let apiKey = flags['api-key'];
|
|
19
|
+
if (!apiKey)
|
|
20
|
+
apiKey = await (0, util_1.promptHidden)('Upstream provider API key: ');
|
|
21
|
+
if (!apiKey)
|
|
22
|
+
return this.error('A provider API key is required.', { exit: 2 });
|
|
23
|
+
const body = {
|
|
24
|
+
api_key: apiKey,
|
|
25
|
+
gateway_mode: flags.mode,
|
|
26
|
+
auto_fetch: !flags['no-fetch'],
|
|
27
|
+
};
|
|
28
|
+
if (flags.label)
|
|
29
|
+
body.label = flags.label;
|
|
30
|
+
const res = await this.api(flags).providersAdd(body);
|
|
31
|
+
if (!this.jsonEnabled()) {
|
|
32
|
+
const id = res.id ?? res.connection?.id;
|
|
33
|
+
const imported = res.fetch_result?.imported ?? res.imported ?? 0;
|
|
34
|
+
this.log(`Provider connection added (id ${id}). Models imported: ${imported}.`);
|
|
35
|
+
this.log('Next: `byte keys create <name>` then `byte integrate <harness>`.');
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = ProvidersAdd;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_1 = require("../../base");
|
|
4
|
+
const output_1 = require("../../lib/output");
|
|
5
|
+
class ProvidersList extends base_1.BaseCommand {
|
|
6
|
+
static description = 'List upstream provider connections for the current org.';
|
|
7
|
+
async run() {
|
|
8
|
+
const { flags } = await this.parse(ProvidersList);
|
|
9
|
+
this.requireToken(flags);
|
|
10
|
+
const res = await this.api(flags).providersList();
|
|
11
|
+
const rows = res.connections ?? res ?? [];
|
|
12
|
+
if (this.jsonEnabled())
|
|
13
|
+
return rows;
|
|
14
|
+
if (!rows.length) {
|
|
15
|
+
this.log('No provider connections yet. Add one with `byte providers add`.');
|
|
16
|
+
return rows;
|
|
17
|
+
}
|
|
18
|
+
this.log((0, output_1.renderTable)(['ID', 'Label', 'Status', 'Secret', 'Models'], rows.map((c) => [c.id, c.label, c.status ?? '-', c.secret_last4 ? `****${c.secret_last4}` : '-', c.model_count ?? c.models ?? '-'])));
|
|
19
|
+
return rows;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = ProvidersList;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base';
|
|
2
|
+
export default class ProvidersRotate extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/lib/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
static flags: {
|
|
11
|
+
'api-key': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
const util_1 = require("../../lib/util");
|
|
6
|
+
class ProvidersRotate extends base_1.BaseCommand {
|
|
7
|
+
static description = 'Replace the upstream API key on a provider connection (keeps imported models).';
|
|
8
|
+
static args = {
|
|
9
|
+
id: core_1.Args.integer({ description: 'Connection id (see `byte providers list`)', required: true }),
|
|
10
|
+
};
|
|
11
|
+
static flags = {
|
|
12
|
+
'api-key': core_1.Flags.string({ description: 'New upstream provider API key', env: 'BYTE_PROVIDER_KEY' }),
|
|
13
|
+
};
|
|
14
|
+
async run() {
|
|
15
|
+
const { args, flags } = await this.parse(ProvidersRotate);
|
|
16
|
+
this.requireToken(flags);
|
|
17
|
+
let apiKey = flags['api-key'];
|
|
18
|
+
if (!apiKey)
|
|
19
|
+
apiKey = await (0, util_1.promptHidden)('New upstream provider API key: ');
|
|
20
|
+
if (!apiKey)
|
|
21
|
+
return this.error('A provider API key is required.', { exit: 2 });
|
|
22
|
+
const res = await this.api(flags).providersRotate(args.id, apiKey);
|
|
23
|
+
if (!this.jsonEnabled())
|
|
24
|
+
this.log(`Rotated provider key on connection ${args.id} (now ****${res.secret_last4 ?? '????'}).`);
|
|
25
|
+
return res;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.default = ProvidersRotate;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base';
|
|
2
|
+
export default class ProvidersTest extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
id: import("@oclif/core/lib/interfaces").Arg<number, {
|
|
6
|
+
max?: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<unknown>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
class ProvidersTest extends base_1.BaseCommand {
|
|
6
|
+
static description = 'Verify a provider connection by re-fetching its model list.';
|
|
7
|
+
static args = {
|
|
8
|
+
id: core_1.Args.integer({ description: 'Connection id (see `byte providers list`)', required: true }),
|
|
9
|
+
};
|
|
10
|
+
async run() {
|
|
11
|
+
const { args, flags } = await this.parse(ProvidersTest);
|
|
12
|
+
this.requireToken(flags);
|
|
13
|
+
const res = await this.api(flags).providersTest(args.id);
|
|
14
|
+
if (!this.jsonEnabled()) {
|
|
15
|
+
const imported = res.imported ?? 0;
|
|
16
|
+
const updated = res.updated ?? 0;
|
|
17
|
+
this.log(`Connection ${args.id} reachable. Models imported: ${imported}, updated: ${updated}.`);
|
|
18
|
+
}
|
|
19
|
+
return res;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = ProvidersTest;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseCommand } from '../base';
|
|
2
|
+
export default class Run extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static args: {
|
|
6
|
+
prompt: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
static flags: {
|
|
9
|
+
model: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
'max-tokens': import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<unknown>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
class Run extends base_1.BaseCommand {
|
|
6
|
+
static description = 'Send a one-off prompt through the Byte gateway using your Byte API key.';
|
|
7
|
+
static examples = ['<%= config.bin %> run "summarize this release note"', '<%= config.bin %> run "hi" --model gpt-4o'];
|
|
8
|
+
static args = {
|
|
9
|
+
prompt: core_1.Args.string({ description: 'The prompt to send', required: true }),
|
|
10
|
+
};
|
|
11
|
+
static flags = {
|
|
12
|
+
model: core_1.Flags.string({ description: 'Model or Byte alias', default: 'byte-default' }),
|
|
13
|
+
'max-tokens': core_1.Flags.integer({ description: 'Maximum output tokens' }),
|
|
14
|
+
};
|
|
15
|
+
async run() {
|
|
16
|
+
const { args, flags } = await this.parse(Run);
|
|
17
|
+
const key = this.requireByteKey(flags);
|
|
18
|
+
const body = { model: flags.model, messages: [{ role: 'user', content: args.prompt }] };
|
|
19
|
+
if (flags['max-tokens'] !== undefined)
|
|
20
|
+
body.max_tokens = flags['max-tokens'];
|
|
21
|
+
const res = await this.api(flags).chat(key, body);
|
|
22
|
+
if (this.jsonEnabled())
|
|
23
|
+
return res;
|
|
24
|
+
const content = res.choices?.[0]?.message?.content ?? '';
|
|
25
|
+
this.log(content);
|
|
26
|
+
const u = res.usage ?? {};
|
|
27
|
+
this.log('');
|
|
28
|
+
this.log(`— ${u.prompt_tokens ?? 0} in / ${u.completion_tokens ?? 0} out tokens · model ${res.model ?? flags.model}`);
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.default = Run;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_1 = require("../../base");
|
|
4
|
+
const output_1 = require("../../lib/output");
|
|
5
|
+
class Sessions extends base_1.BaseCommand {
|
|
6
|
+
static description = 'List active terminal sessions (CLI tokens) for the org.';
|
|
7
|
+
async run() {
|
|
8
|
+
const { flags } = await this.parse(Sessions);
|
|
9
|
+
this.requireToken(flags);
|
|
10
|
+
const rows = await this.api(flags).sessions();
|
|
11
|
+
if (this.jsonEnabled())
|
|
12
|
+
return rows;
|
|
13
|
+
if (!rows.length) {
|
|
14
|
+
this.log('No active CLI sessions.');
|
|
15
|
+
return rows;
|
|
16
|
+
}
|
|
17
|
+
this.log((0, output_1.renderTable)(['ID', 'Name', 'Scope', 'Prefix', 'Last used', 'Expires'], rows.map((s) => [s.id, s.name, s.scope, s.token_prefix, s.last_used_at ?? '-', s.expires_at ?? 'never'])));
|
|
18
|
+
return rows;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = Sessions;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
class SessionsRevoke extends base_1.BaseCommand {
|
|
6
|
+
static description = 'Revoke a terminal session (CLI token) by id.';
|
|
7
|
+
static args = {
|
|
8
|
+
id: core_1.Args.string({ description: 'Session id (see `byte sessions`)', required: true }),
|
|
9
|
+
};
|
|
10
|
+
async run() {
|
|
11
|
+
const { args, flags } = await this.parse(SessionsRevoke);
|
|
12
|
+
this.requireToken(flags);
|
|
13
|
+
const res = await this.api(flags).revokeSession(args.id);
|
|
14
|
+
if (!this.jsonEnabled())
|
|
15
|
+
this.log(`Revoked session ${args.id}.`);
|
|
16
|
+
return res;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = SessionsRevoke;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_1 = require("../base");
|
|
4
|
+
const output_1 = require("../lib/output");
|
|
5
|
+
class Stats extends base_1.BaseCommand {
|
|
6
|
+
static description = 'Headline usage and savings summary for the current org.';
|
|
7
|
+
async run() {
|
|
8
|
+
const { flags } = await this.parse(Stats);
|
|
9
|
+
this.requireToken(flags);
|
|
10
|
+
const api = this.api(flags);
|
|
11
|
+
const [summary, cache] = await Promise.all([
|
|
12
|
+
api.dashboard().catch(() => ({})),
|
|
13
|
+
api.cacheStats().catch(() => ({})),
|
|
14
|
+
]);
|
|
15
|
+
const out = { summary, cache };
|
|
16
|
+
if (this.jsonEnabled())
|
|
17
|
+
return out;
|
|
18
|
+
const s = summary;
|
|
19
|
+
const c = cache;
|
|
20
|
+
this.log(`Requests: ${s.total_requests ?? s.requests ?? '-'}`);
|
|
21
|
+
this.log(`Cache hit rate: ${(0, output_1.pct)(s.cache_hit_rate ?? c.hit_rate)}`);
|
|
22
|
+
this.log(`Total savings: ${(0, output_1.fmtUsd)(s.savings_usd ?? s.total_savings_usd)}`);
|
|
23
|
+
this.log(`Cost (Byte): ${(0, output_1.fmtUsd)(s.cost_byte_usd ?? s.cost_usd)}`);
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = Stats;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseCommand } from '../base';
|
|
2
|
+
export default class Usage extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
granularity: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
6
|
+
};
|
|
7
|
+
run(): Promise<unknown>;
|
|
8
|
+
}
|