Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/chat-deletion-endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@schlessera/brain-ui-server": minor
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-react": patch
---

An authenticated owner can delete its own chat's local history with
`POST /api/chat-deletions` (#3230). The chat is retired first; then its
backend's native history, canonical dialogue, task receipt text, session
projections and positively bound drafts are removed, each confirmed by its
own store. The receipt reports every store's outcome (`removed`, `pending`,
`partial` or `unknown`) and always lists what local deletion keeps:
independent saved content, effects and their audit, provider copies, backups
and offline devices. A repeated operation, or a host restart, finishes an
unconfirmed cleanup. Agents, ambient callers without an owner mapping and
other principals are refused, as are busy chats and backends that cannot
remove native history. A deleted chat is absent from every list, read,
resume, recovery and live-startup path, even for an older client; capable
clients of the same owner receive `chat_retired`. The SDK adds the request,
receipt, frame, capability and schema, and drafts gain `DRAFT_CHAT_RETIRED`.
90 changes: 88 additions & 2 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,15 @@ export "." (./src/index.ts)
type BrainStats
type BudgetObservation
type BudgetScope
CHAT_DELETION_CAPABILITY
CONVERSATION_CAPABILITY_KEYS
CONVERSATION_LIMITS
type ChatDeletionOutcome
type ChatDeletionReceipt
type ChatDeletionRefusal
type ChatDeletionRequest
type ChatDeletionRetained
type ChatDeletionStore
type ChatFileAttachment
type ChatImageAttachment
type ChatSession
Expand Down Expand Up @@ -262,6 +269,7 @@ export "." (./src/index.ts)
type ServerAskUserListRequest
type ServerAskUserRankRequest
type ServerAskUserRequest
type ServerChatRetired
type ServerConversationClosed
type ServerConversationEvent
type ServerConversationOpened
Expand Down Expand Up @@ -502,10 +510,17 @@ export "./client" (./src/client/index.ts)
type BridgeToolName
type BudgetObservation
type BudgetScope
CHAT_DELETION_CAPABILITY
COMPLETE_SHARE_CONTRACT
COMPLETE_SHARE_INPUT_SCHEMA
CONVERSATION_CAPABILITY_KEYS
CONVERSATION_LIMITS
type ChatDeletionOutcome
type ChatDeletionReceipt
type ChatDeletionRefusal
type ChatDeletionRequest
type ChatDeletionRetained
type ChatDeletionStore
type ChatFileAttachment
type ChatImageAttachment
type ChatSession
Expand Down Expand Up @@ -782,6 +797,7 @@ export "./client" (./src/client/index.ts)
type ServerAskUserListRequest
type ServerAskUserRankRequest
type ServerAskUserRequest
type ServerChatRetired
type ServerConversationClosed
type ServerConversationEvent
type ServerConversationOpened
Expand Down Expand Up @@ -1331,8 +1347,15 @@ export "./protocol" (./src/protocol.ts)
type BrainStats
type BudgetObservation
type BudgetScope
CHAT_DELETION_CAPABILITY
CONVERSATION_CAPABILITY_KEYS
CONVERSATION_LIMITS
type ChatDeletionOutcome
type ChatDeletionReceipt
type ChatDeletionRefusal
type ChatDeletionRequest
type ChatDeletionRetained
type ChatDeletionStore
type ChatFileAttachment
type ChatImageAttachment
type ChatSession
Expand Down Expand Up @@ -1528,6 +1551,7 @@ export "./protocol" (./src/protocol.ts)
type ServerAskUserListRequest
type ServerAskUserRankRequest
type ServerAskUserRequest
type ServerChatRetired
type ServerConversationClosed
type ServerConversationEvent
type ServerConversationOpened
Expand Down Expand Up @@ -1794,6 +1818,7 @@ export "./schemas" (./src/schemas.ts)
serverAskUserListRequestSchema
serverAskUserRankRequestSchema
serverAskUserRequestSchema
serverChatRetiredSchema
serverConversationClosedSchema
serverConversationEventSchema
serverConversationOpenedSchema
Expand Down Expand Up @@ -1974,10 +1999,17 @@ export "./server" (./src/server/index.ts)
type BridgeToolName
type BudgetObservation
type BudgetScope
CHAT_DELETION_CAPABILITY
COMPLETE_SHARE_CONTRACT
COMPLETE_SHARE_INPUT_SCHEMA
CONVERSATION_CAPABILITY_KEYS
CONVERSATION_LIMITS
type ChatDeletionOutcome
type ChatDeletionReceipt
type ChatDeletionRefusal
type ChatDeletionRequest
type ChatDeletionRetained
type ChatDeletionStore
type ChatFileAttachment
type ChatImageAttachment
type ChatSession
Expand Down Expand Up @@ -2287,6 +2319,7 @@ export "./server" (./src/server/index.ts)
type ServerAskUserListRequest
type ServerAskUserRankRequest
type ServerAskUserRequest
type ServerChatRetired
type ServerConversationClosed
type ServerConversationEvent
type ServerConversationOpened
Expand Down Expand Up @@ -5531,6 +5564,8 @@ signatures (every public export and the types it is made of)
}
BudgetScope (packages/ui-sdk/src/turn-budgets.ts)
export type BudgetScope = "turn" | "session" | "day";
CHAT_DELETION_CAPABILITY (packages/ui-sdk/src/protocol.ts)
const CHAT_DELETION_CAPABILITY: "chatDeletion";
COMPLETE_SHARE_CONTRACT (packages/ui-sdk/src/tool-contracts/inbox.ts)
const COMPLETE_SHARE_CONTRACT: import("./contract.js").ToolContract<"complete_share", z.ZodObject<{
files: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
Expand Down Expand Up @@ -5597,6 +5632,35 @@ signatures (every public export and the types it is made of)
has(cacheName: string): Promise<boolean>;
open(cacheName: string): Promise<CacheLike>;
}
ChatDeletionOutcome (packages/ui-sdk/src/protocol.ts)
export type ChatDeletionOutcome = "pending" | "partial" | "unknown" | "removed";
ChatDeletionReceipt (packages/ui-sdk/src/protocol.ts)
export interface ChatDeletionReceipt {
operationId: string;
generation: number;
status: ChatDeletionOutcome;
stores: Partial<Record<ChatDeletionStore, ChatDeletionOutcome>>;
retained: ChatDeletionRetained[];
}
ChatDeletionRefusal (packages/ui-sdk/src/protocol.ts)
export type ChatDeletionRefusal = "unauthorized" | "unavailable" | "stale" | "unsupported" | "busy";
ChatDeletionRequest (packages/ui-sdk/src/protocol.ts)
export interface ChatDeletionRequest {
operationId: string;
target: {
sessionId: string;
} | {
historyOwnerId: string;
};
expected: {
backendId: string | null;
generation: number;
};
}
ChatDeletionRetained (packages/ui-sdk/src/protocol.ts)
export type ChatDeletionRetained = "independent_content" | "effects_and_audit" | "provider_copies" | "backups" | "offline_devices";
ChatDeletionStore (packages/ui-sdk/src/protocol.ts)
export type ChatDeletionStore = "native" | "dialogue" | "tasks" | "projections" | "drafts";
ChatFileAttachment (packages/ui-sdk/src/protocol.ts)
export interface ChatFileAttachment {
kind: "file";
Expand Down Expand Up @@ -6327,7 +6391,7 @@ signatures (every public export and the types it is made of)
revision: number;
}
DraftErrorCode (packages/ui-sdk/src/protocol.ts)
export type DraftErrorCode = "DRAFT_CONFLICT" | "DRAFT_DELETED" | "DRAFT_TOO_LARGE" | "DRAFT_CAPACITY" | "DRAFT_NOT_FOUND" | "DRAFT_INVALID" | "DRAFT_PRECONDITION_REQUIRED" | "DRAFT_KEY_REUSED" | "DRAFT_NOT_ACCEPTED";
export type DraftErrorCode = "DRAFT_CONFLICT" | "DRAFT_DELETED" | "DRAFT_TOO_LARGE" | "DRAFT_CAPACITY" | "DRAFT_NOT_FOUND" | "DRAFT_INVALID" | "DRAFT_PRECONDITION_REQUIRED" | "DRAFT_KEY_REUSED" | "DRAFT_NOT_ACCEPTED" | "DRAFT_CHAT_RETIRED";
DraftErrorResponse (packages/ui-sdk/src/protocol.ts)
export type DraftErrorResponse = {
error: "DRAFT_CONFLICT";
Expand Down Expand Up @@ -6362,6 +6426,9 @@ signatures (every public export and the types it is made of)
} | {
error: "DRAFT_NOT_ACCEPTED";
message: string;
} | {
error: "DRAFT_CHAT_RETIRED";
message: string;
};
DraftListResponse (packages/ui-sdk/src/protocol.ts)
export interface DraftListResponse {
Expand Down Expand Up @@ -9595,6 +9662,13 @@ signatures (every public export and the types it is made of)
requestId: string;
questions: AskUserQuestion[];
}
ServerChatRetired (packages/ui-sdk/src/protocol.ts)
export interface ServerChatRetired {
type: "chat_retired";
sessionId?: string;
historyOwnerIds: string[];
generation: number;
}
ServerConversationClosed (packages/ui-sdk/src/protocol.ts)
export interface ServerConversationClosed {
type: "conversation_closed";
Expand Down Expand Up @@ -9725,7 +9799,7 @@ signatures (every public export and the types it is made of)
instruction?: string;
}
ServerMessage (packages/ui-sdk/src/protocol.ts)
export type ServerMessage = ServerScopeDecisionReceipt | ServerHello | ServerRetryReceipt | ServerTextDelta | ServerThinkingDelta | ServerToolUseStart | ServerToolInputDelta | ServerToolUseComplete | ServerToolResult | ServerToolApprovalRequest | ServerResultMessage | ServerError | ServerStatus | ServerSessionInfo | ServerSessionHistory | ServerAskUserRequest | ServerAskUserListRequest | ServerAskUserRankRequest | ServerAskUserFormRequest | ServerAskAnswerReceipt | ServerPong | ServerLocationRequest | ServerMaskRequest | ServerActivitySnapshot | ServerActivityDelta | ServerMessageBlocks | ServerMessageLinks | ServerLocalExchangeResult | ServerHandoffDraft | ServerHandoffReceipt | InboxSnapshot | InboxDelta | ServerToolResolution | ServerSessionQueue | ServerDialogueHistory | ServerConversationOpened | ServerConversationClosed | ServerConversationEvent | ServerConversationWork | ServerConversationOutput | ServerConversationPermission | ServerTurnJournal | ServerUsage;
export type ServerMessage = ServerScopeDecisionReceipt | ServerHello | ServerRetryReceipt | ServerTextDelta | ServerThinkingDelta | ServerToolUseStart | ServerToolInputDelta | ServerToolUseComplete | ServerToolResult | ServerToolApprovalRequest | ServerResultMessage | ServerError | ServerStatus | ServerSessionInfo | ServerSessionHistory | ServerAskUserRequest | ServerAskUserListRequest | ServerAskUserRankRequest | ServerAskUserFormRequest | ServerAskAnswerReceipt | ServerPong | ServerLocationRequest | ServerMaskRequest | ServerActivitySnapshot | ServerActivityDelta | ServerMessageBlocks | ServerMessageLinks | ServerLocalExchangeResult | ServerHandoffDraft | ServerHandoffReceipt | InboxSnapshot | InboxDelta | ServerToolResolution | ServerSessionQueue | ServerDialogueHistory | ServerConversationOpened | ServerConversationClosed | ServerConversationEvent | ServerConversationWork | ServerConversationOutput | ServerConversationPermission | ServerTurnJournal | ServerUsage | ServerChatRetired;
ServerMessageBlocks (packages/ui-sdk/src/protocol.ts)
export interface ServerMessageBlocks extends SessionScoped {
type: "message_blocks";
Expand Down Expand Up @@ -15309,6 +15383,13 @@ signatures (every public export and the types it is made of)
turnId: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"ask_user_request">;
}, z.core.$loose>;
serverChatRetiredSchema (packages/ui-sdk/src/schemas.ts)
const serverChatRetiredSchema: z.ZodObject<{
generation: z.ZodNumber;
historyOwnerIds: z.ZodArray<z.ZodString>;
sessionId: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"chat_retired">;
}, z.core.$loose>;
serverConversationClosedSchema (packages/ui-sdk/src/schemas.ts)
const serverConversationClosedSchema: z.ZodObject<{
conversationId: z.ZodString;
Expand Down Expand Up @@ -16328,6 +16409,11 @@ signatures (every public export and the types it is made of)
outputTokens: z.ZodOptional<z.ZodNumber>;
}, z.core.$loose>>>;
}, z.core.$loose>;
}, z.core.$loose>, z.ZodObject<{
generation: z.ZodNumber;
historyOwnerIds: z.ZodArray<z.ZodString>;
sessionId: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"chat_retired">;
}, z.core.$loose>, z.ZodObject<{
attachmentCount: z.ZodOptional<z.ZodNumber>;
files: z.ZodOptional<z.ZodArray<z.ZodType<import("./protocol.js").SharedFileMeta, unknown, z.core.$ZodTypeInternals<import("./protocol.js").SharedFileMeta, unknown>>>>;
Expand Down
38 changes: 38 additions & 0 deletions api-report/ui-server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,23 @@ signatures (every public export and the types it is made of)
attributes: FlatAttributes;
timestamp: number;
}
ChatDeletion (packages/ui-server/src/ws/chat-deletion.ts)
export type ChatDeletion = ReturnType<typeof createChatDeletion>;
ChatDeletionDeps (packages/ui-server/src/ws/chat-deletion.ts)
export interface ChatDeletionDeps {
catalog: Pick<SessionCatalog, "retireChat" | "chatRetirement" | "recordChatCleanup" | "cleanChatStore" | "unfinishedChatRetirements">;
backends(): Promise<AgentBackend[]>;
busy(identities: RetiredChatIdentities): boolean;
retired(principalId: string, retirement: Retired): void;
}
ChatDeletionResult (packages/ui-server/src/ws/chat-deletion.ts)
export type ChatDeletionResult = {
status: "refused";
reason: RetireRefusal;
} | {
status: "retired";
receipt: ChatDeletionReceipt;
};
ChatRetirementStatus (packages/ui-server/src/ws/chat-lifecycle.ts)
export type ChatRetirementStatus = "pending" | "partial" | "unknown" | "removed";
ChatStore (packages/ui-server/src/ws/chat-lifecycle.ts)
Expand Down Expand Up @@ -1191,6 +1208,8 @@ signatures (every public export and the types it is made of)
refresh(lock: KeyedLock): void;
close(): Promise<void>;
}
HostChatStore (packages/ui-server/src/ws/chat-store-cleanup.ts)
export type HostChatStore = Exclude<ChatStore, "native">;
HostVersionRequirements (packages/ui-server/src/app.ts)
export interface HostVersionRequirements {
brainCli?: string;
Expand Down Expand Up @@ -1672,11 +1691,16 @@ signatures (every public export and the types it is made of)
operationId: string;
generation: number;
identities: RetiredChatIdentities;
backendId: string | null;
cleanup: ChatRetirementStatus;
stores: Partial<Record<ChatStore, ChatStoreOutcome>>;
};
RetireRefusal (packages/ui-server/src/ws/chat-lifecycle.ts)
export type RetireRefusal = "unauthorized" | "unavailable" | "stale" | "unsupported" | "busy";
Retired (packages/ui-server/src/ws/chat-deletion.ts)
type Retired = Extract<RetireChatResult, {
status: "retired";
}>;
RetiredChatIdentities (packages/ui-server/src/ws/chat-lifecycle.ts)
export interface RetiredChatIdentities {
sessions: string[];
Expand Down Expand Up @@ -1798,6 +1822,8 @@ signatures (every public export and the types it is made of)
retireChat?(input: RetireChatInput, busy: (identities: RetiredChatIdentities) => boolean): Promise<RetireChatResult>;
chatRetirement?(operationId: string, principalId: string): Promise<RetireChatResult | null>;
recordChatCleanup?(lifecycleId: string, store: ChatStore, outcome: Exclude<ChatStoreOutcome, "pending">): Promise<ChatRetirementStatus>;
cleanChatStore?(lifecycleId: string, store: HostChatStore): Promise<ChatRetirementStatus>;
unfinishedChatRetirements?(): Promise<ReturnType<typeof unfinishedChatRetirements>>;
chatRetired?(target: ChatTarget | {
conversationId: string;
}): boolean;
Expand Down Expand Up @@ -2113,6 +2139,7 @@ signatures (every public export and the types it is made of)
}
WsHost (packages/ui-server/src/ws/host.ts)
export class WsHost {
chatDeletion?: import("./chat-deletion.js").ChatDeletion;
readonly journal?: import("../brain/turn-journal.js").TurnJournal;
readonly brainPath?: string;
readonly governedTurns?: import("../brain/governed-turn.js").GovernedTurns;
Expand Down Expand Up @@ -2178,6 +2205,11 @@ signatures (every public export and the types it is made of)
export function createApp(options?: CreateAppOptions): Promise<BrainUiApp>;
createBrainClient (packages/ui-server/src/brain/client.ts)
export function createBrainClient(opts: BrainClientOptions): BrainClient;
createChatDeletion (packages/ui-server/src/ws/chat-deletion.ts)
export function createChatDeletion(deps: ChatDeletionDeps): {
delete(input: Omit<RetireChatInput, "at" | "removableBackends">): Promise<ChatDeletionResult>;
reconcile(): Promise<void>;
};
createConsoleLoggerProvider (packages/ui-server/src/observability/loggers.ts)
export function createConsoleLoggerProvider(options?: ConsoleLoggerProviderOptions): LoggerProvider;
createGeminiConversationProvider (packages/ui-server/src/voice/gemini-conversation.ts)
Expand Down Expand Up @@ -2418,6 +2450,12 @@ signatures (every public export and the types it is made of)
export function resolveServerConfig(env?: EnvRecord): ServerConfig;
summary (packages/ui-server/src/brain/turn-journal.ts)
function summary(turnId: string): TurnJournalSummary;
unfinishedChatRetirements (packages/ui-server/src/ws/chat-lifecycle.ts)
export function unfinishedChatRetirements(db: Database): Array<Extract<RetireChatResult, {
status: "retired";
}> & {
principalId: string;
}>;
websocket re-exported from hono
withBrainDb (packages/ui-server/src/db/brain-db.ts)
export function withBrainDb<T>(brainPath: string, options: OpenBrainDbOptions, fn: (db: Database, schemaVersion: number) => T): T;
2 changes: 1 addition & 1 deletion docs/decisions/answer-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ carries, no longer by position.

The host also re-sends a session's pending questions after `session_resume`
(`resendPendingAsks(host, ws, msg.sessionId)`,
`packages/ui-server/src/ws/dispatch.ts:677`). Before this, a resume replaced
`packages/ui-server/src/ws/dispatch.ts:678`). Before this, a resume replaced
the transcript and left only a history card behind, which was the second
symptom.

Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/claude-code-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ next to it.
of this binary. The only version probe in the server is for the `brain` CLI
(`Probe the selected content CLI`,
`packages/ui-server/src/brain/client.ts:142-210`, called at
`probeBrainCliVersion(config.brainPath`, `packages/ui-server/src/app.ts:442`).
`probeBrainCliVersion(config.brainPath`, `packages/ui-server/src/app.ts:444`).
`brain doctor` runs `claude mcp list` from `PATH` (`which("claude")`,
`packages/core/src/cli/commands/doctor.ts:503-507`) — the user's own Claude
Code on their own machine, to check the MCP registration, not the server's
Expand Down Expand Up @@ -212,7 +212,7 @@ unnecessary.
`node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs`. The boot probe below
turns either into a refusal to start, for the same reason a missing backend
refuses to boot (`A missing (or unrecognized) agent backend`,
`packages/ui-server/src/app.ts:380-385`).
`packages/ui-server/src/app.ts:382-387`).
- **The published range is still a caret, and that bounds what this repo can
guarantee.** `@schlessera/brain-backend-claude` depends on `^0.3.241`, and a
host resolves it in its own lockfile. A host can bump the SDK — and so the
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/design-kit/sessions-and-drafts.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ event deletes the whole set. Draft content never enters this record (§5).
null, no time is printed.
- **`lastActiveAt` and `lastTouched` are never read.** A newer
`lastActiveAt` can mean that a new turn started
(`export interface ChatSession`, `packages/ui-sdk/src/protocol.ts:1576-1606`),
(`export interface ChatSession`, `packages/ui-sdk/src/protocol.ts:1580-1610`),
and `lastTouched` is LRU bookkeeping for buffer eviction.

**Merging snapshots and live frames.**
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ The brain's git history stays the durable record of its content.
- **The Activity recorder and its rollups** price those events under the
[cost-tracking rules](cost-tracking.md). An unknown price is never counted as
zero. The session total that counts unknown as zero
(`msg.costUsd ?? 0`, `packages/ui-server/src/ws/session-catalog.ts:485`)
(`msg.costUsd ?? 0`, `packages/ui-server/src/ws/session-catalog.ts:492`)
must not feed any budget.

**Enforcement:**
Expand Down
Loading
Loading