|
|
@@ -14,6 +14,13 @@ type ReviseMode = "local-fix" | "rewrite";
|
|
|
|
|
|
export interface InteractionRuntimeTools {
|
|
|
readonly listBooks: () => Promise<ReadonlyArray<string>>;
|
|
|
+ readonly chat?: (
|
|
|
+ input: string,
|
|
|
+ options: {
|
|
|
+ readonly bookId?: string;
|
|
|
+ readonly automationMode: AutomationMode;
|
|
|
+ },
|
|
|
+ ) => Promise<unknown>;
|
|
|
readonly writeNextChapter: (bookId: string) => Promise<unknown>;
|
|
|
readonly reviseDraft: (bookId: string, chapterNumber: number, mode: ReviseMode) => Promise<unknown>;
|
|
|
readonly patchChapterText: (
|
|
|
@@ -545,13 +552,22 @@ export async function runInteractionRequest(params: {
|
|
|
case "chat": {
|
|
|
const bookId = request.bookId ?? session.activeBookId;
|
|
|
const prompt = request.instruction?.trim().toLowerCase() ?? "";
|
|
|
- const responseText = /^(hi|hello|hey|你好|嗨|哈喽)$/i.test(prompt)
|
|
|
- ? (bookId
|
|
|
- ? `Hi. Active book is ${bookId}. Ask me to continue, revise a chapter, or explain what is blocked.`
|
|
|
- : "Hi. No active book yet. Open a book, list books, or tell me what you want to write.")
|
|
|
- : (bookId
|
|
|
- ? `I’m here. Active book is ${bookId}. You can ask me to continue, revise a chapter, rewrite, change focus, or inspect why the pipeline stopped.`
|
|
|
- : "I’m here. No active book is bound yet. Open a book, list books, or describe what you want to write.");
|
|
|
+ const toolResult = params.tools.chat
|
|
|
+ ? await params.tools.chat(request.instruction ?? "", {
|
|
|
+ bookId,
|
|
|
+ automationMode: session.automationMode,
|
|
|
+ })
|
|
|
+ : undefined;
|
|
|
+ const metadata = extractToolMetadata(toolResult);
|
|
|
+ const responseText = metadata.responseText ?? (
|
|
|
+ /^(hi|hello|hey|你好|嗨|哈喽)$/i.test(prompt)
|
|
|
+ ? (bookId
|
|
|
+ ? `Hi. Active book is ${bookId}. Ask me to continue, revise a chapter, or explain what is blocked.`
|
|
|
+ : "Hi. No active book yet. Open a book, list books, or tell me what you want to write.")
|
|
|
+ : (bookId
|
|
|
+ ? `I’m here. Active book is ${bookId}. You can ask me to continue, revise a chapter, rewrite, change focus, or inspect why the pipeline stopped.`
|
|
|
+ : "I’m here. No active book is bound yet. Open a book, list books, or describe what you want to write.")
|
|
|
+ );
|
|
|
const completed = markCompleted(session);
|
|
|
return {
|
|
|
session: addEvent(completed, "task.completed", "completed", responseText),
|