(result: any)
| 637 | let pendingThought: string = ''; |
| 638 | |
| 639 | const processStreamingResult = (result: any) => { |
| 640 | // ── context_info: show injected rules/knowledge at the top ── |
| 641 | // Rendered as already-completed tool-style steps (✓ prefix) so they |
| 642 | // visually match the rest of the agent's tool-call timeline. |
| 643 | if (result.type === "context_info") { |
| 644 | const rules: string[] = result.rules_injected || []; |
| 645 | const knowledge: Array<{category: string; title: string}> = result.knowledge_injected || []; |
| 646 | let added = false; |
| 647 | if (rules.length > 0) { |
| 648 | thinkingSteps.push('✓ ' + t('dataThread.rulesLoaded', { rules: rules.join(', ') })); |
| 649 | added = true; |
| 650 | } |
| 651 | if (knowledge.length > 0) { |
| 652 | const titles = knowledge.map(k => k.title).join(', '); |
| 653 | thinkingSteps.push('✓ ' + t('dataThread.knowledgeLoaded', { knowledge: titles })); |
| 654 | added = true; |
| 655 | } |
| 656 | if (added && currentDraftId) { |
| 657 | dispatch(dfActions.updateDraftRunningPlan({ draftId: currentDraftId, plan: thinkingSteps.join(STEP_SEP) })); |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | // ── thinking_text: LLM reasoning alongside tool calls ── |
| 662 | // Accumulate into pendingThought; don't create a visible step |
| 663 | if (result.type === "thinking_text") { |
| 664 | pendingThought += (pendingThought ? '\n' : '') + result.content; |
| 665 | // Only show as a step if there are no tool/action steps yet (initial thinking) |
| 666 | if (thinkingSteps.length === 0) { |
| 667 | // Show a temporary "thinking..." indicator |
| 668 | if (currentDraftId) { |
| 669 | dispatch(dfActions.updateDraftRunningPlan({ draftId: currentDraftId, plan: t('dataThread.thinking') })); |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | // ── tool_start: agent is calling a tool (explore/inspect) ── |
| 675 | if (result.type === "tool_start") { |
| 676 | // Show pending thought as a visible step before the tool step |
| 677 | if (pendingThought) { |
| 678 | thinkingSteps.push(pendingThought); |
| 679 | pendingThought = ''; |
| 680 | } |
| 681 | if (result.tool === "explore") { |
| 682 | const purpose = result.purpose || ''; |
| 683 | if (purpose) { |
| 684 | thinkingSteps.push(t('dataThread.runningCode') + ' ' + purpose); |
| 685 | } else { |
| 686 | const codePreview = result.code || ''; |
| 687 | const meaningfulLine = codePreview.split('\n').find((l: string) => l.trim() && !l.trim().startsWith('import ') && !l.trim().startsWith('from ')) || codePreview.split('\n')[0] || ''; |
| 688 | thinkingSteps.push(t('dataThread.runningCode') + (meaningfulLine ? `: ${meaningfulLine.trim()}` : '')); |
| 689 | } |
| 690 | } else if (result.tool === "inspect_source_data") { |
| 691 | const tableNames = result.table_names?.join(', ') || ''; |
| 692 | thinkingSteps.push(t('dataThread.inspectingData') + (tableNames ? ` ${tableNames}` : '')); |
| 693 | } else if (result.tool === "search_data_tables" || result.tool === "search_knowledge") { |
| 694 | const query = result.query || ''; |
| 695 | thinkingSteps.push(t('dataThread.searching') + (query ? ` "${query}"` : '')); |
| 696 | } else if (["visualize", "clarify", "present", "action"].includes(result.tool)) { |
no test coverage detected