biome format

master
Avraham Sakal 2 months ago
parent 5e5549e85f
commit a8eba580d0

@ -1,7 +1,7 @@
// @generated // @generated
// This file is automatically generated by Kanel. Do not modify manually. // 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; type Database = PublicSchema;

@ -1,11 +1,11 @@
// @generated // @generated
// This file is automatically generated by Kanel. Do not modify manually. // This file is automatically generated by Kanel. Do not modify manually.
import type { UsersId } from './Users'; import type { UsersId } from "./Users";
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from "kysely";
/** Identifier type for public.conversations */ /** Identifier type for public.conversations */
export type ConversationsId = number & { __brand: 'public.conversations' }; export type ConversationsId = number & { __brand: "public.conversations" };
/** Represents the table public.conversations */ /** Represents the table public.conversations */
export default interface ConversationsTable { export default interface ConversationsTable {

@ -1,12 +1,12 @@
// @generated // @generated
// This file is automatically generated by Kanel. Do not modify manually. // This file is automatically generated by Kanel. Do not modify manually.
import type { FactsId } from './Facts'; import type { FactsId } from "./Facts";
import type { ConversationsId } from './Conversations'; import type { ConversationsId } from "./Conversations";
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from "kysely";
/** Identifier type for public.fact_triggers */ /** 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 */ /** Represents the table public.fact_triggers */
export default interface FactTriggersTable { export default interface FactTriggersTable {
@ -18,9 +18,17 @@ export default interface FactTriggersTable {
priority_multiplier: ColumnType<number | null, number | null, number | null>; priority_multiplier: ColumnType<number | null, number | null, number | null>;
priority_multiplier_reason: ColumnType<string | null, string | null, string | null>; priority_multiplier_reason: ColumnType<
string | null,
scope_conversation_id: ColumnType<ConversationsId | null, ConversationsId | null, ConversationsId | null>; string | null,
string | null
>;
scope_conversation_id: ColumnType<
ConversationsId | null,
ConversationsId | null,
ConversationsId | null
>;
created_at: ColumnType<string | null, string | null, string | null>; created_at: ColumnType<string | null, string | null, string | null>;
} }

@ -1,12 +1,12 @@
// @generated // @generated
// This file is automatically generated by Kanel. Do not modify manually. // This file is automatically generated by Kanel. Do not modify manually.
import type { UsersId } from './Users'; import type { UsersId } from "./Users";
import type { MessagesId } from './Messages'; import type { MessagesId } from "./Messages";
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from "kysely";
/** Identifier type for public.facts */ /** Identifier type for public.facts */
export type FactsId = number & { __brand: 'public.facts' }; export type FactsId = number & { __brand: "public.facts" };
/** Represents the table public.facts */ /** Represents the table public.facts */
export default interface FactsTable { export default interface FactsTable {
@ -14,7 +14,11 @@ export default interface FactsTable {
user_id: ColumnType<UsersId | null, UsersId | null, UsersId | null>; user_id: ColumnType<UsersId | null, UsersId | null, UsersId | null>;
source_message_id: ColumnType<MessagesId | null, MessagesId | null, MessagesId | null>; source_message_id: ColumnType<
MessagesId | null,
MessagesId | null,
MessagesId | null
>;
content: ColumnType<string | null, string | null, string | null>; content: ColumnType<string | null, string | null, string | null>;

@ -1,18 +1,22 @@
// @generated // @generated
// This file is automatically generated by Kanel. Do not modify manually. // This file is automatically generated by Kanel. Do not modify manually.
import type { ConversationsId } from './Conversations'; import type { ConversationsId } from "./Conversations";
import type { default as Role } from './Role'; import type { default as Role } from "./Role";
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from "kysely";
/** Identifier type for public.messages */ /** Identifier type for public.messages */
export type MessagesId = number & { __brand: 'public.messages' }; export type MessagesId = number & { __brand: "public.messages" };
/** Represents the table public.messages */ /** Represents the table public.messages */
export default interface MessagesTable { export default interface MessagesTable {
id: ColumnType<MessagesId, never, never>; id: ColumnType<MessagesId, never, never>;
conversation_id: ColumnType<ConversationsId | null, ConversationsId | null, ConversationsId | null>; conversation_id: ColumnType<
ConversationsId | null,
ConversationsId | null,
ConversationsId | null
>;
index: ColumnType<number | null, number | null, number | null>; index: ColumnType<number | null, number | null, number | null>;

@ -1,12 +1,12 @@
// @generated // @generated
// This file is automatically generated by Kanel. Do not modify manually. // This file is automatically generated by Kanel. Do not modify manually.
import type { default as UsersTable } from './Users'; import type { default as UsersTable } from "./Users";
import type { default as MessagesTable } from './Messages'; import type { default as MessagesTable } from "./Messages";
import type { default as ToolsTable } from './Tools'; import type { default as ToolsTable } from "./Tools";
import type { default as FactTriggersTable } from './FactTriggers'; import type { default as FactTriggersTable } from "./FactTriggers";
import type { default as FactsTable } from './Facts'; import type { default as FactsTable } from "./Facts";
import type { default as ConversationsTable } from './Conversations'; import type { default as ConversationsTable } from "./Conversations";
export default interface PublicSchema { export default interface PublicSchema {
users: UsersTable; users: UsersTable;

@ -2,9 +2,6 @@
// This file is automatically generated by Kanel. Do not modify manually. // This file is automatically generated by Kanel. Do not modify manually.
/** Represents the enum public.role */ /** Represents the enum public.role */
type Role = type Role = "user" | "assistant" | "system";
| 'user'
| 'assistant'
| 'system';
export default Role; export default Role;

@ -1,12 +1,12 @@
// @generated // @generated
// This file is automatically generated by Kanel. Do not modify manually. // This file is automatically generated by Kanel. Do not modify manually.
import type { UsersId } from './Users'; import type { UsersId } from "./Users";
import type { MessagesId } from './Messages'; import type { MessagesId } from "./Messages";
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from "kysely";
/** Identifier type for public.tools */ /** Identifier type for public.tools */
export type ToolsId = number & { __brand: 'public.tools' }; export type ToolsId = number & { __brand: "public.tools" };
/** Represents the table public.tools */ /** Represents the table public.tools */
export default interface ToolsTable { export default interface ToolsTable {
@ -14,7 +14,11 @@ export default interface ToolsTable {
user_id: ColumnType<UsersId | null, UsersId | null, UsersId | null>; user_id: ColumnType<UsersId | null, UsersId | null, UsersId | null>;
source_message_id: ColumnType<MessagesId | null, MessagesId | null, MessagesId | null>; source_message_id: ColumnType<
MessagesId | null,
MessagesId | null,
MessagesId | null
>;
name: ColumnType<string | null, string | null, string | null>; name: ColumnType<string | null, string | null, string | null>;
@ -22,7 +26,11 @@ export default interface ToolsTable {
parameter_schema: ColumnType<unknown | null, unknown | null, unknown | null>; parameter_schema: ColumnType<unknown | null, unknown | null, unknown | null>;
implementation_language: ColumnType<string | null, string | null, string | null>; implementation_language: ColumnType<
string | null,
string | null,
string | null
>;
implementation_code: ColumnType<string | null, string | null, string | null>; implementation_code: ColumnType<string | null, string | null, string | null>;

@ -1,10 +1,10 @@
// @generated // @generated
// This file is automatically generated by Kanel. Do not modify manually. // 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 */ /** Identifier type for public.users */
export type UsersId = number & { __brand: 'public.users' }; export type UsersId = number & { __brand: "public.users" };
/** Represents the table public.users */ /** Represents the table public.users */
export default interface UsersTable { export default interface UsersTable {

@ -37,4 +37,4 @@
}, },
"share": "disabled", "share": "disabled",
"autoupdate": true "autoupdate": true
} }

@ -63,4 +63,4 @@
"wrangler": "^4.20.5" "wrangler": "^4.20.5"
}, },
"type": "module" "type": "module"
} }

@ -79,49 +79,61 @@ export const factTriggers = router({
return { ok: true }; return { ok: true };
}), }),
generateFromFact: publicProcedure generateFromFact: publicProcedure
.input((x) => x as { .input(
previousRunningSummary: string; (x) =>
messagesSincePreviousRunningSummary: Array<DraftMessage>; x as {
mainResponseContent: string; previousRunningSummary: string;
fact: Fact; messagesSincePreviousRunningSummary: Array<DraftMessage>;
}) mainResponseContent: string;
.mutation(async ({ input: { previousRunningSummary, messagesSincePreviousRunningSummary, mainResponseContent, fact } }) => { fact: Fact;
const factTriggers = await generateObject<{ },
factTriggers: Array<string>; )
}>({ .mutation(
model: openrouter("mistralai/mistral-nemo"), async ({
messages: [ input: {
{ previousRunningSummary,
role: "system" as const, messagesSincePreviousRunningSummary,
content: factTriggersSystemPrompt({ mainResponseContent,
previousRunningSummary, fact,
messagesSincePreviousRunningSummary, },
mainResponseContent, }) => {
}), const factTriggers = await generateObject<{
}, factTriggers: Array<string>;
{ }>({
role: "user" as const, model: openrouter("mistralai/mistral-nemo"),
content: factTriggersUserPrompt({ messages: [
factContent: fact.content, {
}), role: "system" as const,
}, content: factTriggersSystemPrompt({
], previousRunningSummary,
schema: jsonSchema({ messagesSincePreviousRunningSummary,
type: "object", mainResponseContent,
properties: { }),
factTriggers: { },
type: "array", {
items: { role: "user" as const,
type: "string", content: factTriggersUserPrompt({
}, factContent: fact.content,
}),
},
],
schema: jsonSchema({
type: "object",
properties: {
factTriggers: {
type: "array",
items: {
type: "string",
}, },
}, },
}), },
// maxSteps: 3, }),
// tools: undefined, // maxSteps: 3,
}); // tools: undefined,
return factTriggers; });
}) return factTriggers;
},
),
}); });
export const createCaller = createCallerFactory(factTriggers); export const createCaller = createCallerFactory(factTriggers);

@ -6,9 +6,7 @@ import {
import { createCaller as createConversationsCaller } from "./conversations.js"; import { createCaller as createConversationsCaller } from "./conversations.js";
import { openrouter } from "./provider.js"; import { openrouter } from "./provider.js";
import { generateObject, generateText, jsonSchema } from "ai"; import { generateObject, generateText, jsonSchema } from "ai";
import type { import type { DraftMessage } from "../../types.js";
DraftMessage,
} from "../../types.js";
const runningSummarySystemPrompt = ({ const runningSummarySystemPrompt = ({
previousRunningSummary, previousRunningSummary,
@ -47,7 +45,6 @@ ${mainResponseContent}
Generate a new running summary of the conversation.`; Generate a new running summary of the conversation.`;
export const messages = router({ export const messages = router({
fetchByConversationId: publicProcedure fetchByConversationId: publicProcedure
.input((x) => x as { conversationId: string }) .input((x) => x as { conversationId: string })
@ -58,13 +55,23 @@ export const messages = router({
}); });
}), }),
generateRunningSummary: publicProcedure generateRunningSummary: publicProcedure
.input((x) => x as { .input(
previousRunningSummary: string; (x) =>
messagesSincePreviousRunningSummary: Array<DraftMessage>; x as {
mainResponseContent: string; previousRunningSummary: string;
}) messagesSincePreviousRunningSummary: Array<DraftMessage>;
.mutation(async ({ input: { previousRunningSummary, messagesSincePreviousRunningSummary, mainResponseContent } }) => { mainResponseContent: string;
const runningSummaryResponse = await generateText({ },
)
.mutation(
async ({
input: {
previousRunningSummary,
messagesSincePreviousRunningSummary,
mainResponseContent,
},
}) => {
const runningSummaryResponse = await generateText({
model: openrouter("mistralai/mistral-nemo"), model: openrouter("mistralai/mistral-nemo"),
messages: [ messages: [
{ {
@ -84,8 +91,9 @@ export const messages = router({
maxSteps: 3, maxSteps: 3,
tools: undefined, tools: undefined,
}); });
return runningSummaryResponse; return runningSummaryResponse;
}), },
),
}); });
export const createCaller = createCallerFactory(messages); export const createCaller = createCallerFactory(messages);

@ -38,7 +38,6 @@ ${previousRunningSummary}
</running_summary> </running_summary>
`; `;
export const chat = router({ export const chat = router({
conversations, conversations,
messages, messages,
@ -139,11 +138,12 @@ export const chat = router({
* with the model's response to the database. The new running summary is * with the model's response to the database. The new running summary is
* based on the previous running summary combined with the all messages * based on the previous running summary combined with the all messages
* since that summary was produced. */ * since that summary was produced. */
const runningSummaryResponse = await messagesCaller.generateRunningSummary({ const runningSummaryResponse =
messagesSincePreviousRunningSummary, await messagesCaller.generateRunningSummary({
mainResponseContent: mainResponse.text, messagesSincePreviousRunningSummary,
previousRunningSummary, mainResponseContent: mainResponse.text,
}); previousRunningSummary,
});
const insertedAssistantMessage: CommittedMessage = { const insertedAssistantMessage: CommittedMessage = {
id: nanoid(), id: nanoid(),
conversationId, conversationId,
@ -193,7 +193,7 @@ export const chat = router({
mainResponseContent: mainResponse.text, mainResponseContent: mainResponse.text,
previousRunningSummary, previousRunningSummary,
messagesSincePreviousRunningSummary, messagesSincePreviousRunningSummary,
fact fact,
}); });
const insertedFactTriggers: Array<FactTrigger> = const insertedFactTriggers: Array<FactTrigger> =
factTriggers.object.factTriggers.map((factTrigger) => ({ factTriggers.object.factTriggers.map((factTrigger) => ({

Loading…
Cancel
Save