@aaronjmars/openroutercli 0.1.4 → 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 -35
- package/SKILL.md +18 -17
- package/package.json +1 -1
- package/src/api.js +11 -0
- package/src/args.js +17 -1
- package/src/cli.js +10 -14
- package/src/commands/account.js +11 -5
- package/src/commands/chat.js +104 -75
- package/src/commands/embed.js +6 -10
- package/src/commands/guardrails.js +21 -12
- package/src/commands/keys.js +11 -2
- package/src/commands/login.js +25 -20
- package/src/commands/messages.js +36 -34
- package/src/commands/misc.js +9 -3
- package/src/commands/models.js +43 -22
- package/src/commands/request.js +1 -1
- package/src/commands/rerank.js +2 -2
- package/src/commands/speech.js +2 -10
- package/src/commands/video.js +21 -10
- package/src/commands/workspaces.js +12 -8
- package/src/config.js +5 -4
- package/src/output.js +1 -5
package/src/commands/messages.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
parseArgs,
|
|
3
|
+
authFromValues,
|
|
4
|
+
numberOption,
|
|
5
|
+
readStdinIfPiped,
|
|
6
|
+
shouldStream
|
|
7
|
+
} from '../args.js';
|
|
8
|
+
import { api, assertNoStreamError, sseStream } from '../api.js';
|
|
4
9
|
import { isJsonMode, out, outln, printJSON } from '../output.js';
|
|
5
10
|
|
|
6
11
|
const HELP = `Usage: openrouter messages [prompt...] [options]
|
|
@@ -36,11 +41,20 @@ Options:
|
|
|
36
41
|
--body <json|@file> Provide a fully-formed body (overrides flags)
|
|
37
42
|
`;
|
|
38
43
|
|
|
39
|
-
async function
|
|
40
|
-
if (
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
async function resolvePrompt(values, positionals) {
|
|
45
|
+
if (!values.model) throw new Error('--model is required');
|
|
46
|
+
let prompt = positionals.join(' ').trim();
|
|
47
|
+
const piped = await readStdinIfPiped();
|
|
48
|
+
if (piped) prompt = prompt ? `${prompt}\n\n${piped}` : piped;
|
|
49
|
+
if (!prompt) throw new Error('No prompt.');
|
|
50
|
+
return prompt;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function applyNumeric(body, values, map) {
|
|
54
|
+
for (const [flag, field] of Object.entries(map)) {
|
|
55
|
+
const n = numberOption(values[flag], `--${flag}`);
|
|
56
|
+
if (n !== undefined) body[field] = n;
|
|
57
|
+
}
|
|
44
58
|
}
|
|
45
59
|
|
|
46
60
|
async function loadBody(value) {
|
|
@@ -70,25 +84,17 @@ export async function messagesCommand(argv) {
|
|
|
70
84
|
|
|
71
85
|
let body = await loadBody(values.body);
|
|
72
86
|
if (!body) {
|
|
73
|
-
|
|
74
|
-
let prompt = positionals.join(' ').trim();
|
|
75
|
-
const piped = await readStdinIfPiped();
|
|
76
|
-
if (piped) prompt = prompt ? `${prompt}\n\n${piped}` : piped;
|
|
77
|
-
if (!prompt) throw new Error('No prompt.');
|
|
87
|
+
const prompt = await resolvePrompt(values, positionals);
|
|
78
88
|
body = {
|
|
79
89
|
model: values.model,
|
|
80
|
-
max_tokens:
|
|
90
|
+
max_tokens: numberOption(values['max-tokens'], '--max-tokens') ?? 1024,
|
|
81
91
|
messages: [{ role: 'user', content: prompt }]
|
|
82
92
|
};
|
|
83
93
|
if (values.system) body.system = values.system;
|
|
84
|
-
|
|
94
|
+
applyNumeric(body, values, { temperature: 'temperature' });
|
|
85
95
|
}
|
|
86
96
|
|
|
87
|
-
|
|
88
|
-
values.stream ||
|
|
89
|
-
(!values['no-stream'] && !values.raw && !isJsonMode() && process.stdout.isTTY);
|
|
90
|
-
|
|
91
|
-
if (shouldStream) {
|
|
97
|
+
if (shouldStream(values)) {
|
|
92
98
|
body.stream = true;
|
|
93
99
|
const res = await api('POST', '/messages', {
|
|
94
100
|
auth: authFromValues(values),
|
|
@@ -97,6 +103,7 @@ export async function messagesCommand(argv) {
|
|
|
97
103
|
headers: { Accept: 'text/event-stream' }
|
|
98
104
|
});
|
|
99
105
|
for await (const evt of sseStream(res)) {
|
|
106
|
+
assertNoStreamError(evt);
|
|
100
107
|
const t = evt.type;
|
|
101
108
|
if (t === 'content_block_delta' && evt.delta && evt.delta.text) {
|
|
102
109
|
out(evt.delta.text);
|
|
@@ -140,25 +147,19 @@ export async function responsesCommand(argv) {
|
|
|
140
147
|
|
|
141
148
|
let body = await loadBody(values.body);
|
|
142
149
|
if (!body) {
|
|
143
|
-
|
|
144
|
-
let prompt = positionals.join(' ').trim();
|
|
145
|
-
const piped = await readStdinIfPiped();
|
|
146
|
-
if (piped) prompt = prompt ? `${prompt}\n\n${piped}` : piped;
|
|
147
|
-
if (!prompt) throw new Error('No prompt.');
|
|
150
|
+
const prompt = await resolvePrompt(values, positionals);
|
|
148
151
|
body = { model: values.model, input: prompt };
|
|
149
152
|
if (values.instructions) body.instructions = values.instructions;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
applyNumeric(body, values, {
|
|
154
|
+
'max-tokens': 'max_output_tokens',
|
|
155
|
+
temperature: 'temperature',
|
|
156
|
+
'top-p': 'top_p',
|
|
157
|
+
seed: 'seed'
|
|
158
|
+
});
|
|
154
159
|
if (values.reasoning) body.reasoning = { effort: values.reasoning };
|
|
155
160
|
}
|
|
156
161
|
|
|
157
|
-
|
|
158
|
-
values.stream ||
|
|
159
|
-
(!values['no-stream'] && !values.raw && !isJsonMode() && process.stdout.isTTY);
|
|
160
|
-
|
|
161
|
-
if (shouldStream) {
|
|
162
|
+
if (shouldStream(values)) {
|
|
162
163
|
body.stream = true;
|
|
163
164
|
const res = await api('POST', '/responses', {
|
|
164
165
|
auth: authFromValues(values),
|
|
@@ -167,6 +168,7 @@ export async function responsesCommand(argv) {
|
|
|
167
168
|
headers: { Accept: 'text/event-stream' }
|
|
168
169
|
});
|
|
169
170
|
for await (const evt of sseStream(res)) {
|
|
171
|
+
assertNoStreamError(evt);
|
|
170
172
|
if (evt.type && evt.type.endsWith('output_text.delta') && evt.delta) {
|
|
171
173
|
out(evt.delta);
|
|
172
174
|
}
|
package/src/commands/misc.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
parseArgs,
|
|
3
|
+
authFromValues,
|
|
4
|
+
numberOption,
|
|
5
|
+
PAGINATION_OPTIONS,
|
|
6
|
+
paginationQuery
|
|
7
|
+
} from '../args.js';
|
|
2
8
|
import { api } from '../api.js';
|
|
3
9
|
import { printResult, table } from '../output.js';
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
async function orgMembersCommand(argv) {
|
|
6
12
|
const { values } = parseArgs(argv, PAGINATION_OPTIONS);
|
|
7
13
|
if (values.help) {
|
|
8
14
|
process.stdout.write(
|
|
@@ -87,7 +93,7 @@ export async function authCodeCommand(argv) {
|
|
|
87
93
|
if (values['code-challenge-method']) body.code_challenge_method = values['code-challenge-method'];
|
|
88
94
|
if (values['expires-at']) body.expires_at = values['expires-at'];
|
|
89
95
|
if (values['key-label']) body.key_label = values['key-label'];
|
|
90
|
-
if (values.limit) body.limit =
|
|
96
|
+
if (values.limit) body.limit = numberOption(values.limit, '--limit');
|
|
91
97
|
if (values['usage-limit-type']) body.usage_limit_type = values['usage-limit-type'];
|
|
92
98
|
const data = await api('POST', '/auth/keys/code', {
|
|
93
99
|
auth: authFromValues(values),
|
package/src/commands/models.js
CHANGED
|
@@ -2,13 +2,26 @@ import { parseArgs, authFromValues } from '../args.js';
|
|
|
2
2
|
import { api } from '../api.js';
|
|
3
3
|
import { c, isJsonMode, outln, pricePerMillion, printResult, table } from '../output.js';
|
|
4
4
|
|
|
5
|
+
const ENDPOINT_SORT_FIELDS = ['throughput', 'latency', 'prompt', 'completion', 'uptime', 'context'];
|
|
6
|
+
const MODEL_SORT_FIELDS = ['id', 'name', 'context', 'prompt', 'completion'];
|
|
7
|
+
|
|
8
|
+
const PRICE_COLUMN = {
|
|
9
|
+
label: 'in/out $/M',
|
|
10
|
+
value: (x) => {
|
|
11
|
+
const p = x.pricing || {};
|
|
12
|
+
return `${pricePerMillion(p.prompt)}/${pricePerMillion(p.completion)}`;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
5
16
|
const HELP = `Usage: openrouter models [subcommand] [options]
|
|
6
17
|
|
|
7
18
|
Subcommands:
|
|
8
19
|
list List all models (default)
|
|
9
20
|
show <id> Full detail for a single model (pricing breakdown,
|
|
10
|
-
architecture, supported params, top provider)
|
|
21
|
+
architecture, supported params, top provider).
|
|
22
|
+
Aliases: info, detail
|
|
11
23
|
endpoints <author>/<slug> List endpoints (provider variants) for a model
|
|
24
|
+
user Models filtered by your workspace preferences
|
|
12
25
|
count Get the total model count
|
|
13
26
|
|
|
14
27
|
Options for list:
|
|
@@ -28,13 +41,7 @@ function listFormatter(data) {
|
|
|
28
41
|
label: 'context',
|
|
29
42
|
value: (m) => (m.context_length || '').toLocaleString?.() ?? m.context_length
|
|
30
43
|
},
|
|
31
|
-
|
|
32
|
-
label: 'in/out $/M',
|
|
33
|
-
value: (m) => {
|
|
34
|
-
const p = m.pricing || {};
|
|
35
|
-
return `${pricePerMillion(p.prompt)}/${pricePerMillion(p.completion)}`;
|
|
36
|
-
}
|
|
37
|
-
},
|
|
44
|
+
PRICE_COLUMN,
|
|
38
45
|
{ label: 'name', value: (m) => m.name || '' }
|
|
39
46
|
]);
|
|
40
47
|
if (rows.length > 200) outln(c.dim(`... ${rows.length - 200} more (use --json for the full list)`));
|
|
@@ -119,7 +126,8 @@ function renderModelDetail(m) {
|
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
export async function modelsCommand(argv) {
|
|
122
|
-
//
|
|
129
|
+
// A leading non-flag token is the subcommand; otherwise default to list
|
|
130
|
+
// and keep argv intact so the list branch still sees its flags.
|
|
123
131
|
const sub = argv[0] && !argv[0].startsWith('-') ? argv[0] : 'list';
|
|
124
132
|
const rest = sub === argv[0] ? argv.slice(1) : argv;
|
|
125
133
|
|
|
@@ -182,6 +190,11 @@ export async function modelsCommand(argv) {
|
|
|
182
190
|
);
|
|
183
191
|
return values.help ? 0 : 1;
|
|
184
192
|
}
|
|
193
|
+
if (values.sort && !ENDPOINT_SORT_FIELDS.includes(values.sort)) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`Unknown --sort field "${values.sort}". Expected: ${ENDPOINT_SORT_FIELDS.join(' | ')}`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
185
198
|
const target = positionals[0];
|
|
186
199
|
const slash = target.indexOf('/');
|
|
187
200
|
if (slash === -1) throw new Error('Expected <author>/<slug>');
|
|
@@ -205,7 +218,6 @@ export async function modelsCommand(argv) {
|
|
|
205
218
|
case 'completion': return Number(p.completion ?? Infinity);
|
|
206
219
|
case 'uptime': return -(e.uptime_last_30m ?? -Infinity);
|
|
207
220
|
case 'context': return -(e.context_length ?? -Infinity);
|
|
208
|
-
default: return 0;
|
|
209
221
|
}
|
|
210
222
|
};
|
|
211
223
|
eps = [...eps].sort((a, b) => {
|
|
@@ -222,13 +234,7 @@ export async function modelsCommand(argv) {
|
|
|
222
234
|
{ label: 'provider', value: (e) => e.provider_name || e.name || '' },
|
|
223
235
|
{ label: 'context', value: (e) => e.context_length ?? '' },
|
|
224
236
|
{ label: 'max_out', value: (e) => e.max_completion_tokens ?? '' },
|
|
225
|
-
|
|
226
|
-
label: 'in/out $/M',
|
|
227
|
-
value: (e) => {
|
|
228
|
-
const p = e.pricing || {};
|
|
229
|
-
return `${pricePerMillion(p.prompt)}/${pricePerMillion(p.completion)}`;
|
|
230
|
-
}
|
|
231
|
-
},
|
|
237
|
+
PRICE_COLUMN,
|
|
232
238
|
{
|
|
233
239
|
label: 'tput p50',
|
|
234
240
|
value: (e) =>
|
|
@@ -284,7 +290,6 @@ export async function modelsCommand(argv) {
|
|
|
284
290
|
return 0;
|
|
285
291
|
}
|
|
286
292
|
|
|
287
|
-
// list
|
|
288
293
|
const { values } = parseArgs(rest, {
|
|
289
294
|
category: { type: 'string' },
|
|
290
295
|
supported: { type: 'string' },
|
|
@@ -322,14 +327,30 @@ export async function modelsCommand(argv) {
|
|
|
322
327
|
|
|
323
328
|
if (values.sort) {
|
|
324
329
|
const key = values.sort;
|
|
330
|
+
if (!MODEL_SORT_FIELDS.includes(key)) {
|
|
331
|
+
throw new Error(
|
|
332
|
+
`Unknown --sort field "${key}". Expected: ${MODEL_SORT_FIELDS.join(' | ')}`
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
// Unparseable or missing values must score to a definite extreme, or the
|
|
336
|
+
// comparator reports them equal to everything and the sort is a no-op.
|
|
337
|
+
const num = (x) => {
|
|
338
|
+
if (x == null || x === '') return null;
|
|
339
|
+
const n = Number(x);
|
|
340
|
+
return Number.isFinite(n) ? n : null;
|
|
341
|
+
};
|
|
342
|
+
const asc = (x) => num(x) ?? Infinity;
|
|
343
|
+
const desc = (x) => {
|
|
344
|
+
const n = num(x);
|
|
345
|
+
return n === null ? Infinity : -n;
|
|
346
|
+
};
|
|
325
347
|
const get = (m) => {
|
|
326
348
|
switch (key) {
|
|
327
349
|
case 'id': return m.id || '';
|
|
328
350
|
case 'name': return m.name || '';
|
|
329
|
-
case 'context': return
|
|
330
|
-
case 'prompt': return
|
|
331
|
-
case 'completion': return
|
|
332
|
-
default: return 0;
|
|
351
|
+
case 'context': return desc(m.context_length);
|
|
352
|
+
case 'prompt': return asc(m.pricing?.prompt);
|
|
353
|
+
case 'completion': return asc(m.pricing?.completion);
|
|
333
354
|
}
|
|
334
355
|
};
|
|
335
356
|
rows = [...rows].sort((a, b) => {
|
package/src/commands/request.js
CHANGED
package/src/commands/rerank.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { stdin } from 'node:process';
|
|
2
|
-
import { parseArgs, authFromValues } from '../args.js';
|
|
2
|
+
import { parseArgs, authFromValues, numberOption } from '../args.js';
|
|
3
3
|
import { api } from '../api.js';
|
|
4
4
|
import { c, outln, printResult } from '../output.js';
|
|
5
5
|
|
|
@@ -54,7 +54,7 @@ export async function rerankCommand(argv) {
|
|
|
54
54
|
query: values.query,
|
|
55
55
|
documents: docs
|
|
56
56
|
};
|
|
57
|
-
if (values['top-n']) body.top_n =
|
|
57
|
+
if (values['top-n']) body.top_n = numberOption(values['top-n'], '--top-n');
|
|
58
58
|
if (values.provider) body.provider = JSON.parse(values.provider);
|
|
59
59
|
|
|
60
60
|
const data = await api('POST', '/rerank', {
|
package/src/commands/speech.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { parseArgs, authFromValues } from '../args.js';
|
|
1
|
+
import { parseArgs, authFromValues, numberOption, readStdinIfPiped } from '../args.js';
|
|
3
2
|
import { api } from '../api.js';
|
|
4
3
|
import { writeBinaryOutput } from '../output.js';
|
|
5
4
|
|
|
@@ -16,13 +15,6 @@ Options:
|
|
|
16
15
|
--provider <json>
|
|
17
16
|
`;
|
|
18
17
|
|
|
19
|
-
async function readStdinIfPiped() {
|
|
20
|
-
if (stdin.isTTY) return null;
|
|
21
|
-
let data = '';
|
|
22
|
-
for await (const chunk of stdin) data += chunk;
|
|
23
|
-
return data.trim() || null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
18
|
export async function speechCommand(argv) {
|
|
27
19
|
const { values, positionals } = parseArgs(argv, {
|
|
28
20
|
model: { type: 'string', short: 'm' },
|
|
@@ -46,7 +38,7 @@ export async function speechCommand(argv) {
|
|
|
46
38
|
const body = { model: values.model, input: text };
|
|
47
39
|
if (values.voice) body.voice = values.voice;
|
|
48
40
|
if (values.format) body.response_format = values.format;
|
|
49
|
-
if (values.speed) body.speed =
|
|
41
|
+
if (values.speed) body.speed = numberOption(values.speed, '--speed');
|
|
50
42
|
if (values.provider) body.provider = JSON.parse(values.provider);
|
|
51
43
|
|
|
52
44
|
const bytes = await api('POST', '/audio/speech', {
|
package/src/commands/video.js
CHANGED
|
@@ -2,6 +2,9 @@ import { parseArgs, authFromValues, numberOption } from '../args.js';
|
|
|
2
2
|
import { api } from '../api.js';
|
|
3
3
|
import { c, info, outln, printResult, writeBinaryOutput } from '../output.js';
|
|
4
4
|
|
|
5
|
+
const FAILED_STATUSES = ['failed', 'cancelled', 'error'];
|
|
6
|
+
const TERMINAL_STATUSES = ['succeeded', 'completed', ...FAILED_STATUSES];
|
|
7
|
+
|
|
5
8
|
const HELP = `Usage: openrouter video <subcommand> [options]
|
|
6
9
|
|
|
7
10
|
Subcommands:
|
|
@@ -9,7 +12,11 @@ Subcommands:
|
|
|
9
12
|
models List video models
|
|
10
13
|
get <jobId> Get job status
|
|
11
14
|
download <jobId> [-o file] Download generated video content
|
|
12
|
-
wait <jobId>
|
|
15
|
+
wait <jobId> [options] Poll until the job completes
|
|
16
|
+
|
|
17
|
+
wait options:
|
|
18
|
+
--interval <s> Seconds between polls (default: 5)
|
|
19
|
+
--timeout <s> Give up after this many seconds (default: 600)
|
|
13
20
|
|
|
14
21
|
create options:
|
|
15
22
|
-m, --model <id> Video model id (required)
|
|
@@ -27,16 +34,20 @@ async function sleep(ms) {
|
|
|
27
34
|
export async function videoCommand(argv) {
|
|
28
35
|
const sub = argv[0];
|
|
29
36
|
const rest = argv.slice(1);
|
|
30
|
-
const auth = (vals) => authFromValues(vals);
|
|
31
37
|
|
|
32
38
|
if (!sub || sub === '-h' || sub === '--help' || sub === 'help') {
|
|
33
39
|
process.stdout.write(HELP);
|
|
34
40
|
return sub ? 0 : 1;
|
|
35
41
|
}
|
|
36
42
|
|
|
43
|
+
if (rest.includes('-h') || rest.includes('--help')) {
|
|
44
|
+
process.stdout.write(HELP);
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
37
48
|
if (sub === 'models') {
|
|
38
49
|
const { values } = parseArgs(rest, {});
|
|
39
|
-
const data = await api('GET', '/videos/models', { auth:
|
|
50
|
+
const data = await api('GET', '/videos/models', { auth: authFromValues(values) });
|
|
40
51
|
printResult(data);
|
|
41
52
|
return 0;
|
|
42
53
|
}
|
|
@@ -54,12 +65,12 @@ export async function videoCommand(argv) {
|
|
|
54
65
|
const prompt = values.prompt || positionals.join(' ').trim();
|
|
55
66
|
if (!prompt) throw new Error('Prompt is required');
|
|
56
67
|
const body = { model: values.model, prompt };
|
|
57
|
-
if (values.duration) body.duration =
|
|
68
|
+
if (values.duration) body.duration = numberOption(values.duration, '--duration');
|
|
58
69
|
if (values.aspect) body.aspect_ratio = values.aspect;
|
|
59
70
|
if (values.provider) body.provider = JSON.parse(values.provider);
|
|
60
71
|
if (values.extra) Object.assign(body, JSON.parse(values.extra));
|
|
61
72
|
|
|
62
|
-
const data = await api('POST', '/videos', { auth:
|
|
73
|
+
const data = await api('POST', '/videos', { auth: authFromValues(values), body });
|
|
63
74
|
printResult(data, () => {
|
|
64
75
|
const id = data.id || data.job_id || (data.data && data.data.id);
|
|
65
76
|
outln(`${c.bold('job:')} ${id}`);
|
|
@@ -72,7 +83,7 @@ export async function videoCommand(argv) {
|
|
|
72
83
|
const { values, positionals } = parseArgs(rest, {});
|
|
73
84
|
if (!positionals[0]) throw new Error('jobId required');
|
|
74
85
|
const data = await api('GET', `/videos/${encodeURIComponent(positionals[0])}`, {
|
|
75
|
-
auth:
|
|
86
|
+
auth: authFromValues(values)
|
|
76
87
|
});
|
|
77
88
|
printResult(data);
|
|
78
89
|
return 0;
|
|
@@ -91,13 +102,13 @@ export async function videoCommand(argv) {
|
|
|
91
102
|
const start = Date.now();
|
|
92
103
|
while (true) {
|
|
93
104
|
const data = await api('GET', `/videos/${encodeURIComponent(positionals[0])}`, {
|
|
94
|
-
auth:
|
|
105
|
+
auth: authFromValues(values)
|
|
95
106
|
});
|
|
96
107
|
const status = data.status || (data.data && data.data.status);
|
|
97
108
|
info(`status: ${status}`);
|
|
98
|
-
if (
|
|
109
|
+
if (TERMINAL_STATUSES.includes(status)) {
|
|
99
110
|
printResult(data);
|
|
100
|
-
return
|
|
111
|
+
return FAILED_STATUSES.includes(status) ? 4 : 0;
|
|
101
112
|
}
|
|
102
113
|
if (Date.now() - start > timeout) {
|
|
103
114
|
throw new Error('timeout waiting for job');
|
|
@@ -112,7 +123,7 @@ export async function videoCommand(argv) {
|
|
|
112
123
|
});
|
|
113
124
|
if (!positionals[0]) throw new Error('jobId required');
|
|
114
125
|
const bytes = await api('GET', `/videos/${encodeURIComponent(positionals[0])}/content`, {
|
|
115
|
-
auth:
|
|
126
|
+
auth: authFromValues(values),
|
|
116
127
|
binary: true
|
|
117
128
|
});
|
|
118
129
|
const out = values.out || `${positionals[0]}.mp4`;
|
|
@@ -7,7 +7,7 @@ const HELP = `Usage: openrouter workspaces <subcommand> [options]
|
|
|
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,13 +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
59
|
const { values } = parseArgs(rest, PAGINATION_OPTIONS);
|
|
56
60
|
const query = paginationQuery(values);
|
|
57
61
|
const data = await api('GET', '/workspaces', {
|
|
58
|
-
auth:
|
|
62
|
+
auth: authFromValues(values),
|
|
59
63
|
requiresManagement: true,
|
|
60
64
|
query
|
|
61
65
|
});
|
|
@@ -75,7 +79,7 @@ export async function workspacesCommand(argv) {
|
|
|
75
79
|
const { values, positionals } = parseArgs(rest, {});
|
|
76
80
|
if (!positionals[0]) throw new Error('id|slug required');
|
|
77
81
|
const data = await api('GET', `/workspaces/${encodeURIComponent(positionals[0])}`, {
|
|
78
|
-
auth:
|
|
82
|
+
auth: authFromValues(values),
|
|
79
83
|
requiresManagement: true
|
|
80
84
|
});
|
|
81
85
|
printResult(data);
|
|
@@ -88,7 +92,7 @@ export async function workspacesCommand(argv) {
|
|
|
88
92
|
if (!name) throw new Error('name required');
|
|
89
93
|
const body = { name, ...buildBody(values) };
|
|
90
94
|
const data = await api('POST', '/workspaces', {
|
|
91
|
-
auth:
|
|
95
|
+
auth: authFromValues(values),
|
|
92
96
|
requiresManagement: true,
|
|
93
97
|
body
|
|
94
98
|
});
|
|
@@ -102,7 +106,7 @@ export async function workspacesCommand(argv) {
|
|
|
102
106
|
const body = buildBody(values);
|
|
103
107
|
if (values.name) body.name = values.name;
|
|
104
108
|
const data = await api('PATCH', `/workspaces/${encodeURIComponent(positionals[0])}`, {
|
|
105
|
-
auth:
|
|
109
|
+
auth: authFromValues(values),
|
|
106
110
|
requiresManagement: true,
|
|
107
111
|
body
|
|
108
112
|
});
|
|
@@ -114,7 +118,7 @@ export async function workspacesCommand(argv) {
|
|
|
114
118
|
const { values, positionals } = parseArgs(rest, {});
|
|
115
119
|
if (!positionals[0]) throw new Error('id|slug required');
|
|
116
120
|
const data = await api('DELETE', `/workspaces/${encodeURIComponent(positionals[0])}`, {
|
|
117
|
-
auth:
|
|
121
|
+
auth: authFromValues(values),
|
|
118
122
|
requiresManagement: true
|
|
119
123
|
});
|
|
120
124
|
printResult(data, () => outln('deleted'));
|
|
@@ -130,7 +134,7 @@ export async function workspacesCommand(argv) {
|
|
|
130
134
|
? `/workspaces/${encodeURIComponent(id)}/members/add`
|
|
131
135
|
: `/workspaces/${encodeURIComponent(id)}/members/remove`;
|
|
132
136
|
const data = await api('POST', path, {
|
|
133
|
-
auth:
|
|
137
|
+
auth: authFromValues(values),
|
|
134
138
|
requiresManagement: true,
|
|
135
139
|
body: { user_ids: userIds }
|
|
136
140
|
});
|
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 {
|
|
@@ -62,7 +64,6 @@ export async function resolveAuth(opts = {}) {
|
|
|
62
64
|
baseUrl,
|
|
63
65
|
referer,
|
|
64
66
|
title,
|
|
65
|
-
config: cfg,
|
|
66
67
|
hasManagementKey: !!mgmtKey,
|
|
67
68
|
hasUserKey: !!userKey
|
|
68
69
|
};
|
package/src/output.js
CHANGED
|
@@ -14,11 +14,7 @@ export const c = {
|
|
|
14
14
|
dim: wrap(2, 22),
|
|
15
15
|
red: wrap(31, 39),
|
|
16
16
|
green: wrap(32, 39),
|
|
17
|
-
|
|
18
|
-
blue: wrap(34, 39),
|
|
19
|
-
magenta: wrap(35, 39),
|
|
20
|
-
cyan: wrap(36, 39),
|
|
21
|
-
gray: wrap(90, 39)
|
|
17
|
+
cyan: wrap(36, 39)
|
|
22
18
|
};
|
|
23
19
|
|
|
24
20
|
let JSON_MODE = false;
|