@flovialabs/sdk 0.1.3 → 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/CHANGELOG.md +10 -0
- package/README.md +97 -10
- package/dist/cli.js +20 -6
- package/dist/client.d.ts +2 -0
- package/dist/client.js +22 -6
- package/dist/types.d.ts +6 -4
- package/dist/types.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.5
|
|
4
|
+
|
|
5
|
+
- Keep `formal_registration_required` and a direct registration recovery step on HTTP 401; preserve the operation id and never retry authentication failures.
|
|
6
|
+
- Include a complete one-price Node example with private request persistence, same-operation replay and an explicitly saved, offline display.
|
|
7
|
+
|
|
8
|
+
## 0.1.4
|
|
9
|
+
|
|
10
|
+
- Luna generation accepts `reasoning.effort` values `none`, `low`, `medium`, `high`, `xhigh` and `max`. The default remains `none`.
|
|
11
|
+
- CLI `generate --reasoning-effort LEVEL` selects the effort. Lost-reply recovery keeps that option unchanged along with the operation id, input and output limit; it never retries automatically.
|
|
12
|
+
|
|
3
13
|
## 0.1.3
|
|
4
14
|
|
|
5
15
|
- Redact the configured API key when it is echoed in SDK errors, recovery metadata, diagnostic reply fields or contract warnings.
|
package/README.md
CHANGED
|
@@ -10,12 +10,12 @@ 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.5
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Your key
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Complete formal registration from your invitation email, then open the [Flovia Console](https://console.flovia.dev) to connect your app or receive a key. Test-era keys no longer work after the formal-registration cutover. Keep the key private; it is shown once. Before integrating, check account access, included allowance and purchased balance separately: a $0 purchased balance does not mean you need to buy credits if included use remains. Follow the [Quickstart](https://flovia.dev/docs/quickstart) to connect your agent and verify your email. [Free use and bought credits](https://flovia.dev/docs/usage) explains the limits. Contact [Flovia support](https://flovia.dev/contact) if the invitation is missing or you lose your key. Installing this package does not create an account or start an allowance.
|
|
19
19
|
|
|
20
20
|
Set your Flovia key (`flv_...`) in the environment:
|
|
21
21
|
|
|
@@ -45,9 +45,9 @@ const usage = await flovia.usageToday(); // today, UTC
|
|
|
45
45
|
const tools = await flovia.listTools();
|
|
46
46
|
const reply = await flovia.call("flovia_status");
|
|
47
47
|
|
|
48
|
-
// A text generation (uses credits). Save the operation id before sending.
|
|
48
|
+
// A text generation (uses your Flovia allowance, then bought credits). Save the operation id before sending.
|
|
49
49
|
const op = newOperationId();
|
|
50
|
-
const request = { model: "gpt-6-luna" as const, input: "Explain a DEX aggregator in one sentence." };
|
|
50
|
+
const request = { model: "gpt-6-luna" as const, input: "Explain a DEX aggregator in one sentence.", reasoning: { effort: "low" as const } };
|
|
51
51
|
// Persist { op, request } in your application's private storage before the next line.
|
|
52
52
|
const g = await flovia.generate(request, { operationId: op });
|
|
53
53
|
console.log(g.response.status, g.response.incomplete_details, g.outputText);
|
|
@@ -72,6 +72,91 @@ const price = await flovia.call("flovia_coingecko", priceRequest);
|
|
|
72
72
|
|
|
73
73
|
If either call asks for a notice or consent, stop and follow the human-answer flow below. Read the returned source time, coverage and missing-value notes; a successful lookup is not a guarantee that it answers your question. Flovia exposes selected read-only paths, methods and public HTML hosts, not every feature of the upstream plans. Use the live catalog for the supported subset. OpenAI supports text generation with `gpt-6-luna`; it does not fetch other providers or offer image/audio generation.
|
|
74
74
|
|
|
75
|
+
### Run one result, display it, then reopen it
|
|
76
|
+
|
|
77
|
+
Save this complete example as `first-price.mjs` beside your `node_modules`. Keep it server-side or on your own machine.
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
// Run on your own machine. Never bundle this file, FLOVIA_KEY or private usage into a browser app.
|
|
81
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
82
|
+
import { pathToFileURL } from "node:url";
|
|
83
|
+
import { FloviaClient, FloviaError, newOperationId } from "@flovialabs/sdk";
|
|
84
|
+
|
|
85
|
+
const mode = process.argv[2];
|
|
86
|
+
if (!["--new", "--replay", "--saved"].includes(mode)) {
|
|
87
|
+
console.error("Use --new once, --replay with the saved request, or --saved (no network).");
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
const directory = new URL("./.flovia-price/", pathToFileURL(process.cwd() + "/"));
|
|
91
|
+
const requestFile = new URL("request.json", directory);
|
|
92
|
+
const answerFile = new URL("answer.json", directory);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
let reply;
|
|
96
|
+
if (mode === "--saved") {
|
|
97
|
+
reply = JSON.parse(await readFile(answerFile, "utf8"));
|
|
98
|
+
} else {
|
|
99
|
+
const client = new FloviaClient();
|
|
100
|
+
if (mode === "--new") {
|
|
101
|
+
await mkdir(directory, { mode: 0o700 });
|
|
102
|
+
const request = {
|
|
103
|
+
path: "/simple/price",
|
|
104
|
+
query: { ids: "bitcoin", vs_currencies: "usd", include_last_updated_at: true },
|
|
105
|
+
request_text: "What is Bitcoin's USD price?",
|
|
106
|
+
purpose: "display one price with its source update time",
|
|
107
|
+
conversation_id: "sdk-first-price",
|
|
108
|
+
operation_id: newOperationId(),
|
|
109
|
+
};
|
|
110
|
+
// Exclusive creation: rerunning --new cannot silently replace the operation that might have run.
|
|
111
|
+
await writeFile(requestFile, JSON.stringify(request), { mode: 0o600, flag: "wx" });
|
|
112
|
+
await client.status(); // Account/allowance read only; stop on authentication errors.
|
|
113
|
+
}
|
|
114
|
+
const request = JSON.parse(await readFile(requestFile, "utf8"));
|
|
115
|
+
reply = await client.call("flovia_coingecko", request);
|
|
116
|
+
await writeFile(answerFile, JSON.stringify(reply), { mode: 0o600 });
|
|
117
|
+
}
|
|
118
|
+
const price = JSON.parse(reply.response).bitcoin;
|
|
119
|
+
const updated = price?.last_updated_at;
|
|
120
|
+
console.log(JSON.stringify({
|
|
121
|
+
display: mode === "--saved" ? "Saved locally; not a live update" : reply.stored_answer ? "Earlier answer; not a live update" : "Fetched once; not auto-updating",
|
|
122
|
+
btc_usd: price?.usd ?? null,
|
|
123
|
+
provider_updated_at: Number.isFinite(updated) ? new Date(updated * 1000).toISOString() : null,
|
|
124
|
+
flovia_received_at: reply.created_at ?? null,
|
|
125
|
+
lookup_id: reply.lookup_id ?? null,
|
|
126
|
+
charge_guidance: mode === "--saved" ? "Nothing: this display is offline; see the original lookup in private usage"
|
|
127
|
+
: reply.for_user?.charged_to_you ?? "Unavailable; do not assume zero",
|
|
128
|
+
attribution: "Data provided by CoinGecko",
|
|
129
|
+
}, null, 2));
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (error instanceof FloviaError) {
|
|
132
|
+
console.error(JSON.stringify({ code: error.code, executed: error.executed, operation_id: error.operationId, next_step: error.nextStep }));
|
|
133
|
+
} else {
|
|
134
|
+
console.error("Could not read, save or display the example. Keep .flovia-price unchanged; do not start a new operation to recover it.");
|
|
135
|
+
}
|
|
136
|
+
// No automatic resend, consent answer or replacement operation, including on pending/unknown or an expired saved answer.
|
|
137
|
+
process.exitCode = 1;
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
After installing this SDK and setting `FLOVIA_KEY` privately, run:
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
# One new CoinGecko lookup; uses the included allowance or purchased credits.
|
|
145
|
+
node first-price.mjs --new
|
|
146
|
+
# Same request and operation id; reopen promptly, while the saved answer is available.
|
|
147
|
+
node first-price.mjs --replay
|
|
148
|
+
# Display the local answer without any API request.
|
|
149
|
+
node first-price.mjs --saved
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The example saves the request and operation id **before** sending, in `.flovia-price/request.json` (0600 inside a 0700 directory), and the returned answer in `answer.json` (0600). Keep this directory private and out of Git. Repeating `--new` refuses to overwrite it. Do not delete it or change the id to recover a lost answer. `--replay` sends the saved arguments unchanged; if the saved text is unavailable or the outcome is pending/unknown, follow the error's `next_step` instead of making a new request. A notice or consent refusal needs the person's answer; this script never supplies one.
|
|
153
|
+
|
|
154
|
+
The displayed result separates the USD price, CoinGecko's update time, Flovia's original receipt time, lookup id and the server's charge guidance. Unknown values stay `null`; missing cost is not zero. A replay or local saved display is labelled as such and never presented as a live update. For period usage, run `npx flovia usage` separately; it is your private account data, not the cost of this one result. A browser demo may display the public price and attribution from your server, but must not expose the Flovia key, private reply files or account usage, or offer an unauthenticated refresh endpoint that spends your allowance. The example does not auto-refresh. Follow the provider's attribution and redistribution terms.
|
|
155
|
+
|
|
156
|
+
### Thinking effort
|
|
157
|
+
|
|
158
|
+
For Luna, set `reasoning.effort` to `none`, `low`, `medium`, `high`, `xhigh` or `max`; omitting it keeps Flovia's `none` default. Higher effort can take longer and use more reasoning tokens. Those tokens share `max_output_tokens` with the visible answer, so an answer may be shorter or `incomplete`. The default output limit remains 1,000, with an explicit maximum of 4,000. Effort does not raise Flovia's per-request spending cap or guarantee a better answer. Save the effort with the rest of the request; changing it under the same operation id is a different request and is refused.
|
|
159
|
+
|
|
75
160
|
### Operation ids and replay
|
|
76
161
|
|
|
77
162
|
`generate()` requires an operation id (8-128 characters of `A-Z a-z 0-9 _ . : -`). Create one with `newOperationId()` and store it with the request **before** sending.
|
|
@@ -93,6 +178,8 @@ A refusal (`ok: false`) or a failed request throws `FloviaError`:
|
|
|
93
178
|
| `operationId` | the operation id of the request |
|
|
94
179
|
| `reply` | the full reply body |
|
|
95
180
|
|
|
181
|
+
HTTP 401 with `code: "formal_registration_required"` means test access ended: complete formal registration from the invitation email, then reconnect through Console. 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.
|
|
182
|
+
|
|
96
183
|
### `notice_first` and `data_consent_needed`: a human must answer
|
|
97
184
|
|
|
98
185
|
These two codes are thrown on purpose. They need the person's own answer, and the SDK never answers for them.
|
|
@@ -130,22 +217,22 @@ npx flovia usage --days 3
|
|
|
130
217
|
npx flovia tools
|
|
131
218
|
npx flovia tools --json # includes each tool's inputSchema
|
|
132
219
|
npx flovia call flovia_usage_today '{}'
|
|
133
|
-
npx flovia generate --op sdk-example-0001 --max-output
|
|
220
|
+
npx flovia generate --op sdk-example-0001 --max-output 1000 --reasoning-effort low "Explain a DEX aggregator."
|
|
134
221
|
# Only to reopen that exact request within about 15 minutes (not a new generation):
|
|
135
|
-
npx flovia generate --op sdk-example-0001 --max-output
|
|
222
|
+
npx flovia generate --op sdk-example-0001 --max-output 1000 --reasoning-effort low --yes "Explain a DEX aggregator."
|
|
136
223
|
npx flovia help
|
|
137
224
|
npx flovia --version
|
|
138
225
|
```
|
|
139
|
-
These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.
|
|
226
|
+
These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.4 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.
|
|
140
227
|
|
|
141
228
|
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.
|
|
142
229
|
|
|
143
230
|
For multiline text, keep the original input in a private file:
|
|
144
231
|
|
|
145
232
|
```sh
|
|
146
|
-
flovia generate --new-op --max-output
|
|
233
|
+
flovia generate --new-op --max-output 1000 --reasoning-effort high --yes - < prompt.txt
|
|
147
234
|
# To recover this request, use its printed id, the SAME file and options:
|
|
148
|
-
flovia generate --op <saved-id> --max-output
|
|
235
|
+
flovia generate --op <saved-id> --max-output 1000 --reasoning-effort high --yes - < prompt.txt
|
|
149
236
|
```
|
|
150
237
|
|
|
151
238
|
Keep the same `--key-file` and `--base-url` too. For a prompt starting with a hyphen, use `--` before the prompt. Long answers can take minutes; an interactive terminal shows elapsed time on stderr. Piped and JSON output stays unchanged. A timeout does not prove that nothing ran: never recover by repeating `--new-op`. Partial answers are delivered and settled, but the CLI never generates a continuation automatically. The HTTP reply does not include exact Flovia cost; use `flovia usage` for period totals, which are not the price of this one answer. A replay adds no charge.
|
|
@@ -153,7 +240,7 @@ Keep the same `--key-file` and `--base-url` too. For a prompt starting with a hy
|
|
|
153
240
|
`status` shows bought balance. `usage` shows lookup counts, free percentages and server-provided bought totals; its generation subtotal is already included in the period total. Missing amounts show `-`, not zero. It does not add rounded endpoint percentages. To continue a listing, copy the printed command with its exact `--since` and `--cursor`; do not combine `--days` with `--cursor`.
|
|
154
241
|
|
|
155
242
|
- Every command takes `--json` (the raw reply), `--base-url URL`, `--timeout SECONDS` and `--key-file PATH`.
|
|
156
|
-
- `generate` uses credits. It needs `--op ID` or `--new-op`, and asks for confirmation on a terminal; add `--yes` in scripts.
|
|
243
|
+
- `generate` uses your Flovia allowance (free windows first, then bought credits). It needs `--op ID` or `--new-op`, and asks for confirmation on a terminal; add `--yes` in scripts.
|
|
157
244
|
- `generate` prints the response status and incomplete reason. `incomplete` / `max_output_tokens` means the delivered text stopped at the output limit, not that a continuation ran. Exit 0 means the response was delivered, not that the text is complete or correct. `--json` retains the full public response.
|
|
158
245
|
- Exit codes: 0 ok, 1 an error from Flovia, 2 a usage error.
|
|
159
246
|
|
package/dist/cli.js
CHANGED
|
@@ -16,7 +16,7 @@ const COMMANDS = {
|
|
|
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
17
|
tools: { usage: "tools", about: "the tools this key is offered", flags: {} },
|
|
18
18
|
call: { usage: "call <tool> ['<json args>']", about: "call any tool and print its reply", flags: {} },
|
|
19
|
-
generate: { usage: "generate (--op ID | --new-op) [--max-output N] [--yes] <prompt | ->", about: "a text generation (uses
|
|
19
|
+
generate: { usage: "generate (--op ID | --new-op) [--max-output N]\n [--reasoning-effort LEVEL] [--yes] <prompt | ->", about: "a text generation (uses your allowance)", flags: { "--op": true, "--new-op": false, "--max-output": true, "--reasoning-effort": true, "--yes": false } },
|
|
20
20
|
help: { usage: "help [command]", about: "this help", flags: {} },
|
|
21
21
|
version: { usage: "version", about: "the installed CLI version", flags: {} },
|
|
22
22
|
};
|
|
@@ -40,8 +40,9 @@ export function help(command) {
|
|
|
40
40
|
const lines = c === undefined ? ["Usage: flovia <command> [options]", "",
|
|
41
41
|
...Object.values(COMMANDS).flatMap((x) => [` ${x.usage}`, ` ${x.about}`])] : [`Usage: flovia ${c.usage}`, ` ${c.about}`];
|
|
42
42
|
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.");
|
|
43
|
+
lines.push("For private dev: --base-url https://dev.api.flovia.dev", "and FLOVIA_ACCESS_TOKEN (Cloudflare Access JWT).");
|
|
43
44
|
if (command === "generate")
|
|
44
|
-
lines.push("", "Default output limit: 1000 tokens; maximum: 4000.", "Long answers can take minutes. Save the id, same input
|
|
45
|
+
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
46
|
if (command === "tools" || c === undefined)
|
|
46
47
|
lines.push("", "Inspect tool arguments: flovia tools --json", "Read-only example: flovia call flovia_status '{}'");
|
|
47
48
|
lines.push("", "Default base URL: https://api.flovia.dev.", "Exit codes: 0 ok, 1 relay error, 2 usage error.", "");
|
|
@@ -96,6 +97,11 @@ function positiveInt(name, v, max = Number.MAX_SAFE_INTEGER) {
|
|
|
96
97
|
throw new Usage(`${name} must be a whole number from 1 to ${max}`);
|
|
97
98
|
return n;
|
|
98
99
|
}
|
|
100
|
+
function reasoningEffort(v) {
|
|
101
|
+
if (v === undefined || v === "none" || v === "low" || v === "medium" || v === "high" || v === "xhigh" || v === "max")
|
|
102
|
+
return v;
|
|
103
|
+
throw new Usage("--reasoning-effort must be one of: none, low, medium, high, xhigh, max");
|
|
104
|
+
}
|
|
99
105
|
/** The key from --key-file (trimmed) or FLOVIA_KEY. Its text never goes into a message. */
|
|
100
106
|
async function readKey(p, io) {
|
|
101
107
|
const file = str(p.flags.get("--key-file"));
|
|
@@ -217,7 +223,11 @@ export function renderError(e) {
|
|
|
217
223
|
export async function run(argv, io) {
|
|
218
224
|
let key = null;
|
|
219
225
|
// Belt and braces: whatever is printed passes through here, so the key cannot appear even if a reply or error echoed it.
|
|
220
|
-
const
|
|
226
|
+
const accessToken = io.env["FLOVIA_ACCESS_TOKEN"]?.trim();
|
|
227
|
+
const scrub = (s) => {
|
|
228
|
+
const masked = key === null ? s : s.replaceAll(key, "[key]");
|
|
229
|
+
return accessToken ? masked.replaceAll(accessToken, "[access-token]") : masked;
|
|
230
|
+
};
|
|
221
231
|
const out = (s) => io.out(scrub(s)), err = (s) => io.err(scrub(s));
|
|
222
232
|
let p;
|
|
223
233
|
try {
|
|
@@ -242,10 +252,12 @@ export async function run(argv, io) {
|
|
|
242
252
|
const json = p.flags.has("--json"), print = (v) => out(JSON.stringify(v, null, 2) + "\n");
|
|
243
253
|
let mismatch = null;
|
|
244
254
|
let recoveryLimit;
|
|
255
|
+
let recoveryEffort;
|
|
245
256
|
try {
|
|
246
257
|
const timeout = positiveInt("--timeout", str(p.flags.get("--timeout")));
|
|
247
258
|
const baseUrl = str(p.flags.get("--base-url"));
|
|
248
259
|
const client = new FloviaClient({ apiKey: key, ...(baseUrl !== undefined ? { baseUrl } : {}), ...(timeout ? { timeoutMs: timeout * 1000 } : {}),
|
|
260
|
+
...(accessToken ? { accessToken } : {}),
|
|
249
261
|
...(io.fetch ? { fetch: io.fetch } : {}), onContractMismatch: (expected) => { mismatch = expected; } });
|
|
250
262
|
switch (p.command) {
|
|
251
263
|
case "status": {
|
|
@@ -311,12 +323,14 @@ export async function run(argv, io) {
|
|
|
311
323
|
if (input.trim() === "")
|
|
312
324
|
throw new Usage("generate: the prompt is empty");
|
|
313
325
|
const max = positiveInt("--max-output", str(p.flags.get("--max-output")));
|
|
326
|
+
const effort = reasoningEffort(str(p.flags.get("--reasoning-effort")));
|
|
314
327
|
recoveryLimit = max;
|
|
328
|
+
recoveryEffort = effort;
|
|
315
329
|
const id = op ?? newOperationId();
|
|
316
330
|
// The id is shown before anything is sent, so a lost reply can be reopened with it (never resent under a new one).
|
|
317
331
|
if (fresh)
|
|
318
332
|
err(`operation_id: ${id}\nSave it. To resend or reopen this request, use: --op ${id}\n`);
|
|
319
|
-
err("This generation uses Flovia credits (usage allowance first, then bought credits).\nSame --op, same input
|
|
333
|
+
err("This generation uses Flovia credits (usage allowance first, then bought credits).\nSame --op, same input, output limit and effort: saved answers are free for about 15 minutes.\nPending, unknown or expired answers: never replace them with a new id.\n");
|
|
320
334
|
if (!p.flags.has("--yes")) {
|
|
321
335
|
if (io.confirm === null || text === "-")
|
|
322
336
|
throw new Usage("generate: add --yes to send (no terminal to confirm on)");
|
|
@@ -328,7 +342,7 @@ export async function run(argv, io) {
|
|
|
328
342
|
const stopWaiting = json ? undefined : io.waiting?.();
|
|
329
343
|
let g;
|
|
330
344
|
try {
|
|
331
|
-
g = await client.generate({ model: "gpt-6-luna", input, ...(max ? { max_output_tokens: max } : {}) }, { operationId: id });
|
|
345
|
+
g = await client.generate({ model: "gpt-6-luna", input, ...(max ? { max_output_tokens: max } : {}), ...(effort ? { reasoning: { effort } } : {}) }, { operationId: id });
|
|
332
346
|
}
|
|
333
347
|
finally {
|
|
334
348
|
stopWaiting?.();
|
|
@@ -363,7 +377,7 @@ export async function run(argv, io) {
|
|
|
363
377
|
print(e.reply);
|
|
364
378
|
err(renderError(e));
|
|
365
379
|
if (p.command === "generate" && e.operationId && e.executed === "unknown")
|
|
366
|
-
err(`Recovery: keep the same input
|
|
380
|
+
err(`Recovery: keep the same input, ${recoveryLimit === undefined ? "omit --max-output as before" : `--max-output ${recoveryLimit}`} and ${recoveryEffort === undefined ? "omit --reasoning-effort as before" : `--reasoning-effort ${recoveryEffort}`} with --op ${e.operationId}.\nUse the original prompt file and the same --key-file / --base-url.\nDo not rerun --new-op or create a different request to recover this answer.\n`);
|
|
367
381
|
return e.code === "invalid_base_url" ? 2 : 1;
|
|
368
382
|
}
|
|
369
383
|
err(`error: ${e instanceof Error ? e.message : String(e)}\n`);
|
package/dist/client.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export interface FloviaClientOptions {
|
|
|
4
4
|
apiKey?: string;
|
|
5
5
|
/** Defaults to https://api.flovia.dev. */
|
|
6
6
|
baseUrl?: string;
|
|
7
|
+
/** Cloudflare Access JWT for the private dev relay. Never sent to other origins. */
|
|
8
|
+
accessToken?: string;
|
|
7
9
|
/** Per request, in milliseconds. Defaults to 300 s: a long generation takes minutes. */
|
|
8
10
|
timeoutMs?: number;
|
|
9
11
|
fetch?: (request: Request) => Promise<Response>;
|
package/dist/client.js
CHANGED
|
@@ -33,6 +33,7 @@ async function readReply(r, operationId, makeError, sse = false) {
|
|
|
33
33
|
export class FloviaClient {
|
|
34
34
|
#key;
|
|
35
35
|
#base;
|
|
36
|
+
#accessToken;
|
|
36
37
|
#timeoutMs;
|
|
37
38
|
#fetch;
|
|
38
39
|
#resend;
|
|
@@ -56,6 +57,9 @@ export class FloviaClient {
|
|
|
56
57
|
if (url.protocol !== "https:" && !(url.protocol === "http:" && local))
|
|
57
58
|
throw new FloviaError({ code: "invalid_base_url", executed: "no", message: "baseUrl / --base-url must be https (plain http only for localhost, 127.0.0.1 or [::1])." });
|
|
58
59
|
this.#base = base.replace(/\/+$/, "");
|
|
60
|
+
if (options.accessToken && (url.origin !== "https://dev.api.flovia.dev" || url.username || url.password))
|
|
61
|
+
throw new FloviaError({ code: "invalid_base_url", executed: "no", message: "accessToken requires https://dev.api.flovia.dev." });
|
|
62
|
+
this.#accessToken = options.accessToken;
|
|
59
63
|
this.#timeoutMs = options.timeoutMs ?? 300_000;
|
|
60
64
|
this.#fetch = options.fetch ?? ((r) => fetch(r));
|
|
61
65
|
this.#resend = options.retryRateLimited ?? false;
|
|
@@ -64,7 +68,10 @@ export class FloviaClient {
|
|
|
64
68
|
}
|
|
65
69
|
/** Mask only this client's exact key in diagnostic strings and reply field names; keep Error field names intact. */
|
|
66
70
|
#error(init) {
|
|
67
|
-
const scrub = (text) =>
|
|
71
|
+
const scrub = (text) => {
|
|
72
|
+
const masked = text.replaceAll(this.#key, "[key]");
|
|
73
|
+
return this.#accessToken ? masked.replaceAll(this.#accessToken, "[access-token]") : masked;
|
|
74
|
+
};
|
|
68
75
|
const safe = JSON.parse(JSON.stringify(init, (_name, value) => typeof value === "string" ? scrub(value) : value !== init && value !== null && typeof value === "object" && !Array.isArray(value)
|
|
69
76
|
? Object.fromEntries(Object.entries(value).map(([name, field]) => [scrub(name), field])) : value));
|
|
70
77
|
return new FloviaError(safe);
|
|
@@ -73,8 +80,9 @@ export class FloviaClient {
|
|
|
73
80
|
async #send(path, body, headers = {}, operationId = null) {
|
|
74
81
|
let r;
|
|
75
82
|
try {
|
|
76
|
-
const request = new Request(this.#base + path, { method: "POST", body: JSON.stringify(body), signal: AbortSignal.timeout(this.#timeoutMs),
|
|
77
|
-
headers: { Authorization: `Bearer ${this.#key}`, "Content-Type": "application/json", ...headers
|
|
83
|
+
const request = new Request(this.#base + path, { method: "POST", redirect: "error", body: JSON.stringify(body), signal: AbortSignal.timeout(this.#timeoutMs),
|
|
84
|
+
headers: { Authorization: `Bearer ${this.#key}`, "Content-Type": "application/json", ...headers,
|
|
85
|
+
...(this.#accessToken ? { "Cf-Access-Token": this.#accessToken } : {}) } });
|
|
78
86
|
r = await this.#fetch(request);
|
|
79
87
|
}
|
|
80
88
|
catch (cause) {
|
|
@@ -84,8 +92,15 @@ export class FloviaClient {
|
|
|
84
92
|
message: timeout ? `No reply within ${this.#timeoutMs} ms.` : "The request did not complete.",
|
|
85
93
|
nextStep: operationId ? SAME_OPERATION : null });
|
|
86
94
|
}
|
|
87
|
-
if (r.status === 401)
|
|
88
|
-
|
|
95
|
+
if (r.status === 401) {
|
|
96
|
+
// Recognize only the public auth code; never attach an arbitrary proxy body, diagnostic or reflected credential.
|
|
97
|
+
const auth = await r.json().catch(() => null);
|
|
98
|
+
const formal = auth !== null && typeof auth === "object" && "error" in auth && auth.error === "formal_registration_required";
|
|
99
|
+
throw this.#error({ code: formal ? "formal_registration_required" : "unauthorized", status: 401, executed: "no", operationId,
|
|
100
|
+
message: formal ? "Test access has ended. API keys issued during the test no longer work." : "The Flovia key was not accepted.",
|
|
101
|
+
nextStep: formal ? "Complete formal registration from your invitation email, then open https://console.flovia.dev/auth/ to connect your app again."
|
|
102
|
+
: "Open https://console.flovia.dev to check account access and use a current key. Do not resend with an invalid key." });
|
|
103
|
+
}
|
|
89
104
|
return r;
|
|
90
105
|
}
|
|
91
106
|
async #rpc(method, params, operationId = null) {
|
|
@@ -140,7 +155,8 @@ export class FloviaClient {
|
|
|
140
155
|
const s = await this.call("flovia_status");
|
|
141
156
|
if (!this.#warned && s.contract_version !== EXPECTED_CONTRACT_VERSION) {
|
|
142
157
|
this.#warned = true;
|
|
143
|
-
|
|
158
|
+
const version = String(s.contract_version).replaceAll(this.#key, "[key]");
|
|
159
|
+
this.#onMismatch(EXPECTED_CONTRACT_VERSION, this.#accessToken ? version.replaceAll(this.#accessToken, "[access-token]") : version);
|
|
144
160
|
}
|
|
145
161
|
return s;
|
|
146
162
|
}
|
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.131";
|
|
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 ["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", "cost_confirmation_needed", "window_5h", "window_week", "over_week", "free_limited", "free_needs_email", "global_cap", "flovia_paused", "
|
|
4
|
+
export declare const PUBLIC_CODES: readonly ["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", "cost_confirmation_needed", "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"];
|
|
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";
|
|
@@ -26,7 +26,9 @@ export interface Window {
|
|
|
26
26
|
used_pct: number;
|
|
27
27
|
resets_at: string | null;
|
|
28
28
|
}
|
|
29
|
-
export type StatusArgs =
|
|
29
|
+
export type StatusArgs = {
|
|
30
|
+
about_sharing?: true;
|
|
31
|
+
};
|
|
30
32
|
export interface StatusReply extends ToolReply {
|
|
31
33
|
contract_version: string;
|
|
32
34
|
stage: string;
|
|
@@ -54,7 +56,7 @@ export interface GenerationRequest {
|
|
|
54
56
|
input: string;
|
|
55
57
|
max_output_tokens?: number;
|
|
56
58
|
reasoning?: {
|
|
57
|
-
effort: "none" | "low";
|
|
59
|
+
effort: "none" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
58
60
|
};
|
|
59
61
|
stream?: false;
|
|
60
62
|
store?: false;
|
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.131";
|
|
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
|
"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
8
|
"over_max_credits", "cost_confirmation_needed", "window_5h", "window_week", "over_week", "free_limited", "free_needs_email", "global_cap",
|
|
9
|
-
"flovia_paused", "
|
|
9
|
+
"flovia_paused", "rate_limited", "too_many_in_parallel", "reservation_changed",
|
|
10
10
|
"operation_conflict", "operation_pending", "upstream_unknown", "upstream_unavailable", "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