|
1 | 1 | import type { FetchHandlerContext, FetchHandlerResult, FormatDescriptor, PrunedIdData } from "./types" |
2 | 2 | import { type PluginState, ensureSessionRestored } from "../state" |
3 | 3 | import type { Logger } from "../logger" |
4 | | -import { buildPrunableToolsList, buildSystemInjection } from "./prunable-list" |
| 4 | +import { buildPrunableToolsList, buildUserInjection } from "./prunable-list" |
5 | 5 | import { syncToolCache } from "../state/tool-cache" |
| 6 | +import { loadPrompt } from "../core/prompt" |
6 | 7 |
|
| 8 | +const SYNTHETIC_INSTRUCTION = loadPrompt("synthetic") |
7 | 9 | const PRUNED_CONTENT_MESSAGE = '[Output removed to save context - information superseded or no longer needed]' |
8 | 10 |
|
9 | 11 | function getMostRecentActiveSession(allSessions: any): any | undefined { |
@@ -90,10 +92,15 @@ export async function handleFormat( |
90 | 92 |
|
91 | 93 | if (prunableList) { |
92 | 94 | const includeNudge = ctx.config.nudge_freq > 0 && ctx.toolTracker.toolResultCount > ctx.config.nudge_freq |
93 | | - const systemInjection = buildSystemInjection(prunableList, includeNudge) |
94 | | - |
95 | | - if (format.injectSystemMessage(body, systemInjection)) { |
96 | | - ctx.logger.debug("fetch", `Injected prunable tools list into system message (${format.name})`, { |
| 95 | + if (format.injectSystemMessage(body, SYNTHETIC_INSTRUCTION)) { |
| 96 | + modified = true |
| 97 | + } |
| 98 | + |
| 99 | + const userInjection = buildUserInjection(prunableList, includeNudge) |
| 100 | + |
| 101 | + if (format.injectUserMessage && format.injectUserMessage(body, userInjection)) { |
| 102 | + const nudgeMsg = includeNudge ? " with nudge" : "" |
| 103 | + ctx.logger.debug("fetch", `Injected prunable tools list${nudgeMsg} into user message (${format.name})`, { |
97 | 104 | ids: numericIds, |
98 | 105 | nudge: includeNudge, |
99 | 106 | toolsSincePrune: ctx.toolTracker.toolResultCount |
|
0 commit comments