@aaronjmars/openroutercli 0.1.4 → 0.2.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/README.md +40 -35
- package/SKILL.md +18 -17
- package/bin/openrouter.js +3 -3
- package/package.json +7 -2
- package/src/api.js +44 -22
- package/src/args.js +29 -14
- package/src/cli.js +60 -46
- package/src/commands/account.js +54 -46
- package/src/commands/byok.js +153 -0
- package/src/commands/chat.js +304 -154
- package/src/commands/embed.js +35 -34
- package/src/commands/files.js +102 -0
- package/src/commands/generation.js +10 -10
- package/src/commands/guardrails.js +115 -87
- package/src/commands/image.js +149 -0
- package/src/commands/keys.js +70 -55
- package/src/commands/login.js +101 -100
- package/src/commands/messages.js +143 -77
- package/src/commands/misc.js +51 -45
- package/src/commands/models.js +246 -149
- package/src/commands/presets.js +93 -0
- package/src/commands/request.js +21 -21
- package/src/commands/rerank.js +33 -25
- package/src/commands/speech.js +16 -24
- package/src/commands/transcribe.js +62 -0
- package/src/commands/video.js +58 -44
- package/src/commands/workspaces.js +60 -52
- package/src/config.js +17 -22
- package/src/output.js +13 -30
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { parseArgs, authFromValues, PAGINATION_OPTIONS, paginationQuery } from
|
|
2
|
-
import { api } from
|
|
3
|
-
import { outln, printResult, table } from
|
|
1
|
+
import { parseArgs, authFromValues, PAGINATION_OPTIONS, paginationQuery } from "../args.js";
|
|
2
|
+
import { api } from "../api.js";
|
|
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>
|
|
@@ -24,115 +25,122 @@ create / update options:
|
|
|
24
25
|
`;
|
|
25
26
|
|
|
26
27
|
const COMMON = {
|
|
27
|
-
slug: { type:
|
|
28
|
-
description: { type:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
slug: { type: "string" },
|
|
29
|
+
description: { type: "string" },
|
|
30
|
+
"default-text-model": { type: "string" },
|
|
31
|
+
"default-image-model": { type: "string" },
|
|
32
|
+
"default-provider-sort": { type: "string" },
|
|
32
33
|
};
|
|
33
34
|
|
|
34
35
|
function buildBody(values) {
|
|
35
36
|
const body = {};
|
|
36
37
|
if (values.slug !== undefined) body.slug = values.slug;
|
|
37
38
|
if (values.description !== undefined) body.description = values.description;
|
|
38
|
-
if (values[
|
|
39
|
-
|
|
40
|
-
if (values[
|
|
39
|
+
if (values["default-text-model"] !== undefined)
|
|
40
|
+
body.default_text_model = values["default-text-model"];
|
|
41
|
+
if (values["default-image-model"] !== undefined)
|
|
42
|
+
body.default_image_model = values["default-image-model"];
|
|
43
|
+
if (values["default-provider-sort"] !== undefined)
|
|
44
|
+
body.default_provider_sort = values["default-provider-sort"];
|
|
41
45
|
return body;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
export async function workspacesCommand(argv) {
|
|
45
49
|
const sub = argv[0];
|
|
46
50
|
const rest = argv.slice(1);
|
|
47
|
-
if (!sub || sub ===
|
|
51
|
+
if (!sub || sub === "help" || sub === "-h" || sub === "--help") {
|
|
48
52
|
process.stdout.write(HELP);
|
|
49
53
|
return sub ? 0 : 1;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
if (rest.includes("-h") || rest.includes("--help")) {
|
|
57
|
+
process.stdout.write(HELP);
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
53
60
|
|
|
54
|
-
if (sub ===
|
|
61
|
+
if (sub === "list") {
|
|
55
62
|
const { values } = parseArgs(rest, PAGINATION_OPTIONS);
|
|
56
63
|
const query = paginationQuery(values);
|
|
57
|
-
const data = await api(
|
|
58
|
-
auth:
|
|
64
|
+
const data = await api("GET", "/workspaces", {
|
|
65
|
+
auth: authFromValues(values),
|
|
59
66
|
requiresManagement: true,
|
|
60
|
-
query
|
|
67
|
+
query,
|
|
61
68
|
});
|
|
62
69
|
printResult(data, () => {
|
|
63
70
|
const rows = data.data || [];
|
|
64
71
|
table(rows, [
|
|
65
|
-
{ label:
|
|
66
|
-
{ label:
|
|
67
|
-
{ label:
|
|
68
|
-
{ label:
|
|
72
|
+
{ label: "slug", value: (w) => w.slug || "" },
|
|
73
|
+
{ label: "name", value: (w) => w.name || "" },
|
|
74
|
+
{ label: "id", value: (w) => w.id || "" },
|
|
75
|
+
{ label: "is_default", value: (w) => (w.is_default ? "yes" : "") },
|
|
69
76
|
]);
|
|
70
77
|
});
|
|
71
78
|
return 0;
|
|
72
79
|
}
|
|
73
80
|
|
|
74
|
-
if (sub ===
|
|
81
|
+
if (sub === "get") {
|
|
75
82
|
const { values, positionals } = parseArgs(rest, {});
|
|
76
|
-
if (!positionals[0]) throw new Error(
|
|
77
|
-
const data = await api(
|
|
78
|
-
auth:
|
|
79
|
-
requiresManagement: true
|
|
83
|
+
if (!positionals[0]) throw new Error("id|slug required");
|
|
84
|
+
const data = await api("GET", `/workspaces/${encodeURIComponent(positionals[0])}`, {
|
|
85
|
+
auth: authFromValues(values),
|
|
86
|
+
requiresManagement: true,
|
|
80
87
|
});
|
|
81
88
|
printResult(data);
|
|
82
89
|
return 0;
|
|
83
90
|
}
|
|
84
91
|
|
|
85
|
-
if (sub ===
|
|
92
|
+
if (sub === "create") {
|
|
86
93
|
const { values, positionals } = parseArgs(rest, COMMON);
|
|
87
94
|
const name = positionals[0];
|
|
88
|
-
if (!name) throw new Error(
|
|
95
|
+
if (!name) throw new Error("name required");
|
|
89
96
|
const body = { name, ...buildBody(values) };
|
|
90
|
-
const data = await api(
|
|
91
|
-
auth:
|
|
97
|
+
const data = await api("POST", "/workspaces", {
|
|
98
|
+
auth: authFromValues(values),
|
|
92
99
|
requiresManagement: true,
|
|
93
|
-
body
|
|
100
|
+
body,
|
|
94
101
|
});
|
|
95
102
|
printResult(data);
|
|
96
103
|
return 0;
|
|
97
104
|
}
|
|
98
105
|
|
|
99
|
-
if (sub ===
|
|
100
|
-
const { values, positionals } = parseArgs(rest, { ...COMMON, name: { type:
|
|
101
|
-
if (!positionals[0]) throw new Error(
|
|
106
|
+
if (sub === "update") {
|
|
107
|
+
const { values, positionals } = parseArgs(rest, { ...COMMON, name: { type: "string" } });
|
|
108
|
+
if (!positionals[0]) throw new Error("id|slug required");
|
|
102
109
|
const body = buildBody(values);
|
|
103
110
|
if (values.name) body.name = values.name;
|
|
104
|
-
const data = await api(
|
|
105
|
-
auth:
|
|
111
|
+
const data = await api("PATCH", `/workspaces/${encodeURIComponent(positionals[0])}`, {
|
|
112
|
+
auth: authFromValues(values),
|
|
106
113
|
requiresManagement: true,
|
|
107
|
-
body
|
|
114
|
+
body,
|
|
108
115
|
});
|
|
109
116
|
printResult(data);
|
|
110
117
|
return 0;
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
if (sub ===
|
|
120
|
+
if (sub === "delete") {
|
|
114
121
|
const { values, positionals } = parseArgs(rest, {});
|
|
115
|
-
if (!positionals[0]) throw new Error(
|
|
116
|
-
const data = await api(
|
|
117
|
-
auth:
|
|
118
|
-
requiresManagement: true
|
|
122
|
+
if (!positionals[0]) throw new Error("id|slug required");
|
|
123
|
+
const data = await api("DELETE", `/workspaces/${encodeURIComponent(positionals[0])}`, {
|
|
124
|
+
auth: authFromValues(values),
|
|
125
|
+
requiresManagement: true,
|
|
119
126
|
});
|
|
120
|
-
printResult(data, () => outln(
|
|
127
|
+
printResult(data, () => outln("deleted"));
|
|
121
128
|
return 0;
|
|
122
129
|
}
|
|
123
130
|
|
|
124
|
-
if (sub ===
|
|
131
|
+
if (sub === "add-members" || sub === "remove-members") {
|
|
125
132
|
const { values, positionals } = parseArgs(rest, {});
|
|
126
|
-
if (positionals.length < 2) throw new Error(
|
|
133
|
+
if (positionals.length < 2) throw new Error("Usage: <id|slug> <userId>...");
|
|
127
134
|
const id = positionals[0];
|
|
128
135
|
const userIds = positionals.slice(1);
|
|
129
|
-
const path =
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
const path =
|
|
137
|
+
sub === "add-members"
|
|
138
|
+
? `/workspaces/${encodeURIComponent(id)}/members/add`
|
|
139
|
+
: `/workspaces/${encodeURIComponent(id)}/members/remove`;
|
|
140
|
+
const data = await api("POST", path, {
|
|
141
|
+
auth: authFromValues(values),
|
|
134
142
|
requiresManagement: true,
|
|
135
|
-
body: { user_ids: userIds }
|
|
143
|
+
body: { user_ids: userIds },
|
|
136
144
|
});
|
|
137
145
|
printResult(data);
|
|
138
146
|
return 0;
|
package/src/config.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { promises as fs } from
|
|
2
|
-
import { homedir } from
|
|
3
|
-
import { join
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
4
|
|
|
5
|
-
const XDG = process.env.XDG_CONFIG_HOME || join(homedir(),
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const XDG = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
6
|
+
const CONFIG_DIR = join(XDG, "openrouter");
|
|
7
|
+
const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
8
8
|
|
|
9
|
-
export const DEFAULT_BASE_URL =
|
|
10
|
-
export const DEFAULT_AUTH_URL =
|
|
9
|
+
export const DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
|
|
10
|
+
export const DEFAULT_AUTH_URL = "https://openrouter.ai/auth";
|
|
11
|
+
export const PROVISIONING_KEYS_URL = "https://openrouter.ai/settings/provisioning-keys";
|
|
11
12
|
|
|
12
13
|
export async function loadConfig() {
|
|
13
14
|
try {
|
|
14
|
-
const raw = await fs.readFile(CONFIG_FILE,
|
|
15
|
+
const raw = await fs.readFile(CONFIG_FILE, "utf8");
|
|
15
16
|
return JSON.parse(raw);
|
|
16
17
|
} catch (err) {
|
|
17
|
-
if (err.code ===
|
|
18
|
+
if (err.code === "ENOENT") return {};
|
|
18
19
|
throw err;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export async function saveConfig(cfg) {
|
|
23
24
|
await fs.mkdir(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
24
|
-
const tmp = CONFIG_FILE +
|
|
25
|
+
const tmp = CONFIG_FILE + ".tmp";
|
|
25
26
|
await fs.writeFile(tmp, JSON.stringify(cfg, null, 2), { mode: 0o600 });
|
|
26
27
|
await fs.rename(tmp, CONFIG_FILE);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export async function resolveAuth(opts = {}) {
|
|
30
31
|
const cfg = await loadConfig();
|
|
31
|
-
const userKey =
|
|
32
|
-
process.env.OPENROUTER_API_KEY || process.env.OPENROUTER_KEY || cfg.apiKey;
|
|
32
|
+
const userKey = process.env.OPENROUTER_API_KEY || process.env.OPENROUTER_KEY || cfg.apiKey;
|
|
33
33
|
const mgmtKey = process.env.OPENROUTER_MANAGEMENT_KEY || cfg.managementKey;
|
|
34
34
|
|
|
35
35
|
// If the caller explicitly passed --key, that always wins.
|
|
@@ -46,24 +46,19 @@ export async function resolveAuth(opts = {}) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const baseUrl =
|
|
49
|
-
opts.baseUrl ||
|
|
50
|
-
process.env.OPENROUTER_BASE_URL ||
|
|
51
|
-
cfg.baseUrl ||
|
|
52
|
-
DEFAULT_BASE_URL;
|
|
49
|
+
opts.baseUrl || process.env.OPENROUTER_BASE_URL || cfg.baseUrl || DEFAULT_BASE_URL;
|
|
53
50
|
const referer =
|
|
54
51
|
opts.referer ||
|
|
55
52
|
process.env.OPENROUTER_REFERER ||
|
|
56
53
|
cfg.referer ||
|
|
57
|
-
|
|
58
|
-
const title =
|
|
59
|
-
opts.title || process.env.OPENROUTER_TITLE || cfg.title || 'openrouter-cli';
|
|
54
|
+
"https://github.com/aaronjmars/openroutercli";
|
|
55
|
+
const title = opts.title || process.env.OPENROUTER_TITLE || cfg.title || "openrouter-cli";
|
|
60
56
|
return {
|
|
61
57
|
apiKey,
|
|
62
58
|
baseUrl,
|
|
63
59
|
referer,
|
|
64
60
|
title,
|
|
65
|
-
config: cfg,
|
|
66
61
|
hasManagementKey: !!mgmtKey,
|
|
67
|
-
hasUserKey: !!userKey
|
|
62
|
+
hasUserKey: !!userKey,
|
|
68
63
|
};
|
|
69
64
|
}
|
package/src/output.js
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import { writeFile } from
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
2
|
|
|
3
3
|
const isTTY = process.stdout.isTTY;
|
|
4
|
-
const noColor =
|
|
5
|
-
process.env.NO_COLOR != null ||
|
|
6
|
-
process.env.OPENROUTER_NO_COLOR != null ||
|
|
7
|
-
!isTTY;
|
|
4
|
+
const noColor = process.env.NO_COLOR != null || process.env.OPENROUTER_NO_COLOR != null || !isTTY;
|
|
8
5
|
|
|
9
|
-
const wrap = (open, close) => (s) =>
|
|
10
|
-
noColor ? String(s) : `\x1b[${open}m${s}\x1b[${close}m`;
|
|
6
|
+
const wrap = (open, close) => (s) => (noColor ? String(s) : `\x1b[${open}m${s}\x1b[${close}m`);
|
|
11
7
|
|
|
12
8
|
export const c = {
|
|
13
9
|
bold: wrap(1, 22),
|
|
14
10
|
dim: wrap(2, 22),
|
|
15
11
|
red: wrap(31, 39),
|
|
16
12
|
green: wrap(32, 39),
|
|
17
|
-
yellow: wrap(33, 39),
|
|
18
|
-
blue: wrap(34, 39),
|
|
19
|
-
magenta: wrap(35, 39),
|
|
20
13
|
cyan: wrap(36, 39),
|
|
21
|
-
gray: wrap(90, 39)
|
|
22
14
|
};
|
|
23
15
|
|
|
24
16
|
let JSON_MODE = false;
|
|
@@ -38,27 +30,27 @@ export function out(text) {
|
|
|
38
30
|
process.stdout.write(text);
|
|
39
31
|
}
|
|
40
32
|
|
|
41
|
-
export function outln(text =
|
|
42
|
-
process.stdout.write(text +
|
|
33
|
+
export function outln(text = "") {
|
|
34
|
+
process.stdout.write(text + "\n");
|
|
43
35
|
}
|
|
44
36
|
|
|
45
37
|
export function info(text) {
|
|
46
38
|
if (QUIET || JSON_MODE) return;
|
|
47
|
-
process.stderr.write(c.dim(text) +
|
|
39
|
+
process.stderr.write(c.dim(text) + "\n");
|
|
48
40
|
}
|
|
49
41
|
|
|
50
42
|
export function printJSON(data) {
|
|
51
|
-
process.stdout.write(JSON.stringify(data, null, 2) +
|
|
43
|
+
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
52
44
|
}
|
|
53
45
|
|
|
54
46
|
// OpenRouter prices are per-token; tables show them per million.
|
|
55
47
|
export function pricePerMillion(x) {
|
|
56
|
-
return x == null ?
|
|
48
|
+
return x == null ? "-" : (Number(x) * 1e6).toFixed(2);
|
|
57
49
|
}
|
|
58
50
|
|
|
59
51
|
export async function writeBinaryOutput(bytes, out) {
|
|
60
52
|
const buf = Buffer.from(bytes);
|
|
61
|
-
if (out ===
|
|
53
|
+
if (out === "-") {
|
|
62
54
|
process.stdout.write(buf);
|
|
63
55
|
return;
|
|
64
56
|
}
|
|
@@ -78,21 +70,12 @@ export function printResult(data, formatter) {
|
|
|
78
70
|
export function table(rows, columns) {
|
|
79
71
|
if (rows.length === 0) return;
|
|
80
72
|
const widths = columns.map((col) =>
|
|
81
|
-
Math.max(
|
|
82
|
-
col.label.length,
|
|
83
|
-
...rows.map((r) => String(col.value(r) ?? '').length)
|
|
84
|
-
)
|
|
73
|
+
Math.max(col.label.length, ...rows.map((r) => String(col.value(r) ?? "").length)),
|
|
85
74
|
);
|
|
86
|
-
const header = columns
|
|
87
|
-
.map((col, i) => c.bold(col.label.padEnd(widths[i])))
|
|
88
|
-
.join(' ');
|
|
75
|
+
const header = columns.map((col, i) => c.bold(col.label.padEnd(widths[i]))).join(" ");
|
|
89
76
|
outln(header);
|
|
90
|
-
outln(columns.map((_, i) => c.dim(
|
|
77
|
+
outln(columns.map((_, i) => c.dim("-".repeat(widths[i]))).join(" "));
|
|
91
78
|
for (const row of rows) {
|
|
92
|
-
outln(
|
|
93
|
-
columns
|
|
94
|
-
.map((col, i) => String(col.value(row) ?? '').padEnd(widths[i]))
|
|
95
|
-
.join(' ')
|
|
96
|
-
);
|
|
79
|
+
outln(columns.map((col, i) => String(col.value(row) ?? "").padEnd(widths[i])).join(" "));
|
|
97
80
|
}
|
|
98
81
|
}
|