Update imports to use handlers index.ts and reduce exports to necessary components

This commit is contained in:
Steven T. Cramer 2025-06-15 14:00:19 +07:00
parent 31c51e3109
commit 8914d599cb
5 changed files with 15 additions and 35 deletions

View file

@ -1,6 +1,5 @@
import { DirectiveHandler } from "./DirectiveHandler"
import { TextDirectiveHandler } from "./handlers/TextDirectiveHandler"
import { ToolDirectiveHandler } from "./handlers/ToolDirectiveHandler"
import { TextDirectiveHandler, ToolDirectiveHandler } from "./handlers"
export class DirectiveHandlerRegistry {
private handlers: Map<string, DirectiveHandler> = new Map()

View file

@ -1,5 +1,5 @@
import { DirectiveHandlerRegistry } from "./DirectiveHandlerRegistry"
import { LogDirectiveHandler } from "./handlers/LogDirectiveHandler"
import { LogDirectiveHandler } from "./handlers"
import { toolNames } from "@roo-code/types"
export class DirectiveRegistryFactory {

View file

@ -1,5 +1,5 @@
import { suite, test, expect } from "vitest"
import { parseAssistantMessage } from ".."
import { DirectiveStreamingParser } from ".."
suite("Log Entry Parsing", () => {
test("should parse complete log entries correctly", () => {
@ -8,7 +8,7 @@ suite("Log Entry Parsing", () => {
<level>debug</level>
</log_message>`
const result = parseAssistantMessage(message)
const result = DirectiveStreamingParser.parse(message)
// Filter out empty text blocks
const filteredResult = result.filter((block) => !(block.type === "text" && block.content === ""))
@ -26,7 +26,7 @@ suite("Log Entry Parsing", () => {
const message = `<log_message>
<message>This is a test log message</message>`
const result = parseAssistantMessage(message)
const result = DirectiveStreamingParser.parse(message)
// Filter out empty text blocks
const filteredResult = result.filter((block) => !(block.type === "text" && block.content === ""))
@ -45,7 +45,7 @@ suite("Log Entry Parsing", () => {
<message>This is a test log message</message>
</log_message>`
const result = parseAssistantMessage(message)
const result = DirectiveStreamingParser.parse(message)
// Filter out empty text blocks
const filteredResult = result.filter((block) => !(block.type === "text" && block.content === ""))
@ -74,7 +74,7 @@ suite("Log Entry Parsing", () => {
// Process each chunk as it would happen during streaming
for (const chunk of chunks) {
accumulatedMessage += chunk
const result = parseAssistantMessage(accumulatedMessage)
const result = DirectiveStreamingParser.parse(accumulatedMessage)
results.push(result)
}
@ -135,7 +135,7 @@ suite("Log Entry Parsing", () => {
<level>error</level>
</log_message>`
const result = parseAssistantMessage(message)
const result = DirectiveStreamingParser.parse(message)
// Filter out empty text blocks
const filteredResult = result.filter((block) => !(block.type === "text" && block.content === ""))

View file

@ -1,26 +1,5 @@
export { type AssistantMessageContent, parseAssistantMessage } from "./parseAssistantMessage"
export { presentAssistantMessage } from "./presentAssistantMessage"
export { type LogDirective } from "./directives/LogDirective"
// Main API
export type { Directive } from "./directives"
export { DirectiveStreamingParser } from "./DirectiveStreamingParser"
// Core interfaces and types
export type { DirectiveHandler } from "./DirectiveHandler"
export type { ParseContext } from "./ParseContext"
// Base classes for extension
export { BaseDirectiveHandler } from "./handlers/BaseDirectiveHandler"
// Registry system
export { DirectiveHandlerRegistry } from "./DirectiveHandlerRegistry"
export { DirectiveRegistryFactory } from "./DirectiveRegistryFactory"
// Built-in handlers (for custom registration)
export { LogDirectiveHandler } from "./handlers/LogDirectiveHandler"
export { ToolDirectiveHandler } from "./handlers/ToolDirectiveHandler"
export { TextDirectiveHandler } from "./handlers/TextDirectiveHandler"
// Utilities
export { XmlUtils } from "./XmlUtils"
export { FallbackParser } from "./FallbackParser"

View file

@ -65,7 +65,7 @@ import { SYSTEM_PROMPT } from "../prompts/system"
import { ToolRepetitionDetector } from "../tools/ToolRepetitionDetector"
import { FileContextTracker } from "../context-tracking/FileContextTracker"
import { RooIgnoreController } from "../ignore/RooIgnoreController"
import { type AssistantMessageContent, parseAssistantMessage, presentAssistantMessage } from "../assistant-message"
import { presentAssistantMessage } from "../assistant-message"
import { truncateConversationIfNeeded } from "../sliding-window"
import { ClineProvider } from "../webview/ClineProvider"
import { MultiSearchReplaceDiffStrategy } from "../diff/strategies/multi-search-replace"
@ -85,6 +85,8 @@ import { ApiMessage } from "../task-persistence/apiMessages"
import { getMessagesSinceLastSummary, summarizeConversation } from "../condense"
import { maybeRemoveImageBlocks } from "../../api/transform/image-cleaning"
import { LogManager } from "../logging"
import { Directive } from "../assistant-message"
import { DirectiveStreamingParser } from "../assistant-message"
export type ClineEvents = {
message: [{ action: "created" | "updated"; message: ClineMessage }]
@ -184,7 +186,7 @@ export class Task extends EventEmitter<ClineEvents> {
isWaitingForFirstChunk = false
isStreaming = false
currentStreamingContentIndex = 0
assistantMessageContent: AssistantMessageContent[] = []
assistantMessageContent: Directive[] = []
presentAssistantMessageLocked = false
presentAssistantMessageHasPendingUpdates = false
userMessageContent: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[] = []
@ -1334,7 +1336,7 @@ export class Task extends EventEmitter<ClineEvents> {
try {
for await (const chunk of stream) {
if (!chunk) {
// Sometimes chunk is undefined, no idea that can cause
// Sometimes chunk is undefined, no idea what can cause
// it, but this workaround seems to fix it.
continue
}
@ -1356,7 +1358,7 @@ export class Task extends EventEmitter<ClineEvents> {
// Parse raw assistant message into content blocks.
const prevLength = this.assistantMessageContent.length
this.assistantMessageContent = parseAssistantMessage(assistantMessage)
this.assistantMessageContent = DirectiveStreamingParser.parse(assistantMessage)
if (this.assistantMessageContent.length > prevLength) {
// New content we need to present, reset to