feat: update Makelore modules and conversations
This commit is contained in:
@@ -238,6 +238,21 @@ function normalizeLegacyBlocks(content: unknown): ContentBlock[] {
|
||||
blocks.push({ type: 'thinking', thinking: record.thinking, id: typeof record.id === 'string' ? record.id : undefined });
|
||||
continue;
|
||||
}
|
||||
if (type === 'reasoning') {
|
||||
const reasoning = typeof record.text === 'string'
|
||||
? record.text
|
||||
: typeof record.reasoning === 'string'
|
||||
? record.reasoning
|
||||
: typeof record.reasoning_content === 'string'
|
||||
? record.reasoning_content
|
||||
: typeof record.reasoning_text === 'string'
|
||||
? record.reasoning_text
|
||||
: undefined;
|
||||
if (reasoning) {
|
||||
blocks.push({ type: 'thinking', thinking: reasoning, id: typeof record.id === 'string' ? record.id : undefined });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ((type === 'tool_use' || type === 'toolCall') && typeof record.name === 'string') {
|
||||
blocks.push({
|
||||
type: 'tool_use',
|
||||
@@ -263,6 +278,16 @@ function normalizeLegacyBlocks(content: unknown): ContentBlock[] {
|
||||
|
||||
function normalizeLegacyMessage(input: Record<string, unknown>): RawMessage {
|
||||
const contentBlocks = normalizeLegacyBlocks(input.content);
|
||||
const topLevelReasoning = typeof input.reasoning === 'string'
|
||||
? input.reasoning
|
||||
: typeof input.reasoning_content === 'string'
|
||||
? input.reasoning_content
|
||||
: typeof input.reasoning_text === 'string'
|
||||
? input.reasoning_text
|
||||
: undefined;
|
||||
if (topLevelReasoning?.trim()) {
|
||||
contentBlocks.unshift({ type: 'thinking', thinking: topLevelReasoning });
|
||||
}
|
||||
if (contentBlocks.length > 0) {
|
||||
return {
|
||||
id: typeof input.id === 'string' ? input.id : undefined,
|
||||
@@ -543,6 +568,12 @@ function getStreamingDelta(record: Record<string, unknown> | null, part: Record<
|
||||
const delta = getRecord(rawDelta);
|
||||
if (typeof delta?.text === 'string') return delta.text;
|
||||
if (typeof delta?.thinking === 'string') return delta.thinking;
|
||||
if (typeof delta?.reasoning === 'string') return delta.reasoning;
|
||||
if (typeof delta?.reasoning_content === 'string') return delta.reasoning_content;
|
||||
if (typeof delta?.reasoning_text === 'string') return delta.reasoning_text;
|
||||
if (typeof part.reasoning === 'string') return part.reasoning;
|
||||
if (typeof part.reasoning_content === 'string') return part.reasoning_content;
|
||||
if (typeof part.reasoning_text === 'string') return part.reasoning_text;
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -714,6 +745,13 @@ export function applyStreamingPartToMessage(message: RawMessage | null, input: u
|
||||
const toolEvidence = normalizeToolEvidence(part);
|
||||
const rawCandidate = normalized.blocks.at(0);
|
||||
const delta = getStreamingDelta(record, part);
|
||||
const messageId = typeof record?.messageID === 'string'
|
||||
? record.messageID
|
||||
: typeof record?.messageId === 'string'
|
||||
? record.messageId
|
||||
: typeof part.messageID === 'string'
|
||||
? part.messageID
|
||||
: undefined;
|
||||
const blockId = rawCandidate?.id ?? (typeof part.id === 'string' ? part.id : undefined);
|
||||
const index = blockId
|
||||
? nextContent.findIndex((block) => ('id' in block ? block.id : undefined) === blockId)
|
||||
@@ -735,6 +773,7 @@ export function applyStreamingPartToMessage(message: RawMessage | null, input: u
|
||||
|
||||
return {
|
||||
...current,
|
||||
...(current.id || !messageId ? {} : { id: messageId }),
|
||||
content: nextContent,
|
||||
_attachedFiles: mergeAttachments(current._attachedFiles, normalized.attachments),
|
||||
_toolEvidence: mergeToolEvidence(current._toolEvidence, toolEvidence),
|
||||
@@ -745,10 +784,10 @@ export function applyStreamingPartDeltaToMessage(message: RawMessage | null, inp
|
||||
const record = getRecord(input);
|
||||
if (!record) return message;
|
||||
|
||||
const delta = typeof record.delta === 'string' ? record.delta : '';
|
||||
const part = getRecord(record.part) ?? record;
|
||||
const delta = getStreamingDelta(record, part);
|
||||
if (!delta) return message;
|
||||
|
||||
const part = getRecord(record.part);
|
||||
const messageID = typeof record.messageID === 'string'
|
||||
? record.messageID
|
||||
: typeof record.messageId === 'string'
|
||||
@@ -769,7 +808,9 @@ export function applyStreamingPartDeltaToMessage(message: RawMessage | null, inp
|
||||
const isThinkingDelta = part?.type === 'reasoning'
|
||||
|| part?.type === 'thinking'
|
||||
|| field === 'reasoning'
|
||||
|| field === 'thinking';
|
||||
|| field === 'thinking'
|
||||
|| field === 'reasoning_content'
|
||||
|| field === 'reasoning_text';
|
||||
|
||||
if (message?.id && messageID && message.id !== messageID) return message;
|
||||
|
||||
@@ -819,6 +860,43 @@ export function applyStreamingPartDeltaToMessage(message: RawMessage | null, inp
|
||||
};
|
||||
}
|
||||
|
||||
export function removeStreamingPartFromMessage(
|
||||
message: RawMessage | null,
|
||||
input: unknown,
|
||||
): RawMessage | null {
|
||||
if (!message || !input || typeof input !== 'object') return message;
|
||||
const record = input as Record<string, unknown>;
|
||||
const messageID = typeof record.messageID === 'string'
|
||||
? record.messageID
|
||||
: typeof record.messageId === 'string'
|
||||
? record.messageId
|
||||
: undefined;
|
||||
if (message.id && messageID && message.id !== messageID) return message;
|
||||
const part = record.part && typeof record.part === 'object' && !Array.isArray(record.part)
|
||||
? record.part as Record<string, unknown>
|
||||
: null;
|
||||
const partID = typeof record.partID === 'string'
|
||||
? record.partID
|
||||
: typeof record.partId === 'string'
|
||||
? record.partId
|
||||
: typeof part?.id === 'string'
|
||||
? part.id
|
||||
: undefined;
|
||||
if (!partID || !Array.isArray(message.content)) return message;
|
||||
|
||||
const content = message.content.filter((block) => (
|
||||
!('id' in block) || block.id !== partID
|
||||
));
|
||||
const toolEvidence = message._toolEvidence?.filter((evidence) => (
|
||||
evidence.id !== partID && evidence.toolCallId !== partID
|
||||
));
|
||||
return {
|
||||
...message,
|
||||
content,
|
||||
...(toolEvidence?.length ? { _toolEvidence: toolEvidence } : { _toolEvidence: undefined }),
|
||||
};
|
||||
}
|
||||
|
||||
export function getStreamingToolStatus(input: unknown): ToolStatus | null {
|
||||
const record = getRecord(input);
|
||||
const part = getRecord(record?.part ?? input);
|
||||
|
||||
Reference in New Issue
Block a user