Synced from private repo (feature/ai-sdk-6-upgrade): - Upgrade AI SDK 5 → 6 (packages + API changes) - Add sqliteQuery tool for flexible read-only queries - New WorkflowExecutor with workflow-specific tools - 83% token reduction for workflow execution - Remove mini-rah dead code (simplified architecture) - Add context management usage endpoint - Fix Connect workflow instructions - Clickable node references in workflow UI Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
29 lines
817 B
TypeScript
29 lines
817 B
TypeScript
import { NextRequest } from 'next/server';
|
|
import { getSQLiteClient } from '@/services/database/sqlite-client';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const sessionId = request.nextUrl.searchParams.get('sessionId');
|
|
|
|
if (!sessionId) {
|
|
return Response.json({ inputTokens: 0 });
|
|
}
|
|
|
|
try {
|
|
const sqlite = getSQLiteClient();
|
|
const row = sqlite.prepare(`
|
|
SELECT json_extract(metadata, '$.input_tokens') as input_tokens
|
|
FROM chats
|
|
WHERE thread_id LIKE ?
|
|
ORDER BY created_at DESC
|
|
LIMIT 1
|
|
`).get(`%${sessionId}%`) as { input_tokens: number | null } | undefined;
|
|
|
|
return Response.json({
|
|
inputTokens: row?.input_tokens ?? 0
|
|
});
|
|
} catch (error) {
|
|
console.error('Usage fetch error:', error);
|
|
return Response.json({ inputTokens: 0 });
|
|
}
|
|
}
|