/** * Awareness engine API types — the observe wall and the findings inbox. * * The engine runs in shadow mode: observations are appended verbatim, a * background judge distills them into findings and routes each one * (would_promote / inbox / dropped), but nothing is written into the graph * without a human approval through the inbox. */ import type { DeepRecallUsage } from "./recall"; /** * Observe request. * POST /v1/awareness/observe * * The wall is deliberately dumb: append, 202, no parsing. There are no * scope/threshold/"remember this" fields — scope derives from the graph's * permission list server-side, thresholds are system policy, and authority * rides the credential + declared source, never payload content. * * @example * ```ts * await client.observe({ * source: 'turn', * payload: 'user: the new parking spot is level 3, row F\nassistant: noted.', * }); * ``` */ export type ObserveSource = "policy" | "verified" | "tool" | "turn"; export interface ObserveRequest { /** Graph to observe into; falls back to the client's default. */ graph_id?: string; /** * Provenance of the observed moment — the wall's 4-rung ladder, narrower * than the event-source ladder used by store/ingest: * * policy organizational mandate (graph-bound) * verified machine-checked fact * tool tool/model output — structurally capped at the inbox * turn a full user+assistant exchange, merged by the caller with * speaker labels ("user: ...\nassistant: ...") * * The retired event names (`user`, `assistant`, `system`, `document`) * and `derived` are rejected by the wall. */ source: ObserveSource; /** * What was observed — a string, or any JSON object (stored as its JSON * serialization, never parsed by the server). Max 64 KB; whole documents * belong to ingest. */ payload: string | Record; /** Optional hint: name a stream to keep concurrent workflows apart. */ stream?: string; /** Optional hint: when the observed thing happened (epoch seconds). */ observed_at?: number; } /** POST /v1/awareness/observe response (HTTP 202). */ export interface ObserveResponse { observed: boolean; observation_id: string; } /** Where the judge routed a finding. */ export type FindingDestination = "would_promote" | "graph" | "inbox" | "dropped"; /** A finding's lifecycle status. */ export type FindingStatus = "pending" | "promoted" | "edited_promoted" | "rejected" | "expired" | "dropped" | "shadow"; /** One judged finding — a distilled statement with the judge's verdict. */ export interface AwarenessFinding { id: string; /** The raw observation this was distilled from. */ observation_id: string; /** Context id (`type:name`) the statement would accrete on. */ context_id: string; statement: string; /** Judge-declared event kind: fact | decision | rule | constraint | observation. */ kind: string; /** Judge confidence (0.0–1.0) against the keep/save bars. */ confidence: number; stakes: string; /** Context ids this finding contradicts — contradiction outranks all. */ contradicts: string[]; /** Known context ids this finding adds detail to (rides the bars). */ extends: string[]; /** Other brief-menu entities this finding involves. */ related_to: string[]; destination: FindingDestination | string; status: FindingStatus | string; judged_at: number; rejudged_at?: number; resolved_at?: number; /** Verbatim excerpt of the raw observation (inbox reads only). */ observation_excerpt?: string; } /** * GET /v1/awareness/findings/{graph_id} and /v1/awareness/inbox/{graph_id} * response. `usage` is the judge's LLM spend summed over the graph's judged * observations — same shape as deep recall's usage block (raw provider cost; * billing markup happens at settlement). */ export interface FindingsResponse { findings: AwarenessFinding[]; usage: DeepRecallUsage; } /** Options for approving an inbox finding. */ export interface ApproveFindingOptions { /** * Edited statement; presence makes this an edit-then-approve, which the * shadow promote-rate metric counts separately. */ statement?: string; } /** POST /v1/awareness/inbox/{finding_id}/approve | reject response. */ export interface FindingActionResponse { id: string; /** `promoted` | `edited_promoted` | `rejected`. */ status: string; }