summaryrefslogtreecommitdiffhomepage
path: root/js
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-05-26 21:08:15 -0400
committerDax Raad <[email protected]>2025-05-26 21:08:22 -0400
commite5242093526e407f829cd9eee1e90b7286d100f7 (patch)
treefe9b43a7d96b32435783e9c3370f4e45b640482b /js
parente1c897c1aed381aa07354f398417aeff6a720471 (diff)
downloadopencode-e5242093526e407f829cd9eee1e90b7286d100f7.tar.gz
opencode-e5242093526e407f829cd9eee1e90b7286d100f7.zip
title
Diffstat (limited to 'js')
-rw-r--r--js/src/session/prompt/title.txt7
-rw-r--r--js/src/session/session.ts31
2 files changed, 35 insertions, 3 deletions
diff --git a/js/src/session/prompt/title.txt b/js/src/session/prompt/title.txt
new file mode 100644
index 000000000..a57f9082b
--- /dev/null
+++ b/js/src/session/prompt/title.txt
@@ -0,0 +1,7 @@
+you will generate a short title based on the first message a user begins a conversation with
+- ensure it is not more than 50 characters long
+- the title should be a summary of the user's message
+- it should be one line long
+- do not use quotes or colons
+- the entire text you return will be used as the title
+- never return anything that is more than one sentence (one line) long
diff --git a/js/src/session/session.ts b/js/src/session/session.ts
index 4def98283..c8a941e40 100644
--- a/js/src/session/session.ts
+++ b/js/src/session/session.ts
@@ -6,6 +6,7 @@ import { Storage } from "../storage/storage";
import { Log } from "../util/log";
import {
convertToModelMessages,
+ generateText,
stepCountIs,
streamText,
type TextUIPart,
@@ -17,7 +18,9 @@ import {
import { z } from "zod";
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 { Share } from "../share/share";
@@ -120,6 +123,7 @@ export namespace Session {
sessionID: string,
...parts: UIMessagePart<UIDataTypes>[]
) {
+ const model = await LLM.findModel("claude-sonnet-4-20250514");
const session = await get(sessionID);
const l = log.clone().tag("session", sessionID);
l.info("chatting");
@@ -138,7 +142,7 @@ export namespace Session {
parts: [
{
type: "text",
- text: ANTHROPIC_PROMPT,
+ text: PROMPT_ANTHROPIC,
},
],
metadata: {
@@ -151,6 +155,28 @@ export namespace Session {
};
msgs.push(system);
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);
}
const msg: Message = {
@@ -168,7 +194,6 @@ export namespace Session {
msgs.push(msg);
await write(msg);
- const model = await LLM.findModel("claude-sonnet-4-20250514");
const result = streamText({
stopWhen: stepCountIs(1000),
messages: convertToModelMessages(msgs),