Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768/** * NormalizedBlock — the flattened, pair-indexed stream the compaction pipeline operates * on (ARCHITECTURE §11). Produced by `normalize(messages)`. * * Distinct from ContentBlock: `bash` is materialized from a `bash` tool_call/result pair * (command + output + exitCode), and `tool_result` carries its name + isError so extractors * don't need to look the call back up. Pure data, wire-safe. */import { Type, type Static } from '@sinclair/typebox';
// Names are prefixed `Normalized*` to avoid collisions with the parallel ContentBlock// schemas in content.ts when both are re-exported from the barrel.export const NormalizedUserBlockSchema = Type.Object({ kind: Type.Literal('user'), text: Type.String(),});
export const NormalizedAssistantBlockSchema = Type.Object({ kind: Type.Literal('assistant'), text: Type.String(),});
export const NormalizedToolCallBlockSchema = Type.Object({ kind: Type.Literal('tool_call'), name: Type.String(), args: Type.Record(Type.String(), Type.Unknown()),});
export const NormalizedToolResultBlockSchema = Type.Object({ kind: Type.Literal('tool_result'), name: Type.String(), text: Type.String(), isError: Type.Boolean(),});
export const NormalizedBashBlockSchema = Type.Object({ kind: Type.Literal('bash'), command: Type.String(), output: Type.String(), exitCode: Type.Optional(Type.Integer()),});
export const NormalizedThinkingBlockSchema = Type.Object({ kind: Type.Literal('thinking'), text: Type.String(), // Mirrors ThinkingBlockSchema's optional replay/redaction fields (content.ts). Carried // through normalization so compaction can preserve round-trip signatures. thinkingSignature: Type.Optional(Type.String()), redacted: Type.Optional(Type.Boolean()),});
export const NormalizedBlockSchema = Type.Union([ NormalizedUserBlockSchema, NormalizedAssistantBlockSchema, NormalizedToolCallBlockSchema, NormalizedToolResultBlockSchema, NormalizedBashBlockSchema, NormalizedThinkingBlockSchema,]);
export type NormalizedUserBlock = Static<typeof NormalizedUserBlockSchema>;export type NormalizedAssistantBlock = Static<typeof NormalizedAssistantBlockSchema>;export type NormalizedToolCallBlock = Static<typeof NormalizedToolCallBlockSchema>;export type NormalizedToolResultBlock = Static<typeof NormalizedToolResultBlockSchema>;export type NormalizedBashBlock = Static<typeof NormalizedBashBlockSchema>;export type NormalizedThinkingBlock = Static<typeof NormalizedThinkingBlockSchema>;export type NormalizedBlock = Static<typeof NormalizedBlockSchema>;