|
@@ -6,6 +6,7 @@ import { Storage } from "../storage/storage";
|
|
|
import { Log } from "../util/log";
|
|
import { Log } from "../util/log";
|
|
|
import {
|
|
import {
|
|
|
convertToModelMessages,
|
|
convertToModelMessages,
|
|
|
|
|
+ generateText,
|
|
|
stepCountIs,
|
|
stepCountIs,
|
|
|
streamText,
|
|
streamText,
|
|
|
type TextUIPart,
|
|
type TextUIPart,
|
|
@@ -17,7 +18,9 @@ import {
|
|
|
import { z } from "zod";
|
|
import { z } from "zod";
|
|
|
import * as tools from "../tool";
|
|
import * as tools from "../tool";
|
|
|
|
|
|
|
|
-import ANTHROPIC_PROMPT from "./prompt/anthropic.txt";
|
|
|
|
|
|
|
+import PROMPT_ANTHROPIC from "./prompt/anthropic.txt";
|
|
|
|
|
+import PROMPT_TITLE from "./prompt/title.txt";
|
|
|
|
|
+
|
|
|
import type { Tool } from "../tool/tool";
|
|
import type { Tool } from "../tool/tool";
|
|
|
import { Share } from "../share/share";
|
|
import { Share } from "../share/share";
|
|
|
|
|
|
|
@@ -120,6 +123,7 @@ export namespace Session {
|
|
|
sessionID: string,
|
|
sessionID: string,
|
|
|
...parts: UIMessagePart<UIDataTypes>[]
|
|
...parts: UIMessagePart<UIDataTypes>[]
|
|
|
) {
|
|
) {
|
|
|
|
|
+ const model = await LLM.findModel("claude-sonnet-4-20250514");
|
|
|
const session = await get(sessionID);
|
|
const session = await get(sessionID);
|
|
|
const l = log.clone().tag("session", sessionID);
|
|
const l = log.clone().tag("session", sessionID);
|
|
|
l.info("chatting");
|
|
l.info("chatting");
|
|
@@ -138,7 +142,7 @@ export namespace Session {
|
|
|
parts: [
|
|
parts: [
|
|
|
{
|
|
{
|
|
|
type: "text",
|
|
type: "text",
|
|
|
- text: ANTHROPIC_PROMPT,
|
|
|
|
|
|
|
+ text: PROMPT_ANTHROPIC,
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
|
metadata: {
|
|
metadata: {
|
|
@@ -151,6 +155,28 @@ export namespace Session {
|
|
|
};
|
|
};
|
|
|
msgs.push(system);
|
|
msgs.push(system);
|
|
|
state().messages.set(sessionID, msgs);
|
|
state().messages.set(sessionID, msgs);
|
|
|
|
|
+ generateText({
|
|
|
|
|
+ messages: convertToModelMessages([
|
|
|
|
|
+ {
|
|
|
|
|
+ role: "system",
|
|
|
|
|
+ parts: [
|
|
|
|
|
+ {
|
|
|
|
|
+ type: "text",
|
|
|
|
|
+ text: PROMPT_TITLE,
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ role: "user",
|
|
|
|
|
+ parts,
|
|
|
|
|
+ },
|
|
|
|
|
+ ]),
|
|
|
|
|
+ model,
|
|
|
|
|
+ }).then(async (result) => {
|
|
|
|
|
+ const session = await Session.get(sessionID);
|
|
|
|
|
+ session.title = result.text;
|
|
|
|
|
+ return Session.update(session);
|
|
|
|
|
+ });
|
|
|
await write(system);
|
|
await write(system);
|
|
|
}
|
|
}
|
|
|
const msg: Message = {
|
|
const msg: Message = {
|
|
@@ -168,7 +194,6 @@ export namespace Session {
|
|
|
msgs.push(msg);
|
|
msgs.push(msg);
|
|
|
await write(msg);
|
|
await write(msg);
|
|
|
|
|
|
|
|
- const model = await LLM.findModel("claude-sonnet-4-20250514");
|
|
|
|
|
const result = streamText({
|
|
const result = streamText({
|
|
|
stopWhen: stepCountIs(1000),
|
|
stopWhen: stepCountIs(1000),
|
|
|
messages: convertToModelMessages(msgs),
|
|
messages: convertToModelMessages(msgs),
|