@byokit/accounts 0.6.0 → 0.7.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
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.7.0 (2026-09-30)
6
+
7
+ - Add the portable `chatgptPlan` adapter for a host-validated official token-sharing session, checking
8
+ ChatGPT plan usage consent on every access. Uses subscription billing and never falls back to an API key
9
+ (billed per use); the host owns sign-in, identity verification, storage and refresh per person.
10
+
5
11
  ## 0.6.0 (2026-09-30)
6
12
 
7
13
  - `respond` and `Accounts.respond` accept `originator` (or set it once on `Accounts`): the app's own originator header value. Default: 'byokit', as before.
package/README.md CHANGED
@@ -276,3 +276,18 @@ tests and demos sign in and ask end to end with no account. Point the kit at it
276
276
  ## License
277
277
 
278
278
  Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](../../NOTICE).
279
+
280
+ ## Official ChatGPT plan token-sharing adapter
281
+
282
+ `chatgptPlan({ session })`, also exported from `@byokit/accounts/chatgpt-plan`, binds a single person's
283
+ validated [official token-sharing session](https://developers.openai.com/siwc/token-sharing-open-source) to a
284
+ consumer such as `@byokit/decide`. `session(signal)` returns `{ accessToken, scopes }` after the host's own
285
+ sign-in integration validates identity and refreshes tokens. The adapter checks `resource.invoke` and
286
+ `chatgpt.tokens.use.direct` on every access; missing consent throws `UnsupportedAccountError` with
287
+ `code: 'unsupported_account'`. Billing is `subscription`, with no API-key fallback.
288
+
289
+ The host follows [official registration/sign-in](https://developers.openai.com/siwc/token-sharing-open-source/sign-in),
290
+ including ID-token signature/issuer/audience/nonce verification and protected per-person storage. Plan usage is
291
+ available to eligible open-source/local apps; paid/remote apps require approval. This adapter does not start an
292
+ OAuth flow and does not convert the existing Codex `Accounts.login()` credential into a token-sharing session.
293
+ It reads no environment or files, and remains portable to browsers and React Native.
@@ -0,0 +1,21 @@
1
+ /** A host-owned, validated Sign in with ChatGPT token-sharing session. The host completes the official
2
+ * OAuth flow (including ID-token verification), stores it per person, and refreshes it before returning it.
3
+ * This adapter never discovers credentials, starts a login, or substitutes a Codex credential. */
4
+ export type ChatGPTPlanSession = {
5
+ accessToken: string;
6
+ scopes: readonly string[];
7
+ };
8
+ export type ChatGPTPlanAccount = {
9
+ readonly billing: 'subscription';
10
+ access(signal: AbortSignal): Promise<string>;
11
+ };
12
+ /** The selected account, consent or model cannot support this request. Never falls back to API billing. */
13
+ export declare class UnsupportedAccountError extends Error {
14
+ readonly code = "unsupported_account";
15
+ constructor(message: string);
16
+ }
17
+ /** Bind one person's official token-sharing session to this app. Eligibility and identity verification
18
+ * belong to the host's sign-in integration; granted plan-usage scopes are checked on every request. */
19
+ export declare function chatgptPlan(o: {
20
+ session(signal: AbortSignal): Promise<ChatGPTPlanSession>;
21
+ }): ChatGPTPlanAccount;
@@ -0,0 +1,20 @@
1
+ /** The selected account, consent or model cannot support this request. Never falls back to API billing. */
2
+ export class UnsupportedAccountError extends Error {
3
+ code = 'unsupported_account';
4
+ constructor(message) { super(message); this.name = 'UnsupportedAccountError'; }
5
+ }
6
+ /** Bind one person's official token-sharing session to this app. Eligibility and identity verification
7
+ * belong to the host's sign-in integration; granted plan-usage scopes are checked on every request. */
8
+ export function chatgptPlan(o) {
9
+ return {
10
+ billing: 'subscription',
11
+ async access(signal) {
12
+ const session = await o.session(signal);
13
+ if (!session || !Array.isArray(session.scopes) || !session.scopes.includes('chatgpt.tokens.use.direct') ||
14
+ !session.scopes.includes('resource.invoke') || typeof session.accessToken !== 'string' || !session.accessToken.trim()) {
15
+ throw new UnsupportedAccountError('ChatGPT plan usage needs a consented token-sharing session.');
16
+ }
17
+ return session.accessToken;
18
+ },
19
+ };
20
+ }
@@ -5,3 +5,4 @@ export { REST_MS, classify, type Kind } from './limits.ts';
5
5
  export { ResponseError, isFunctionCall, limitResponse, respond, sseReader, type Ask, type ResponseFunctionCall, type ResponseInputItem, type ResponseOutputItem, type ResponseOutputMessage, type ResponseReasoning, type ResponseResult, type ResponseStreamEvent, type ResponseText, type ResponseTextFormat, type ResponseTool, type ResponseToolChoice } from './responses.ts';
6
6
  export { browserStore, memoryStore, recordStore, secureStore, type SecureStoreLike } from './stores.ts';
7
7
  export { WORDS, billingWords, callbackPage, clock, failure, say, signInError, type WordKey, type Why } from './words.ts';
8
+ export { chatgptPlan, UnsupportedAccountError, type ChatGPTPlanAccount, type ChatGPTPlanSession } from './chatgpt-plan.ts';
package/dist/portable.js CHANGED
@@ -7,3 +7,4 @@ export { REST_MS, classify } from "./limits.js";
7
7
  export { ResponseError, isFunctionCall, limitResponse, respond, sseReader } from "./responses.js";
8
8
  export { browserStore, memoryStore, recordStore, secureStore } from "./stores.js";
9
9
  export { WORDS, billingWords, callbackPage, clock, failure, say, signInError } from "./words.js";
10
+ export { chatgptPlan, UnsupportedAccountError } from "./chatgpt-plan.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byokit/accounts",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Sign in with the AI plan you already pay for, into your app's own store.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -32,6 +32,10 @@
32
32
  "./testing": {
33
33
  "types": "./dist/testing/index.d.ts",
34
34
  "default": "./dist/testing/index.js"
35
+ },
36
+ "./chatgpt-plan": {
37
+ "types": "./dist/chatgpt-plan.d.ts",
38
+ "default": "./dist/chatgpt-plan.js"
35
39
  }
36
40
  },
37
41
  "files": [