mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
DeepSeek V3.2 Thinking Mode Integration (#1134)
This commit is contained in:
@@ -542,6 +542,39 @@ export class SessionService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for building API history from conversation.
|
||||
*/
|
||||
export interface BuildApiHistoryOptions {
|
||||
/**
|
||||
* Whether to strip thought parts from the history.
|
||||
* Thought parts are content parts that have `thought: true`.
|
||||
* @default true
|
||||
*/
|
||||
stripThoughtsFromHistory?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips thought parts from a Content object.
|
||||
* Thought parts are identified by having `thought: true`.
|
||||
* Returns null if the content only contained thought parts.
|
||||
*/
|
||||
function stripThoughtsFromContent(content: Content): Content | null {
|
||||
if (!content.parts) return content;
|
||||
|
||||
const filteredParts = content.parts.filter((part) => !(part as Part).thought);
|
||||
|
||||
// If all parts were thoughts, remove the entire content
|
||||
if (filteredParts.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
...content,
|
||||
parts: filteredParts,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the model-facing chat history (Content[]) from a reconstructed
|
||||
* conversation. This keeps UI history intact while applying chat compression
|
||||
@@ -555,7 +588,9 @@ export class SessionService {
|
||||
*/
|
||||
export function buildApiHistoryFromConversation(
|
||||
conversation: ConversationRecord,
|
||||
options: BuildApiHistoryOptions = {},
|
||||
): Content[] {
|
||||
const { stripThoughtsFromHistory = true } = options;
|
||||
const { messages } = conversation;
|
||||
|
||||
let lastCompressionIndex = -1;
|
||||
@@ -585,14 +620,26 @@ export function buildApiHistoryFromConversation(
|
||||
}
|
||||
}
|
||||
|
||||
if (stripThoughtsFromHistory) {
|
||||
return baseHistory
|
||||
.map(stripThoughtsFromContent)
|
||||
.filter((content): content is Content => content !== null);
|
||||
}
|
||||
return baseHistory;
|
||||
}
|
||||
|
||||
// Fallback: return linear messages as Content[]
|
||||
return messages
|
||||
const result = messages
|
||||
.map((record) => record.message)
|
||||
.filter((message): message is Content => message !== undefined)
|
||||
.map((message) => structuredClone(message));
|
||||
|
||||
if (stripThoughtsFromHistory) {
|
||||
return result
|
||||
.map(stripThoughtsFromContent)
|
||||
.filter((content): content is Content => content !== null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user