Collapsed Segment Types
In v2, three specialized segment types have been collapsed into ToolCallSegment. This simplifies the segment union while preserving all functionality through name-based dispatch.
What changed
| Old type | New type | How to identify |
|---|---|---|
SpawnAgentSegment | ToolCallSegment | segment.name === 'spawn_agent' |
SequentialThinkingSegment | ToolCallSegment | segment.name === 'sequential_thinking' |
DSLPipelineSegment | ToolCallSegment | segment.name matches your pipeline tool |
All three are now regular ToolCallSegment instances. The name property (which holds the tool name) tells you which kind of tool call it is.
Migration: SpawnAgentSegment
// Before
import type { SpawnAgentSegment } from '@baleybots/core';
function renderSegment(segment: StreamSegment) {
if (segment.type === 'spawn_agent') {
return <AgentCard agentName={segment.agentName} />;
}
}
// After
import type { ToolCallSegment } from '@baleybots/core';
import { getSpawnAgentData } from '@baleybots/core';
function renderSegment(segment: StreamSegment) {
if (segment.type === 'tool_call' && segment.name === 'spawn_agent') {
const data = getSpawnAgentData(segment);
return <AgentCard agentName={data.agentName} />;
}
}
Migration: SequentialThinkingSegment
// Before
if (segment.type === 'sequential_thinking') {
return <ThinkingCard thoughts={segment.thoughts} />;
}
// After
import { getSequentialThinkingData } from '@baleybots/core';
if (segment.type === 'tool_call' && segment.name === 'sequential_thinking') {
const data = getSequentialThinkingData(segment);
return <ThinkingCard thoughts={data.thoughts} />;
}
Migration: DSLPipelineSegment
// Before
if (segment.type === 'dsl_pipeline') {
return <PipelineCard steps={segment.steps} />;
}
// After
import { getDSLPipelineData } from '@baleybots/core';
if (segment.type === 'tool_call' && segment.name === 'dsl_pipeline') {
const data = getDSLPipelineData(segment);
return <PipelineCard steps={data.steps} />;
}
Generic rendering
If you don't need special rendering for these tool types, you can treat all tool calls uniformly:
function renderSegment(segment: StreamSegment) {
if (segment.type === 'tool_call') {
return (
<div>
<b>Tool: {segment.name}</b>
<pre>{JSON.stringify(segment.args, null, 2)}</pre>
{segment.result && <pre>{JSON.stringify(segment.result, null, 2)}</pre>}
</div>
);
}
}
Typed helper functions
The @baleybots/core package provides typed helper functions for accessing tool-specific data:
getSpawnAgentData(segment)-- returns{ agentName, agentGoal, status, ... }getSequentialThinkingData(segment)-- returns{ thoughts, ... }getDSLPipelineData(segment)-- returns{ steps, ... }
These helpers parse the tool call arguments and results into typed objects, so you don't need to manually extract data from segment.args and segment.result.