Skip to content

feat: fully dynamic model catalog - no hardcoded models - #224

Open
KpihX wants to merge 11 commits into
anthonyhaussman:mainfrom
kpihx-labs:main
Open

KpihX wants to merge 11 commits into
anthonyhaussman:mainfrom
kpihx-labs:main

Conversation

@KpihX

@KpihX KpihX commented Nov 15, 2026

Copy link
Copy Markdown

This PR makes the opencode-agy-auth plugin fully dynamic by removing all hardcoded model lists.

Changes

  • Removed STATIC_MODELS_SIMPLE and TIER_MAPPING hardcoded constants from tier.ts
  • Added dynamic model discovery via AGY quota API (retrieveUserQuota)
  • New exports in tier.ts:
    • inferModelMetadata() - infers model metadata from model ID patterns
    • extractBaseModelId() - extracts base model ID from tiered variants
    • buildTierMapping() - builds tier mapping from quota response
    • fetchAvailableModelIds() - fetches available model IDs from AGY
    • resolveModelTier() - now accepts dynamic tier mapping
  • Updated plugin.ts:
    • buildModelFromBase() - builds ProviderModel from dynamic data
    • buildDynamicModelCatalog() - creates catalog from quota response
    • getDynamicModels() - merges dynamic models with user config
    • Provider models hook now calls dynamic catalog
  • Updated v2.ts to use dynamic catalog at startup

How it works

  1. When authenticated, the plugin calls AGY's retrieveUserQuota API
  2. Extracts modelId from each bucket in the response
  3. Groups tiered variants by base model (e.g., gemini-3.8-flash-low -> gemini-3.8-flash)
  4. Infers metadata (name, capabilities, limits) from base model ID patterns
  5. Builds full ProviderModel catalog dynamically
  6. Merges with any user-defined model overrides

Verification

  • npm run build passes TypeScript
  • Manual test with opencode models shows only models from user's actual AGY quota

This ensures the plugin always shows exactly the models the user has access to in their AGY account, not a stale hardcoded list.

- Removed STATIC_MODELS_SIMPLE and TIER_MAPPING hardcoded lists
- Added dynamic model inference from AGY quota API (retrieveUserQuota)
- Models are now discovered at runtime based on user's actual AGY access
- Updated tier.ts with inferModelMetadata, extractBaseModelId, buildTierMapping, fetchAvailableModelIds
- Updated plugin.ts to use dynamic catalog via buildDynamicModelCatalog
- Updated v2.ts to use dynamic catalog at startup
- Tests updated to verify dynamic behavior instead of hardcoded models
KpihX added 10 commits November 15, 2026 17:24
- Remove STATIC_MODELS_SIMPLE and TIER_MAPPING hardcoded lists
- Discover models live from AGY quota API (retrieveUserQuota)
- Infer model metadata (name, limits, capabilities) from model ID patterns
- Config hook populates models at startup without touching client
  (avoids re-entrant config.get deadlock); NOOP auth client + 25s cap
  so a stalled network can never hang server startup
- Resolve projectId via refresh-token parts, config, env, then AGY API
  (resolveProjectContextFromAccessToken) as last resort
- v2 setup registers dynamic models via provider/model/catalog transforms
  using the connection API
- provider.models hook merges dynamic catalog with user overrides,
  applies models.dev pricing, normalizes costs; login-required fallback
- Verified: opencode models lists live AGY inventory (4.6, gemini-3.8,
  gpt-oss-120b, etc.), zero 5.5 entries; nvidia-labs unaffected
- Remove accidentally committed npm tarball
…static catalog

Fork identity + fully dynamic model catalog.

- package renamed @anthonyhaussman/opencode-agy-auth -> @kpihx-labs/opencode-agy-auth (1.6.0-kpihx.1)
  so a stray npm spec can never be installed alongside the local file:// fork and
  silently override the provider model list with upstream statics (root cause 2026-11-17).
- removed the bundled models.json catalog and its importer (src/sdk/request/prepare.ts);
  getModelEnum no longer reads a hardcoded model map.
- emptied REQUEST_MODEL_FALLBACKS (src/sdk/request/shared.ts).
- tier/v2 metadata derived structurally from model IDs (no claude-/gpt-/gemini- names).
- models are discovered live from the AGY quota API (retrieveUserQuota).

Runtime verified: no claude-*-5-5, no ToS warning, 4.6 line-up exposed dynamically.
…tics

- Multi-account storage with plugin-owned file (agy-accounts.json) immune to OpenCode clobbering
- Namespaced models: google-agy/<account>/<model> for per-account quota isolation
- Dynamic model_enum fetching via fetchAvailableModels (no more stale catalog)
- Project resolution prefers API-discovered project over stale refresh-token project
- Exhaustion tracking + 30-min TTL + automatic failover on 429
- Stub accounts (needsCredentials) replace credential cloning
- importAccountFromProvider / importAccountFromJson / describeAccounts diagnostics
- Fix: projectId resolution prefers backend-discovered project over stale refresh-token project
- enumLabel: omits model_enum when unknown (avoids M16 placeholder)
- Model enums fetched from live catalogue per account/project with 10-min TTL
- URL rewrite handles both /models/ and /v1beta/ paths
- seedAccountFromActive creates stubs (needsCredentials) instead of cloning credentials
- Storage survives OpenCode clobbering via plugin-owned agy-accounts.json
- IdentifyAccounts() diagnostic for duplicate-email detection
- importAccountFromProvider/Json for safe credential import
- Purged redundant demar (duplicate of kpihx) and activeAccount pointer
- Version bump to 1.6.0-kpihx.2
- Replace dual V1/V2 plugin with v2-clean.ts: options.ids drives N provider IDs
  (agy, agy-labs), each with one OAuth method; credentials stored by OpenCode.
- Remove multi-account store, account/model namespacing, failover, plugin-owned secrets.
- Dynamic catalog loaded before synchronous transforms, replayed on credential.updated.
- Reuse proven SDK helpers for request shaping, tier variants and enum mapping.
- Archive legacy V1/V2 dual-architecture tests under test/legacy/ (audit, excluded).
- Fix stale test expectations aligned with intentional dynamic-catalog design.
…rite

- connection.resolve() returns the stored (stale) access token and does not
  drive OAuth refresh because the provider declares a dummy apiKey. Refresh
  expired tokens in resolveCredential via the shared dedup/cache helper.
- Replace dead aisdk.hook with real session http.request/http.response hooks
  that rewrite generative-language calls to the Antigravity internal endpoint
  with a Bearer token, and transform streaming responses.
- Dynamic model catalog from live quota (20 models for AGY account).
- Update index-export test to assert no aisdk.hook + session hook registration.

Result: 401 'API key not valid' -> genuine Google 429 (quota), 392/392 tests.
Root cause of the false 'Resource has been exhausted' 429 on a full-quota
account was in the request shaping, NOT the account/auth/quota:

- prepareAgyRequest derived a display-variant model id (gemini-3.8-flash-medium)
  rejected by the backend with 404/429. Force the wrapped body's model to the
  canonical bucket id (gemini-3.8-flash-tiered). Recognize -tiered as a tier
  suffix and strip inline tier suffixes when resolving.
- OpenCode injects the entire AGENTS.md kernel (~90k chars) into
  systemInstruction; the backend rejects >~12k chars with a misleading 429.
  Relocate the full text into a leading user content part (lossless), keeping
  a short systemInstruction. Verified: <=12000->200, >=16000->429.

Verified end-to-end: opencode run -m agy/gemini-3.8-flash exits 0 with a real
answer, zero 429. 392/392 tests, typecheck + build clean.
- DEFAULT_IDS, options guidance and tests now use ['agy','agy-x'].
- Kernel opencode.jsonc options.ids updated to ['agy','agy-x'] (live config).
- agy-x starts as login-required until its own OAuth account is added.
- DEFAULT_IDS back to ['agy'] only; no personal provider ids, emails or
  project ids baked into the published plugin (tests use neutral ids).
- Restore agent-callable agy_quota / agy_quota_summary tools and
  /agy-quota, /agy-quota-summary commands (per configured id), using the
  existing quota factories with an OpenCode-owned credential resolver.
- Earlier fix retained: canonical bucket model id + lossless AGENTS.md
  relocation (root cause of the false 429 on a full-quota account).

392/392 tests, typecheck + build clean. Quota tools verified live for both
configured accounts.
…account

# Conflicts:
#	CHANGELOG.md
#	package-lock.json
#	package.json
#	src/plugin.ts
#	src/plugin/v2.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant