@flovialabs/sdk 0.1.5 → 0.1.6
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 +14 -0
- package/README.md +18 -13
- package/dist/cli.js +45 -37
- package/dist/client.js +3 -3
- package/dist/types.d.ts +2 -2
- package/dist/types.js +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.1.6
|
|
6
|
+
|
|
7
|
+
- Interactive `status`, `usage`, `tools` and `call` show elapsed waiting time on stderr, as `generate` already does. JSON output stays quiet.
|
|
8
|
+
- CLI and README use the same two terms for paying: "free allowance" and "purchased balance".
|
|
9
|
+
- Clearer recovery advice after a lost generation reply: rerun with the same `--op`, prompt and options; a new id can charge again. The id line no longer tells you to resend when the next step says not to.
|
|
10
|
+
- A rejected key shows one Console link and one next step. Timeouts are shown in seconds. A network error or timeout without an operation id now says to check usage before sending again.
|
|
11
|
+
- Shorter help; exit code 1 is described as "an error from Flovia".
|
|
12
|
+
- CLI argument mistakes (a missing tool, `--op` or a bad option value) show the usage line before the key is read, so they no longer show "No key".
|
|
13
|
+
- `status` labels its windows "free 5-hour" and "free week" and lines up its values in one column. `usage` says "1 lookup".
|
|
14
|
+
- `PUBLIC_CODES` includes `approval_pending`.
|
|
15
|
+
- README: shorter key setup, current docs links, the generation codes `generation_pending` and `generation_unknown`, and the 0.1.5 `npx` example.
|
|
16
|
+
|
|
3
17
|
## 0.1.5
|
|
4
18
|
|
|
5
19
|
- Keep `formal_registration_required` and a direct registration recovery step on HTTP 401; preserve the operation id and never retry authentication failures.
|
package/README.md
CHANGED
|
@@ -10,20 +10,25 @@ 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.6
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Your key
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Set
|
|
18
|
+
1. Open the link in your invitation email and register.
|
|
19
|
+
2. In [Flovia Console](https://console.flovia.dev/groupbuy/), create an API key. Console shows it once; save it somewhere private.
|
|
20
|
+
3. Set the key (`flv_...`) in the environment, then check it:
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
23
|
export FLOVIA_KEY=flv_...
|
|
24
|
+
npx flovia status
|
|
24
25
|
```
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
`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
|
+
|
|
29
|
+
Keys from the test period no longer work. The [Quickstart](https://flovia.dev/docs/quickstart) has the full steps, and [Free and paid use](https://flovia.dev/docs/usage) explains the limits. If the invitation is missing or you lose your key, [contact Flovia](https://flovia.dev/contact). Installing this package does not create an account or start a free allowance.
|
|
30
|
+
|
|
31
|
+
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.
|
|
27
32
|
|
|
28
33
|
`baseUrl` requires HTTPS. Plain HTTP is allowed only for loopback development (`localhost`, `127.0.0.1`, `[::1]`). Raw transport diagnostics are not attached to errors because they may contain request headers.
|
|
29
34
|
|
|
@@ -34,7 +39,7 @@ import { FloviaClient, newOperationId } from "@flovialabs/sdk";
|
|
|
34
39
|
|
|
35
40
|
const flovia = new FloviaClient(); // reads FLOVIA_KEY; base URL https://api.flovia.dev
|
|
36
41
|
|
|
37
|
-
// Your free windows, services and the contract version
|
|
42
|
+
// Your free allowance windows, services and the contract version
|
|
38
43
|
const status = await flovia.status();
|
|
39
44
|
console.log(status.five_hour.used_pct, status.week.used_pct);
|
|
40
45
|
|
|
@@ -45,7 +50,7 @@ const usage = await flovia.usageToday(); // today, UTC
|
|
|
45
50
|
const tools = await flovia.listTools();
|
|
46
51
|
const reply = await flovia.call("flovia_status");
|
|
47
52
|
|
|
48
|
-
// A text generation (uses your
|
|
53
|
+
// A text generation (uses your free allowance first, then your purchased balance). Save the operation id before sending.
|
|
49
54
|
const op = newOperationId();
|
|
50
55
|
const request = { model: "gpt-6-luna" as const, input: "Explain a DEX aggregator in one sentence.", reasoning: { effort: "low" as const } };
|
|
51
56
|
// Persist { op, request } in your application's private storage before the next line.
|
|
@@ -66,7 +71,7 @@ const priceRequest = {
|
|
|
66
71
|
request_text: "What is Bitcoin's USD price?", purpose: "check a price with its update time",
|
|
67
72
|
conversation_id: "sdk-price-example", operation_id: newOperationId(),
|
|
68
73
|
};
|
|
69
|
-
// Save priceRequest before sending; this lookup uses
|
|
74
|
+
// Save priceRequest before sending; this lookup uses your free allowance or purchased balance.
|
|
70
75
|
const price = await flovia.call("flovia_coingecko", priceRequest);
|
|
71
76
|
```
|
|
72
77
|
|
|
@@ -141,7 +146,7 @@ try {
|
|
|
141
146
|
After installing this SDK and setting `FLOVIA_KEY` privately, run:
|
|
142
147
|
|
|
143
148
|
```sh
|
|
144
|
-
# One new CoinGecko lookup; uses
|
|
149
|
+
# One new CoinGecko lookup; uses your free allowance or purchased balance.
|
|
145
150
|
node first-price.mjs --new
|
|
146
151
|
# Same request and operation id; reopen promptly, while the saved answer is available.
|
|
147
152
|
node first-price.mjs --replay
|
|
@@ -161,7 +166,7 @@ For Luna, set `reasoning.effort` to `none`, `low`, `medium`, `high`, `xhigh` or
|
|
|
161
166
|
|
|
162
167
|
`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.
|
|
163
168
|
|
|
164
|
-
If the reply is lost (timeout, network error, `executed: "unknown"`), keep the request and **same** id. A completed or incomplete answer can normally be reopened for about **15 minutes** with the unchanged request, `replayed: true` and no additional charge. Follow `nextStep` for `
|
|
169
|
+
If the reply is lost (timeout, network error, `executed: "unknown"`), keep the request and **same** id. A completed or incomplete answer can normally be reopened for about **15 minutes** with the unchanged request, `replayed: true` and no additional charge. Follow `nextStep` for `generation_pending` or `generation_unknown`; the answer may not be available yet. After `answer_expired` or `operation_retired`, Flovia cannot return the saved text. Never start a new id to recover a lost answer: that may run and charge twice. A genuinely new generation requires the person's decision to spend again.
|
|
165
170
|
|
|
166
171
|
## Errors
|
|
167
172
|
|
|
@@ -223,7 +228,7 @@ npx flovia generate --op sdk-example-0001 --max-output 1000 --reasoning-effort l
|
|
|
223
228
|
npx flovia help
|
|
224
229
|
npx flovia --version
|
|
225
230
|
```
|
|
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.
|
|
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.6 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.
|
|
227
232
|
|
|
228
233
|
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.
|
|
229
234
|
|
|
@@ -237,10 +242,10 @@ flovia generate --op <saved-id> --max-output 1000 --reasoning-effort high --yes
|
|
|
237
242
|
|
|
238
243
|
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.
|
|
239
244
|
|
|
240
|
-
`status` shows
|
|
245
|
+
`status` shows your purchased balance. `usage` shows lookup counts, free allowance percentages and the purchased-balance totals from the server; 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`.
|
|
241
246
|
|
|
242
247
|
- Every command takes `--json` (the raw reply), `--base-url URL`, `--timeout SECONDS` and `--key-file PATH`.
|
|
243
|
-
- `generate` uses your
|
|
248
|
+
- `generate` uses your free allowance first, then your purchased balance. It needs `--op ID` or `--new-op`, and asks for confirmation on a terminal; add `--yes` in scripts.
|
|
244
249
|
- `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.
|
|
245
250
|
- Exit codes: 0 ok, 1 an error from Flovia, 2 a usage error.
|
|
246
251
|
|
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]\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 } },
|
|
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
20
|
help: { usage: "help [command]", about: "this help", flags: {} },
|
|
21
21
|
version: { usage: "version", about: "the installed CLI version", flags: {} },
|
|
22
22
|
};
|
|
@@ -40,12 +40,11 @@ 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).");
|
|
44
43
|
if (command === "generate")
|
|
45
44
|
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.");
|
|
46
45
|
if (command === "tools" || c === undefined)
|
|
47
46
|
lines.push("", "Inspect tool arguments: flovia tools --json", "Read-only example: flovia call flovia_status '{}'");
|
|
48
|
-
lines.push("", "Default base URL: https://api.flovia.dev.", "Exit codes: 0 ok, 1
|
|
47
|
+
lines.push("", "Default base URL: https://api.flovia.dev.", "Exit codes: 0 ok, 1 error from Flovia, 2 usage error.", "");
|
|
49
48
|
return lines.join("\n");
|
|
50
49
|
}
|
|
51
50
|
export function parse(argv) {
|
|
@@ -142,6 +141,8 @@ export function when(v, now = Date.now()) {
|
|
|
142
141
|
const obj = (v) => v !== null && typeof v === "object" ? v : {};
|
|
143
142
|
/** Wrap prose only, never prompts, answers, consent notices, JSON or copyable commands. */
|
|
144
143
|
const prose = (text) => (text.match(/.{1,76}(?:\s|$)|\S+/g) ?? []).map((line) => line.trim()).join("\n ");
|
|
144
|
+
/** Status labels share one column; the longest is "purchased balance". */
|
|
145
|
+
const label = (name) => name.padEnd(19);
|
|
145
146
|
export function renderStatus(s, expected, now = Date.now()) {
|
|
146
147
|
const lines = ["Connection: OK", `Flovia ${s.stage}, contract ${s.contract_version}`];
|
|
147
148
|
if (expected !== null)
|
|
@@ -159,15 +160,15 @@ export function renderStatus(s, expected, now = Date.now()) {
|
|
|
159
160
|
lines.push("Data consent: accepted. Service and allowance limits still apply.");
|
|
160
161
|
else
|
|
161
162
|
lines.push("Data consent: not reported (see --json).");
|
|
162
|
-
for (const [
|
|
163
|
-
lines.push(`${label
|
|
164
|
-
lines.push(
|
|
163
|
+
for (const [name, w] of [["free 5-hour", s.five_hour], ["free week", s.week]])
|
|
164
|
+
lines.push(`${label(name)}${pct(w?.used_pct)} used${w?.resets_at ? `, resets ${when(w.resets_at, now)}` : name === "free 5-hour" ? ", not started" : ""}`);
|
|
165
|
+
lines.push(`${label("purchased balance")}${String(s["purchased_balance_display"] ?? "-")}`);
|
|
165
166
|
const pending = obj(s["free_pending"]);
|
|
166
167
|
if (pending["next_step"])
|
|
167
|
-
lines.push(`
|
|
168
|
+
lines.push(`free allowance not started: ${String(pending["next_step"])}`);
|
|
168
169
|
const services = Object.entries(obj(s["services"])).map(([name, v]) => { const x = obj(v); return `${name} ${String(x["state"] ?? "?")}${x["until"] ? ` until ${when(x["until"], now)}` : ""}`; });
|
|
169
|
-
lines.push("services
|
|
170
|
-
lines.push(
|
|
170
|
+
lines.push(`${label("services")}(provider state)`, ...services.map((v) => ` ${v}`));
|
|
171
|
+
lines.push(`${label("turned off")}${s.services_off.length ? s.services_off.join(", ") : "none"}`);
|
|
171
172
|
const updates = Array.isArray(s["recent_updates"]) ? s["recent_updates"] : [];
|
|
172
173
|
for (const u of updates.slice(0, 2)) {
|
|
173
174
|
const x = obj(u), first = Array.isArray(x["lines"]) ? String(x["lines"][0] ?? "") : "";
|
|
@@ -180,9 +181,9 @@ export function renderStatus(s, expected, now = Date.now()) {
|
|
|
180
181
|
export function renderUsage(u, today = false, now = Date.now()) {
|
|
181
182
|
const lines = [`since ${when(u["since"], now)} until ${when(u["until"], now)}${today ? " (today, UTC; use --days 7 for the week)" : ""}`];
|
|
182
183
|
const week = obj(u["free_week"]);
|
|
183
|
-
lines.push(`week
|
|
184
|
-
lines.push(`total in this period: ${String(obj(u["total"])["free_display"] ?? "-")} of the weekly
|
|
185
|
-
lines.push(`
|
|
184
|
+
lines.push(`free allowance this week: ${pct(week["used_pct"])} used${week["resets_at"] ? `, resets ${when(week["resets_at"], now)}` : ""}`);
|
|
185
|
+
lines.push(`total in this period: ${String(obj(u["total"])["free_display"] ?? "-")} of the weekly free allowance, ${String(u["count"] ?? 0)} ${u["count"] === 1 ? "lookup" : "lookups"}`);
|
|
186
|
+
lines.push(`purchased balance used: ${String(obj(u["total"])["bought_display"] ?? "-")} total (includes generations)`);
|
|
186
187
|
// Endpoint percentages are rounded (0 can mean <1%); only counts can be summed by source.
|
|
187
188
|
const bySource = new Map();
|
|
188
189
|
for (const e of Array.isArray(u["by_endpoint"]) ? u["by_endpoint"] : []) {
|
|
@@ -192,7 +193,7 @@ export function renderUsage(u, today = false, now = Date.now()) {
|
|
|
192
193
|
if (bySource.size)
|
|
193
194
|
lines.push("", table([["source", "lookups"], ...[...bySource].map(([n, count]) => [n, String(count)])]).trimEnd());
|
|
194
195
|
const g = obj(u["generations"]);
|
|
195
|
-
lines.push("", `generations: ${String(g["operations"] ?? 0)} (completed ${String(g["completed"] ?? 0)}, incomplete ${String(g["incomplete"] ?? 0)}, unknown ${String(g["unknown"] ?? 0)}), ${String(g["free_display"] ?? "-")} of the weekly
|
|
196
|
+
lines.push("", `generations: ${String(g["operations"] ?? 0)} (completed ${String(g["completed"] ?? 0)}, incomplete ${String(g["incomplete"] ?? 0)}, unknown ${String(g["unknown"] ?? 0)}), ${String(g["free_display"] ?? "-")} of the weekly free allowance, purchased ${String(g["bought_display"] ?? "-")} (included in total)`);
|
|
196
197
|
if (u.has_more)
|
|
197
198
|
lines.push("", `more lookups: rerun flovia usage with the same --key-file and --base-url options, adding --since ${String(u["since"])} --cursor ${String(u.next_cursor)}`);
|
|
198
199
|
return lines.join("\n") + "\n";
|
|
@@ -200,15 +201,15 @@ export function renderUsage(u, today = false, now = Date.now()) {
|
|
|
200
201
|
/** A refusal or failure: code, next_step, executed; a handshake's notice or question is shown for the person, never answered here. */
|
|
201
202
|
export function renderError(e) {
|
|
202
203
|
const lines = [`error: ${e.code}: ${e.message}`];
|
|
203
|
-
if (e.code === "unauthorized")
|
|
204
|
-
lines.push(`Check your key in ${CONSOLE}`, "Then: flovia status --key-file <saved-key-file>", "Keep the same --base-url if you selected another relay.");
|
|
205
204
|
if (e.nextStep)
|
|
206
205
|
lines.push(`next_step: ${e.nextStep}`);
|
|
206
|
+
if (e.code === "unauthorized")
|
|
207
|
+
lines.push("After you save a current key, check it: flovia status --key-file <saved-key-file>");
|
|
207
208
|
lines.push(`executed: ${e.executed}`);
|
|
208
209
|
if (e.retryAfterSeconds !== null)
|
|
209
210
|
lines.push(`retry_after_seconds: ${e.retryAfterSeconds}`);
|
|
210
211
|
if (e.operationId)
|
|
211
|
-
lines.push(`operation_id: ${e.operationId}${e.executed === "unknown" ? " (
|
|
212
|
+
lines.push(`operation_id: ${e.operationId}${e.executed === "unknown" ? " (keep this id; never send the request again under a new one)" : ""}`);
|
|
212
213
|
const reply = obj(e.reply);
|
|
213
214
|
if (e.code === "notice_first" || e.code === "data_consent_needed") {
|
|
214
215
|
if (reply["user_notice"])
|
|
@@ -240,7 +241,6 @@ export async function run(argv, io) {
|
|
|
240
241
|
out(`flovia ${VERSION}\n`);
|
|
241
242
|
return 0;
|
|
242
243
|
}
|
|
243
|
-
key = await readKey(p, io);
|
|
244
244
|
}
|
|
245
245
|
catch (e) {
|
|
246
246
|
if (e instanceof Usage) {
|
|
@@ -250,18 +250,31 @@ export async function run(argv, io) {
|
|
|
250
250
|
throw e;
|
|
251
251
|
}
|
|
252
252
|
const json = p.flags.has("--json"), print = (v) => out(JSON.stringify(v, null, 2) + "\n");
|
|
253
|
+
const waitFor = async (request) => {
|
|
254
|
+
const stop = json ? undefined : io.waiting?.();
|
|
255
|
+
try {
|
|
256
|
+
return await request();
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
stop?.();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
253
262
|
let mismatch = null;
|
|
254
263
|
let recoveryLimit;
|
|
255
264
|
let recoveryEffort;
|
|
256
265
|
try {
|
|
257
266
|
const timeout = positiveInt("--timeout", str(p.flags.get("--timeout")));
|
|
258
267
|
const baseUrl = str(p.flags.get("--base-url"));
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
268
|
+
// The key is read only after the command's own arguments are checked, so a usage mistake shows the usage line first.
|
|
269
|
+
const connect = async () => {
|
|
270
|
+
key = await readKey(p, io);
|
|
271
|
+
return new FloviaClient({ apiKey: key, ...(baseUrl !== undefined ? { baseUrl } : {}), ...(timeout ? { timeoutMs: timeout * 1000 } : {}),
|
|
272
|
+
...(accessToken ? { accessToken } : {}),
|
|
273
|
+
...(io.fetch ? { fetch: io.fetch } : {}), onContractMismatch: (expected) => { mismatch = expected; } });
|
|
274
|
+
};
|
|
262
275
|
switch (p.command) {
|
|
263
276
|
case "status": {
|
|
264
|
-
const s = await client.status();
|
|
277
|
+
const client = await connect(), s = await waitFor(() => client.status());
|
|
265
278
|
if (json)
|
|
266
279
|
print(s);
|
|
267
280
|
else
|
|
@@ -280,7 +293,7 @@ export async function run(argv, io) {
|
|
|
280
293
|
throw new Usage("--since must be an ISO 8601 time");
|
|
281
294
|
// A minute's margin so --days 7 stays inside the relay's 7 days by the time it arrives.
|
|
282
295
|
const from = days === undefined ? since : new Date((io.now ?? Date.now)() - days * 86_400_000 + 60_000).toISOString();
|
|
283
|
-
const u = await client.usageToday({ ...(from ? { since: from } : {}), ...(cursor ? { cursor } : {}) });
|
|
296
|
+
const client = await connect(), u = await waitFor(() => client.usageToday({ ...(from ? { since: from } : {}), ...(cursor ? { cursor } : {}) }));
|
|
284
297
|
if (json)
|
|
285
298
|
print(u);
|
|
286
299
|
else
|
|
@@ -288,7 +301,7 @@ export async function run(argv, io) {
|
|
|
288
301
|
return 0;
|
|
289
302
|
}
|
|
290
303
|
case "tools": {
|
|
291
|
-
const tools = await client.listTools();
|
|
304
|
+
const client = await connect(), tools = await waitFor(() => client.listTools());
|
|
292
305
|
if (json)
|
|
293
306
|
print(tools);
|
|
294
307
|
else
|
|
@@ -309,7 +322,8 @@ export async function run(argv, io) {
|
|
|
309
322
|
}
|
|
310
323
|
if (args === null || typeof args !== "object" || Array.isArray(args))
|
|
311
324
|
throw new Usage("call: the arguments must be a JSON object");
|
|
312
|
-
|
|
325
|
+
const client = await connect();
|
|
326
|
+
print(await waitFor(() => client.call(tool, args)));
|
|
313
327
|
return 0;
|
|
314
328
|
}
|
|
315
329
|
case "generate": {
|
|
@@ -319,18 +333,19 @@ export async function run(argv, io) {
|
|
|
319
333
|
const [text, extra] = p.positional;
|
|
320
334
|
if (text === undefined || extra !== undefined)
|
|
321
335
|
throw new Usage(`Usage: flovia ${COMMANDS["generate"]?.usage}`);
|
|
336
|
+
const max = positiveInt("--max-output", str(p.flags.get("--max-output")));
|
|
337
|
+
const effort = reasoningEffort(str(p.flags.get("--reasoning-effort")));
|
|
338
|
+
const client = await connect();
|
|
322
339
|
const input = text === "-" ? await io.readStdin() : text;
|
|
323
340
|
if (input.trim() === "")
|
|
324
341
|
throw new Usage("generate: the prompt is empty");
|
|
325
|
-
const max = positiveInt("--max-output", str(p.flags.get("--max-output")));
|
|
326
|
-
const effort = reasoningEffort(str(p.flags.get("--reasoning-effort")));
|
|
327
342
|
recoveryLimit = max;
|
|
328
343
|
recoveryEffort = effort;
|
|
329
344
|
const id = op ?? newOperationId();
|
|
330
345
|
// The id is shown before anything is sent, so a lost reply can be reopened with it (never resent under a new one).
|
|
331
346
|
if (fresh)
|
|
332
347
|
err(`operation_id: ${id}\nSave it. To resend or reopen this request, use: --op ${id}\n`);
|
|
333
|
-
err("This generation uses
|
|
348
|
+
err("This generation uses your free allowance first, then your purchased balance.\nIf the reply is lost, rerun with the same --op, prompt, output limit and effort.\nA saved answer comes back free for about 15 minutes. Never use a new id to recover an answer.\n");
|
|
334
349
|
if (!p.flags.has("--yes")) {
|
|
335
350
|
if (io.confirm === null || text === "-")
|
|
336
351
|
throw new Usage("generate: add --yes to send (no terminal to confirm on)");
|
|
@@ -339,14 +354,7 @@ export async function run(argv, io) {
|
|
|
339
354
|
return 2;
|
|
340
355
|
}
|
|
341
356
|
}
|
|
342
|
-
const
|
|
343
|
-
let g;
|
|
344
|
-
try {
|
|
345
|
-
g = await client.generate({ model: "gpt-6-luna", input, ...(max ? { max_output_tokens: max } : {}), ...(effort ? { reasoning: { effort } } : {}) }, { operationId: id });
|
|
346
|
-
}
|
|
347
|
-
finally {
|
|
348
|
-
stopWaiting?.();
|
|
349
|
-
}
|
|
357
|
+
const g = await waitFor(() => client.generate({ model: "gpt-6-luna", input, ...(max ? { max_output_tokens: max } : {}), ...(effort ? { reasoning: { effort } } : {}) }, { operationId: id }));
|
|
350
358
|
const reason = obj(g.response["incomplete_details"])["reason"];
|
|
351
359
|
if (json)
|
|
352
360
|
print(g);
|
|
@@ -377,7 +385,7 @@ export async function run(argv, io) {
|
|
|
377
385
|
print(e.reply);
|
|
378
386
|
err(renderError(e));
|
|
379
387
|
if (p.command === "generate" && e.operationId && e.executed === "unknown")
|
|
380
|
-
err(`
|
|
388
|
+
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`);
|
|
381
389
|
return e.code === "invalid_base_url" ? 2 : 1;
|
|
382
390
|
}
|
|
383
391
|
err(`error: ${e instanceof Error ? e.message : String(e)}\n`);
|
|
@@ -416,7 +424,7 @@ if (isMain) {
|
|
|
416
424
|
confirm: tty ? confirm : null,
|
|
417
425
|
...(process.stderr.isTTY ? { waiting: () => {
|
|
418
426
|
const start = Date.now();
|
|
419
|
-
process.stderr.write("Waiting for Flovia
|
|
427
|
+
process.stderr.write("Waiting for Flovia.\n");
|
|
420
428
|
const timer = setInterval(() => process.stderr.write(`Waiting for Flovia (${Math.floor((Date.now() - start) / 1000)}s elapsed).\n`), 5000);
|
|
421
429
|
timer.unref();
|
|
422
430
|
return () => clearInterval(timer);
|
package/dist/client.js
CHANGED
|
@@ -89,8 +89,8 @@ export class FloviaClient {
|
|
|
89
89
|
const timeout = cause instanceof Error && cause.name === "TimeoutError";
|
|
90
90
|
// Transport diagnostics may contain request headers, so never attach their raw cause.
|
|
91
91
|
throw this.#error({ code: timeout ? "timeout" : "network_error", executed: "unknown", operationId,
|
|
92
|
-
message: timeout ? `No reply within ${this.#timeoutMs}
|
|
93
|
-
nextStep: operationId ? SAME_OPERATION :
|
|
92
|
+
message: timeout ? `No reply within ${this.#timeoutMs / 1000} seconds.` : "The request did not complete.",
|
|
93
|
+
nextStep: operationId ? SAME_OPERATION : "The request may have reached Flovia. Check your usage before you send it again." });
|
|
94
94
|
}
|
|
95
95
|
if (r.status === 401) {
|
|
96
96
|
// Recognize only the public auth code; never attach an arbitrary proxy body, diagnostic or reflected credential.
|
|
@@ -99,7 +99,7 @@ export class FloviaClient {
|
|
|
99
99
|
throw this.#error({ code: formal ? "formal_registration_required" : "unauthorized", status: 401, executed: "no", operationId,
|
|
100
100
|
message: formal ? "Test access has ended. API keys issued during the test no longer work." : "The Flovia key was not accepted.",
|
|
101
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
|
|
102
|
+
: "Open https://console.flovia.dev/groupbuy/ to check your account and get a current key. Do not resend with the same key." });
|
|
103
103
|
}
|
|
104
104
|
return r;
|
|
105
105
|
}
|
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.134";
|
|
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", "
|
|
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"];
|
|
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,11 +1,11 @@
|
|
|
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.134";
|
|
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
|
-
"key_disabled", "key_stopped", "consent_missing", "data_consent_mismatch", "data_consent_needed", "notice_first",
|
|
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", "
|
|
8
|
+
"over_max_credits", "window_5h", "window_week", "over_week", "free_limited", "free_needs_email", "global_cap",
|
|
9
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",
|
package/package.json
CHANGED