frutebox 0.0.0-stage → 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Frutebox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,54 @@
1
- # Temporary Holding Version
1
+ # frutebox
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The official [Frutebox](https://frutebox.com) SDK for JavaScript and TypeScript — call the Frutebox
4
+ network with no third-party AI library. Zero dependencies.
5
+
6
+ ```bash
7
+ npm install frutebox
8
+ ```
9
+
10
+ ```js
11
+ import { Frutebox } from "frutebox";
12
+
13
+ const frutebox = new Frutebox({ apiKey: process.env.FRUTEBOX_API_KEY });
14
+
15
+ const res = await frutebox.chat({ message: "Say hello in five words." });
16
+ console.log(res.reply);
17
+ console.log(res.usage); // tokens, compute time, and what it cost
18
+ ```
19
+
20
+ TypeScript types ship with the package. HTTPS is enforced, so your key is never sent in plaintext.
21
+
22
+ - Get an API key: <https://frutebox.com/app/keys>
23
+ - Documentation: <https://frutebox.com/docs>
24
+
25
+ `FRUTEBOX_API_KEY` is read from the environment when no `apiKey` is passed. The older
26
+ `STEVAI_API_KEY` is still accepted so existing environments keep working.
27
+
28
+ ## Errors
29
+
30
+ Every failure throws a `FruteboxError` carrying the HTTP `status` and, where the API supplies one,
31
+ a `code`.
32
+
33
+ ```js
34
+ import { Frutebox, FruteboxError } from "frutebox";
35
+
36
+ try {
37
+ await frutebox.chat({ message: "..." });
38
+ } catch (err) {
39
+ if (err instanceof FruteboxError) console.error(err.status, err.code, err.message);
40
+ }
41
+ ```
42
+
43
+ ## Status
44
+
45
+ **0.0.1 is an early release.** It covers `chat` and `models` against the native Frutebox endpoint,
46
+ and requires Node 18 or newer (it uses the built-in `fetch`). A fully typed client generated from
47
+ the published API specification is planned, and the surface may change before 1.0.
48
+
49
+ This package talks to the native endpoint. The OpenAI-shaped compatibility surface is a separate
50
+ migration path that is being phased out — see the documentation if you are moving an existing app.
51
+
52
+ ## Licence
53
+
54
+ MIT — see [LICENSE](LICENSE).
package/index.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ export declare class FruteboxError extends Error {
2
+ readonly name: "FruteboxError";
3
+ readonly status: number;
4
+ readonly code?: string;
5
+ constructor(message: string, status?: number, code?: string);
6
+ }
7
+
8
+ export interface FruteboxOptions {
9
+ /** Your Frutebox API key. Falls back to FRUTEBOX_API_KEY (then STEVAI_API_KEY). */
10
+ apiKey?: string;
11
+ /** Defaults to https://frutebox.com. Must be https:// unless it is localhost. */
12
+ baseUrl?: string;
13
+ /** Request timeout in milliseconds. Defaults to 60000. */
14
+ timeoutMs?: number;
15
+ }
16
+
17
+ export interface ChatUsage {
18
+ tokens: number;
19
+ computeMs: number;
20
+ nodes: number;
21
+ electricityCost: number;
22
+ internetCost: number;
23
+ cost: number;
24
+ currency: string;
25
+ }
26
+
27
+ export interface ChatResult {
28
+ reply: string;
29
+ model: string;
30
+ region: string;
31
+ usage: ChatUsage;
32
+ }
33
+
34
+ export interface ChatRequest {
35
+ /** The message to send. 1–8000 characters. */
36
+ message: string;
37
+ /** Optional region to pin this request to. */
38
+ region?: string;
39
+ }
40
+
41
+ export declare class Frutebox {
42
+ readonly baseUrl: string;
43
+ constructor(options?: FruteboxOptions);
44
+ chat(request: ChatRequest): Promise<ChatResult>;
45
+ models(): Promise<unknown>;
46
+ }
47
+
48
+ export default Frutebox;
package/index.mjs ADDED
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Official Frutebox SDK for JavaScript and TypeScript.
3
+ *
4
+ * Built against the NATIVE endpoint (`POST /api/v1/chat`) rather than the OpenAI-shaped
5
+ * compatibility surface at `/api/v1/chat/completions`. The compatibility surface is being phased
6
+ * out, so a new client should not be born on it.
7
+ *
8
+ * Zero dependencies: `fetch` is built into Node 18+.
9
+ */
10
+
11
+ export class FruteboxError extends Error {
12
+ constructor(message, status = 0, code = undefined) {
13
+ super(message);
14
+ this.name = "FruteboxError";
15
+ this.status = status;
16
+ this.code = code;
17
+ }
18
+ }
19
+
20
+ export class Frutebox {
21
+ constructor({ apiKey, baseUrl = "https://frutebox.com", timeoutMs = 60000 } = {}) {
22
+ // Accept the environment as a fallback, new spelling first. STEVAI_API_KEY is still read so
23
+ // existing environments keep working.
24
+ const key = apiKey
25
+ || (typeof process !== "undefined" && process.env
26
+ ? (process.env.FRUTEBOX_API_KEY || process.env.STEVAI_API_KEY)
27
+ : undefined);
28
+ if (!key) {
29
+ throw new FruteboxError("A Frutebox API key is required.", 0, "missing_api_key");
30
+ }
31
+
32
+ const base = String(baseUrl).replace(/\/+$/, "");
33
+ // Enforce HTTPS so the key is never sent in plaintext; localhost is exempt for development.
34
+ const isLocal = base.startsWith("http://localhost") || base.startsWith("http://127.0.0.1");
35
+ if (!base.startsWith("https://") && !isLocal) {
36
+ throw new FruteboxError(
37
+ "baseUrl must use https:// (refusing to send your key in plaintext).",
38
+ 0,
39
+ "insecure_base_url",
40
+ );
41
+ }
42
+
43
+ this.baseUrl = base;
44
+ this.#apiKey = key;
45
+ this.#timeoutMs = timeoutMs;
46
+ }
47
+
48
+ #apiKey;
49
+ #timeoutMs;
50
+
51
+ /**
52
+ * Send one message to the Frutebox network and get the reply.
53
+ * Returns { reply, model, region, usage }.
54
+ */
55
+ async chat({ message, region } = {}) {
56
+ if (typeof message !== "string" || message.length === 0) {
57
+ throw new FruteboxError("`message` must be a non-empty string.", 0, "invalid_request");
58
+ }
59
+
60
+ const body = { message };
61
+ if (region) body.region = region;
62
+
63
+ const controller = new AbortController();
64
+ const timer = setTimeout(() => controller.abort(), this.#timeoutMs);
65
+ let res;
66
+ try {
67
+ res = await fetch(`${this.baseUrl}/api/v1/chat`, {
68
+ method: "POST",
69
+ headers: {
70
+ "content-type": "application/json",
71
+ authorization: `Bearer ${this.#apiKey}`,
72
+ },
73
+ body: JSON.stringify(body),
74
+ signal: controller.signal,
75
+ });
76
+ } catch (err) {
77
+ if (err && err.name === "AbortError") {
78
+ throw new FruteboxError(`Frutebox request timed out after ${this.#timeoutMs}ms.`, 0, "timeout");
79
+ }
80
+ throw new FruteboxError(`Frutebox request failed: ${err && err.message ? err.message : err}`, 0, "network");
81
+ } finally {
82
+ clearTimeout(timer);
83
+ }
84
+
85
+ if (!res.ok) throw await toError(res);
86
+ return res.json();
87
+ }
88
+
89
+ /** List the models available to your key. */
90
+ async models() {
91
+ const res = await fetch(`${this.baseUrl}/api/v1/models`, {
92
+ headers: { authorization: `Bearer ${this.#apiKey}` },
93
+ });
94
+ if (!res.ok) throw await toError(res);
95
+ return res.json();
96
+ }
97
+ }
98
+
99
+ async function toError(res) {
100
+ let message = `Frutebox request failed (${res.status}).`;
101
+ let code;
102
+ try {
103
+ const body = await res.json();
104
+ if (typeof body?.error === "string") message = body.error;
105
+ else if (body?.error?.message) {
106
+ message = body.error.message;
107
+ code = body.error.code;
108
+ }
109
+ if (!code && typeof body?.code === "string") code = body.code;
110
+ } catch {
111
+ // A non-JSON error body leaves the status-derived message in place.
112
+ }
113
+ return new FruteboxError(message, res.status, code);
114
+ }
115
+
116
+ export default Frutebox;
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "frutebox",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "description": "Official Frutebox SDK — call the Frutebox network from JavaScript and TypeScript. No third-party AI SDK required.",
5
+ "type": "module",
6
+ "main": "./index.mjs",
7
+ "module": "./index.mjs",
8
+ "types": "./index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "import": "./index.mjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "index.mjs",
17
+ "index.d.ts",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "keywords": [
22
+ "frutebox",
23
+ "ai",
24
+ "llm",
25
+ "assistant",
26
+ "sdk"
27
+ ],
28
+ "homepage": "https://frutebox.com",
29
+ "license": "MIT",
30
+ "author": "Frutebox",
31
+ "engines": {
32
+ "node": ">=18"
33
+ }
34
+ }