@theokit/agents 4.2.2 → 4.3.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/dist/auth.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { OAuthProviderConfig, CredentialStoreConfig, ResolvedCredential, ensureFreshCredential, OpenAIDeviceConfig, openaiDeviceLogin, OAuthTokens } from '@theokit/sdk/auth';
2
+ export { CredentialStoreConfig, DeviceDeps, OAuthProviderConfig, OAuthTokens, OpenAIDeviceConfig, ResolvedCredential } from '@theokit/sdk/auth';
3
+
4
+ /**
5
+ * M60 — `AuthProvider`, the OO contract that unifies the SDK's free OAuth-lifecycle functions
6
+ * (`openaiDeviceLogin` → `persistOAuthTokens` → `ensureFreshCredential`). Those are stateful across a
7
+ * SHARED `config` (`OAuthProviderConfig`) + `store` (`CredentialStoreConfig`); this class holds that
8
+ * state so a consumer authors `new AuthProvider(config, store).persist(...)` / `.ensureFresh(...)`
9
+ * instead of threading `config`/`store` through every call — the `SDK → Theokit → AgentBuilder`
10
+ * boundary applied to the auth domain (ENRICH, per blueprint D2: auth carries orchestration + state).
11
+ *
12
+ * It DELEGATES, never reimplements (parsimony Rung 9): each method forwards verbatim to the SDK
13
+ * function, so login → persist → refresh produces byte-identical state to calling the SDK directly.
14
+ *
15
+ * SECRET-SAFETY (hard rule): this class NEVER logs, stringifies, or otherwise surfaces token material.
16
+ * Methods return exactly what the SDK returns and add no observability — a token is data that flows
17
+ * through, never something this layer emits. The parity/secret tests pin both properties.
18
+ */
19
+ /** The HTTP deps of `ensureFreshCredential` (`{ fetch, now }`) — typed off the SDK to avoid drift. */
20
+ type EnsureFreshHttpDeps = Parameters<typeof ensureFreshCredential>[2];
21
+ /** The device-flow deps + prompt hook of `openaiDeviceLogin` — typed off the SDK. */
22
+ type DeviceLoginDeps = Parameters<typeof openaiDeviceLogin>[1];
23
+ type DeviceLoginHooks = Parameters<typeof openaiDeviceLogin>[2];
24
+ declare class AuthProvider {
25
+ private readonly config;
26
+ private readonly store;
27
+ constructor(config: OAuthProviderConfig, store: CredentialStoreConfig);
28
+ /**
29
+ * Refresh a resolved credential if stale. Delegates to `ensureFreshCredential` with the held
30
+ * `config` + `store`; `env` (for reading the store's env overrides) + the `{ fetch, now }` HTTP deps
31
+ * thread through. Returns the fresh `ResolvedCredential` — never logs the rotated token.
32
+ */
33
+ ensureFresh(resolved: ResolvedCredential, opts: EnsureFreshHttpDeps & {
34
+ env?: Record<string, string | undefined>;
35
+ }): Promise<ResolvedCredential>;
36
+ /**
37
+ * Run the headless OpenAI device-login flow. Delegates to `openaiDeviceLogin` (which JWT-extracts the
38
+ * account id). `deviceConfig` is passed per-call because it is a distinct endpoint set from the
39
+ * refresh `config`. Returns `OAuthTokens` — the caller persists them via {@link AuthProvider.persist}.
40
+ */
41
+ deviceLogin(deviceConfig: OpenAIDeviceConfig, deps: DeviceLoginDeps, hooks: DeviceLoginHooks): Promise<OAuthTokens>;
42
+ /**
43
+ * Persist freshly-obtained tokens through the held `store`. Delegates to `persistOAuthTokens` and
44
+ * returns the credential-file path (never the token). `env` selects the store's home override.
45
+ */
46
+ persist(provider: string, tokens: OAuthTokens, env?: Record<string, string | undefined>): string;
47
+ }
48
+
49
+ export { AuthProvider };
package/dist/auth.js ADDED
@@ -0,0 +1,49 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-7QVYU63E.js";
4
+
5
+ // src/auth/auth-provider.ts
6
+ import { ensureFreshCredential, openaiDeviceLogin, persistOAuthTokens } from "@theokit/sdk/auth";
7
+ var AuthProvider = class {
8
+ static {
9
+ __name(this, "AuthProvider");
10
+ }
11
+ config;
12
+ store;
13
+ constructor(config, store) {
14
+ this.config = config;
15
+ this.store = store;
16
+ }
17
+ /**
18
+ * Refresh a resolved credential if stale. Delegates to `ensureFreshCredential` with the held
19
+ * `config` + `store`; `env` (for reading the store's env overrides) + the `{ fetch, now }` HTTP deps
20
+ * thread through. Returns the fresh `ResolvedCredential` — never logs the rotated token.
21
+ */
22
+ ensureFresh(resolved, opts) {
23
+ const { env, ...http } = opts;
24
+ return ensureFreshCredential(resolved, {
25
+ config: this.config,
26
+ store: this.store,
27
+ env
28
+ }, http);
29
+ }
30
+ /**
31
+ * Run the headless OpenAI device-login flow. Delegates to `openaiDeviceLogin` (which JWT-extracts the
32
+ * account id). `deviceConfig` is passed per-call because it is a distinct endpoint set from the
33
+ * refresh `config`. Returns `OAuthTokens` — the caller persists them via {@link AuthProvider.persist}.
34
+ */
35
+ deviceLogin(deviceConfig, deps, hooks) {
36
+ return openaiDeviceLogin(deviceConfig, deps, hooks);
37
+ }
38
+ /**
39
+ * Persist freshly-obtained tokens through the held `store`. Delegates to `persistOAuthTokens` and
40
+ * returns the credential-file path (never the token). `env` selects the store's home override.
41
+ */
42
+ persist(provider, tokens, env) {
43
+ return persistOAuthTokens(provider, tokens, this.store, env);
44
+ }
45
+ };
46
+ export {
47
+ AuthProvider
48
+ };
49
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth/auth-provider.ts"],"sourcesContent":["import {\n ensureFreshCredential,\n openaiDeviceLogin,\n persistOAuthTokens,\n} from '@theokit/sdk/auth'\nimport type {\n CredentialStoreConfig,\n OAuthProviderConfig,\n OAuthTokens,\n OpenAIDeviceConfig,\n ResolvedCredential,\n} from '@theokit/sdk/auth'\n\n/**\n * M60 — `AuthProvider`, the OO contract that unifies the SDK's free OAuth-lifecycle functions\n * (`openaiDeviceLogin` → `persistOAuthTokens` → `ensureFreshCredential`). Those are stateful across a\n * SHARED `config` (`OAuthProviderConfig`) + `store` (`CredentialStoreConfig`); this class holds that\n * state so a consumer authors `new AuthProvider(config, store).persist(...)` / `.ensureFresh(...)`\n * instead of threading `config`/`store` through every call — the `SDK → Theokit → AgentBuilder`\n * boundary applied to the auth domain (ENRICH, per blueprint D2: auth carries orchestration + state).\n *\n * It DELEGATES, never reimplements (parsimony Rung 9): each method forwards verbatim to the SDK\n * function, so login → persist → refresh produces byte-identical state to calling the SDK directly.\n *\n * SECRET-SAFETY (hard rule): this class NEVER logs, stringifies, or otherwise surfaces token material.\n * Methods return exactly what the SDK returns and add no observability — a token is data that flows\n * through, never something this layer emits. The parity/secret tests pin both properties.\n */\n\n/** The HTTP deps of `ensureFreshCredential` (`{ fetch, now }`) — typed off the SDK to avoid drift. */\ntype EnsureFreshHttpDeps = Parameters<typeof ensureFreshCredential>[2]\n/** The device-flow deps + prompt hook of `openaiDeviceLogin` — typed off the SDK. */\ntype DeviceLoginDeps = Parameters<typeof openaiDeviceLogin>[1]\ntype DeviceLoginHooks = Parameters<typeof openaiDeviceLogin>[2]\n\nexport class AuthProvider {\n constructor(\n private readonly config: OAuthProviderConfig,\n private readonly store: CredentialStoreConfig,\n ) {}\n\n /**\n * Refresh a resolved credential if stale. Delegates to `ensureFreshCredential` with the held\n * `config` + `store`; `env` (for reading the store's env overrides) + the `{ fetch, now }` HTTP deps\n * thread through. Returns the fresh `ResolvedCredential` — never logs the rotated token.\n */\n ensureFresh(\n resolved: ResolvedCredential,\n opts: EnsureFreshHttpDeps & { env?: Record<string, string | undefined> },\n ): Promise<ResolvedCredential> {\n const { env, ...http } = opts\n return ensureFreshCredential(resolved, { config: this.config, store: this.store, env }, http)\n }\n\n /**\n * Run the headless OpenAI device-login flow. Delegates to `openaiDeviceLogin` (which JWT-extracts the\n * account id). `deviceConfig` is passed per-call because it is a distinct endpoint set from the\n * refresh `config`. Returns `OAuthTokens` — the caller persists them via {@link AuthProvider.persist}.\n */\n deviceLogin(\n deviceConfig: OpenAIDeviceConfig,\n deps: DeviceLoginDeps,\n hooks: DeviceLoginHooks,\n ): Promise<OAuthTokens> {\n return openaiDeviceLogin(deviceConfig, deps, hooks)\n }\n\n /**\n * Persist freshly-obtained tokens through the held `store`. Delegates to `persistOAuthTokens` and\n * returns the credential-file path (never the token). `env` selects the store's home override.\n */\n persist(\n provider: string,\n tokens: OAuthTokens,\n env?: Record<string, string | undefined>,\n ): string {\n return persistOAuthTokens(provider, tokens, this.store, env)\n }\n}\n"],"mappings":";;;;;AAAA,SACEA,uBACAC,mBACAC,0BACK;AA+BA,IAAMC,eAAN,MAAMA;EAnCb,OAmCaA;;;;;EACX,YACmBC,QACAC,OACjB;SAFiBD,SAAAA;SACAC,QAAAA;EAChB;;;;;;EAOHC,YACEC,UACAC,MAC6B;AAC7B,UAAM,EAAEC,KAAK,GAAGC,KAAAA,IAASF;AACzB,WAAOG,sBAAsBJ,UAAU;MAAEH,QAAQ,KAAKA;MAAQC,OAAO,KAAKA;MAAOI;IAAI,GAAGC,IAAAA;EAC1F;;;;;;EAOAE,YACEC,cACAC,MACAC,OACsB;AACtB,WAAOC,kBAAkBH,cAAcC,MAAMC,KAAAA;EAC/C;;;;;EAMAE,QACEC,UACAC,QACAV,KACQ;AACR,WAAOW,mBAAmBF,UAAUC,QAAQ,KAAKd,OAAOI,GAAAA;EAC1D;AACF;","names":["ensureFreshCredential","openaiDeviceLogin","persistOAuthTokens","AuthProvider","config","store","ensureFresh","resolved","opts","env","http","ensureFreshCredential","deviceLogin","deviceConfig","deps","hooks","openaiDeviceLogin","persist","provider","tokens","persistOAuthTokens"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theokit/agents",
3
- "version": "4.2.2",
3
+ "version": "4.3.0",
4
4
  "description": "AI agents as first-class citizens of the TheoKit pipeline. The fluent agent()/tool() builders compile to SDK Agent.create() (M31 builder-only authoring API).",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -34,6 +34,10 @@
34
34
  "./pty": {
35
35
  "types": "./dist/pty.d.ts",
36
36
  "import": "./dist/pty.js"
37
+ },
38
+ "./auth": {
39
+ "types": "./dist/auth.d.ts",
40
+ "import": "./dist/auth.js"
37
41
  }
38
42
  },
39
43
  "files": [
@@ -69,8 +73,8 @@
69
73
  "typescript": "^5.9.3",
70
74
  "vitest": "^3.2.6",
71
75
  "zod": "^4.4.3",
72
- "@theokit/http": "1.0.0",
73
- "@theokit/presenter": "0.3.0"
76
+ "@theokit/presenter": "0.3.0",
77
+ "@theokit/http": "1.0.0"
74
78
  },
75
79
  "engines": {
76
80
  "node": ">=22.12.0"