@aaronjmars/openroutercli 0.1.3 → 0.1.6
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 +36 -39
- package/SKILL.md +18 -17
- package/package.json +1 -1
- package/src/api.js +11 -0
- package/src/args.js +40 -0
- package/src/cli.js +12 -15
- package/src/commands/account.js +11 -5
- package/src/commands/chat.js +104 -76
- package/src/commands/embed.js +8 -16
- package/src/commands/guardrails.js +33 -29
- package/src/commands/keys.js +16 -7
- package/src/commands/login.js +25 -20
- package/src/commands/messages.js +36 -34
- package/src/commands/misc.js +14 -13
- package/src/commands/models.js +44 -25
- package/src/commands/request.js +1 -1
- package/src/commands/rerank.js +2 -2
- package/src/commands/speech.js +4 -19
- package/src/commands/video.js +31 -24
- package/src/commands/workspaces.js +20 -21
- package/src/config.js +5 -15
- package/src/output.js +19 -9
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { parseArgs, authFromValues } from '../args.js';
|
|
1
|
+
import { parseArgs, authFromValues, PAGINATION_OPTIONS, paginationQuery } from '../args.js';
|
|
2
2
|
import { api } from '../api.js';
|
|
3
|
-
import {
|
|
3
|
+
import { outln, printResult, table } from '../output.js';
|
|
4
4
|
|
|
5
5
|
const HELP = `Usage: openrouter workspaces <subcommand> [options]
|
|
6
6
|
|
|
7
7
|
Manage workspaces (requires a management key).
|
|
8
8
|
|
|
9
9
|
Subcommands:
|
|
10
|
-
list
|
|
10
|
+
list [--offset <n>] [--limit <n>] List workspaces
|
|
11
11
|
get <id|slug> Get one
|
|
12
12
|
create <name> [options] Create
|
|
13
13
|
update <id|slug> [options] Update
|
|
@@ -16,6 +16,7 @@ Subcommands:
|
|
|
16
16
|
remove-members <id|slug> <userId>... Bulk remove members
|
|
17
17
|
|
|
18
18
|
create / update options:
|
|
19
|
+
--name <name> (update only)
|
|
19
20
|
--slug <slug>
|
|
20
21
|
--description <text>
|
|
21
22
|
--default-text-model <id>
|
|
@@ -49,18 +50,16 @@ export async function workspacesCommand(argv) {
|
|
|
49
50
|
return sub ? 0 : 1;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
if (rest.includes('-h') || rest.includes('--help')) {
|
|
54
|
+
process.stdout.write(HELP);
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
53
57
|
|
|
54
58
|
if (sub === 'list') {
|
|
55
|
-
const { values } = parseArgs(rest,
|
|
56
|
-
|
|
57
|
-
limit: { type: 'string' }
|
|
58
|
-
});
|
|
59
|
-
const query = {};
|
|
60
|
-
if (values.offset) query.offset = values.offset;
|
|
61
|
-
if (values.limit) query.limit = values.limit;
|
|
59
|
+
const { values } = parseArgs(rest, PAGINATION_OPTIONS);
|
|
60
|
+
const query = paginationQuery(values);
|
|
62
61
|
const data = await api('GET', '/workspaces', {
|
|
63
|
-
auth:
|
|
62
|
+
auth: authFromValues(values),
|
|
64
63
|
requiresManagement: true,
|
|
65
64
|
query
|
|
66
65
|
});
|
|
@@ -80,10 +79,10 @@ export async function workspacesCommand(argv) {
|
|
|
80
79
|
const { values, positionals } = parseArgs(rest, {});
|
|
81
80
|
if (!positionals[0]) throw new Error('id|slug required');
|
|
82
81
|
const data = await api('GET', `/workspaces/${encodeURIComponent(positionals[0])}`, {
|
|
83
|
-
auth:
|
|
82
|
+
auth: authFromValues(values),
|
|
84
83
|
requiresManagement: true
|
|
85
84
|
});
|
|
86
|
-
printResult(data
|
|
85
|
+
printResult(data);
|
|
87
86
|
return 0;
|
|
88
87
|
}
|
|
89
88
|
|
|
@@ -93,11 +92,11 @@ export async function workspacesCommand(argv) {
|
|
|
93
92
|
if (!name) throw new Error('name required');
|
|
94
93
|
const body = { name, ...buildBody(values) };
|
|
95
94
|
const data = await api('POST', '/workspaces', {
|
|
96
|
-
auth:
|
|
95
|
+
auth: authFromValues(values),
|
|
97
96
|
requiresManagement: true,
|
|
98
97
|
body
|
|
99
98
|
});
|
|
100
|
-
printResult(data
|
|
99
|
+
printResult(data);
|
|
101
100
|
return 0;
|
|
102
101
|
}
|
|
103
102
|
|
|
@@ -107,11 +106,11 @@ export async function workspacesCommand(argv) {
|
|
|
107
106
|
const body = buildBody(values);
|
|
108
107
|
if (values.name) body.name = values.name;
|
|
109
108
|
const data = await api('PATCH', `/workspaces/${encodeURIComponent(positionals[0])}`, {
|
|
110
|
-
auth:
|
|
109
|
+
auth: authFromValues(values),
|
|
111
110
|
requiresManagement: true,
|
|
112
111
|
body
|
|
113
112
|
});
|
|
114
|
-
printResult(data
|
|
113
|
+
printResult(data);
|
|
115
114
|
return 0;
|
|
116
115
|
}
|
|
117
116
|
|
|
@@ -119,7 +118,7 @@ export async function workspacesCommand(argv) {
|
|
|
119
118
|
const { values, positionals } = parseArgs(rest, {});
|
|
120
119
|
if (!positionals[0]) throw new Error('id|slug required');
|
|
121
120
|
const data = await api('DELETE', `/workspaces/${encodeURIComponent(positionals[0])}`, {
|
|
122
|
-
auth:
|
|
121
|
+
auth: authFromValues(values),
|
|
123
122
|
requiresManagement: true
|
|
124
123
|
});
|
|
125
124
|
printResult(data, () => outln('deleted'));
|
|
@@ -135,11 +134,11 @@ export async function workspacesCommand(argv) {
|
|
|
135
134
|
? `/workspaces/${encodeURIComponent(id)}/members/add`
|
|
136
135
|
: `/workspaces/${encodeURIComponent(id)}/members/remove`;
|
|
137
136
|
const data = await api('POST', path, {
|
|
138
|
-
auth:
|
|
137
|
+
auth: authFromValues(values),
|
|
139
138
|
requiresManagement: true,
|
|
140
139
|
body: { user_ids: userIds }
|
|
141
140
|
});
|
|
142
|
-
printResult(data
|
|
141
|
+
printResult(data);
|
|
143
142
|
return 0;
|
|
144
143
|
}
|
|
145
144
|
|
package/src/config.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
|
-
import { join
|
|
3
|
+
import { join } from 'node:path';
|
|
4
4
|
|
|
5
5
|
const XDG = process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const CONFIG_DIR = join(XDG, 'openrouter');
|
|
7
|
+
const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
|
|
8
8
|
|
|
9
9
|
export const DEFAULT_BASE_URL = 'https://openrouter.ai/api/v1';
|
|
10
10
|
export const DEFAULT_AUTH_URL = 'https://openrouter.ai/auth';
|
|
11
|
+
export const PROVISIONING_KEYS_URL =
|
|
12
|
+
'https://openrouter.ai/settings/provisioning-keys';
|
|
11
13
|
|
|
12
14
|
export async function loadConfig() {
|
|
13
15
|
try {
|
|
@@ -26,14 +28,6 @@ export async function saveConfig(cfg) {
|
|
|
26
28
|
await fs.rename(tmp, CONFIG_FILE);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
export async function clearConfig() {
|
|
30
|
-
try {
|
|
31
|
-
await fs.unlink(CONFIG_FILE);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
if (err.code !== 'ENOENT') throw err;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
31
|
export async function resolveAuth(opts = {}) {
|
|
38
32
|
const cfg = await loadConfig();
|
|
39
33
|
const userKey =
|
|
@@ -45,12 +39,10 @@ export async function resolveAuth(opts = {}) {
|
|
|
45
39
|
// the regular key); inference commands prefer the regular key (falling back
|
|
46
40
|
// to the management key).
|
|
47
41
|
let apiKey;
|
|
48
|
-
let usedManagementSlot = false;
|
|
49
42
|
if (opts.key) {
|
|
50
43
|
apiKey = opts.key;
|
|
51
44
|
} else if (opts.requiresManagement) {
|
|
52
45
|
apiKey = mgmtKey || userKey;
|
|
53
|
-
usedManagementSlot = !!mgmtKey;
|
|
54
46
|
} else {
|
|
55
47
|
apiKey = userKey || mgmtKey;
|
|
56
48
|
}
|
|
@@ -72,8 +64,6 @@ export async function resolveAuth(opts = {}) {
|
|
|
72
64
|
baseUrl,
|
|
73
65
|
referer,
|
|
74
66
|
title,
|
|
75
|
-
config: cfg,
|
|
76
|
-
usedManagementSlot,
|
|
77
67
|
hasManagementKey: !!mgmtKey,
|
|
78
68
|
hasUserKey: !!userKey
|
|
79
69
|
};
|
package/src/output.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
|
|
1
3
|
const isTTY = process.stdout.isTTY;
|
|
2
4
|
const noColor =
|
|
3
5
|
process.env.NO_COLOR != null ||
|
|
@@ -12,11 +14,7 @@ export const c = {
|
|
|
12
14
|
dim: wrap(2, 22),
|
|
13
15
|
red: wrap(31, 39),
|
|
14
16
|
green: wrap(32, 39),
|
|
15
|
-
|
|
16
|
-
blue: wrap(34, 39),
|
|
17
|
-
magenta: wrap(35, 39),
|
|
18
|
-
cyan: wrap(36, 39),
|
|
19
|
-
gray: wrap(90, 39)
|
|
17
|
+
cyan: wrap(36, 39)
|
|
20
18
|
};
|
|
21
19
|
|
|
22
20
|
let JSON_MODE = false;
|
|
@@ -45,14 +43,26 @@ export function info(text) {
|
|
|
45
43
|
process.stderr.write(c.dim(text) + '\n');
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
export function warn(text) {
|
|
49
|
-
process.stderr.write(c.yellow('warning: ') + text + '\n');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
46
|
export function printJSON(data) {
|
|
53
47
|
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
54
48
|
}
|
|
55
49
|
|
|
50
|
+
// OpenRouter prices are per-token; tables show them per million.
|
|
51
|
+
export function pricePerMillion(x) {
|
|
52
|
+
return x == null ? '-' : (Number(x) * 1e6).toFixed(2);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function writeBinaryOutput(bytes, out) {
|
|
56
|
+
const buf = Buffer.from(bytes);
|
|
57
|
+
if (out === '-') {
|
|
58
|
+
process.stdout.write(buf);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
await writeFile(out, buf);
|
|
62
|
+
if (JSON_MODE) printJSON({ saved: out, bytes: bytes.length });
|
|
63
|
+
else info(`Wrote ${bytes.length} bytes to ${out}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
export function printResult(data, formatter) {
|
|
57
67
|
if (JSON_MODE || !formatter) {
|
|
58
68
|
printJSON(data);
|