Files
wehub-resource-sync c48612c494
CI / E2E Tests (push) Has been cancelled
CI / Lint, Typecheck & Unit Tests (push) Has been cancelled
Docs Build / Build docs site (push) Has been cancelled
Publish @openmaic packages / Build, validate & publish (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:23 +08:00

29 lines
1.4 KiB
TypeScript

import { thinkingContext } from '@/lib/ai/thinking-context';
import type { ThinkingConfig } from '@/lib/types/provider';
/**
* PBL v2 runtime LLM calls force-disable thinking.
*
* The instructing turn forces `begin_turn` via `tool_choice`, which several
* providers reject when thinking is on — DeepSeek returns 400 "Thinking mode
* does not support this tool_choice". We never intentionally enabled thinking
* on these turns (the PBL v2 client sends no `thinkingConfig`); some pinned
* models just default it on. Disabling it removes the incompatibility without
* losing any behavior we relied on.
*
* For OpenAI-compatible providers (e.g. DeepSeek) thinking is injected by the
* fetch wrapper in `providers.ts`, which reads the per-request config from the
* `thinkingContext` AsyncLocalStorage. The agents call the AI SDK directly
* (not via `callLLM`/`streamLLM`), so nothing seeds that store — we do it here.
* The SDK call must be started INSIDE `run` (its consumption can be outside) so
* the lazily-issued fetch inherits the context, matching `streamLLM`.
*
* Scope: PBL v2 runtime only (instructor / evaluator). Generation (planner) is
* intentionally untouched.
*/
const PBL_V2_THINKING_DISABLED: ThinkingConfig = { mode: 'disabled', enabled: false };
export function withThinkingDisabled<T>(startCall: () => T): T {
return thinkingContext.run(PBL_V2_THINKING_DISABLED, startCall);
}