From a8eba580d00d4b8337a719304145313b05c9a340 Mon Sep 17 00:00:00 2001 From: Avraham Sakal Date: Fri, 8 Aug 2025 17:02:53 -0400 Subject: [PATCH] biome format --- database/generated/Database.ts | 2 +- database/generated/public/Conversations.ts | 6 +- database/generated/public/FactTriggers.ts | 22 +++-- database/generated/public/Facts.ts | 14 ++-- database/generated/public/Messages.ts | 14 ++-- database/generated/public/PublicSchema.ts | 12 +-- database/generated/public/Role.ts | 5 +- database/generated/public/Tools.ts | 20 +++-- database/generated/public/Users.ts | 4 +- opencode.json | 2 +- package.json | 2 +- pages/chat/fact-triggers.ts | 94 ++++++++++++---------- pages/chat/messages.ts | 34 +++++--- pages/chat/trpc.ts | 14 ++-- 14 files changed, 143 insertions(+), 102 deletions(-) diff --git a/database/generated/Database.ts b/database/generated/Database.ts index 2fa9940..8fa64f8 100644 --- a/database/generated/Database.ts +++ b/database/generated/Database.ts @@ -1,7 +1,7 @@ // @generated // This file is automatically generated by Kanel. Do not modify manually. -import type { default as PublicSchema } from './public/PublicSchema'; +import type { default as PublicSchema } from "./public/PublicSchema"; type Database = PublicSchema; diff --git a/database/generated/public/Conversations.ts b/database/generated/public/Conversations.ts index 660622f..eebf6b2 100644 --- a/database/generated/public/Conversations.ts +++ b/database/generated/public/Conversations.ts @@ -1,11 +1,11 @@ // @generated // This file is automatically generated by Kanel. Do not modify manually. -import type { UsersId } from './Users'; -import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; +import type { UsersId } from "./Users"; +import type { ColumnType, Selectable, Insertable, Updateable } from "kysely"; /** Identifier type for public.conversations */ -export type ConversationsId = number & { __brand: 'public.conversations' }; +export type ConversationsId = number & { __brand: "public.conversations" }; /** Represents the table public.conversations */ export default interface ConversationsTable { diff --git a/database/generated/public/FactTriggers.ts b/database/generated/public/FactTriggers.ts index 27bb280..aa8bdba 100644 --- a/database/generated/public/FactTriggers.ts +++ b/database/generated/public/FactTriggers.ts @@ -1,12 +1,12 @@ // @generated // This file is automatically generated by Kanel. Do not modify manually. -import type { FactsId } from './Facts'; -import type { ConversationsId } from './Conversations'; -import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; +import type { FactsId } from "./Facts"; +import type { ConversationsId } from "./Conversations"; +import type { ColumnType, Selectable, Insertable, Updateable } from "kysely"; /** Identifier type for public.fact_triggers */ -export type FactTriggersId = number & { __brand: 'public.fact_triggers' }; +export type FactTriggersId = number & { __brand: "public.fact_triggers" }; /** Represents the table public.fact_triggers */ export default interface FactTriggersTable { @@ -18,9 +18,17 @@ export default interface FactTriggersTable { priority_multiplier: ColumnType; - priority_multiplier_reason: ColumnType; - - scope_conversation_id: ColumnType; + priority_multiplier_reason: ColumnType< + string | null, + string | null, + string | null + >; + + scope_conversation_id: ColumnType< + ConversationsId | null, + ConversationsId | null, + ConversationsId | null + >; created_at: ColumnType; } diff --git a/database/generated/public/Facts.ts b/database/generated/public/Facts.ts index 869a654..b44732b 100644 --- a/database/generated/public/Facts.ts +++ b/database/generated/public/Facts.ts @@ -1,12 +1,12 @@ // @generated // This file is automatically generated by Kanel. Do not modify manually. -import type { UsersId } from './Users'; -import type { MessagesId } from './Messages'; -import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; +import type { UsersId } from "./Users"; +import type { MessagesId } from "./Messages"; +import type { ColumnType, Selectable, Insertable, Updateable } from "kysely"; /** Identifier type for public.facts */ -export type FactsId = number & { __brand: 'public.facts' }; +export type FactsId = number & { __brand: "public.facts" }; /** Represents the table public.facts */ export default interface FactsTable { @@ -14,7 +14,11 @@ export default interface FactsTable { user_id: ColumnType; - source_message_id: ColumnType; + source_message_id: ColumnType< + MessagesId | null, + MessagesId | null, + MessagesId | null + >; content: ColumnType; diff --git a/database/generated/public/Messages.ts b/database/generated/public/Messages.ts index 20caba6..c596dee 100644 --- a/database/generated/public/Messages.ts +++ b/database/generated/public/Messages.ts @@ -1,18 +1,22 @@ // @generated // This file is automatically generated by Kanel. Do not modify manually. -import type { ConversationsId } from './Conversations'; -import type { default as Role } from './Role'; -import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; +import type { ConversationsId } from "./Conversations"; +import type { default as Role } from "./Role"; +import type { ColumnType, Selectable, Insertable, Updateable } from "kysely"; /** Identifier type for public.messages */ -export type MessagesId = number & { __brand: 'public.messages' }; +export type MessagesId = number & { __brand: "public.messages" }; /** Represents the table public.messages */ export default interface MessagesTable { id: ColumnType; - conversation_id: ColumnType; + conversation_id: ColumnType< + ConversationsId | null, + ConversationsId | null, + ConversationsId | null + >; index: ColumnType; diff --git a/database/generated/public/PublicSchema.ts b/database/generated/public/PublicSchema.ts index 5612c18..bb33082 100644 --- a/database/generated/public/PublicSchema.ts +++ b/database/generated/public/PublicSchema.ts @@ -1,12 +1,12 @@ // @generated // This file is automatically generated by Kanel. Do not modify manually. -import type { default as UsersTable } from './Users'; -import type { default as MessagesTable } from './Messages'; -import type { default as ToolsTable } from './Tools'; -import type { default as FactTriggersTable } from './FactTriggers'; -import type { default as FactsTable } from './Facts'; -import type { default as ConversationsTable } from './Conversations'; +import type { default as UsersTable } from "./Users"; +import type { default as MessagesTable } from "./Messages"; +import type { default as ToolsTable } from "./Tools"; +import type { default as FactTriggersTable } from "./FactTriggers"; +import type { default as FactsTable } from "./Facts"; +import type { default as ConversationsTable } from "./Conversations"; export default interface PublicSchema { users: UsersTable; diff --git a/database/generated/public/Role.ts b/database/generated/public/Role.ts index 309d9ed..c69e55f 100644 --- a/database/generated/public/Role.ts +++ b/database/generated/public/Role.ts @@ -2,9 +2,6 @@ // This file is automatically generated by Kanel. Do not modify manually. /** Represents the enum public.role */ -type Role = - | 'user' - | 'assistant' - | 'system'; +type Role = "user" | "assistant" | "system"; export default Role; diff --git a/database/generated/public/Tools.ts b/database/generated/public/Tools.ts index b18899f..2b8ad61 100644 --- a/database/generated/public/Tools.ts +++ b/database/generated/public/Tools.ts @@ -1,12 +1,12 @@ // @generated // This file is automatically generated by Kanel. Do not modify manually. -import type { UsersId } from './Users'; -import type { MessagesId } from './Messages'; -import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; +import type { UsersId } from "./Users"; +import type { MessagesId } from "./Messages"; +import type { ColumnType, Selectable, Insertable, Updateable } from "kysely"; /** Identifier type for public.tools */ -export type ToolsId = number & { __brand: 'public.tools' }; +export type ToolsId = number & { __brand: "public.tools" }; /** Represents the table public.tools */ export default interface ToolsTable { @@ -14,7 +14,11 @@ export default interface ToolsTable { user_id: ColumnType; - source_message_id: ColumnType; + source_message_id: ColumnType< + MessagesId | null, + MessagesId | null, + MessagesId | null + >; name: ColumnType; @@ -22,7 +26,11 @@ export default interface ToolsTable { parameter_schema: ColumnType; - implementation_language: ColumnType; + implementation_language: ColumnType< + string | null, + string | null, + string | null + >; implementation_code: ColumnType; diff --git a/database/generated/public/Users.ts b/database/generated/public/Users.ts index 0dcf5bb..5539cb0 100644 --- a/database/generated/public/Users.ts +++ b/database/generated/public/Users.ts @@ -1,10 +1,10 @@ // @generated // This file is automatically generated by Kanel. Do not modify manually. -import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; +import type { ColumnType, Selectable, Insertable, Updateable } from "kysely"; /** Identifier type for public.users */ -export type UsersId = number & { __brand: 'public.users' }; +export type UsersId = number & { __brand: "public.users" }; /** Represents the table public.users */ export default interface UsersTable { diff --git a/opencode.json b/opencode.json index a82a801..7e545bd 100644 --- a/opencode.json +++ b/opencode.json @@ -37,4 +37,4 @@ }, "share": "disabled", "autoupdate": true -} \ No newline at end of file +} diff --git a/package.json b/package.json index 461f87a..6216172 100644 --- a/package.json +++ b/package.json @@ -63,4 +63,4 @@ "wrangler": "^4.20.5" }, "type": "module" -} \ No newline at end of file +} diff --git a/pages/chat/fact-triggers.ts b/pages/chat/fact-triggers.ts index d8269a0..84c4f02 100644 --- a/pages/chat/fact-triggers.ts +++ b/pages/chat/fact-triggers.ts @@ -79,49 +79,61 @@ export const factTriggers = router({ return { ok: true }; }), generateFromFact: publicProcedure - .input((x) => x as { - previousRunningSummary: string; - messagesSincePreviousRunningSummary: Array; - mainResponseContent: string; - fact: Fact; - }) - .mutation(async ({ input: { previousRunningSummary, messagesSincePreviousRunningSummary, mainResponseContent, fact } }) => { - const factTriggers = await generateObject<{ - factTriggers: Array; - }>({ - model: openrouter("mistralai/mistral-nemo"), - messages: [ - { - role: "system" as const, - content: factTriggersSystemPrompt({ - previousRunningSummary, - messagesSincePreviousRunningSummary, - mainResponseContent, - }), - }, - { - role: "user" as const, - content: factTriggersUserPrompt({ - factContent: fact.content, - }), - }, - ], - schema: jsonSchema({ - type: "object", - properties: { - factTriggers: { - type: "array", - items: { - type: "string", - }, + .input( + (x) => + x as { + previousRunningSummary: string; + messagesSincePreviousRunningSummary: Array; + mainResponseContent: string; + fact: Fact; + }, + ) + .mutation( + async ({ + input: { + previousRunningSummary, + messagesSincePreviousRunningSummary, + mainResponseContent, + fact, + }, + }) => { + const factTriggers = await generateObject<{ + factTriggers: Array; + }>({ + model: openrouter("mistralai/mistral-nemo"), + messages: [ + { + role: "system" as const, + content: factTriggersSystemPrompt({ + previousRunningSummary, + messagesSincePreviousRunningSummary, + mainResponseContent, + }), + }, + { + role: "user" as const, + content: factTriggersUserPrompt({ + factContent: fact.content, + }), + }, + ], + schema: jsonSchema({ + type: "object", + properties: { + factTriggers: { + type: "array", + items: { + type: "string", }, }, - }), - // maxSteps: 3, - // tools: undefined, - }); - return factTriggers; - }) + }, + }), + // maxSteps: 3, + // tools: undefined, + }); + return factTriggers; + }, + ), }); export const createCaller = createCallerFactory(factTriggers); diff --git a/pages/chat/messages.ts b/pages/chat/messages.ts index 9b89f42..48d7660 100644 --- a/pages/chat/messages.ts +++ b/pages/chat/messages.ts @@ -6,9 +6,7 @@ import { import { createCaller as createConversationsCaller } from "./conversations.js"; import { openrouter } from "./provider.js"; import { generateObject, generateText, jsonSchema } from "ai"; -import type { - DraftMessage, -} from "../../types.js"; +import type { DraftMessage } from "../../types.js"; const runningSummarySystemPrompt = ({ previousRunningSummary, @@ -47,7 +45,6 @@ ${mainResponseContent} Generate a new running summary of the conversation.`; - export const messages = router({ fetchByConversationId: publicProcedure .input((x) => x as { conversationId: string }) @@ -58,13 +55,23 @@ export const messages = router({ }); }), generateRunningSummary: publicProcedure - .input((x) => x as { - previousRunningSummary: string; - messagesSincePreviousRunningSummary: Array; - mainResponseContent: string; - }) - .mutation(async ({ input: { previousRunningSummary, messagesSincePreviousRunningSummary, mainResponseContent } }) => { - const runningSummaryResponse = await generateText({ + .input( + (x) => + x as { + previousRunningSummary: string; + messagesSincePreviousRunningSummary: Array; + mainResponseContent: string; + }, + ) + .mutation( + async ({ + input: { + previousRunningSummary, + messagesSincePreviousRunningSummary, + mainResponseContent, + }, + }) => { + const runningSummaryResponse = await generateText({ model: openrouter("mistralai/mistral-nemo"), messages: [ { @@ -84,8 +91,9 @@ export const messages = router({ maxSteps: 3, tools: undefined, }); - return runningSummaryResponse; - }), + return runningSummaryResponse; + }, + ), }); export const createCaller = createCallerFactory(messages); diff --git a/pages/chat/trpc.ts b/pages/chat/trpc.ts index 8977172..2e8b388 100644 --- a/pages/chat/trpc.ts +++ b/pages/chat/trpc.ts @@ -38,7 +38,6 @@ ${previousRunningSummary} `; - export const chat = router({ conversations, messages, @@ -139,11 +138,12 @@ export const chat = router({ * with the model's response to the database. The new running summary is * based on the previous running summary combined with the all messages * since that summary was produced. */ - const runningSummaryResponse = await messagesCaller.generateRunningSummary({ - messagesSincePreviousRunningSummary, - mainResponseContent: mainResponse.text, - previousRunningSummary, - }); + const runningSummaryResponse = + await messagesCaller.generateRunningSummary({ + messagesSincePreviousRunningSummary, + mainResponseContent: mainResponse.text, + previousRunningSummary, + }); const insertedAssistantMessage: CommittedMessage = { id: nanoid(), conversationId, @@ -193,7 +193,7 @@ export const chat = router({ mainResponseContent: mainResponse.text, previousRunningSummary, messagesSincePreviousRunningSummary, - fact + fact, }); const insertedFactTriggers: Array = factTriggers.object.factTriggers.map((factTrigger) => ({