|
|
|
@ -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<DraftMessage>;
|
|
|
|
|
mainResponseContent: string;
|
|
|
|
|
})
|
|
|
|
|
.mutation(async ({ input: { previousRunningSummary, messagesSincePreviousRunningSummary, mainResponseContent } }) => {
|
|
|
|
|
const runningSummaryResponse = await generateText({
|
|
|
|
|
.input(
|
|
|
|
|
(x) =>
|
|
|
|
|
x as {
|
|
|
|
|
previousRunningSummary: string;
|
|
|
|
|
messagesSincePreviousRunningSummary: Array<DraftMessage>;
|
|
|
|
|
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);
|
|
|
|
|