@flovialabs/sdk 0.1.15 → 0.1.17
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 +27 -5
- package/README.md +26 -38
- package/dist/cli.d.ts +3 -1
- package/dist/cli.js +95 -6
- package/dist/client.d.ts +18 -3
- package/dist/client.js +90 -2
- package/dist/types.d.ts +27 -2
- package/dist/types.js +4 -4
- package/package.json +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.1.17
|
|
4
|
+
|
|
5
|
+
- Introduce the consent API and CLI described below; these are not in the published 0.1.16 package. Expect contract `2026-10-07.172`. When the current notice is `relay-consent-19`, `flovia consent` describes notice 19's December 3/new-record retrieval rules. Earlier yes answers keep working; a new answer is not required to keep looking up.
|
|
6
|
+
- `flovia consent` reads the current notice version, your last yes, whether it is to an earlier version (`updated`), and the full notice text. `flovia consent accept <version> --yes` records the account owner's own yes to exactly that version, as in Console; without `--yes` nothing is sent. In code: `client.consent()` and `client.acceptConsent(version)`. An agent must never answer for the person.
|
|
7
|
+
- Notice 18-eligible Nansen answers and generated text/audio can be reopened only by their owner for up to 30 days from creation. Eligibility starts with accepted use from 2026-12-01, or records after an earlier explicit yes to notice 18 or matching registration Terms. Retrieval availability follows the Relay rollout and the notice on each original record. Earlier records keep their original periods; reopening does not renew the deadline or restore a missing or expired copy. Runway's eligible media retrieval period remains up to 30 days.
|
|
8
|
+
- Other lookup replies and fal.ai URL copies get up to 30 days only for new notice 19 records, from 2026-12-03 or after a fresh explicit yes to notice 19. Old notice 18 and earlier lookup copies keep about 15 minutes; later agreement never extends them. These copies are owner-only retrieval data, not fresh results or a shared cache.
|
|
9
|
+
- A saved fal.ai URL still expires at the provider after about an hour. Saving its URL for longer does not extend or restore the image.
|
|
10
|
+
|
|
11
|
+
## 0.1.16
|
|
12
|
+
|
|
13
|
+
- Expect contract `2026-10-07.167`: `call("flovia_runway", { action: "list" })` previews maximum reservations for an image or 2–5-second video, as allowance shares and USD if purchased balance pays. Listing never generates or reserves; the final charge can differ.
|
|
14
|
+
- Expect contract `2026-10-07.166`: free month window and expiring plan credit, combined with API key provider restrictions.
|
|
15
|
+
- Expect contract `2026-10-07.163`: `flovia_firecrawl` scrape takes an optional `country` (one of 26 ISO 3166-1 alpha-2 codes listed by `action: "list"`). Query strings are still refused.
|
|
16
|
+
|
|
17
|
+
- Expect contract `2026-10-07.162`: `flovia_x` adds read-only actions (`search_all`, `count_all`, `replies`, `posts`, `users`, `users_by_usernames`, `user_mentions`, `followers`, `following`, `reposted_by`, `list_lookup`, `list_posts`, `trends`); `action: "list"` shows each one's arguments.
|
|
18
|
+
- X is currently withdrawn from Flovia's public tools. SDK types do not enable it or guarantee its availability.
|
|
19
|
+
- `flovia status` prints one line when you have a saved reset (from `flovia_status`'s `banked_resets`), pointing to `flovia resets`. Nothing is shown when you have none or the relay does not report it; it never uses one.
|
|
20
|
+
|
|
21
|
+
- Breaking: contract `2026-10-07.161` requires `operation_id` on every `flovia_x` action, including `list`. X accepts usernames with `@`, fractional UTC timestamps or `+00:00`, and clamps times and result counts to its supported range. Keep the same operation ID when recovering a call.
|
|
22
|
+
|
|
23
|
+
- Contract `2026-10-07.160` adds public Firecrawl PDFs up to 10 pages (text, no OCR). Use `pdf: true` for PDF URLs without a `.pdf` path. HTML is unchanged.
|
|
24
|
+
|
|
25
|
+
- Banked resets: `bankedResets()` and `flovia resets` check saved resets and the CLI shows both free windows. `useBankedReset(id)` and `flovia resets use <id> --yes` use one right to restart the 5-hour and weekly free windows. They require the relay's account routes; they never resend automatically. After a lost, unreadable or 401 reply, check first; an unknown result does not mean nothing changed.
|
|
26
|
+
|
|
27
|
+
- Expect contract `2026-10-07.159`; `PUBLIC_CODES` includes `provider_not_allowed` for API key provider restrictions. Credentials are never switched automatically.
|
|
28
|
+
- Expect contract `2026-10-07.158`: use `call("flovia_fal", ...)` for asynchronous fal.ai image jobs; preserve the operation ID for status and recovery.
|
|
4
29
|
|
|
5
30
|
## 0.1.15
|
|
6
31
|
|
|
7
|
-
- Expect contract `2026-10-07.
|
|
32
|
+
- Expect contract `2026-10-07.153`.
|
|
8
33
|
- Runway: use `call("flovia_runway", ...)` for image/video creation and status after the person's separate consent. `downloadRunwayOutput()` and `flovia runway-output <generation_id> --out PATH` download a private output without regenerating; files are created exclusively with mode `0600`.
|
|
9
34
|
- Runway calls never auto-resend, including pre-execution refusals when `retryRateLimited` is enabled. Preserve the original operation ID for recovery; unknown is not proof of failure or zero cost.
|
|
10
35
|
|
|
@@ -21,17 +46,14 @@
|
|
|
21
46
|
## 0.1.12
|
|
22
47
|
|
|
23
48
|
- 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.
|
|
24
|
-
|
|
25
49
|
- 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.
|
|
26
50
|
|
|
27
51
|
- 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.
|
|
28
|
-
|
|
29
52
|
- Contract `2026-10-07.143` adds nine read-only Nansen GET endpoints for swap quotes, bridge status, perp account data and token sectors.
|
|
30
53
|
|
|
31
54
|
- `FloviaCode` and `PUBLIC_CODES` include the relay's Firecrawl codes `page_tls_invalid` and `page_unreachable`.
|
|
32
55
|
|
|
33
56
|
- 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.
|
|
34
|
-
|
|
35
57
|
- Expect contract `2026-10-07.137`: Exa supports optional publication-date bounds and category filters; default search and charges are unchanged.
|
|
36
58
|
|
|
37
59
|
- The CLI reads the key from `~/.config/flovia/key` when neither `--key-file` nor `FLOVIA_KEY` is given.
|
package/README.md
CHANGED
|
@@ -10,13 +10,19 @@ 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.17
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
## 0.1.17 release notes
|
|
17
|
+
|
|
18
|
+
This release introduces `client.consent()`, `client.acceptConsent(version)` and the `flovia consent` commands, which are not in the published 0.1.16 package. It expects contract `2026-10-07.172`. When the current notice is `relay-consent-19`, the CLI shows its December 3/new-record rule. Your earlier yes keeps working, and the CLI never answers for you.
|
|
19
|
+
|
|
20
|
+
Eligible Nansen answers and generated text/audio can be reopened only by their owner for up to 30 days under notice 18, from the original record's creation. Retrieval availability follows the Relay rollout and the notice on each original record. Earlier records keep their original periods. Other lookup replies and fal.ai URL copies get this period only for new notice 19 records, from 2026-12-03 or after your fresh explicit yes to notice 19. Old notice 18 and earlier lookup copies keep about 15 minutes; later agreement never extends them. Reopening does not renew the deadline, fetch fresh data or restore a missing copy. A fal.ai image URL still expires after about an hour; a saved URL does not extend the image's lifetime.
|
|
21
|
+
|
|
16
22
|
## Your key
|
|
17
23
|
|
|
18
24
|
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.
|
|
25
|
+
2. In [Flovia Console](https://console.flovia.dev/groupbuy/), press Create API key. Give it an app name such as CLI or Cursor. Console shows it once; save it somewhere private.
|
|
20
26
|
3. Set the key (`flv_...`) in the environment, then check it:
|
|
21
27
|
|
|
22
28
|
```sh
|
|
@@ -26,11 +32,11 @@ npx flovia status
|
|
|
26
32
|
|
|
27
33
|
Without `FLOVIA_KEY` or `--key-file`, the CLI reads `~/.config/flovia/key`, the file Console's Claude Code setup saves.
|
|
28
34
|
|
|
29
|
-
Claude Code pluginの既定の保存先は別ファイル `~/.config/flovia/relay-key` です。
|
|
35
|
+
Claude Code pluginの既定の保存先は別ファイル `~/.config/flovia/relay-key` です。CLIとpluginには別々のキーを使えます。キーを交換したときは、そのキーを使っていた保存先だけを更新してください。pluginのキーを交換した場合は、Claude Codeで `/flovia:setup` を再実行してください(保存先の基点 `28e5cbeee1d7bca5c68c18d765e576445e452997`、2026-10-25確認)。
|
|
30
36
|
|
|
31
37
|
`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.
|
|
32
38
|
|
|
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.
|
|
39
|
+
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. You can keep up to five active API keys on one account; all share its allowance, balance and limits. If a key is lost or exposed, select Revoke for that key on the API Key tab in [Flovia Console](https://console.flovia.dev/groupbuy/), then Create API key and update the apps that used it. Other keys and OAuth connections keep working. See [Manage API keys](https://docs.flovia.dev/connect/check/#manage-api-keys). Installing this package does not create an account or start a free allowance.
|
|
34
40
|
|
|
35
41
|
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.
|
|
36
42
|
|
|
@@ -81,30 +87,6 @@ const price = await flovia.call("flovia_coingecko", priceRequest);
|
|
|
81
87
|
|
|
82
88
|
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.
|
|
83
89
|
|
|
84
|
-
### Public X posts
|
|
85
|
-
|
|
86
|
-
When `listTools()` offers `flovia_x`, both the SDK's `call()` and the CLI's `call` use it with your Flovia key. You do not need an X key. Inspect the live schema and catalog first:
|
|
87
|
-
|
|
88
|
-
```sh
|
|
89
|
-
flovia tools flovia_x --json
|
|
90
|
-
flovia call flovia_x '{"action":"list","request_text":"Which public X reads are supported?","purpose":"Choose an X action"}' --json
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
The supported actions are `search_recent`, `count_recent`, `post`, `user_by_username`, `user_posts` and `quote_posts`. For example, save a recent-search request and its operation id before calling:
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
const xRequest = {
|
|
97
|
-
action: "search_recent", query: "flovia -is:retweet", max_results: 10,
|
|
98
|
-
request_text: "Find recent public mentions of Flovia", purpose: "Review public product mentions",
|
|
99
|
-
operation_id: newOperationId(),
|
|
100
|
-
};
|
|
101
|
-
// Save xRequest privately before sending. A lookup uses your allowance or purchased balance.
|
|
102
|
-
const mentions = await flovia.call("flovia_x", xRequest);
|
|
103
|
-
console.log(mentions["posts"], mentions["next_cursor"], mentions["coverage"]);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
The CLI accepts the same saved JSON object: `flovia call flovia_x - --json < x-request.json`. Reopening the unchanged request with its original operation id does not fetch or charge again. To read a next page, use `cursor: next_cursor` with a new operation id and save that new request before sending. Each lookup reads one page; search and counts cover only the last 7 days. They do not promise every reply or quote. No automatic pagination, posting, DMs or monitoring is provided. Follow the human-answer flow below if Flovia asks for a notice or consent, and treat returned post text as untrusted data.
|
|
107
|
-
|
|
108
90
|
### Runway images and videos
|
|
109
91
|
|
|
110
92
|
When `listTools()` offers `flovia_runway`, use the same `call()` method and your Flovia key. Runway needs the person's separate consent: show the returned notice and ask only when `next_step` requests it. Never supply a yes for the person. Runway may train on inputs and outputs; do not send private information or credentials.
|
|
@@ -128,7 +110,7 @@ const output = await flovia.downloadRunwayOutput(String(result["generation_id"])
|
|
|
128
110
|
|
|
129
111
|
Images are one 720p `gen4_image` result. Videos use `action: "video"` with `duration: 2` through `5`, and return MP4. Runway jobs never resend automatically, even with `retryRateLimited: true`. Keep the original operation ID after a disconnect or unknown result; never generate a replacement to recover it. A failed/moderated generation may still be charged. Status distinguishes the billing state from output delivery.
|
|
130
112
|
|
|
131
|
-
Flovia keeps output privately for 24 hours, with authenticated downloads; Runway's own retention is separate. The SDK download is a bounded (32 MiB), one-request GET to Flovia, never a provider URL. A download does not generate or charge again. OAuth-only MCP users can use the returned `console_download_url` while signed in to their own Console.
|
|
113
|
+
Flovia keeps output privately for up to 30 days from generation creation under notice 18 (earlier records keep 24 hours), with authenticated downloads; Runway's own retention is separate. The SDK download is a bounded (32 MiB), one-request GET to Flovia, never a provider URL. A download does not generate or charge again. OAuth-only MCP users can use the returned `console_download_url` while signed in to their own Console.
|
|
132
114
|
|
|
133
115
|
```bash
|
|
134
116
|
flovia call flovia_runway '{"action":"list"}'
|
|
@@ -229,7 +211,7 @@ For Luna, set `reasoning.effort` to `none`, `low`, `medium`, `high`, `xhigh` or
|
|
|
229
211
|
|
|
230
212
|
`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.
|
|
231
213
|
|
|
232
|
-
If the reply is lost (timeout, network error, `executed: "unknown"`), keep the request and **same** id. A completed or incomplete answer can
|
|
214
|
+
If the reply is lost (timeout, network error, `executed: "unknown"`), keep the request and **same** id. A completed or incomplete saved answer can be reopened with the unchanged request, `replayed: true` and no additional charge. For generations made under data-use notice 18 (including matching registration Terms), the period is up to 30 days from creation. This covers accepted use from 2026-12-01T00:00Z, or work after your earlier explicit agreement to notice 18. Earlier generations keep about 15 minutes; later agreement does not extend them. A failed save or missing copy can prevent reopening even before expiry. 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. Expired or deleted copies are not restored. Never start a new id to recover a lost answer: that may run and charge twice. A new generation requires the person's decision to spend again. [Data use](https://docs.flovia.dev/data-use/) explains the retrieval periods and their limits.
|
|
233
215
|
|
|
234
216
|
## Errors
|
|
235
217
|
|
|
@@ -248,13 +230,13 @@ A refusal (`ok: false`) or a failed request throws `FloviaError`:
|
|
|
248
230
|
|
|
249
231
|
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.
|
|
250
232
|
|
|
251
|
-
###
|
|
233
|
+
### Notices and consent
|
|
252
234
|
|
|
253
|
-
These two codes
|
|
235
|
+
These two codes stop the call on purpose. Show the notice in full and follow `nextStep`; a separate explicit opt-in may be required. The SDK never consents for the person.
|
|
254
236
|
|
|
255
|
-
1. Show the full `error.reply.user_notice` unchanged.
|
|
256
|
-
2. For `data_consent_needed`, get the person's own answer through your normal flow.
|
|
257
|
-
3. For `data_consent_needed`, repeat the unchanged call only after their `y` is accepted; with `n`, stop. For `notice_first`,
|
|
237
|
+
1. Show the full `error.reply.user_notice` unchanged (`error.reply.notice` for case reports), and `error.reply.consent.question` when present. For `data_consent_needed`, use `consent.line` when there is no question; the short question does not replace the notice.
|
|
238
|
+
2. For `data_consent_needed`, get the person's own answer through your normal flow. Follow `nextStep` for the consent tool: lookup consent uses `flovia_data_consent`; Runway uses `flovia_runway` with `action: "consent"`. Pass `answer` (`"y"` or `"n"` from that answer), `consent_version` from `error.reply.consent.version`, and `user_words` containing their actual words. Do not substitute the current SDK version or a generated answer. Case-report `notice_first` uses its own explicit opt-in and returned `consent_version`, not `flovia_data_consent`.
|
|
239
|
+
3. For `data_consent_needed`, repeat the unchanged call only after their `y` is accepted; with `n`, stop. For `notice_first`, show the notice and follow `nextStep`; add `notice_shown: true` only when requested. Never opt in to a report automatically.
|
|
258
240
|
|
|
259
241
|
Do not answer these automatically from code or from an agent.
|
|
260
242
|
|
|
@@ -287,13 +269,17 @@ npx flovia tools --json # includes each tool's inputSchema
|
|
|
287
269
|
npx flovia tools flovia_coingecko --json # only this tool's description and inputSchema
|
|
288
270
|
npx flovia call flovia_usage_today '{}'
|
|
289
271
|
npx flovia generate --op sdk-example-0001 --max-output 1000 --reasoning-effort low "Explain a DEX aggregator."
|
|
290
|
-
# Only to reopen that exact request
|
|
272
|
+
# Only to reopen that exact request while its saved answer is available:
|
|
291
273
|
npx flovia generate --op sdk-example-0001 --max-output 1000 --reasoning-effort low --yes "Explain a DEX aggregator."
|
|
274
|
+
npx flovia resets # saved resets and both free windows (read-only)
|
|
275
|
+
npx flovia resets use 42 --yes # use saved reset 42 (cannot be undone)
|
|
276
|
+
npx flovia consent # current notice version, your yes and the notice text (read-only)
|
|
277
|
+
npx flovia consent accept relay-consent-19 --yes # your own yes to the version just shown (same as Console)
|
|
292
278
|
npx flovia agents-md # a short note for CLAUDE.md or AGENTS.md
|
|
293
279
|
npx flovia help
|
|
294
280
|
npx flovia --version
|
|
295
281
|
```
|
|
296
|
-
These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.
|
|
282
|
+
These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.17 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.
|
|
297
283
|
|
|
298
284
|
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.
|
|
299
285
|
|
|
@@ -324,6 +310,8 @@ Keep the same `--key-file` and `--base-url` too. For a prompt starting with a hy
|
|
|
324
310
|
- Every command takes `--json` (the raw reply), `--base-url URL`, `--timeout SECONDS` and `--key-file PATH`.
|
|
325
311
|
- `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.
|
|
326
312
|
- `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.
|
|
313
|
+
- `resets` only reads: the number of saved resets, the next to expire, and the 5-hour and weekly windows. `resets use <id> --yes` uses one; both free windows (5-hour and week) start again from 0%. Without `--yes` nothing is sent, even on a terminal. It is never resent automatically: after a lost reply, run `flovia resets` before trying again. `Not used; nothing changed.` exits 1. In code: `client.bankedResets()` and `client.useBankedReset(id)`.
|
|
314
|
+
- `consent` only reads: the current notice version, the version you last said yes to, whether that yes is to an earlier version (it keeps working; continued use accepts the current one), and the full notice. `consent accept <version> --yes` records your own yes to exactly that version, the same as answering in Console; an older version is refused and nothing is recorded, and a repeat changes nothing. Without `--yes` it shows the text and sends nothing (exit 2). Only the account owner should run it, never an agent on their behalf. In code: `client.consent()` and `client.acceptConsent(version)`.
|
|
327
315
|
- Exit codes: 0 ok, 1 an error from Flovia, 2 a usage error.
|
|
328
316
|
|
|
329
317
|
### Safety
|
|
@@ -331,7 +319,7 @@ Keep the same `--key-file` and `--base-url` too. For a prompt starting with a hy
|
|
|
331
319
|
- The key is read only from `FLOVIA_KEY` or a key file, never from a command-line argument (other users can see arguments in `ps`). It is never printed.
|
|
332
320
|
- A key file readable by other users gets a warning; use `chmod 600`.
|
|
333
321
|
- `--base-url` must be `https`, so the key is never sent unencrypted. Plain `http` is allowed only for `localhost`, `127.0.0.1` and `[::1]`.
|
|
334
|
-
-
|
|
322
|
+
- The CLI shows the full notice, `next_step` and any returned `consent.question`, then stops. On `data_consent_needed`, `consent.line` (as Runway returns) supplies the question when `consent.question` is absent. Questions appear under `Your choice:`. Notice text, links and questions stay unchanged; only headings and help text are shortened. The person answers themselves; `--yes` confirms spending, not data consent or report opt-in.
|
|
335
323
|
|
|
336
324
|
## License
|
|
337
325
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { FloviaError, type StatusReply, type UsageTodayReply } from "./index.js";
|
|
2
|
+
import { FloviaError, type BankedResets, type ConsentState, type StatusReply, type UsageTodayReply } from "./index.js";
|
|
3
3
|
/** Exclusive creation: a failed write may leave a private partial file, never overwrite or delete an existing path. */
|
|
4
4
|
export declare function writePrivateOutput(path: string, data: Uint8Array): Promise<void>;
|
|
5
5
|
export interface Io {
|
|
@@ -32,6 +32,8 @@ export declare function parse(argv: string[]): Parsed;
|
|
|
32
32
|
export declare function when(v: unknown, now?: number): string;
|
|
33
33
|
export declare function renderStatus(s: StatusReply, expected: string | null, now?: number): string;
|
|
34
34
|
export declare function renderUsage(u: UsageTodayReply, today?: boolean, now?: number): string;
|
|
35
|
+
export declare function renderResets(r: BankedResets, s: StatusReply, now?: number): string;
|
|
36
|
+
export declare function renderConsent(c: ConsentState): string;
|
|
35
37
|
/** A refusal or failure: code, next_step, executed; a handshake's notice or question is shown for the person, never answered here. */
|
|
36
38
|
export declare function renderError(e: FloviaError): string;
|
|
37
39
|
export declare function run(argv: string[], io: Io): Promise<number>;
|
package/dist/cli.js
CHANGED
|
@@ -29,6 +29,8 @@ const COMMANDS = {
|
|
|
29
29
|
call: { usage: "call <tool> ['<json args>' | -]", about: "call a tool; - reads a JSON object from stdin", flags: {} },
|
|
30
30
|
"runway-output": { usage: "runway-output <generation_id> --out PATH", about: "download an existing private output; never regenerates or overwrites", flags: { "--out": true } },
|
|
31
31
|
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 } },
|
|
32
|
+
resets: { usage: "resets [use <id> --yes]", about: "check saved resets (read-only), or use one to restart both free windows", flags: { "--yes": false } },
|
|
33
|
+
consent: { usage: "consent [accept <version> --yes]", about: "read Flovia's current notice and your answer, or record your own yes to it", flags: { "--yes": false } },
|
|
32
34
|
"agents-md": { usage: "agents-md", about: "a short Flovia note to paste into CLAUDE.md or AGENTS.md (no network)", flags: {} },
|
|
33
35
|
help: { usage: "help [command]", about: "this help", flags: {} },
|
|
34
36
|
version: { usage: "version", about: "the installed CLI version", flags: {} },
|
|
@@ -103,6 +105,10 @@ export function help(command) {
|
|
|
103
105
|
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.");
|
|
104
106
|
if (command === "tools" || c === undefined)
|
|
105
107
|
lines.push("", "Inspect one tool: flovia tools <tool> --json", "Inspect all tool arguments: flovia tools --json", "Read-only example: flovia call flovia_status '{}'");
|
|
108
|
+
if (command === "resets")
|
|
109
|
+
lines.push("", "flovia resets only reads; it never uses one.", "Using one starts both free windows (5-hour and week) again; it cannot be undone.", " flovia resets use <id> --yes", "It is never resent automatically; after a lost reply, run flovia resets first.");
|
|
110
|
+
if (command === "consent")
|
|
111
|
+
lines.push("", "flovia consent only reads; it never answers.", "Only the account owner may answer, for themselves, after reading the notice:", " flovia consent accept <version> --yes", "Without --yes nothing is sent. The same answer can be given in Console.");
|
|
106
112
|
if (command === "call")
|
|
107
113
|
lines.push("", "Read a saved request: flovia call <tool> - < request.json", ...SAVE_OP);
|
|
108
114
|
lines.push("", "Default base URL: https://api.flovia.dev.", "Exit codes: 0 ok, 1 error from Flovia, 2 usage error.", "");
|
|
@@ -231,6 +237,10 @@ export function renderStatus(s, expected, now = Date.now()) {
|
|
|
231
237
|
for (const [name, w] of [["free 5-hour", s.five_hour], ["free week", s.week]])
|
|
232
238
|
lines.push(`${label(name)}${pct(w?.used_pct)} used${w?.resets_at ? `, resets ${when(w.resets_at, now)}` : name === "free 5-hour" ? ", not started" : ""}`);
|
|
233
239
|
lines.push(`${label("purchased balance")}${String(s["purchased_balance_display"] ?? "-")}`);
|
|
240
|
+
// An older relay omits banked_resets; nothing is shown then.
|
|
241
|
+
const banked = obj(s["banked_resets"]), n = banked["available"];
|
|
242
|
+
if (typeof n === "number" && n > 0)
|
|
243
|
+
lines.push(`You have ${n} saved reset${n === 1 ? "" : "s"} (until ${String(banked["next_expires_at"]).slice(0, 10)}). Run: flovia resets`);
|
|
234
244
|
const pending = obj(s["free_pending"]);
|
|
235
245
|
if (pending["next_step"])
|
|
236
246
|
lines.push(`free allowance not started: ${String(pending["next_step"])}`);
|
|
@@ -266,6 +276,26 @@ export function renderUsage(u, today = false, now = Date.now()) {
|
|
|
266
276
|
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)}`);
|
|
267
277
|
return lines.join("\n") + "\n";
|
|
268
278
|
}
|
|
279
|
+
export function renderResets(r, s, now = Date.now()) {
|
|
280
|
+
const lines = [`${label("saved resets")}${r.available}`];
|
|
281
|
+
if (r.next)
|
|
282
|
+
lines.push(`${label("next to expire")}id ${r.next.id}, expires ${when(r.next.expires_at, now)}`);
|
|
283
|
+
for (const [name, w] of [["free 5-hour", s.five_hour], ["free week", s.week]])
|
|
284
|
+
lines.push(`${label(name)}${pct(w?.used_pct)} used${w?.resets_at ? `, resets ${when(w.resets_at, now)}` : ""}`);
|
|
285
|
+
if (r.next)
|
|
286
|
+
lines.push("Using one starts both free windows (5-hour and week) again from 0%. It cannot be undone.", `To use it: flovia resets use ${r.next.id} --yes`);
|
|
287
|
+
return lines.join("\n") + "\n";
|
|
288
|
+
}
|
|
289
|
+
export function renderConsent(c) {
|
|
290
|
+
const lines = [`${label("current notice")}${c.version}`, `${label("your yes")}${c.answered_version ?? "none"}`];
|
|
291
|
+
if (!c.needed && !c.updated)
|
|
292
|
+
return lines.join("\n") + "\n";
|
|
293
|
+
if (c.updated)
|
|
294
|
+
lines.push("", c.version === "relay-consent-19" ? "Your earlier yes keeps working. Notice 19 adds owner-only lookup reply copies for up to 30 days for new records from 2026-12-03 or after your fresh explicit yes. Earlier records keep their original periods; no answer is needed to keep looking up." : "Your earlier yes keeps working. If you keep using Flovia from 2026-12-01 (30 days after the notice), you agree to the current notice; recording a yes below now is optional and applies from when you give it.");
|
|
295
|
+
lines.push("", "Notice:", c.notice);
|
|
296
|
+
lines.push("", `To answer yes yourself: flovia consent accept ${c.version} --yes (or in Console: ${CONSOLE})`);
|
|
297
|
+
return lines.join("\n") + "\n";
|
|
298
|
+
}
|
|
269
299
|
/** A refusal or failure: code, next_step, executed; a handshake's notice or question is shown for the person, never answered here. */
|
|
270
300
|
export function renderError(e) {
|
|
271
301
|
const lines = [`error: ${e.code}: ${e.message}`];
|
|
@@ -280,12 +310,17 @@ export function renderError(e) {
|
|
|
280
310
|
lines.push(`operation_id: ${e.operationId}${e.executed === "unknown" ? " (keep this id; never send the request again under a new one)" : ""}`);
|
|
281
311
|
const reply = obj(e.reply);
|
|
282
312
|
if (e.code === "notice_first" || e.code === "data_consent_needed") {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
313
|
+
const notice = reply["user_notice"] || reply["notice"];
|
|
314
|
+
if (notice)
|
|
315
|
+
lines.push("", "Notice:", String(notice));
|
|
316
|
+
const consent = obj(reply["consent"]), question = consent["question"] || (e.code === "data_consent_needed" ? consent["line"] : undefined);
|
|
286
317
|
if (question)
|
|
287
|
-
lines.push("", `
|
|
288
|
-
|
|
318
|
+
lines.push("", `Your choice: ${String(question)}`);
|
|
319
|
+
if (e.code === "data_consent_needed") {
|
|
320
|
+
lines.push("", "Only the user can consent; the CLI does not answer for them.");
|
|
321
|
+
}
|
|
322
|
+
else
|
|
323
|
+
lines.push("", "Follow next_step. The CLI does not opt in for the user.");
|
|
289
324
|
}
|
|
290
325
|
return lines.join("\n") + "\n";
|
|
291
326
|
}
|
|
@@ -377,6 +412,60 @@ export async function run(argv, io) {
|
|
|
377
412
|
err(`warning: contract ${s.contract_version} differs from this CLI's ${String(mismatch)}\n`);
|
|
378
413
|
return 0;
|
|
379
414
|
}
|
|
415
|
+
case "resets": {
|
|
416
|
+
const [action, id, extra] = p.positional;
|
|
417
|
+
if (action === undefined) {
|
|
418
|
+
if (p.flags.has("--yes"))
|
|
419
|
+
throw new Usage("Usage: flovia resets use <id> --yes");
|
|
420
|
+
const client = await connect(), r = await waitFor(() => client.bankedResets()), s = await waitFor(() => client.status());
|
|
421
|
+
if (json)
|
|
422
|
+
print({ ...r, five_hour: s.five_hour, week: s.week });
|
|
423
|
+
else
|
|
424
|
+
out(renderResets(r, s, (io.now ?? Date.now)()));
|
|
425
|
+
return 0;
|
|
426
|
+
}
|
|
427
|
+
const grant = action === "use" && extra === undefined && id !== undefined && /^[1-9][0-9]{0,15}$/.test(id) ? Number(id) : NaN;
|
|
428
|
+
if (!Number.isSafeInteger(grant))
|
|
429
|
+
throw new Usage("Usage: flovia resets use <id> --yes (the id from flovia resets)");
|
|
430
|
+
if (!p.flags.has("--yes"))
|
|
431
|
+
throw new Usage("resets use: add --yes to use it; it cannot be undone. Check first: flovia resets");
|
|
432
|
+
const client = await connect(), u = await waitFor(() => client.useBankedReset(grant));
|
|
433
|
+
if (json)
|
|
434
|
+
print(u);
|
|
435
|
+
else
|
|
436
|
+
out(u.outcome === "used" ? `Used. Both free windows (5-hour and week) start again from 0%.\n${label("saved resets")}${u.available}\n`
|
|
437
|
+
: `Not used; nothing changed.\n${label("saved resets")}${u.available}\nCheck: flovia resets\n`);
|
|
438
|
+
return u.outcome === "used" ? 0 : 1;
|
|
439
|
+
}
|
|
440
|
+
case "consent": {
|
|
441
|
+
const [action, version, extra] = p.positional;
|
|
442
|
+
if (action === undefined) {
|
|
443
|
+
if (p.flags.has("--yes"))
|
|
444
|
+
throw new Usage("Usage: flovia consent accept <version> --yes");
|
|
445
|
+
const client = await connect(), c = await waitFor(() => client.consent());
|
|
446
|
+
if (json)
|
|
447
|
+
print(c);
|
|
448
|
+
else
|
|
449
|
+
out(renderConsent(c));
|
|
450
|
+
return 0;
|
|
451
|
+
}
|
|
452
|
+
if (action !== "accept" || version === undefined || extra !== undefined)
|
|
453
|
+
throw new Usage("Usage: flovia consent accept <version> --yes (the version from flovia consent)");
|
|
454
|
+
const client = await connect();
|
|
455
|
+
if (!p.flags.has("--yes")) {
|
|
456
|
+
// Show what would be agreed to, then stop: nothing is sent without --yes.
|
|
457
|
+
const c = await waitFor(() => client.consent());
|
|
458
|
+
if (!json)
|
|
459
|
+
out(renderConsent(c));
|
|
460
|
+
throw new Usage(`consent accept: nothing was sent. Read the notice, then add --yes to answer yes to ${version} yourself.`);
|
|
461
|
+
}
|
|
462
|
+
const a = await waitFor(() => client.acceptConsent(version));
|
|
463
|
+
if (json)
|
|
464
|
+
print(a);
|
|
465
|
+
else
|
|
466
|
+
out(a.outcome === "recorded" ? `Recorded: yes to ${a.version}.\n` : `Already answered yes to ${a.version}; nothing changed.\n`);
|
|
467
|
+
return 0;
|
|
468
|
+
}
|
|
380
469
|
case "usage": {
|
|
381
470
|
const since = str(p.flags.get("--since")), days = positiveInt("--days", str(p.flags.get("--days")), 7), cursor = str(p.flags.get("--cursor"));
|
|
382
471
|
if (since !== undefined && days !== undefined)
|
|
@@ -476,7 +565,7 @@ export async function run(argv, io) {
|
|
|
476
565
|
// The id is shown before anything is sent, so a lost reply can be reopened with it (never resent under a new one).
|
|
477
566
|
if (fresh)
|
|
478
567
|
err(`operation_id: ${id}\nSave it. To resend or reopen this request, use: --op ${id}\n`);
|
|
479
|
-
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
|
|
568
|
+
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 may reopen free: up to 30 days from creation for notice 18 generations; earlier ones about 15 minutes. Missing or deleted copies are not restored. Never use a new id to recover an answer.\n");
|
|
480
569
|
if (!p.flags.has("--yes")) {
|
|
481
570
|
if (io.confirm === null || text === "-")
|
|
482
571
|
throw new Usage("generate: add --yes to send (no terminal to confirm on)");
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Generation, type GenerationRequest, type StatusReply, type ToolReply, type UsageTodayArgs, type UsageTodayReply } from "./types.js";
|
|
1
|
+
import { type Generation, type GenerationRequest, type StatusReply, type ToolReply, type UsageTodayArgs, type UsageTodayReply, type BankedResets, type BankedResetUse, type ConsentState, type ConsentAccept } from "./types.js";
|
|
2
2
|
export interface FloviaClientOptions {
|
|
3
3
|
/** A Flovia key (flv_...). Defaults to the FLOVIA_KEY environment variable. Never logged. */
|
|
4
4
|
apiKey?: string;
|
|
@@ -27,11 +27,25 @@ export declare const newOperationId: () => string;
|
|
|
27
27
|
export declare class FloviaClient {
|
|
28
28
|
#private;
|
|
29
29
|
constructor(options?: FloviaClientOptions);
|
|
30
|
-
/** Download an existing Runway output before
|
|
30
|
+
/** Download an existing Runway output before output.expires_at (up to 30 days under notice 18; earlier outputs keep 24h). This GET never creates, regenerates or retries a task. */
|
|
31
31
|
downloadRunwayOutput(generationId: string): Promise<{
|
|
32
32
|
data: Uint8Array;
|
|
33
33
|
contentType: string;
|
|
34
34
|
}>;
|
|
35
|
+
/** The account's saved resets: count and the first to expire. Read-only; nothing is used. */
|
|
36
|
+
bankedResets(): Promise<BankedResets>;
|
|
37
|
+
/**
|
|
38
|
+
* Use one saved reset (its id from bankedResets()): both free windows, 5-hour and week, start again. Never resent automatically;
|
|
39
|
+
* "not_used" means nothing changed. After a lost, refused (401) or unreadable reply, check bankedResets() before deciding to try again.
|
|
40
|
+
*/
|
|
41
|
+
useBankedReset(grantId: number): Promise<BankedResetUse>;
|
|
42
|
+
/** The account's answer to Flovia's current notice and the notice text. Read-only; nothing is answered. */
|
|
43
|
+
consent(): Promise<ConsentState>;
|
|
44
|
+
/**
|
|
45
|
+
* Record the account owner's own yes to exactly this notice version (from consent()). Only call it on the owner's explicit instruction; an agent must
|
|
46
|
+
* never answer for them. An older version is refused and nothing is recorded; a repeat changes nothing.
|
|
47
|
+
*/
|
|
48
|
+
acceptConsent(version: string): Promise<ConsentAccept>;
|
|
35
49
|
/** tools/list: the tools this key is offered, with their input schemas. */
|
|
36
50
|
listTools(): Promise<ToolInfo[]>;
|
|
37
51
|
/** tools/call for any tool. A reply with ok: false throws FloviaError (handshakes such as notice_first too; see error.reply). */
|
|
@@ -42,7 +56,8 @@ export declare class FloviaClient {
|
|
|
42
56
|
usageToday(args?: UsageTodayArgs): Promise<UsageTodayReply>;
|
|
43
57
|
/**
|
|
44
58
|
* POST /openai/v1/responses. operationId is required: save it with the request before calling. Sending the same request with the same id
|
|
45
|
-
* again can return the saved answer (replayed: true)
|
|
59
|
+
* again can return the saved answer (replayed: true) at no charge: notice 18 generations up to 30 days from creation, earlier ones about 15 minutes.
|
|
60
|
+
* Missing or deleted copies are not restored. Pending, unknown and expired answers
|
|
46
61
|
* are not proof that nothing ran. Never resent automatically, and never under a new id to recover an answer.
|
|
47
62
|
*/
|
|
48
63
|
generate(request: GenerationRequest, options: {
|
package/dist/client.js
CHANGED
|
@@ -119,7 +119,7 @@ export class FloviaClient {
|
|
|
119
119
|
message: String(message.error?.message ?? "No result."), nextStep: operationId ? SAME_OPERATION : null });
|
|
120
120
|
return message.result;
|
|
121
121
|
}
|
|
122
|
-
/** Download an existing Runway output before
|
|
122
|
+
/** Download an existing Runway output before output.expires_at (up to 30 days under notice 18; earlier outputs keep 24h). This GET never creates, regenerates or retries a task. */
|
|
123
123
|
async downloadRunwayOutput(generationId) {
|
|
124
124
|
const unavailable = () => this.#error({ code: "output_unavailable", executed: "no", message: "The private output could not be downloaded.", nextStep: "Check the original generation's status and expiry; never regenerate it automatically." });
|
|
125
125
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(generationId))
|
|
@@ -163,6 +163,81 @@ export class FloviaClient {
|
|
|
163
163
|
reader?.releaseLock();
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
+
/** The account's saved resets: count and the first to expire. Read-only; nothing is used. */
|
|
167
|
+
async bankedResets() {
|
|
168
|
+
const r = await this.#send("/account/banked-resets", null, {}, null, "GET");
|
|
169
|
+
const body = await this.#account(r, null);
|
|
170
|
+
if (!isResets(body))
|
|
171
|
+
throw this.#error({ code: "invalid_reply", status: r.status, executed: "no", message: "The saved-reset reply was not in the expected form.", nextStep: null });
|
|
172
|
+
return { available: body.available, next: body.next };
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Use one saved reset (its id from bankedResets()): both free windows, 5-hour and week, start again. Never resent automatically;
|
|
176
|
+
* "not_used" means nothing changed. After a lost, refused (401) or unreadable reply, check bankedResets() before deciding to try again.
|
|
177
|
+
*/
|
|
178
|
+
async useBankedReset(grantId) {
|
|
179
|
+
if (!Number.isSafeInteger(grantId) || grantId <= 0)
|
|
180
|
+
throw new FloviaError({ code: "invalid_request", executed: "no", message: "grantId must be a positive whole number from bankedResets()." });
|
|
181
|
+
const check = "It may have been used. Run bankedResets() (flovia resets) to see whether it was used before trying again.";
|
|
182
|
+
const unknown = (e) => this.#error({ code: e.code, status: e.status, executed: "unknown", message: e.message,
|
|
183
|
+
nextStep: e.nextStep && e.executed !== "unknown" ? `${check} ${e.nextStep}` : check });
|
|
184
|
+
let r;
|
|
185
|
+
try {
|
|
186
|
+
r = await this.#send("/account/banked-resets/use", { grant_id: grantId });
|
|
187
|
+
}
|
|
188
|
+
// The relay rechecks the key after the use, so a 401 does not prove that nothing changed.
|
|
189
|
+
catch (e) {
|
|
190
|
+
throw e instanceof FloviaError && (e.executed === "unknown" || e.status === 401) ? unknown(e) : e;
|
|
191
|
+
}
|
|
192
|
+
const body = await this.#account(r, check);
|
|
193
|
+
if (!isResets(body) || (body["outcome"] !== "used" && body["outcome"] !== "not_used"))
|
|
194
|
+
throw this.#error({ code: "invalid_reply", status: r.status, executed: "unknown", message: "The saved-reset reply was not in the expected form.", nextStep: check });
|
|
195
|
+
return { outcome: body["outcome"], available: body.available, next: body.next };
|
|
196
|
+
}
|
|
197
|
+
/** The account's answer to Flovia's current notice and the notice text. Read-only; nothing is answered. */
|
|
198
|
+
async consent() {
|
|
199
|
+
const r = await this.#send("/account/consent", null, {}, null, "GET");
|
|
200
|
+
const body = await this.#account(r, null);
|
|
201
|
+
if (!isConsent(body))
|
|
202
|
+
throw this.#error({ code: "invalid_reply", status: r.status, executed: "no", message: "The consent reply was not in the expected form.", nextStep: null });
|
|
203
|
+
return { version: body.version, answered_version: body.answered_version, needed: body.needed, updated: body.updated, notice: body.notice };
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Record the account owner's own yes to exactly this notice version (from consent()). Only call it on the owner's explicit instruction; an agent must
|
|
207
|
+
* never answer for them. An older version is refused and nothing is recorded; a repeat changes nothing.
|
|
208
|
+
*/
|
|
209
|
+
async acceptConsent(version) {
|
|
210
|
+
if (typeof version !== "string" || !/^[a-z0-9-]{1,80}$/.test(version))
|
|
211
|
+
throw new FloviaError({ code: "invalid_request", executed: "no", message: "version must be the version from consent()." });
|
|
212
|
+
const check = "It may have been recorded. Run consent() (flovia consent) to see whether it was recorded before trying again.";
|
|
213
|
+
const unknown = (e) => this.#error({ code: e.code, status: e.status, executed: "unknown", message: e.message,
|
|
214
|
+
nextStep: e.nextStep && e.executed !== "unknown" ? `${check} ${e.nextStep}` : check });
|
|
215
|
+
let r;
|
|
216
|
+
try {
|
|
217
|
+
r = await this.#send("/account/consent/accept", { version });
|
|
218
|
+
}
|
|
219
|
+
// The relay rechecks the key after the write, so a 401 does not prove that nothing was recorded.
|
|
220
|
+
catch (e) {
|
|
221
|
+
throw e instanceof FloviaError && (e.executed === "unknown" || e.status === 401) ? unknown(e) : e;
|
|
222
|
+
}
|
|
223
|
+
const body = await this.#account(r, check);
|
|
224
|
+
if (!isConsent(body) || (body["outcome"] !== "recorded" && body["outcome"] !== "unchanged"))
|
|
225
|
+
throw this.#error({ code: "invalid_reply", status: r.status, executed: "unknown", message: "The consent reply was not in the expected form.", nextStep: check });
|
|
226
|
+
return { outcome: body["outcome"], version: body.version, answered_version: body.answered_version, needed: body.needed, updated: body.updated, notice: body.notice };
|
|
227
|
+
}
|
|
228
|
+
async #account(r, unknownStep) {
|
|
229
|
+
let body;
|
|
230
|
+
try {
|
|
231
|
+
body = await readReply(r, null, init => this.#error(init));
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
throw e instanceof FloviaError && unknownStep !== null ? this.#error({ code: e.code, status: r.status, executed: "unknown", message: e.message, nextStep: unknownStep }) : e;
|
|
235
|
+
}
|
|
236
|
+
if (r.status === 200)
|
|
237
|
+
return body;
|
|
238
|
+
throw this.#error({ code: typeof body["error"] === "string" ? body["error"] : `http_${r.status}`, status: r.status, executed: r.status >= 500 && unknownStep !== null ? "unknown" : "no",
|
|
239
|
+
message: typeof body["message"] === "string" ? body["message"] : `HTTP ${r.status}`, nextStep: r.status >= 500 ? unknownStep : null });
|
|
240
|
+
}
|
|
166
241
|
/** tools/list: the tools this key is offered, with their input schemas. */
|
|
167
242
|
async listTools() {
|
|
168
243
|
return (await this.#rpc("tools/list")).tools;
|
|
@@ -218,7 +293,8 @@ export class FloviaClient {
|
|
|
218
293
|
}
|
|
219
294
|
/**
|
|
220
295
|
* POST /openai/v1/responses. operationId is required: save it with the request before calling. Sending the same request with the same id
|
|
221
|
-
* again can return the saved answer (replayed: true)
|
|
296
|
+
* again can return the saved answer (replayed: true) at no charge: notice 18 generations up to 30 days from creation, earlier ones about 15 minutes.
|
|
297
|
+
* Missing or deleted copies are not restored. Pending, unknown and expired answers
|
|
222
298
|
* are not proof that nothing ran. Never resent automatically, and never under a new id to recover an answer.
|
|
223
299
|
*/
|
|
224
300
|
async generate(request, options) {
|
|
@@ -241,6 +317,18 @@ export class FloviaClient {
|
|
|
241
317
|
retryAfterSeconds: seconds(r.headers.get("Retry-After")) ?? seconds(body["retry_after_seconds"]) });
|
|
242
318
|
}
|
|
243
319
|
}
|
|
320
|
+
const count = (v, min) => typeof v === "number" && Number.isSafeInteger(v) && v >= min;
|
|
321
|
+
/** The saved-reset summary's exact public form. */
|
|
322
|
+
function isResets(b) {
|
|
323
|
+
const next = b["next"];
|
|
324
|
+
return count(b["available"], 0) && (next === null || (typeof next === "object" && !Array.isArray(next) && count(next["id"], 1)
|
|
325
|
+
&& typeof next["expires_at"] === "string" && !Number.isNaN(Date.parse(next["expires_at"])))) && (next === null) === (b["available"] === 0);
|
|
326
|
+
}
|
|
327
|
+
function isConsent(b) {
|
|
328
|
+
const text = (v) => typeof v === "string" && v.length > 0;
|
|
329
|
+
return text(b["version"]) && (b["answered_version"] === null || text(b["answered_version"])) && typeof b["needed"] === "boolean"
|
|
330
|
+
&& typeof b["updated"] === "boolean" && text(b["notice"]);
|
|
331
|
+
}
|
|
244
332
|
/** Whether a refused generation ran, from its public code (the same reading flovia_openai gives over MCP). */
|
|
245
333
|
function generationExecuted(code) {
|
|
246
334
|
if (["answer_unavailable", "answer_expired", "answer_delivery_denied"].includes(code))
|
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.172";
|
|
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", "free_not_granted", "global_cap", "flovia_paused", "rate_limited", "too_many_in_parallel", "reservation_changed", "operation_conflict", "operation_pending", "relay_internal_error", "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"];
|
|
4
|
+
export declare const PUBLIC_CODES: readonly ["approval_pending", "key_disabled", "key_stopped", "consent_missing", "data_consent_mismatch", "data_consent_needed", "notice_first", "provider_not_allowed", "account_key_required", "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_month", "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", "relay_internal_error", "relay_internal_unknown", "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";
|
|
@@ -80,3 +80,28 @@ export interface Generation {
|
|
|
80
80
|
receivedAt: string | null;
|
|
81
81
|
conversationId: string | null;
|
|
82
82
|
}
|
|
83
|
+
/** GET /account/banked-resets: saved resets that can still be used, and the first to expire. */
|
|
84
|
+
export interface BankedResets {
|
|
85
|
+
available: number;
|
|
86
|
+
next: {
|
|
87
|
+
id: number;
|
|
88
|
+
expires_at: string;
|
|
89
|
+
} | null;
|
|
90
|
+
}
|
|
91
|
+
/** "used": both free windows (5-hour and week) start again. "not_used": nothing changed (already used, expired, a lookup still settling, or nothing to reset). */
|
|
92
|
+
export interface BankedResetUse extends BankedResets {
|
|
93
|
+
outcome: "used" | "not_used";
|
|
94
|
+
}
|
|
95
|
+
/** GET /account/consent: the current notice version, the version this account last said yes to (null: none), and the notice text.
|
|
96
|
+
* updated: the yes is to an earlier version; it keeps working and continued use accepts the current one, so an explicit yes is optional. */
|
|
97
|
+
export interface ConsentState {
|
|
98
|
+
version: string;
|
|
99
|
+
answered_version: string | null;
|
|
100
|
+
needed: boolean;
|
|
101
|
+
updated: boolean;
|
|
102
|
+
notice: string;
|
|
103
|
+
}
|
|
104
|
+
/** "recorded": the yes to the current notice was saved now. "unchanged": it was already saved; nothing changed. */
|
|
105
|
+
export interface ConsentAccept extends ConsentState {
|
|
106
|
+
outcome: "recorded" | "unchanged";
|
|
107
|
+
}
|
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.172";
|
|
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
|
-
"endpoint_unknown", "endpoint_disabled", "read_only", "not_relayed", "key_in_query", "secret_in_input", "invalid_body", "body_too_large",
|
|
6
|
+
"provider_not_allowed", "account_key_required", "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", "free_not_granted", "global_cap",
|
|
8
|
+
"over_max_credits", "window_5h", "window_month", "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", "relay_internal_error", "upstream_unknown", "cannot_summarize", "upstream_unavailable", "page_tls_invalid", "page_unreachable", "replay_response_unavailable", "rpc_error",
|
|
10
|
+
"operation_conflict", "operation_pending", "relay_internal_error", "relay_internal_unknown", "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
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flovialabs/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "TypeScript client and CLI for Flovia: MCP tools over HTTP and OpenAI-compatible generation. Zero dependencies.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://api.flovia.dev",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/flovia/groupbuy.git",
|
|
11
|
+
"directory": "packages/flovia-sdk"
|
|
12
|
+
},
|
|
8
13
|
"keywords": [
|
|
9
14
|
"flovia",
|
|
10
15
|
"mcp",
|