@flovialabs/sdk 0.1.2 → 0.1.3

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.3
4
+
5
+ - Redact the configured API key when it is echoed in SDK errors, recovery metadata, diagnostic reply fields or contract warnings.
6
+
3
7
  ## 0.1.2
4
8
 
5
9
  - CLI status distinguishes a successful connection from declined sharing, withdrawal, stopped keys and consent that needs an answer.
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.2
13
+ npm install --save-exact @flovialabs/sdk@0.1.3
14
14
  ```
15
15
 
16
16
  ## Your key
@@ -136,7 +136,7 @@ npx flovia generate --op sdk-example-0001 --max-output 300 --yes "Explain a DEX
136
136
  npx flovia help
137
137
  npx flovia --version
138
138
  ```
139
- These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.2 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.
139
+ These commands run after installing `@flovialabs/sdk` in the current project. Without a local installation, specify the package: `npx --package=@flovialabs/sdk@0.1.3 flovia --help`. Use a unique operation id for each new request; `sdk-example-0001` is only an example. Save the id, prompt and options before sending, and keep them unchanged for replay.
140
140
 
141
141
  Get or manage your key in [Console](https://console.flovia.dev/groupbuy/), save it privately, then run `flovia status --key-file <saved-key-file>`. A connected key can still have sharing declined, withdrawn or stopped; `status` shows those separately from provider availability. It never answers consent for you.
142
142
 
package/dist/client.js CHANGED
@@ -14,7 +14,7 @@ const seconds = (v) => {
14
14
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
15
15
  const SAME_OPERATION = "Resend with the same operation_id; do not use a new one.";
16
16
  /** A lost or unreadable reply cannot prove that the operation did not run. */
17
- async function readReply(r, operationId, sse = false) {
17
+ async function readReply(r, operationId, makeError, sse = false) {
18
18
  try {
19
19
  const text = (await r.text()).trimStart();
20
20
  const payload = sse && !text.startsWith("{") ? text.split(/\r?\n/).filter((l) => l.startsWith("data:"))
@@ -26,7 +26,7 @@ async function readReply(r, operationId, sse = false) {
26
26
  }
27
27
  catch (cause) {
28
28
  const timeout = cause instanceof Error && cause.name === "TimeoutError";
29
- throw new FloviaError({ code: timeout ? "timeout" : `http_${r.status}`, status: r.status, executed: "unknown", operationId,
29
+ throw makeError({ code: timeout ? "timeout" : `http_${r.status}`, status: r.status, executed: "unknown", operationId,
30
30
  message: timeout ? "Timed out while reading the reply." : `Unexpected reply (HTTP ${r.status}).`, nextStep: operationId ? SAME_OPERATION : null });
31
31
  }
32
32
  }
@@ -62,6 +62,13 @@ export class FloviaClient {
62
62
  // eslint-disable-next-line no-console -- versions only, never the key
63
63
  this.#onMismatch = options.onContractMismatch ?? ((expected, actual) => console.warn(`Flovia contract ${actual} differs from the SDK's ${expected}; check flovia_status recent_updates.`));
64
64
  }
65
+ /** Mask only this client's exact key in diagnostic strings and reply field names; keep Error field names intact. */
66
+ #error(init) {
67
+ const scrub = (text) => text.replaceAll(this.#key, "[key]");
68
+ const safe = JSON.parse(JSON.stringify(init, (_name, value) => typeof value === "string" ? scrub(value) : value !== init && value !== null && typeof value === "object" && !Array.isArray(value)
69
+ ? Object.fromEntries(Object.entries(value).map(([name, field]) => [scrub(name), field])) : value));
70
+ return new FloviaError(safe);
71
+ }
65
72
  /** One HTTP request. A network failure or timeout is executed "unknown": the relay may have received it. */
66
73
  async #send(path, body, headers = {}, operationId = null) {
67
74
  let r;
@@ -73,7 +80,7 @@ export class FloviaClient {
73
80
  catch (cause) {
74
81
  const timeout = cause instanceof Error && cause.name === "TimeoutError";
75
82
  // Transport diagnostics may contain request headers, so never attach their raw cause.
76
- throw new FloviaError({ code: timeout ? "timeout" : "network_error", executed: "unknown", operationId,
83
+ throw this.#error({ code: timeout ? "timeout" : "network_error", executed: "unknown", operationId,
77
84
  message: timeout ? `No reply within ${this.#timeoutMs} ms.` : "The request did not complete.",
78
85
  nextStep: operationId ? SAME_OPERATION : null });
79
86
  }
@@ -83,9 +90,9 @@ export class FloviaClient {
83
90
  }
84
91
  async #rpc(method, params, operationId = null) {
85
92
  const r = await this.#send("/mcp", { jsonrpc: "2.0", id: ++this.#id, method, ...(params ? { params } : {}) }, { Accept: "application/json, text/event-stream", "MCP-Protocol-Version": "2025-06-18" }, operationId);
86
- const message = await readReply(r, operationId, true);
93
+ const message = await readReply(r, operationId, init => this.#error(init), true);
87
94
  if (message.error !== undefined || message.result === null || typeof message.result !== "object" || Array.isArray(message.result))
88
- throw new FloviaError({ code: "mcp_error", status: r.status, executed: "unknown", operationId,
95
+ throw this.#error({ code: "mcp_error", status: r.status, executed: "unknown", operationId,
89
96
  message: String(message.error?.message ?? "No result."), nextStep: operationId ? SAME_OPERATION : null });
90
97
  return message.result;
91
98
  }
@@ -113,7 +120,7 @@ export class FloviaClient {
113
120
  }
114
121
  }
115
122
  catch {
116
- throw new FloviaError({ code: "tool_error", executed: "unknown", operationId, nextStep: operationId ? SAME_OPERATION : null,
123
+ throw this.#error({ code: "tool_error", executed: "unknown", operationId, nextStep: operationId ? SAME_OPERATION : null,
117
124
  message: result.isError ? "The tool failed." : "The tool reply is not JSON." });
118
125
  }
119
126
  const e = reply.explanation;
@@ -125,7 +132,7 @@ export class FloviaClient {
125
132
  await sleep(Math.max(1, wait ?? 0) * 1000);
126
133
  continue;
127
134
  }
128
- throw new FloviaError({ code: e.code, message: e.meaning, nextStep: e.next_step, executed: e.executed, retryAfterSeconds: wait, operationId, reply });
135
+ throw this.#error({ code: e.code, message: e.meaning, nextStep: e.next_step, executed: e.executed, retryAfterSeconds: wait, operationId, reply });
129
136
  }
130
137
  }
131
138
  /** flovia_status. Warns once when the relay's contract_version is not the one this SDK expects. */
@@ -133,7 +140,7 @@ export class FloviaClient {
133
140
  const s = await this.call("flovia_status");
134
141
  if (!this.#warned && s.contract_version !== EXPECTED_CONTRACT_VERSION) {
135
142
  this.#warned = true;
136
- this.#onMismatch(EXPECTED_CONTRACT_VERSION, s.contract_version);
143
+ this.#onMismatch(EXPECTED_CONTRACT_VERSION, String(s.contract_version).replaceAll(this.#key, "[key]"));
137
144
  }
138
145
  return s;
139
146
  }
@@ -151,9 +158,9 @@ export class FloviaClient {
151
158
  if (!OPERATION_ID.test(op))
152
159
  throw new FloviaError({ code: "invalid_operation_id", executed: "no", message: "operationId must be 8-128 of A-Z a-z 0-9 _ . : -" });
153
160
  const r = await this.#send("/openai/v1/responses", request, { "Flovia-Operation-Id": op, ...(options.conversationId ? { "Flovia-Conversation-Id": options.conversationId } : {}) }, op);
154
- const body = await readReply(r, op);
161
+ const body = await readReply(r, op, init => this.#error(init));
155
162
  if (r.status === 200 && !Array.isArray(body["output"]))
156
- throw new FloviaError({ code: "http_200", status: 200, executed: "unknown", operationId: op, message: "Unexpected generation reply (HTTP 200).", nextStep: SAME_OPERATION });
163
+ throw this.#error({ code: "http_200", status: 200, executed: "unknown", operationId: op, message: "Unexpected generation reply (HTTP 200).", nextStep: SAME_OPERATION });
157
164
  if (r.status === 200)
158
165
  return { response: body, outputText: outputText(body), generationId: r.headers.get("Flovia-Generation-Id"),
159
166
  replayed: r.headers.get("Flovia-Replayed") === "1", receivedAt: r.headers.get("Flovia-Received-At"), conversationId: r.headers.get("Flovia-Conversation-Id") };
@@ -161,7 +168,7 @@ export class FloviaClient {
161
168
  const code = typeof err === "string" ? err : String(err?.code ?? `http_${r.status}`);
162
169
  const message = String(err?.message ?? body["message"] ?? `HTTP ${r.status}`);
163
170
  const executed = explanation?.executed ?? generationExecuted(code);
164
- throw new FloviaError({ code, message, status: r.status, operationId: op, reply: body,
171
+ throw this.#error({ code, message, status: r.status, operationId: op, reply: body,
165
172
  executed, nextStep: explanation?.next_step ?? (executed === "unknown" ? SAME_OPERATION : null),
166
173
  retryAfterSeconds: seconds(r.headers.get("Retry-After")) ?? seconds(body["retry_after_seconds"]) });
167
174
  }
package/dist/errors.d.ts CHANGED
@@ -11,7 +11,7 @@ export declare class FloviaError extends Error {
11
11
  readonly status: number | null;
12
12
  readonly retryAfterSeconds: number | null;
13
13
  readonly operationId: string | null;
14
- /** The full reply body, for fields such as user_notice or consent.question. */
14
+ /** The reply body with configured-key echoes redacted, including fields such as user_notice or consent.question. */
15
15
  readonly reply: ToolReply | null;
16
16
  constructor(init: {
17
17
  code: string;
package/dist/errors.js CHANGED
@@ -10,7 +10,7 @@ export class FloviaError extends Error {
10
10
  status;
11
11
  retryAfterSeconds;
12
12
  operationId;
13
- /** The full reply body, for fields such as user_notice or consent.question. */
13
+ /** The reply body with configured-key echoes redacted, including fields such as user_notice or consent.question. */
14
14
  reply;
15
15
  constructor(init) {
16
16
  super(init.message, init.cause === undefined ? undefined : { cause: init.cause });
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
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.118";
2
+ export declare const EXPECTED_CONTRACT_VERSION = "2026-10-07.119";
3
3
  /** Every public explanation.code (the relay's contract). A provider's own HTTP error is `http_<status>`. */
4
4
  export declare const PUBLIC_CODES: readonly ["key_disabled", "key_stopped", "consent_missing", "data_consent_mismatch", "data_consent_needed", "notice_first", "endpoint_unknown", "endpoint_disabled", "read_only", "not_relayed", "key_in_query", "secret_in_input", "invalid_body", "body_too_large", "answer_too_large", "answer_precision_unsafe", "answer_not_relayed", "request_text_too_long", "over_max_credits", "cost_confirmation_needed", "window_5h", "window_week", "over_week", "free_limited", "free_needs_email", "global_cap", "flovia_paused", "free_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}`;
@@ -39,6 +39,8 @@ export interface UsageTodayArgs {
39
39
  since?: string;
40
40
  /** The previous next_cursor, unchanged, with the same since and conversation. */
41
41
  cursor?: string;
42
+ /** The previous generations.next_cursor, with the same since and conversation. */
43
+ generation_cursor?: string;
42
44
  /** Only this conversation's lookups. */
43
45
  conversation?: string;
44
46
  }
package/dist/types.js CHANGED
@@ -1,5 +1,5 @@
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.118";
2
+ export const EXPECTED_CONTRACT_VERSION = "2026-10-07.119";
3
3
  /** Every public explanation.code (the relay's contract). A provider's own HTTP error is `http_<status>`. */
4
4
  export const PUBLIC_CODES = [
5
5
  "key_disabled", "key_stopped", "consent_missing", "data_consent_mismatch", "data_consent_needed", "notice_first",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flovialabs/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
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",