| 32 | import type { ProjectFileContext } from '@codebuff/common/util/file' |
| 33 | |
| 34 | export async function processStream( |
| 35 | params: { |
| 36 | agentContext: Record<string, Subgoal> |
| 37 | agentTemplate: AgentTemplate |
| 38 | ancestorRunIds: string[] |
| 39 | fileContext: ProjectFileContext |
| 40 | fingerprintId: string |
| 41 | fullResponse: string |
| 42 | logger: Logger |
| 43 | messages: Message[] |
| 44 | repoId: string | undefined |
| 45 | runId: string |
| 46 | signal: AbortSignal |
| 47 | userId: string | undefined |
| 48 | |
| 49 | onCostCalculated: (credits: number) => Promise<void> |
| 50 | onResponseChunk: (chunk: string | PrintModeEvent) => void |
| 51 | } & Omit< |
| 52 | ExecuteToolCallParams<any>, |
| 53 | | 'fileProcessingState' |
| 54 | | 'fromHandleSteps' |
| 55 | | 'fullResponse' |
| 56 | | 'input' |
| 57 | | 'previousToolCallFinished' |
| 58 | | 'state' |
| 59 | | 'toolCallId' |
| 60 | | 'toolCalls' |
| 61 | | 'toolCallsToAddToMessageHistory' |
| 62 | | 'toolName' |
| 63 | | 'toolResults' |
| 64 | | 'toolResultsToAddToMessageHistory' |
| 65 | > & |
| 66 | ParamsExcluding< |
| 67 | typeof processStreamWithTools, |
| 68 | | 'processors' |
| 69 | | 'defaultProcessor' |
| 70 | | 'loggerOptions' |
| 71 | | 'executeXmlToolCall' |
| 72 | >, |
| 73 | ) { |
| 74 | const { |
| 75 | agentState, |
| 76 | agentTemplate, |
| 77 | ancestorRunIds, |
| 78 | fileContext, |
| 79 | fullResponse, |
| 80 | onCostCalculated, |
| 81 | onResponseChunk, |
| 82 | runId, |
| 83 | signal, |
| 84 | userId, |
| 85 | } = params |
| 86 | const fullResponseChunks: string[] = [fullResponse] |
| 87 | |
| 88 | // === MUTABLE STATE === |
| 89 | const toolResults: ToolMessage[] = [] |
| 90 | const toolResultsToAddToMessageHistory: ToolMessage[] = [] |
| 91 | const toolCalls: (CodebuffToolCall | CustomToolCall)[] = [] |