system prompt

This commit is contained in:
2026-02-17 22:03:02 +00:00
parent 680f623b41
commit cb603e3cf9
7 changed files with 53 additions and 17 deletions
@@ -63,6 +63,10 @@ export const useClaude = (initialSessionId?: string, initialModel?: string | nul
if (replaceUrl) window.history.replaceState(null, '', `/chat/${msg.sessionId}`);
break;
case 'system:prompt':
setMessages((prev) => [...prev, { role: 'system', text: msg.text }]);
break;
case 'assistant:partial':
streamingRef.current += msg.text;
flushStreaming();
@@ -5,6 +5,26 @@ import { useVisibleOpenCodeModels } from '@/state/useModels';
import { useChatSessions } from '@/state/useChatSessions';
import type { ChatMessage, ServerMessage, TaskInfo } from 'widgets/Chat';
const SYSTEM_RE = /^<system>([\s\S]*?)<\/system>\s*/;
const splitSystemBlocks = (messages: ChatMessage[]): ChatMessage[] => {
const result: ChatMessage[] = [];
for (const msg of messages) {
if (msg.role !== 'user') {
result.push(msg);
continue;
}
const match = msg.text.match(SYSTEM_RE);
if (!match) {
result.push(msg);
continue;
}
result.push({ role: 'user', text: msg.text.slice(match[0]!.length), images: msg.images });
result.push({ role: 'system', text: match[1]!.trim() });
}
return result;
};
type UseOpenCodeOptions = {
replaceUrl?: boolean;
taskInfo?: TaskInfo;
@@ -68,6 +88,10 @@ export const useOpenCode = (initialSessionId?: string, initialModel?: string | n
if (replaceUrl) window.history.replaceState(null, '', `/chat/opencode/${msg.sessionId}`);
break;
case 'system:prompt':
setMessages((prev) => [...prev, { role: 'system', text: msg.text }]);
break;
case 'assistant:partial':
streamingRef.current += msg.text;
flushStreaming();
@@ -146,7 +170,7 @@ export const useOpenCode = (initialSessionId?: string, initialModel?: string | n
if (!initialSessionId) return;
getMessages('opencode', initialSessionId)
.then((data) => {
if (Array.isArray(data) && data.length > 0) setMessages(data);
if (Array.isArray(data) && data.length > 0) setMessages(splitSystemBlocks(data));
})
.catch(() => {});
}, [initialSessionId]);