@demicodes/provider-claude-code 0.3.2 → 0.3.3

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/index.d.mts CHANGED
@@ -11,8 +11,17 @@ type ModelCatalogFetch = (input: string | URL | Request, init?: RequestInit) =>
11
11
  declare function listClaudeCodeModels(options?: ClaudeCodeModelCatalogOptions): Promise<ProviderModelList>;
12
12
  //#endregion
13
13
  //#region src/oauth.d.ts
14
+ /**
15
+ * Where a resolved token came from. Callers that inject the token into a
16
+ * spawned CLI must skip `keychain`: that token is the CLI's own short-lived
17
+ * credential, and injecting it via CLAUDE_CODE_OAUTH_TOKEN disables the CLI's
18
+ * refresh flow — the run starts 401ing as soon as the token expires. Owned
19
+ * sources (static/file/env) are the caller's responsibility and inject as-is.
20
+ */
21
+ type ClaudeCodeOAuthSource = 'static' | 'file' | 'env' | 'keychain';
14
22
  interface ClaudeCodeOAuthAccess {
15
23
  accessToken: string;
24
+ source: ClaudeCodeOAuthSource;
16
25
  subscriptionType?: string | null;
17
26
  rateLimitTier?: string | null;
18
27
  }
package/dist/index.mjs CHANGED
@@ -230,7 +230,10 @@ var FileClaudeCodeAuthStore = class {
230
230
  }
231
231
  }
232
232
  async resolveAccess() {
233
- if (this.accessToken) return { accessToken: this.accessToken };
233
+ if (this.accessToken) return {
234
+ accessToken: this.accessToken,
235
+ source: "static"
236
+ };
234
237
  if (this.oauthFile) try {
235
238
  const raw = JSON.parse(await readFile(this.oauthFile, "utf8"));
236
239
  if (!isRecord(raw)) throw new ClaudeCodeAuthError("auth_invalid", `Invalid OAuth file: ${this.oauthFile}`);
@@ -238,6 +241,7 @@ var FileClaudeCodeAuthStore = class {
238
241
  if (!accessToken) throw new ClaudeCodeAuthError("auth_missing", `No accessToken in ${this.oauthFile}`);
239
242
  return {
240
243
  accessToken,
244
+ source: "file",
241
245
  subscriptionType: nonEmptyString(raw.subscriptionType) ?? null,
242
246
  rateLimitTier: nonEmptyString(raw.rateLimitTier) ?? null
243
247
  };
@@ -246,7 +250,10 @@ var FileClaudeCodeAuthStore = class {
246
250
  throw new ClaudeCodeAuthError("auth_missing", `Failed to read Claude OAuth file ${this.oauthFile}: ${error instanceof Error ? error.message : String(error)}`);
247
251
  }
248
252
  const fromEnv = nonEmptyString(process$1.env.CLAUDE_CODE_OAUTH_TOKEN);
249
- if (fromEnv) return { accessToken: fromEnv };
253
+ if (fromEnv) return {
254
+ accessToken: fromEnv,
255
+ source: "env"
256
+ };
250
257
  if (process$1.platform === "darwin") try {
251
258
  const { stdout } = await execFileAsync("security", [
252
259
  "find-generic-password",
@@ -265,6 +272,7 @@ var FileClaudeCodeAuthStore = class {
265
272
  if (!accessToken) throw new ClaudeCodeAuthError("auth_missing", "Claude Code keychain missing accessToken");
266
273
  return {
267
274
  accessToken,
275
+ source: "keychain",
268
276
  subscriptionType: nonEmptyString(oauth.subscriptionType) ?? null,
269
277
  rateLimitTier: nonEmptyString(oauth.rateLimitTier) ?? null
270
278
  };
@@ -408,6 +416,7 @@ function createClaudeCodeCredentials(pool, authStore, options = {}) {
408
416
  add: async (input) => {
409
417
  if (typeof input.accessToken === "string") return importAccess({
410
418
  accessToken: input.accessToken,
419
+ source: "static",
411
420
  subscriptionType: typeof input.subscriptionType === "string" ? input.subscriptionType : null,
412
421
  rateLimitTier: typeof input.rateLimitTier === "string" ? input.rateLimitTier : null
413
422
  }, "add:accessToken");
@@ -415,6 +424,7 @@ function createClaudeCodeCredentials(pool, authStore, options = {}) {
415
424
  const oauth = input.oauth;
416
425
  return importAccess({
417
426
  accessToken: oauth.accessToken,
427
+ source: "static",
418
428
  subscriptionType: typeof oauth.subscriptionType === "string" ? oauth.subscriptionType : null,
419
429
  rateLimitTier: typeof oauth.rateLimitTier === "string" ? oauth.rateLimitTier : null
420
430
  }, "add:oauth");
@@ -663,6 +673,28 @@ function toolNameToClaude(name) {
663
673
  return `mcp__main__${name}`;
664
674
  }
665
675
  //#endregion
676
+ //#region src/oauth.ts
677
+ /**
678
+ * The token to inject into a spawned CLI as CLAUDE_CODE_OAUTH_TOKEN, or null
679
+ * to let the CLI authenticate itself. Keychain-sourced tokens are never
680
+ * injected — see {@link ClaudeCodeOAuthSource}.
681
+ */
682
+ function injectableCliToken(access) {
683
+ return access.source === "keychain" ? null : access.accessToken;
684
+ }
685
+ /**
686
+ * Resolve Claude Code consumer OAuth access for quota APIs.
687
+ * Order: options env CLAUDE_CODE_OAUTH_TOKEN, then macOS Keychain "Claude Code-credentials".
688
+ * Prefer injecting {@link ClaudeCodeAuthStore} when multi-credential is enabled.
689
+ */
690
+ async function resolveClaudeCodeOAuthAccess() {
691
+ try {
692
+ return await new FileClaudeCodeAuthStore().resolveAccess();
693
+ } catch {
694
+ return null;
695
+ }
696
+ }
697
+ //#endregion
666
698
  //#region src/output.ts
667
699
  function mapClaudeStdoutMessage(message, options = {}) {
668
700
  const events = [];
@@ -872,20 +904,6 @@ function stripMcpToolPrefix(name) {
872
904
  return /^mcp__[^_]+__(.+)$/.exec(name)?.[1] ?? name;
873
905
  }
874
906
  //#endregion
875
- //#region src/oauth.ts
876
- /**
877
- * Resolve Claude Code consumer OAuth access for quota APIs.
878
- * Order: options env CLAUDE_CODE_OAUTH_TOKEN, then macOS Keychain "Claude Code-credentials".
879
- * Prefer injecting {@link ClaudeCodeAuthStore} when multi-credential is enabled.
880
- */
881
- async function resolveClaudeCodeOAuthAccess() {
882
- try {
883
- return await new FileClaudeCodeAuthStore().resolveAccess();
884
- } catch {
885
- return null;
886
- }
887
- }
888
- //#endregion
889
907
  //#region src/quota.ts
890
908
  const DEFAULT_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
891
909
  const DEFAULT_OAUTH_BETA = "oauth-2025-04-20";
@@ -1227,7 +1245,7 @@ var ClaudeCodeProvider = class {
1227
1245
  claudePath: options.claudePath,
1228
1246
  resolveOAuthAccessToken: options.authStore ? async () => {
1229
1247
  try {
1230
- return (await options.authStore.resolveAccess()).accessToken;
1248
+ return injectableCliToken(await options.authStore.resolveAccess());
1231
1249
  } catch {
1232
1250
  return null;
1233
1251
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@demicodes/provider-claude-code",
3
3
  "description": "Claude Code provider adapter for Demi.",
4
- "version": "0.3.2",
4
+ "version": "0.3.3",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "exports": {