@aaronjmars/openroutercli 0.2.2 → 0.4.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 +39 -7
- package/SKILL.md +93 -22
- package/package.json +1 -1
- package/src/api.js +24 -4
- package/src/args.js +50 -0
- package/src/cli.js +68 -11
- package/src/commands/account.js +48 -4
- package/src/commands/batches.js +358 -0
- package/src/commands/byok.js +114 -40
- package/src/commands/chat.js +277 -43
- package/src/commands/containers.js +75 -0
- package/src/commands/data.js +376 -0
- package/src/commands/decisions.js +96 -0
- package/src/commands/embed.js +35 -10
- package/src/commands/files.js +61 -10
- package/src/commands/generation.js +78 -9
- package/src/commands/guardrails.js +131 -11
- package/src/commands/image.js +43 -12
- package/src/commands/keys.js +59 -11
- package/src/commands/messages.js +231 -47
- package/src/commands/misc.js +76 -11
- package/src/commands/models.js +164 -26
- package/src/commands/observability.js +267 -0
- package/src/commands/presets.js +62 -3
- package/src/commands/rerank.js +28 -6
- package/src/commands/speech.js +80 -15
- package/src/commands/tools.js +102 -0
- package/src/commands/transcribe.js +113 -13
- package/src/commands/video.js +112 -14
- package/src/commands/workspaces.js +201 -6
- package/src/config.js +3 -0
- package/src/media.js +44 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { parseArgs, authFromValues, numberOption } from "../args.js";
|
|
2
|
+
import { api } from "../api.js";
|
|
3
|
+
import { outln, printResult, table } from "../output.js";
|
|
4
|
+
|
|
5
|
+
async function loadJson(value, flag) {
|
|
6
|
+
if (value == null) return undefined;
|
|
7
|
+
const text = value.startsWith("@")
|
|
8
|
+
? await (async () => {
|
|
9
|
+
const { readFile } = await import("node:fs/promises");
|
|
10
|
+
return readFile(value.slice(1), "utf8");
|
|
11
|
+
})()
|
|
12
|
+
: value;
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(text);
|
|
15
|
+
} catch (err) {
|
|
16
|
+
throw new Error(`Invalid JSON for ${flag}: ${err.message}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function add(query, key, value) {
|
|
21
|
+
if (value !== undefined) query[key] = value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function addNumber(query, key, value, flag) {
|
|
25
|
+
if (value !== undefined) query[key] = numberOption(value, flag);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const BENCHMARK_HELP = `Usage: openrouter benchmarks [options]
|
|
29
|
+
|
|
30
|
+
List OpenRouter's unified benchmark data. Supports Artificial Analysis, Design
|
|
31
|
+
Arena, OpenRouter evaluations, and search benchmarks.
|
|
32
|
+
|
|
33
|
+
Options:
|
|
34
|
+
--source <name> artificial-analysis | design-arena
|
|
35
|
+
--task-type <type> coding | intelligence | agentic | search
|
|
36
|
+
--benchmark-type <type> Exact OpenRouter benchmark (e.g. search_widesearch)
|
|
37
|
+
--include-run-config Include published search benchmark run config
|
|
38
|
+
--search-engine <name> Filter search benchmarks by engine
|
|
39
|
+
--search-surface <name> server-tool | openai | anthropic
|
|
40
|
+
--arena <name> models | builders | agents
|
|
41
|
+
--category <name> Design Arena category
|
|
42
|
+
--max-results <n>
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
export async function benchmarksCommand(argv) {
|
|
46
|
+
const { values } = parseArgs(argv, {
|
|
47
|
+
source: { type: "string" },
|
|
48
|
+
"task-type": { type: "string" },
|
|
49
|
+
"benchmark-type": { type: "string" },
|
|
50
|
+
"include-run-config": { type: "boolean" },
|
|
51
|
+
"search-engine": { type: "string" },
|
|
52
|
+
"search-surface": { type: "string" },
|
|
53
|
+
arena: { type: "string" },
|
|
54
|
+
category: { type: "string" },
|
|
55
|
+
"max-results": { type: "string" },
|
|
56
|
+
});
|
|
57
|
+
if (values.help) {
|
|
58
|
+
process.stdout.write(BENCHMARK_HELP);
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
const query = {};
|
|
62
|
+
add(query, "source", values.source);
|
|
63
|
+
add(query, "task_type", values["task-type"]);
|
|
64
|
+
add(query, "benchmark_type", values["benchmark-type"]);
|
|
65
|
+
if (values["include-run-config"]) query.include_run_config = "true";
|
|
66
|
+
add(query, "search_engine", values["search-engine"]);
|
|
67
|
+
add(query, "search_surface", values["search-surface"]);
|
|
68
|
+
add(query, "arena", values.arena);
|
|
69
|
+
add(query, "category", values.category);
|
|
70
|
+
addNumber(query, "max_results", values["max-results"], "--max-results");
|
|
71
|
+
const data = await api("GET", "/benchmarks", {
|
|
72
|
+
auth: authFromValues(values),
|
|
73
|
+
query,
|
|
74
|
+
});
|
|
75
|
+
printResult(data, () => {
|
|
76
|
+
const rows = data.data || [];
|
|
77
|
+
table(rows, [
|
|
78
|
+
{ label: "model", value: (r) => r.display_name || r.model_permaslug || r.model || "" },
|
|
79
|
+
{ label: "source", value: (r) => r.source || "" },
|
|
80
|
+
{
|
|
81
|
+
label: "score",
|
|
82
|
+
value: (r) =>
|
|
83
|
+
r.primary_score ??
|
|
84
|
+
r.intelligence_index ??
|
|
85
|
+
r.coding_index ??
|
|
86
|
+
r.agentic_index ??
|
|
87
|
+
r.elo ??
|
|
88
|
+
"",
|
|
89
|
+
},
|
|
90
|
+
{ label: "benchmark", value: (r) => r.benchmark_type || r.category || "" },
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const CLASSIFICATIONS_HELP = `Usage: openrouter classifications [options]
|
|
97
|
+
|
|
98
|
+
Show task-classification market share over the trailing window.
|
|
99
|
+
|
|
100
|
+
Options:
|
|
101
|
+
--window <window> Currently only 7d (default: 7d)
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
export async function classificationsCommand(argv) {
|
|
105
|
+
const { values } = parseArgs(argv, { window: { type: "string" } });
|
|
106
|
+
if (values.help) {
|
|
107
|
+
process.stdout.write(CLASSIFICATIONS_HELP);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
const query = {};
|
|
111
|
+
add(query, "window", values.window);
|
|
112
|
+
const data = await api("GET", "/classifications/task", {
|
|
113
|
+
auth: authFromValues(values),
|
|
114
|
+
query,
|
|
115
|
+
});
|
|
116
|
+
printResult(data, () => {
|
|
117
|
+
const rows = data.data?.classifications || [];
|
|
118
|
+
table(rows, [
|
|
119
|
+
{ label: "tag", value: (r) => r.tag || "" },
|
|
120
|
+
{ label: "category", value: (r) => r.display_name || "" },
|
|
121
|
+
{ label: "macro", value: (r) => r.macro_category || "" },
|
|
122
|
+
{ label: "usage", value: (r) => r.usage_share ?? "" },
|
|
123
|
+
{ label: "tokens", value: (r) => r.token_share ?? "" },
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const DATASETS_HELP = `Usage: openrouter datasets <subcommand> [options]
|
|
130
|
+
|
|
131
|
+
Public OpenRouter usage datasets.
|
|
132
|
+
|
|
133
|
+
Subcommands:
|
|
134
|
+
apps [options] Top public apps by token usage
|
|
135
|
+
daily [options] Daily/weekly/monthly model rankings
|
|
136
|
+
session-cost [options] Cost per session by harness and model
|
|
137
|
+
|
|
138
|
+
apps options:
|
|
139
|
+
--category <name> --subcategory <name> --sort popular|trending
|
|
140
|
+
--start-date <date> --end-date <date> --limit <n> --offset <n>
|
|
141
|
+
|
|
142
|
+
daily options:
|
|
143
|
+
--start-date <date> --end-date <date> --period day|week|month
|
|
144
|
+
--modality <name> --context-bucket <bucket> --category <name>
|
|
145
|
+
--language-type natural|programming
|
|
146
|
+
|
|
147
|
+
session-cost options:
|
|
148
|
+
--app-slug <slug> --model <id> --turn-range <range> --limit <n> --offset <n>
|
|
149
|
+
`;
|
|
150
|
+
|
|
151
|
+
function printDataset(data, columns) {
|
|
152
|
+
printResult(data, () => table(data.data || [], columns));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function datasetsCommand(argv) {
|
|
156
|
+
const sub = argv[0] && !argv[0].startsWith("-") ? argv[0] : "apps";
|
|
157
|
+
const rest = sub === argv[0] ? argv.slice(1) : argv;
|
|
158
|
+
if (!argv.length || sub === "help" || sub === "-h" || sub === "--help") {
|
|
159
|
+
process.stdout.write(DATASETS_HELP);
|
|
160
|
+
return argv.length ? 0 : 1;
|
|
161
|
+
}
|
|
162
|
+
if (rest.includes("-h") || rest.includes("--help")) {
|
|
163
|
+
process.stdout.write(DATASETS_HELP);
|
|
164
|
+
return 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (sub === "apps" || sub === "app-rankings") {
|
|
168
|
+
const { values } = parseArgs(rest, {
|
|
169
|
+
category: { type: "string" },
|
|
170
|
+
subcategory: { type: "string" },
|
|
171
|
+
sort: { type: "string" },
|
|
172
|
+
"start-date": { type: "string" },
|
|
173
|
+
"end-date": { type: "string" },
|
|
174
|
+
limit: { type: "string" },
|
|
175
|
+
offset: { type: "string" },
|
|
176
|
+
});
|
|
177
|
+
const query = {};
|
|
178
|
+
add(query, "category", values.category);
|
|
179
|
+
add(query, "subcategory", values.subcategory);
|
|
180
|
+
add(query, "sort", values.sort);
|
|
181
|
+
add(query, "start_date", values["start-date"]);
|
|
182
|
+
add(query, "end_date", values["end-date"]);
|
|
183
|
+
addNumber(query, "limit", values.limit, "--limit");
|
|
184
|
+
addNumber(query, "offset", values.offset, "--offset");
|
|
185
|
+
const data = await api("GET", "/datasets/app-rankings", {
|
|
186
|
+
auth: authFromValues(values),
|
|
187
|
+
query,
|
|
188
|
+
});
|
|
189
|
+
printDataset(data, [
|
|
190
|
+
{ label: "rank", value: (r) => r.rank ?? "" },
|
|
191
|
+
{ label: "app", value: (r) => r.app_name || r.app_slug || "" },
|
|
192
|
+
{ label: "requests", value: (r) => r.total_requests ?? "" },
|
|
193
|
+
{ label: "tokens", value: (r) => r.total_tokens ?? "" },
|
|
194
|
+
]);
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (sub === "daily" || sub === "rankings" || sub === "rankings-daily") {
|
|
199
|
+
const { values } = parseArgs(rest, {
|
|
200
|
+
"start-date": { type: "string" },
|
|
201
|
+
"end-date": { type: "string" },
|
|
202
|
+
period: { type: "string" },
|
|
203
|
+
modality: { type: "string" },
|
|
204
|
+
"context-bucket": { type: "string" },
|
|
205
|
+
category: { type: "string" },
|
|
206
|
+
"language-type": { type: "string" },
|
|
207
|
+
});
|
|
208
|
+
const query = {};
|
|
209
|
+
add(query, "start_date", values["start-date"]);
|
|
210
|
+
add(query, "end_date", values["end-date"]);
|
|
211
|
+
add(query, "period", values.period);
|
|
212
|
+
add(query, "modality", values.modality);
|
|
213
|
+
add(query, "context_bucket", values["context-bucket"]);
|
|
214
|
+
add(query, "category", values.category);
|
|
215
|
+
add(query, "language_type", values["language-type"]);
|
|
216
|
+
const data = await api("GET", "/datasets/rankings-daily", {
|
|
217
|
+
auth: authFromValues(values),
|
|
218
|
+
query,
|
|
219
|
+
});
|
|
220
|
+
printDataset(data, [
|
|
221
|
+
{ label: "date", value: (r) => r.date || "" },
|
|
222
|
+
{ label: "model", value: (r) => r.model_permaslug || r.model || "" },
|
|
223
|
+
{ label: "tokens", value: (r) => r.total_tokens ?? "" },
|
|
224
|
+
]);
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (sub === "session-cost" || sub === "sessions") {
|
|
229
|
+
const { values } = parseArgs(rest, {
|
|
230
|
+
"app-slug": { type: "string" },
|
|
231
|
+
model: { type: "string" },
|
|
232
|
+
"turn-range": { type: "string" },
|
|
233
|
+
limit: { type: "string" },
|
|
234
|
+
offset: { type: "string" },
|
|
235
|
+
});
|
|
236
|
+
const query = {};
|
|
237
|
+
add(query, "app_slug", values["app-slug"]);
|
|
238
|
+
add(query, "model", values.model);
|
|
239
|
+
add(query, "turn_range", values["turn-range"]);
|
|
240
|
+
addNumber(query, "limit", values.limit, "--limit");
|
|
241
|
+
addNumber(query, "offset", values.offset, "--offset");
|
|
242
|
+
const data = await api("GET", "/datasets/session-cost", {
|
|
243
|
+
auth: authFromValues(values),
|
|
244
|
+
query,
|
|
245
|
+
});
|
|
246
|
+
printDataset(data, [
|
|
247
|
+
{ label: "app", value: (r) => r.app_name || r.app_slug || "" },
|
|
248
|
+
{ label: "model", value: (r) => r.model_permaslug || r.model || "" },
|
|
249
|
+
{ label: "turns", value: (r) => r.turn_range || r.turns || "" },
|
|
250
|
+
{
|
|
251
|
+
label: "median $/session",
|
|
252
|
+
value: (r) => r.median_session_cost_usd ?? r.cost ?? r.total_cost ?? "",
|
|
253
|
+
},
|
|
254
|
+
]);
|
|
255
|
+
return 0;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
throw new Error(`Unknown datasets subcommand: ${sub}`);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const ANALYTICS_HELP = `Usage: openrouter analytics <subcommand> [options]
|
|
262
|
+
|
|
263
|
+
Management-key analytics. Use the meta subcommand to discover valid metrics,
|
|
264
|
+
dimensions, operators, and granularities before querying.
|
|
265
|
+
|
|
266
|
+
Subcommands:
|
|
267
|
+
meta List available analytics fields
|
|
268
|
+
query [options] Run an analytics query
|
|
269
|
+
|
|
270
|
+
query options:
|
|
271
|
+
--metrics <name> Required; repeat or pass comma-separated values
|
|
272
|
+
--dimensions <name> Repeat or pass comma-separated values
|
|
273
|
+
--filter <json> Filter object; repeatable or use @file.json
|
|
274
|
+
--granularity <name> --group-limit <n> --limit <n>
|
|
275
|
+
--start <iso> --end <iso>
|
|
276
|
+
--order-by <json> --classifier-dimensions <json>
|
|
277
|
+
--classifier-filters <json> --body <json|@file>
|
|
278
|
+
`;
|
|
279
|
+
|
|
280
|
+
function splitValues(values) {
|
|
281
|
+
return (values || []).flatMap((v) =>
|
|
282
|
+
v
|
|
283
|
+
.split(",")
|
|
284
|
+
.map((x) => x.trim())
|
|
285
|
+
.filter(Boolean),
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export async function analyticsCommand(argv) {
|
|
290
|
+
const sub = argv[0] && !argv[0].startsWith("-") ? argv[0] : "meta";
|
|
291
|
+
const rest = sub === argv[0] ? argv.slice(1) : argv;
|
|
292
|
+
if (!argv.length || sub === "help" || sub === "-h" || sub === "--help") {
|
|
293
|
+
process.stdout.write(ANALYTICS_HELP);
|
|
294
|
+
return argv.length ? 0 : 1;
|
|
295
|
+
}
|
|
296
|
+
if (rest.includes("-h") || rest.includes("--help")) {
|
|
297
|
+
process.stdout.write(ANALYTICS_HELP);
|
|
298
|
+
return 0;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (sub === "meta") {
|
|
302
|
+
const { values } = parseArgs(rest, {});
|
|
303
|
+
const data = await api("GET", "/analytics/meta", {
|
|
304
|
+
auth: authFromValues(values),
|
|
305
|
+
requiresManagement: true,
|
|
306
|
+
});
|
|
307
|
+
printResult(data);
|
|
308
|
+
return 0;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (sub === "query") {
|
|
312
|
+
const { values } = parseArgs(rest, {
|
|
313
|
+
metrics: { type: "string", multiple: true },
|
|
314
|
+
dimensions: { type: "string", multiple: true },
|
|
315
|
+
filter: { type: "string", multiple: true },
|
|
316
|
+
granularity: { type: "string" },
|
|
317
|
+
"group-limit": { type: "string" },
|
|
318
|
+
limit: { type: "string" },
|
|
319
|
+
start: { type: "string" },
|
|
320
|
+
end: { type: "string" },
|
|
321
|
+
"order-by": { type: "string" },
|
|
322
|
+
"classifier-dimensions": { type: "string" },
|
|
323
|
+
"classifier-filters": { type: "string" },
|
|
324
|
+
body: { type: "string" },
|
|
325
|
+
});
|
|
326
|
+
let body = values.body ? await loadJson(values.body, "--body") : {};
|
|
327
|
+
if (!values.body) {
|
|
328
|
+
const metrics = splitValues(values.metrics);
|
|
329
|
+
if (!metrics.length) throw new Error("--metrics is required");
|
|
330
|
+
body.metrics = metrics;
|
|
331
|
+
const dimensions = splitValues(values.dimensions);
|
|
332
|
+
if (dimensions.length) body.dimensions = dimensions;
|
|
333
|
+
if (values.filter)
|
|
334
|
+
body.filters = await Promise.all(values.filter.map((v) => loadJson(v, "--filter")));
|
|
335
|
+
if (values.granularity) body.granularity = values.granularity;
|
|
336
|
+
addNumber(body, "group_limit", values["group-limit"], "--group-limit");
|
|
337
|
+
addNumber(body, "limit", values.limit, "--limit");
|
|
338
|
+
if (values.start || values.end) {
|
|
339
|
+
body.time_range = {};
|
|
340
|
+
add(body.time_range, "start", values.start);
|
|
341
|
+
add(body.time_range, "end", values.end);
|
|
342
|
+
}
|
|
343
|
+
if (values["order-by"]) body.order_by = await loadJson(values["order-by"], "--order-by");
|
|
344
|
+
if (values["classifier-dimensions"])
|
|
345
|
+
body.classifier_dimensions = await loadJson(
|
|
346
|
+
values["classifier-dimensions"],
|
|
347
|
+
"--classifier-dimensions",
|
|
348
|
+
);
|
|
349
|
+
if (values["classifier-filters"])
|
|
350
|
+
body.classifier_filters = await loadJson(
|
|
351
|
+
values["classifier-filters"],
|
|
352
|
+
"--classifier-filters",
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
if (!Array.isArray(body.metrics) || body.metrics.length === 0)
|
|
356
|
+
throw new Error("Analytics body must include a non-empty metrics array.");
|
|
357
|
+
const data = await api("POST", "/analytics/query", {
|
|
358
|
+
auth: authFromValues(values),
|
|
359
|
+
requiresManagement: true,
|
|
360
|
+
body,
|
|
361
|
+
});
|
|
362
|
+
printResult(data, () => {
|
|
363
|
+
const result = data.data || {};
|
|
364
|
+
const rows = result.data || [];
|
|
365
|
+
if (!rows.length) {
|
|
366
|
+
outln("(no rows)");
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const columns = Object.keys(rows[0]).map((key) => ({ label: key, value: (row) => row[key] }));
|
|
370
|
+
table(rows, columns);
|
|
371
|
+
});
|
|
372
|
+
return 0;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
throw new Error(`Unknown analytics subcommand: ${sub}`);
|
|
376
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { parseArgs, authFromValues, loadJson } from "../args.js";
|
|
2
|
+
import { api } from "../api.js";
|
|
3
|
+
import { mediaUrl } from "../media.js";
|
|
4
|
+
import { printResult } from "../output.js";
|
|
5
|
+
|
|
6
|
+
const HELP = `Usage: openrouter systemone [options]
|
|
7
|
+
openrouter decisions [options] (same command)
|
|
8
|
+
|
|
9
|
+
Submit a System One (Decisions) request: state plus typed questions (choice,
|
|
10
|
+
score, yes/no), answered by a System One model such as typesafe/jev-latest.
|
|
11
|
+
Used for routing, classification and other structured decisions.
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
-m, --model <id> Model id, e.g. jev-latest (required without --body)
|
|
15
|
+
--state <json|text> State to evaluate (required without --body)
|
|
16
|
+
--questions <json> Questions object or @questions.json
|
|
17
|
+
--image <url|path> Add an image to the state (repeatable). Local files
|
|
18
|
+
are sent as data URLs. For multimodal models.
|
|
19
|
+
--body <json|@file> Fully-formed request body
|
|
20
|
+
--extra <json> Extra fields merged into the request
|
|
21
|
+
--alpha Use the older /api/alpha/decisions route
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
openrouter systemone -m jev-latest --state "Refund request for order 123" \\
|
|
25
|
+
--questions '{"route":{"type":"choice","options":["billing","support"]}}'
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
async function imagePart(value) {
|
|
29
|
+
return { type: "image_url", image_url: { url: await mediaUrl(value) } };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// State becomes an array of parts: a text state turns into a text part, an
|
|
33
|
+
// object stays one element, an array keeps its items; images go last.
|
|
34
|
+
export function withImages(state, parts) {
|
|
35
|
+
if (!parts.length) return state;
|
|
36
|
+
let base;
|
|
37
|
+
if (state === undefined || state === null || state === "") base = [];
|
|
38
|
+
else if (Array.isArray(state)) base = state;
|
|
39
|
+
else if (typeof state === "string") base = [{ type: "text", text: state }];
|
|
40
|
+
else base = [state];
|
|
41
|
+
return [...base, ...parts];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function loadState(value) {
|
|
45
|
+
if (value == null) return undefined;
|
|
46
|
+
if (value.startsWith("@")) return loadJson(value, "--state");
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(value);
|
|
49
|
+
} catch {
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function decisionsCommand(argv) {
|
|
55
|
+
const { values } = parseArgs(argv, {
|
|
56
|
+
model: { type: "string", short: "m" },
|
|
57
|
+
state: { type: "string" },
|
|
58
|
+
questions: { type: "string" },
|
|
59
|
+
image: { type: "string", multiple: true },
|
|
60
|
+
body: { type: "string" },
|
|
61
|
+
extra: { type: "string" },
|
|
62
|
+
alpha: { type: "boolean" },
|
|
63
|
+
});
|
|
64
|
+
if (values.help) {
|
|
65
|
+
process.stdout.write(HELP);
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
const images = values.image || [];
|
|
69
|
+
let body = values.body ? await loadJson(values.body, "--body") : null;
|
|
70
|
+
if (!body) {
|
|
71
|
+
if (!values.model) throw new Error("--model is required");
|
|
72
|
+
if (values.state === undefined && !images.length) throw new Error("--state is required");
|
|
73
|
+
if (!values.questions) throw new Error("--questions is required");
|
|
74
|
+
body = {
|
|
75
|
+
model: values.model,
|
|
76
|
+
state: await loadState(values.state),
|
|
77
|
+
questions: await loadJson(values.questions, "--questions"),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (images.length) {
|
|
81
|
+
const parts = await Promise.all(images.map(imagePart));
|
|
82
|
+
body.state = withImages(body.state, parts);
|
|
83
|
+
}
|
|
84
|
+
if (values.extra) Object.assign(body, await loadJson(values.extra, "--extra"));
|
|
85
|
+
const data = values.alpha
|
|
86
|
+
? await api("POST", "/decisions", {
|
|
87
|
+
rootPath: "/api/alpha",
|
|
88
|
+
auth: authFromValues(values),
|
|
89
|
+
body,
|
|
90
|
+
})
|
|
91
|
+
: await api("POST", "/systemone", { auth: authFromValues(values), body });
|
|
92
|
+
printResult(data);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const systemoneCommand = decisionsCommand;
|
package/src/commands/embed.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
parseArgs,
|
|
3
|
+
authFromValues,
|
|
4
|
+
numberOption,
|
|
5
|
+
readStdinIfPiped,
|
|
6
|
+
loadJson,
|
|
7
|
+
applyRequestFields,
|
|
8
|
+
MEDIA_FIELD_HELP,
|
|
9
|
+
MEDIA_FIELD_OPTIONS,
|
|
10
|
+
} from "../args.js";
|
|
2
11
|
import { api } from "../api.js";
|
|
12
|
+
import { mediaUrl } from "../media.js";
|
|
3
13
|
import { outln, pricePerMillion, printResult, table } from "../output.js";
|
|
4
14
|
|
|
5
15
|
const HELP = `Usage: openrouter embed [text...] [options]
|
|
@@ -10,11 +20,14 @@ Generate embeddings, or list embedding models.
|
|
|
10
20
|
Options:
|
|
11
21
|
-m, --model <id> Embedding model id (required for inference)
|
|
12
22
|
-i, --input <text> Input string (repeatable)
|
|
13
|
-
--
|
|
23
|
+
--image <url|path> Image to embed (repeatable, multimodal models); each is
|
|
24
|
+
its own input. Local files are sent as data URLs.
|
|
25
|
+
--input-type <t> e.g. search_query | search_document
|
|
14
26
|
--dimensions <n>
|
|
15
27
|
--encoding <fmt> float | base64
|
|
16
|
-
--provider <json> Provider routing as JSON
|
|
17
|
-
|
|
28
|
+
--provider <json|@file> Provider routing as JSON
|
|
29
|
+
--extra <json|@file> Extra fields merged into the body (last)
|
|
30
|
+
${MEDIA_FIELD_HELP}`;
|
|
18
31
|
|
|
19
32
|
export async function embedCommand(argv) {
|
|
20
33
|
if (argv[0] === "models") {
|
|
@@ -47,8 +60,11 @@ export async function embedCommand(argv) {
|
|
|
47
60
|
input: { type: "string", short: "i", multiple: true },
|
|
48
61
|
"input-type": { type: "string" },
|
|
49
62
|
dimensions: { type: "string" },
|
|
63
|
+
image: { type: "string", multiple: true },
|
|
50
64
|
encoding: { type: "string" },
|
|
51
65
|
provider: { type: "string" },
|
|
66
|
+
extra: { type: "string" },
|
|
67
|
+
...MEDIA_FIELD_OPTIONS,
|
|
52
68
|
});
|
|
53
69
|
if (values.help) {
|
|
54
70
|
process.stdout.write(HELP);
|
|
@@ -59,16 +75,25 @@ export async function embedCommand(argv) {
|
|
|
59
75
|
const inputs = [...(values.input || []), ...positionals];
|
|
60
76
|
const piped = await readStdinIfPiped();
|
|
61
77
|
if (piped) inputs.push(piped);
|
|
62
|
-
|
|
78
|
+
const images = values.image || [];
|
|
79
|
+
if (!inputs.length && !images.length)
|
|
80
|
+
throw new Error("No input. Pass text, use --input or --image, or pipe stdin.");
|
|
63
81
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
let input = inputs.length === 1 ? inputs[0] : inputs;
|
|
83
|
+
if (images.length) {
|
|
84
|
+
// Multimodal form: one { content: [part] } item per text or image.
|
|
85
|
+
input = inputs.map((text) => ({ content: [{ type: "text", text }] }));
|
|
86
|
+
for (const img of images) {
|
|
87
|
+
input.push({ content: [{ type: "image_url", image_url: { url: await mediaUrl(img) } }] });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const body = { model: values.model, input };
|
|
68
91
|
if (values["input-type"]) body.input_type = values["input-type"];
|
|
69
92
|
if (values.dimensions) body.dimensions = numberOption(values.dimensions, "--dimensions");
|
|
70
93
|
if (values.encoding) body.encoding_format = values.encoding;
|
|
71
|
-
if (values.provider) body.provider =
|
|
94
|
+
if (values.provider) body.provider = await loadJson(values.provider, "--provider");
|
|
95
|
+
await applyRequestFields(body, values);
|
|
96
|
+
if (values.extra) Object.assign(body, await loadJson(values.extra, "--extra"));
|
|
72
97
|
|
|
73
98
|
const data = await api("POST", "/embeddings", {
|
|
74
99
|
auth: authFromValues(values),
|