@chabi/js 0.1.0 → 0.2.0

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.2.0 (2026-11-29)
4
+
5
+ - `chabiAI(chabi, options?)` from `@chabi/js/ai`: the client for other makers' models (ids like `vendor/model`), chat and images. It's the official OpenAI client with Chabi's address and the user's token, so `openai` is now an optional peer dependency, needed only for `@chabi/js/ai`. Nothing else changes.
6
+
3
7
  ## 0.1.0 (2026-11-29)
4
8
 
5
9
  First release.
package/README.md CHANGED
@@ -68,6 +68,29 @@ const anthropic = new Anthropic({ ...chabi.anthropic(), dangerouslyAllowBrowser:
68
68
  | `signIn()` | Sends the user to Chabi to sign in and allow your app. They come back to `redirectUri`. |
69
69
  | `handleRedirect()` | Call on every page load. Resolves `true` if this load finished a sign-in, `false` otherwise. Throws a `ChabiError` if the sign-in failed (`kind` is `access_denied` when the user declined). It removes only the sign-in parameters from the address bar and keeps your app's own. |
70
70
 
71
+ ## Other makers' models: `chabiAI`
72
+
73
+ GPT stays on the OpenAI SDK and Claude on the Anthropic SDK. Every other maker's model (DeepSeek, Mistral, Llama, Qwen, xAI and the rest, ids like `vendor/model`) goes through `chabiAI`, from `@chabi/js/ai`:
74
+
75
+ ```js
76
+ import { chabiAI } from "@chabi/js/ai";
77
+
78
+ const ai = chabiAI(chabi);
79
+
80
+ const reply = await ai.chat.completions.create({
81
+ model: "deepseek/deepseek-v4-flash",
82
+ messages: [{ role: "user", content: "Write a haiku about keys." }],
83
+ max_tokens: 1024,
84
+ });
85
+
86
+ const image = await ai.images.generate({
87
+ model: "black-forest-labs/flux-3-image",
88
+ prompt: "A brass key on a gold circle, flat illustration",
89
+ });
90
+ ```
91
+
92
+ These models speak OpenAI's API, the common format for many models behind one address, so `chabiAI` returns the official OpenAI client with Chabi's address and the user's token: streaming, tools and types work as its docs say. It needs `openai` installed (`npm install openai`). Pass any OpenAI client option except `baseURL`, `apiKey` and `fetch`, such as `chabiAI(chabi, { maxRetries: 0 })`. In a browser it's allowed without `dangerouslyAllowBrowser`. The full list of models is at [chabi.dev/docs/models](https://chabi.dev/docs/models).
93
+
71
94
  ## In Node and Electron
72
95
 
73
96
  Sign-in opens the system browser and comes back to a loopback address on this machine. Register `http://127.0.0.1/callback` as a redirect URI; any port works.
@@ -111,7 +134,7 @@ const openai = new OpenAI(chabi.openai());
111
134
 
112
135
  | | |
113
136
  |---|---|
114
- | `openai()` | Options for `new OpenAI(...)`: Chabi's URL, a placeholder key, and `fetch`. |
137
+ | `openai()` | Options for `new OpenAI(...)`: Chabi's URL, a placeholder key, and `fetch`. `chabiAI(chabi)` from `@chabi/js/ai` makes that client for you. |
115
138
  | `anthropic()` | The same for `new Anthropic(...)`. |
116
139
  | `fetch` | A `fetch` that adds the user's token to requests to Chabi, refreshing it when needed. Requests to any other address go out untouched, with no token. |
117
140
  | `signedIn` | Whether a user is signed in. |
package/dist/ai.cjs ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/ai.ts
31
+ var ai_exports = {};
32
+ __export(ai_exports, {
33
+ chabiAI: () => chabiAI
34
+ });
35
+ module.exports = __toCommonJS(ai_exports);
36
+ var import_openai = __toESM(require("openai"), 1);
37
+ function chabiAI(chabi, options = {}) {
38
+ return new import_openai.default({
39
+ // The token only spends this user's credits in this app, so it's safe in a browser.
40
+ dangerouslyAllowBrowser: typeof window !== "undefined" && typeof window.document !== "undefined",
41
+ ...options,
42
+ ...chabi.openai()
43
+ });
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ chabiAI
48
+ });
49
+ //# sourceMappingURL=ai.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ai.ts"],"sourcesContent":["// The client for every other maker's models (DeepSeek, Mistral, Llama, Qwen, xAI and the rest, ids like\n// \"vendor/model\"), chat and images. They speak OpenAI's API, the common format for many models behind one address,\n// so this is the official OpenAI SDK with Chabi's address and the signed-in user's token: streaming, tools and types\n// work as documented. OpenAI's own models are just as happy here, but apps usually keep them on\n// `new OpenAI(chabi.openai())`; Claude models are served on /v1/messages, through `new Anthropic(chabi.anthropic())`.\nimport OpenAI, { type ClientOptions } from \"openai\";\nimport type { ChabiBase } from \"./client.js\";\n\n/** OpenAI client options an app may set. Chabi's address, the key and fetch always come from the signed-in user. */\nexport type ChabiAIOptions = Omit<ClientOptions, \"baseURL\" | \"apiKey\" | \"fetch\">;\n\n/** The client that `chabiAI` returns: the official OpenAI client. */\nexport type ChabiAI = OpenAI;\n\n/**\n * A client for other makers' models on Chabi: `ai.chat.completions.create` and `ai.images.generate` with ids like\n * \"deepseek/deepseek-v4-flash\". Needs the `openai` package installed.\n */\nexport function chabiAI(chabi: Pick<ChabiBase, \"openai\">, options: ChabiAIOptions = {}): ChabiAI {\n return new OpenAI({\n // The token only spends this user's credits in this app, so it's safe in a browser.\n dangerouslyAllowBrowser: typeof window !== \"undefined\" && typeof window.document !== \"undefined\",\n ...options,\n ...chabi.openai(),\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAA2C;AAapC,SAAS,QAAQ,OAAkC,UAA0B,CAAC,GAAY;AAC/F,SAAO,IAAI,cAAAA,QAAO;AAAA;AAAA,IAEhB,yBAAyB,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAAA,IACrF,GAAG;AAAA,IACH,GAAG,MAAM,OAAO;AAAA,EAClB,CAAC;AACH;","names":["OpenAI"]}
package/dist/ai.d.cts ADDED
@@ -0,0 +1,15 @@
1
+ import OpenAI, { ClientOptions } from 'openai';
2
+ import { ChabiBase } from './browser.cjs';
3
+
4
+ /** OpenAI client options an app may set. Chabi's address, the key and fetch always come from the signed-in user. */
5
+ type ChabiAIOptions = Omit<ClientOptions, "baseURL" | "apiKey" | "fetch">;
6
+ /** The client that `chabiAI` returns: the official OpenAI client. */
7
+ type ChabiAI = OpenAI;
8
+ /**
9
+ * A client for other makers' models on Chabi: `ai.chat.completions.create` and `ai.images.generate` with ids like
10
+ * "deepseek/deepseek-v4-flash". Needs the `openai` package installed.
11
+ */
12
+ declare function chabiAI(chabi: Pick<ChabiBase, "openai">, options?: ChabiAIOptions): ChabiAI;
13
+
14
+ export { chabiAI };
15
+ export type { ChabiAI, ChabiAIOptions };
package/dist/ai.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import OpenAI, { ClientOptions } from 'openai';
2
+ import { ChabiBase } from './browser.js';
3
+
4
+ /** OpenAI client options an app may set. Chabi's address, the key and fetch always come from the signed-in user. */
5
+ type ChabiAIOptions = Omit<ClientOptions, "baseURL" | "apiKey" | "fetch">;
6
+ /** The client that `chabiAI` returns: the official OpenAI client. */
7
+ type ChabiAI = OpenAI;
8
+ /**
9
+ * A client for other makers' models on Chabi: `ai.chat.completions.create` and `ai.images.generate` with ids like
10
+ * "deepseek/deepseek-v4-flash". Needs the `openai` package installed.
11
+ */
12
+ declare function chabiAI(chabi: Pick<ChabiBase, "openai">, options?: ChabiAIOptions): ChabiAI;
13
+
14
+ export { chabiAI };
15
+ export type { ChabiAI, ChabiAIOptions };
package/dist/ai.js ADDED
@@ -0,0 +1,14 @@
1
+ // src/ai.ts
2
+ import OpenAI from "openai";
3
+ function chabiAI(chabi, options = {}) {
4
+ return new OpenAI({
5
+ // The token only spends this user's credits in this app, so it's safe in a browser.
6
+ dangerouslyAllowBrowser: typeof window !== "undefined" && typeof window.document !== "undefined",
7
+ ...options,
8
+ ...chabi.openai()
9
+ });
10
+ }
11
+ export {
12
+ chabiAI
13
+ };
14
+ //# sourceMappingURL=ai.js.map
package/dist/ai.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ai.ts"],"sourcesContent":["// The client for every other maker's models (DeepSeek, Mistral, Llama, Qwen, xAI and the rest, ids like\n// \"vendor/model\"), chat and images. They speak OpenAI's API, the common format for many models behind one address,\n// so this is the official OpenAI SDK with Chabi's address and the signed-in user's token: streaming, tools and types\n// work as documented. OpenAI's own models are just as happy here, but apps usually keep them on\n// `new OpenAI(chabi.openai())`; Claude models are served on /v1/messages, through `new Anthropic(chabi.anthropic())`.\nimport OpenAI, { type ClientOptions } from \"openai\";\nimport type { ChabiBase } from \"./client.js\";\n\n/** OpenAI client options an app may set. Chabi's address, the key and fetch always come from the signed-in user. */\nexport type ChabiAIOptions = Omit<ClientOptions, \"baseURL\" | \"apiKey\" | \"fetch\">;\n\n/** The client that `chabiAI` returns: the official OpenAI client. */\nexport type ChabiAI = OpenAI;\n\n/**\n * A client for other makers' models on Chabi: `ai.chat.completions.create` and `ai.images.generate` with ids like\n * \"deepseek/deepseek-v4-flash\". Needs the `openai` package installed.\n */\nexport function chabiAI(chabi: Pick<ChabiBase, \"openai\">, options: ChabiAIOptions = {}): ChabiAI {\n return new OpenAI({\n // The token only spends this user's credits in this app, so it's safe in a browser.\n dangerouslyAllowBrowser: typeof window !== \"undefined\" && typeof window.document !== \"undefined\",\n ...options,\n ...chabi.openai(),\n });\n}\n"],"mappings":";AAKA,OAAO,YAAoC;AAapC,SAAS,QAAQ,OAAkC,UAA0B,CAAC,GAAY;AAC/F,SAAO,IAAI,OAAO;AAAA;AAAA,IAEhB,yBAAyB,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAAA,IACrF,GAAG;AAAA,IACH,GAAG,MAAM,OAAO;AAAA,EAClB,CAAC;AACH;","names":[]}
@@ -1,5 +1,6 @@
1
- import { T as TokenStorage, R as RefreshLock, C as ChabiBase } from './errors-CfeLVOW7.cjs';
2
- export { a as ChabiError, b as ChabiErrorInfo, c as ChangeListener, d as ChangeReason, E as ErrorKind, e as Tokens, f as describeError, g as describeResponse } from './errors-CfeLVOW7.cjs';
1
+ import { T as TokenStorage, R as RefreshLock, C as ChabiBase } from './client-X74kWdDv.cjs';
2
+ export { a as ChabiErrorInfo, b as ChangeListener, c as ChangeReason, E as ErrorKind, d as Tokens } from './client-X74kWdDv.cjs';
3
+ export { C as ChabiError, d as describeError, a as describeResponse } from './errors-DcA-sSRY.cjs';
3
4
 
4
5
  /** The Sign in with Chabi button, gold (default) or dark. Attach your own click handler that calls `chabi.signIn()`. */
5
6
  declare function signInButton(opts?: {
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { T as TokenStorage, R as RefreshLock, C as ChabiBase } from './errors-CfeLVOW7.js';
2
- export { a as ChabiError, b as ChabiErrorInfo, c as ChangeListener, d as ChangeReason, E as ErrorKind, e as Tokens, f as describeError, g as describeResponse } from './errors-CfeLVOW7.js';
1
+ import { T as TokenStorage, R as RefreshLock, C as ChabiBase } from './client-X74kWdDv.js';
2
+ export { a as ChabiErrorInfo, b as ChangeListener, c as ChangeReason, E as ErrorKind, d as Tokens } from './client-X74kWdDv.js';
3
+ export { C as ChabiError, d as describeError, a as describeResponse } from './errors-BD8FIApC.js';
3
4
 
4
5
  /** The Sign in with Chabi button, gold (default) or dark. Attach your own click handler that calls `chabi.signIn()`. */
5
6
  declare function signInButton(opts?: {
@@ -115,18 +115,5 @@ declare class ChabiBase {
115
115
  private send;
116
116
  }
117
117
 
118
- /** An error the SDK raises itself. `info` is what `describeError` returns for it. */
119
- declare class ChabiError extends Error {
120
- readonly info: ChabiErrorInfo;
121
- constructor(info: ChabiErrorInfo);
122
- }
123
- /**
124
- * Any error from a Chabi request in one shape: an OpenAI or Anthropic SDK error, a ChabiError, a failed fetch.
125
- * For a `Response` you got from `chabi.fetch` yourself, use `describeResponse`.
126
- */
127
- declare function describeError(e: unknown): ChabiErrorInfo;
128
- /** `describeError` for a `Response`, such as one from `chabi.fetch` that wasn't ok. */
129
- declare function describeResponse(res: Response): Promise<ChabiErrorInfo>;
130
-
131
- export { ChabiBase as C, ChabiError as a, describeError as f, describeResponse as g };
132
- export type { ErrorKind as E, RefreshLock as R, TokenStorage as T, ChabiErrorInfo as b, ChangeListener as c, ChangeReason as d, Tokens as e };
118
+ export { ChabiBase as C };
119
+ export type { ErrorKind as E, RefreshLock as R, TokenStorage as T, ChabiErrorInfo as a, ChangeListener as b, ChangeReason as c, Tokens as d };
@@ -115,18 +115,5 @@ declare class ChabiBase {
115
115
  private send;
116
116
  }
117
117
 
118
- /** An error the SDK raises itself. `info` is what `describeError` returns for it. */
119
- declare class ChabiError extends Error {
120
- readonly info: ChabiErrorInfo;
121
- constructor(info: ChabiErrorInfo);
122
- }
123
- /**
124
- * Any error from a Chabi request in one shape: an OpenAI or Anthropic SDK error, a ChabiError, a failed fetch.
125
- * For a `Response` you got from `chabi.fetch` yourself, use `describeResponse`.
126
- */
127
- declare function describeError(e: unknown): ChabiErrorInfo;
128
- /** `describeError` for a `Response`, such as one from `chabi.fetch` that wasn't ok. */
129
- declare function describeResponse(res: Response): Promise<ChabiErrorInfo>;
130
-
131
- export { ChabiBase as C, ChabiError as a, describeError as f, describeResponse as g };
132
- export type { ErrorKind as E, RefreshLock as R, TokenStorage as T, ChabiErrorInfo as b, ChangeListener as c, ChangeReason as d, Tokens as e };
118
+ export { ChabiBase as C };
119
+ export type { ErrorKind as E, RefreshLock as R, TokenStorage as T, ChabiErrorInfo as a, ChangeListener as b, ChangeReason as c, Tokens as d };
@@ -0,0 +1,16 @@
1
+ import { a as ChabiErrorInfo } from './client-X74kWdDv.js';
2
+
3
+ /** An error the SDK raises itself. `info` is what `describeError` returns for it. */
4
+ declare class ChabiError extends Error {
5
+ readonly info: ChabiErrorInfo;
6
+ constructor(info: ChabiErrorInfo);
7
+ }
8
+ /**
9
+ * Any error from a Chabi request in one shape: an OpenAI or Anthropic SDK error, a ChabiError, a failed fetch.
10
+ * For a `Response` you got from `chabi.fetch` yourself, use `describeResponse`.
11
+ */
12
+ declare function describeError(e: unknown): ChabiErrorInfo;
13
+ /** `describeError` for a `Response`, such as one from `chabi.fetch` that wasn't ok. */
14
+ declare function describeResponse(res: Response): Promise<ChabiErrorInfo>;
15
+
16
+ export { ChabiError as C, describeResponse as a, describeError as d };
@@ -0,0 +1,16 @@
1
+ import { a as ChabiErrorInfo } from './client-X74kWdDv.cjs';
2
+
3
+ /** An error the SDK raises itself. `info` is what `describeError` returns for it. */
4
+ declare class ChabiError extends Error {
5
+ readonly info: ChabiErrorInfo;
6
+ constructor(info: ChabiErrorInfo);
7
+ }
8
+ /**
9
+ * Any error from a Chabi request in one shape: an OpenAI or Anthropic SDK error, a ChabiError, a failed fetch.
10
+ * For a `Response` you got from `chabi.fetch` yourself, use `describeResponse`.
11
+ */
12
+ declare function describeError(e: unknown): ChabiErrorInfo;
13
+ /** `describeError` for a `Response`, such as one from `chabi.fetch` that wasn't ok. */
14
+ declare function describeResponse(res: Response): Promise<ChabiErrorInfo>;
15
+
16
+ export { ChabiError as C, describeResponse as a, describeError as d };
package/dist/node.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import { C as ChabiBase, T as TokenStorage, e as Tokens } from './errors-CfeLVOW7.cjs';
2
- export { a as ChabiError, b as ChabiErrorInfo, c as ChangeListener, d as ChangeReason, E as ErrorKind, R as RefreshLock, f as describeError, g as describeResponse } from './errors-CfeLVOW7.cjs';
1
+ import { C as ChabiBase, T as TokenStorage, d as Tokens } from './client-X74kWdDv.cjs';
2
+ export { a as ChabiErrorInfo, b as ChangeListener, c as ChangeReason, E as ErrorKind, R as RefreshLock } from './client-X74kWdDv.cjs';
3
+ export { C as ChabiError, d as describeError, a as describeResponse } from './errors-DcA-sSRY.cjs';
3
4
 
4
5
  /** What the browser tab shows once it has handed the sign-in back. */
5
6
  type Outcome = "signed_in" | "denied" | "failed";
package/dist/node.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { C as ChabiBase, T as TokenStorage, e as Tokens } from './errors-CfeLVOW7.js';
2
- export { a as ChabiError, b as ChabiErrorInfo, c as ChangeListener, d as ChangeReason, E as ErrorKind, R as RefreshLock, f as describeError, g as describeResponse } from './errors-CfeLVOW7.js';
1
+ import { C as ChabiBase, T as TokenStorage, d as Tokens } from './client-X74kWdDv.js';
2
+ export { a as ChabiErrorInfo, b as ChangeListener, c as ChangeReason, E as ErrorKind, R as RefreshLock } from './client-X74kWdDv.js';
3
+ export { C as ChabiError, d as describeError, a as describeResponse } from './errors-BD8FIApC.js';
3
4
 
4
5
  /** What the browser tab shows once it has handed the sign-in back. */
5
6
  type Outcome = "signed_in" | "denied" | "failed";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chabi/js",
3
- "version": "0.1.0",
4
- "description": "Sign in with Chabi: your users bring their own AI. Works with the official OpenAI and Anthropic SDKs.",
3
+ "version": "0.2.0",
4
+ "description": "Sign in with Chabi: your users bring their own AI. Works with the official OpenAI and Anthropic SDKs, and chabiAI gives you one client for Chabi's models.",
5
5
  "keywords": [
6
6
  "chabi",
7
7
  "sign in",
@@ -38,6 +38,16 @@
38
38
  "types": "./dist/node.d.cts",
39
39
  "default": "./dist/node.cjs"
40
40
  }
41
+ },
42
+ "./ai": {
43
+ "import": {
44
+ "types": "./dist/ai.d.ts",
45
+ "default": "./dist/ai.js"
46
+ },
47
+ "require": {
48
+ "types": "./dist/ai.d.cts",
49
+ "default": "./dist/ai.cjs"
50
+ }
41
51
  }
42
52
  },
43
53
  "main": "./dist/browser.cjs",
@@ -47,6 +57,14 @@
47
57
  "engines": {
48
58
  "node": ">=20"
49
59
  },
60
+ "peerDependencies": {
61
+ "openai": ">=7.0.0"
62
+ },
63
+ "peerDependenciesMeta": {
64
+ "openai": {
65
+ "optional": true
66
+ }
67
+ },
50
68
  "scripts": {
51
69
  "build": "tsup",
52
70
  "test": "vitest run",