openmaic-custom/lib/ai/thinking-context.ts
wyuc 0d20abfed9 Initial commit: OpenMAIC AI classroom platform
Next.js 16 App Router application with:
- AI-powered interactive classroom generation from PDF/text requirements
- Multi-agent discussion system (teacher, students, assistant roles)
- Provider abstraction for LLM, TTS, ASR, image, video, web search
- Local-first data architecture (IndexedDB/Dexie)
- i18n support (zh-CN/en-US)
- Structured logger, SSRF guard, lint/build passing (0 errors)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 16:41:07 +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;