|
@@ -55,6 +55,7 @@ import type { PrePluginChainResult } from "@/lib/agent/pipeline"
|
|
|
import { applyAgentToolActivityEvent, applyAgentToolEvent } from "@/lib/agent/tool-events"
|
|
import { applyAgentToolActivityEvent, applyAgentToolEvent } from "@/lib/agent/tool-events"
|
|
|
import { applyAgentActivityEvent, createAgentActivityEvent, settleRunningAgentStages } from "@/lib/agent/activity-trace"
|
|
import { applyAgentActivityEvent, createAgentActivityEvent, settleRunningAgentStages } from "@/lib/agent/activity-trace"
|
|
|
import { useAgentConfig } from "@/hooks/use-agent-config"
|
|
import { useAgentConfig } from "@/hooks/use-agent-config"
|
|
|
|
|
+import { resolveContextPackTokenBudget } from "@/lib/context-budget"
|
|
|
import { resolveChapterLengthSpec } from "@/lib/novel/deep-chapter-prompts"
|
|
import { resolveChapterLengthSpec } from "@/lib/novel/deep-chapter-prompts"
|
|
|
import { executeIngestWrites } from "@/lib/ingest"
|
|
import { executeIngestWrites } from "@/lib/ingest"
|
|
|
import { routeTask, buildTaskDirective, type TaskRouteResult } from "@/lib/novel/task-router"
|
|
import { routeTask, buildTaskDirective, type TaskRouteResult } from "@/lib/novel/task-router"
|
|
@@ -104,6 +105,10 @@ import type { FrameworkBinding, StoryFramework } from "@/lib/novel/story-simulat
|
|
|
|
|
|
|
|
import type { AiWorkflowMode } from "@/lib/agent/workflow-mode"
|
|
import type { AiWorkflowMode } from "@/lib/agent/workflow-mode"
|
|
|
import { buildPlanExecutePolicyPrompt, WRITING_INTENTS } from "@/lib/agent/plan-execute-policy"
|
|
import { buildPlanExecutePolicyPrompt, WRITING_INTENTS } from "@/lib/agent/plan-execute-policy"
|
|
|
|
|
+import {
|
|
|
|
|
+ buildOutlineFindProtocol,
|
|
|
|
|
+ shouldIncludeOutlineFindProtocol,
|
|
|
|
|
+} from "@/lib/novel/outline-find-protocol"
|
|
|
import { createContextTrace, finishTrace, setContextInfo, type ContextTrace } from "@/lib/agent/context-trace"
|
|
import { createContextTrace, finishTrace, setContextInfo, type ContextTrace } from "@/lib/agent/context-trace"
|
|
|
import { settleRunningAgentToolCalls } from "@/lib/agent/tool-events"
|
|
import { settleRunningAgentToolCalls } from "@/lib/agent/tool-events"
|
|
|
import { appendMcpCallTrace } from "@/lib/agent/mcp-trace"
|
|
import { appendMcpCallTrace } from "@/lib/agent/mcp-trace"
|
|
@@ -285,6 +290,9 @@ function buildChatAgentSystemPrompt(options: {
|
|
|
agentWritingSkills?: UserSkill[]
|
|
agentWritingSkills?: UserSkill[]
|
|
|
projectName?: string
|
|
projectName?: string
|
|
|
bindingTitle?: string
|
|
bindingTitle?: string
|
|
|
|
|
+ targetChapterNumber?: number
|
|
|
|
|
+ /** 仅章节写作且不会走 pre-plugin 时注入,避免与 build_system_prompt plugin 重复 */
|
|
|
|
|
+ includeOutlineFindProtocol?: boolean
|
|
|
}): string {
|
|
}): string {
|
|
|
const lines = [
|
|
const lines = [
|
|
|
options.novelMode
|
|
options.novelMode
|
|
@@ -305,6 +313,9 @@ function buildChatAgentSystemPrompt(options: {
|
|
|
lines.push("小说模式下,如果用户要求生成、续写或改写章节,只输出可直接放入章节库的正文。")
|
|
lines.push("小说模式下,如果用户要求生成、续写或改写章节,只输出可直接放入章节库的正文。")
|
|
|
lines.push("章节生成、续写或改写任务的最终回复必须只包含章节正文,不要把工具读取过程、写作计划或执行过程展示给用户。")
|
|
lines.push("章节生成、续写或改写任务的最终回复必须只包含章节正文,不要把工具读取过程、写作计划或执行过程展示给用户。")
|
|
|
lines.push("不要输出读取说明、执行总结、完成目标表格、章节结构、后续建议、引用来源或 Markdown 表格;章节标题和正文以外的内容都不要输出。")
|
|
lines.push("不要输出读取说明、执行总结、完成目标表格、章节结构、后续建议、引用来源或 Markdown 表格;章节标题和正文以外的内容都不要输出。")
|
|
|
|
|
+ if (options.includeOutlineFindProtocol) {
|
|
|
|
|
+ lines.push(buildOutlineFindProtocol(options.targetChapterNumber))
|
|
|
|
|
+ }
|
|
|
if (options.aiWorkflowMode === "fast") {
|
|
if (options.aiWorkflowMode === "fast") {
|
|
|
lines.push("快速模式下可以读取必要上下文;除非用户明确要求使用工作流或 Skill,否则不要主动调用 run_chapter_workflow。")
|
|
lines.push("快速模式下可以读取必要上下文;除非用户明确要求使用工作流或 Skill,否则不要主动调用 run_chapter_workflow。")
|
|
|
} else {
|
|
} else {
|
|
@@ -1350,16 +1361,6 @@ export function ChatPanel() {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const sessionAgentSystemPrompt = buildChatAgentSystemPrompt({
|
|
|
|
|
- novelMode,
|
|
|
|
|
- mode,
|
|
|
|
|
- deepChapterEnabled,
|
|
|
|
|
- chatEditModeEnabled,
|
|
|
|
|
- aiWorkflowMode,
|
|
|
|
|
- planExecuteEnabled: planExecuteActive,
|
|
|
|
|
- projectName: project?.name,
|
|
|
|
|
- bindingTitle: activeBinding?.framework.title,
|
|
|
|
|
- })
|
|
|
|
|
const lastGeneratedChapterNumber = novelMode
|
|
const lastGeneratedChapterNumber = novelMode
|
|
|
? detectLastGeneratedChapterNumber(
|
|
? detectLastGeneratedChapterNumber(
|
|
|
activeConvMessages
|
|
activeConvMessages
|
|
@@ -1468,6 +1469,22 @@ export function ChatPanel() {
|
|
|
}
|
|
}
|
|
|
: taskRoute
|
|
: taskRoute
|
|
|
|
|
|
|
|
|
|
+ const sessionAgentSystemPrompt = buildChatAgentSystemPrompt({
|
|
|
|
|
+ novelMode,
|
|
|
|
|
+ mode,
|
|
|
|
|
+ deepChapterEnabled,
|
|
|
|
|
+ chatEditModeEnabled,
|
|
|
|
|
+ aiWorkflowMode,
|
|
|
|
|
+ planExecuteEnabled: planExecuteActive,
|
|
|
|
|
+ projectName: project?.name,
|
|
|
|
|
+ bindingTitle: activeBinding?.framework.title,
|
|
|
|
|
+ targetChapterNumber,
|
|
|
|
|
+ // pre-plugin 会注入找纲协议;仅在不会跑 pre-plugin 的章节写作路径由这里注入一次
|
|
|
|
|
+ includeOutlineFindProtocol:
|
|
|
|
|
+ shouldIncludeOutlineFindProtocol(effectiveTaskRoute?.intent) &&
|
|
|
|
|
+ !(novelMode && (aiWorkflowMode !== "fast" || planExecuteActive)),
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
if (novelMode && effectiveTaskRoute) {
|
|
if (novelMode && effectiveTaskRoute) {
|
|
|
const contextHub = getContextHub(pp)
|
|
const contextHub = getContextHub(pp)
|
|
|
const novelConfig = useWikiStore.getState().novelConfig
|
|
const novelConfig = useWikiStore.getState().novelConfig
|
|
@@ -1488,9 +1505,8 @@ export function ChatPanel() {
|
|
|
content: message.content,
|
|
content: message.content,
|
|
|
})),
|
|
})),
|
|
|
existingSummary: activeConv?.contextSummary,
|
|
existingSummary: activeConv?.contextSummary,
|
|
|
- tokenBudget: novelConfig.contextTokenBudget > 0
|
|
|
|
|
- ? novelConfig.contextTokenBudget
|
|
|
|
|
- : undefined,
|
|
|
|
|
|
|
+ tokenBudget: novelConfig.contextTokenBudget,
|
|
|
|
|
+ maxContextSize: agentConfig.llmConfig.maxContextSize,
|
|
|
})
|
|
})
|
|
|
if (contextHubResult) {
|
|
if (contextHubResult) {
|
|
|
try {
|
|
try {
|
|
@@ -1611,7 +1627,10 @@ export function ChatPanel() {
|
|
|
revisionDirectives: "",
|
|
revisionDirectives: "",
|
|
|
}))
|
|
}))
|
|
|
const novelConfig = useWikiStore.getState().novelConfig
|
|
const novelConfig = useWikiStore.getState().novelConfig
|
|
|
- const budget = novelConfig.contextTokenBudget > 0 ? novelConfig.contextTokenBudget : undefined
|
|
|
|
|
|
|
+ const budget = resolveContextPackTokenBudget({
|
|
|
|
|
+ maxContextSize: agentConfig.llmConfig.maxContextSize,
|
|
|
|
|
+ contextTokenBudget: novelConfig.contextTokenBudget,
|
|
|
|
|
+ })
|
|
|
novelContextPrompt = [
|
|
novelContextPrompt = [
|
|
|
taskDirective,
|
|
taskDirective,
|
|
|
goldenDirective,
|
|
goldenDirective,
|
|
@@ -1696,6 +1715,8 @@ export function ChatPanel() {
|
|
|
getChatConversations: () => [],
|
|
getChatConversations: () => [],
|
|
|
getOutlineConversations: () => [],
|
|
getOutlineConversations: () => [],
|
|
|
readTextFile: contextHubResult.readFile,
|
|
readTextFile: contextHubResult.readFile,
|
|
|
|
|
+ llmConfig: agentConfig.llmConfig,
|
|
|
|
|
+ maxContextSize: agentConfig.llmConfig.maxContextSize,
|
|
|
enabledToolNames: [
|
|
enabledToolNames: [
|
|
|
"read_chapter",
|
|
"read_chapter",
|
|
|
"read_outline",
|
|
"read_outline",
|