Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:777genius Agent teams ai CliProviderModelAvailabilityService

From Leeroopedia
Knowledge Sources
Domains Model_Management, Provider_Management
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for probing and caching model availability across CLI providers with signature-based caching and concurrency-limited probes, provided by the Agent Teams application.

Description

The CliProviderModelAvailabilityService class determines which models a CLI provider can actually serve by spawning lightweight CLI probe queries. Results are cached by a provider signature (binary path + model list + env), with a queue limiting concurrent probe processes.

Key behaviors:

  • Signature-based cache: `getSnapshot()` builds a signature from the provider ID, binary path, and visible model list. If the signature matches a cached entry, the cached snapshot is cloned and returned.
  • Checking snapshot: On cache miss, a 'checking' snapshot is created and cached immediately, then probes are started asynchronously. The UI shows "checking" until probes complete.
  • Probe queue: Probes are queued when `activeProbeCount` reaches the limit, preventing resource exhaustion.
  • Provider-aware CLI environment: `buildProviderAwareCliEnv()` constructs the environment for the probe, with stored API key decryption disabled for security.
  • Idle snapshots: Providers not eligible for model verification return an idle snapshot immediately.
  • Invalidation: `invalidate()` clears the entire cache and queue, forcing fresh probes on next access.

Usage

  • Model catalog UI: Call `getSnapshot()` to get the current availability state for a provider's models.
  • Pre-launch validation: Check model availability before launching a team to ensure the selected model is actually servable.
  • Cache reset: Call `invalidate()` when a provider's configuration changes (e.g., new API key, new models).

Code Reference

Source Location

  • Repository: agent-teams
  • File: src/main/services/runtime/CliProviderModelAvailabilityService.ts

Signature

export class CliProviderModelAvailabilityService {
  constructor(onUpdate?: ProviderAvailabilityUpdateHandler);

  invalidate(): void;

  getSnapshot(
    context: ProviderModelAvailabilityContext
  ): ProviderModelAvailabilitySnapshot;
}

Import

import { CliProviderModelAvailabilityService } from '@main/services/runtime/CliProviderModelAvailabilityService';

I/O Contract

Inputs

Name Type Required Description
context.provider CliProviderStatus Yes Provider status with model list
context.binaryPath string Yes Path to the CLI binary
onUpdate ProviderAvailabilityUpdateHandler No Callback for availability updates

Outputs

Name Type Description
return ProviderModelAvailabilitySnapshot Availability state per model
snapshot.modelAvailability Array Per-model availability with status
snapshot.status string Aggregate status: 'idle', 'checking', 'ready'

Usage Examples

Checking Model Availability

import { CliProviderModelAvailabilityService } from '@main/services/runtime/CliProviderModelAvailabilityService';

const service = new CliProviderModelAvailabilityService();

const snapshot = service.getSnapshot({
  provider: claudeProviderStatus,
  binaryPath: '/usr/local/bin/claude',
});

for (const model of snapshot.modelAvailability) {
  console.log(`${model.modelId}: ${model.available ? 'available' : 'unavailable'}`);
}

With Update Callback

const service = new CliProviderModelAvailabilityService((snapshot) => {
  // Called when probe results arrive asynchronously
  updateModelCatalogUI(snapshot);
});

// First call returns 'checking' snapshot immediately
const initial = service.getSnapshot(context);
// Later, onUpdate fires with updated availability

Invalidating After Config Change

// When the user changes their API key or provider config,
// invalidate the cache so models are re-probed
service.invalidate();
const fresh = service.getSnapshot(context);  // Starts new probes

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment