/** * Model Policy Provider types. * * These types define the pull-mode model selection callback interface. * The host registers a `ModelPolicyProvider` callback, which the SDK invokes * whenever the CLI sends a `get_model_policy` control request before an LLM call. */ import type { QoderModelPurpose } from './control.js'; import type { ModelInfo } from './common.js'; import type { CustomModel } from './byok.js'; export type { SDKControlGetModelPolicyRequest, SDKControlGetModelPolicyResponse, } from '../protocol/index.js'; /** * SDK capability declaration sent to CLI during initialization. * When `modelPolicy: 'pull'` is present, CLI will send `get_model_policy` * control requests before each LLM call. */ export interface SDKCapabilities { modelPolicy?: 'pull'; } /** * Context passed to the host's resolveModel callback. * Contains request metadata and available model information. */ export interface ModelPolicyContext { /** LLM call purpose */ purpose: QoderModelPurpose; /** Session ID */ sessionId: string; /** Current conversation turn index (0-based) */ turnIndex: number; /** Available models provided by CLI on each `get_model_policy` request (real-time) */ availableModels: ModelInfo[]; } /** * Result returned by the resolveModel callback. */ export interface ModelPolicyResult { /** * Selected model identifier, or a BYOK custom model object. * * - `string` — a platform model id (e.g. `'auto'`, `'performance'`). * - `CustomModel & { model: string }` — a BYOK model with credentials. * The SDK extracts `model` as the identifier and forwards the rest * as `custom_model` on the wire. */ model: string | (CustomModel & { model: string; }); /** Optional per-request model policy parameters (contextWindow, reasoningEffort). */ parameters?: Record; /** * Optional routing scene label sent as the inference request body `task_id`. * The server selects models by it; internal CLI tasks keep their own values. */ taskId?: string; /** * Optional business sub-task label sent as `business.sub_task` on the * inference request, used for billing/analytics. Not involved in routing. */ subTask?: string; } /** * Host-registered callback for pull-mode model selection. * * Called before each LLM request. The callback may be synchronous or async. * If the callback throws or times out, the error is propagated to the SDK * caller — no silent fallback occurs. */ export type ModelPolicyProvider = (context: ModelPolicyContext) => ModelPolicyResult | Promise;