@flovialabs/sdk 0.1.8 → 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 +13 -0
- package/README.md +17 -3
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +100 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
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
|
+
|
|
13
|
+
## 0.1.9
|
|
14
|
+
|
|
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.
|
|
16
|
+
- `flovia call <tool> -` reads a saved JSON object from stdin, keeping the operation ID and request unchanged. Invalid input stops before connecting. No automatic replay or new operation ID is added.
|
|
17
|
+
|
|
5
18
|
## 0.1.8
|
|
6
19
|
|
|
7
20
|
- Expect relay contract `2026-10-07.135`, which adds optional `fresh` input for Exa and Firecrawl. Identical requests by the same user can reuse a completed answer for 15 minutes; `fresh: true` asks for a new lookup. Recovery with the same operation id stays unchanged.
|
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
|
|
@@ -221,18 +221,32 @@ npx flovia status
|
|
|
221
221
|
npx flovia usage --days 3
|
|
222
222
|
npx flovia tools
|
|
223
223
|
npx flovia tools --json # includes each tool's inputSchema
|
|
224
|
+
npx flovia tools flovia_coingecko --json # only this tool's description and inputSchema
|
|
224
225
|
npx flovia call flovia_usage_today '{}'
|
|
225
226
|
npx flovia generate --op sdk-example-0001 --max-output 1000 --reasoning-effort low "Explain a DEX aggregator."
|
|
226
227
|
# Only to reopen that exact request within about 15 minutes (not a new generation):
|
|
227
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
|
|
228
230
|
npx flovia help
|
|
229
231
|
npx flovia --version
|
|
230
232
|
```
|
|
231
|
-
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.
|
|
232
234
|
|
|
233
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.
|
|
234
236
|
|
|
235
|
-
For
|
|
237
|
+
For a data lookup, save its JSON object (including your chosen `operation_id`) in a private `request.json` before sending. Keep it out of Git and read it from stdin rather than quoting it in a shell argument:
|
|
238
|
+
|
|
239
|
+
```sh
|
|
240
|
+
flovia call flovia_coingecko - < request.json
|
|
241
|
+
```
|
|
242
|
+
|
|
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.
|
|
248
|
+
|
|
249
|
+
For multiline generation text, keep the original input in a private file:
|
|
236
250
|
|
|
237
251
|
```sh
|
|
238
252
|
flovia generate --new-op --max-output 1000 --reasoning-effort high --yes - < prompt.txt
|
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
|
@@ -14,9 +14,10 @@ const VERSION = String(JSON.parse(readFileSync(new URL("../package.json", import
|
|
|
14
14
|
const COMMANDS = {
|
|
15
15
|
status: { usage: "status", about: "usage windows, services, contract version and recent updates", flags: {} },
|
|
16
16
|
usage: { usage: "usage [--since ISO | --days N] [--cursor C]", about: "lookups and generations (today, or since a time within 7 days)", flags: { "--since": true, "--days": true, "--cursor": true } },
|
|
17
|
-
tools: { usage: "tools", about: "
|
|
18
|
-
call: { usage: "call <tool> ['<json args>']", about: "call
|
|
17
|
+
tools: { usage: "tools [tool]", about: "list offered tools, or inspect one tool's description and arguments", flags: {} },
|
|
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]", "",
|
|
@@ -43,7 +88,9 @@ export function help(command) {
|
|
|
43
88
|
if (command === "generate")
|
|
44
89
|
lines.push("", "Default output limit: 1000 tokens; maximum: 4000.", "--reasoning-effort: none (default), low, medium, high, xhigh, max.", "Reasoning shares the output token limit; higher effort can leave less visible text.", "Long answers can take minutes. Save the id, same input, output limit and effort.", " flovia generate --new-op --reasoning-effort high --yes - < prompt.txt", "Replay only: replace --new-op with --op <saved-id>; keep everything else.", "Use -- before a prompt that starts with a hyphen.");
|
|
45
90
|
if (command === "tools" || c === undefined)
|
|
46
|
-
lines.push("", "Inspect tool arguments: flovia tools --json", "Read-only example: flovia call flovia_status '{}'");
|
|
91
|
+
lines.push("", "Inspect one tool: flovia tools <tool> --json", "Inspect all tool arguments: flovia tools --json", "Read-only example: flovia call flovia_status '{}'");
|
|
92
|
+
if (command === "call")
|
|
93
|
+
lines.push("", "Read a saved request: flovia call <tool> - < request.json", ...SAVE_OP);
|
|
47
94
|
lines.push("", "Default base URL: https://api.flovia.dev.", "Exit codes: 0 ok, 1 error from Flovia, 2 usage error.", "");
|
|
48
95
|
return lines.join("\n");
|
|
49
96
|
}
|
|
@@ -241,10 +288,16 @@ export async function run(argv, io) {
|
|
|
241
288
|
out(`flovia ${VERSION}\n`);
|
|
242
289
|
return 0;
|
|
243
290
|
}
|
|
291
|
+
if (p.command === "agents-md") {
|
|
292
|
+
out(AGENTS_MD);
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
244
295
|
}
|
|
245
296
|
catch (e) {
|
|
246
297
|
if (e instanceof Usage) {
|
|
247
298
|
err(`${e.message}\n`);
|
|
299
|
+
if (argv.includes("--json"))
|
|
300
|
+
out(JSON.stringify({ ok: false, code: "usage", meaning: e.message }, null, 2) + "\n");
|
|
248
301
|
return 2;
|
|
249
302
|
}
|
|
250
303
|
throw e;
|
|
@@ -301,17 +354,38 @@ export async function run(argv, io) {
|
|
|
301
354
|
return 0;
|
|
302
355
|
}
|
|
303
356
|
case "tools": {
|
|
357
|
+
const [name, extra] = p.positional;
|
|
358
|
+
if (extra !== undefined)
|
|
359
|
+
throw new Usage(`Usage: flovia ${COMMANDS["tools"]?.usage}`);
|
|
304
360
|
const client = await connect(), tools = await waitFor(() => client.listTools());
|
|
305
|
-
if (
|
|
361
|
+
if (name !== undefined) {
|
|
362
|
+
const tool = tools.find((t) => t.name === name);
|
|
363
|
+
if (tool === undefined)
|
|
364
|
+
throw new Usage(notOffered(name, tools.map((t) => t.name)));
|
|
365
|
+
if (json)
|
|
366
|
+
print(tool);
|
|
367
|
+
else
|
|
368
|
+
out(`${tool.name}\n${tool.description ?? ""}\n\nArguments (JSON Schema):\n${JSON.stringify(tool.inputSchema, null, 2)}\n${exampleCall(tool.name, tool.inputSchema)}`);
|
|
369
|
+
}
|
|
370
|
+
else if (json)
|
|
306
371
|
print(tools);
|
|
307
372
|
else
|
|
308
|
-
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");
|
|
309
374
|
return 0;
|
|
310
375
|
}
|
|
311
376
|
case "call": {
|
|
312
|
-
const [tool,
|
|
377
|
+
const [tool, input, extra] = p.positional;
|
|
313
378
|
if (tool === undefined || extra !== undefined)
|
|
314
379
|
throw new Usage(`Usage: flovia ${COMMANDS["call"]?.usage}`);
|
|
380
|
+
let raw = input;
|
|
381
|
+
if (input === "-") {
|
|
382
|
+
try {
|
|
383
|
+
raw = await io.readStdin();
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
throw new Usage("call: cannot read JSON from stdin");
|
|
387
|
+
}
|
|
388
|
+
}
|
|
315
389
|
let args = {};
|
|
316
390
|
if (raw !== undefined)
|
|
317
391
|
try {
|
|
@@ -323,7 +397,16 @@ export async function run(argv, io) {
|
|
|
323
397
|
if (args === null || typeof args !== "object" || Array.isArray(args))
|
|
324
398
|
throw new Usage("call: the arguments must be a JSON object");
|
|
325
399
|
const client = await connect();
|
|
326
|
-
|
|
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
|
+
}
|
|
327
410
|
return 0;
|
|
328
411
|
}
|
|
329
412
|
case "generate": {
|
|
@@ -378,17 +461,24 @@ export async function run(argv, io) {
|
|
|
378
461
|
catch (e) {
|
|
379
462
|
if (e instanceof Usage) {
|
|
380
463
|
err(`${e.message}\n`);
|
|
464
|
+
if (json)
|
|
465
|
+
print({ ok: false, code: "usage", meaning: e.message });
|
|
381
466
|
return 2;
|
|
382
467
|
}
|
|
383
468
|
if (e instanceof FloviaError) {
|
|
384
|
-
|
|
385
|
-
|
|
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 } : {}) });
|
|
386
473
|
err(renderError(e));
|
|
387
474
|
if (p.command === "generate" && e.operationId && e.executed === "unknown")
|
|
388
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`);
|
|
389
476
|
return e.code === "invalid_base_url" ? 2 : 1;
|
|
390
477
|
}
|
|
391
|
-
|
|
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 });
|
|
392
482
|
return 1;
|
|
393
483
|
}
|
|
394
484
|
}
|
package/package.json
CHANGED