diff --git a/.kiro/specs/agent-variants/.config.kiro b/.kiro/specs/agent-variants/.config.kiro new file mode 100644 index 0000000..4092c23 --- /dev/null +++ b/.kiro/specs/agent-variants/.config.kiro @@ -0,0 +1 @@ +{"specId": "ed016b42-56e9-435c-891d-f585c27796df", "workflowType": "requirements-first", "specType": "feature"} diff --git a/.kiro/specs/agent-variants/design.md b/.kiro/specs/agent-variants/design.md new file mode 100644 index 0000000..05e3fb7 --- /dev/null +++ b/.kiro/specs/agent-variants/design.md @@ -0,0 +1,514 @@ +# Design Document: Agent Variants + +## Overview + +Add variant support to the existing AI agents system so each agent can have multiple configurations (different models, prompts, parameters) that can be independently tracked, compared, and swapped into production. This builds on the existing `ai_agents` table, `agent_performance_log` table, API endpoints, and frontend Agents page. + +## Architecture + +### System Context + +``` +┌──────────────┐ ┌──────────────────┐ ┌───────────────┐ +│ Agents Page │────▶│ Query API │────▶│ PostgreSQL │ +│ (React) │ │ (FastAPI) │ │ ai_agents │ +│ │ │ │ │ agent_variants│ +│ - List │ │ /api/agents/ │ │ agent_perf_log│ +│ - Compare │ │ /api/agents/ │ └───────────────┘ +│ - Activate │ │ {id}/variants/ │ +└──────────────┘ └──────────────────┘ + │ + ┌────────┴────────┐ + │ Config Resolver │ + │ (shared module) │ + └────────┬────────┘ + │ + ┌───────────────────┼───────────────────┐ + ▼ ▼ ▼ + ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ + │ Extractor │ │ Event │ │ Thesis │ + │ (client.py) │ │ Classifier │ │ Rewriter │ + └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ + │ │ │ + └──────────────────┼──────────────────┘ + ▼ + ┌──────────────┐ + │ Ollama │ + │ Service │ + └──────────────┘ +``` + +### Key Design Decisions + +1. **Variants as a separate table** (not rows in `ai_agents`): Keeps the parent agent as the canonical role definition. Variants are children that override config fields. This avoids polluting the existing agent table with parent/child semantics and keeps backward compatibility. + +2. **Partial unique index for single-active enforcement**: Rather than application-level logic, a PostgreSQL partial unique index on `(agent_id) WHERE is_active = TRUE` guarantees at most one active variant per agent at the database level. + +3. **Shared config resolver module**: A new `services/shared/agent_config.py` module encapsulates the "resolve active config for an agent slug" logic with TTL caching. All three services import this instead of duplicating resolution logic. + +4. **Nullable variant_id on performance log**: Adding `variant_id` as nullable to `agent_performance_log` preserves backward compatibility — existing rows have NULL, new invocations record the variant when applicable. + +5. **No schema_version on variants**: Variants inherit the parent agent's schema_version since that defines the output structure, not a tuning parameter. Variants override model, prompt, and inference parameters only. + +## Database Schema + +### Migration 027: Agent Variants + +```sql +-- Agent variant configurations: alternative model/prompt/parameter sets per agent. +CREATE TABLE IF NOT EXISTS agent_variants ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + agent_id UUID NOT NULL REFERENCES ai_agents(id) ON DELETE CASCADE, + variant_name VARCHAR(200) NOT NULL, + variant_slug VARCHAR(200) NOT NULL, + description TEXT NOT NULL DEFAULT '', + model_provider VARCHAR(50) NOT NULL DEFAULT 'ollama', + model_name VARCHAR(200) NOT NULL, + system_prompt TEXT NOT NULL DEFAULT '', + user_prompt_template TEXT NOT NULL DEFAULT '', + prompt_version VARCHAR(100) NOT NULL DEFAULT '', + temperature FLOAT DEFAULT 0.0, + max_tokens INTEGER DEFAULT 32768, + context_window INTEGER DEFAULT 0, -- Ollama num_ctx; 0 = use model default + input_token_limit INTEGER DEFAULT 0, -- max input tokens before truncation; 0 = no limit + token_budget INTEGER DEFAULT 0, -- total tokens per hour; 0 = unlimited + timeout_seconds INTEGER DEFAULT 120, + max_retries INTEGER DEFAULT 2, + is_active BOOLEAN NOT NULL DEFAULT FALSE, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +-- Each agent can have many variants, but variant slugs must be unique per agent. +CREATE UNIQUE INDEX IF NOT EXISTS idx_agent_variants_slug + ON agent_variants(agent_id, variant_slug); + +-- At most one active variant per agent (database-enforced invariant). +CREATE UNIQUE INDEX IF NOT EXISTS idx_agent_variants_active + ON agent_variants(agent_id) WHERE is_active = TRUE; + +-- Fast lookup by agent. +CREATE INDEX IF NOT EXISTS idx_agent_variants_agent + ON agent_variants(agent_id); + +-- Add variant_id to performance log for per-variant attribution. +ALTER TABLE agent_performance_log + ADD COLUMN IF NOT EXISTS variant_id UUID REFERENCES agent_variants(id) ON DELETE SET NULL; + +CREATE INDEX IF NOT EXISTS idx_agent_perf_variant + ON agent_performance_log(variant_id, recorded_at DESC); +``` + +### Entity Relationships + +``` +ai_agents (1) ──── (0..*) agent_variants + │ │ + │ │ (variant_id, nullable) + └───── agent_performance_log ◀──┘ + (agent_id, required) +``` + +## API Design + +### Pydantic Models + +```python +class VariantCreateBody(BaseModel): + variant_name: str + variant_slug: str | None = None # auto-generated from name if omitted + description: str = "" + model_provider: str = "ollama" + model_name: str + system_prompt: str = "" + user_prompt_template: str = "" + prompt_version: str = "" + temperature: float = 0.0 + max_tokens: int = 32768 + context_window: int = 0 # Ollama num_ctx; 0 = model default + input_token_limit: int = 0 # max input tokens; 0 = no limit + token_budget: int = 0 # tokens per hour; 0 = unlimited + timeout_seconds: int = 120 + max_retries: int = 2 + +class VariantUpdateBody(BaseModel): + variant_name: str | None = None + description: str | None = None + model_provider: str | None = None + model_name: str | None = None + system_prompt: str | None = None + user_prompt_template: str | None = None + prompt_version: str | None = None + temperature: float | None = None + max_tokens: int | None = None + context_window: int | None = None + input_token_limit: int | None = None + token_budget: int | None = None + timeout_seconds: int | None = None + max_retries: int | None = None + +class VariantCloneBody(BaseModel): + variant_name: str + variant_slug: str | None = None + # All config fields optional — omitted fields inherit from source + description: str | None = None + model_provider: str | None = None + model_name: str | None = None + system_prompt: str | None = None + user_prompt_template: str | None = None + prompt_version: str | None = None + temperature: float | None = None + max_tokens: int | None = None + context_window: int | None = None + input_token_limit: int | None = None + token_budget: int | None = None + timeout_seconds: int | None = None + max_retries: int | None = None +``` + +### Endpoints + +| Method | Path | Description | Req | +|--------|------|-------------|-----| +| GET | `/api/agents/{agent_id}/variants` | List all variants for an agent | 3.1 | +| GET | `/api/agents/{agent_id}/variants/{variant_id}` | Get a single variant | 3.2 | +| POST | `/api/agents/{agent_id}/variants` | Create a variant (direct create) | 3 | +| POST | `/api/agents/{agent_id}/clone` | Clone agent as variant | 2.1 | +| POST | `/api/agents/{agent_id}/variants/{variant_id}/clone` | Clone variant as new variant | 2.2 | +| PUT | `/api/agents/{agent_id}/variants/{variant_id}` | Update a variant | 3.4 | +| DELETE | `/api/agents/{agent_id}/variants/{variant_id}` | Delete a variant | 3.5 | +| POST | `/api/agents/{agent_id}/variants/{variant_id}/activate` | Set variant as active | 4.1 | +| POST | `/api/agents/{agent_id}/variants/deactivate` | Deactivate current active variant | 4.2 | +| GET | `/api/agents/{agent_id}/variants/{variant_id}/performance` | Variant performance metrics | 6.3 | +| GET | `/api/agents/{agent_id}/variants/{variant_id}/performance/history` | Variant performance time-series | 6.4 | + +### Clone Endpoint Logic (POST `/api/agents/{agent_id}/clone`) + +```python +# 1. Fetch source agent +agent = await pool.fetchrow("SELECT * FROM ai_agents WHERE id = $1", agent_id) + +# 2. Build variant record: start with agent fields, overlay user overrides +variant_data = { + "model_provider": body.model_provider or agent["model_provider"], + "model_name": body.model_name or agent["model_name"], + "system_prompt": body.system_prompt if body.system_prompt is not None else agent["system_prompt"], + # ... etc for all config fields +} + +# 3. Generate slug if not provided +slug = body.variant_slug or slugify(body.variant_name) + +# 4. Insert into agent_variants +row = await pool.fetchrow( + "INSERT INTO agent_variants (...) VALUES (...) RETURNING *", + agent_id, body.variant_name, slug, **variant_data +) +``` + +### Activate Endpoint Logic (POST `.../activate`) + +```python +# Single transaction: deactivate previous, activate target +async with pool.acquire() as conn: + async with conn.transaction(): + await conn.execute( + "UPDATE agent_variants SET is_active = FALSE, updated_at = NOW() " + "WHERE agent_id = $1 AND is_active = TRUE", agent_id + ) + row = await conn.fetchrow( + "UPDATE agent_variants SET is_active = TRUE, updated_at = NOW() " + "WHERE id = $1 AND agent_id = $2 RETURNING *", + variant_id, agent_id + ) +``` + +## Config Resolution Module + +### `services/shared/agent_config.py` + +```python +@dataclass +class ResolvedAgentConfig: + """Runtime configuration resolved from DB agent + optional active variant.""" + agent_id: str + variant_id: str | None + model_provider: str + model_name: str + system_prompt: str + user_prompt_template: str + prompt_version: str + temperature: float + max_tokens: int + context_window: int + input_token_limit: int + token_budget: int + timeout_seconds: int + max_retries: int + +class AgentConfigResolver: + """Resolves agent configuration from DB with active variant override and TTL cache.""" + + def __init__(self, pool: asyncpg.Pool, ttl_seconds: int = 60): + self._pool = pool + self._ttl = ttl_seconds + self._cache: dict[str, tuple[float, ResolvedAgentConfig]] = {} + + async def resolve(self, agent_slug: str) -> ResolvedAgentConfig | None: + """Resolve config for an agent slug, preferring active variant if present.""" + now = time.monotonic() + cached = self._cache.get(agent_slug) + if cached and (now - cached[0]) < self._ttl: + return cached[1] + + # Query: LEFT JOIN active variant onto agent + row = await self._pool.fetchrow(""" + SELECT a.id AS agent_id, + v.id AS variant_id, + COALESCE(v.model_provider, a.model_provider) AS model_provider, + COALESCE(v.model_name, a.model_name) AS model_name, + COALESCE(v.system_prompt, a.system_prompt) AS system_prompt, + COALESCE(v.user_prompt_template, a.user_prompt_template) AS user_prompt_template, + COALESCE(v.prompt_version, a.prompt_version) AS prompt_version, + COALESCE(v.temperature, a.temperature) AS temperature, + COALESCE(v.max_tokens, a.max_tokens) AS max_tokens, + COALESCE(v.context_window, 0) AS context_window, + COALESCE(v.input_token_limit, 0) AS input_token_limit, + COALESCE(v.token_budget, 0) AS token_budget, + COALESCE(v.timeout_seconds, a.timeout_seconds) AS timeout_seconds, + COALESCE(v.max_retries, a.max_retries) AS max_retries + FROM ai_agents a + LEFT JOIN agent_variants v ON v.agent_id = a.id AND v.is_active = TRUE + WHERE a.slug = $1 AND a.active = TRUE + """, agent_slug) + + if not row: + return None + + config = ResolvedAgentConfig( + agent_id=str(row["agent_id"]), + variant_id=str(row["variant_id"]) if row["variant_id"] else None, + model_provider=row["model_provider"], + model_name=row["model_name"], + system_prompt=row["system_prompt"], + user_prompt_template=row["user_prompt_template"], + prompt_version=row["prompt_version"], + temperature=row["temperature"], + max_tokens=row["max_tokens"], + context_window=row["context_window"], + input_token_limit=row["input_token_limit"], + token_budget=row["token_budget"], + timeout_seconds=row["timeout_seconds"], + max_retries=row["max_retries"], + ) + self._cache[agent_slug] = (now, config) + return config +``` + +## Service Integration Points + +### Document Extractor (`services/extractor/client.py`) + +The `OllamaClient` currently receives an `OllamaConfig` at construction time. Integration approach: + +1. Before creating `OllamaClient`, call `resolver.resolve("document-extractor")` +2. If resolved, build an `OllamaConfig` from the resolved values +3. If resolution fails (DB down), fall back to env-var `OllamaConfig()` +4. Pass resolved config to `OllamaClient.__init__` +5. After extraction, log to `agent_performance_log` with both `agent_id` and `variant_id` + +### Event Classifier (`services/extractor/event_classifier.py`) + +The `classify_global_event` function receives an `ollama_client` (OllamaClient). Same pattern: + +1. Resolve config via `resolver.resolve("event-classifier")` +2. If resolved, construct an OllamaClient with the resolved config +3. Pass the variant_id through to performance logging + +### Thesis Rewriter (`services/recommendation/thesis_llm.py`) + +The `rewrite_thesis_with_llm` function receives an `OllamaConfig` directly: + +1. Resolve config via `resolver.resolve("thesis-rewriter")` +2. If resolved, override the `config` parameter with resolved values +3. Log variant_id in performance metrics + +### Performance Logging Changes + +The existing `agent_performance_log` INSERT statements need to include `variant_id`: + +```python +await pool.execute( + """INSERT INTO agent_performance_log + (agent_id, variant_id, document_id, ticker, success, duration_ms, + confidence, retry_count, input_tokens, output_tokens, error_message) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)""", + agent_id, variant_id, # variant_id may be None + document_id, ticker, success, duration_ms, + confidence, retry_count, input_tokens, output_tokens, error_message, +) +``` + +## Frontend Design + +### Agents Page Changes + +The existing `AgentsPage` component gets extended with variant management. The layout stays the same (sidebar + detail panel), with variant sections added inside the detail panel. + +### Component Hierarchy + +``` +AgentsPage +├── AgentListSidebar (existing) +├── AgentDetail (existing, extended) +│ ├── Agent config card (existing) +│ ├── Agent performance card (existing) +│ ├── VariantList (new) +│ │ ├── VariantRow (name, model, active badge, actions) +│ │ └── "Clone as Variant" button +│ ├── VariantCompare (new, shown when 2+ variants selected) +│ │ ├── MetricsComparisonTable +│ │ └── OverlayPerformanceChart +│ └── VariantDetail (new, shown when single variant selected) +│ ├── Variant config card +│ └── Variant performance card +├── VariantCreateForm (new) +├── VariantEditForm (new) +└── VariantCloneForm (new) +``` + +### New TanStack Query Hooks + +```typescript +// api/hooks.ts additions +function useAgentVariants(agentId: string | undefined) +function useVariantPerformance(agentId: string, variantId: string, hours?: number) +function useVariantPerfHistory(agentId: string, variantId: string, hours?: number) + +// Mutations +function useCloneAgentAsVariant(agentId: string) +function useCloneVariant(agentId: string, variantId: string) +function useCreateVariant(agentId: string) +function useUpdateVariant(agentId: string, variantId: string) +function useDeleteVariant(agentId: string, variantId: string) +function useActivateVariant(agentId: string, variantId: string) +function useDeactivateVariants(agentId: string) +``` + +### TypeScript Types + +```typescript +interface AgentVariant { + id: string; + agent_id: string; + variant_name: string; + variant_slug: string; + description: string; + model_provider: string; + model_name: string; + system_prompt: string; + user_prompt_template: string; + prompt_version: string; + temperature: number; + max_tokens: number; + context_window: number; + input_token_limit: number; + token_budget: number; + timeout_seconds: number; + max_retries: number; + is_active: boolean; + created_at: string; + updated_at: string; +} +``` + +### Comparison View Behavior + +1. Each `VariantRow` has a checkbox for comparison selection +2. When 2+ variants are checked, `VariantCompare` renders above the variant list +3. Comparison table shows metrics side-by-side (columns = variants) +4. Chart overlays performance history lines for selected variants on shared axes +5. "Activate" button in comparison view calls the activate endpoint and invalidates queries + +## Correctness Properties + +### Property 1: Single Active Variant Invariant (Req 1.4, 4.1) + +For any sequence of activate/deactivate operations on variants of an agent, at most one variant per agent has `is_active = TRUE` at any point in time. + +- **Test approach**: Property-based test generating random sequences of create-variant + activate + deactivate operations, then asserting the DB invariant holds after each operation. +- **Generator**: Random agent with 1-5 variants, random sequence of 1-20 activate/deactivate calls. +- **Assertion**: `SELECT COUNT(*) FROM agent_variants WHERE agent_id = $1 AND is_active = TRUE` returns 0 or 1. + +### Property 2: Clone Preserves Unoverridden Fields (Req 2.1, 2.3) + +For any agent and any subset of override fields, cloning produces a variant where: overridden fields match the override values, and non-overridden fields match the source agent's values. + +- **Test approach**: Property-based test generating random agent configs and random subsets of overrides. +- **Generator**: Random agent config (model_name, temperature, max_tokens, etc.) + random subset of override values. +- **Assertion**: For each field, if an override was provided the variant has the override value; otherwise it matches the source. + +### Property 3: Config Resolution Prefers Active Variant (Req 4.3, 4.4, 9.1-9.3) + +For any agent with N variants, `AgentConfigResolver.resolve(slug)` returns the active variant's config when one exists, and the base agent config when none is active. + +- **Test approach**: Property-based test. Generate agent + 0-5 variants with 0 or 1 active. Resolve and verify returned config matches the expected source. +- **Generator**: Random agent config, random variant configs, random active/inactive state. +- **Assertion**: If an active variant exists, all config fields in the resolved result match the variant. If no active variant, all fields match the base agent. + +### Property 4: Variant Performance Metrics Consistency (Req 6.3, 6.5) + +For any agent with variants and performance log entries, the agent-level aggregated metrics are always >= variant-level metrics for any single variant (since agent-level includes all variants). + +- **Test approach**: Property-based test. Generate performance log entries attributed to different variants of the same agent. Query agent-level and variant-level metrics. Assert agent total >= variant total for each metric. +- **Generator**: Random agent with 2-4 variants, 5-50 random performance log entries distributed across variants. +- **Assertion**: `agent.total_invocations >= variant.total_invocations` for each variant. Same for success count, token totals. + +### Property 5: Partial Update Idempotence (Req 3.4) + +For any variant, applying an update with a subset of fields, then applying the same update again, produces the same variant state (ignoring updated_at). The update operation is idempotent on the data fields. + +- **Test approach**: Property-based test. Generate a variant, apply random partial update, read result, apply same update again, read result. Assert all fields except updated_at are identical. +- **Generator**: Random variant + random subset of updatable fields with random values. +- **Assertion**: `variant_after_first_update.fields == variant_after_second_update.fields` (excluding updated_at). + +### Property 6: TTL Cache Expiry (Req 9.5) + +Within the TTL window, the resolver returns cached config without querying the DB. After TTL expires, the resolver re-queries and reflects any changes. + +- **Test approach**: Property-based test. Resolve config, change the active variant in the DB, resolve again within TTL (should get old value), advance time past TTL, resolve again (should get new value). +- **Generator**: Random agent configs with different variant configs. Random TTL values (1-120s). +- **Assertion**: Pre-TTL resolve returns original config. Post-TTL resolve returns updated config. + +### Property 7: Slug Auto-Generation Determinism (Req 2.4) + +For any variant_name, the auto-generated slug is deterministic (same name → same slug), is a valid kebab-case string (lowercase, alphanumeric + hyphens, no leading/trailing hyphens), and is non-empty for any non-empty name. + +- **Test approach**: Property-based test over random variant names. +- **Generator**: Random non-empty strings with unicode, spaces, special characters. +- **Assertion**: `slugify(name) == slugify(name)` (deterministic), slug matches `^[a-z0-9]+(-[a-z0-9]+)*$`, slug is non-empty. + +## File Changes Summary + +### New Files +| File | Purpose | +|------|---------| +| `infra/migrations/027_agent_variants.sql` | Migration: agent_variants table + performance log variant_id column | +| `services/shared/agent_config.py` | AgentConfigResolver with TTL cache | + +### Modified Files +| File | Change | +|------|--------| +| `services/api/app.py` | Add variant CRUD, clone, activate/deactivate, performance endpoints + Pydantic models | +| `services/extractor/client.py` | Accept optional resolved config; pass variant_id to perf logging | +| `services/extractor/event_classifier.py` | Use resolver for runtime config; pass variant_id to perf logging | +| `services/recommendation/thesis_llm.py` | Use resolver for runtime config; pass variant_id to perf logging | +| `frontend/src/pages/Agents.tsx` | Add variant list, comparison, create/edit/clone forms, activate/delete actions | +| `frontend/src/test/mocks/handlers.ts` | Add MSW handlers for variant endpoints | + +### Test Files +| File | Purpose | +|------|---------| +| `tests/test_pbt_agent_variants.py` | Property-based tests for variant invariants, clone, config resolution | +| `tests/test_agent_variants_api.py` | Example/edge-case tests for API endpoints | +| `frontend/src/test/pages.test.tsx` | Frontend tests for variant UI components | diff --git a/.kiro/specs/agent-variants/requirements.md b/.kiro/specs/agent-variants/requirements.md new file mode 100644 index 0000000..2fc1f04 --- /dev/null +++ b/.kiro/specs/agent-variants/requirements.md @@ -0,0 +1,142 @@ +# Requirements Document + +## Introduction + +Add variant support to the existing AI agents system. Each agent (Document Intelligence Extractor, Global Event Classifier, Thesis Rewriter) can have multiple variants — different model, prompt, and parameter configurations — enabling A/B testing, model comparison, and iterative prompt engineering. Users can clone agents as variants, track per-variant performance, compare variants side-by-side, and swap which variant is the active one running in production for a given agent role. + +## Glossary + +- **Agent**: A record in the `ai_agents` table representing an AI role (e.g. Document Intelligence Extractor). Each Agent has a purpose, model configuration, and prompts. +- **Variant**: A child configuration of an Agent that inherits the parent Agent's role and purpose but allows independent model, prompt, and parameter overrides. Stored in a new `agent_variants` table. +- **Active_Variant**: The single Variant (or the base Agent configuration) currently designated to execute in production for a given Agent role. Only one Variant per Agent can be active at a time. +- **Base_Configuration**: The original Agent's model, prompt, and parameter settings before any Variant is created. Serves as the default Active_Variant when no Variant has been promoted. +- **Variant_Performance**: Per-invocation metrics (success rate, latency, confidence, token usage) attributed to a specific Variant rather than just the parent Agent. +- **Agents_Page**: The existing React frontend page at `/agents` that displays agent configurations and performance metrics. +- **Ollama_Service**: The local LLM inference service at `ollama.ollama-service.svc.cluster.local:11434` used by all three system agents. +- **Clone_Operation**: The act of creating a new Variant from an existing Agent or Variant, copying all configuration fields while allowing the user to modify them. + +## Requirements + +### Requirement 1: Variant Data Model + +**User Story:** As a developer, I want each agent to support multiple variant configurations stored in the database, so that I can experiment with different models and prompts without modifying the base agent. + +#### Acceptance Criteria + +1. THE Database SHALL store Variant records in an `agent_variants` table with columns: id (UUID), agent_id (FK to ai_agents), variant_name, variant_slug, description, model_provider, model_name, system_prompt, user_prompt_template, prompt_version, temperature, max_tokens, context_window, input_token_limit, token_budget, timeout_seconds, max_retries, is_active (boolean), created_at, and updated_at. +2. WHEN a Variant is created, THE Database SHALL enforce a foreign key constraint from `agent_variants.agent_id` to `ai_agents.id` with ON DELETE CASCADE. +3. THE Database SHALL enforce a unique constraint on the combination of agent_id and variant_slug to prevent duplicate Variant slugs within the same Agent. +4. WHEN a Variant has `is_active` set to TRUE, THE Database SHALL ensure that at most one Variant per Agent has `is_active = TRUE` by using a partial unique index on (agent_id) WHERE is_active = TRUE. +5. THE Database SHALL create indexes on agent_id and on (agent_id, is_active) for efficient lookup of Variants by Agent and Active_Variant resolution. + +### Requirement 2: Clone Agent as Variant + +**User Story:** As a user, I want to clone an existing agent as a variant that inherits the agent's role and purpose but lets me tweak the model, prompt, and parameters, so that I can create experimental configurations quickly. + +#### Acceptance Criteria + +1. WHEN a user submits a clone request for an Agent, THE API SHALL create a new Variant record that copies the Agent's model_provider, model_name, system_prompt, user_prompt_template, prompt_version, temperature, max_tokens, context_window, input_token_limit, token_budget, timeout_seconds, and max_retries into the new Variant. +2. WHEN a user submits a clone request for an existing Variant, THE API SHALL create a new Variant record under the same parent Agent that copies the source Variant's configuration fields. +3. WHEN a Variant is created via clone, THE API SHALL allow the user to override any of the copied configuration fields in the same request. +4. WHEN a Variant is created, THE API SHALL require a variant_name and auto-generate a variant_slug from the variant_name if one is not provided. +5. IF a clone request specifies a variant_slug that already exists for the same Agent, THEN THE API SHALL return a 409 Conflict error with a descriptive message. +6. WHEN a Variant is successfully created, THE API SHALL return the complete Variant record including the generated id and timestamps. + +### Requirement 3: Variant CRUD Operations + +**User Story:** As a user, I want to create, read, update, and delete variants through the API, so that I can manage variant configurations programmatically. + +#### Acceptance Criteria + +1. WHEN a GET request is made to `/api/agents/{agent_id}/variants`, THE API SHALL return a list of all Variant records belonging to the specified Agent, ordered by created_at ascending. +2. WHEN a GET request is made to `/api/agents/{agent_id}/variants/{variant_id}`, THE API SHALL return the full Variant record. +3. IF a GET request references a non-existent Agent or Variant, THEN THE API SHALL return a 404 Not Found error. +4. WHEN a PUT request is made to `/api/agents/{agent_id}/variants/{variant_id}`, THE API SHALL update only the fields provided in the request body and set updated_at to the current timestamp. +5. WHEN a DELETE request is made for a Variant, THE API SHALL remove the Variant record and cascade-delete associated performance log entries. +6. IF a DELETE request targets a Variant that is currently the Active_Variant, THEN THE API SHALL return a 400 Bad Request error indicating the user must deactivate or promote a different Variant first. + +### Requirement 4: Active Variant Swap + +**User Story:** As a user, I want to designate which variant is the active one for a given agent role, so that production inference uses my chosen configuration. + +#### Acceptance Criteria + +1. WHEN a user sends a POST request to `/api/agents/{agent_id}/variants/{variant_id}/activate`, THE API SHALL set `is_active = TRUE` on the specified Variant and set `is_active = FALSE` on any previously active Variant for that Agent, within a single database transaction. +2. WHEN a user sends a POST request to `/api/agents/{agent_id}/variants/deactivate`, THE API SHALL set `is_active = FALSE` on the currently active Variant for that Agent, causing the Agent to fall back to its Base_Configuration. +3. WHEN the extractor, event classifier, or thesis rewriter service resolves its runtime configuration, THE Service SHALL check for an Active_Variant for its Agent and use the Variant's model_name, system_prompt, temperature, max_tokens, context_window, input_token_limit, token_budget, timeout_seconds, and max_retries instead of the Base_Configuration or environment variable defaults. +4. IF no Active_Variant exists for an Agent, THEN THE Service SHALL use the Agent's Base_Configuration from the `ai_agents` table. +5. WHEN an Active_Variant swap occurs, THE API SHALL return the updated Variant record with the new is_active state. + +### Requirement 5: Model Swapping + +**User Story:** As a user, I want to configure variants with different Ollama models (e.g. qwen3.5, llama3.1, gemma2), so that I can compare model quality and performance for each agent role. + +#### Acceptance Criteria + +1. THE Variant record SHALL accept any valid model_name string in the model_name field, enabling the user to specify different Ollama models per Variant. +2. WHEN a Variant specifies a model_name, THE Ollama_Service client SHALL use that model_name in the `/api/chat` request to the Ollama endpoint. +3. WHEN a user updates a Variant's model_name via the API, THE API SHALL validate that the model_name field is a non-empty string and persist the change. +4. THE Agents_Page SHALL display the model_name for each Variant in the variant list, enabling users to see which model each Variant uses at a glance. + +### Requirement 6: Per-Variant Performance Tracking + +**User Story:** As a user, I want performance metrics (success rate, latency, confidence, token usage) tracked per variant, so that I can evaluate which configuration performs best. + +#### Acceptance Criteria + +1. THE Database SHALL add a nullable `variant_id` column (FK to `agent_variants.id`, ON DELETE SET NULL) to the `agent_performance_log` table. +2. WHEN a service invocation uses an Active_Variant, THE Service SHALL record the variant_id in the `agent_performance_log` entry alongside the existing agent_id. +3. WHEN a GET request is made to `/api/agents/{agent_id}/variants/{variant_id}/performance`, THE API SHALL return aggregated Variant_Performance metrics (total invocations, success count, failure count, average duration, p95 duration, average confidence, average retries, total input tokens, total output tokens, success rate) for the specified Variant within the requested time window. +4. WHEN a GET request is made to `/api/agents/{agent_id}/variants/{variant_id}/performance/history`, THE API SHALL return hourly time-series Variant_Performance data for the specified Variant. +5. WHEN performance is queried for the base Agent without a variant filter, THE API SHALL continue to return metrics across all invocations for that Agent, including those attributed to Variants. + +### Requirement 7: Side-by-Side Variant Comparison + +**User Story:** As a user, I want to compare two or more variants side-by-side on the Agents page, so that I can make informed decisions about which variant to activate. + +#### Acceptance Criteria + +1. WHEN a user selects an Agent on the Agents_Page, THE Agents_Page SHALL display a list of all Variants for that Agent below the Agent detail section, showing variant_name, model_name, is_active status, and creation date for each. +2. WHEN a user selects two or more Variants for comparison, THE Agents_Page SHALL display a comparison view showing performance metrics (success rate, average latency, p95 latency, average confidence, total tokens) for each selected Variant in adjacent columns. +3. THE Agents_Page SHALL visually highlight the Active_Variant in the variant list with a distinct badge or indicator. +4. WHEN a user views the comparison view, THE Agents_Page SHALL display a time-series chart overlaying the performance history of the selected Variants on the same axes for direct visual comparison. +5. THE Agents_Page SHALL provide an "Activate" button next to each non-active Variant in the list, allowing the user to promote a Variant to Active_Variant directly from the comparison view. + +### Requirement 8: Variant UI Management + +**User Story:** As a user, I want to create, edit, clone, and delete variants from the Agents page, so that I can manage variant configurations without leaving the dashboard. + +#### Acceptance Criteria + +1. WHEN a user clicks "Clone as Variant" on an Agent detail view, THE Agents_Page SHALL open a pre-filled form with the Agent's current configuration, allowing the user to modify fields and submit to create a new Variant. +2. WHEN a user clicks "Clone" on an existing Variant, THE Agents_Page SHALL open a pre-filled form with that Variant's configuration for creating a new Variant. +3. WHEN a user clicks "Edit" on a Variant, THE Agents_Page SHALL display an edit form pre-populated with the Variant's current configuration, allowing modification and save. +4. WHEN a user clicks "Delete" on a non-active Variant, THE Agents_Page SHALL display a confirmation dialog before deleting the Variant. +5. IF a user attempts to delete the Active_Variant, THEN THE Agents_Page SHALL display an error message indicating the user must deactivate the Variant first. +6. WHEN a Variant is created, edited, activated, or deleted, THE Agents_Page SHALL refresh the variant list and performance data to reflect the change. + +### Requirement 10: Token Window and Budget Controls + +**User Story:** As a user, I want to configure context window sizes, input token limits, and hourly token budgets per variant, so that I can control resource usage for cloud models while running unlimited for local Ollama. + +#### Acceptance Criteria + +1. THE Variant record SHALL include a `context_window` integer field (default 0) that maps to the Ollama `num_ctx` parameter. A value of 0 means use the model's default context window. +2. THE Variant record SHALL include an `input_token_limit` integer field (default 0) that caps how many tokens are sent as input to the model. A value of 0 means no limit (no truncation). +3. THE Variant record SHALL include a `token_budget` integer field (default 0) representing the maximum total tokens (input + output) allowed per hour for the variant. A value of 0 means unlimited. +4. WHEN a service invocation uses an Active_Variant with a non-zero `context_window`, THE Ollama_Service client SHALL pass `num_ctx` in the Ollama API options. +5. WHEN a service invocation uses an Active_Variant with a non-zero `input_token_limit`, THE Service SHALL truncate the input content to approximately that many tokens before sending it to the model. +6. WHEN a service invocation uses an Active_Variant with a non-zero `token_budget` and the hourly token usage for that variant has reached or exceeded the budget, THE Service SHALL skip the invocation and log a warning. +7. THE Agents_Page SHALL display context_window, input_token_limit, and token_budget fields in the variant create, edit, and clone forms, with clear labels indicating that 0 means "use default" or "unlimited". + + + +**User Story:** As a developer, I want the extractor, event classifier, and thesis rewriter services to dynamically resolve their configuration from the database (including active variant overrides), so that variant swaps take effect without restarting services. + +#### Acceptance Criteria + +1. WHEN the Document Intelligence Extractor service prepares an inference request, THE Service SHALL query the `ai_agents` table (joined with `agent_variants` if an Active_Variant exists) by the agent slug `document-extractor` to resolve model_name, system_prompt, temperature, max_tokens, context_window, input_token_limit, token_budget, timeout_seconds, and max_retries. +2. WHEN the Global Event Classifier service prepares a classification request, THE Service SHALL query the database by the agent slug `event-classifier` to resolve runtime configuration, preferring the Active_Variant's values when one exists. +3. WHEN the Thesis Rewriter service prepares a rewrite request, THE Service SHALL query the database by the agent slug `thesis-rewriter` to resolve runtime configuration, preferring the Active_Variant's values when one exists. +4. IF the database is unreachable during configuration resolution, THEN THE Service SHALL fall back to the environment variable defaults from OllamaConfig and log a warning. +5. THE Service SHALL cache resolved configuration with a time-to-live of 60 seconds to avoid querying the database on every invocation, while still reflecting Active_Variant swaps within a reasonable delay. diff --git a/.kiro/specs/agent-variants/tasks.md b/.kiro/specs/agent-variants/tasks.md new file mode 100644 index 0000000..cde74cc --- /dev/null +++ b/.kiro/specs/agent-variants/tasks.md @@ -0,0 +1,108 @@ +# Implementation Tasks: Agent Variants + +## Phase 1: Database Schema + +- [x] 1.1 Create migration `infra/migrations/027_agent_variants.sql` + - [x] 1.1.1 Create `agent_variants` table with columns: id (UUID PK), agent_id (UUID FK to ai_agents ON DELETE CASCADE), variant_name (VARCHAR 200 NOT NULL), variant_slug (VARCHAR 200 NOT NULL), description (TEXT DEFAULT ''), model_provider (VARCHAR 50 DEFAULT 'ollama'), model_name (VARCHAR 200 NOT NULL), system_prompt (TEXT DEFAULT ''), user_prompt_template (TEXT DEFAULT ''), prompt_version (VARCHAR 100 DEFAULT ''), temperature (FLOAT DEFAULT 0.0), max_tokens (INTEGER DEFAULT 32768), context_window (INTEGER DEFAULT 0), input_token_limit (INTEGER DEFAULT 0), token_budget (INTEGER DEFAULT 0), timeout_seconds (INTEGER DEFAULT 120), max_retries (INTEGER DEFAULT 2), is_active (BOOLEAN DEFAULT FALSE), created_at (TIMESTAMPTZ DEFAULT NOW()), updated_at (TIMESTAMPTZ DEFAULT NOW()) + - [x] 1.1.2 Create unique index `idx_agent_variants_slug` on (agent_id, variant_slug) to prevent duplicate slugs per agent + - [x] 1.1.3 Create partial unique index `idx_agent_variants_active` on (agent_id) WHERE is_active = TRUE to enforce at most one active variant per agent + - [x] 1.1.4 Create index `idx_agent_variants_agent` on (agent_id) for fast lookup + - [x] 1.1.5 Add nullable `variant_id` column (UUID FK to agent_variants ON DELETE SET NULL) to `agent_performance_log` table + - [x] 1.1.6 Create index `idx_agent_perf_variant` on (variant_id, recorded_at DESC) on `agent_performance_log` + +## Phase 2: Config Resolution Module + +- [x] 2.1 Create `services/shared/agent_config.py` with AgentConfigResolver + - [x] 2.1.1 Define `ResolvedAgentConfig` dataclass with fields: agent_id, variant_id (optional), model_provider, model_name, system_prompt, user_prompt_template, prompt_version, temperature, max_tokens, context_window, input_token_limit, token_budget, timeout_seconds, max_retries + - [x] 2.1.2 Implement `AgentConfigResolver.__init__` accepting asyncpg.Pool and ttl_seconds (default 60) + - [x] 2.1.3 Implement `AgentConfigResolver.resolve(agent_slug)` that queries ai_agents LEFT JOIN agent_variants (WHERE is_active = TRUE) using COALESCE to prefer variant values, with TTL-based in-memory cache + - [x] 2.1.4 Implement cache invalidation: entries expire after ttl_seconds; return None and log warning if DB query fails (callers fall back to env-var defaults) + +## Phase 3: Backend API Endpoints + +- [x] 3.1 Add Pydantic models for variant operations in `services/api/app.py` + - [x] 3.1.1 Add `VariantCreateBody` model with fields: variant_name (str), variant_slug (str | None), description (str = ""), model_provider (str = "ollama"), model_name (str), system_prompt (str = ""), user_prompt_template (str = ""), prompt_version (str = ""), temperature (float = 0.0), max_tokens (int = 32768), context_window (int = 0), input_token_limit (int = 0), token_budget (int = 0), timeout_seconds (int = 120), max_retries (int = 2) + - [x] 3.1.2 Add `VariantUpdateBody` model with all config fields optional (str | None, float | None, int | None) + - [x] 3.1.3 Add `VariantCloneBody` model with variant_name (str), variant_slug (str | None), and all config fields optional for overrides + - [x] 3.1.4 Add slug auto-generation helper: `_slugify(name: str) -> str` that lowercases, replaces non-alphanumeric with hyphens, strips leading/trailing hyphens + +- [x] 3.2 Add variant CRUD endpoints in `services/api/app.py` + - [x] 3.2.1 `GET /api/agents/{agent_id}/variants` — list all variants for an agent ordered by created_at ASC, return list of variant dicts + - [x] 3.2.2 `GET /api/agents/{agent_id}/variants/{variant_id}` — get single variant, return 404 if not found or agent mismatch + - [x] 3.2.3 `POST /api/agents/{agent_id}/variants` — create variant with VariantCreateBody, auto-generate slug if not provided, return 409 on duplicate slug, return 201 with created variant + - [x] 3.2.4 `PUT /api/agents/{agent_id}/variants/{variant_id}` — partial update with VariantUpdateBody, set updated_at = NOW(), return 404 if not found + - [x] 3.2.5 `DELETE /api/agents/{agent_id}/variants/{variant_id}` — delete variant, return 400 if variant is currently active (is_active = TRUE), return 404 if not found + +- [x] 3.3 Add clone endpoints in `services/api/app.py` + - [x] 3.3.1 `POST /api/agents/{agent_id}/clone` — clone agent as variant: fetch agent by id, build variant fields from agent config with VariantCloneBody overrides, auto-generate slug, insert into agent_variants, return 201 + - [x] 3.3.2 `POST /api/agents/{agent_id}/variants/{variant_id}/clone` — clone variant as new variant: fetch source variant, build new variant fields with overrides, insert, return 201 + +- [x] 3.4 Add activate/deactivate endpoints in `services/api/app.py` + - [x] 3.4.1 `POST /api/agents/{agent_id}/variants/{variant_id}/activate` — within a transaction: set is_active = FALSE on current active variant for agent, then set is_active = TRUE on target variant, return updated variant + - [x] 3.4.2 `POST /api/agents/{agent_id}/variants/deactivate` — set is_active = FALSE on current active variant for agent, return {"deactivated": true} + +- [x] 3.5 Add per-variant performance endpoints in `services/api/app.py` + - [x] 3.5.1 `GET /api/agents/{agent_id}/variants/{variant_id}/performance` — aggregated metrics (total invocations, successes, failures, avg/p95 duration, avg confidence, avg retries, total tokens, success rate) filtered by variant_id and time window + - [x] 3.5.2 `GET /api/agents/{agent_id}/variants/{variant_id}/performance/history` — hourly time-series filtered by variant_id + +## Phase 4: Service Integration + +- [x] 4.1 Integrate config resolver into Document Extractor + - [x] 4.1.1 In the extractor service startup or invocation path, instantiate AgentConfigResolver and call `resolve("document-extractor")` to get runtime config; fall back to OllamaConfig() from env vars if resolve returns None or raises + - [x] 4.1.2 Build OllamaConfig from ResolvedAgentConfig fields (model_name → config.model, system_prompt, temperature, max_tokens, timeout, max_retries) + - [x] 4.1.3 Update performance logging to include variant_id from the resolved config when inserting into agent_performance_log + +- [x] 4.2 Integrate config resolver into Event Classifier + - [x] 4.2.1 In classify_global_event or its caller, resolve config for "event-classifier" slug; fall back to existing OllamaConfig if resolution fails + - [x] 4.2.2 Use resolved model_name and system_prompt when building the Ollama request + - [x] 4.2.3 Pass variant_id to performance log entries + +- [x] 4.3 Integrate config resolver into Thesis Rewriter + - [x] 4.3.1 In rewrite_thesis_with_llm or its caller, resolve config for "thesis-rewriter" slug; fall back to passed OllamaConfig if resolution fails + - [x] 4.3.2 Override OllamaConfig fields with resolved values (model, timeout, max_retries) + - [x] 4.3.3 Pass variant_id to performance log entries if performance logging exists for thesis rewrites + +## Phase 5: Frontend — Variant List and Detail + +- [x] 5.1 Add TypeScript types and API hooks for variants + - [x] 5.1.1 Add `AgentVariant` interface to Agents.tsx with fields: id, agent_id, variant_name, variant_slug, description, model_provider, model_name, system_prompt, user_prompt_template, prompt_version, temperature, max_tokens, context_window, input_token_limit, token_budget, timeout_seconds, max_retries, is_active, created_at, updated_at + - [x] 5.1.2 Add `useAgentVariants(agentId)` query hook fetching `GET /api/agents/{agentId}/variants` + - [x] 5.1.3 Add `useVariantPerformance(agentId, variantId, hours)` query hook + - [x] 5.1.4 Add `useVariantPerfHistory(agentId, variantId, hours)` query hook + - [x] 5.1.5 Add mutation hooks: `useCloneAgentAsVariant`, `useCreateVariant`, `useUpdateVariant`, `useDeleteVariant`, `useActivateVariant`, `useDeactivateVariants` — each invalidates `['agent-variants']` query on success + +- [x] 5.2 Add VariantList component to AgentDetail + - [x] 5.2.1 Create `VariantList` component that renders a table/list of variants for the selected agent showing: variant_name, model_name, is_active badge, created_at, and action buttons (Edit, Clone, Delete, Activate) + - [x] 5.2.2 Add "Clone as Variant" button to the AgentDetail header that opens the clone form pre-filled with agent config + - [x] 5.2.3 Highlight the active variant row with a distinct badge (e.g. green "Active" StatusBadge) + - [x] 5.2.4 Wire Activate button to call the activate endpoint and invalidate queries; disable on the already-active variant + +- [x] 5.3 Add Variant Create/Edit/Clone forms + - [x] 5.3.1 Create `VariantCloneForm` component pre-filled with source (agent or variant) config fields, allowing modification before submit; uses useCloneAgentAsVariant or clone-variant mutation + - [x] 5.3.2 Create `VariantEditForm` component pre-filled with current variant config, using useUpdateVariant mutation + - [x] 5.3.3 Add delete confirmation dialog: show warning, call useDeleteVariant on confirm; show error toast if variant is active (400 response) + +## Phase 6: Frontend — Comparison View + +- [x] 6.1 Add variant comparison UI + - [x] 6.1.1 Add checkbox selection to each VariantRow; track selected variant IDs in component state + - [x] 6.1.2 Create `VariantCompare` component that renders when 2+ variants are selected: shows a table with one column per selected variant, rows for each metric (success rate, avg latency, p95 latency, avg confidence, total tokens) + - [x] 6.1.3 Add an overlay performance chart in VariantCompare: use Recharts LineChart with one Line per selected variant, shared XAxis (hour), showing success rate or latency over time + - [x] 6.1.4 Add "Activate" button in comparison view for each non-active variant column + +## Phase 7: Tests + +- [x] 7.1 Add backend tests for variant API + - [x] 7.1.1 Add `tests/test_agent_variants_api.py` with example tests for: create variant, clone from agent, clone from variant, list variants, get variant, update variant, delete variant, delete active variant (expect 400), activate/deactivate, variant performance queries + - [x] 7.1.2 Add edge-case tests: duplicate slug (409), non-existent agent (404), non-existent variant (404), empty model_name validation + +- [x] 7.2 Add property-based tests for variant logic + - [x] 7.2.1 [PBT] Property: Single active variant invariant — generate random sequences of activate/deactivate operations, assert at most one active variant per agent after each operation + - [x] 7.2.2 [PBT] Property: Clone preserves unoverridden fields — generate random agent configs and random override subsets, assert non-overridden fields match source + - [x] 7.2.3 [PBT] Property: Config resolution prefers active variant — generate agent + variants with random active state, assert resolver returns correct config source + - [x] 7.2.4 [PBT] Property: Slug auto-generation determinism — generate random names, assert slugify is deterministic, produces valid kebab-case, and is non-empty for non-empty input + - [x] 7.2.5 [PBT] Property: Partial update idempotence — generate variant + random update subset, apply twice, assert fields match (excluding updated_at) + +- [x] 7.3 Add frontend tests + - [x] 7.3.1 Add MSW handlers in `frontend/src/test/mocks/handlers.ts` for all variant endpoints (list, get, create, clone, update, delete, activate, deactivate, performance, history) + - [x] 7.3.2 Add test in `frontend/src/test/pages.test.tsx` verifying the Agents page renders variant list when an agent is selected, and that the comparison view appears when multiple variants are checked diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 3e82ea8..56dd797 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -369,9 +369,9 @@ } }, "node_modules/@csstools/css-calc": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-3.1.1.tgz", - "integrity": "sha512-HJ26Z/vmsZQqs/o3a6bgKslXGFAungXGbinULZO3eMsOyNJHeBBZfup5FiZInOghgoM4Hwnmw+OgbJCNg1wwUQ==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-3.2.0.tgz", + "integrity": "sha512-bR9e6o2BDB12jzN/gIbjHa5wLJ4UjD1CB9pM7ehlc0ddk6EBz+yYS1EV2MF55/HUxrHcB/hehAyt5vhsA3hx7w==", "dev": true, "funding": [ { @@ -393,9 +393,9 @@ } }, "node_modules/@csstools/css-color-parser": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@csstools/css-color-parser/-/css-color-parser-4.0.2.tgz", - "integrity": "sha512-0GEfbBLmTFf0dJlpsNU7zwxRIH0/BGEMuXLTCvFYxuL1tNhqzTbtnFICyJLTNK4a+RechKP75e7w42ClXSnJQw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@csstools/css-color-parser/-/css-color-parser-4.1.0.tgz", + "integrity": "sha512-U0KhLYmy2GVj6q4T3WaAe6NPuFYCPQoE3b0dRGxejWDgcPp8TP7S5rVdM5ZrFaqu4N67X8YaPBw14dQSYx3IyQ==", "dev": true, "funding": [ { @@ -410,7 +410,7 @@ "license": "MIT", "dependencies": { "@csstools/color-helpers": "^6.0.2", - "@csstools/css-calc": "^3.1.1" + "@csstools/css-calc": "^3.2.0" }, "engines": { "node": ">=20.19.0" @@ -444,9 +444,9 @@ } }, "node_modules/@csstools/css-syntax-patches-for-csstree": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@csstools/css-syntax-patches-for-csstree/-/css-syntax-patches-for-csstree-1.1.2.tgz", - "integrity": "sha512-5GkLzz4prTIpoyeUiIu3iV6CSG3Plo7xRVOFPKI7FVEJ3mZ0A8SwK0XU3Gl7xAkiQ+mDyam+NNp875/C5y+jSA==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@csstools/css-syntax-patches-for-csstree/-/css-syntax-patches-for-csstree-1.1.3.tgz", + "integrity": "sha512-SH60bMfrRCJF3morcdk57WklujF4Jr/EsQUzqkarfHXEFcAR1gg7fS/chAE922Sehgzc1/+Tz5H3Ypa1HiEKrg==", "dev": true, "funding": [ { @@ -921,9 +921,9 @@ } }, "node_modules/@napi-rs/wasm-runtime": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.3.tgz", - "integrity": "sha512-xK9sGVbJWYb08+mTJt3/YV24WxvxpXcXtP6B172paPZ+Ts69Re9dAr7lKwJoeIx8OoeuimEiRZ7umkiUVClmmQ==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.4.tgz", + "integrity": "sha512-3NQNNgA1YSlJb/kMH1ildASP9HW7/7kYnRI2szWJaofaS1hWmbGI4H+d3+22aGzXXN9IJ+n+GiFVcGipJP18ow==", "license": "MIT", "optional": true, "dependencies": { @@ -1566,14 +1566,14 @@ } }, "node_modules/@tanstack/react-router": { - "version": "1.168.18", - "resolved": "https://registry.npmjs.org/@tanstack/react-router/-/react-router-1.168.18.tgz", - "integrity": "sha512-RmBptS3/qtkGhvG/u41JWOgxz1FIWybBz7iBTgLUIoFkqOj6NE4XlhUOsP2fabxACtbZdJnpvCWcJFWpWGIngw==", + "version": "1.168.22", + "resolved": "https://registry.npmjs.org/@tanstack/react-router/-/react-router-1.168.22.tgz", + "integrity": "sha512-W2LyfkfJtDCf//jOjZeUBWwOVl8iDRVTECpGHa2M28MT3T5/VVnjgicYNHR/ax0Filk1iU67MRjcjHheTYvK1Q==", "license": "MIT", "dependencies": { "@tanstack/history": "1.161.6", "@tanstack/react-store": "^0.9.3", - "@tanstack/router-core": "1.168.14", + "@tanstack/router-core": "1.168.15", "isbot": "^5.1.22" }, "engines": { @@ -1607,9 +1607,9 @@ } }, "node_modules/@tanstack/router-core": { - "version": "1.168.14", - "resolved": "https://registry.npmjs.org/@tanstack/router-core/-/router-core-1.168.14.tgz", - "integrity": "sha512-UhCJtjNrd5wcTmhgB2HyUP0+Rj1M7BD4dS11YsF9x6VC2KH/eqxzs/vK+nN5f+cOhPOLZdmLkWMW+WGmacZ8HA==", + "version": "1.168.15", + "resolved": "https://registry.npmjs.org/@tanstack/router-core/-/router-core-1.168.15.tgz", + "integrity": "sha512-Wr0424NDtD8fT/uALobMZ9DdcfsTyXtW5IPR++7zvW8/7RaIOeaqXpVDId8ywaGtqPWLWOfaUg2zUtYtukoXYA==", "license": "MIT", "dependencies": { "@tanstack/history": "1.161.6", @@ -1893,17 +1893,17 @@ "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.58.1.tgz", - "integrity": "sha512-eSkwoemjo76bdXl2MYqtxg51HNwUSkWfODUOQ3PaTLZGh9uIWWFZIjyjaJnex7wXDu+TRx+ATsnSxdN9YWfRTQ==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.58.2.tgz", + "integrity": "sha512-aC2qc5thQahutKjP+cl8cgN9DWe3ZUqVko30CMSZHnFEHyhOYoZSzkGtAI2mcwZ38xeImDucI4dnqsHiOYuuCw==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.12.2", - "@typescript-eslint/scope-manager": "8.58.1", - "@typescript-eslint/type-utils": "8.58.1", - "@typescript-eslint/utils": "8.58.1", - "@typescript-eslint/visitor-keys": "8.58.1", + "@typescript-eslint/scope-manager": "8.58.2", + "@typescript-eslint/type-utils": "8.58.2", + "@typescript-eslint/utils": "8.58.2", + "@typescript-eslint/visitor-keys": "8.58.2", "ignore": "^7.0.5", "natural-compare": "^1.4.0", "ts-api-utils": "^2.5.0" @@ -1916,7 +1916,7 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "@typescript-eslint/parser": "^8.58.1", + "@typescript-eslint/parser": "^8.58.2", "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } @@ -1932,16 +1932,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.58.1.tgz", - "integrity": "sha512-gGkiNMPqerb2cJSVcruigx9eHBlLG14fSdPdqMoOcBfh+vvn4iCq2C8MzUB89PrxOXk0y3GZ1yIWb9aOzL93bw==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.58.2.tgz", + "integrity": "sha512-/Zb/xaIDfxeJnvishjGdcR4jmr7S+bda8PKNhRGdljDM+elXhlvN0FyPSsMnLmJUrVG9aPO6dof80wjMawsASg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "8.58.1", - "@typescript-eslint/types": "8.58.1", - "@typescript-eslint/typescript-estree": "8.58.1", - "@typescript-eslint/visitor-keys": "8.58.1", + "@typescript-eslint/scope-manager": "8.58.2", + "@typescript-eslint/types": "8.58.2", + "@typescript-eslint/typescript-estree": "8.58.2", + "@typescript-eslint/visitor-keys": "8.58.2", "debug": "^4.4.3" }, "engines": { @@ -1957,14 +1957,14 @@ } }, "node_modules/@typescript-eslint/project-service": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.58.1.tgz", - "integrity": "sha512-gfQ8fk6cxhtptek+/8ZIqw8YrRW5048Gug8Ts5IYcMLCw18iUgrZAEY/D7s4hkI0FxEfGakKuPK/XUMPzPxi5g==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.58.2.tgz", + "integrity": "sha512-Cq6UfpZZk15+r87BkIh5rDpi38W4b+Sjnb8wQCPPDDweS/LRCFjCyViEbzHk5Ck3f2QDfgmlxqSa7S7clDtlfg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/tsconfig-utils": "^8.58.1", - "@typescript-eslint/types": "^8.58.1", + "@typescript-eslint/tsconfig-utils": "^8.58.2", + "@typescript-eslint/types": "^8.58.2", "debug": "^4.4.3" }, "engines": { @@ -1979,14 +1979,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.58.1.tgz", - "integrity": "sha512-TPYUEqJK6avLcEjumWsIuTpuYODTTDAtoMdt8ZZa93uWMTX13Nb8L5leSje1NluammvU+oI3QRr5lLXPgihX3w==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.58.2.tgz", + "integrity": "sha512-SgmyvDPexWETQek+qzZnrG6844IaO02UVyOLhI4wpo82dpZJY9+6YZCKAMFzXb7qhx37mFK1QcPQ18tud+vo6Q==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.58.1", - "@typescript-eslint/visitor-keys": "8.58.1" + "@typescript-eslint/types": "8.58.2", + "@typescript-eslint/visitor-keys": "8.58.2" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1997,9 +1997,9 @@ } }, "node_modules/@typescript-eslint/tsconfig-utils": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.58.1.tgz", - "integrity": "sha512-JAr2hOIct2Q+qk3G+8YFfqkqi7sC86uNryT+2i5HzMa2MPjw4qNFvtjnw1IiA1rP7QhNKVe21mSSLaSjwA1Olw==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.58.2.tgz", + "integrity": "sha512-3SR+RukipDvkkKp/d0jP0dyzuls3DbGmwDpVEc5wqk5f38KFThakqAAO0XMirWAE+kT00oTauTbzMFGPoAzB0A==", "dev": true, "license": "MIT", "engines": { @@ -2014,15 +2014,15 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.58.1.tgz", - "integrity": "sha512-HUFxvTJVroT+0rXVJC7eD5zol6ID+Sn5npVPWoFuHGg9Ncq5Q4EYstqR+UOqaNRFXi5TYkpXXkLhoCHe3G0+7w==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.58.2.tgz", + "integrity": "sha512-Z7EloNR/B389FvabdGeTo2XMs4W9TjtPiO9DAsmT0yom0bwlPyRjkJ1uCdW1DvrrrYP50AJZ9Xc3sByZA9+dcg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.58.1", - "@typescript-eslint/typescript-estree": "8.58.1", - "@typescript-eslint/utils": "8.58.1", + "@typescript-eslint/types": "8.58.2", + "@typescript-eslint/typescript-estree": "8.58.2", + "@typescript-eslint/utils": "8.58.2", "debug": "^4.4.3", "ts-api-utils": "^2.5.0" }, @@ -2039,9 +2039,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.58.1.tgz", - "integrity": "sha512-io/dV5Aw5ezwzfPBBWLoT+5QfVtP8O7q4Kftjn5azJ88bYyp/ZMCsyW1lpKK46EXJcaYMZ1JtYj+s/7TdzmQMw==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.58.2.tgz", + "integrity": "sha512-9TukXyATBQf/Jq9AMQXfvurk+G5R2MwfqQGDR2GzGz28HvY/lXNKGhkY+6IOubwcquikWk5cjlgPvD2uAA7htQ==", "dev": true, "license": "MIT", "engines": { @@ -2053,16 +2053,16 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.58.1.tgz", - "integrity": "sha512-w4w7WR7GHOjqqPnvAYbazq+Y5oS68b9CzasGtnd6jIeOIeKUzYzupGTB2T4LTPSv4d+WPeccbxuneTFHYgAAWg==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.58.2.tgz", + "integrity": "sha512-ELGuoofuhhoCvNbQjFFiobFcGgcDCEm0ThWdmO4Z0UzLqPXS3KFvnEZ+SHewwOYHjM09tkzOWXNTv9u6Gqtyuw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/project-service": "8.58.1", - "@typescript-eslint/tsconfig-utils": "8.58.1", - "@typescript-eslint/types": "8.58.1", - "@typescript-eslint/visitor-keys": "8.58.1", + "@typescript-eslint/project-service": "8.58.2", + "@typescript-eslint/tsconfig-utils": "8.58.2", + "@typescript-eslint/types": "8.58.2", + "@typescript-eslint/visitor-keys": "8.58.2", "debug": "^4.4.3", "minimatch": "^10.2.2", "semver": "^7.7.3", @@ -2133,16 +2133,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.58.1.tgz", - "integrity": "sha512-Ln8R0tmWC7pTtLOzgJzYTXSCjJ9rDNHAqTaVONF4FEi2qwce8mD9iSOxOpLFFvWp/wBFlew0mjM1L1ihYWfBdQ==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.58.2.tgz", + "integrity": "sha512-QZfjHNEzPY8+l0+fIXMvuQ2sJlplB4zgDZvA+NmvZsZv3EQwOcc1DuIU1VJUTWZ/RKouBMhDyNaBMx4sWvrzRA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.9.1", - "@typescript-eslint/scope-manager": "8.58.1", - "@typescript-eslint/types": "8.58.1", - "@typescript-eslint/typescript-estree": "8.58.1" + "@typescript-eslint/scope-manager": "8.58.2", + "@typescript-eslint/types": "8.58.2", + "@typescript-eslint/typescript-estree": "8.58.2" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2157,13 +2157,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.58.1.tgz", - "integrity": "sha512-y+vH7QE8ycjoa0bWciFg7OpFcipUuem1ujhrdLtq1gByKwfbC7bPeKsiny9e0urg93DqwGcHey+bGRKCnF1nZQ==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.58.2.tgz", + "integrity": "sha512-f1WO2Lx8a9t8DARmcWAUPJbu0G20bJlj8L4z72K00TMeJAoyLr/tHhI/pzYBLrR4dXWkcxO1cWYZEOX8DKHTqA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.58.1", + "@typescript-eslint/types": "8.58.2", "eslint-visitor-keys": "^5.0.0" }, "engines": { @@ -2427,9 +2427,9 @@ "license": "MIT" }, "node_modules/baseline-browser-mapping": { - "version": "2.10.18", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.18.tgz", - "integrity": "sha512-VSnGQAOLtP5mib/DPyg2/t+Tlv65NTBz83BJBJvmLVHHuKJVaDOBvJJykiT5TR++em5nfAySPccDZDa4oSrn8A==", + "version": "2.10.19", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.19.tgz", + "integrity": "sha512-qCkNLi2sfBOn8XhZQ0FXsT1Ki/Yo5P90hrkRamVFRS7/KV9hpfA4HkoWNU152+8w0zPjnxo5psx5NL3PSGgv5g==", "dev": true, "license": "Apache-2.0", "bin": { @@ -2505,9 +2505,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001787", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001787.tgz", - "integrity": "sha512-mNcrMN9KeI68u7muanUpEejSLghOKlVhRqS/Za2IeyGllJ9I9otGpR9g3nsw7n4W378TE/LyIteA0+/FOZm4Kg==", + "version": "1.0.30001788", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001788.tgz", + "integrity": "sha512-6q8HFp+lOQtcf7wBK+uEenxymVWkGKkjFpCvw5W25cmMwEDU45p1xQFBQv8JDlMMry7eNxyBaR+qxgmTUZkIRQ==", "dev": true, "funding": [ { @@ -2912,9 +2912,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.335", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.335.tgz", - "integrity": "sha512-q9n5T4BR4Xwa2cwbrwcsDJtHD/enpQ5S1xF1IAtdqf5AAgqDFmR/aakqH3ChFdqd/QXJhS3rnnXFtexU7rax6Q==", + "version": "1.5.336", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.336.tgz", + "integrity": "sha512-AbH9q9J455r/nLmdNZes0G0ZKcRX73FicwowalLs6ijwOmCJSRRrLX63lcAlzy9ux3dWK1w1+1nsBJEWN11hcQ==", "dev": true, "license": "ISC" }, @@ -3338,9 +3338,9 @@ } }, "node_modules/globals": { - "version": "17.4.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-17.4.0.tgz", - "integrity": "sha512-hjrNztw/VajQwOLsMNT1cbJiH2muO3OROCHnbehc8eY5JyD2gqz4AcMHPqgaOR59DjgUjYAYLeH699g/eWi2jw==", + "version": "17.5.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-17.5.0.tgz", + "integrity": "sha512-qoV+HK2yFl/366t2/Cb3+xxPUo5BuMynomoDmiaZBIdbs+0pYbjfZU+twLhGKp4uCZ/+NbtpVepH5bGCxRyy2g==", "dev": true, "license": "MIT", "engines": { @@ -3527,9 +3527,9 @@ "license": "MIT" }, "node_modules/isbot": { - "version": "5.1.37", - "resolved": "https://registry.npmjs.org/isbot/-/isbot-5.1.37.tgz", - "integrity": "sha512-5bcicX81xf6NlTEV8rWdg7Pk01LFizDetuYGHx6d/f6y3lR2/oo8IfxjzJqn1UdDEyCcwT9e7NRloj8DwCYujQ==", + "version": "5.1.38", + "resolved": "https://registry.npmjs.org/isbot/-/isbot-5.1.38.tgz", + "integrity": "sha512-Cus2702JamTNMEY4zTP+TShgq/3qzjvGcBC4XMOV45BLaxD4iUFENkqu7ZhFeSzwNsCSZLjnGlihDQznnpnEEA==", "license": "Unlicense", "engines": { "node": ">=18" @@ -3613,9 +3613,9 @@ } }, "node_modules/jsdom/node_modules/lru-cache": { - "version": "11.3.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.3.3.tgz", - "integrity": "sha512-JvNw9Y81y33E+BEYPr0U7omo+U9AySnsMsEiXgwT6yqd31VQWTLNQqmT4ou5eqPFUrTfIDFta2wKhB1hyohtAQ==", + "version": "11.3.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.3.5.tgz", + "integrity": "sha512-NxVFwLAnrd9i7KUBxC4DrUhmgjzOs+1Qm50D3oF1/oL+r1NpZ4gA7xvG0/zJ8evR7zIKn4vLf7qTNduWFtCrRw==", "dev": true, "license": "BlueOak-1.0.0", "engines": { @@ -4066,9 +4066,9 @@ "license": "MIT" }, "node_modules/msw": { - "version": "2.13.2", - "resolved": "https://registry.npmjs.org/msw/-/msw-2.13.2.tgz", - "integrity": "sha512-go2H1TIERKkC48pXiwec5l6sbNqYuvqOk3/vHGo1Zd+pq/H63oFawDQerH+WQdUw/flJFHDG7F+QdWMwhntA/A==", + "version": "2.13.3", + "resolved": "https://registry.npmjs.org/msw/-/msw-2.13.3.tgz", + "integrity": "sha512-/F49bxavkNGfreMlrKmTxZs6YorjfMbbDLd89Q3pWi+cXGtQQNXXaHt4MkXN7li91xnQJ24HWXqW9QDm5id33w==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -4084,7 +4084,7 @@ "outvariant": "^1.4.3", "path-to-regexp": "^6.3.0", "picocolors": "^1.1.1", - "rettime": "^0.10.1", + "rettime": "^0.11.7", "statuses": "^2.0.2", "strict-event-emitter": "^0.5.1", "tough-cookie": "^6.0.0", @@ -4299,9 +4299,9 @@ } }, "node_modules/postcss": { - "version": "8.5.9", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.9.tgz", - "integrity": "sha512-7a70Nsot+EMX9fFU3064K/kdHWZqGVY+BADLyXc8Dfv+mTLLVl6JzJpPaCZ2kQL9gIJvKXSLMHhqdRRjwQeFtw==", + "version": "8.5.10", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.10.tgz", + "integrity": "sha512-pMMHxBOZKFU6HgAZ4eyGnwXF/EvPGGqUr0MnZ5+99485wwW41kW91A4LOGxSHhgugZmSChL5AlElNdwlNgcnLQ==", "funding": [ { "type": "opencollective", @@ -4531,9 +4531,9 @@ } }, "node_modules/rettime": { - "version": "0.10.1", - "resolved": "https://registry.npmjs.org/rettime/-/rettime-0.10.1.tgz", - "integrity": "sha512-uyDrIlUEH37cinabq0AX4QbgV4HbFZ/gqoiunWQ1UqBtRvTTytwhNYjE++pO/MjPTZL5KQCf2bEoJ/BJNVQ5Kw==", + "version": "0.11.7", + "resolved": "https://registry.npmjs.org/rettime/-/rettime-0.11.7.tgz", + "integrity": "sha512-DoAm1WjR1eH7z8sHPtvvUMIZh4/CSKkGCz6CxPqOrEAnOGtOuHSnSE9OC+razqxKuf4ub7pAYyl/vZV0vGs5tg==", "dev": true, "license": "MIT" }, @@ -4702,9 +4702,9 @@ } }, "node_modules/std-env": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.0.0.tgz", - "integrity": "sha512-zUMPtQ/HBY3/50VbpkupYHbRroTRZJPRLvreamgErJVys0ceuzMkD44J/QjqhHjOzK42GQ3QZIeFG1OYfOtKqQ==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.1.0.tgz", + "integrity": "sha512-Rq7ybcX2RuC55r9oaPVEW7/xu3tj8u4GeBYHBWCychFtzMIr86A7e3PPEBPT37sHStKX3+TiX/Fr/ACmJLVlLQ==", "dev": true, "license": "MIT" }, @@ -4980,16 +4980,16 @@ } }, "node_modules/typescript-eslint": { - "version": "8.58.1", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.58.1.tgz", - "integrity": "sha512-gf6/oHChByg9HJvhMO1iBexJh12AqqTfnuxscMDOVqfJW3htsdRJI/GfPpHTTcyeB8cSTUY2JcZmVgoyPqcrDg==", + "version": "8.58.2", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.58.2.tgz", + "integrity": "sha512-V8iSng9mRbdZjl54VJ9NKr6ZB+dW0J3TzRXRGcSbLIej9jV86ZRtlYeTKDR/QLxXykocJ5icNzbsl2+5TzIvcQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/eslint-plugin": "8.58.1", - "@typescript-eslint/parser": "8.58.1", - "@typescript-eslint/typescript-estree": "8.58.1", - "@typescript-eslint/utils": "8.58.1" + "@typescript-eslint/eslint-plugin": "8.58.2", + "@typescript-eslint/parser": "8.58.2", + "@typescript-eslint/typescript-estree": "8.58.2", + "@typescript-eslint/utils": "8.58.2" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5004,9 +5004,9 @@ } }, "node_modules/undici": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/undici/-/undici-7.24.7.tgz", - "integrity": "sha512-H/nlJ/h0ggGC+uRL3ovD+G0i4bqhvsDOpbDv7At5eFLlj2b41L8QliGbnl2H7SnDiYhENphh1tQFJZf+MyfLsQ==", + "version": "7.25.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.25.0.tgz", + "integrity": "sha512-xXnp4kTyor2Zq+J1FfPI6Eq3ew5h6Vl0F/8d9XU5zZQf1tX9s2Su1/3PiMmUANFULpmksxkClamIZcaUqryHsQ==", "dev": true, "license": "MIT", "engines": { diff --git a/frontend/src/pages/Agents.tsx b/frontend/src/pages/Agents.tsx index 1b7def9..e8e5f79 100644 --- a/frontend/src/pages/Agents.tsx +++ b/frontend/src/pages/Agents.tsx @@ -1,9 +1,9 @@ -import { useState } from 'react'; +import { useState, useEffect, useCallback } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; -import { apiGet, apiPost, apiPut, apiDelete } from '../api/client'; +import { apiGet, apiPost, apiPut, apiDelete, ApiError } from '../api/client'; import { Card, LoadingSpinner, StatusBadge } from '../components/ui'; import { - LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid, + LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid, Legend, } from 'recharts'; // --------------------------------------------------------------------------- @@ -52,6 +52,29 @@ interface PerfHistoryPoint { avg_confidence: number; } +interface AgentVariant { + id: string; + agent_id: string; + variant_name: string; + variant_slug: string; + description: string; + model_provider: string; + model_name: string; + system_prompt: string; + user_prompt_template: string; + prompt_version: string; + temperature: number; + max_tokens: number; + context_window: number; + input_token_limit: number; + token_budget: number; + timeout_seconds: number; + max_retries: number; + is_active: boolean; + created_at: string; + updated_at: string; +} + // --------------------------------------------------------------------------- // Hooks // --------------------------------------------------------------------------- @@ -79,6 +102,82 @@ function useAgentPerfHistory(agentId: string | undefined, hours = 24) { }); } +// -- Variant query hooks -- + +function useAgentVariants(agentId: string | undefined) { + return useQuery({ + queryKey: ['agent-variants', agentId], + queryFn: () => apiGet('query', `/api/agents/${agentId}/variants`), + enabled: !!agentId, + }); +} + +export function useVariantPerformance(agentId: string, variantId: string, hours = 24) { + return useQuery({ + queryKey: ['variant-performance', agentId, variantId, hours], + queryFn: () => apiGet('query', `/api/agents/${agentId}/variants/${variantId}/performance?hours=${hours}`), + enabled: !!agentId && !!variantId, + }); +} + +export function useVariantPerfHistory(agentId: string, variantId: string, hours = 24) { + return useQuery({ + queryKey: ['variant-perf-history', agentId, variantId, hours], + queryFn: () => apiGet('query', `/api/agents/${agentId}/variants/${variantId}/performance/history?hours=${hours}`), + enabled: !!agentId && !!variantId, + }); +} + +// -- Variant mutation hooks -- + +function useCloneAgentAsVariant(agentId: string) { + const qc = useQueryClient(); + return useMutation({ + mutationFn: (body: Record) => apiPost('query', `/api/agents/${agentId}/clone`, body), + onSuccess: () => { qc.invalidateQueries({ queryKey: ['agent-variants'] }); }, + }); +} + +export function useCreateVariant(agentId: string) { + const qc = useQueryClient(); + return useMutation({ + mutationFn: (body: Record) => apiPost('query', `/api/agents/${agentId}/variants`, body), + onSuccess: () => { qc.invalidateQueries({ queryKey: ['agent-variants'] }); }, + }); +} + +function useUpdateVariant(agentId: string, variantId: string) { + const qc = useQueryClient(); + return useMutation({ + mutationFn: (body: Record) => apiPut('query', `/api/agents/${agentId}/variants/${variantId}`, body), + onSuccess: () => { qc.invalidateQueries({ queryKey: ['agent-variants'] }); }, + }); +} + +function useDeleteVariant(agentId: string, variantId: string) { + const qc = useQueryClient(); + return useMutation({ + mutationFn: () => apiDelete('query', `/api/agents/${agentId}/variants/${variantId}`), + onSuccess: () => { qc.invalidateQueries({ queryKey: ['agent-variants'] }); }, + }); +} + +function useActivateVariant(agentId: string, variantId: string) { + const qc = useQueryClient(); + return useMutation({ + mutationFn: () => apiPost('query', `/api/agents/${agentId}/variants/${variantId}/activate`, {}), + onSuccess: () => { qc.invalidateQueries({ queryKey: ['agent-variants'] }); }, + }); +} + +export function useDeactivateVariants(agentId: string) { + const qc = useQueryClient(); + return useMutation({ + mutationFn: () => apiPost('query', `/api/agents/${agentId}/variants/deactivate`, {}), + onSuccess: () => { qc.invalidateQueries({ queryKey: ['agent-variants'] }); }, + }); +} + // --------------------------------------------------------------------------- // Page Component // --------------------------------------------------------------------------- @@ -162,6 +261,36 @@ function AgentDetail({ agent, onEdit, onDeleted }: { agent: Agent; onEdit: () => const qc = useQueryClient(); const { data: perf } = useAgentPerformance(agent.id); const { data: history } = useAgentPerfHistory(agent.id); + const { data: variants } = useAgentVariants(agent.id); + + // Variant UI state + const [variantView, setVariantView] = useState< + | { mode: 'list' } + | { mode: 'clone-agent' } + | { mode: 'clone-variant'; source: AgentVariant } + | { mode: 'edit-variant'; variant: AgentVariant } + | { mode: 'delete-confirm'; variant: AgentVariant } + >({ mode: 'list' }); + + // Comparison selection state + const [selectedVariantIds, setSelectedVariantIds] = useState>(new Set()); + + // Clear selection when variants change (e.g., after activation, deletion) + useEffect(() => { + setSelectedVariantIds(new Set()); + }, [variants]); + + const toggleVariantSelection = useCallback((variantId: string) => { + setSelectedVariantIds((prev) => { + const next = new Set(prev); + if (next.has(variantId)) { + next.delete(variantId); + } else { + next.add(variantId); + } + return next; + }); + }, []); const deleteMut = useMutation({ mutationFn: () => apiDelete('query', `/api/agents/${agent.id}`), @@ -188,6 +317,7 @@ function AgentDetail({ agent, onEdit, onDeleted }: { agent: Agent; onEdit: () =>
+ {agent.source === 'user' && ( @@ -258,10 +388,601 @@ function AgentDetail({ agent, onEdit, onDeleted }: { agent: Agent; onEdit: () => )} + + {/* Variant Section */} + {variantView.mode === 'clone-agent' && ( + setVariantView({ mode: 'list' })} + /> + )} + {variantView.mode === 'clone-variant' && ( + setVariantView({ mode: 'list' })} + /> + )} + {variantView.mode === 'edit-variant' && ( + setVariantView({ mode: 'list' })} + /> + )} + {variantView.mode === 'delete-confirm' && ( + setVariantView({ mode: 'list' })} + /> + )} + + setVariantView({ mode: 'clone-variant', source: v })} + onEdit={(v) => setVariantView({ mode: 'edit-variant', variant: v })} + onDelete={(v) => setVariantView({ mode: 'delete-confirm', variant: v })} + /> + + {selectedVariantIds.size >= 2 && ( + selectedVariantIds.has(v.id))} + /> + )}
); } +// --------------------------------------------------------------------------- +// Variant List +// --------------------------------------------------------------------------- + +function VariantList({ agentId, variants, selectedIds, onToggleSelect, onClone, onEdit, onDelete }: { + agentId: string; + variants: AgentVariant[]; + selectedIds: Set; + onToggleSelect: (id: string) => void; + onClone: (v: AgentVariant) => void; + onEdit: (v: AgentVariant) => void; + onDelete: (v: AgentVariant) => void; +}) { + return ( + +

Variants ({variants.length})

+ {variants.length === 0 ? ( +

No variants yet. Clone this agent to create one.

+ ) : ( +
+ + + + + + + + + + + + + {variants.map((v) => ( + + ))} + +
+ Select + NameModelStatusCreatedActions
+ {selectedIds.size > 0 && selectedIds.size < 2 && ( +

Select at least 2 variants to compare.

+ )} +
+ )} +
+ ); +} + +function VariantRow({ agentId, variant, selected, onToggleSelect, onClone, onEdit, onDelete }: { + agentId: string; + variant: AgentVariant; + selected: boolean; + onToggleSelect: (id: string) => void; + onClone: (v: AgentVariant) => void; + onEdit: (v: AgentVariant) => void; + onDelete: (v: AgentVariant) => void; +}) { + const activateMut = useActivateVariant(agentId, variant.id); + + return ( + + + onToggleSelect(variant.id)} + className="rounded border-surface-600 bg-surface-950 text-brand-500 focus:ring-brand-500 focus:ring-offset-0 h-3.5 w-3.5" + /> + + + {variant.variant_name} + {variant.description &&

{variant.description}

} + + {variant.model_name} + + {variant.is_active ? : inactive} + + {new Date(variant.created_at).toLocaleDateString()} + +
+ + + + +
+ + + ); +} + +// --------------------------------------------------------------------------- +// Variant Comparison View +// --------------------------------------------------------------------------- + +const COMPARE_COLORS = ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899', '#06b6d4', '#84cc16']; + +function VariantCompareColumn({ agentId, variant, color }: { + agentId: string; + variant: AgentVariant; + color: string; +}) { + const { data: perf } = useVariantPerformance(agentId, variant.id); + const activateMut = useActivateVariant(agentId, variant.id); + + return ( + +
+ {variant.variant_name} + {variant.model_name} + {variant.is_active && } +
+
+
+ Success Rate +
= 0.95 ? 'text-green-400' : 'text-yellow-400'}`}> + {perf?.success_rate != null ? `${(perf.success_rate * 100).toFixed(1)}%` : '—'} +
+
+
+ Avg Latency +
{perf?.avg_duration_ms != null ? `${Math.round(perf.avg_duration_ms)}ms` : '—'}
+
+
+ P95 Latency +
{perf?.p95_duration_ms != null ? `${Math.round(perf.p95_duration_ms)}ms` : '—'}
+
+
+ Avg Confidence +
{perf?.avg_confidence != null ? `${(perf.avg_confidence * 100).toFixed(0)}%` : '—'}
+
+
+ Total Tokens +
+ {perf?.total_input_tokens != null || perf?.total_output_tokens != null + ? ((perf.total_input_tokens ?? 0) + (perf.total_output_tokens ?? 0)).toLocaleString() + : '—'} +
+
+
+ {!variant.is_active && ( + + )} + + ); +} + +function VariantCompareChart({ agentId, variants }: { agentId: string; variants: AgentVariant[] }) { + // Fetch history for each selected variant + const historyQueries = variants.map((v) => + // eslint-disable-next-line react-hooks/rules-of-hooks + useVariantPerfHistory(agentId, v.id) + ); + + // Merge all history data into a unified time-series keyed by hour + const hourMap = new Map>(); + + variants.forEach((v, idx) => { + const history = historyQueries[idx].data ?? []; + for (const pt of history) { + const hourKey = new Date(pt.hour).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); + if (!hourMap.has(hourKey)) { + hourMap.set(hourKey, { hour: hourKey }); + } + const entry = hourMap.get(hourKey)!; + entry[`sr_${v.id}`] = pt.invocations > 0 ? Math.round((pt.successes / pt.invocations) * 100) : 0; + entry[`lat_${v.id}`] = Math.round(pt.avg_duration_ms); + } + }); + + const chartData = Array.from(hourMap.values()); + + if (chartData.length < 2) return null; + + return ( +
+

Success Rate Over Time

+ + + + + + + + {variants.map((v, idx) => ( + + ))} + + +
+ ); +} + +function VariantCompare({ agentId, variants }: { agentId: string; variants: AgentVariant[] }) { + return ( + +

Variant Comparison ({variants.length} selected)

+
+ + + + + {variants.map((v, idx) => ( + + ))} + + + + + + {variants.map((v, idx) => ( + + ))} + + +
Metric + {v.variant_name} +
Metrics
+
+ +
+ ); +} + +// --------------------------------------------------------------------------- +// Variant Clone Form +// --------------------------------------------------------------------------- + +interface VariantConfigSource { + model_provider: string; + model_name: string; + system_prompt: string; + user_prompt_template: string; + prompt_version: string; + temperature: number; + max_tokens: number; + context_window: number; + input_token_limit: number; + token_budget: number; + timeout_seconds: number; + max_retries: number; +} + +function VariantCloneForm({ agentId, source, sourceType, sourceVariantId, onDone }: { + agentId: string; + source: VariantConfigSource; + sourceType: 'agent' | 'variant'; + sourceVariantId?: string; + onDone: () => void; +}) { + const [form, setForm] = useState({ + variant_name: '', + description: '', + model_provider: source.model_provider, + model_name: source.model_name, + system_prompt: source.system_prompt, + user_prompt_template: source.user_prompt_template, + prompt_version: source.prompt_version, + temperature: source.temperature, + max_tokens: source.max_tokens, + context_window: source.context_window, + input_token_limit: source.input_token_limit, + token_budget: source.token_budget, + timeout_seconds: source.timeout_seconds, + max_retries: source.max_retries, + }); + + const cloneAgentMut = useCloneAgentAsVariant(agentId); + const qc = useQueryClient(); + + // For cloning from a variant, we use a direct mutation since the hook needs variantId + const cloneVariantMut = useMutation({ + mutationFn: (body: Record) => apiPost('query', `/api/agents/${agentId}/variants/${sourceVariantId}/clone`, body), + onSuccess: () => { qc.invalidateQueries({ queryKey: ['agent-variants'] }); }, + }); + + const mutation = sourceType === 'agent' ? cloneAgentMut : cloneVariantMut; + + function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + mutation.mutate(form, { onSuccess: () => onDone() }); + } + + return ( + +

+ Clone {sourceType === 'agent' ? 'Agent' : 'Variant'} as New Variant +

+
+
+ + setForm({ ...form, variant_name: e.target.value })} className="w-full rounded-md border border-surface-700 bg-surface-950 px-2 py-1.5 text-sm text-gray-200 focus:border-brand-500 focus:outline-none" required /> + + + setForm({ ...form, description: e.target.value })} className="w-full rounded-md border border-surface-700 bg-surface-950 px-2 py-1.5 text-sm text-gray-200 focus:border-brand-500 focus:outline-none" /> + +
+
+ + setForm({ ...form, model_provider: e.target.value })} className="w-full rounded-md border border-surface-700 bg-surface-950 px-2 py-1.5 text-sm text-gray-200 focus:border-brand-500 focus:outline-none" /> + + + setForm({ ...form, model_name: e.target.value })} className="w-full rounded-md border border-surface-700 bg-surface-950 px-2 py-1.5 text-sm text-gray-200 focus:border-brand-500 focus:outline-none" required /> + +
+ +