@flovialabs/sdk 0.1.10 → 0.1.12
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 +25 -0
- package/README.md +10 -6
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +39 -26
- package/dist/client.js +10 -3
- package/dist/types.d.ts +2 -2
- package/dist/types.js +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.12
|
|
6
|
+
|
|
7
|
+
- Expect contract `2026-10-07.146`: Flovia can look up public X posts (recent search and counts, one post and its quote posts, an account's recent posts); the tool is closed unless Flovia offers it.
|
|
8
|
+
|
|
9
|
+
- Expect contract `2026-10-07.145`: reopened Nansen trade quotes replace transaction data with SHA-256 fingerprints. Fresh replies are unchanged; preparation uses only an owned, encrypted short-lived quote copy when enabled.
|
|
10
|
+
|
|
11
|
+
- Expect contract `2026-10-07.144`: the Base unsigned-preparation tool takes an owned quote reference and index, with separately billed chain checks; it is available only when Flovia offers it. `cannot_summarize` returns nothing to sign; Flovia does not charge for the preparation. Flovia never signs or sends.
|
|
12
|
+
|
|
13
|
+
- Contract `2026-10-07.143` adds nine read-only Nansen GET endpoints for swap quotes, bridge status, perp account data and token sectors.
|
|
14
|
+
|
|
15
|
+
- `FloviaCode` and `PUBLIC_CODES` include the relay's Firecrawl codes `page_tls_invalid` and `page_unreachable`.
|
|
16
|
+
|
|
17
|
+
- Expect contract `2026-10-07.138`: Exa accepts optional `text_max_characters` (1–12,000) for page text in the existing search. Missing text and possible truncation are marked; all results share the existing reply budget. Default excerpts, search count and charges are unchanged.
|
|
18
|
+
|
|
19
|
+
- Expect contract `2026-10-07.137`: Exa supports optional publication-date bounds and category filters; default search and charges are unchanged.
|
|
20
|
+
|
|
21
|
+
- The CLI reads the key from `~/.config/flovia/key` when neither `--key-file` nor `FLOVIA_KEY` is given.
|
|
22
|
+
|
|
23
|
+
- Expect relay contract `2026-10-07.136`: `flovia_feedback` accepts optional `type` and `area` fields for user feedback and agent-observed reports. Existing calls without these fields still work.
|
|
24
|
+
|
|
25
|
+
## 0.1.11
|
|
26
|
+
|
|
27
|
+
- SDK request-construction failures use `invalid_request` with `executed: no` before any request is sent; raw exception causes are not exposed.
|
|
28
|
+
- CLI stdin rejects malformed UTF-8 before sending, and key-file errors no longer expose the local file path.
|
|
29
|
+
|
|
5
30
|
## 0.1.10
|
|
6
31
|
|
|
7
32
|
- `flovia tools` keeps a short second sentence of each description, so what a tool is for stays visible.
|
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@ 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.12
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Your key
|
|
17
17
|
|
|
18
|
-
1.
|
|
19
|
-
2. In [Flovia Console](https://console.flovia.dev/groupbuy/),
|
|
18
|
+
1. Register at https://console.flovia.dev/auth/register with email verification and a Passkey.
|
|
19
|
+
2. In [Flovia Console](https://console.flovia.dev/groupbuy/), press Create API key. Console shows it once; save it somewhere private.
|
|
20
20
|
3. Set the key (`flv_...`) in the environment, then check it:
|
|
21
21
|
|
|
22
22
|
```sh
|
|
@@ -24,9 +24,13 @@ export FLOVIA_KEY=flv_...
|
|
|
24
24
|
npx flovia status
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
Without `FLOVIA_KEY` or `--key-file`, the CLI reads `~/.config/flovia/key`, the file Console's Claude Code setup saves.
|
|
28
|
+
|
|
29
|
+
Claude Code pluginの既定の保存先は別ファイル `~/.config/flovia/relay-key` です。Consoleでキーを更新したら、CLIのキーファイル(または `FLOVIA_KEY`)とpluginの両方を更新し、pluginはClaude Codeで `/flovia:setup` を再実行してください(基点 `28e5cbeee1d7bca5c68c18d765e576445e452997`、2026-10-25確認)。
|
|
30
|
+
|
|
27
31
|
`status` shows how much of your free allowance you have used, and your purchased balance. A $0 purchased balance is fine while free allowance remains.
|
|
28
32
|
|
|
29
|
-
Keys from the test period no longer work. The [Quickstart](https://flovia.dev/
|
|
33
|
+
Keys from the test period no longer work. The [Quickstart](https://docs.flovia.dev/get-started/quickstart/) has the full steps, and [Free and paid use](https://docs.flovia.dev/usage/) explains the limits. If you lose your key or think it leaked, regenerate it on the API Key tab in [Flovia Console](https://console.flovia.dev/groupbuy/); the old key stops working at once. Installing this package does not create an account or start a free allowance.
|
|
30
34
|
|
|
31
35
|
In code, the client reads `FLOVIA_KEY`, or you can pass it as `new FloviaClient({ apiKey })`. The client keeps the key private: it does not appear in logs, error messages or `console.log(client)`. The SDK sends no telemetry.
|
|
32
36
|
|
|
@@ -183,7 +187,7 @@ A refusal (`ok: false`) or a failed request throws `FloviaError`:
|
|
|
183
187
|
| `operationId` | the operation id of the request |
|
|
184
188
|
| `reply` | the full reply body |
|
|
185
189
|
|
|
186
|
-
HTTP 401 with `code: "formal_registration_required"` means test access ended:
|
|
190
|
+
HTTP 401 with `code: "formal_registration_required"` means test access ended: register at https://console.flovia.dev/auth/register with email verification and a Passkey (or use the link in your invitation email if you have one); if you have already registered, sign in to Console, press Create API key, then reconnect with the new key. A generic `unauthorized` means the key was not accepted; check your account and current key in Console. Both are unsent (`executed: "no"`) and are never retried automatically. The SDK does not expose arbitrary authentication response bodies.
|
|
187
191
|
|
|
188
192
|
### `notice_first` and `data_consent_needed`: a human must answer
|
|
189
193
|
|
|
@@ -230,7 +234,7 @@ npx flovia agents-md # a short note for CLAUDE.md or AGENTS.md
|
|
|
230
234
|
npx flovia help
|
|
231
235
|
npx flovia --version
|
|
232
236
|
```
|
|
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.
|
|
237
|
+
These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.12 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.
|
|
234
238
|
|
|
235
239
|
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.
|
|
236
240
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -32,5 +32,5 @@ export declare function renderUsage(u: UsageTodayReply, today?: boolean, now?: n
|
|
|
32
32
|
/** A refusal or failure: code, next_step, executed; a handshake's notice or question is shown for the person, never answered here. */
|
|
33
33
|
export declare function renderError(e: FloviaError): string;
|
|
34
34
|
export declare function run(argv: string[], io: Io): Promise<number>;
|
|
35
|
-
/** Decode UTF-8
|
|
35
|
+
/** Decode UTF-8 once over all bytes (a character split between reads survives); invalid bytes throw instead of becoming U+FFFD. */
|
|
36
36
|
export declare function readStdin(input: NodeJS.ReadableStream): Promise<string>;
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* flovia: a small CLI over the SDK's public client, for people to check their status and usage and try calls with their own key.
|
|
4
|
-
* The key comes from FLOVIA_KEY
|
|
4
|
+
* The key comes from FLOVIA_KEY, --key-file or ~/.config/flovia/key only (never argv, which ps shows), and is never printed. Exit 2: usage error; 1: a relay error.
|
|
5
5
|
*/
|
|
6
6
|
import { readFile, stat } from "node:fs/promises";
|
|
7
7
|
import { readFileSync, realpathSync } from "node:fs";
|
|
@@ -84,7 +84,7 @@ export function help(command) {
|
|
|
84
84
|
const c = command === undefined || !Object.hasOwn(COMMANDS, command) ? undefined : COMMANDS[command];
|
|
85
85
|
const lines = c === undefined ? ["Usage: flovia <command> [options]", "",
|
|
86
86
|
...Object.values(COMMANDS).flatMap((x) => [` ${x.usage}`, ` ${x.about}`])] : [`Usage: flovia ${c.usage}`, ` ${c.about}`];
|
|
87
|
-
lines.push("", "Options: " + GLOBAL, "", `Get or manage your key: ${CONSOLE}`, "Save the key privately, then: flovia status --key-file <saved-key-file>", "Or set FLOVIA_KEY. Never paste the key into a command argument.");
|
|
87
|
+
lines.push("", "Options: " + GLOBAL, "", `Get or manage your key: ${CONSOLE}`, "Save the key privately, then: flovia status --key-file <saved-key-file>", "Or set FLOVIA_KEY, or save it to ~/.config/flovia/key.", "Never paste the key into a command argument.");
|
|
88
88
|
if (command === "generate")
|
|
89
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.");
|
|
90
90
|
if (command === "tools" || c === undefined)
|
|
@@ -148,28 +148,35 @@ function reasoningEffort(v) {
|
|
|
148
148
|
return v;
|
|
149
149
|
throw new Usage("--reasoning-effort must be one of: none, low, medium, high, xhigh, max");
|
|
150
150
|
}
|
|
151
|
-
/** The key from --key-file (
|
|
151
|
+
/** The key from --key-file, FLOVIA_KEY, or the file Console's setup saves (~/.config/flovia/key), in that order, trimmed. Its text never goes into a message. */
|
|
152
152
|
async function readKey(p, io) {
|
|
153
153
|
const file = str(p.flags.get("--key-file"));
|
|
154
|
-
if (file !== undefined)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
catch {
|
|
160
|
-
throw new Usage(`--key-file: cannot read ${file}`);
|
|
161
|
-
}
|
|
162
|
-
const key = text.trim();
|
|
163
|
-
if (key === "")
|
|
164
|
-
throw new Usage(`--key-file: ${file} is empty`);
|
|
165
|
-
const mode = await io.fileMode?.(file).catch(() => null);
|
|
166
|
-
if (typeof mode === "number" && (mode & 0o077) !== 0)
|
|
167
|
-
io.err(`warning: ${file} is readable by other users (mode ${(mode & 0o777).toString(8)}); run: chmod 600 ${file}\n`);
|
|
154
|
+
if (file !== undefined)
|
|
155
|
+
return fromFile(file, io, "--key-file");
|
|
156
|
+
const key = io.env["FLOVIA_KEY"]?.trim();
|
|
157
|
+
if (key)
|
|
168
158
|
return key;
|
|
159
|
+
const home = io.env["HOME"];
|
|
160
|
+
if (home && await io.readFile(`${home}/${DEFAULT_KEY_FILE}`).then(() => true, () => false))
|
|
161
|
+
return fromFile(`${home}/${DEFAULT_KEY_FILE}`, io, `~/${DEFAULT_KEY_FILE}`);
|
|
162
|
+
throw new Usage(`No key: set FLOVIA_KEY, pass --key-file PATH, or save it to ~/${DEFAULT_KEY_FILE}. Never paste a key as an argument.\nGet or manage your key: ${CONSOLE}\nThen: flovia status --key-file <saved-key-file>`);
|
|
163
|
+
}
|
|
164
|
+
const DEFAULT_KEY_FILE = ".config/flovia/key";
|
|
165
|
+
async function fromFile(file, io, label) {
|
|
166
|
+
let text;
|
|
167
|
+
// Never echo a user-given path: a key pasted in its place would land in the output.
|
|
168
|
+
try {
|
|
169
|
+
text = await io.readFile(file);
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
catch {
|
|
172
|
+
throw new Usage(`${label}: cannot read the key file`);
|
|
173
|
+
}
|
|
174
|
+
const key = text.trim();
|
|
175
|
+
if (key === "")
|
|
176
|
+
throw new Usage(`${label}: the key file is empty`);
|
|
177
|
+
const mode = await io.fileMode?.(file).catch(() => null);
|
|
178
|
+
if (typeof mode === "number" && (mode & 0o077) !== 0)
|
|
179
|
+
io.err(`warning: the key file is readable by other users (mode ${(mode & 0o777).toString(8)}); run chmod 600 on it\n`);
|
|
173
180
|
return key;
|
|
174
181
|
}
|
|
175
182
|
const pct = (v) => typeof v === "number" ? `${v}%` : "-";
|
|
@@ -419,7 +426,14 @@ export async function run(argv, io) {
|
|
|
419
426
|
const max = positiveInt("--max-output", str(p.flags.get("--max-output")));
|
|
420
427
|
const effort = reasoningEffort(str(p.flags.get("--reasoning-effort")));
|
|
421
428
|
const client = await connect();
|
|
422
|
-
|
|
429
|
+
let input = text;
|
|
430
|
+
if (text === "-")
|
|
431
|
+
try {
|
|
432
|
+
input = await io.readStdin();
|
|
433
|
+
}
|
|
434
|
+
catch {
|
|
435
|
+
throw new Usage("generate: cannot read the prompt from stdin (it must be UTF-8 text)");
|
|
436
|
+
}
|
|
423
437
|
if (input.trim() === "")
|
|
424
438
|
throw new Usage("generate: the prompt is empty");
|
|
425
439
|
recoveryLimit = max;
|
|
@@ -482,13 +496,12 @@ export async function run(argv, io) {
|
|
|
482
496
|
return 1;
|
|
483
497
|
}
|
|
484
498
|
}
|
|
485
|
-
/** Decode UTF-8
|
|
499
|
+
/** Decode UTF-8 once over all bytes (a character split between reads survives); invalid bytes throw instead of becoming U+FFFD. */
|
|
486
500
|
export async function readStdin(input) {
|
|
487
|
-
|
|
488
|
-
let text = "";
|
|
501
|
+
const chunks = [];
|
|
489
502
|
for await (const chunk of input)
|
|
490
|
-
|
|
491
|
-
return
|
|
503
|
+
chunks.push(Buffer.from(chunk));
|
|
504
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks));
|
|
492
505
|
}
|
|
493
506
|
/** Run only as the program (also through npm's bin symlink), not when imported. Node and Bun alike. */
|
|
494
507
|
const isMain = (() => { try {
|
package/dist/client.js
CHANGED
|
@@ -78,12 +78,19 @@ export class FloviaClient {
|
|
|
78
78
|
}
|
|
79
79
|
/** One HTTP request. A network failure or timeout is executed "unknown": the relay may have received it. */
|
|
80
80
|
async #send(path, body, headers = {}, operationId = null) {
|
|
81
|
-
let
|
|
81
|
+
let request;
|
|
82
82
|
try {
|
|
83
|
-
|
|
83
|
+
request = new Request(this.#base + path, { method: "POST", redirect: "error", body: JSON.stringify(body), signal: AbortSignal.timeout(this.#timeoutMs),
|
|
84
84
|
// The family only, so the relay can count SDK calls apart from other clients; never a version or an id.
|
|
85
85
|
headers: { Authorization: `Bearer ${this.#key}`, "Content-Type": "application/json", "X-Flovia-Client": "flovia-sdk", ...headers,
|
|
86
86
|
...(this.#accessToken ? { "Cf-Access-Token": this.#accessToken } : {}) } });
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Built before any send (a multi-line key or header, a body JSON cannot hold): nothing reached Flovia. The cause may hold a header.
|
|
90
|
+
throw this.#error({ code: "invalid_request", executed: "no", operationId, message: "The request could not be built (check the key, ids and body); nothing was sent.", nextStep: null });
|
|
91
|
+
}
|
|
92
|
+
let r;
|
|
93
|
+
try {
|
|
87
94
|
r = await this.#fetch(request);
|
|
88
95
|
}
|
|
89
96
|
catch (cause) {
|
|
@@ -99,7 +106,7 @@ export class FloviaClient {
|
|
|
99
106
|
const formal = auth !== null && typeof auth === "object" && "error" in auth && auth.error === "formal_registration_required";
|
|
100
107
|
throw this.#error({ code: formal ? "formal_registration_required" : "unauthorized", status: 401, executed: "no", operationId,
|
|
101
108
|
message: formal ? "Test access has ended. API keys issued during the test no longer work." : "The Flovia key was not accepted.",
|
|
102
|
-
nextStep: formal ? "
|
|
109
|
+
nextStep: formal ? "Register at https://console.flovia.dev/auth/register with email verification and a Passkey (or use the link in your invitation email if you have one); if you have already registered, sign in at https://console.flovia.dev/auth/, open Console, press Create API key, then reconnect with the new key."
|
|
103
110
|
: "Open https://console.flovia.dev/groupbuy/ to check your account and get a current key. Do not resend with the same key." });
|
|
104
111
|
}
|
|
105
112
|
return r;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** The relay's tool contract this SDK was written against (flovia_status.contract_version). */
|
|
2
|
-
export declare const EXPECTED_CONTRACT_VERSION = "2026-10-07.
|
|
2
|
+
export declare const EXPECTED_CONTRACT_VERSION = "2026-10-07.146";
|
|
3
3
|
/** Every public explanation.code (the relay's contract). A provider's own HTTP error is `http_<status>`. */
|
|
4
|
-
export declare const PUBLIC_CODES: readonly ["approval_pending", "key_disabled", "key_stopped", "consent_missing", "data_consent_mismatch", "data_consent_needed", "notice_first", "endpoint_unknown", "endpoint_disabled", "read_only", "not_relayed", "key_in_query", "secret_in_input", "invalid_body", "body_too_large", "answer_too_large", "answer_precision_unsafe", "answer_not_relayed", "request_text_too_long", "over_max_credits", "window_5h", "window_week", "over_week", "free_limited", "free_needs_email", "global_cap", "flovia_paused", "rate_limited", "too_many_in_parallel", "reservation_changed", "operation_conflict", "operation_pending", "upstream_unknown", "upstream_unavailable", "replay_response_unavailable", "rpc_error", "unknown_lookup", "invalid_cursor", "since_too_old", "since_in_future", "feedback_too_long", "feedback_limit", "not_configured", "service_off"];
|
|
4
|
+
export declare const PUBLIC_CODES: readonly ["approval_pending", "key_disabled", "key_stopped", "consent_missing", "data_consent_mismatch", "data_consent_needed", "notice_first", "endpoint_unknown", "endpoint_disabled", "read_only", "not_relayed", "key_in_query", "secret_in_input", "invalid_body", "body_too_large", "answer_too_large", "answer_precision_unsafe", "answer_not_relayed", "request_text_too_long", "over_max_credits", "window_5h", "window_week", "over_week", "free_limited", "free_needs_email", "free_not_granted", "global_cap", "flovia_paused", "rate_limited", "too_many_in_parallel", "reservation_changed", "operation_conflict", "operation_pending", "upstream_unknown", "cannot_summarize", "upstream_unavailable", "page_tls_invalid", "page_unreachable", "replay_response_unavailable", "rpc_error", "unknown_lookup", "invalid_cursor", "since_too_old", "since_in_future", "feedback_too_long", "feedback_limit", "not_configured", "service_off"];
|
|
5
5
|
export type FloviaCode = (typeof PUBLIC_CODES)[number] | `http_${number}`;
|
|
6
6
|
/** Whether the request ran upstream: "unknown" means keep the same operation_id and never send a replacement. */
|
|
7
7
|
export type Executed = "yes" | "no" | "unknown";
|
package/dist/types.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** The relay's tool contract this SDK was written against (flovia_status.contract_version). */
|
|
2
|
-
export const EXPECTED_CONTRACT_VERSION = "2026-10-07.
|
|
2
|
+
export const EXPECTED_CONTRACT_VERSION = "2026-10-07.146";
|
|
3
3
|
/** Every public explanation.code (the relay's contract). A provider's own HTTP error is `http_<status>`. */
|
|
4
4
|
export const PUBLIC_CODES = [
|
|
5
5
|
"approval_pending", "key_disabled", "key_stopped", "consent_missing", "data_consent_mismatch", "data_consent_needed", "notice_first",
|
|
6
6
|
"endpoint_unknown", "endpoint_disabled", "read_only", "not_relayed", "key_in_query", "secret_in_input", "invalid_body", "body_too_large",
|
|
7
7
|
"answer_too_large", "answer_precision_unsafe", "answer_not_relayed", "request_text_too_long",
|
|
8
|
-
"over_max_credits", "window_5h", "window_week", "over_week", "free_limited", "free_needs_email", "global_cap",
|
|
8
|
+
"over_max_credits", "window_5h", "window_week", "over_week", "free_limited", "free_needs_email", "free_not_granted", "global_cap",
|
|
9
9
|
"flovia_paused", "rate_limited", "too_many_in_parallel", "reservation_changed",
|
|
10
|
-
"operation_conflict", "operation_pending", "upstream_unknown", "upstream_unavailable", "replay_response_unavailable", "rpc_error",
|
|
10
|
+
"operation_conflict", "operation_pending", "upstream_unknown", "cannot_summarize", "upstream_unavailable", "page_tls_invalid", "page_unreachable", "replay_response_unavailable", "rpc_error",
|
|
11
11
|
"unknown_lookup", "invalid_cursor", "since_too_old", "since_in_future", "feedback_too_long", "feedback_limit", "not_configured", "service_off",
|
|
12
12
|
];
|
package/package.json
CHANGED