Repository navigation
fix(server): read Claude usage windows when nonessential traffic is disabled #22280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1b0653a
ed9e60f
d4c032b
2482d13
c328676
5381e25
dfb0dd6
d0a2114
ee08a13
2efe0f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ import { | |
| type ServerProvider, | ||
| type ServerProviderModel, | ||
| type ServerProviderSlashCommand, | ||
| type ServerProviderResetCredits, | ||
| } from "@t3tools/contracts"; | ||
| import * as Cause from "effect/Cause"; | ||
| import * as DateTime from "effect/DateTime"; | ||
|
|
@@ -52,6 +51,7 @@ import { | |
| } from "./Drivers/ClaudeSkills.ts"; | ||
| import type { ProviderWorkspaceSnapshot } from "@t3tools/provider-core/server/driver"; | ||
| import { makeUnavailableUsageLimits } from "@t3tools/provider-core/server/usageLimits"; | ||
| import type { ClaudeOAuthUsage, ClaudeOAuthUsageError } from "./claudeResetCredits.ts"; | ||
| import { | ||
| type ClaudeScopedLimitNames, | ||
| claudeUsageResponseToLimits, | ||
|
|
@@ -617,7 +617,9 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")( | |
| modelCatalog: ClaudeModelCatalog = BUNDLED_CLAUDE_MODEL_CATALOG, | ||
| /** Shared with the adapter so turn events reuse the scoped-bucket names this probe saw. */ | ||
| scopedLimitNames?: Ref.Ref<ClaudeScopedLimitNames>, | ||
| resolveResetCredits?: (version: string) => Effect.Effect<ServerProviderResetCredits | undefined>, | ||
| resolveOAuthUsage?: ( | ||
| version: string, | ||
| ) => Effect.Effect<ClaudeOAuthUsage | undefined, ClaudeOAuthUsageError>, | ||
| ): Effect.fn.Return< | ||
| ServerProviderDraft, | ||
| never, | ||
|
|
@@ -801,25 +803,28 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")( | |
| subscriptionType: capabilities.subscriptionType, | ||
| authMethod: capabilities.tokenSource, | ||
| }); | ||
| const usageCheckedAt = capabilities.usageCheckedAt ?? checkedAt; | ||
| const usageLimits = !capabilities.usage | ||
| ? makeUnavailableUsageLimits({ checkedAt, reason: "probeFailed" }) | ||
| : scopedLimitNames | ||
| ? yield* recordClaudeUsageResponse(scopedLimitNames, { | ||
| response: capabilities.usage, | ||
| checkedAt: usageCheckedAt, | ||
| }) | ||
| : claudeUsageResponseToLimits({ | ||
| response: capabilities.usage, | ||
| checkedAt: usageCheckedAt, | ||
| }).limits; | ||
| const resetCredits = | ||
| resolveResetCredits && | ||
| capabilities.subscriptionType && | ||
| !usageLimits.unavailable && | ||
| parsedVersion | ||
| ? yield* resolveResetCredits(parsedVersion) | ||
| const oauthResult = | ||
| resolveOAuthUsage && capabilities.subscriptionType && parsedVersion | ||
| ? yield* resolveOAuthUsage(parsedVersion).pipe(Effect.result) | ||
| : undefined; | ||
| const oauthUsage = oauthResult && Result.isSuccess(oauthResult) ? oauthResult.success : undefined; | ||
| const usage = oauthUsage?.usage ?? capabilities.usage; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
merrkry marked this conversation as resolved.
Resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For file-backed logins, switching accounts externally in the same config directory and then refreshing Limits within five minutes now combines the new account's windows with the previous account's identity. Useful? React with 👍 / 👎. |
||
| const usageCheckedAt = oauthUsage | ||
| ? DateTime.formatIso(yield* DateTime.now) | ||
| : (capabilities.usageCheckedAt ?? checkedAt); | ||
| const usageFailed = oauthResult && Result.isFailure(oauthResult) && !usage?.rate_limits_available; | ||
| // Only the SDK's filtered model list identifies the streamed overage bucket. | ||
| if (scopedLimitNames && capabilities.usage) { | ||
| yield* recordClaudeUsageResponse(scopedLimitNames, { | ||
| response: capabilities.usage, | ||
| checkedAt: usageCheckedAt, | ||
| }); | ||
| } | ||
| const usageLimits = | ||
| !usage || usageFailed | ||
| ? makeUnavailableUsageLimits({ checkedAt, reason: "probeFailed" }) | ||
| : claudeUsageResponseToLimits({ response: usage, checkedAt: usageCheckedAt }).limits; | ||
| const resetCredits = oauthUsage?.resetCredits; | ||
| return buildServerProvider({ | ||
| presentation: CLAUDE_PRESENTATION, | ||
| enabled: claudeSettings.enabled, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.