Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/core/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ export class Agent {
if (lastAssistant) {
const combined = lastAssistant.content
.filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')
.filter(
(block) =>
block.text.length > 0 ||
!(block.meta?.thought_signature || block.meta?.thoughtSignature)
)
.map((block) => block.text)
.join('\n');
if (combined.trim().length > 0) {
Expand Down Expand Up @@ -1068,12 +1073,20 @@ export class Agent {
if (chunk.content_block?.type === 'text') {
currentBlockIndex = chunk.index ?? 0;
textBuffers.set(currentBlockIndex, '');
assistantBlocks[currentBlockIndex] = { type: 'text', text: '' };
assistantBlocks[currentBlockIndex] = {
type: 'text',
text: '',
...(chunk.content_block.meta ? { meta: chunk.content_block.meta } : {}),
};
this.events.emitProgress({ channel: 'progress', type: 'text_chunk_start', step: this.stepCount });
} else if (chunk.content_block?.type === 'reasoning') {
currentBlockIndex = chunk.index ?? 0;
reasoningBuffers.set(currentBlockIndex, '');
assistantBlocks[currentBlockIndex] = { type: 'reasoning', reasoning: '' };
assistantBlocks[currentBlockIndex] = {
type: 'reasoning',
reasoning: '',
...(chunk.content_block.meta ? { meta: chunk.content_block.meta } : {}),
};
if (this.exposeThinking) {
this.events.emitProgress({ channel: 'progress', type: 'think_chunk_start', step: this.stepCount });
}
Expand Down Expand Up @@ -1161,7 +1174,8 @@ export class Agent {
const storedBlocks = this.retainThinking
? originalBlocks
: originalBlocks.filter((block) => block.type !== 'reasoning');
const metadata = this.buildMessageMetadata(originalBlocks, storedBlocks, this.retainThinking ? 'provider' : 'omit');
const metadataBlocks = this.retainThinking ? originalBlocks : storedBlocks;
const metadata = this.buildMessageMetadata(metadataBlocks, storedBlocks, this.retainThinking ? 'provider' : 'omit');

this.messages.push({ role: 'assistant', content: storedBlocks, metadata });
await this.persistMessages();
Expand Down Expand Up @@ -2507,6 +2521,7 @@ function ensureModelFactory(factory?: ModelFactory): ModelFactory {
extraBody: config.extraBody,
providerOptions: config.providerOptions,
multimodal: config.multimodal,
thinking: config.thinking,
});
}
if (config.provider === 'glm') {
Expand Down
2 changes: 1 addition & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export type MessageRole = 'user' | 'assistant' | 'system';

export type ContentBlock =
| { type: 'text'; text: string }
| { type: 'text'; text: string; meta?: Record<string, any> }
| { type: 'image_url'; image_url: { url: string } }
| { type: 'tool_use'; id: string; name: string; input: any; meta?: Record<string, any> }
| { type: 'tool_result'; tool_use_id: string; content: any; is_error?: boolean }
Expand Down
2 changes: 1 addition & 1 deletion src/infra/providers/core/fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export const geminiResumeHandler: ResumeHandler = {
const processedBlocks = msg.content.map(block => {
if (block.type === 'reasoning') {
// Keep if has signature, otherwise omit
if (block.meta?.thoughtSignature) {
if (block.meta?.thought_signature || block.meta?.thoughtSignature) {
return block;
}
return null;
Expand Down
Loading
Loading