@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
28 lines • 1.22 kB
JavaScript
export const MESSAGE_KEY = "message";
const COMPACT_DELTA_TYPES = new Set(["text_delta", "thinking_delta", "toolcall_delta"]);
export function compactDelta(value) {
if (value.type !== "message_update" || !Object.hasOwn(value, "message"))
return undefined;
const event = value.assistantMessageEvent;
if (typeof event !== "object" || event === null)
return undefined;
const { type, contentIndex, delta } = event;
if (typeof type !== "string" ||
!COMPACT_DELTA_TYPES.has(type) ||
typeof contentIndex !== "number" ||
typeof delta !== "string") {
return undefined;
}
return { type: type, contentIndex, delta };
}
/** The delta-only form of a compact message_update: cumulative snapshot fields blanked, delta kept. */
export function demoteToDeltaOnly(value) {
const event = value.assistantMessageEvent;
return { ...value, message: null, assistantMessageEvent: { ...event, partial: null } };
}
export function toolUpdateKey(value) {
return value.type === "tool_execution_update" && typeof value.toolCallId === "string"
? `tool:${value.toolCallId}`
: undefined;
}
//# sourceMappingURL=session-event-writer-compaction.js.map