align permission attachments with SSE stream

This commit is contained in:
Shantur Rathore
2025-12-02 23:53:34 +00:00
parent 78338f33c1
commit 6a16dd8f98
6 changed files with 53 additions and 160 deletions

View File

@@ -40,7 +40,22 @@ function ensurePartId(messageId: string, part: ClientPart, index: number): strin
if (typeof part.id === "string" && part.id.length > 0) {
return part.id
}
return `${messageId}-part-${index}`
const toolCallId =
(part as any).callID ??
(part as any).callId ??
(part as any).toolCallID ??
(part as any).toolCallId ??
undefined
if (part.type === "tool" && typeof toolCallId === "string" && toolCallId.length > 0) {
part.id = toolCallId
return toolCallId
}
const fallbackId = `${messageId}-part-${index}`
part.id = fallbackId
return fallbackId
}
const PENDING_PART_MAX_AGE_MS = 30_000

View File

@@ -26,11 +26,37 @@ function decodeTextSegment(segment: any): any {
return segment
}
function deriveToolPartId(part: any): string | undefined {
if (!part || typeof part !== "object") {
return undefined
}
if (part.type !== "tool") {
return undefined
}
const callId =
part.callID ??
part.callId ??
part.toolCallID ??
part.toolCallId ??
undefined
if (typeof callId === "string" && callId.length > 0) {
return callId
}
return undefined
}
export function normalizeMessagePart(part: any): any {
if (!part || typeof part !== "object") {
return part
}
if ((typeof part.id !== "string" || part.id.length === 0) && part.type === "tool") {
const inferredId = deriveToolPartId(part)
if (inferredId) {
part = { ...part, id: inferredId }
}
}
if (part.type !== "text") {
return part
}