@flovialabs/sdk 0.1.10 → 0.1.11
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 +5 -0
- package/README.md +2 -2
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +16 -9
- package/dist/client.js +9 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.11
|
|
6
|
+
|
|
7
|
+
- SDK request-construction failures use `invalid_request` with `executed: no` before any request is sent; raw exception causes are not exposed.
|
|
8
|
+
- CLI stdin rejects malformed UTF-8 before sending, and key-file errors no longer expose the local file path.
|
|
9
|
+
|
|
5
10
|
## 0.1.10
|
|
6
11
|
|
|
7
12
|
- `flovia tools` keeps a short second sentence of each description, so what a tool is for stays visible.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ TypeScript client and command-line tool for [Flovia](https://api.flovia.dev). It
|
|
|
10
10
|
## Install
|
|
11
11
|
|
|
12
12
|
```sh
|
|
13
|
-
npm install --save-exact @flovialabs/sdk@0.1.
|
|
13
|
+
npm install --save-exact @flovialabs/sdk@0.1.11
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Your key
|
|
@@ -230,7 +230,7 @@ npx flovia agents-md # a short note for CLAUDE.md or AGENTS.md
|
|
|
230
230
|
npx flovia help
|
|
231
231
|
npx flovia --version
|
|
232
232
|
```
|
|
233
|
-
These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.
|
|
233
|
+
These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.11 flovia --help`. Use a unique operation id for each new request; `sdk-example-0001` is only an example. Save the id, prompt and options before sending, and keep them unchanged for replay.
|
|
234
234
|
|
|
235
235
|
Get or manage your key in [Console](https://console.flovia.dev/groupbuy/), save it privately, then run `flovia status --key-file <saved-key-file>`. A connected key can still have sharing declined, withdrawn or stopped; `status` shows those separately from provider availability. It never answers consent for you.
|
|
236
236
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -32,5 +32,5 @@ export declare function renderUsage(u: UsageTodayReply, today?: boolean, now?: n
|
|
|
32
32
|
/** A refusal or failure: code, next_step, executed; a handshake's notice or question is shown for the person, never answered here. */
|
|
33
33
|
export declare function renderError(e: FloviaError): string;
|
|
34
34
|
export declare function run(argv: string[], io: Io): Promise<number>;
|
|
35
|
-
/** Decode UTF-8
|
|
35
|
+
/** Decode UTF-8 once over all bytes (a character split between reads survives); invalid bytes throw instead of becoming U+FFFD. */
|
|
36
36
|
export declare function readStdin(input: NodeJS.ReadableStream): Promise<string>;
|
package/dist/cli.js
CHANGED
|
@@ -153,18 +153,19 @@ async function readKey(p, io) {
|
|
|
153
153
|
const file = str(p.flags.get("--key-file"));
|
|
154
154
|
if (file !== undefined) {
|
|
155
155
|
let text;
|
|
156
|
+
// Never echo the path: a key pasted in its place would land in the output.
|
|
156
157
|
try {
|
|
157
158
|
text = await io.readFile(file);
|
|
158
159
|
}
|
|
159
160
|
catch {
|
|
160
|
-
throw new Usage(
|
|
161
|
+
throw new Usage("--key-file: cannot read the key file");
|
|
161
162
|
}
|
|
162
163
|
const key = text.trim();
|
|
163
164
|
if (key === "")
|
|
164
|
-
throw new Usage(
|
|
165
|
+
throw new Usage("--key-file: the key file is empty");
|
|
165
166
|
const mode = await io.fileMode?.(file).catch(() => null);
|
|
166
167
|
if (typeof mode === "number" && (mode & 0o077) !== 0)
|
|
167
|
-
io.err(`warning:
|
|
168
|
+
io.err(`warning: the key file is readable by other users (mode ${(mode & 0o777).toString(8)}); run chmod 600 on it\n`);
|
|
168
169
|
return key;
|
|
169
170
|
}
|
|
170
171
|
const key = io.env["FLOVIA_KEY"]?.trim();
|
|
@@ -419,7 +420,14 @@ export async function run(argv, io) {
|
|
|
419
420
|
const max = positiveInt("--max-output", str(p.flags.get("--max-output")));
|
|
420
421
|
const effort = reasoningEffort(str(p.flags.get("--reasoning-effort")));
|
|
421
422
|
const client = await connect();
|
|
422
|
-
|
|
423
|
+
let input = text;
|
|
424
|
+
if (text === "-")
|
|
425
|
+
try {
|
|
426
|
+
input = await io.readStdin();
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
throw new Usage("generate: cannot read the prompt from stdin (it must be UTF-8 text)");
|
|
430
|
+
}
|
|
423
431
|
if (input.trim() === "")
|
|
424
432
|
throw new Usage("generate: the prompt is empty");
|
|
425
433
|
recoveryLimit = max;
|
|
@@ -482,13 +490,12 @@ export async function run(argv, io) {
|
|
|
482
490
|
return 1;
|
|
483
491
|
}
|
|
484
492
|
}
|
|
485
|
-
/** Decode UTF-8
|
|
493
|
+
/** Decode UTF-8 once over all bytes (a character split between reads survives); invalid bytes throw instead of becoming U+FFFD. */
|
|
486
494
|
export async function readStdin(input) {
|
|
487
|
-
|
|
488
|
-
let text = "";
|
|
495
|
+
const chunks = [];
|
|
489
496
|
for await (const chunk of input)
|
|
490
|
-
|
|
491
|
-
return
|
|
497
|
+
chunks.push(Buffer.from(chunk));
|
|
498
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks));
|
|
492
499
|
}
|
|
493
500
|
/** Run only as the program (also through npm's bin symlink), not when imported. Node and Bun alike. */
|
|
494
501
|
const isMain = (() => { try {
|
package/dist/client.js
CHANGED
|
@@ -78,12 +78,19 @@ export class FloviaClient {
|
|
|
78
78
|
}
|
|
79
79
|
/** One HTTP request. A network failure or timeout is executed "unknown": the relay may have received it. */
|
|
80
80
|
async #send(path, body, headers = {}, operationId = null) {
|
|
81
|
-
let
|
|
81
|
+
let request;
|
|
82
82
|
try {
|
|
83
|
-
|
|
83
|
+
request = new Request(this.#base + path, { method: "POST", redirect: "error", body: JSON.stringify(body), signal: AbortSignal.timeout(this.#timeoutMs),
|
|
84
84
|
// The family only, so the relay can count SDK calls apart from other clients; never a version or an id.
|
|
85
85
|
headers: { Authorization: `Bearer ${this.#key}`, "Content-Type": "application/json", "X-Flovia-Client": "flovia-sdk", ...headers,
|
|
86
86
|
...(this.#accessToken ? { "Cf-Access-Token": this.#accessToken } : {}) } });
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Built before any send (a multi-line key or header, a body JSON cannot hold): nothing reached Flovia. The cause may hold a header.
|
|
90
|
+
throw this.#error({ code: "invalid_request", executed: "no", operationId, message: "The request could not be built (check the key, ids and body); nothing was sent.", nextStep: null });
|
|
91
|
+
}
|
|
92
|
+
let r;
|
|
93
|
+
try {
|
|
87
94
|
r = await this.#fetch(request);
|
|
88
95
|
}
|
|
89
96
|
catch (cause) {
|
package/package.json
CHANGED