Files
openclaw/extensions/opencode/provider-policy-api.ts
Peter Steinberger 708632c451 perf: stop provider policy loads from compiling the transport graph (#129652)
* perf(plugins): keep provider policy artifacts on leaf module graphs

Provider policy artifacts (provider-policy-api.js) load eagerly whenever a
provider is resolved, but five of them imported the provider-model-shared
barrel at runtime, dragging the transports/compat/state graph into every
policy load. In contexts without a native TS require hook (Vitest workers,
non-tsx source runs) jiti compiled that whole graph: ~65s of event-loop
starvation on the first embedded run, which is what pushed
run.session-permissions.test.ts past its 120s timeout before #129582.

Add openclaw/plugin-sdk/claude-model-runtime, a narrow family-level and
local-only subpath re-exporting the Claude identity/thinking helpers from
their leaf owners (@openclaw/llm-core, plugins/provider-claude-thinking).
Switch anthropic, anthropic-vertex, and opencode policy artifacts to it, and
amazon-bedrock plus ollama to the already-plugin-visible
@openclaw/model-catalog-core leaves. The barrel keeps re-exporting the same
symbols, so no existing consumer changes.

Measured on the embedded-runner host route (first run, Vitest worker):
65540ms -> 6627ms; jiti self-time 23.4s -> 1.3s, statSync 18.6s -> 0.7s.
run.shared-integration.test.ts drops from 167s to 65s as a side effect.

Also pin run.inherited-auth-owner.test.ts to the mocked plugin-harness route
(its assertions are provider-agnostic; 37.6s -> sub-second test time) and
document the no-provider default-route trap on overflowBaseRunParams.

Follow-up to #129582.

* chore(plugins): register claude-model-runtime boundary aliases

The extension package boundary contract requires every local-only plugin-sdk
entrypoint to carry a d.ts path alias in the shared boundary map and xai's
derived override set; CI's contracts-plugin lane caught the missing entries.

* chore(release): exclude claude-model-runtime declarations from the pack

Local-only plugin-sdk entrypoints ship runtime .js only; the release check
derives the required pack exclusion from the local-only registry and CI's
core-tooling lane caught the missing package.json files entry.

* test(agents): assert the mocked harness route in auth-owner proof

ClawSweeper P2: without the agentHarnessId assertion a silent fall-back to
the built-in host harness would still pass the auth-owner assertions while
proving the wrong route; fail loudly like run.session-permissions.test.ts.
2026-08-26 00:39:38 -07:00

51 lines
1.8 KiB
TypeScript

import { resolveClaudeThinkingProfile } from "openclaw/plugin-sdk/claude-model-runtime";
// Opencode API module exposes the plugin public contract.
import type {
ProviderDefaultThinkingPolicyContext,
ProviderThinkingProfile,
} from "openclaw/plugin-sdk/plugin-entry";
const FIXED_REASONING_PROFILE = {
levels: [{ id: "off", label: "always on" }],
defaultLevel: "off",
} as const satisfies ProviderThinkingProfile;
const THINKING_LEVEL_IDS = new Set(["off", "minimal", "low", "medium", "high", "xhigh", "max"]);
function resolveEffortThinkingProfile(
efforts: readonly string[] | null | undefined,
): ProviderThinkingProfile | undefined {
if (!efforts || efforts.length === 0) {
return undefined;
}
const acceptedLevelIds = ["off", ...efforts.map((effort) => (effort === "none" ? "off" : effort))]
.filter((id) => THINKING_LEVEL_IDS.has(id))
.filter((id, index, values) => values.indexOf(id) === index) as Array<
"off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"
>;
const levels = acceptedLevelIds.map((id) => ({ id }));
const levelIdSet = new Set(acceptedLevelIds);
const defaultLevel = levelIdSet.has("medium")
? "medium"
: levelIdSet.has("high")
? "high"
: levelIdSet.has("low")
? "low"
: "off";
return { levels, defaultLevel };
}
export function resolveThinkingProfile(params: ProviderDefaultThinkingPolicyContext) {
const modelId = params.modelId.trim().toLowerCase();
if (modelId.startsWith("claude-")) {
return resolveClaudeThinkingProfile(modelId);
}
const effortProfile = resolveEffortThinkingProfile(params.compat?.supportedReasoningEfforts);
if (effortProfile) {
return effortProfile;
}
return params.reasoning === true && params.api !== "anthropic-messages"
? FIXED_REASONING_PROFILE
: undefined;
}