@lidianai/cli 0.1.4 → 0.1.5

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 CHANGED
@@ -2,19 +2,41 @@
2
2
 
3
3
  Bun CLI for Lidian core REST endpoints.
4
4
 
5
- ## Install
5
+ ## Install & Run
6
+
7
+ ### Quick Run (no install)
6
8
 
7
9
  ```bash
8
10
  bunx @lidianai/cli --help
11
+ npm exec @lidianai/cli -- --help
12
+ ```
13
+
14
+ ### Global Install
15
+
16
+ ```bash
17
+ # bun
18
+ bun add -g @lidianai/cli
19
+
20
+ # npm
21
+ npm install -g @lidianai/cli
22
+
23
+ # yarn
24
+ yarn global add @lidianai/cli
25
+
26
+ # pnpm
27
+ pnpm add -g @lidianai/cli
28
+
29
+ # Then run
30
+ lidian --help
9
31
  ```
10
32
 
11
33
  ## Commands
12
34
 
13
35
  ```bash
14
- lidian discover --q "<term>" [--page 1] [--pageSize 1..3] [--category <name>] [--auth-type none|api_key|bearer|basic|oauth2|custom] [--min-price <cents>] [--max-price <cents>] [--api-key <key>] [--env production|staging] [--api-base <url>] [--json]
15
- lidian consume --endpoint-id <uuid> --params '<json>' [--payment-rail prepaid_credits|x402] [--network base|ethereum] [--api-key <key>] [--env production|staging] [--api-base <url>] [--json]
16
- lidian feedback --execution-id <uuid> --rank <0..10> [--feedback "<text>"] [--api-key <key>] [--env production|staging] [--api-base <url>] [--json]
17
- lidian account [--api-key <key>] [--env production|staging] [--api-base <url>] [--json]
36
+ lidian discover --q "<term>" [--page 1] [--pageSize 1..3] [--category <name>] [--auth-type none|api_key|bearer|basic|oauth2|custom] [--min-price <cents>] [--max-price <cents>] [--env production|staging] [--api-base <url>] [--json]
37
+ lidian consume --endpoint-id <uuid> --params '<json>' [--payment-rail prepaid_credits|x402] [--network base|ethereum] [--env production|staging] [--api-base <url>] [--json]
38
+ lidian feedback --execution-id <uuid> --rank <0..10> [--feedback "<text>"] [--env production|staging] [--api-base <url>] [--json]
39
+ lidian account [--env production|staging] [--api-base <url>] [--json]
18
40
  lidian login [--key ld_...] [--json]
19
41
  lidian --help
20
42
  ```
package/dist/index.js ADDED
@@ -0,0 +1,575 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // src/commands/account.ts
5
+ var runAccountCommand = async (http, apiKey) => {
6
+ return http.get("/v1/account", apiKey);
7
+ };
8
+
9
+ // src/lib/errors.ts
10
+ class CliError extends Error {
11
+ code;
12
+ constructor(message, code = 1) {
13
+ super(message);
14
+ this.name = "CliError";
15
+ this.code = code;
16
+ }
17
+ }
18
+
19
+ // src/lib/x402.ts
20
+ var requestPaymentRequirements = async (http, apiKey, endpointId, network) => {
21
+ return http.post("/v1/payments/requirements", { endpointId, ...network ? { network } : {} }, apiKey);
22
+ };
23
+ var verifyPaymentAddress = async (http, apiKey, payTo) => {
24
+ return http.post("/v1/payments/verify", { payTo }, apiKey);
25
+ };
26
+
27
+ // src/commands/consume.ts
28
+ var runConsumeCommand = async (http, apiKey, input) => {
29
+ if (!isUuid(input.endpointId)) {
30
+ throw new CliError("endpointId must be a valid UUID.");
31
+ }
32
+ if (input.paymentRail === "x402") {
33
+ const requirements = await requestPaymentRequirements(http, apiKey, input.endpointId, input.network);
34
+ const verification = await verifyPaymentAddress(http, apiKey, requirements.payTo);
35
+ const execution2 = await http.post("/v1/consume", input, apiKey);
36
+ return {
37
+ execution: execution2,
38
+ payment: {
39
+ requirements,
40
+ verified: verification.valid
41
+ }
42
+ };
43
+ }
44
+ const execution = await http.post("/v1/consume", input, apiKey);
45
+ return { execution };
46
+ };
47
+ var isUuid = (value) => {
48
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
49
+ };
50
+
51
+ // src/commands/discover.ts
52
+ var runDiscoverCommand = async (http, apiKey, input) => {
53
+ if (input.pageSize < 1 || input.pageSize > 3) {
54
+ throw new CliError("pageSize must be between 1 and 3.");
55
+ }
56
+ const params = new URLSearchParams;
57
+ params.set("q", input.q);
58
+ params.set("page", String(input.page));
59
+ params.set("pageSize", String(input.pageSize));
60
+ if (input.category)
61
+ params.set("category", input.category);
62
+ if (input.authType)
63
+ params.set("authType", input.authType);
64
+ if (typeof input.minPrice === "number") {
65
+ params.set("minPrice", String(input.minPrice));
66
+ }
67
+ if (typeof input.maxPrice === "number") {
68
+ params.set("maxPrice", String(input.maxPrice));
69
+ }
70
+ return http.get(`/v1/discover?${params.toString()}`, apiKey);
71
+ };
72
+
73
+ // src/commands/feedback.ts
74
+ var runFeedbackCommand = async (http, apiKey, input) => {
75
+ if (!isUuid2(input.executionId)) {
76
+ throw new CliError("executionId must be a valid UUID.");
77
+ }
78
+ if (!Number.isInteger(input.rank) || input.rank < 0 || input.rank > 10) {
79
+ throw new CliError("rank must be an integer between 0 and 10.");
80
+ }
81
+ if (typeof input.feedback === "string" && input.feedback.length > 1000) {
82
+ throw new CliError("feedback cannot exceed 1000 characters.");
83
+ }
84
+ return http.post("/v1/consume/feedback", input, apiKey);
85
+ };
86
+ var isUuid2 = (value) => {
87
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
88
+ };
89
+
90
+ // src/commands/login.ts
91
+ import { stdin, stdout } from "process";
92
+ import { createInterface } from "readline/promises";
93
+
94
+ // src/lib/config.ts
95
+ import { mkdir, readFile, writeFile } from "fs/promises";
96
+ import { homedir } from "os";
97
+ import { dirname, join } from "path";
98
+ var CONFIG_PATH = join(homedir(), ".lidian", "config.json");
99
+ var getConfigPath = () => CONFIG_PATH;
100
+ var readConfig = async () => {
101
+ try {
102
+ const raw = await readFile(CONFIG_PATH, "utf8");
103
+ const parsed = JSON.parse(raw);
104
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
105
+ return {};
106
+ }
107
+ const apiKey = "apiKey" in parsed && typeof parsed.apiKey === "string" ? parsed.apiKey : undefined;
108
+ return { apiKey };
109
+ } catch {
110
+ return {};
111
+ }
112
+ };
113
+ var writeConfig = async (config) => {
114
+ await mkdir(dirname(CONFIG_PATH), { recursive: true });
115
+ await writeFile(CONFIG_PATH, `${JSON.stringify(config, null, 2)}
116
+ `, "utf8");
117
+ };
118
+
119
+ // src/lib/output.ts
120
+ var print = (message) => {
121
+ process.stdout.write(`${message}
122
+ `);
123
+ };
124
+ var printError = (message) => {
125
+ process.stderr.write(`${message}
126
+ `);
127
+ };
128
+ var printResult = (result, asJson) => {
129
+ if (asJson) {
130
+ print(JSON.stringify(result, null, 2));
131
+ return;
132
+ }
133
+ print(formatForHuman(result));
134
+ };
135
+ var printDiscoverResult = (result, asJson) => {
136
+ if (asJson) {
137
+ printResult(result, true);
138
+ return;
139
+ }
140
+ if (result.items.length === 0) {
141
+ print("No APIs found.");
142
+ return;
143
+ }
144
+ print(`Found ${result.items.length} of ${result.total} APIs (page ${result.page}).`);
145
+ for (const item of result.items) {
146
+ const confidence = item.matchPercent ? ` confidence=${item.matchPercent.toFixed(1)}%` : "";
147
+ const modes = item.paymentModes.join(",");
148
+ print(`- ${item.name} (${item.id}) cost=${item.defaultCostPerUse}c (${formatUsd(item.defaultCostPerUse)}) executable=${String(item.isExecutable)} requiresClientAuth=${String(item.requiresClientAuth)} paymentModes=${modes}${confidence}`);
149
+ for (const endpoint of item.endpoints ?? []) {
150
+ print(` \xB7 endpoint=${endpoint.id} ${endpoint.method} ${endpoint.path} cost=${endpoint.pricingCents}c (${formatUsd(endpoint.pricingCents)})`);
151
+ }
152
+ }
153
+ };
154
+ var printConsumeResult = (result, asJson) => {
155
+ if (asJson) {
156
+ printResult(result.execution, true);
157
+ return;
158
+ }
159
+ if (result.payment) {
160
+ print(`x402 preflight: payTo=${result.payment.requirements.payTo} amount=${result.payment.requirements.amountFormatted} verified=${String(result.payment.verified)}`);
161
+ }
162
+ printExecutionResult(result.execution);
163
+ };
164
+ var printAccountResult = (result, asJson) => {
165
+ if (asJson) {
166
+ printResult(result, true);
167
+ return;
168
+ }
169
+ print(`Account: ${result.user.id}`);
170
+ print(`Balance: ${result.balance.balance} cents (${formatUsd(result.balance.balance)})`);
171
+ };
172
+ var printFeedbackResult = (result, asJson) => {
173
+ if (asJson) {
174
+ printResult(result, true);
175
+ return;
176
+ }
177
+ const feedback = result.feedback ?? "<none>";
178
+ print(`Feedback saved for execution=${result.executionId} rank=${result.rank} submittedBy=${result.submittedBy}`);
179
+ print(`Updated at: ${result.updatedAt}`);
180
+ print(`Comment: ${feedback}`);
181
+ };
182
+ var printExecutionResult = (result) => {
183
+ print(`Execution ID: ${result.executionId}`);
184
+ print(`Execution succeeded. Spent=${result.credits.spent} cents (${formatUsd(result.credits.spent)}) balance=${result.credits.balance} cents (${formatUsd(result.credits.balance)})`);
185
+ print(JSON.stringify(result.data, null, 2));
186
+ };
187
+ var formatForHuman = (value) => {
188
+ if (typeof value === "string") {
189
+ return value;
190
+ }
191
+ return JSON.stringify(value, null, 2);
192
+ };
193
+ var formatUsd = (cents) => {
194
+ return `$${(cents / 100).toFixed(2)}`;
195
+ };
196
+ var fail = (error) => {
197
+ if (error instanceof CliError) {
198
+ printError(`Error: ${error.message}`);
199
+ process.exit(error.code);
200
+ }
201
+ if (error instanceof Error) {
202
+ printError(`Error: ${error.message}`);
203
+ process.exit(1);
204
+ }
205
+ printError("Error: Unknown failure");
206
+ process.exit(1);
207
+ };
208
+
209
+ // src/commands/login.ts
210
+ var runLoginCommand = async (input) => {
211
+ const key = input.key ?? await promptForKeyViaBrowserFlow();
212
+ validateApiKey(key);
213
+ const current = await readConfig();
214
+ await writeConfig({
215
+ ...current,
216
+ apiKey: key
217
+ });
218
+ return { path: getConfigPath() };
219
+ };
220
+ var promptForKeyViaBrowserFlow = async () => {
221
+ const loginUrl = "https://app.lidian.ai/login?next=/user/api-keys";
222
+ openUrl(loginUrl);
223
+ print(`Open this URL to authenticate and create/copy an API key:
224
+ ${loginUrl}`);
225
+ const rl = createInterface({ input: stdin, output: stdout });
226
+ try {
227
+ const entered = (await rl.question("Paste your API key (ld_...): ")).trim();
228
+ if (!entered) {
229
+ throw new CliError("No API key entered.");
230
+ }
231
+ return entered;
232
+ } finally {
233
+ rl.close();
234
+ }
235
+ };
236
+ var validateApiKey = (key) => {
237
+ if (!key.startsWith("ld_")) {
238
+ throw new CliError("Invalid API key format. Expected key starting with ld_.");
239
+ }
240
+ };
241
+ var openUrl = (url) => {
242
+ try {
243
+ if (process.platform === "darwin") {
244
+ Bun.spawn(["open", url], { stdout: "ignore", stderr: "ignore" });
245
+ return;
246
+ }
247
+ if (process.platform === "win32") {
248
+ Bun.spawn(["cmd", "/c", "start", "", url], {
249
+ stdout: "ignore",
250
+ stderr: "ignore"
251
+ });
252
+ return;
253
+ }
254
+ Bun.spawn(["xdg-open", url], { stdout: "ignore", stderr: "ignore" });
255
+ } catch {}
256
+ };
257
+
258
+ // src/lib/auth.ts
259
+ var resolveApiKey = async (argsApiKey) => {
260
+ const config = await readConfig();
261
+ return argsApiKey ?? process.env.LIDIAN_API_KEY ?? config.apiKey;
262
+ };
263
+
264
+ // src/lib/http.ts
265
+ var createHttpClient = (baseUrl) => {
266
+ const normalizedBaseUrl = baseUrl.replace(/\/$/, "");
267
+ return {
268
+ async get(path, apiKey) {
269
+ const response = await fetch(`${normalizedBaseUrl}${path}`, {
270
+ method: "GET",
271
+ headers: authHeaders(apiKey)
272
+ });
273
+ return handleResponse(response);
274
+ },
275
+ async post(path, body, apiKey) {
276
+ const response = await fetch(`${normalizedBaseUrl}${path}`, {
277
+ method: "POST",
278
+ headers: {
279
+ ...authHeaders(apiKey),
280
+ "Content-Type": "application/json"
281
+ },
282
+ body: JSON.stringify(body)
283
+ });
284
+ return handleResponse(response);
285
+ }
286
+ };
287
+ };
288
+ var authHeaders = (apiKey) => {
289
+ if (!apiKey || apiKey.trim().length === 0) {
290
+ return {};
291
+ }
292
+ return {
293
+ Authorization: `Bearer ${apiKey}`
294
+ };
295
+ };
296
+ var handleResponse = async (response) => {
297
+ const json = await response.json().catch(() => null);
298
+ if (!response.ok) {
299
+ if (json && "success" in json && json.success === false) {
300
+ throw new CliError(`${json.error.code}: ${json.error.message}`, 1);
301
+ }
302
+ if (json && typeof json === "object" && "error" in json && typeof json.error === "string") {
303
+ throw new CliError(json.error, 1);
304
+ }
305
+ if (json && typeof json === "object" && "message" in json && typeof json.message === "string") {
306
+ throw new CliError(json.message, 1);
307
+ }
308
+ throw new CliError(`Request failed with status ${response.status}`, 1);
309
+ }
310
+ if (!json || !("success" in json) || json.success !== true) {
311
+ throw new CliError("Unexpected API response format", 1);
312
+ }
313
+ return json.data;
314
+ };
315
+
316
+ // src/index.ts
317
+ var DEFAULT_API_BASE = "https://api.lidian.ai";
318
+ var API_BASE_BY_ENV = {
319
+ production: "https://api.lidian.ai",
320
+ staging: "https://staging-api.lidian.ai"
321
+ };
322
+ var GLOBAL_OPTIONS = new Set(["api-key", "api-base", "env", "json", "help"]);
323
+ var BOOLEAN_OPTIONS = new Set(["json", "help"]);
324
+ var COMMAND_OPTIONS = {
325
+ discover: new Set([
326
+ "q",
327
+ "page",
328
+ "pageSize",
329
+ "category",
330
+ "auth-type",
331
+ "min-price",
332
+ "max-price"
333
+ ]),
334
+ consume: new Set(["endpoint-id", "params", "payment-rail", "network"]),
335
+ feedback: new Set(["execution-id", "rank", "feedback"]),
336
+ account: new Set([]),
337
+ login: new Set(["key"])
338
+ };
339
+ var main = async () => {
340
+ if (process.argv.length <= 2 || process.argv.includes("--help")) {
341
+ printUsage();
342
+ return;
343
+ }
344
+ const parsed = parseArgs(process.argv.slice(2));
345
+ const apiBase = resolveApiBase(asString(parsed.options["api-base"]), asEnvironment(asString(parsed.options.env) ?? process.env.LIDIAN_ENV));
346
+ const asJson = Boolean(parsed.options.json);
347
+ const http = createHttpClient(apiBase);
348
+ switch (parsed.command) {
349
+ case "login": {
350
+ const key = asString(parsed.options.key);
351
+ const result = await runLoginCommand({ key });
352
+ if (asJson) {
353
+ print(JSON.stringify({ success: true, data: result }, null, 2));
354
+ } else {
355
+ print(`Saved API key to ${result.path}`);
356
+ }
357
+ return;
358
+ }
359
+ case "discover": {
360
+ const apiKey = await resolveApiKey(asString(parsed.options["api-key"]));
361
+ const qValue = asString(parsed.options.q);
362
+ if (!qValue) {
363
+ throw new CliError("Missing --q for discover command.");
364
+ }
365
+ const page = toInt(asString(parsed.options.page), 1);
366
+ const pageSize = toInt(asString(parsed.options.pageSize), 1);
367
+ const authType = asAuthType(asString(parsed.options["auth-type"]));
368
+ const minPrice = toNumber(asString(parsed.options["min-price"]), "min-price");
369
+ const maxPrice = toNumber(asString(parsed.options["max-price"]), "max-price");
370
+ const result = await runDiscoverCommand(http, apiKey, {
371
+ q: qValue,
372
+ page,
373
+ pageSize,
374
+ category: asString(parsed.options.category),
375
+ ...authType ? { authType } : {},
376
+ ...typeof minPrice === "number" ? { minPrice } : {},
377
+ ...typeof maxPrice === "number" ? { maxPrice } : {}
378
+ });
379
+ printDiscoverResult(result, asJson);
380
+ return;
381
+ }
382
+ case "consume": {
383
+ const apiKey = await resolveApiKey(asString(parsed.options["api-key"]));
384
+ const endpointIdValue = asString(parsed.options["endpoint-id"]);
385
+ if (!endpointIdValue) {
386
+ throw new CliError("Missing --endpoint-id for consume command.");
387
+ }
388
+ const paramsRaw = asString(parsed.options.params) ?? "{}";
389
+ const params = parseJsonObject(paramsRaw, "--params");
390
+ const paymentRail = resolvePaymentRail(asString(parsed.options["payment-rail"]), apiKey);
391
+ const network = asNetwork(asString(parsed.options.network));
392
+ const result = await runConsumeCommand(http, apiKey, {
393
+ endpointId: endpointIdValue,
394
+ params,
395
+ paymentRail,
396
+ ...network ? { network } : {}
397
+ });
398
+ printConsumeResult(result, asJson);
399
+ return;
400
+ }
401
+ case "account": {
402
+ const apiKey = await resolveApiKey(asString(parsed.options["api-key"]));
403
+ const result = await runAccountCommand(http, apiKey);
404
+ printAccountResult(result, asJson);
405
+ return;
406
+ }
407
+ case "feedback": {
408
+ const apiKey = await resolveApiKey(asString(parsed.options["api-key"]));
409
+ const executionId = asString(parsed.options["execution-id"]);
410
+ if (!executionId) {
411
+ throw new CliError("Missing --execution-id for feedback command.");
412
+ }
413
+ const rankRaw = asString(parsed.options.rank);
414
+ if (!rankRaw) {
415
+ throw new CliError("Missing --rank for feedback command.");
416
+ }
417
+ const rank = toIntInRange(rankRaw, "rank", 0, 10);
418
+ const feedback = asString(parsed.options.feedback);
419
+ const result = await runFeedbackCommand(http, apiKey, {
420
+ executionId,
421
+ rank,
422
+ ...feedback ? { feedback } : {}
423
+ });
424
+ printFeedbackResult(result, asJson);
425
+ return;
426
+ }
427
+ default:
428
+ throw new CliError("Unknown command.", 1);
429
+ }
430
+ };
431
+ var parseArgs = (argv) => {
432
+ const command = argv[0];
433
+ if (command !== "discover" && command !== "consume" && command !== "feedback" && command !== "account" && command !== "login") {
434
+ printUsage();
435
+ throw new CliError("Invalid command. Use one of: login, discover, consume, feedback, account.", 1);
436
+ }
437
+ const options = {};
438
+ let index = 1;
439
+ while (index < argv.length) {
440
+ const token = argv[index];
441
+ if (!token || !token.startsWith("--")) {
442
+ throw new CliError(`Unexpected argument: ${token ?? "<empty>"}`);
443
+ }
444
+ const key = token.slice(2);
445
+ const allowedForCommand = COMMAND_OPTIONS[command];
446
+ if (!GLOBAL_OPTIONS.has(key) && !allowedForCommand.has(key)) {
447
+ throw new CliError(`Unknown option for ${command}: --${key}`);
448
+ }
449
+ const next = argv[index + 1];
450
+ if (!next || next.startsWith("--")) {
451
+ if (!BOOLEAN_OPTIONS.has(key)) {
452
+ throw new CliError(`Missing value for --${key}`);
453
+ }
454
+ options[key] = true;
455
+ index += 1;
456
+ continue;
457
+ }
458
+ options[key] = next;
459
+ index += 2;
460
+ }
461
+ return {
462
+ command,
463
+ options
464
+ };
465
+ };
466
+ var printUsage = () => {
467
+ print("Usage:");
468
+ print(" lidian login [--key ld_...] [--json]");
469
+ print(' lidian discover --q "<term>" [--page 1] [--pageSize 1..3] [--category <name>] [--auth-type none|api_key|bearer|basic|oauth2|custom]');
470
+ print(" [--min-price <cents>] [--max-price <cents>] [--env production|staging] [--api-base <url>] [--json]");
471
+ print(" lidian consume --endpoint-id <uuid> --params '<json>' [--payment-rail prepaid_credits|x402] [--network base|ethereum] [--env production|staging] [--api-base <url>] [--json]");
472
+ print(' lidian feedback --execution-id <uuid> --rank <0..10> [--feedback "<text>"] [--env production|staging] [--api-base <url>] [--json]');
473
+ print(" lidian account [--env production|staging] [--api-base <url>] [--json]");
474
+ print("");
475
+ print("Auth (all optional):");
476
+ print(" --api-key <key> | LIDIAN_API_KEY | lidian login");
477
+ print("");
478
+ print("Env resolution:");
479
+ print(" --api-base > LIDIAN_API_BASE > --env > LIDIAN_ENV > production");
480
+ print(` production=${API_BASE_BY_ENV.production}`);
481
+ print(` staging=${API_BASE_BY_ENV.staging}`);
482
+ };
483
+ var asString = (value) => {
484
+ if (typeof value === "string")
485
+ return value;
486
+ return;
487
+ };
488
+ var toInt = (value, fallback) => {
489
+ if (!value)
490
+ return fallback;
491
+ const parsed = Number.parseInt(value, 10);
492
+ if (Number.isNaN(parsed) || parsed < 1) {
493
+ throw new CliError(`Invalid integer value: ${value}`);
494
+ }
495
+ return parsed;
496
+ };
497
+ var toIntInRange = (value, flagName, min, max) => {
498
+ const parsed = Number.parseInt(value, 10);
499
+ if (Number.isNaN(parsed) || String(parsed) !== value || parsed < min || parsed > max) {
500
+ throw new CliError(`Invalid --${flagName} value: ${value}. Expected integer ${min}..${max}.`);
501
+ }
502
+ return parsed;
503
+ };
504
+ var toNumber = (value, flagName) => {
505
+ if (!value)
506
+ return;
507
+ const parsed = Number(value);
508
+ if (Number.isNaN(parsed)) {
509
+ throw new CliError(`Invalid --${flagName} value: ${value}`);
510
+ }
511
+ return parsed;
512
+ };
513
+ var parseJsonObject = (value, flagName) => {
514
+ let parsed;
515
+ try {
516
+ parsed = JSON.parse(value);
517
+ } catch {
518
+ throw new CliError(`${flagName} must be valid JSON.`);
519
+ }
520
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
521
+ throw new CliError(`${flagName} must be a JSON object.`);
522
+ }
523
+ return parsed;
524
+ };
525
+ var asPaymentRail = (value) => {
526
+ if (value === "prepaid_credits" || value === "x402")
527
+ return value;
528
+ throw new CliError("Invalid --payment-rail. Use prepaid_credits or x402.");
529
+ };
530
+ var resolvePaymentRail = (value, apiKey) => {
531
+ if (value) {
532
+ return asPaymentRail(value);
533
+ }
534
+ return apiKey && apiKey.trim().length > 0 ? "prepaid_credits" : "x402";
535
+ };
536
+ var asAuthType = (value) => {
537
+ if (!value)
538
+ return;
539
+ const valid = new Set([
540
+ "none",
541
+ "api_key",
542
+ "bearer",
543
+ "basic",
544
+ "oauth2",
545
+ "custom"
546
+ ]);
547
+ if (valid.has(value)) {
548
+ return value;
549
+ }
550
+ throw new CliError("Invalid --auth-type. Use none, api_key, bearer, basic, oauth2, or custom.");
551
+ };
552
+ var asNetwork = (value) => {
553
+ if (!value)
554
+ return;
555
+ if (value === "base" || value === "ethereum")
556
+ return value;
557
+ throw new CliError("Invalid --network. Use base or ethereum.");
558
+ };
559
+ var asEnvironment = (value) => {
560
+ if (!value)
561
+ return;
562
+ if (value === "production" || value === "staging")
563
+ return value;
564
+ throw new CliError("Invalid --env. Use production or staging.");
565
+ };
566
+ var resolveApiBase = (cliApiBase, environment) => {
567
+ if (cliApiBase)
568
+ return cliApiBase;
569
+ if (process.env.LIDIAN_API_BASE)
570
+ return process.env.LIDIAN_API_BASE;
571
+ if (environment)
572
+ return API_BASE_BY_ENV[environment];
573
+ return DEFAULT_API_BASE;
574
+ };
575
+ main().catch(fail);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lidianai/cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "publishConfig": {
package/src/index.ts CHANGED
@@ -209,19 +209,21 @@ const printUsage = (): void => {
209
209
  ' lidian discover --q "<term>" [--page 1] [--pageSize 1..3] [--category <name>] [--auth-type none|api_key|bearer|basic|oauth2|custom]',
210
210
  );
211
211
  print(
212
- " [--min-price <cents>] [--max-price <cents>] [--api-key <key>] [--env production|staging] [--api-base <url>] [--json]",
212
+ " [--min-price <cents>] [--max-price <cents>] [--env production|staging] [--api-base <url>] [--json]",
213
213
  );
214
214
  print(
215
- " lidian consume --endpoint-id <uuid> --params '<json>' [--payment-rail prepaid_credits|x402] [--api-key <key>] [--env production|staging] [--api-base <url>] [--json]",
215
+ " lidian consume --endpoint-id <uuid> --params '<json>' [--payment-rail prepaid_credits|x402] [--network base|ethereum] [--env production|staging] [--api-base <url>] [--json]",
216
216
  );
217
- print(" [--network base|ethereum]");
218
217
  print(
219
- ' lidian feedback --execution-id <uuid> --rank <0..10> [--feedback "<text>"] [--api-key <key>] [--env production|staging] [--api-base <url>] [--json]',
218
+ ' lidian feedback --execution-id <uuid> --rank <0..10> [--feedback "<text>"] [--env production|staging] [--api-base <url>] [--json]',
220
219
  );
221
220
  print(
222
- " lidian account [--api-key <key>] [--env production|staging] [--api-base <url>] [--json]",
221
+ " lidian account [--env production|staging] [--api-base <url>] [--json]",
223
222
  );
224
223
  print("");
224
+ print("Auth (all optional):");
225
+ print(" --api-key <key> | LIDIAN_API_KEY | lidian login");
226
+ print("");
225
227
  print("Env resolution:");
226
228
  print(" --api-base > LIDIAN_API_BASE > --env > LIDIAN_ENV > production");
227
229
  print(` production=${API_BASE_BY_ENV.production}`);