@flovialabs/sdk 0.1.9 → 0.1.10
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/CHANGELOG.md +8 -0
- package/README.md +8 -3
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +75 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.10
|
|
6
|
+
|
|
7
|
+
- `flovia tools` keeps a short second sentence of each description, so what a tool is for stays visible.
|
|
8
|
+
- `flovia tools <tool>` ends with a runnable `flovia call` example from the schema's required arguments and the stdin form; tools with `operation_id` repeat how to keep it for recovery.
|
|
9
|
+
- An unknown tool name in `tools <tool>` or `call` suggests the closest offered name. `call` reads the catalog only after Flovia reports the name as unknown.
|
|
10
|
+
- With `--json`, errors are also printed as one JSON object on stdout (`ok`, `code`, `meaning`, `next_step`, `executed`, `retry_after_seconds`, `operation_id`, plus the reply's fields). Exit codes are unchanged.
|
|
11
|
+
- New `flovia agents-md` prints a short note for `CLAUDE.md` or `AGENTS.md`. No key or network is used.
|
|
12
|
+
|
|
5
13
|
## 0.1.9
|
|
6
14
|
|
|
7
15
|
- `flovia tools <tool>` shows just one offered tool's full description and input schema. With `--json` it returns that tool object; the existing full catalog array is unchanged. This only reads the catalog.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ TypeScript client and command-line tool for [Flovia](https://api.flovia.dev). It
|
|
|
10
10
|
## Install
|
|
11
11
|
|
|
12
12
|
```sh
|
|
13
|
-
npm install --save-exact @flovialabs/sdk@0.1.
|
|
13
|
+
npm install --save-exact @flovialabs/sdk@0.1.10
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Your key
|
|
@@ -226,10 +226,11 @@ npx flovia call flovia_usage_today '{}'
|
|
|
226
226
|
npx flovia generate --op sdk-example-0001 --max-output 1000 --reasoning-effort low "Explain a DEX aggregator."
|
|
227
227
|
# Only to reopen that exact request within about 15 minutes (not a new generation):
|
|
228
228
|
npx flovia generate --op sdk-example-0001 --max-output 1000 --reasoning-effort low --yes "Explain a DEX aggregator."
|
|
229
|
+
npx flovia agents-md # a short note for CLAUDE.md or AGENTS.md
|
|
229
230
|
npx flovia help
|
|
230
231
|
npx flovia --version
|
|
231
232
|
```
|
|
232
|
-
These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.
|
|
233
|
+
These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.10 flovia --help`. Use a unique operation id for each new request; `sdk-example-0001` is only an example. Save the id, prompt and options before sending, and keep them unchanged for replay.
|
|
233
234
|
|
|
234
235
|
Get or manage your key in [Console](https://console.flovia.dev/groupbuy/), save it privately, then run `flovia status --key-file <saved-key-file>`. A connected key can still have sharing declined, withdrawn or stopped; `status` shows those separately from provider availability. It never answers consent for you.
|
|
235
236
|
|
|
@@ -239,7 +240,11 @@ For a data lookup, save its JSON object (including your chosen `operation_id`) i
|
|
|
239
240
|
flovia call flovia_coingecko - < request.json
|
|
240
241
|
```
|
|
241
242
|
|
|
242
|
-
This sends the saved request once. Reopening it uses the same file and operation ID; never create a new ID to recover a lost answer. The CLI does not invent or save an ID for `call`. Inspect the live `inputSchema` first, and follow any returned consent or recovery instructions. `tools <tool> --json` returns one tool object; `tools --json` keeps returning the full array. Neither executes a data lookup.
|
|
243
|
+
This sends the saved request once. Reopening it uses the same file and operation ID; never create a new ID to recover a lost answer. The CLI does not invent or save an ID for `call`. Inspect the live `inputSchema` first, and follow any returned consent or recovery instructions. `tools <tool> --json` returns one tool object; `tools --json` keeps returning the full array. Neither executes a data lookup. Without `--json`, `tools <tool>` ends with an example `call` line built from the schema's required arguments (placeholders to replace). An unknown tool name gets the closest offered name.
|
|
244
|
+
|
|
245
|
+
With `--json`, an error is also one JSON object on stdout: `ok: false`, `code`, `meaning`, and when present `next_step`, `executed`, `retry_after_seconds` and `operation_id`, next to the reply's own fields. Exit codes stay 0, 1 and 2.
|
|
246
|
+
|
|
247
|
+
For an AI agent, `flovia agents-md` prints a short note to paste into `CLAUDE.md` or `AGENTS.md`. It contains no key and makes no request.
|
|
243
248
|
|
|
244
249
|
For multiline generation text, keep the original input in a private file:
|
|
245
250
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -15,6 +15,9 @@ export interface Io {
|
|
|
15
15
|
/** TTY-only waiting feedback on stderr; returns a cleanup function. Never used with --json. */
|
|
16
16
|
waiting?: () => () => void;
|
|
17
17
|
}
|
|
18
|
+
export declare const AGENTS_MD = "## Flovia\n- Flovia is available through the `flovia` CLI. The key is in the FLOVIA_KEY environment variable; never paste, print or commit it.\n- Run `flovia status` first: it shows allowances, services and any consent the person must answer.\n- Find a tool with `flovia tools`, and its arguments with `flovia tools <tool> --json`.\n- Write the arguments to request.json, then run `flovia call <tool> - < request.json`.\n- Before a data lookup, save request.json with its operation_id. To recover a lost reply, send the same file with the same id; never a new id.\n- On an error, read `next_step` (and `retry_after_seconds`) and follow it. With `--json`, errors are one JSON object on stdout.\n";
|
|
19
|
+
/** Runnable call lines from the schema's required properties, the stdin form and, with operation_id, how to keep it. */
|
|
20
|
+
export declare function exampleCall(tool: string, schema: unknown): string;
|
|
18
21
|
export declare function help(command?: string): string;
|
|
19
22
|
export interface Parsed {
|
|
20
23
|
command: string;
|
package/dist/cli.js
CHANGED
|
@@ -17,6 +17,7 @@ const COMMANDS = {
|
|
|
17
17
|
tools: { usage: "tools [tool]", about: "list offered tools, or inspect one tool's description and arguments", flags: {} },
|
|
18
18
|
call: { usage: "call <tool> ['<json args>' | -]", about: "call a tool; - reads a JSON object from stdin", flags: {} },
|
|
19
19
|
generate: { usage: "generate (--op ID | --new-op) [--max-output N]\n [--reasoning-effort LEVEL] [--yes] <prompt | ->", about: "a text generation (uses your free allowance, then your purchased balance)", flags: { "--op": true, "--new-op": false, "--max-output": true, "--reasoning-effort": true, "--yes": false } },
|
|
20
|
+
"agents-md": { usage: "agents-md", about: "a short Flovia note to paste into CLAUDE.md or AGENTS.md (no network)", flags: {} },
|
|
20
21
|
help: { usage: "help [command]", about: "this help", flags: {} },
|
|
21
22
|
version: { usage: "version", about: "the installed CLI version", flags: {} },
|
|
22
23
|
};
|
|
@@ -35,6 +36,50 @@ function distance(a, b) {
|
|
|
35
36
|
}
|
|
36
37
|
const near = (word, options) => options.find((k) => distance(k, word) <= 2 || k.startsWith(word));
|
|
37
38
|
const didYouMean = (word, options, quote = "") => { const n = near(word, options); return n === undefined ? "" : `; did you mean ${quote}${n}${quote}?`; };
|
|
39
|
+
/** Agents often drop the flovia_ prefix ("coingecko"), which is too far for near() alone. */
|
|
40
|
+
const notOffered = (word, names) => {
|
|
41
|
+
const n = near(word, names) ?? near(`flovia_${word}`, names);
|
|
42
|
+
return `Tool is not offered to this key${n === undefined ? "." : `; did you mean "${n}"?`} Run: flovia tools`;
|
|
43
|
+
};
|
|
44
|
+
const SAVE_OP = ["Save the request and operation_id before sending a data lookup.",
|
|
45
|
+
"To recover a lost reply, keep the same request and operation_id.",
|
|
46
|
+
"Never create a new operation_id just to recover an answer."];
|
|
47
|
+
export const AGENTS_MD = `## Flovia
|
|
48
|
+
- Flovia is available through the \`flovia\` CLI. The key is in the FLOVIA_KEY environment variable; never paste, print or commit it.
|
|
49
|
+
- Run \`flovia status\` first: it shows allowances, services and any consent the person must answer.
|
|
50
|
+
- Find a tool with \`flovia tools\`, and its arguments with \`flovia tools <tool> --json\`.
|
|
51
|
+
- Write the arguments to request.json, then run \`flovia call <tool> - < request.json\`.
|
|
52
|
+
- Before a data lookup, save request.json with its operation_id. To recover a lost reply, send the same file with the same id; never a new id.
|
|
53
|
+
- On an error, read \`next_step\` (and \`retry_after_seconds\`) and follow it. With \`--json\`, errors are one JSON object on stdout.
|
|
54
|
+
`;
|
|
55
|
+
/** A placeholder for one schema property: its example, default or first enum value, else a value of its type. */
|
|
56
|
+
function placeholder(name, s) {
|
|
57
|
+
if (s.example !== undefined)
|
|
58
|
+
return s.example;
|
|
59
|
+
if (Array.isArray(s.examples) && s.examples.length)
|
|
60
|
+
return s.examples[0];
|
|
61
|
+
if (s.default !== undefined)
|
|
62
|
+
return s.default;
|
|
63
|
+
if (Array.isArray(s.enum) && s.enum.length)
|
|
64
|
+
return s.enum[0];
|
|
65
|
+
const type = Array.isArray(s.type) ? s.type[0] : s.type;
|
|
66
|
+
return type === "integer" || type === "number" ? 1 : type === "boolean" ? false : type === "array" ? [] : type === "object" ? {} : `<${name}>`;
|
|
67
|
+
}
|
|
68
|
+
/** Runnable call lines from the schema's required properties, the stdin form and, with operation_id, how to keep it. */
|
|
69
|
+
export function exampleCall(tool, schema) {
|
|
70
|
+
const s = obj(schema), props = obj(s["properties"]), required = Array.isArray(s["required"]) ? s["required"].map(String) : [];
|
|
71
|
+
const args = Object.fromEntries(required.map((k) => [k, placeholder(k, obj(props[k]))]));
|
|
72
|
+
const lines = ["", "Example (replace the placeholders):", ` flovia call ${tool} '${JSON.stringify(args).replaceAll("'", "'\\''")}'`,
|
|
73
|
+
"Or from a saved file:", ` flovia call ${tool} - < request.json`];
|
|
74
|
+
if (Object.hasOwn(props, "operation_id"))
|
|
75
|
+
lines.push(...SAVE_OP);
|
|
76
|
+
return lines.join("\n") + "\n";
|
|
77
|
+
}
|
|
78
|
+
/** The first sentence, plus the next when both fit in about 200 characters, so what the tool is for survives. */
|
|
79
|
+
const brief = (description) => {
|
|
80
|
+
const [first = "", second] = description.split(/(?<=\.)\s/);
|
|
81
|
+
return second !== undefined && first.length + second.length < 200 ? `${first} ${second}` : first;
|
|
82
|
+
};
|
|
38
83
|
export function help(command) {
|
|
39
84
|
const c = command === undefined || !Object.hasOwn(COMMANDS, command) ? undefined : COMMANDS[command];
|
|
40
85
|
const lines = c === undefined ? ["Usage: flovia <command> [options]", "",
|
|
@@ -45,7 +90,7 @@ export function help(command) {
|
|
|
45
90
|
if (command === "tools" || c === undefined)
|
|
46
91
|
lines.push("", "Inspect one tool: flovia tools <tool> --json", "Inspect all tool arguments: flovia tools --json", "Read-only example: flovia call flovia_status '{}'");
|
|
47
92
|
if (command === "call")
|
|
48
|
-
lines.push("", "Read a saved request: flovia call <tool> - < request.json",
|
|
93
|
+
lines.push("", "Read a saved request: flovia call <tool> - < request.json", ...SAVE_OP);
|
|
49
94
|
lines.push("", "Default base URL: https://api.flovia.dev.", "Exit codes: 0 ok, 1 error from Flovia, 2 usage error.", "");
|
|
50
95
|
return lines.join("\n");
|
|
51
96
|
}
|
|
@@ -243,10 +288,16 @@ export async function run(argv, io) {
|
|
|
243
288
|
out(`flovia ${VERSION}\n`);
|
|
244
289
|
return 0;
|
|
245
290
|
}
|
|
291
|
+
if (p.command === "agents-md") {
|
|
292
|
+
out(AGENTS_MD);
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
246
295
|
}
|
|
247
296
|
catch (e) {
|
|
248
297
|
if (e instanceof Usage) {
|
|
249
298
|
err(`${e.message}\n`);
|
|
299
|
+
if (argv.includes("--json"))
|
|
300
|
+
out(JSON.stringify({ ok: false, code: "usage", meaning: e.message }, null, 2) + "\n");
|
|
250
301
|
return 2;
|
|
251
302
|
}
|
|
252
303
|
throw e;
|
|
@@ -310,16 +361,16 @@ export async function run(argv, io) {
|
|
|
310
361
|
if (name !== undefined) {
|
|
311
362
|
const tool = tools.find((t) => t.name === name);
|
|
312
363
|
if (tool === undefined)
|
|
313
|
-
throw new Usage(
|
|
364
|
+
throw new Usage(notOffered(name, tools.map((t) => t.name)));
|
|
314
365
|
if (json)
|
|
315
366
|
print(tool);
|
|
316
367
|
else
|
|
317
|
-
out(`${tool.name}\n${tool.description ?? ""}\n\nArguments (JSON Schema):\n${JSON.stringify(tool.inputSchema, null, 2)}\n`);
|
|
368
|
+
out(`${tool.name}\n${tool.description ?? ""}\n\nArguments (JSON Schema):\n${JSON.stringify(tool.inputSchema, null, 2)}\n${exampleCall(tool.name, tool.inputSchema)}`);
|
|
318
369
|
}
|
|
319
370
|
else if (json)
|
|
320
371
|
print(tools);
|
|
321
372
|
else
|
|
322
|
-
out(tools.map((t) => `${t.name}\n ${prose((t.description ?? "")
|
|
373
|
+
out(tools.map((t) => `${t.name}\n ${prose(brief(t.description ?? ""))}\n`).join("\n") + "\nArguments: flovia tools <tool> --json\nRead-only example: flovia call flovia_status '{}'\n");
|
|
323
374
|
return 0;
|
|
324
375
|
}
|
|
325
376
|
case "call": {
|
|
@@ -346,7 +397,16 @@ export async function run(argv, io) {
|
|
|
346
397
|
if (args === null || typeof args !== "object" || Array.isArray(args))
|
|
347
398
|
throw new Usage("call: the arguments must be a JSON object");
|
|
348
399
|
const client = await connect();
|
|
349
|
-
|
|
400
|
+
try {
|
|
401
|
+
print(await waitFor(() => client.call(tool, args)));
|
|
402
|
+
}
|
|
403
|
+
catch (e) {
|
|
404
|
+
// The relay's MCP server refuses an unknown name with "Tool <name> not found" before running anything; only then read the catalog to suggest one.
|
|
405
|
+
if (!(e instanceof FloviaError && e.code === "mcp_error" && /\bTool \S+ (not found|disabled)/.test(e.message)))
|
|
406
|
+
throw e;
|
|
407
|
+
const names = await client.listTools().then((t) => t.map((x) => x.name), () => []);
|
|
408
|
+
throw new FloviaError({ code: "tool_not_offered", executed: "no", message: notOffered(tool, names), nextStep: "Run: flovia tools" });
|
|
409
|
+
}
|
|
350
410
|
return 0;
|
|
351
411
|
}
|
|
352
412
|
case "generate": {
|
|
@@ -401,17 +461,24 @@ export async function run(argv, io) {
|
|
|
401
461
|
catch (e) {
|
|
402
462
|
if (e instanceof Usage) {
|
|
403
463
|
err(`${e.message}\n`);
|
|
464
|
+
if (json)
|
|
465
|
+
print({ ok: false, code: "usage", meaning: e.message });
|
|
404
466
|
return 2;
|
|
405
467
|
}
|
|
406
468
|
if (e instanceof FloviaError) {
|
|
407
|
-
|
|
408
|
-
|
|
469
|
+
// One JSON object on stdout: the reply's own fields, plus the cause and next step at the top level.
|
|
470
|
+
if (json)
|
|
471
|
+
print({ ...obj(e.reply), ok: false, code: e.code, meaning: e.message, ...(e.nextStep ? { next_step: e.nextStep } : {}), executed: e.executed,
|
|
472
|
+
...(e.retryAfterSeconds !== null ? { retry_after_seconds: e.retryAfterSeconds } : {}), ...(e.operationId ? { operation_id: e.operationId } : {}) });
|
|
409
473
|
err(renderError(e));
|
|
410
474
|
if (p.command === "generate" && e.operationId && e.executed === "unknown")
|
|
411
475
|
err(`To recover: rerun with --op ${e.operationId}, the same prompt or prompt file, ${recoveryLimit === undefined ? "no --max-output" : `--max-output ${recoveryLimit}`}, ${recoveryEffort === undefined ? "no --reasoning-effort" : `--reasoning-effort ${recoveryEffort}`},\nand the same --key-file and --base-url. Do not use --new-op or change the request; that can charge again.\n`);
|
|
412
476
|
return e.code === "invalid_base_url" ? 2 : 1;
|
|
413
477
|
}
|
|
414
|
-
|
|
478
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
479
|
+
err(`error: ${message}\n`);
|
|
480
|
+
if (json)
|
|
481
|
+
print({ ok: false, code: "error", meaning: message });
|
|
415
482
|
return 1;
|
|
416
483
|
}
|
|
417
484
|
}
|
package/package.json
CHANGED