mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-25 05:51:15 +00:00
* refactor(plugin-sdk): narrow wildcard barrels to explicit used exports * refactor(tools): delete dead tool-planning module exposed by barrel narrowing * fix(plugin-sdk): restore deprecation tag on OpenClawSchemaType alias * test(agents): drop test for deleted runtime proxy module * refactor(tools): trim descriptor types to cache consumers * refactor(deadcode): harvest exports orphaned by barrel narrowing * refactor(deadcode): harvest exports orphaned by barrel narrowing (rest) * fix(agents): restore sdk imports and test markers via public predicate * fix(plugin-sdk): named type re-exports in plugin-entry; trim types barrel precisely * chore(plugin-sdk): account unmasked deprecated provider types in budgets * fix(plugins): name star-only type rows for dts bundling * fix(plugins): restore host-hook surface; unexport internal api compositions * fix(plugins): named type imports for api composition; restore needed source exports * fix(plugins): knip-visible type imports for registry surfaces * test: adapt tests to privatized media and command internals * fix(qa-lab): re-export snapshot conversation type * style: format sessions sdk imports * fix(plugins): restore smoke entry export; pin budgets to exact actuals * fix(plugins): canonical smoke-entry import; drop orphaned root shims * fix(plugins): allowlist manifest probe, repoint qa web import, drop dead browser barrels * fix(plugin-sdk): pin codex auth marker and scaffold provider type * fix(qa-lab): keep web-facing model-selection shim within boundary rules * fix(plugin-sdk): preserve merged contracts through narrowed barrels * chore(plugin-sdk): pin post-rebase surface budgets
304 lines
9.8 KiB
TypeScript
304 lines
9.8 KiB
TypeScript
import type { AuthProfileCredential, AuthProfileStore } from "../agents/auth-profiles/types.js";
|
|
import type { ProviderSystemPromptContribution } from "../agents/system-prompt-contribution.js";
|
|
import type { ReplyPayload } from "../auto-reply/reply-payload.js";
|
|
import type { ThinkLevel } from "../auto-reply/thinking.shared.js";
|
|
import type { ModelProviderConfig } from "../config/types.js";
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import type { ModelRegistry } from "../llm/model-registry.js";
|
|
import type { ProviderSystemPromptContributionContext } from "./provider-authentication.types.js";
|
|
import type { ProviderRuntimeModel } from "./provider-runtime-model.types.js";
|
|
|
|
type ModelProviderRequestTransportOverrides =
|
|
import("../agents/provider-request-config.js").ModelProviderRequestTransportOverrides;
|
|
|
|
type ProviderRuntimeProviderConfig = {
|
|
baseUrl?: string;
|
|
api?: ModelProviderConfig["api"];
|
|
auth?: ModelProviderConfig["auth"];
|
|
models?: ModelProviderConfig["models"];
|
|
headers?: unknown;
|
|
};
|
|
|
|
/**
|
|
* Sync hook for provider-owned model ids that are not present in the local
|
|
* registry/catalog yet.
|
|
*
|
|
* Use this for pass-through providers or provider-specific forward-compat
|
|
* behavior. The hook should be cheap and side-effect free; async refreshes
|
|
* belong in `prepareDynamicModel`.
|
|
*/
|
|
export type ProviderResolveDynamicModelContext = {
|
|
config?: OpenClawConfig;
|
|
agentDir?: string;
|
|
workspaceDir?: string;
|
|
agentRuntimeId?: string;
|
|
provider: string;
|
|
modelId: string;
|
|
modelRegistry: ModelRegistry;
|
|
providerConfig?: ProviderRuntimeProviderConfig;
|
|
authProfileId?: string;
|
|
authProfileMode?: AuthProfileCredential["type"] | "aws-sdk";
|
|
};
|
|
|
|
/**
|
|
* Optional async warm-up for dynamic model resolution.
|
|
*
|
|
* Called only from async model resolution paths, before retrying
|
|
* `resolveDynamicModel`. This is the place to refresh caches or fetch provider
|
|
* metadata over the network.
|
|
*/
|
|
export type ProviderPrepareDynamicModelContext = ProviderResolveDynamicModelContext;
|
|
|
|
export type ProviderPreferRuntimeResolvedModelContext = {
|
|
config?: OpenClawConfig;
|
|
agentDir?: string;
|
|
workspaceDir?: string;
|
|
provider: string;
|
|
modelId: string;
|
|
};
|
|
|
|
/**
|
|
* Last-chance rewrite hook for provider-owned transport normalization.
|
|
*
|
|
* Runs after OpenClaw resolves an explicit/discovered/dynamic model and before
|
|
* the embedded runner uses it. Typical uses: swap API ids, fix base URLs, or
|
|
* patch provider-specific compat bits.
|
|
*/
|
|
export type ProviderNormalizeResolvedModelContext = {
|
|
config?: OpenClawConfig;
|
|
agentDir?: string;
|
|
workspaceDir?: string;
|
|
provider: string;
|
|
modelId: string;
|
|
model: ProviderRuntimeModel;
|
|
};
|
|
|
|
/**
|
|
* Provider-owned model-id normalization before config/runtime lookup.
|
|
*
|
|
* Use this for provider-specific alias cleanup that should stay with the
|
|
* plugin rather than in core string tables.
|
|
*/
|
|
export type ProviderNormalizeModelIdContext = {
|
|
provider: string;
|
|
modelId: string;
|
|
};
|
|
|
|
/**
|
|
* Provider-owned transport normalization for arbitrary provider/model config.
|
|
*
|
|
* Use this when transport cleanup depends on API/baseUrl rather than the
|
|
* owning provider id, for example custom providers that still target a
|
|
* plugin-owned transport family.
|
|
*/
|
|
export type ProviderNormalizeTransportContext = {
|
|
config?: OpenClawConfig;
|
|
workspaceDir?: string;
|
|
provider: string;
|
|
modelId?: string;
|
|
api?: string | null;
|
|
baseUrl?: string;
|
|
};
|
|
|
|
/**
|
|
* Runtime auth input for providers that need an extra exchange step before
|
|
* inference. The incoming `apiKey` is the raw credential resolved from auth
|
|
* profiles/env/config. The returned value should be the actual token/key to use
|
|
* for the request.
|
|
*/
|
|
export type ProviderPrepareRuntimeAuthContext = {
|
|
config?: OpenClawConfig;
|
|
agentDir?: string;
|
|
workspaceDir?: string;
|
|
env: NodeJS.ProcessEnv;
|
|
provider: string;
|
|
modelId: string;
|
|
model: ProviderRuntimeModel;
|
|
apiKey: string;
|
|
authMode: string;
|
|
profileId?: string;
|
|
};
|
|
|
|
/**
|
|
* Result of `prepareRuntimeAuth`.
|
|
*
|
|
* `apiKey` is required and becomes the runtime credential stored in auth
|
|
* storage. `baseUrl` is optional and lets providers like GitHub Copilot swap to
|
|
* an entitlement-specific endpoint at request time. `expiresAt` enables generic
|
|
* background refresh in long-running turns.
|
|
*/
|
|
export type ProviderPreparedRuntimeAuth = {
|
|
apiKey: string;
|
|
baseUrl?: string;
|
|
request?: ModelProviderRequestTransportOverrides;
|
|
expiresAt?: number;
|
|
};
|
|
|
|
/**
|
|
* Usage/billing auth input for providers that expose quota/usage endpoints.
|
|
*
|
|
* This hook is intentionally separate from `prepareRuntimeAuth`: usage
|
|
* snapshots often need a different credential source than live inference
|
|
* requests, and they run outside the embedded runner.
|
|
*
|
|
* The helper methods cover the common OpenClaw auth resolution paths:
|
|
*
|
|
* - `resolveApiKeyFromConfigAndStore`: env/config/plain token/api_key profiles
|
|
* - `resolveOAuthToken`: oauth/token profiles resolved through the auth store,
|
|
* optionally for an explicit provider override
|
|
*
|
|
* Plugins can still do extra provider-specific work on top (for example parse a
|
|
* token blob, read a legacy credential file, or pick between aliases).
|
|
*/
|
|
export type ProviderResolveUsageAuthContext = {
|
|
config: OpenClawConfig;
|
|
agentDir?: string;
|
|
workspaceDir?: string;
|
|
env: NodeJS.ProcessEnv;
|
|
provider: string;
|
|
resolveApiKeyFromConfigAndStore: (params?: {
|
|
providerIds?: string[];
|
|
envDirect?: Array<string | undefined>;
|
|
}) => string | undefined;
|
|
/** Ordered API-key/token candidates, including resolved SecretRefs, for credential classification. */
|
|
resolveApiKeyCandidatesFromConfigAndStore?: (params?: {
|
|
providerIds?: string[];
|
|
envDirect?: Array<string | undefined>;
|
|
}) => Promise<string[]>;
|
|
resolveOAuthToken: (params?: { provider?: string }) => Promise<ProviderUsageAuthToken | null>;
|
|
};
|
|
|
|
export type ProviderUsageAuthToken = {
|
|
token: string;
|
|
accountId?: string;
|
|
/** Non-secret plan metadata from the resolved credential (e.g. Claude "max"). */
|
|
subscriptionType?: string;
|
|
rateLimitTier?: string;
|
|
/** Account email captured on the resolved credential, when known. */
|
|
email?: string;
|
|
};
|
|
|
|
/**
|
|
* Result of `resolveUsageAuth`.
|
|
*
|
|
* Two shapes are supported:
|
|
* - `{ token: string; accountId?: string }` — use this token for provider usage endpoints.
|
|
* - `{ handled: true }` — this provider handled the request but has no usable
|
|
* usage token; core must skip further fallback (generic API-key/OAuth fallback
|
|
* must not run).
|
|
*
|
|
* Returning `null` or `undefined` means "not handled by this provider"; core
|
|
* proceeds to generic fallback resolution.
|
|
*/
|
|
export type ProviderResolvedUsageAuth = ProviderUsageAuthToken | { handled: true };
|
|
|
|
/**
|
|
* Usage/quota snapshot input for providers that own their usage endpoint
|
|
* fetch/parsing behavior.
|
|
*
|
|
* This hook runs after `resolveUsageAuth` succeeds. Core still owns summary
|
|
* fan-out, timeout wrapping, filtering, and formatting; the provider plugin
|
|
* owns the provider-specific HTTP request + response normalization.
|
|
*/
|
|
export type ProviderFetchUsageSnapshotContext = {
|
|
config: OpenClawConfig;
|
|
agentDir?: string;
|
|
workspaceDir?: string;
|
|
env: NodeJS.ProcessEnv;
|
|
provider: string;
|
|
token: string;
|
|
accountId?: string;
|
|
authProfileId?: string;
|
|
/** Non-secret plan metadata from the resolved credential (e.g. Claude "max"). */
|
|
subscriptionType?: string;
|
|
rateLimitTier?: string;
|
|
/** Account email captured on the resolved credential, when known. */
|
|
email?: string;
|
|
timeoutMs: number;
|
|
fetchFn: typeof fetch;
|
|
};
|
|
|
|
/**
|
|
* Provider-owned auth-doctor hint input.
|
|
*
|
|
* Called when OAuth refresh fails and OpenClaw wants a provider-specific repair
|
|
* hint to append to the generic re-auth message. Use this for legacy profile-id
|
|
* migrations or other provider-owned auth-store cleanup guidance.
|
|
*/
|
|
export type ProviderAuthDoctorHintContext = {
|
|
config?: OpenClawConfig;
|
|
store: AuthProfileStore;
|
|
provider: string;
|
|
profileId?: string;
|
|
};
|
|
|
|
/**
|
|
* Provider-owned extra-param normalization before OpenClaw builds its generic
|
|
* stream option wrapper.
|
|
*
|
|
* Use this to set provider defaults or rewrite provider-specific config keys
|
|
* into the merged `extraParams` object. Return the full next extraParams object.
|
|
*/
|
|
/** Provider-facing effort after OpenClaw lowers orchestration-only modes. */
|
|
type ProviderTransportThinkingLevel = Exclude<ThinkLevel, "ultra">;
|
|
|
|
export type ProviderPrepareExtraParamsContext = {
|
|
config?: OpenClawConfig;
|
|
agentDir?: string;
|
|
workspaceDir?: string;
|
|
agentId?: string;
|
|
nativeWebSearchAllowedByToolPolicy?: boolean;
|
|
provider: string;
|
|
modelId: string;
|
|
model?: ProviderRuntimeModel;
|
|
extraParams?: Record<string, unknown>;
|
|
thinkingLevel?: ProviderTransportThinkingLevel;
|
|
};
|
|
|
|
export type ProviderExtraParamsForTransportContext = Omit<
|
|
ProviderPrepareExtraParamsContext,
|
|
"extraParams"
|
|
> & {
|
|
model?: ProviderRuntimeModel;
|
|
transport?: "sse" | "websocket" | "auto";
|
|
extraParams: Record<string, unknown>;
|
|
};
|
|
|
|
export type ProviderExtraParamsForTransportResult = {
|
|
patch?: Record<string, unknown> | null;
|
|
};
|
|
|
|
export type ProviderResolvePromptOverlayContext = ProviderSystemPromptContributionContext & {
|
|
baseOverlay?: ProviderSystemPromptContribution;
|
|
};
|
|
|
|
export type ProviderFollowupFallbackRouteContext = {
|
|
config?: OpenClawConfig;
|
|
agentDir?: string;
|
|
workspaceDir?: string;
|
|
provider: string;
|
|
modelId: string;
|
|
payload: ReplyPayload;
|
|
originatingChannel?: string;
|
|
originatingTo?: string;
|
|
originRoutable: boolean;
|
|
dispatcherAvailable: boolean;
|
|
};
|
|
|
|
export type ProviderFollowupFallbackRouteResult = {
|
|
route?: "origin" | "dispatcher" | "drop";
|
|
reason?: string;
|
|
};
|
|
|
|
export type ProviderResolveAuthProfileIdContext = {
|
|
config?: OpenClawConfig;
|
|
agentDir?: string;
|
|
workspaceDir?: string;
|
|
provider: string;
|
|
modelId: string;
|
|
preferredProfileId?: string;
|
|
lockedProfileId?: string;
|
|
profileOrder: string[];
|
|
authStore: AuthProfileStore;
|
|
};
|