diff --git a/src/core/assistant-message/directives/StreamingParser.ts b/src/core/assistant-message/DirectiveStreamingParser.ts similarity index 75% rename from src/core/assistant-message/directives/StreamingParser.ts rename to src/core/assistant-message/DirectiveStreamingParser.ts index 3d272b06b5..dd26a9f9a9 100644 --- a/src/core/assistant-message/directives/StreamingParser.ts +++ b/src/core/assistant-message/DirectiveStreamingParser.ts @@ -1,9 +1,9 @@ -import { Directive, ParsingState } from "./types" -import { TextContentHandler } from "./TextContentHandler" -import { ToolUseHandler } from "./ToolUseHandler" -import { ParameterHandler } from "./ParameterHandler" +import { Directive, ParsingState } from "./parsers/types" +import { TextContentParser } from "./parsers/TextContentParser" +import { ToolUseParser } from "./parsers/ToolUseParser" +import { ParameterParser } from "./parsers/ParameterParser" -export class StreamingParser { +export class DirectiveStreamingParser { static parse(assistantMessage: string): Directive[] { const state: ParsingState = { contentBlocks: [], @@ -21,18 +21,18 @@ export class StreamingParser { state.accumulator += char // There should not be a param without a tool use. - if (ParameterHandler.handleParameter(state)) { + if (ParameterParser.parse(state)) { continue } // No currentParamName. - if (ToolUseHandler.handleToolUse(state)) { + if (ToolUseParser.parse(state)) { continue } // No currentToolUse. - const didStartToolUse = ToolUseHandler.checkForToolStart(state) - TextContentHandler.handleTextContent(state, i, didStartToolUse) + const didStartToolUse = ToolUseParser.checkForToolStart(state) + TextContentParser.parse(state, i, didStartToolUse) } // Handle remaining partial content diff --git a/src/core/assistant-message/directives/index.ts b/src/core/assistant-message/directives/index.ts deleted file mode 100644 index 0941cefaba..0000000000 --- a/src/core/assistant-message/directives/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export { StreamingParser } from "./StreamingParser" -export { TextContentHandler } from "./TextContentHandler" -export { ToolUseHandler } from "./ToolUseHandler" -export { ParameterHandler } from "./ParameterHandler" -export type { TextDirective, ToolDirective, Directive, ParsingState } from "./types" diff --git a/src/core/assistant-message/parseAssistantMessage.ts b/src/core/assistant-message/parseAssistantMessage.ts index a71acdb475..8bf25978e9 100644 --- a/src/core/assistant-message/parseAssistantMessage.ts +++ b/src/core/assistant-message/parseAssistantMessage.ts @@ -1,12 +1,12 @@ -import { StreamingParser } from "./directives/StreamingParser" -import type { Directive } from "./directives" +import { DirectiveStreamingParser } from "./DirectiveStreamingParser" +import type { Directive } from "./parsers/types" // Re-export types for backward compatibility -export type { TextDirective, ToolDirective, Directive } from "./directives" +export type { TextDirective, ToolDirective, Directive } from "./parsers/types" // Backward compatibility alias export type AssistantMessageContent = Directive export function parseAssistantMessage(assistantMessage: string): Directive[] { - return StreamingParser.parse(assistantMessage) + return DirectiveStreamingParser.parse(assistantMessage) } diff --git a/src/core/assistant-message/directives/ParameterHandler.ts b/src/core/assistant-message/parsers/ParameterParser.ts similarity index 87% rename from src/core/assistant-message/directives/ParameterHandler.ts rename to src/core/assistant-message/parsers/ParameterParser.ts index 72d7f11b6e..69e9526961 100644 --- a/src/core/assistant-message/directives/ParameterHandler.ts +++ b/src/core/assistant-message/parsers/ParameterParser.ts @@ -1,7 +1,7 @@ import { ParsingState } from "./types" -export class ParameterHandler { - static handleParameter(state: ParsingState): boolean { +export class ParameterParser { + static parse(state: ParsingState): boolean { if (!state.currentToolUse || !state.currentParamName) return false const currentParamValue = state.accumulator.slice(state.currentParamValueStartIndex) diff --git a/src/core/assistant-message/directives/TextContentHandler.ts b/src/core/assistant-message/parsers/TextContentParser.ts similarity index 78% rename from src/core/assistant-message/directives/TextContentHandler.ts rename to src/core/assistant-message/parsers/TextContentParser.ts index b03d31ef8f..2e931350bb 100644 --- a/src/core/assistant-message/directives/TextContentHandler.ts +++ b/src/core/assistant-message/parsers/TextContentParser.ts @@ -1,7 +1,7 @@ import { ParsingState } from "./types" -export class TextContentHandler { - static handleTextContent(state: ParsingState, currentIndex: number, didStartToolUse: boolean): void { +export class TextContentParser { + static parse(state: ParsingState, currentIndex: number, didStartToolUse: boolean): void { if (!didStartToolUse) { // No tool use, so it must be text either at the beginning or between tools. if (state.currentTextContent === undefined) { @@ -16,7 +16,7 @@ export class TextContentHandler { } } - static finalizeTextContent(state: ParsingState, toolUseOpeningTag: string): void { + static finalize(state: ParsingState, toolUseOpeningTag: string): void { if (state.currentTextContent) { state.currentTextContent.partial = false diff --git a/src/core/assistant-message/directives/ToolUseHandler.ts b/src/core/assistant-message/parsers/ToolUseParser.ts similarity index 86% rename from src/core/assistant-message/directives/ToolUseHandler.ts rename to src/core/assistant-message/parsers/ToolUseParser.ts index 83394ec9ef..66d286f3bb 100644 --- a/src/core/assistant-message/directives/ToolUseHandler.ts +++ b/src/core/assistant-message/parsers/ToolUseParser.ts @@ -1,9 +1,9 @@ import { type ToolName, toolNames } from "@roo-code/types" import { ToolParamName, toolParamNames } from "../../../shared/tools" import { ParsingState } from "./types" -import { TextContentHandler } from "./TextContentHandler" +import { TextContentParser } from "./TextContentParser" -export class ToolUseHandler { +export class ToolUseParser { static checkForToolStart(state: ParsingState): boolean { let didStartToolUse = false const possibleToolUseOpeningTags = toolNames.map((name) => `<${name}>`) @@ -21,7 +21,7 @@ export class ToolUseHandler { state.currentToolUseStartIndex = state.accumulator.length // This also indicates the end of the current text content. - TextContentHandler.finalizeTextContent(state, toolUseOpeningTag) + TextContentParser.finalize(state, toolUseOpeningTag) didStartToolUse = true break @@ -31,7 +31,7 @@ export class ToolUseHandler { return didStartToolUse } - static handleToolUse(state: ParsingState): boolean { + static parse(state: ParsingState): boolean { if (!state.currentToolUse) return false const currentToolValue = state.accumulator.slice(state.currentToolUseStartIndex) @@ -44,13 +44,13 @@ export class ToolUseHandler { state.currentToolUse = undefined return true } else { - this.handleParameterParsing(state) - this.handleSpecialCases(state) + this.parseParameter(state) + this.parseSpecialCases(state) return true // Continue processing } } - private static handleParameterParsing(state: ParsingState): void { + private static parseParameter(state: ParsingState): void { const possibleParamOpeningTags = toolParamNames.map((name) => `<${name}>`) for (const paramOpeningTag of possibleParamOpeningTags) { if (state.accumulator.endsWith(paramOpeningTag)) { @@ -62,7 +62,7 @@ export class ToolUseHandler { } } - private static handleSpecialCases(state: ParsingState): void { + private static parseSpecialCases(state: ParsingState): void { if (!state.currentToolUse) return // Special case for write_to_file where file contents could diff --git a/src/core/assistant-message/directives/types.ts b/src/core/assistant-message/parsers/types.ts similarity index 100% rename from src/core/assistant-message/directives/types.ts rename to src/core/assistant-message/parsers/types.ts