feat: multi-provider AI support with per-provider model selection

- Add llm-factory.ts: unified LLM provider abstraction (Google/Claude/OpenAI)
- Install @langchain/anthropic and @langchain/openai packages
- resolveAiProvider picks active provider from DB settings (Claude > OpenAI > Google)
- All AI graphs (reminder, new-patient, reschedule, internal-chat) now accept provider+model params
- Add claudeAiModel, openAiModel, googleAiModel columns to ai_settings table
- New PUT /api/ai/provider-model route to save selected model per provider
- UI model dropdowns for Claude (Haiku/Sonnet/Opus), OpenAI (GPT-5.x series), Google (Gemini 2.5/3.x)
- Google AI section also gets model selector alongside existing API key field

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ff
2026-06-06 09:34:11 -04:00
parent d5bc96ff39
commit 4899ab8368
57 changed files with 681 additions and 138 deletions

View File

@@ -8,6 +8,9 @@ export const AiSettingsAggregateResultSchema = z.object({ _count: z.object({
openAiEnabled: z.number(),
claudeAiKey: z.number(),
claudeAiEnabled: z.number(),
claudeAiModel: z.number(),
openAiModel: z.number(),
googleAiModel: z.number(),
dentalMgmtKey: z.number(),
dentalMgmtEnabled: z.number(),
afterHoursEnabled: z.number(),
@@ -28,6 +31,9 @@ export const AiSettingsAggregateResultSchema = z.object({ _count: z.object({
apiKey: z.string().nullable(),
openAiKey: z.string().nullable(),
claudeAiKey: z.string().nullable(),
claudeAiModel: z.string().nullable(),
openAiModel: z.string().nullable(),
googleAiModel: z.string().nullable(),
dentalMgmtKey: z.string().nullable()
}).nullable().optional(),
_max: z.object({
@@ -36,5 +42,8 @@ export const AiSettingsAggregateResultSchema = z.object({ _count: z.object({
apiKey: z.string().nullable(),
openAiKey: z.string().nullable(),
claudeAiKey: z.string().nullable(),
claudeAiModel: z.string().nullable(),
openAiModel: z.string().nullable(),
googleAiModel: z.string().nullable(),
dentalMgmtKey: z.string().nullable()
}).nullable().optional()});

View File

@@ -8,6 +8,9 @@ export const AiSettingsCreateResultSchema = z.object({
openAiEnabled: z.boolean(),
claudeAiKey: z.string(),
claudeAiEnabled: z.boolean(),
claudeAiModel: z.string(),
openAiModel: z.string(),
googleAiModel: z.string(),
dentalMgmtKey: z.string(),
dentalMgmtEnabled: z.boolean(),
afterHoursEnabled: z.boolean(),

View File

@@ -8,6 +8,9 @@ export const AiSettingsDeleteResultSchema = z.nullable(z.object({
openAiEnabled: z.boolean(),
claudeAiKey: z.string(),
claudeAiEnabled: z.boolean(),
claudeAiModel: z.string(),
openAiModel: z.string(),
googleAiModel: z.string(),
dentalMgmtKey: z.string(),
dentalMgmtEnabled: z.boolean(),
afterHoursEnabled: z.boolean(),

View File

@@ -8,6 +8,9 @@ export const AiSettingsFindFirstResultSchema = z.nullable(z.object({
openAiEnabled: z.boolean(),
claudeAiKey: z.string(),
claudeAiEnabled: z.boolean(),
claudeAiModel: z.string(),
openAiModel: z.string(),
googleAiModel: z.string(),
dentalMgmtKey: z.string(),
dentalMgmtEnabled: z.boolean(),
afterHoursEnabled: z.boolean(),

View File

@@ -9,6 +9,9 @@ export const AiSettingsFindManyResultSchema = z.object({
openAiEnabled: z.boolean(),
claudeAiKey: z.string(),
claudeAiEnabled: z.boolean(),
claudeAiModel: z.string(),
openAiModel: z.string(),
googleAiModel: z.string(),
dentalMgmtKey: z.string(),
dentalMgmtEnabled: z.boolean(),
afterHoursEnabled: z.boolean(),

View File

@@ -8,6 +8,9 @@ export const AiSettingsFindUniqueResultSchema = z.nullable(z.object({
openAiEnabled: z.boolean(),
claudeAiKey: z.string(),
claudeAiEnabled: z.boolean(),
claudeAiModel: z.string(),
openAiModel: z.string(),
googleAiModel: z.string(),
dentalMgmtKey: z.string(),
dentalMgmtEnabled: z.boolean(),
afterHoursEnabled: z.boolean(),

View File

@@ -8,6 +8,9 @@ export const AiSettingsGroupByResultSchema = z.array(z.object({
openAiEnabled: z.boolean(),
claudeAiKey: z.string(),
claudeAiEnabled: z.boolean(),
claudeAiModel: z.string(),
openAiModel: z.string(),
googleAiModel: z.string(),
dentalMgmtKey: z.string(),
dentalMgmtEnabled: z.boolean(),
afterHoursEnabled: z.boolean(),
@@ -21,6 +24,9 @@ export const AiSettingsGroupByResultSchema = z.array(z.object({
openAiEnabled: z.number(),
claudeAiKey: z.number(),
claudeAiEnabled: z.number(),
claudeAiModel: z.number(),
openAiModel: z.number(),
googleAiModel: z.number(),
dentalMgmtKey: z.number(),
dentalMgmtEnabled: z.number(),
afterHoursEnabled: z.number(),
@@ -41,6 +47,9 @@ export const AiSettingsGroupByResultSchema = z.array(z.object({
apiKey: z.string().nullable(),
openAiKey: z.string().nullable(),
claudeAiKey: z.string().nullable(),
claudeAiModel: z.string().nullable(),
openAiModel: z.string().nullable(),
googleAiModel: z.string().nullable(),
dentalMgmtKey: z.string().nullable()
}).nullable().optional(),
_max: z.object({
@@ -49,6 +58,9 @@ export const AiSettingsGroupByResultSchema = z.array(z.object({
apiKey: z.string().nullable(),
openAiKey: z.string().nullable(),
claudeAiKey: z.string().nullable(),
claudeAiModel: z.string().nullable(),
openAiModel: z.string().nullable(),
googleAiModel: z.string().nullable(),
dentalMgmtKey: z.string().nullable()
}).nullable().optional()
}));

View File

@@ -8,6 +8,9 @@ export const AiSettingsUpdateResultSchema = z.nullable(z.object({
openAiEnabled: z.boolean(),
claudeAiKey: z.string(),
claudeAiEnabled: z.boolean(),
claudeAiModel: z.string(),
openAiModel: z.string(),
googleAiModel: z.string(),
dentalMgmtKey: z.string(),
dentalMgmtEnabled: z.boolean(),
afterHoursEnabled: z.boolean(),

View File

@@ -8,6 +8,9 @@ export const AiSettingsUpsertResultSchema = z.object({
openAiEnabled: z.boolean(),
claudeAiKey: z.string(),
claudeAiEnabled: z.boolean(),
claudeAiModel: z.string(),
openAiModel: z.string(),
googleAiModel: z.string(),
dentalMgmtKey: z.string(),
dentalMgmtEnabled: z.boolean(),
afterHoursEnabled: z.boolean(),