// src/kb/types.ts

/** A single FTS5 search result chunk from KbStore. */
export interface KbChunk {
  readonly toolCallId: string;
  readonly content: string;
  readonly rank: number;
}

/** A single search result from KbStore.search() — used by porter+trigram FTS5 store. */
export interface KbSearchResult {
  readonly toolCallId?: string;
  readonly sourceLabel: string;    // tool name + session hint
  readonly content: string;        // chunk text
  readonly score: number;          // BM25 * recency_boost
  readonly tier: "porter" | "trigram";
}

/** Anthropic content block — text variant. */
export interface TextContentBlock {
  readonly type: "text";
  readonly text: string;
}

/** Anthropic content block — tool_use variant. */
export interface ToolUseContentBlock {
  readonly type: "tool_use";
  readonly id: string;
  readonly name: string;
  readonly input: Record<string, unknown>;
}

/** Anthropic thinking block. Must be passed back unchanged with its signature. */
export interface ThinkingContentBlock {
  readonly type: "thinking";
  readonly thinking: string;
  readonly signature: string;
}

/** Anthropic redacted_thinking block. Encrypted thinking; opaque `data` must round-trip verbatim. */
export interface RedactedThinkingContentBlock {
  readonly type: "redacted_thinking";
  readonly data: string;
}

/** Union of content block types carried in an assistant turn. */
export type ContentBlock =
  | TextContentBlock
  | ToolUseContentBlock
  | ThinkingContentBlock
  | RedactedThinkingContentBlock;

/**
 * Callback provided by handler to KbResponseInterceptor.
 * Receives the full buffered assistant turn (all content blocks),
 * the id of the kb tool_use that was intercepted, and the formatted
 * FTS5 search result. Returns a new upstream Response for the
 * continuation turn.
 */
export type ContinuationFn = (
  assistantContent: ContentBlock[],
  kbToolUseId: string,
  toolResultContent: string,
) => Promise<Response>;
