evOo-local/packages/contracts/src/model-tiers.ts
Claude f28f9b7d55
feat(models): map model tiers per space and let bots and helpers ask for one
A space can now map the tiers fast, standard and code to connected models,
including several models served by one OpenAI-compatible router endpoint
(one credential, many model ids). A bot can ask for a tier, and a single
run_subagent call can ask for one. A tier with no model mapped falls back
to the usual model choice, so nothing breaks before tiers are set up.

- db: SpaceModelTier repo (list, find, set or clear); tier mappings are
  copied into a new space like model and voice preferences; createBot
  carries a tier, so duplicates keep it and spawned bots inherit it.
- contracts/api: models.tiers.list and models.tiers.set;
  models.probeOpenAiCompatible can list a connected server's models by
  credential id with its stored address and key; bots.update accepts
  modelTier and keeps a pinned model and a tier mutually exclusive, so a
  model picked on a surface that knows no tiers (mobile) is never silently
  overridden. Thinking-level validation follows the tier's model. AI
  consent status discloses tier models; desktop local settings allow the
  tier procedures.
- adapters: selectConfiguredModel runs a mapped tier ahead of the pinned
  model and the space default; the executor resolves bot tiers for runs
  and model lookups, and helper tiers through resolveModelTier.
  run_subagent takes model_tier; an explicit model wins over it.
- web: a collapsed Tiers section in model settings (shown once a model is
  connected) and mapped tiers as choices in the bot Model select.
- docs: tiers in self-host model setup.
- tests: resolution order and fallbacks (selection, executor, Pi helper),
  repo, API and contract units, authorization and offline Pi Postgres
  suites, and a model-tiers web E2E spec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u
2026-10-02 22:07:32 +00:00

25 lines
750 B
TypeScript

import * as z from "zod";
import { ModelTierSchema } from "./domain.js";
import { Id } from "./ids.js";
/** One tier of a space mapped to a model of a connected credential. */
export const ModelTierMappingSchema = z.object({
tier: ModelTierSchema,
credentialId: Id,
provider: z.string(),
modelId: z.string(),
});
export type ModelTierMapping = z.infer<typeof ModelTierMappingSchema>;
export const SetModelTierInput = z.object({
tier: ModelTierSchema,
/** null removes the mapping, so bots asking for this tier use their usual model again. */
model: z
.object({
credentialId: Id,
modelId: z.string().trim().min(1).max(200),
})
.nullable(),
});
export type SetModelTierInput = z.infer<typeof SetModelTierInput>;