32 lines
1.8 KiB
TypeScript
32 lines
1.8 KiB
TypeScript
import type { TeacherRequest } from '../../shared/coding-teacher';
|
||
import { parseTeacherReply } from '../../shared/teacher-reply';
|
||
|
||
const MAX_CURRENT_QUICK_REPLIES = 3;
|
||
|
||
export function teacherReplyInstructions(): string {
|
||
return `本轮界面接收一个 JSON 对象 {"reply":string,"quickReplies":string[]}。reply 是回复正文,可使用 Markdown;quickReplies 是可选的快捷回复,最多 ${MAX_CURRENT_QUICK_REPLIES} 条,每条为非空字符串,没有快捷回复时用空数组。只使用这两个字段。字符串中的英文双引号、反斜杠和换行必须按 JSON 规则转义,确保整个对象是合法 JSON。回复的内容、语言、风格、长度和前缀遵循当前智能体的云端配置。`;
|
||
}
|
||
|
||
/** The original response remains available for diagnosis when parsing is incomplete. */
|
||
export function applyTeacherReply(request: TeacherRequest, raw: string): void {
|
||
const parsed = parseTeacherReply(raw);
|
||
// Apply the current UI contract only to new replies; archived replies keep
|
||
// their original cards through the compatibility parser and topic store.
|
||
if (parsed.quickReplies.length > MAX_CURRENT_QUICK_REPLIES) {
|
||
parsed.quickReplies = [];
|
||
parsed.parseError ??= '快捷回复超过当前界面最多 3 条的限制,正文已保留,快捷回复未展示。';
|
||
}
|
||
request.response = parsed.reply;
|
||
request.suggestedQuestions = parsed.quickReplies;
|
||
if (parsed.incomplete) request.replyIncomplete = true;
|
||
else delete request.replyIncomplete;
|
||
if (parsed.parseError) {
|
||
request.replyParseError = parsed.parseError;
|
||
} else {
|
||
delete request.replyParseError;
|
||
delete request.discussionError;
|
||
}
|
||
if (parsed.parseError || parsed.recovered) request.unparsedResponse = raw;
|
||
else delete request.unparsedResponse;
|
||
}
|