funolio-agent 1.0.4 → 1.0.6

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.
Files changed (50) hide show
  1. package/dist/auth/anthropic-subscription.d.ts +29 -9
  2. package/dist/auth/anthropic-subscription.d.ts.map +1 -1
  3. package/dist/auth/anthropic-subscription.js +133 -12
  4. package/dist/auth/anthropic-subscription.js.map +1 -1
  5. package/dist/auth/auto-detect.d.ts +6 -28
  6. package/dist/auth/auto-detect.d.ts.map +1 -1
  7. package/dist/auth/auto-detect.js +200 -57
  8. package/dist/auth/auto-detect.js.map +1 -1
  9. package/dist/auth/credential-reader.d.ts +4 -24
  10. package/dist/auth/credential-reader.d.ts.map +1 -1
  11. package/dist/auth/credential-reader.js +256 -31
  12. package/dist/auth/credential-reader.js.map +1 -1
  13. package/dist/auth/credential-status.d.ts +27 -7
  14. package/dist/auth/credential-status.d.ts.map +1 -1
  15. package/dist/auth/credential-status.js +95 -7
  16. package/dist/auth/credential-status.js.map +1 -1
  17. package/dist/auth/index.d.ts +2 -9
  18. package/dist/auth/index.d.ts.map +1 -1
  19. package/dist/auth/index.js +10 -10
  20. package/dist/auth/index.js.map +1 -1
  21. package/dist/auth/subscription-runtime.d.ts +23 -19
  22. package/dist/auth/subscription-runtime.d.ts.map +1 -1
  23. package/dist/auth/subscription-runtime.js +292 -24
  24. package/dist/auth/subscription-runtime.js.map +1 -1
  25. package/dist/auth/token-refresh.d.ts +28 -19
  26. package/dist/auth/token-refresh.d.ts.map +1 -1
  27. package/dist/auth/token-refresh.js +464 -26
  28. package/dist/auth/token-refresh.js.map +1 -1
  29. package/dist/bot-manager.d.ts +6 -6
  30. package/dist/bot-manager.d.ts.map +1 -1
  31. package/dist/bot-manager.js +61 -26
  32. package/dist/bot-manager.js.map +1 -1
  33. package/dist/commands/start.d.ts.map +1 -1
  34. package/dist/commands/start.js +223 -49
  35. package/dist/commands/start.js.map +1 -1
  36. package/dist/message-loop.d.ts +10 -2
  37. package/dist/message-loop.d.ts.map +1 -1
  38. package/dist/message-loop.js +249 -184
  39. package/dist/message-loop.js.map +1 -1
  40. package/dist/providers/anthropic.d.ts +5 -0
  41. package/dist/providers/anthropic.d.ts.map +1 -1
  42. package/dist/providers/anthropic.js +48 -13
  43. package/dist/providers/anthropic.js.map +1 -1
  44. package/dist/providers/index.d.ts +2 -2
  45. package/dist/providers/index.d.ts.map +1 -1
  46. package/dist/wizard-support.d.ts +2 -2
  47. package/dist/wizard-support.d.ts.map +1 -1
  48. package/dist/wizard-support.js +93 -80
  49. package/dist/wizard-support.js.map +1 -1
  50. package/package.json +1 -1
@@ -1,12 +1,32 @@
1
- /**
2
- * REMOVED: Anthropic Subscription OAuth auth has been removed.
3
- *
4
- * Connection to Anthropic is now exclusively via:
5
- * 1. claude-cli — spawns the Claude CLI binary (uses your subscription)
6
- * 2. API key (BYOK) — standard x-api-key authentication
7
- */
1
+ import { OAuthCredential } from './credential-reader';
8
2
  export declare const ANTHROPIC_OAUTH_BETA_HEADER = "oauth-2025-04-20";
3
+ export declare const ANTHROPIC_CLAUDE_CODE_API_KEY_URL = "https://api.anthropic.com/api/oauth/claude_cli/create_api_key";
4
+ export declare const ANTHROPIC_CLAUDE_CODE_MESSAGES_BASE_URL = "https://api.anthropic.com/v1";
5
+ export declare const ANTHROPIC_CLAUDE_CODE_MESSAGES_QUERY = "beta=true";
6
+ export interface AnthropicSubscriptionTokenInput {
7
+ accessToken: string;
8
+ refreshToken?: string | null;
9
+ expiresAt?: number | null;
10
+ onRefresh?: ((credential: OAuthCredential) => void) | null;
11
+ }
9
12
  export type AnthropicAuthMode = 'api-key' | 'oauth-bearer';
10
- /** @deprecated Subscription API removed. Always throws. */
11
- export declare function resolveAnthropicSubscriptionAuth(_input: any): Promise<never>;
13
+ export interface AnthropicSubscriptionAuthResult {
14
+ token: string;
15
+ authMode: AnthropicAuthMode;
16
+ credential: OAuthCredential;
17
+ refreshed: boolean;
18
+ source: 'api-key-exchange' | 'oauth-bearer';
19
+ }
20
+ export interface ClaudeSubscriptionRequestConfig {
21
+ baseUrl: string;
22
+ apiQuery: string;
23
+ extraHeaders: Record<string, string>;
24
+ }
25
+ export declare function ensureFreshAnthropicCredential(input: AnthropicSubscriptionTokenInput): Promise<{
26
+ credential: OAuthCredential;
27
+ refreshed: boolean;
28
+ }>;
29
+ export declare function createAnthropicApiKeyFromOauth(accessToken: string): Promise<string>;
30
+ export declare function resolveAnthropicSubscriptionAuth(input: AnthropicSubscriptionTokenInput): Promise<AnthropicSubscriptionAuthResult>;
31
+ export declare function getClaudeSubscriptionRequestConfig(source?: string | null): ClaudeSubscriptionRequestConfig;
12
32
  //# sourceMappingURL=anthropic-subscription.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-subscription.d.ts","sourceRoot":"","sources":["../../src/auth/anthropic-subscription.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,eAAO,MAAM,2BAA2B,qBAAqB,CAAC;AAE9D,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,cAAc,CAAC;AAE3D,2DAA2D;AAC3D,wBAAsB,gCAAgC,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAElF"}
1
+ {"version":3,"file":"anthropic-subscription.d.ts","sourceRoot":"","sources":["../../src/auth/anthropic-subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAa,MAAM,qBAAqB,CAAC;AAIjE,eAAO,MAAM,2BAA2B,qBAAqB,CAAC;AAC9D,eAAO,MAAM,iCAAiC,kEAAkE,CAAC;AACjH,eAAO,MAAM,uCAAuC,iCAAiC,CAAC;AACtF,eAAO,MAAM,oCAAoC,cAAc,CAAC;AAUhE,MAAM,WAAW,+BAA+B;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,eAAe,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,cAAc,CAAC;AAE3D,MAAM,WAAW,+BAA+B;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,UAAU,EAAE,eAAe,CAAC;IAC5B,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,kBAAkB,GAAG,cAAc,CAAC;CAC7C;AAED,MAAM,WAAW,+BAA+B;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAuDD,wBAAsB,8BAA8B,CAClD,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC;IAAE,UAAU,EAAE,eAAe,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC,CAS9D;AAED,wBAAsB,8BAA8B,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BzF;AAED,wBAAsB,gCAAgC,CACpD,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,+BAA+B,CAAC,CA0B1C;AAED,wBAAgB,kCAAkC,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,+BAA+B,CAU1G"}
@@ -1,18 +1,139 @@
1
1
  "use strict";
2
- /**
3
- * REMOVED: Anthropic Subscription OAuth auth has been removed.
4
- *
5
- * Connection to Anthropic is now exclusively via:
6
- * 1. claude-cli — spawns the Claude CLI binary (uses your subscription)
7
- * 2. API key (BYOK) — standard x-api-key authentication
8
- */
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ANTHROPIC_OAUTH_BETA_HEADER = void 0;
3
+ exports.ANTHROPIC_CLAUDE_CODE_MESSAGES_QUERY = exports.ANTHROPIC_CLAUDE_CODE_MESSAGES_BASE_URL = exports.ANTHROPIC_CLAUDE_CODE_API_KEY_URL = exports.ANTHROPIC_OAUTH_BETA_HEADER = void 0;
4
+ exports.ensureFreshAnthropicCredential = ensureFreshAnthropicCredential;
5
+ exports.createAnthropicApiKeyFromOauth = createAnthropicApiKeyFromOauth;
11
6
  exports.resolveAnthropicSubscriptionAuth = resolveAnthropicSubscriptionAuth;
12
- // Stub types retained for backwards compatibility.
7
+ exports.getClaudeSubscriptionRequestConfig = getClaudeSubscriptionRequestConfig;
8
+ const credential_reader_1 = require("./credential-reader");
9
+ const token_refresh_1 = require("./token-refresh");
10
+ const child_process_1 = require("child_process");
13
11
  exports.ANTHROPIC_OAUTH_BETA_HEADER = 'oauth-2025-04-20';
14
- /** @deprecated Subscription API removed. Always throws. */
15
- async function resolveAnthropicSubscriptionAuth(_input) {
16
- throw new Error('Subscription API has been removed. Use claude-cli or API key instead.');
12
+ exports.ANTHROPIC_CLAUDE_CODE_API_KEY_URL = 'https://api.anthropic.com/api/oauth/claude_cli/create_api_key';
13
+ exports.ANTHROPIC_CLAUDE_CODE_MESSAGES_BASE_URL = 'https://api.anthropic.com/v1';
14
+ exports.ANTHROPIC_CLAUDE_CODE_MESSAGES_QUERY = 'beta=true';
15
+ const API_KEY_CACHE_TTL_MS = 30 * 60_000;
16
+ let cachedClaudeCliUserAgent = null;
17
+ function getClaudeCliUserAgent() {
18
+ if (cachedClaudeCliUserAgent)
19
+ return cachedClaudeCliUserAgent;
20
+ try {
21
+ const raw = (0, child_process_1.execSync)('claude --version', {
22
+ encoding: 'utf8',
23
+ timeout: 5000,
24
+ stdio: ['pipe', 'pipe', 'pipe'],
25
+ windowsHide: true,
26
+ }).trim();
27
+ const version = raw.match(/\d+\.\d+\.\d+/)?.[0] || '2.1.63';
28
+ cachedClaudeCliUserAgent = `claude-cli/${version}`;
29
+ return cachedClaudeCliUserAgent;
30
+ }
31
+ catch {
32
+ cachedClaudeCliUserAgent = 'claude-cli/2.1.63';
33
+ return cachedClaudeCliUserAgent;
34
+ }
35
+ }
36
+ const apiKeyCache = new Map();
37
+ function readCachedApiKey(accessToken) {
38
+ const cached = apiKeyCache.get(accessToken);
39
+ if (!cached)
40
+ return null;
41
+ if (cached.expiresAt <= Date.now()) {
42
+ apiKeyCache.delete(accessToken);
43
+ return null;
44
+ }
45
+ return cached.rawKey;
46
+ }
47
+ function storeCachedApiKey(accessToken, rawKey) {
48
+ apiKeyCache.set(accessToken, {
49
+ rawKey,
50
+ expiresAt: Date.now() + API_KEY_CACHE_TTL_MS,
51
+ });
52
+ }
53
+ function toCredential(input) {
54
+ return {
55
+ provider: 'anthropic',
56
+ accessToken: input.accessToken,
57
+ refreshToken: input.refreshToken || '',
58
+ expiresAt: input.expiresAt || 0,
59
+ };
60
+ }
61
+ function isScopeLimitedOauthError(message) {
62
+ const normalized = message.toLowerCase();
63
+ return normalized.includes('org:create_api_key')
64
+ || normalized.includes('permission_error')
65
+ || normalized.includes('scope requirement');
66
+ }
67
+ async function ensureFreshAnthropicCredential(input) {
68
+ const credential = toCredential(input);
69
+ if (!credential.refreshToken || !(0, credential_reader_1.isExpired)(credential)) {
70
+ return { credential, refreshed: false };
71
+ }
72
+ const refreshed = await (0, token_refresh_1.refreshToken)(credential);
73
+ input.onRefresh?.(refreshed.credential);
74
+ return { credential: refreshed.credential, refreshed: true };
75
+ }
76
+ async function createAnthropicApiKeyFromOauth(accessToken) {
77
+ const cached = readCachedApiKey(accessToken);
78
+ if (cached)
79
+ return cached;
80
+ const response = await fetch(exports.ANTHROPIC_CLAUDE_CODE_API_KEY_URL, {
81
+ method: 'POST',
82
+ headers: {
83
+ Authorization: `Bearer ${accessToken}`,
84
+ 'anthropic-beta': exports.ANTHROPIC_OAUTH_BETA_HEADER,
85
+ 'Content-Type': 'application/json',
86
+ 'User-Agent': 'funolio-agent',
87
+ 'x-app': 'funolio-desktop',
88
+ },
89
+ body: '{}',
90
+ });
91
+ if (!response.ok) {
92
+ const body = await response.text().catch(() => '');
93
+ throw new Error(`Anthropic Claude subscription API key exchange failed (${response.status}): ${body}`);
94
+ }
95
+ const data = await response.json();
96
+ if (!data.raw_key) {
97
+ throw new Error('Anthropic Claude subscription API key exchange returned no raw_key');
98
+ }
99
+ storeCachedApiKey(accessToken, data.raw_key);
100
+ return data.raw_key;
101
+ }
102
+ async function resolveAnthropicSubscriptionAuth(input) {
103
+ const { credential, refreshed } = await ensureFreshAnthropicCredential(input);
104
+ try {
105
+ const apiKey = await createAnthropicApiKeyFromOauth(credential.accessToken);
106
+ return {
107
+ token: apiKey,
108
+ authMode: 'api-key',
109
+ credential,
110
+ refreshed,
111
+ source: 'api-key-exchange',
112
+ };
113
+ }
114
+ catch (err) {
115
+ const message = err?.message || String(err);
116
+ if (!isScopeLimitedOauthError(message)) {
117
+ throw err;
118
+ }
119
+ return {
120
+ token: credential.accessToken,
121
+ authMode: 'oauth-bearer',
122
+ credential,
123
+ refreshed,
124
+ source: 'oauth-bearer',
125
+ };
126
+ }
127
+ }
128
+ function getClaudeSubscriptionRequestConfig(source) {
129
+ const isOpenClaw = String(source || '').toLowerCase().includes('openclaw');
130
+ return {
131
+ baseUrl: exports.ANTHROPIC_CLAUDE_CODE_MESSAGES_BASE_URL,
132
+ apiQuery: exports.ANTHROPIC_CLAUDE_CODE_MESSAGES_QUERY,
133
+ extraHeaders: {
134
+ 'User-Agent': isOpenClaw ? getClaudeCliUserAgent() : 'funolio-agent',
135
+ 'x-app': 'funolio-desktop',
136
+ },
137
+ };
17
138
  }
18
139
  //# sourceMappingURL=anthropic-subscription.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-subscription.js","sourceRoot":"","sources":["../../src/auth/anthropic-subscription.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AASH,4EAEC;AATD,mDAAmD;AAEtC,QAAA,2BAA2B,GAAG,kBAAkB,CAAC;AAI9D,2DAA2D;AACpD,KAAK,UAAU,gCAAgC,CAAC,MAAW;IAChE,MAA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,SAAS,EAAE,GAAG,MAAM,8BAA8B,CAAC,KAAK,CAAC,CAAC;IAE9E,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,8BAA8B,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC5E,OAAO;YACL,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,SAAS;YACnB,UAAU;YACV,SAAS;YACT,MAAM,EAAE,kBAAkB;SAC3B,CAAC;IACJ,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5C,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,MAAM,GAAG,CAAC;QACZ,CAAC;QAED,OAAO;YACL,KAAK,EAAE,UAAU,CAAC,WAAW;YAC7B,QAAQ,EAAE,cAAc;YACxB,UAAU;YACV,SAAS;YACT,MAAM,EAAE,cAAc;SACvB,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAgB,kCAAkC,CAAC,MAAsB;IACvE,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC3E,OAAO;QACL,OAAO,EAAE,+CAAuC;QAChD,QAAQ,EAAE,4CAAoC;QAC9C,YAAY,EAAE;YACZ,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC,qBAAqB,EAAE,CAAC,CAAC,CAAC,eAAe;YACpE,OAAO,EAAE,iBAAiB;SAC3B;KACF,CAAC;AACJ,CAAC"}
@@ -1,38 +1,16 @@
1
- /**
2
- * Auth Auto-Detect — Funolio Agent
3
- *
4
- * Resolves the best available authentication method for LLM providers.
5
- * Supported auth methods:
6
- * 1. Explicit API key (BYOK) — passed via config or CLI flag
7
- * 2. Environment variable API keys — ANTHROPIC_API_KEY, OPENAI_API_KEY, etc.
8
- *
9
- * CLI providers (claude-cli, codex-cli) do not need auth resolution here —
10
- * they spawn the CLI binary which handles its own authentication.
11
- *
12
- * NOTE: Subscription API / OAuth credential resolution has been removed.
13
- * OAuth tokens passed in config are ignored. Use CLI providers for
14
- * subscription-based access, or provide an explicit API key.
15
- */
1
+ import { OAuthCredential } from './credential-reader';
16
2
  export interface ResolvedAuth {
17
3
  provider: string;
18
4
  model: string;
19
5
  apiKey: string;
20
- source: 'api-key' | 'env';
6
+ source: 'oauth' | 'api-key' | 'env';
7
+ credential?: OAuthCredential;
21
8
  expired?: boolean;
22
9
  error?: string;
23
10
  }
24
11
  /**
25
12
  * Resolve the best available authentication method.
26
- *
27
- * Priority:
28
- * 1. Explicit API key (from config.apiKey)
29
- * 2. Environment variable API key
30
- *
31
- * OAuth/subscription tokens are ignored. For subscription-based access,
32
- * use a CLI provider (claude-cli, codex-cli) instead.
33
- *
34
- * @param config - Auth configuration. oauthToken fields are accepted for
35
- * backwards compatibility but are ignored.
13
+ * Priority: explicit API key > OAuth credentials > env vars
36
14
  */
37
15
  export declare function resolveAuth(config: {
38
16
  provider?: string;
@@ -43,8 +21,8 @@ export declare function resolveAuth(config: {
43
21
  oauthExpiresAt?: number;
44
22
  }): Promise<ResolvedAuth | null>;
45
23
  /**
46
- * Ensure the auth is still valid. For API keys, this is a no-op passthrough.
47
- * OAuth token refresh has been removed.
24
+ * Ensure the token in a ResolvedAuth is still valid. Refreshes if needed.
25
+ * Returns the same object if still valid, or a new one with updated token.
48
26
  */
49
27
  export declare function ensureFreshToken(auth: ResolvedAuth): Promise<ResolvedAuth>;
50
28
  //# sourceMappingURL=auto-detect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auto-detect.d.ts","sourceRoot":"","sources":["../../src/auth/auto-detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MA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CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAiI/B;AAoCD;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAgChF"}
@@ -1,99 +1,242 @@
1
1
  "use strict";
2
- /**
3
- * Auth Auto-Detect Funolio Agent
4
- *
5
- * Resolves the best available authentication method for LLM providers.
6
- * Supported auth methods:
7
- * 1. Explicit API key (BYOK) — passed via config or CLI flag
8
- * 2. Environment variable API keys — ANTHROPIC_API_KEY, OPENAI_API_KEY, etc.
9
- *
10
- * CLI providers (claude-cli, codex-cli) do not need auth resolution here —
11
- * they spawn the CLI binary which handles its own authentication.
12
- *
13
- * NOTE: Subscription API / OAuth credential resolution has been removed.
14
- * OAuth tokens passed in config are ignored. Use CLI providers for
15
- * subscription-based access, or provide an explicit API key.
16
- */
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
17
35
  Object.defineProperty(exports, "__esModule", { value: true });
18
36
  exports.resolveAuth = resolveAuth;
19
37
  exports.ensureFreshToken = ensureFreshToken;
38
+ const credential_reader_1 = require("./credential-reader");
39
+ const token_refresh_1 = require("./token-refresh");
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const os = __importStar(require("os"));
20
43
  // ── Default Models ──────────────────────────────────────────────────────────
21
44
  const DEFAULT_MODELS = {
22
45
  anthropic: 'claude-sonnet-4-5',
23
46
  openai: 'gpt-4o',
24
47
  'google-gemini': 'gemini-2.5-flash',
25
48
  };
26
- // ── Environment API Key Detection ───────────────────────────────────────────
27
- function getEnvApiKey(provider) {
28
- switch (provider) {
29
- case 'anthropic': return process.env.ANTHROPIC_API_KEY;
30
- case 'openai': return process.env.OPENAI_API_KEY;
31
- case 'google':
32
- case 'google-gemini': return process.env.GOOGLE_API_KEY;
33
- default: return undefined;
34
- }
35
- }
36
49
  // ── resolveAuth ─────────────────────────────────────────────────────────────
37
50
  /**
38
51
  * Resolve the best available authentication method.
39
- *
40
- * Priority:
41
- * 1. Explicit API key (from config.apiKey)
42
- * 2. Environment variable API key
43
- *
44
- * OAuth/subscription tokens are ignored. For subscription-based access,
45
- * use a CLI provider (claude-cli, codex-cli) instead.
46
- *
47
- * @param config - Auth configuration. oauthToken fields are accepted for
48
- * backwards compatibility but are ignored.
52
+ * Priority: explicit API key > OAuth credentials > env vars
49
53
  */
50
54
  async function resolveAuth(config) {
51
- const provider = config.provider || 'anthropic';
52
- const model = config.model || DEFAULT_MODELS[provider] || 'claude-sonnet-4-5';
53
55
  // 1. Explicit API key takes priority (BYOK)
54
56
  if (config.apiKey) {
57
+ const provider = config.provider || 'anthropic';
55
58
  console.log(`[auto-detect] Using explicit API key (source: api-key, provider: ${provider})`);
56
59
  return {
57
60
  provider,
58
- model,
61
+ model: config.model || DEFAULT_MODELS[provider] || 'claude-sonnet-4-5',
59
62
  apiKey: config.apiKey,
60
63
  source: 'api-key',
61
64
  };
62
65
  }
63
- // 2. Anthropic bearer config token (sk-ant-oat01-*)
64
- if (config.oauthToken && config.oauthToken.startsWith('sk-ant-oat')) {
65
- console.log(`[auto-detect] Using Anthropic bearer config token (source: oauth, provider: ${provider})`);
66
+ // 2. Use OAuth token from agent config (written during setup/configure)
67
+ if (config.oauthToken) {
68
+ const provider = config.provider || 'anthropic';
69
+ const model = config.model || DEFAULT_MODELS[provider] || 'claude-sonnet-4-5';
70
+ const credential = {
71
+ provider: provider,
72
+ accessToken: config.oauthToken,
73
+ refreshToken: config.oauthRefreshToken || '',
74
+ expiresAt: config.oauthExpiresAt || 0,
75
+ };
76
+ // If token is expired OR has no expiry info, and no refresh token in config,
77
+ // try to find one from CLI credentials (which track expiry properly)
78
+ if (!credential.refreshToken && ((0, credential_reader_1.isExpired)(credential) || !credential.expiresAt)) {
79
+ console.log(`[auto-detect] Config OAuth token expired with no refresh token — checking CLI credentials...`);
80
+ const cliCreds = detectClaudeCodeCredentials();
81
+ if (cliCreds?.refreshToken) {
82
+ console.log(`[auto-detect] Found refresh token in Claude Code credentials`);
83
+ credential.refreshToken = cliCreds.refreshToken;
84
+ credential.expiresAt = cliCreds.expiresAt || credential.expiresAt;
85
+ // Use CLI access token if it's newer
86
+ if (cliCreds.accessToken && (!(0, credential_reader_1.isExpired)(cliCreds) || cliCreds.expiresAt > credential.expiresAt)) {
87
+ credential.accessToken = cliCreds.accessToken;
88
+ }
89
+ }
90
+ }
91
+ // Refresh if expired (or if we just imported CLI expiry that shows it's expired)
92
+ if (credential.refreshToken && ((0, credential_reader_1.isExpired)(credential) || (credential.expiresAt > 0 && Date.now() >= credential.expiresAt))) {
93
+ try {
94
+ const result = await (0, token_refresh_1.refreshToken)(credential);
95
+ credential.accessToken = result.credential.accessToken;
96
+ credential.refreshToken = result.credential.refreshToken;
97
+ credential.expiresAt = result.credential.expiresAt;
98
+ // Persist the refresh token back to config so we don't lose it
99
+ try {
100
+ const configPath = path.join(os.homedir(), '.funolio', 'config.json');
101
+ if (fs.existsSync(configPath)) {
102
+ const cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
103
+ const idx = cfg.providers?.findIndex((p) => p.id === provider);
104
+ if (idx >= 0 && cfg.providers[idx]) {
105
+ cfg.providers[idx].oauthToken = credential.accessToken;
106
+ cfg.providers[idx].oauthRefreshToken = credential.refreshToken;
107
+ cfg.providers[idx].oauthExpiresAt = credential.expiresAt;
108
+ fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
109
+ console.log(`[auto-detect] Persisted refreshed tokens to config`);
110
+ }
111
+ }
112
+ }
113
+ catch (writeErr) {
114
+ console.warn(`[auto-detect] Failed to persist refreshed tokens:`, writeErr);
115
+ }
116
+ }
117
+ catch {
118
+ console.log(`[auto-detect] OAuth token expired and refresh failed for ${provider}`);
119
+ return {
120
+ provider,
121
+ model,
122
+ apiKey: credential.accessToken,
123
+ source: 'oauth',
124
+ credential,
125
+ expired: true,
126
+ error: `OAuth token expired for ${provider}. Run \`funolio-agent configure\` to re-authenticate.`,
127
+ };
128
+ }
129
+ }
130
+ console.log(`[auto-detect] Resolved auth: provider=${provider}, model=${model}, source=oauth (from config)`);
66
131
  return {
67
132
  provider,
68
133
  model,
69
- apiKey: config.oauthToken,
70
- source: 'api-key', // Use api-key source type for downstream compat; authMode handles bearer
134
+ apiKey: credential.accessToken,
135
+ source: 'oauth',
136
+ credential,
71
137
  };
72
138
  }
73
- // 3. Check environment variable API keys
74
- const envKey = getEnvApiKey(provider);
75
- if (envKey) {
76
- console.log(`[auto-detect] Using environment variable API key (source: env, provider: ${provider})`);
139
+ // 3. Try to auto-detect OAuth token from Claude Code credentials
140
+ const claudeCodeAuth = detectClaudeCodeCredentials();
141
+ if (claudeCodeAuth) {
142
+ const provider = config.provider || 'anthropic';
143
+ const model = config.model || DEFAULT_MODELS[provider] || 'claude-sonnet-4-5';
144
+ // Refresh if expired
145
+ if ((0, credential_reader_1.isExpired)(claudeCodeAuth) && claudeCodeAuth.refreshToken) {
146
+ try {
147
+ const result = await (0, token_refresh_1.refreshToken)(claudeCodeAuth);
148
+ claudeCodeAuth.accessToken = result.credential.accessToken;
149
+ claudeCodeAuth.refreshToken = result.credential.refreshToken;
150
+ claudeCodeAuth.expiresAt = result.credential.expiresAt;
151
+ }
152
+ catch {
153
+ console.log(`[auto-detect] Claude Code OAuth token expired and refresh failed`);
154
+ return {
155
+ provider,
156
+ model,
157
+ apiKey: claudeCodeAuth.accessToken,
158
+ source: 'oauth',
159
+ credential: claudeCodeAuth,
160
+ expired: true,
161
+ error: `Claude Code OAuth token expired and refresh failed. Run \`claude login\` to re-authenticate.`,
162
+ };
163
+ }
164
+ }
165
+ console.log(`[auto-detect] Resolved auth: provider=${provider}, model=${model}, source=oauth (from Claude Code credentials)`);
77
166
  return {
78
167
  provider,
79
168
  model,
80
- apiKey: envKey,
81
- source: 'env',
169
+ apiKey: claudeCodeAuth.accessToken,
170
+ source: 'oauth',
171
+ credential: claudeCodeAuth,
82
172
  };
83
173
  }
84
- // No API key found CLI providers handle their own auth, so returning null
85
- // is expected for claude-cli / codex-cli. For API-based providers, this
86
- // means the user needs to configure an API key.
87
- console.log(`[auto-detect] No API key found for provider: ${provider}`);
174
+ console.log('[auto-detect] No API key or OAuth token found in config');
88
175
  return null;
89
176
  }
177
+ // ── Claude Code Credential Detection ────────────────────────────────────────
178
+ /**
179
+ * Detect OAuth credentials from Claude Code's local credential files.
180
+ * Checks ~/.claude/.credentials.json for claudeAiOauth tokens.
181
+ */
182
+ function detectClaudeCodeCredentials() {
183
+ try {
184
+ const credPath = path.join(os.homedir(), '.claude', '.credentials.json');
185
+ if (!fs.existsSync(credPath))
186
+ return null;
187
+ const raw = JSON.parse(fs.readFileSync(credPath, 'utf-8'));
188
+ const oauth = raw?.claudeAiOauth;
189
+ if (!oauth?.accessToken?.startsWith('sk-ant-oat01-'))
190
+ return null;
191
+ const credential = {
192
+ provider: 'anthropic',
193
+ accessToken: oauth.accessToken,
194
+ refreshToken: oauth.refreshToken || '',
195
+ expiresAt: oauth.expiresAt || 0,
196
+ };
197
+ if ((0, credential_reader_1.isExpired)(credential)) {
198
+ console.log('[auto-detect] Claude Code OAuth token is expired, will attempt refresh');
199
+ }
200
+ return credential;
201
+ }
202
+ catch {
203
+ return null;
204
+ }
205
+ }
90
206
  // ── ensureFreshToken ────────────────────────────────────────────────────────
91
207
  /**
92
- * Ensure the auth is still valid. For API keys, this is a no-op passthrough.
93
- * OAuth token refresh has been removed.
208
+ * Ensure the token in a ResolvedAuth is still valid. Refreshes if needed.
209
+ * Returns the same object if still valid, or a new one with updated token.
94
210
  */
95
211
  async function ensureFreshToken(auth) {
96
- // API keys don't expire return as-is
97
- return auth;
212
+ if (auth.source !== 'oauth' || !auth.credential) {
213
+ return auth;
214
+ }
215
+ if (!(0, credential_reader_1.isExpired)(auth.credential)) {
216
+ return auth;
217
+ }
218
+ try {
219
+ const result = await (0, token_refresh_1.refreshToken)(auth.credential);
220
+ const refreshed = result.credential;
221
+ if (refreshed.accessToken === auth.credential.accessToken) {
222
+ return auth; // refresh failed or not needed, return as-is
223
+ }
224
+ return {
225
+ ...auth,
226
+ apiKey: refreshed.accessToken,
227
+ credential: refreshed,
228
+ };
229
+ }
230
+ catch (err) {
231
+ if (err instanceof token_refresh_1.TokenRefreshError) {
232
+ console.error(`[auto-detect] Token refresh failed for ${err.provider}: ${err.message}`);
233
+ return {
234
+ ...auth,
235
+ expired: true,
236
+ error: `Token refresh failed for ${err.provider}${err.httpStatus ? ` (HTTP ${err.httpStatus})` : ''}: ${err.message}`,
237
+ };
238
+ }
239
+ throw err;
240
+ }
98
241
  }
99
242
  //# sourceMappingURL=auto-detect.js.map
@@ -1 +1 @@
1
- {"version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UAAU,CAAC;QACpC,IAAI,SAAS,CAAC,WAAW,KAAK,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC,CAAC,6CAA6C;QAC5D,CAAC;QAED,OAAO;YACL,GAAG,IAAI;YACP,MAAM,EAAE,SAAS,CAAC,WAAW;YAC7B,UAAU,EAAE,SAAS;SACtB,CAAC;IACJ,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,IAAI,GAAG,YAAY,iCAAiB,EAAE,CAAC;YACrC,OAAO,CAAC,KAAK,CAAC,0CAA0C,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YACxF,OAAO;gBACL,GAAG,IAAI;gBACP,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,4BAA4B,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,OAAO,EAAE;aACtH,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -1,18 +1,3 @@
1
- /**
2
- * REMOVED: OAuth credential reading from disk has been removed.
3
- *
4
- * Connection to LLM providers is now exclusively via:
5
- * 1. CLI providers (claude-cli, codex-cli) — spawns the CLI binary
6
- * 2. API key (BYOK) — standard x-api-key authentication
7
- *
8
- * The credential-reader previously read OAuth tokens from:
9
- * - ~/.claude/.credentials.json (Anthropic)
10
- * - ~/.codex/auth.json (OpenAI)
11
- * - ~/.config/gcloud/application_default_credentials.json (Google)
12
- *
13
- * These files are now only used by the CLI providers themselves (claude, codex)
14
- * and are not read by the Funolio agent.
15
- */
16
1
  export interface OAuthCredential {
17
2
  provider: 'anthropic' | 'openai' | 'google-gemini';
18
3
  accessToken: string;
@@ -29,16 +14,11 @@ export interface CredentialDetectionResult {
29
14
  error: string;
30
15
  }[];
31
16
  }
32
- /** @deprecated Always returns empty results. */
33
- export declare function detectCredentials(): CredentialDetectionResult;
34
- /** @deprecated Always returns null. */
17
+ /** Clear the credential cache (useful for testing or forced refresh). */
18
+ export declare function clearCache(): void;
35
19
  export declare function readClaudeCredentials(): OAuthCredential | null;
36
- /** @deprecated Always returns null. */
37
20
  export declare function readCodexCredentials(): OAuthCredential | null;
38
- /** @deprecated Always returns null. */
39
21
  export declare function readGeminiCredentials(): OAuthCredential | null;
40
- /** Clear the credential cache (no-op). */
41
- export declare function clearCache(): void;
42
- /** @deprecated Always returns true (expired). */
43
- export declare function isExpired(_cred: OAuthCredential): boolean;
22
+ export declare function detectCredentials(): CredentialDetectionResult;
23
+ export declare function isExpired(cred: OAuthCredential): boolean;
44
24
  //# sourceMappingURL=credential-reader.d.ts.map