Commit Graph
21 Commits
Author SHA1 Message Date
Brent d76780a6aa fix(ai): repair Alibaba Token Plan usage reporting 2026-07-24 14:00:50 +00:00
Brent e184fe8f8d feat: add native Alibaba Token Plan provider 2026-07-23 23:04:00 +00:00
LunarECL 4a9ad17298 fix(ai): stop header ingests from sliding the usage-report deadline 2026-07-23 22:26:51 +09:00
LunarECL 2e138ee45d fix(ai): keep header ingests from clearing usage-fetch cooldowns 2026-07-23 22:08:54 +09:00
LunarECL 7f4c3bfba3 fix(ai): keep header-only usage from suppressing full fetch 2026-07-23 21:47:25 +09:00
LunarECL e7fdc99afd feat(ai): report Anthropic extra usage 2026-07-23 21:25:15 +09:00
can1357 2c355102ce chore: applied biome formatting to merged sources 2026-07-16 03:52:48 +02:00
can1357 1a5331e500 test(ai): aligned suppression regression with versioned usage cache key 2026-07-16 03:40:45 +02:00
can1357 792f75298a fix(auth): retain targeted OAuth row after refresh races 2026-07-16 03:39:24 +02:00
can1357 908d45a98c merged PR #5519: fix(auth): serialize provider OAuth refreshes
# Conflicts:
#	packages/ai/src/auth-storage.ts
#	packages/ai/test/auth-storage-usage-cache.test.ts
2026-07-16 03:39:16 +02:00
roboomp e858c1be65 fix(auth): serialized provider oauth refreshes
- Routed provider refreshes through durable SQLite leases and fenced follow-up writes against peer rotations.
- Kept background usage probes from disabling credentials when refresh fails.
- Added multi-instance and post-lease rotation regressions.

Fixes #5396
2026-07-14 20:12:20 +00:00
chan1103 c001d660e3 fix(ai): claim same-org rows via stored credential bases; stable org-only usage cache identity
Codex review round 9 on 0dbab2ec3:
- matchesReplacementCredential: a same-org incoming credential now also
  claims a row whose STORED credential shares a base identity
  (email/account/project) with it, so a later login that loses the email
  but keeps the account updates its row instead of duplicating the
  subscription. Different orgs still never match; org-less logins keep
  exact-key matching only.
- #buildUsageCacheIdentity: treat orgId as a stable identifier so
  org-only credentials no longer fall back to a rotating token hash that
  churned their usage cache keys on every OAuth refresh and fragmented
  usage history.
2026-07-11 22:49:12 +09:00
chan1103 044d722a36 fix(ai): scope Anthropic credential identity by organization
One Anthropic account email can hold multiple organizations (a Team seat
plus a personal Max plan), each with its own org-scoped OAuth token and
independent 5h/7d limit pools. Credentials were deduped by bare email, so
logging in with the second subscription silently replaced the first, and
usage reports from the two pools merged into one row with mixed numbers.

- capture organization uuid/name at login (token exchange response, with
  a claude_cli/bootstrap fallback); token refreshes never rewrite it
- key anthropic credential identity as email + org; a legacy email-keyed
  row is claimed in place by the first org-scoped login with the same
  email, and org-less credentials never clobber org-scoped rows
- partition usage-report dedupe and the per-credential usage cache by
  org so the two subscriptions' limit pools stay distinct for rotation
- show the organization in omp usage (redaction-safe) and name the
  stored account/org in the login success message
2026-07-11 22:49:12 +09:00
can1357 a17ec81477 feat(ai): integrated granular credential usage tracking and rate limiting
- Added client-side usage overlays to the auth broker to support granular, credential-specific usage reporting.
- Integrated Fable weekly usage windows and limits into the Claude rate-limiting and ranking strategies.
- Optimized rate-limit handling by caching null results during backoff and disabling retries for 429 status codes.
- Updated credential storage to ingest and persist overlay-based usage data for improved account selection.
2026-07-02 22:38:54 +02:00
Alexander Kirilin 881ae78010 fix(tui): include tiered Codex usage limits 2026-06-23 07:58:11 -04:00
can1357 9d457f73d9 test: migrated test imports to package subpath exports
- Replaced relative `../src` imports with `@oh-my-pi/pi-ai` and `@oh-my-pi/pi-agent-core` subpaths.
2026-06-08 19:03:55 +02:00
can1357 7f3e17a3b6 feat(ai): added rate-limit header warming for Anthropic usage cache
- Added `parseClaudeRateLimitHeaders` to extract 5h/7d utilization from `anthropic-ratelimit-unified-*` response headers.
- Added `AuthStorage.ingestUsageHeaders` to warm the per-credential usage cache from headers, throttled to 60s per key.
- Merges header-derived limits onto the last full usage report, preserving per-tier data not present in headers.
- Wires ingestion into `AgentSession` on each Anthropic response to reduce direct OAuth `/usage` probes.
2026-06-02 10:50:54 +02:00
can1357 c936620c63 fix(ai): resolved OAuth refresh failures by disabling creds
- Replaced inline definitive-failure checks with shared isDefinitiveOAuthFailure in auth-storage and refresher.
- Disabled credentials during definitive OAuth refresh failures and captured the disabling cause on the credential row.
- Wrote null usage-cache entries with expiresAt set to 0 when credentials were disabled to prevent stale reports.
- Added tests for invalid_grant and transient OAuth refresh outcomes, including cache and credential-state assertions.
- Updated Unreleased changelog notes to document OAuth refresh fixes and stale usage-cache clearing behavior.
2026-05-26 20:22:25 +02:00
can1357 90b134ca4c test: replaced real timers and sleeps with deterministic test hooks
- Added `providerRetryWait` and `retryWait` hooks to stream/usage options so tests bypass real scheduler delays.
- Parameterized GitHub Copilot poll intervals and Copilot model retry base delay for fast test execution.
- Replaced `Bun.sleep`/`setTimeout` polling loops with `AbortSignal` event listeners in agent session tests.
- Consolidated auth-gateway E2E helpers into a shared `test/helpers` module, eliminating duplicated `checkGatewayAvailable` implementations.
- Migrated credential-disabled tests from SQLite-backed stores to an in-memory store, removing temp-dir lifecycle overhead.
2026-05-17 04:02:09 +02:00
can1357 2155b8e020 perf: replaced WeakMap caches with symbol-keyed properties
- Migrated per-object caches (chat/tool starts, model fingerprints, validation contexts, provider indexes, render IDs) from WeakMap to Symbol-keyed properties on the objects themselves.
- Rewrote SSE debug tee as a single-pass inline parser, eliminating the body.tee() + readSseEvents re-parse pipeline.
- Refactored MockModel from a factory function + external WeakMap state into a self-contained class.
- Added FIFO memoization caches for heuristic candidate expansion and namespace suffix lookups.
2026-05-17 03:47:45 +02:00
can1357 df1c1a6ba8 feat(auth): added auth-gateway forward-proxy and broker usage/migrate endpoints
- Added `omp auth-gateway serve/token/status` — a forward-proxy injecting broker credentials for OpenAI Chat, Anthropic Messages, and OpenAI Responses wire formats.
- Added `GET /v1/usage` to auth-broker and auth-gateway; usage cache switched to 5-min per-credential TTL with jitter and last-good fallback on failure.
- Added `AuthStorage.setConfigApiKey/removeConfigApiKey/clearConfigApiKeys` so `models.yml` `apiKey` beats OAuth tokens without overriding `--api-key`.
- Added `omp auth-broker migrate --from-local` for idempotent upload of local SQLite/env credentials to the broker.
2026-05-16 23:25:10 +02:00