feat: add agent search config and system assistant defaults

Adds a config jsonb column to agents for per-agent search settings
(enabled, rerank, maxResults). Types systemAssistants with rename and
rerank sub-objects. Backfills missing systemAssistants keys on settings
fetch. Includes generated drizzle migrations.
This commit is contained in:
Zoe
2026-04-27 12:05:27 -05:00
parent 1ed2bd8b16
commit 90d5698e76
10 changed files with 5565 additions and 19 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,16 @@
ALTER TABLE "agents" ADD COLUMN "config" jsonb DEFAULT '{}';--> statement-breakpoint
ALTER TABLE "accounts" DROP CONSTRAINT "accounts_user_id_users_id_fkey", ADD CONSTRAINT "accounts_user_id_users_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "agents" DROP CONSTRAINT "agents_default_model_id_models_id_fkey", ADD CONSTRAINT "agents_default_model_id_models_id_fkey" FOREIGN KEY ("default_model_id") REFERENCES "models"("id") ON DELETE SET NULL;--> statement-breakpoint
ALTER TABLE "attachments" DROP CONSTRAINT "attachments_file_id_files_id_fkey", ADD CONSTRAINT "attachments_file_id_files_id_fkey" FOREIGN KEY ("file_id") REFERENCES "files"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "attachments" DROP CONSTRAINT "attachments_message_id_messages_id_fkey", ADD CONSTRAINT "attachments_message_id_messages_id_fkey" FOREIGN KEY ("message_id") REFERENCES "messages"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "attachments" DROP CONSTRAINT "attachments_topic_id_topics_id_fkey", ADD CONSTRAINT "attachments_topic_id_topics_id_fkey" FOREIGN KEY ("topic_id") REFERENCES "topics"("id");--> statement-breakpoint
ALTER TABLE "embeddings" DROP CONSTRAINT "embeddings_file_id_files_id_fkey", ADD CONSTRAINT "embeddings_file_id_files_id_fkey" FOREIGN KEY ("file_id") REFERENCES "files"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "generations" DROP CONSTRAINT "generations_topic_id_topics_id_fkey", ADD CONSTRAINT "generations_topic_id_topics_id_fkey" FOREIGN KEY ("topic_id") REFERENCES "topics"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "message_parts" DROP CONSTRAINT "message_parts_message_id_messages_id_fkey", ADD CONSTRAINT "message_parts_message_id_messages_id_fkey" FOREIGN KEY ("message_id") REFERENCES "messages"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "message_parts" DROP CONSTRAINT "message_parts_tool_call_id_tool_calls_id_fkey", ADD CONSTRAINT "message_parts_tool_call_id_tool_calls_id_fkey" FOREIGN KEY ("tool_call_id") REFERENCES "tool_calls"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "message_parts" DROP CONSTRAINT "message_parts_topic_id_topics_id_fkey", ADD CONSTRAINT "message_parts_topic_id_topics_id_fkey" FOREIGN KEY ("topic_id") REFERENCES "topics"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "messages" DROP CONSTRAINT "messages_generation_id_generations_id_fkey", ADD CONSTRAINT "messages_generation_id_generations_id_fkey" FOREIGN KEY ("generation_id") REFERENCES "generations"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "messages" DROP CONSTRAINT "messages_topic_id_topics_id_fkey", ADD CONSTRAINT "messages_topic_id_topics_id_fkey" FOREIGN KEY ("topic_id") REFERENCES "topics"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "models" DROP CONSTRAINT "models_provider_id_providers_id_fkey", ADD CONSTRAINT "models_provider_id_providers_id_fkey" FOREIGN KEY ("provider_id") REFERENCES "providers"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "sessions" DROP CONSTRAINT "sessions_user_id_users_id_fkey", ADD CONSTRAINT "sessions_user_id_users_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "topics" DROP CONSTRAINT "topics_agent_id_agents_id_fkey", ADD CONSTRAINT "topics_agent_id_agents_id_fkey" FOREIGN KEY ("agent_id") REFERENCES "agents"("id") ON DELETE CASCADE;
File diff suppressed because it is too large Load Diff
+18 -2
View File
@@ -23,7 +23,16 @@ export enum ToolCallType {
export const settings = pgTable('settings', {
id: text('id').primaryKey().$defaultFn(nanoid),
userId: text('user_id').notNull(),
systemAssistants: jsonb('system_assistants').$type<Record<string, any>>().notNull().default({}),
systemAssistants: jsonb('system_assistants').$type<{
rename: {
enabled: boolean;
modelId: string | null;
};
rerank: {
enabled: boolean;
modelId: string | null;
};
}>().notNull().default({} as any),
appearance: jsonb('appearance').$type<{
colorScheme?: 'light' | 'dark' | 'system';
accent?: string;
@@ -93,6 +102,13 @@ export const agents = pgTable('agents', {
systemPrompt: text('system_prompt'),
imageUrl: text('image_url'),
defaultModelId: text('default_model_id').references(() => models.id, { onDelete: 'set null' }),
config: jsonb('config').$type<{
search?: {
enabled: boolean;
rerank: boolean;
maxResults: number;
}
}>().default({}),
createdAt: timestamp('created_at').notNull().defaultNow(),
}, (table) => [
index('agents_userId_idx').on(table.userId),
@@ -215,7 +231,7 @@ export const embeddings = pgTable('embeddings', {
export const attachments = pgTable('attachments', {
id: text('id').primaryKey().$defaultFn(nanoid),
userId: text('user_id').notNull(),
topicId: text('topic_id').notNull().references(() => topics.id),
topicId: text('topic_id').notNull().references(() => topics.id, { onDelete: 'cascade' }),
messageId: text('message_id').notNull().references(() => messages.id, { onDelete: 'cascade' }),
fileId: text('file_id').notNull().references(() => files.id, { onDelete: 'cascade' }),
createdAt: timestamp('created_at').notNull().defaultNow(),