@agentrouter/agentrouter 0.1.13 → 0.2.1
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 +16 -803
- package/dist/cli.js +3 -4
- package/dist/core.d.ts +28 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +598 -0
- package/dist/credentials.d.ts +43 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +98 -0
- package/dist/login-page.d.ts +2 -0
- package/dist/login-page.d.ts.map +1 -0
- package/dist/login-page.js +45 -0
- package/dist/login.d.ts +23 -0
- package/dist/login.d.ts.map +1 -0
- package/dist/login.js +90 -0
- package/dist/terminal.d.ts +3 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +32 -0
- package/icon.svg +11 -0
- package/package.json +9 -17
- package/dist/cli-core.d.ts +0 -13
- package/dist/cli-core.d.ts.map +0 -1
- package/dist/cli-core.js +0 -627
- package/dist/index.d.ts +0 -553
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -797
package/dist/cli-core.js
DELETED
|
@@ -1,627 +0,0 @@
|
|
|
1
|
-
import { readFile as readFileFromFs } from "node:fs/promises";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
import { AGENTIC_API_INSTALL_URL, AGENTROUTER_SDK_VERSION, AgentRouterClient, AgentRouterClientError, DEFAULT_AGENTIC_API_BASE_URL, } from "./index.js";
|
|
4
|
-
const BOOLEAN_FLAGS = new Set(["allow-fallback", "help", "json"]);
|
|
5
|
-
const MULTI_VALUE_FLAGS = new Set(["query"]);
|
|
6
|
-
function createRuntime(io = {}) {
|
|
7
|
-
return {
|
|
8
|
-
env: io.env ?? process.env,
|
|
9
|
-
stdout: io.stdout ?? ((value) => process.stdout.write(value)),
|
|
10
|
-
stderr: io.stderr ?? ((value) => process.stderr.write(value)),
|
|
11
|
-
readFile: io.readFile ?? ((path) => readFileFromFs(path, "utf8")),
|
|
12
|
-
...(io.fetch ? { fetch: io.fetch } : {}),
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function renderHelp() {
|
|
16
|
-
return `AgentRouter CLI
|
|
17
|
-
|
|
18
|
-
Usage:
|
|
19
|
-
agentrouter wallet [--json]
|
|
20
|
-
agentrouter usage [--limit 20] [--json]
|
|
21
|
-
agentrouter domains list [--json]
|
|
22
|
-
agentrouter domains get <domain> [--json]
|
|
23
|
-
agentrouter capabilities list <domain> [--json]
|
|
24
|
-
agentrouter capabilities get <domain> <capability> [--json]
|
|
25
|
-
agentrouter capabilities routes <domain> <capability> [--json]
|
|
26
|
-
agentrouter capabilities contract <domain> <capability> [--json]
|
|
27
|
-
agentrouter routes context <routeKey> [--json]
|
|
28
|
-
agentrouter recommend <domain> <capability> --input <json|@file> [--json]
|
|
29
|
-
agentrouter execute <domain> <capability> --input <json|@file> [--route-key <key>] [--provider <key>] [--allow-fallback] [--json]
|
|
30
|
-
agentrouter route <domain> --input <json|@file> [--json]
|
|
31
|
-
agentrouter raw <method> <path> [--auth none|api-key|session] [--query key=value] [--input <json|@file>] [--json]
|
|
32
|
-
|
|
33
|
-
Global flags:
|
|
34
|
-
--base-url <url> Default: ${DEFAULT_AGENTIC_API_BASE_URL}
|
|
35
|
-
--api-key <key> Overrides AGENTIC_API_KEY
|
|
36
|
-
--session-token <token> Overrides AGENTIC_API_SESSION_TOKEN
|
|
37
|
-
--user-id <id> Local development fallback identity
|
|
38
|
-
--timeout <ms> Request timeout in milliseconds
|
|
39
|
-
--json Emit structured JSON instead of formatted text
|
|
40
|
-
--help Show this help text
|
|
41
|
-
|
|
42
|
-
Get an API key:
|
|
43
|
-
1. Sign in at ${AGENTIC_API_INSTALL_URL}
|
|
44
|
-
2. Copy your API key
|
|
45
|
-
3. export AGENTIC_API_KEY=your_key_here
|
|
46
|
-
|
|
47
|
-
Environment variables:
|
|
48
|
-
AGENTIC_API_BASE_URL
|
|
49
|
-
AGENTIC_API_KEY
|
|
50
|
-
AGENTIC_API_SESSION_TOKEN
|
|
51
|
-
AGENTIC_API_USER_ID
|
|
52
|
-
AGENTIC_API_TIMEOUT_MS
|
|
53
|
-
|
|
54
|
-
Examples:
|
|
55
|
-
agentrouter domains list
|
|
56
|
-
agentrouter capabilities list email
|
|
57
|
-
agentrouter capabilities list models
|
|
58
|
-
agentrouter capabilities list text
|
|
59
|
-
agentrouter capabilities list media
|
|
60
|
-
agentrouter capabilities list geo
|
|
61
|
-
agentrouter capabilities list tax
|
|
62
|
-
agentrouter capabilities list captcha
|
|
63
|
-
agentrouter capabilities list commerce
|
|
64
|
-
agentrouter capabilities list lottery
|
|
65
|
-
agentrouter capabilities list music
|
|
66
|
-
agentrouter capabilities list property
|
|
67
|
-
agentrouter routes context email.send.resend
|
|
68
|
-
agentrouter routes context models.chat.complete.deepseek.mpp
|
|
69
|
-
agentrouter routes context models.chat.complete.groq.mpp
|
|
70
|
-
agentrouter routes context text.analyze.diffbot-nl.mpp
|
|
71
|
-
agentrouter routes context translation.text.rephrase.deepl.mpp
|
|
72
|
-
agentrouter routes context web.extract.diffbot.mpp
|
|
73
|
-
agentrouter routes context web.publication.list.dripstack.mpp
|
|
74
|
-
agentrouter routes context web.publication.post.get.dripstack.mpp
|
|
75
|
-
agentrouter routes context enrichment.people.enrich.diffbot.mpp
|
|
76
|
-
agentrouter routes context finance.fx.convert.abstract-exchange-rates.mpp
|
|
77
|
-
agentrouter routes context geo.time.current.abstract-timezone.mpp
|
|
78
|
-
agentrouter routes context geo.time.convert.abstract-timezone.mpp
|
|
79
|
-
agentrouter routes context tax.vat.validate.abstract-vat.mpp
|
|
80
|
-
agentrouter routes context captcha.task.create.twocaptcha.mpp
|
|
81
|
-
agentrouter routes context commerce.product.search.kicksdb.stockx.mpp
|
|
82
|
-
agentrouter routes context lottery.round.active.megapot
|
|
83
|
-
agentrouter routes context music.song.generate.suno.mpp
|
|
84
|
-
agentrouter routes context property.records.search.rentcast.mpp
|
|
85
|
-
agentrouter routes context media.image.generate.fal.mpp
|
|
86
|
-
agentrouter routes context travel.airport.operations.flightapi.mpp
|
|
87
|
-
agentrouter recommend email send --input '{"optimizationPreferences":["cost"]}' --json
|
|
88
|
-
agentrouter recommend text analyze --input '{"provider":"diffbot-nl","fields":"entities,sentiment,language","optimizationPreferences":["quality"]}' --json
|
|
89
|
-
agentrouter execute models chat-complete --input '{"model":"deepseek-flash","messages":[{"role":"user","content":"Say AgentRouter DeepSeek smoke OK."}]}' --route-key models.chat.complete.deepseek.mpp --json
|
|
90
|
-
agentrouter execute translation text-rephrase --input '{"text":"Please make this product update friendlier.","targetLanguage":"EN-US","tone":"prefer_friendly"}' --route-key translation.text.rephrase.deepl.mpp --json
|
|
91
|
-
agentrouter execute web extract --input '{"url":"https://www.example.com/article"}' --route-key web.extract.diffbot.mpp --json
|
|
92
|
-
agentrouter execute web publication-list --input '{"allowFallback":false}' --route-key web.publication.list.dripstack.mpp --json
|
|
93
|
-
agentrouter execute web publication-posts-list --input '{"publicationSlug":"newsletter.morning-brew.morningbrew.com","allowFallback":false}' --route-key web.publication.posts.list.dripstack.mpp --json
|
|
94
|
-
agentrouter execute web publication-post-get --input '{"publicationSlug":"newsletter.morning-brew.morningbrew.com","postSlug":"cheers-to-beer-20260506","allowFallback":false}' --route-key web.publication.post.get.dripstack.mpp --json
|
|
95
|
-
agentrouter execute enrichment people-enrich --input '{"fullName":"Sam Altman","companyName":"OpenAI"}' --route-key enrichment.people.enrich.diffbot.mpp --json
|
|
96
|
-
agentrouter execute finance fx-convert --input '{"fromCurrency":"USD","toCurrency":"JPY","amount":25}' --route-key finance.fx.convert.abstract-exchange-rates.mpp --json
|
|
97
|
-
agentrouter execute geo time-current --input '{"location":"Los Angeles, CA","allowFallback":false}' --route-key geo.time.current.abstract-timezone.mpp --provider abstract-timezone --json
|
|
98
|
-
agentrouter execute geo time-convert --input '{"fromLocation":"Los Angeles, CA","toLocation":"Tokyo, Japan","datetime":"2026-05-08 09:30:00","allowFallback":false}' --route-key geo.time.convert.abstract-timezone.mpp --provider abstract-timezone --json
|
|
99
|
-
agentrouter execute tax vat-validate --input '{"vatNumber":"DE123456789","countryCode":"DE","allowFallback":false}' --route-key tax.vat.validate.abstract-vat.mpp --provider abstract-vat --json
|
|
100
|
-
agentrouter execute tax vat-calculate --input '{"countryCode":"DE","amount":100,"calculationType":"add","allowFallback":false}' --route-key tax.vat.calculate.abstract-vat.mpp --provider abstract-vat --json
|
|
101
|
-
agentrouter execute media image-generate --input '{"prompt":"Create a clean launch hero image for an AI developer tool","aspectRatio":"16:9","allowFallback":false}' --route-key media.image.generate.fal.mpp --provider fal --json
|
|
102
|
-
agentrouter execute email send --input @send-email.json --route-key email.send.resend --allow-fallback
|
|
103
|
-
agentrouter execute travel airport-operations --input '{"iataCode":"JFK","mode":"departures","limit":1}' --route-key travel.airport.operations.flightapi.mpp --provider flightapi --json
|
|
104
|
-
agentrouter route enrichment --input '{"intent":"Find the work email for the VP Engineering at Example Corp"}'
|
|
105
|
-
agentrouter raw get /domains/email/capabilities/send/contract
|
|
106
|
-
`;
|
|
107
|
-
}
|
|
108
|
-
function parseArgv(argv) {
|
|
109
|
-
const flags = {
|
|
110
|
-
allowFallback: false,
|
|
111
|
-
help: false,
|
|
112
|
-
json: false,
|
|
113
|
-
query: [],
|
|
114
|
-
};
|
|
115
|
-
const positionals = [];
|
|
116
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
117
|
-
const token = argv[index];
|
|
118
|
-
if (!token) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (token === "-h") {
|
|
122
|
-
flags.help = true;
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
if (!token.startsWith("--")) {
|
|
126
|
-
positionals.push(token);
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const equalIndex = token.indexOf("=");
|
|
130
|
-
const rawName = equalIndex >= 0 ? token.slice(2, equalIndex) : token.slice(2);
|
|
131
|
-
const inlineValue = equalIndex >= 0 ? token.slice(equalIndex + 1) : undefined;
|
|
132
|
-
if (BOOLEAN_FLAGS.has(rawName)) {
|
|
133
|
-
const resolved = inlineValue ?? "true";
|
|
134
|
-
const normalized = resolved.toLowerCase();
|
|
135
|
-
if (normalized !== "true" && normalized !== "false") {
|
|
136
|
-
throw new Error(`Flag --${rawName} only accepts true or false.`);
|
|
137
|
-
}
|
|
138
|
-
const value = normalized === "true";
|
|
139
|
-
if (rawName === "allow-fallback") {
|
|
140
|
-
flags.allowFallback = value;
|
|
141
|
-
}
|
|
142
|
-
if (rawName === "help") {
|
|
143
|
-
flags.help = value;
|
|
144
|
-
}
|
|
145
|
-
if (rawName === "json") {
|
|
146
|
-
flags.json = value;
|
|
147
|
-
}
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
const nextValue = inlineValue ?? argv[index + 1];
|
|
151
|
-
if (typeof nextValue === "undefined") {
|
|
152
|
-
throw new Error(`Flag --${rawName} requires a value.`);
|
|
153
|
-
}
|
|
154
|
-
if (typeof inlineValue === "undefined") {
|
|
155
|
-
index += 1;
|
|
156
|
-
}
|
|
157
|
-
if (MULTI_VALUE_FLAGS.has(rawName)) {
|
|
158
|
-
flags.query.push(nextValue);
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
switch (rawName) {
|
|
162
|
-
case "api-key":
|
|
163
|
-
flags.apiKey = nextValue;
|
|
164
|
-
break;
|
|
165
|
-
case "auth":
|
|
166
|
-
flags.auth = nextValue;
|
|
167
|
-
break;
|
|
168
|
-
case "base-url":
|
|
169
|
-
flags.baseUrl = nextValue;
|
|
170
|
-
break;
|
|
171
|
-
case "input":
|
|
172
|
-
flags.input = nextValue;
|
|
173
|
-
break;
|
|
174
|
-
case "limit":
|
|
175
|
-
flags.limit = nextValue;
|
|
176
|
-
break;
|
|
177
|
-
case "provider":
|
|
178
|
-
flags.provider = nextValue;
|
|
179
|
-
break;
|
|
180
|
-
case "route-key":
|
|
181
|
-
flags.routeKey = nextValue;
|
|
182
|
-
break;
|
|
183
|
-
case "session-token":
|
|
184
|
-
flags.sessionToken = nextValue;
|
|
185
|
-
break;
|
|
186
|
-
case "timeout":
|
|
187
|
-
flags.timeout = nextValue;
|
|
188
|
-
break;
|
|
189
|
-
case "user-id":
|
|
190
|
-
flags.userId = nextValue;
|
|
191
|
-
break;
|
|
192
|
-
default:
|
|
193
|
-
throw new Error(`Unknown flag --${rawName}.`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return {
|
|
197
|
-
flags,
|
|
198
|
-
positionals,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
function resolveNumber(value, flagName) {
|
|
202
|
-
if (typeof value === "undefined") {
|
|
203
|
-
return undefined;
|
|
204
|
-
}
|
|
205
|
-
const parsed = Number(value);
|
|
206
|
-
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
207
|
-
throw new Error(`Flag ${flagName} must be a non-negative number.`);
|
|
208
|
-
}
|
|
209
|
-
return parsed;
|
|
210
|
-
}
|
|
211
|
-
function resolveInputSource(value, label) {
|
|
212
|
-
if (!value) {
|
|
213
|
-
throw new Error(`Missing ${label}. Pass --input <json> or --input @file.json.`);
|
|
214
|
-
}
|
|
215
|
-
return value;
|
|
216
|
-
}
|
|
217
|
-
async function parseJsonInput(inputValue, runtime) {
|
|
218
|
-
const rawInput = inputValue.startsWith("@")
|
|
219
|
-
? await runtime.readFile(inputValue.slice(1))
|
|
220
|
-
: inputValue;
|
|
221
|
-
let parsed;
|
|
222
|
-
try {
|
|
223
|
-
parsed = JSON.parse(rawInput);
|
|
224
|
-
}
|
|
225
|
-
catch (error) {
|
|
226
|
-
throw new Error(`Failed to parse JSON input: ${error instanceof Error ? error.message : "Unknown parse error."}`);
|
|
227
|
-
}
|
|
228
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
229
|
-
throw new Error("CLI input JSON must be an object.");
|
|
230
|
-
}
|
|
231
|
-
return parsed;
|
|
232
|
-
}
|
|
233
|
-
function resolveAuthMode(value) {
|
|
234
|
-
const normalized = value?.trim().toLowerCase();
|
|
235
|
-
if (!normalized || normalized === "none") {
|
|
236
|
-
return "none";
|
|
237
|
-
}
|
|
238
|
-
if (normalized === "api-key" || normalized === "apikey") {
|
|
239
|
-
return "apiKey";
|
|
240
|
-
}
|
|
241
|
-
if (normalized === "session") {
|
|
242
|
-
return "session";
|
|
243
|
-
}
|
|
244
|
-
throw new Error("Flag --auth must be one of: none, api-key, session.");
|
|
245
|
-
}
|
|
246
|
-
function parseQueryArgs(values) {
|
|
247
|
-
if (values.length === 0) {
|
|
248
|
-
return undefined;
|
|
249
|
-
}
|
|
250
|
-
const query = {};
|
|
251
|
-
for (const item of values) {
|
|
252
|
-
const equalIndex = item.indexOf("=");
|
|
253
|
-
if (equalIndex <= 0) {
|
|
254
|
-
throw new Error("Each --query value must be in key=value format.");
|
|
255
|
-
}
|
|
256
|
-
const key = item.slice(0, equalIndex).trim();
|
|
257
|
-
const value = item.slice(equalIndex + 1);
|
|
258
|
-
if (!key) {
|
|
259
|
-
throw new Error("Each --query value must include a key before '='.");
|
|
260
|
-
}
|
|
261
|
-
query[key] = value;
|
|
262
|
-
}
|
|
263
|
-
return query;
|
|
264
|
-
}
|
|
265
|
-
function printJson(value, runtime) {
|
|
266
|
-
runtime.stdout(`${JSON.stringify(value, null, 2)}\n`);
|
|
267
|
-
}
|
|
268
|
-
function renderTable(headers, rows) {
|
|
269
|
-
const widths = headers.map((header, index) => Math.max(header.length, ...rows.map((row) => (row[index] ?? "").length)));
|
|
270
|
-
const formatRow = (row) => row
|
|
271
|
-
.map((cell, index) => cell.padEnd(widths[index] ?? 0))
|
|
272
|
-
.join(" ")
|
|
273
|
-
.trimEnd();
|
|
274
|
-
return [
|
|
275
|
-
formatRow(headers),
|
|
276
|
-
formatRow(widths.map((width) => "-".repeat(width))),
|
|
277
|
-
...rows.map(formatRow),
|
|
278
|
-
].join("\n");
|
|
279
|
-
}
|
|
280
|
-
function formatCredits(value) {
|
|
281
|
-
if (typeof value !== "number") {
|
|
282
|
-
return "-";
|
|
283
|
-
}
|
|
284
|
-
return String(value);
|
|
285
|
-
}
|
|
286
|
-
function formatWallet(wallet) {
|
|
287
|
-
return [
|
|
288
|
-
`userId: ${wallet.userId}`,
|
|
289
|
-
`balanceCredits: ${wallet.balanceCredits}`,
|
|
290
|
-
].join("\n");
|
|
291
|
-
}
|
|
292
|
-
function formatDomains(domains) {
|
|
293
|
-
return renderTable(["domain", "status", "live/total", "startCredits", "intentRouting"], domains.map((domain) => [
|
|
294
|
-
domain.domainKey,
|
|
295
|
-
domain.status,
|
|
296
|
-
`${domain.liveCapabilityCount}/${domain.totalCapabilityCount}`,
|
|
297
|
-
formatCredits(domain.startingPriceCredits),
|
|
298
|
-
domain.supportsIntentRouting ? "yes" : "no",
|
|
299
|
-
]));
|
|
300
|
-
}
|
|
301
|
-
function formatCapabilities(capabilities) {
|
|
302
|
-
return renderTable(["capability", "status", "providers", "startCredits"], capabilities.map((capability) => [
|
|
303
|
-
capability.capabilityId,
|
|
304
|
-
capability.status,
|
|
305
|
-
capability.enabledProviders.join(",") || "-",
|
|
306
|
-
formatCredits(capability.startingPriceCredits),
|
|
307
|
-
]));
|
|
308
|
-
}
|
|
309
|
-
function formatRoutes(routes) {
|
|
310
|
-
return renderTable([
|
|
311
|
-
"route",
|
|
312
|
-
"provider",
|
|
313
|
-
"mode",
|
|
314
|
-
"network",
|
|
315
|
-
"settlement",
|
|
316
|
-
"status",
|
|
317
|
-
"startCredits",
|
|
318
|
-
], routes.map((route) => [
|
|
319
|
-
route.routeKey,
|
|
320
|
-
route.providerKey,
|
|
321
|
-
route.routeMode,
|
|
322
|
-
route.networkKey,
|
|
323
|
-
route.settlementRail ?? "-",
|
|
324
|
-
route.status,
|
|
325
|
-
String(route.startingCostCredits),
|
|
326
|
-
]));
|
|
327
|
-
}
|
|
328
|
-
function formatUsage(usage) {
|
|
329
|
-
const rows = usage.items.map((item) => [
|
|
330
|
-
item.requestId,
|
|
331
|
-
item.providerKey,
|
|
332
|
-
item.status,
|
|
333
|
-
String(item.chargedCredits),
|
|
334
|
-
String(item.latencyMs),
|
|
335
|
-
]);
|
|
336
|
-
return [
|
|
337
|
-
`userId: ${usage.userId}`,
|
|
338
|
-
renderTable(["requestId", "provider", "status", "chargedCredits", "latencyMs"], rows),
|
|
339
|
-
].join("\n");
|
|
340
|
-
}
|
|
341
|
-
function printText(value, runtime) {
|
|
342
|
-
runtime.stdout(`${value}\n`);
|
|
343
|
-
}
|
|
344
|
-
function buildClient(flags, runtime) {
|
|
345
|
-
const timeoutMs = resolveNumber(flags.timeout ?? runtime.env.AGENTIC_API_TIMEOUT_MS, "--timeout");
|
|
346
|
-
return new AgentRouterClient({
|
|
347
|
-
apiKey: flags.apiKey ?? runtime.env.AGENTIC_API_KEY ?? null,
|
|
348
|
-
sessionToken: flags.sessionToken ?? runtime.env.AGENTIC_API_SESSION_TOKEN ?? null,
|
|
349
|
-
baseUrl: flags.baseUrl ??
|
|
350
|
-
runtime.env.AGENTIC_API_BASE_URL ??
|
|
351
|
-
DEFAULT_AGENTIC_API_BASE_URL,
|
|
352
|
-
...(typeof timeoutMs === "number" ? { timeoutMs } : {}),
|
|
353
|
-
...(runtime.fetch ? { fetch: runtime.fetch } : {}),
|
|
354
|
-
headers: {
|
|
355
|
-
"X-AgentRouter-Client": `agentrouter-cli/${AGENTROUTER_SDK_VERSION}`,
|
|
356
|
-
},
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
function resolveUserId(flags, runtime) {
|
|
360
|
-
const value = flags.userId ?? runtime.env.AGENTIC_API_USER_ID;
|
|
361
|
-
return value?.trim() || undefined;
|
|
362
|
-
}
|
|
363
|
-
function ensureNoUnexpectedArgs(positionals, expected) {
|
|
364
|
-
if (positionals.length > expected) {
|
|
365
|
-
throw new Error("Too many positional arguments. Use --help to inspect CLI usage.");
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
async function runDomainsCommand(client, args, flags, runtime) {
|
|
369
|
-
const action = args[0] ?? "list";
|
|
370
|
-
if (action === "list") {
|
|
371
|
-
ensureNoUnexpectedArgs(args, 1);
|
|
372
|
-
const domains = await client.catalog.domains.list();
|
|
373
|
-
if (flags.json) {
|
|
374
|
-
printJson(domains, runtime);
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
printText(formatDomains(domains), runtime);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
if (action === "get") {
|
|
381
|
-
const domainKey = args[1];
|
|
382
|
-
if (!domainKey) {
|
|
383
|
-
throw new Error("Usage: agentrouter domains get <domain>");
|
|
384
|
-
}
|
|
385
|
-
ensureNoUnexpectedArgs(args, 2);
|
|
386
|
-
const domain = await client.catalog.domains.get(domainKey);
|
|
387
|
-
printJson(domain, runtime);
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
throw new Error("Usage: agentrouter domains [list|get]");
|
|
391
|
-
}
|
|
392
|
-
async function runCapabilitiesCommand(client, args, flags, runtime) {
|
|
393
|
-
const action = args[0];
|
|
394
|
-
if (!action) {
|
|
395
|
-
throw new Error("Usage: agentrouter capabilities <list|get|routes|contract> ...");
|
|
396
|
-
}
|
|
397
|
-
if (action === "list") {
|
|
398
|
-
const domainKey = args[1];
|
|
399
|
-
if (!domainKey) {
|
|
400
|
-
throw new Error("Usage: agentrouter capabilities list <domain>");
|
|
401
|
-
}
|
|
402
|
-
ensureNoUnexpectedArgs(args, 2);
|
|
403
|
-
const capabilities = await client.catalog.capabilities.list(domainKey);
|
|
404
|
-
if (flags.json) {
|
|
405
|
-
printJson(capabilities, runtime);
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
printText(formatCapabilities(capabilities), runtime);
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
if (action === "get") {
|
|
412
|
-
const domainKey = args[1];
|
|
413
|
-
const capabilityId = args[2];
|
|
414
|
-
if (!domainKey || !capabilityId) {
|
|
415
|
-
throw new Error("Usage: agentrouter capabilities get <domain> <capability>");
|
|
416
|
-
}
|
|
417
|
-
ensureNoUnexpectedArgs(args, 3);
|
|
418
|
-
const capability = await client.catalog.capabilities.get(domainKey, capabilityId);
|
|
419
|
-
printJson(capability, runtime);
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
if (action === "routes") {
|
|
423
|
-
const domainKey = args[1];
|
|
424
|
-
const capabilityId = args[2];
|
|
425
|
-
if (!domainKey || !capabilityId) {
|
|
426
|
-
throw new Error("Usage: agentrouter capabilities routes <domain> <capability>");
|
|
427
|
-
}
|
|
428
|
-
ensureNoUnexpectedArgs(args, 3);
|
|
429
|
-
const routes = await client.catalog.capabilities.routes(domainKey, capabilityId);
|
|
430
|
-
if (flags.json) {
|
|
431
|
-
printJson(routes, runtime);
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
printText(formatRoutes(routes), runtime);
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
if (action === "contract") {
|
|
438
|
-
const domainKey = args[1];
|
|
439
|
-
const capabilityId = args[2];
|
|
440
|
-
if (!domainKey || !capabilityId) {
|
|
441
|
-
throw new Error("Usage: agentrouter capabilities contract <domain> <capability>");
|
|
442
|
-
}
|
|
443
|
-
ensureNoUnexpectedArgs(args, 3);
|
|
444
|
-
const contract = await client.catalog.capabilities.contract(domainKey, capabilityId);
|
|
445
|
-
printJson(contract, runtime);
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
throw new Error("Usage: agentrouter capabilities <list|get|routes|contract> ...");
|
|
449
|
-
}
|
|
450
|
-
async function runRoutesCommand(client, args, _flags, runtime) {
|
|
451
|
-
const action = args[0];
|
|
452
|
-
if (!action) {
|
|
453
|
-
throw new Error("Usage: agentrouter routes context <routeKey>");
|
|
454
|
-
}
|
|
455
|
-
if (action === "context") {
|
|
456
|
-
const routeKey = args[1];
|
|
457
|
-
if (!routeKey) {
|
|
458
|
-
throw new Error("Usage: agentrouter routes context <routeKey>");
|
|
459
|
-
}
|
|
460
|
-
ensureNoUnexpectedArgs(args, 2);
|
|
461
|
-
const context = await client.catalog.routes.context(routeKey);
|
|
462
|
-
printJson(context, runtime);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
throw new Error("Usage: agentrouter routes context <routeKey>");
|
|
466
|
-
}
|
|
467
|
-
async function runRecommendCommand(client, args, flags, runtime) {
|
|
468
|
-
const domainKey = args[0];
|
|
469
|
-
const capabilityId = args[1];
|
|
470
|
-
if (!domainKey || !capabilityId) {
|
|
471
|
-
throw new Error("Usage: agentrouter recommend <domain> <capability> --input <json|@file>");
|
|
472
|
-
}
|
|
473
|
-
ensureNoUnexpectedArgs(args, 2);
|
|
474
|
-
const input = await parseJsonInput(resolveInputSource(flags.input, "request input"), runtime);
|
|
475
|
-
const result = await client.capabilities.recommend({
|
|
476
|
-
domain: domainKey,
|
|
477
|
-
capability: capabilityId,
|
|
478
|
-
input,
|
|
479
|
-
...(resolveUserId(flags, runtime)
|
|
480
|
-
? { userId: resolveUserId(flags, runtime) }
|
|
481
|
-
: {}),
|
|
482
|
-
});
|
|
483
|
-
printJson(result, runtime);
|
|
484
|
-
}
|
|
485
|
-
async function runExecuteCommand(client, args, flags, runtime) {
|
|
486
|
-
const domainKey = args[0];
|
|
487
|
-
const capabilityId = args[1];
|
|
488
|
-
if (!domainKey || !capabilityId) {
|
|
489
|
-
throw new Error("Usage: agentrouter execute <domain> <capability> --input <json|@file>");
|
|
490
|
-
}
|
|
491
|
-
ensureNoUnexpectedArgs(args, 2);
|
|
492
|
-
const input = await parseJsonInput(resolveInputSource(flags.input, "request input"), runtime);
|
|
493
|
-
const userId = resolveUserId(flags, runtime);
|
|
494
|
-
const result = await client.capabilities.execute({
|
|
495
|
-
domain: domainKey,
|
|
496
|
-
capability: capabilityId,
|
|
497
|
-
input,
|
|
498
|
-
...(flags.provider ? { provider: flags.provider } : {}),
|
|
499
|
-
...(flags.routeKey ? { routeKey: flags.routeKey } : {}),
|
|
500
|
-
...(flags.allowFallback ? { allowFallback: true } : {}),
|
|
501
|
-
...(userId ? { userId } : {}),
|
|
502
|
-
});
|
|
503
|
-
printJson(result, runtime);
|
|
504
|
-
}
|
|
505
|
-
async function runRouteCommand(client, args, flags, runtime) {
|
|
506
|
-
const domainKey = args[0];
|
|
507
|
-
if (!domainKey) {
|
|
508
|
-
throw new Error("Usage: agentrouter route <domain> --input <json|@file>");
|
|
509
|
-
}
|
|
510
|
-
ensureNoUnexpectedArgs(args, 1);
|
|
511
|
-
const input = await parseJsonInput(resolveInputSource(flags.input, "request input"), runtime);
|
|
512
|
-
const userId = resolveUserId(flags, runtime);
|
|
513
|
-
const result = await client.routing.route({
|
|
514
|
-
domain: domainKey,
|
|
515
|
-
input,
|
|
516
|
-
...(userId ? { userId } : {}),
|
|
517
|
-
});
|
|
518
|
-
printJson(result, runtime);
|
|
519
|
-
}
|
|
520
|
-
async function runRawCommand(client, args, flags, runtime) {
|
|
521
|
-
const method = args[0]?.toUpperCase();
|
|
522
|
-
const path = args[1];
|
|
523
|
-
if (!method || !path) {
|
|
524
|
-
throw new Error("Usage: agentrouter raw <method> <path> [--input <json|@file>]");
|
|
525
|
-
}
|
|
526
|
-
ensureNoUnexpectedArgs(args, 2);
|
|
527
|
-
const authMode = resolveAuthMode(flags.auth);
|
|
528
|
-
const userId = resolveUserId(flags, runtime);
|
|
529
|
-
const query = parseQueryArgs(flags.query);
|
|
530
|
-
const body = flags.input
|
|
531
|
-
? await parseJsonInput(resolveInputSource(flags.input, "request input"), runtime)
|
|
532
|
-
: undefined;
|
|
533
|
-
const result = await client.raw.request({
|
|
534
|
-
path,
|
|
535
|
-
method: method,
|
|
536
|
-
...(query ? { query } : {}),
|
|
537
|
-
...(body ? { body } : {}),
|
|
538
|
-
authMode,
|
|
539
|
-
...(userId ? { userId } : {}),
|
|
540
|
-
});
|
|
541
|
-
printJson(result, runtime);
|
|
542
|
-
}
|
|
543
|
-
export async function runAgentRouterCli(argv, io = {}) {
|
|
544
|
-
const runtime = createRuntime(io);
|
|
545
|
-
try {
|
|
546
|
-
const { flags, positionals } = parseArgv(argv);
|
|
547
|
-
if (flags.help || positionals.length === 0) {
|
|
548
|
-
runtime.stdout(renderHelp());
|
|
549
|
-
return 0;
|
|
550
|
-
}
|
|
551
|
-
const client = buildClient(flags, runtime);
|
|
552
|
-
const userId = resolveUserId(flags, runtime);
|
|
553
|
-
const command = positionals[0];
|
|
554
|
-
const rest = positionals.slice(1);
|
|
555
|
-
if (command === "wallet") {
|
|
556
|
-
ensureNoUnexpectedArgs(positionals, 1);
|
|
557
|
-
const wallet = await client.wallet.get(userId ? { userId } : {});
|
|
558
|
-
if (flags.json) {
|
|
559
|
-
printJson(wallet, runtime);
|
|
560
|
-
}
|
|
561
|
-
else {
|
|
562
|
-
printText(formatWallet(wallet), runtime);
|
|
563
|
-
}
|
|
564
|
-
return 0;
|
|
565
|
-
}
|
|
566
|
-
if (command === "usage") {
|
|
567
|
-
ensureNoUnexpectedArgs(positionals, 1);
|
|
568
|
-
const usage = await client.usage.list({
|
|
569
|
-
...(typeof resolveNumber(flags.limit, "--limit") === "number"
|
|
570
|
-
? { limit: resolveNumber(flags.limit, "--limit") }
|
|
571
|
-
: {}),
|
|
572
|
-
...(userId ? { userId } : {}),
|
|
573
|
-
});
|
|
574
|
-
if (flags.json) {
|
|
575
|
-
printJson(usage, runtime);
|
|
576
|
-
}
|
|
577
|
-
else {
|
|
578
|
-
printText(formatUsage(usage), runtime);
|
|
579
|
-
}
|
|
580
|
-
return 0;
|
|
581
|
-
}
|
|
582
|
-
if (command === "domains") {
|
|
583
|
-
await runDomainsCommand(client, rest, flags, runtime);
|
|
584
|
-
return 0;
|
|
585
|
-
}
|
|
586
|
-
if (command === "capabilities") {
|
|
587
|
-
await runCapabilitiesCommand(client, rest, flags, runtime);
|
|
588
|
-
return 0;
|
|
589
|
-
}
|
|
590
|
-
if (command === "routes") {
|
|
591
|
-
await runRoutesCommand(client, rest, flags, runtime);
|
|
592
|
-
return 0;
|
|
593
|
-
}
|
|
594
|
-
if (command === "recommend") {
|
|
595
|
-
await runRecommendCommand(client, rest, flags, runtime);
|
|
596
|
-
return 0;
|
|
597
|
-
}
|
|
598
|
-
if (command === "execute") {
|
|
599
|
-
await runExecuteCommand(client, rest, flags, runtime);
|
|
600
|
-
return 0;
|
|
601
|
-
}
|
|
602
|
-
if (command === "route") {
|
|
603
|
-
await runRouteCommand(client, rest, flags, runtime);
|
|
604
|
-
return 0;
|
|
605
|
-
}
|
|
606
|
-
if (command === "raw") {
|
|
607
|
-
await runRawCommand(client, rest, flags, runtime);
|
|
608
|
-
return 0;
|
|
609
|
-
}
|
|
610
|
-
throw new Error(`Unknown command '${command}'. Use --help to inspect CLI usage.`);
|
|
611
|
-
}
|
|
612
|
-
catch (error) {
|
|
613
|
-
if (error instanceof AgentRouterClientError) {
|
|
614
|
-
runtime.stderr(`AgentRouterClientError ${error.status}: ${error.message}\n`);
|
|
615
|
-
if (error.code) {
|
|
616
|
-
runtime.stderr(`code: ${error.code}\n`);
|
|
617
|
-
}
|
|
618
|
-
if (error.hint) {
|
|
619
|
-
runtime.stderr(`hint: ${error.hint}\n`);
|
|
620
|
-
}
|
|
621
|
-
return 1;
|
|
622
|
-
}
|
|
623
|
-
runtime.stderr(`${error instanceof Error ? error.message : "Unknown CLI error."}\n`);
|
|
624
|
-
return 1;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
export const runAgenticCli = runAgentRouterCli;
|