feat: per-provider options (thinking mode, 1M context) and SDK betas integration

- Add ProviderOptionsSection component for per-provider thinking_mode and context_1m
- Store options in options_json column (DB providers) or settings table (env provider)
- Add /api/providers/options GET/PUT route
- Fix SDK integration: use `betas` (not `betaHeaders`) for context-1m-2025-08-07
- ChatView and /chat page always reset thinkingMode on provider change (isolation fix)
- Auto-correct model when switching providers if model not in new provider's list
- Add i18n keys for provider options in both en.ts and zh.ts
- Update test fixtures with options_json field
- Remove unused lastAssistantText variable in claude-client.ts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
7418andClaude Opus 4.6 committed 2026-03-12 17:26:00 +08:00
1 parent e694d75f10
commit cc3cae6868
14 files changed
+282 -84

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import { NextRequest, NextResponse } from 'next/server';
import { getProviderOptions, setProviderOptions } from '@/lib/db';
import type { ProviderOptions } from '@/types';
/**
* GET /api/providers/options?providerId=xxx
* Returns per-provider options (thinking_mode, context_1m).
*/
export async function GET(request: NextRequest) {
const providerId = request.nextUrl.searchParams.get('providerId') || 'env';
const options = getProviderOptions(providerId);
return NextResponse.json({ options });
}
/**
* PUT /api/providers/options
* Update per-provider options. Body: { providerId, options: { thinking_mode?, context_1m? } }
*/
export async function PUT(request: NextRequest) {
try {
const body = await request.json();
const { providerId = 'env', options } = body as { providerId?: string; options: ProviderOptions };
if (!options || typeof options !== 'object') {
return NextResponse.json({ error: 'Invalid options' }, { status: 400 });
}
// Merge with existing options (partial update)
const existing = getProviderOptions(providerId);
const merged: ProviderOptions = { ...existing, ...options };
setProviderOptions(providerId, merged);
return NextResponse.json({ options: merged });
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : 'Failed to update options' },
{ status: 500 },
);
}
}