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

24 lines
1.1 KiB
TypeScript

/**
* Async-context carrier for per-request ThinkingConfig.
*
* callLLM / streamLLM wrap each AI SDK call in thinkingContext.run()
* so that the custom fetch wrapper in providers.ts can read the
* current thinking preference and inject vendor-specific body params.
*
* IMPORTANT: This module uses node:async_hooks which is server-only.
* providers.ts must NOT import this module directly (it's also used
* on the client via settings.ts). Instead, providers.ts reads the
* context via globalThis.__thinkingContext, which is set here at
* module load time and guaranteed to be available before any fetch
* wrapper runs.
*/
import { AsyncLocalStorage } from 'node:async_hooks';
import type { ThinkingConfig } from '@/lib/types/provider';
export const thinkingContext = new AsyncLocalStorage<ThinkingConfig | undefined>();
// Expose on globalThis so providers.ts can access the store without
// importing this module (which would pull node:async_hooks into the
// client bundle via the settings.ts → providers.ts import chain).
(globalThis as Record<string, unknown>).__thinkingContext = thinkingContext;