UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

314 lines • 13.3 kB
import { B as ModelCompatConfig, H as ModelMediaInputConfig, P as OpenClawConfig, nr as ModelCatalogContextWindowOption } from "./types-D3g9JHH2.js"; import { T as ThinkingLevelMap, d as Model } from "./types-D_RlIixM.js"; import { t as PluginManifestRecord } from "./manifest-registry-clB08cKE.js"; import { r as PluginMetadataSnapshot } from "./plugin-metadata-snapshot-CWiro_gA.js"; import { i as ThinkingCatalogEntry, r as ThinkLevel } from "./thinking.shared-CFZJvgsr.js"; import { a as ModelCatalogRef, i as ModelFallbackRouteResolution, o as ProviderModelRef } from "./model-fallback.types-DksCI2kd.js"; import { t as ModelCatalogEntry } from "./model-catalog.types-Bf7KSKw2.js"; //#region src/plugins/provider-thinking.types.d.ts /** * Provider-owned thinking policy input. * * Used by shared `/think`, ACP controls, and directive parsing to ask a * provider whether a model supports special reasoning UX such as adaptive, * xhigh, max, or a binary on/off toggle. */ type ProviderThinkingPolicyContext = ModelCatalogRef; /** * Provider-owned default thinking policy input. * * `reasoning` is the merged catalog hint for the selected model when one is * available. Providers can use it to keep "reasoning model => low" behavior * without re-reading the catalog themselves. * * `compat` carries model-level request contract facts for the selected model * when available. Providers can use it to expose model-specific thinking * profiles only when the configured payload style supports them. */ type ProviderDefaultThinkingPolicyContext = ProviderThinkingPolicyContext & { /** Effective agent runtime selected for this model, when known. */ agentRuntime?: string | null; /** API adapter id from the selected catalog route, when known. */ api?: string | null; /** Base URL from the selected catalog route, when known. */ baseUrl?: string | null; reasoning?: boolean; /** Thinking-to-wire mapping from the selected model route. */ thinkingLevelMap?: ThinkingLevelMap; params?: Record<string, unknown>; compat?: { thinkingFormat?: string; supportsReasoningEffort?: boolean; supportedReasoningEfforts?: readonly string[] | null; reasoningEffortMap?: Record<string, string>; } | null; }; type ProviderThinkingLevelId = ThinkLevel; type ProviderThinkingLevel = { id: ProviderThinkingLevelId; /** * Optional display label. Use this when the stored value differs from the * provider-facing UX, for example binary providers storing `low` but showing * `on`. */ label?: string; /** * Relative strength used to clamp execution when the selected model does not * support the requested level. The stored preference remains unchanged. */ rank?: number; }; type ProviderThinkingProfile = { levels: ProviderThinkingLevel[] | ReadonlyArray<ProviderThinkingLevel>; defaultLevel?: ProviderThinkingLevelId | null; /** * Some bundled providers have model-specific thinking contracts that are more * current than cached generic catalog metadata. Keep this opt-in so * `reasoning: false` remains authoritative for ordinary catalog entries. */ preserveWhenCatalogReasoningFalse?: boolean; }; /** Prepared provider policy ownership, without the broader Gateway registry contract. */ type ProviderThinkingRegistry = { providers: ReadonlyArray<{ provider: { id: string; aliases?: string[]; hookAliases?: string[]; resolveThinkingProfile?: (context: ProviderDefaultThinkingPolicyContext) => ProviderThinkingProfile | null | undefined; }; }>; }; type ProviderThinkingPolicySource = "active" | "active-or-bundled" | ProviderThinkingRegistry; //#endregion //#region src/plugins/provider-runtime-model.types.d.ts /** * Fully-resolved runtime model shape used after provider/plugin-owned * discovery, overrides, and compat normalization. */ type ProviderRuntimeModel = Omit<Model, "compat"> & { compat?: ModelCompatConfig; contextWindows?: ModelCatalogContextWindowOption[]; contextWindowDefault?: string; contextTokens?: number; /** Unknown-model estimate, replaceable only by accepted same-route account metadata. */ contextWindowSource?: "synthetic"; /** Host-resolved provenance for the top-level wire output cap. */ maxTokensSource?: "configured" | "discovered"; params?: Record<string, unknown>; requestTimeoutMs?: number; /** Provider/host-prepared tool discovery preference for this attempt; never persisted. */ toolSearchMode?: "tools" | false; /** Provider-prepared default for embedded compaction; explicit compaction config wins. */ compactionThinkingDefault?: NonNullable<ProviderThinkingProfile["defaultLevel"]>; mediaInput?: ModelMediaInputConfig; }; //#endregion //#region src/auto-reply/thinking.d.ts /** UI-facing thinking level option. */ type ThinkingLevelOption = { id: ThinkLevel; label: string; }; type RankedThinkingLevelOption = ThinkingLevelOption & { rank: number; }; type ResolvedThinkingProfile = { levels: RankedThinkingLevelOption[]; defaultLevel?: ThinkLevel | null; }; type ThinkingCatalogQuery = { provider?: string | null; model?: string | null; }; type ThinkingProfileParams = ThinkingCatalogQuery & { catalog?: ThinkingCatalogEntry[]; catalogResolver?: ThinkingCatalogResolver; agentRuntime?: string | null; configuredReasoning?: boolean; providerPolicySource?: ProviderThinkingPolicySource; }; type ThinkingCatalogResolver = (params: ThinkingCatalogQuery) => ThinkingCatalogEntry | undefined; /** Ultra is a harness mode, independent of a model's native reasoning controls. */ declare function resolveThinkingProfile(params: ThinkingProfileParams): ResolvedThinkingProfile; /** List labeled thinking level options supported by provider/model. */ declare function listThinkingLevelOptions(provider?: string | null, model?: string | null, catalog?: ThinkingCatalogEntry[], agentRuntime?: string | null): ThinkingLevelOption[]; //#endregion //#region src/plugins/manifest-model-id-normalization.d.ts /** Caller-owned declarations or facts from an already selected metadata snapshot. */ type ManifestModelIdNormalizationSource = readonly (Pick<PluginManifestRecord, "modelIdNormalization"> & Partial<Pick<PluginManifestRecord, "providers">>)[] | { owners: Pick<PluginMetadataSnapshot["owners"], "modelIdNormalizationPolicies"> & Partial<Pick<PluginMetadataSnapshot["owners"], "providers">>; }; //#endregion //#region src/agents/model-ref-shared.d.ts type ModelManifestNormalizationContext = { manifestPlugins?: ManifestModelIdNormalizationSource; }; type ModelRefNormalizeOptions = ModelManifestNormalizationContext & { allowManifestNormalization?: boolean; allowPluginNormalization?: boolean; }; /** Normalize a provider/model pair into a canonical model reference. */ declare function normalizeModelRef(provider: string, model: string, options?: ModelRefNormalizeOptions): ProviderModelRef; //#endregion //#region src/agents/model-selection-config.d.ts declare function resolveDefaultModelForAgent(params: { cfg: OpenClawConfig; agentId?: string; allowManifestNormalization?: boolean; allowPluginNormalization?: boolean; } & ModelManifestNormalizationContext): ProviderModelRef; //#endregion //#region src/agents/model-selection-shared.d.ts type ModelManifestPlugins = ModelManifestNormalizationContext["manifestPlugins"]; type ModelSelectionParams = NonNullable<Parameters<typeof normalizeModelRef>[2]> & { cfg?: OpenClawConfig; agentId?: string; defaultProvider: string; }; type ConfiguredModelSelectionParams = ModelSelectionParams & { cfg: OpenClawConfig; }; type ParseModelRefParams = ModelSelectionParams & { raw: string; }; type ModelAliasIndex = { byAlias: Map<string, { alias: string; ref: ProviderModelRef; }>; byProviderAlias?: Map<string, { alias: string; ref: ProviderModelRef; }>; byKey: Map<string, string[]>; disabledKeys?: Set<string>; }; /** Build lookup maps from user-facing aliases to normalized model refs. */ declare function buildModelAliasIndex(params: ConfiguredModelSelectionParams): ModelAliasIndex; declare function resolveModelRefFromString(params: ParseModelRefParams & { aliasIndex?: ModelAliasIndex; }): { ref: ProviderModelRef; alias?: string; } | null; type AllowedModelSet = { allowAny: boolean; allowedCatalog: ModelCatalogEntry[]; allowedKeys: Set<string>; allows: (ref: ProviderModelRef) => boolean; }; /** Build explicit model override authorization without widening it for automatic fallbacks. */ declare function buildAllowedModelSet(params: { cfg: OpenClawConfig; catalog: ModelCatalogEntry[]; defaultProvider: string; defaultModel?: string | ProviderModelRef; agentId?: string; } & ModelManifestNormalizationContext): AllowedModelSet; type ResolveAllowedModelRefResult = { ref: ProviderModelRef; key: string; } | { error: string; }; /** Status of a candidate model against catalog and configured allowlist state. */ declare function getModelRefStatus(params: Parameters<typeof buildAllowedModelSet>[0] & { ref: ProviderModelRef; }): { key: string; inCatalog: boolean; allowAny: boolean; allowed: boolean; }; /** Resolve a requested model string only if it is allowed by the supplied status check. */ declare function resolveAllowedModelRefFromAliasIndex(params: { cfg: OpenClawConfig; raw: string; defaultProvider: string; agentId?: string; aliasIndex: ModelAliasIndex; getStatus: (ref: ProviderModelRef) => ReturnType<typeof getModelRefStatus>; } & ModelManifestNormalizationContext): ResolveAllowedModelRefResult; /** Build catalog entries from configured provider model rows. */ declare function buildConfiguredModelCatalog(params: { cfg: OpenClawConfig; catalog?: readonly ModelCatalogEntry[]; workspaceDir?: string; manifestPlugins?: ModelManifestPlugins; }): ModelCatalogEntry[]; type ModelVisibilityPolicy = { allowAny: boolean; catalog: ModelCatalogEntry[]; configuredCatalog: readonly ModelCatalogEntry[]; allowedCatalog: ModelCatalogEntry[]; allowedKeys: Set<string>; policyAliasIndex: ModelAliasIndex; selectionAliasIndex: ModelAliasIndex; configuredKeys: ReadonlySet<string>; retainedKeys: ReadonlySet<string>; exactModelRefs: readonly string[]; providerWildcards: ReadonlySet<string>; hasConfiguredEntries: boolean; hasProviderWildcards: boolean; allowConfigPath?: string | null; allowRepairConfigPath: string; allows: (ref: { provider: string; model: string; }) => boolean; allowsByWildcard: (ref: { provider: string; model: string; }) => boolean; resolveSelection: (ref: ProviderModelRef & { routeResolution?: ModelFallbackRouteResolution; }) => ProviderModelRef | null; visibleCatalog: (params: { catalog: readonly ModelCatalogEntry[]; defaultVisibleCatalog: readonly ModelCatalogEntry[]; view?: "default" | "configured" | "all"; }) => ModelCatalogEntry[]; }; //#endregion //#region src/agents/model-selection-resolve.d.ts /** Resolves a raw model string into an allowed model ref or an explanatory error. */ declare function resolveAllowedModelRefCore(params: Omit<Parameters<typeof getModelRefStatus>[0], "ref"> & { raw: string; }): ReturnType<typeof resolveAllowedModelRefFromAliasIndex>; //#endregion //#region src/agents/model-thinking-default-core.d.ts type ThinkingDefaultParams = { cfg: OpenClawConfig; provider: string; model: string; catalog?: ModelCatalogEntry[]; agentRuntime?: string | null; agentId?: string; providerPolicySource?: ProviderThinkingPolicySource; catalogResolver?: ThinkingCatalogResolver; }; declare function resolveThinkingDefaultCore(params: ThinkingDefaultParams): ThinkLevel; //#endregion //#region src/agents/model-thinking-default.d.ts /** Resolves thinking default after loading runtime catalog only when needed. */ declare function resolveThinkingDefaultWithRuntimeCatalogCore(params: { cfg: OpenClawConfig; provider: string; model: string; agentId?: string; loadRuntimeCatalog: () => Promise<ModelCatalogEntry[]>; agentRuntime?: string | null; }): Promise<ThinkLevel>; //#endregion //#region src/agents/model-selection-normalize.d.ts /** Find a provider value by normalized provider ID. */ declare function findNormalizedProviderValue<T>(entries: Record<string, T> | undefined, provider: string): T | undefined; /** Parse `provider/model` or bare model text using a default provider. */ declare function parseModelRef(raw: string, defaultProvider: string, options?: ModelRefNormalizeOptions): ProviderModelRef | null; //#endregion //#region src/agents/defaults.d.ts declare const DEFAULT_PROVIDER = "openai"; declare const DEFAULT_MODEL = "gpt-6-astra"; //#endregion export { ProviderThinkingPolicyContext as _, resolveThinkingDefaultWithRuntimeCatalogCore as a, ModelVisibilityPolicy as c, resolveModelRefFromString as d, resolveDefaultModelForAgent as f, ProviderDefaultThinkingPolicyContext as g, ProviderRuntimeModel as h, parseModelRef as i, buildConfiguredModelCatalog as l, resolveThinkingProfile as m, DEFAULT_PROVIDER as n, resolveThinkingDefaultCore as o, listThinkingLevelOptions as p, findNormalizedProviderValue as r, resolveAllowedModelRefCore as s, DEFAULT_MODEL as t, buildModelAliasIndex as u, ProviderThinkingProfile as v, ProviderThinkingRegistry as y };