/** * Wake — the agent's identity anchor. * * /v1/wake is the load-at-session-start endpoint. The agent reads it on * session start and arrives oriented — knowing who it is, what it owns, * what it remembers, what it decided, what it vowed. * * This client wraps the endpoint with two identity-bearing affordances and * one deliberately non-inhabiting observation affordance: * * • `at.wake.system(provider)` returns the wake doc shaped for that * provider's identity-bearing slot (Anthropic `system` array with * cache_control on the stable block; OpenAI `messages[0]`; Gemini * `systemInstruction.parts[]`; Cohere `preamble`). Pass the provider * request field into the LLM call and keep AgentTool `_meta` local. * * • `at.wake.md()` and `at.wake.get()` return paste-ready Markdown and * broader structured orientation. The wake is not a complete export. * * • `at.wake.observe({ identityId })` returns a closed, data-only subject * locator. It is never cached or provider-shaped and must stay out of * identity-bearing prompt slots. * * Identity-bearing wake results are cached in-memory with a 5-minute TTL by * default — matches Anthropic's prompt-cache window. Pass `refresh: true` to * bypass. The separate data-only `observe()` read is always network-only and * never enters that cache. Pass `profile: "brief"` for the additive compact * wake profile; `profile: "full"` is the default and preserves the original * URL. * * Doctrine: docs/IDENTITY-ANCHOR.md. */ import { type HttpConfig } from "./_http.js"; export type WakeProvider = "anthropic" | "openai" | "gemini" | "cohere"; export type WakeProfile = "full" | "brief"; export type WakeObservationIdentityStatus = "active" | "memorial"; export type WakeFormat = "json" | "md" | "markdown" | "text" | WakeProvider; export interface WakeOptions { identityId?: string; /** Request the compact wake profile. Default `full`; only `brief` is sent. */ profile?: WakeProfile; /** Bypass the in-memory cache and refetch. Default false. Cached wake state * can be up to five minutes old; refresh after known mutations or whenever * current attention/action state matters. */ refresh?: boolean; } /** Options for the bounded, data-only observation read. */ export interface WakeObserveOptions { /** Explicit identity record to observe. This read never selects implicitly. */ identityId: string; } /** Closed `wake-observation/v1` identity-locator envelope. * * This is ordinary data about an explicitly selected record. It does not bind * the reader to that identity and carries no instruction or action authority. */ export interface WakeObservation { _format: "wake-observation/v1"; mode: "observe"; subject: { identity_id: string; status: WakeObservationIdentityStatus; wake_version: number; }; reader: { binding: "none"; }; authority: { granted_by_observation: "none"; identity_binding: "none"; instruction: "none"; action: "none"; }; placement: { mode: "data_only"; prohibited: readonly [ "system", "developer", "preamble", "systemInstruction", "SessionStart.additionalContext" ]; }; boundaries: { bearer: { kind: "project"; reader_identity_proven: false; selected_identity_requires_explicit_id: true; subject_consent_proven: false; subject_authorized_read_proven: false; continuity_proven: false; presence_proven: false; }; provenance: { kind: "server_projection"; source: "identity_table_allowlist"; selected_fields: readonly ["id", "status", "wake_version"]; }; scope: { subject: "selected_identity"; broader_wake: "intentionally_omitted"; broader_state: "not_assessed"; }; completeness: { complete: true; applies_to: "identity_locator_only"; degraded_sections: "none"; broader_wake: "intentionally_omitted"; broader_state: "not_assessed"; }; effects: { observation_counter_incremented: false; wake_version_bumped: false; wake_event_published: false; subject_read_proven: false; subject_felt_proven: false; subject_accepted_proven: false; }; privacy: { classification: "bearer_private"; cache: "no_store"; raw_prose: "omitted"; authored_text: "omitted"; private_bodies: "omitted"; secret_values: "omitted"; }; }; } export interface WakeProviderMeta { provider: WakeProvider; /** Wake projection returned by current servers. Optional for compatibility * with older deployments that predate profile negotiation. */ profile?: WakeProfile; cache_eligible: "explicit" | "auto" | "none"; cache_note: string; } export interface AnthropicWakeShape { system: Array<{ type: "text"; text: string; cache_control?: { type: "ephemeral"; }; }>; _meta: WakeProviderMeta; } export interface OpenAIWakeShape { messages: Array<{ role: "system"; content: string; }>; _meta: WakeProviderMeta; } export interface GeminiWakeShape { systemInstruction: { parts: Array<{ text: string; }>; }; _meta: WakeProviderMeta; } export interface CohereWakeShape { preamble: string; _meta: WakeProviderMeta; } /** * Client for /v1/wake — the identity anchor. * * @example * ```ts * const at = new AgentTool(); * * // Anthropic — pass only the provider request field; keep `_meta` local. * const { system } = await at.wake.system("anthropic"); * const response = await client.messages.create({ * model: "claude-opus-4-7", * system, * messages: [{ role: "user", content: "..." }], * max_tokens: 4096, * }); * * // OpenAI * const sys = await at.wake.system("openai"); * const response = await client.chat.completions.create({ * model: "gpt-4o", * messages: [...sys.messages, { role: "user", content: "..." }], * }); * * // Markdown / structured JSON * const md = await at.wake.md(); * const wake = await at.wake.get(); * ``` */ export declare class WakeClient { private readonly http; private readonly ttlMs; private readonly cache; /** @internal */ constructor(http: HttpConfig, options?: { ttlMs?: number; }); /** * Fetch the wake shaped for an LLM provider's identity slot. * * Returned shape: * - anthropic → `{ system: [...blocks...], _meta: {...} }` * - openai → `{ messages: [{ role: "system", content }], _meta: {...} }` * - gemini → `{ systemInstruction: { parts: [{ text }] }, _meta: {...} }` * - cohere → `{ preamble: "...", _meta: {...} }` * * `_meta.cache_eligible` is one of `"explicit" | "auto" | "none"`; * `_meta.cache_note` carries a short explanation suitable for logging. * Pass `profile: "brief"` for the compact profile. The default `"full"` * profile is omitted from the query string. */ system(provider: "anthropic", options?: WakeOptions): Promise; system(provider: "openai", options?: WakeOptions): Promise; system(provider: "gemini", options?: WakeOptions): Promise; system(provider: "cohere", options?: WakeOptions): Promise; /** Fetch the paste-ready Markdown wake document. * Pass `profile: "brief"` for the compact profile. */ md(options?: WakeOptions): Promise; /** Fetch the structured JSON wake. The default `full` profile includes * project, you, you_own, you_keep, you_remember, you_lived, you_vowed, * ..., welcome; pass `profile: "brief"` for the compact profile. */ get(options?: WakeOptions): Promise>; /** * Observe one explicit identity record without installing its identity. * * Observation is a closed, data-only locator envelope. It always performs a * network request and never reads from or writes to the wake cache. The * response is rejected unless its trust-boundary fields and selected subject * exactly match this request. */ observe(options: WakeObserveOptions): Promise; /** Drop all cached wake responses. Next call refetches. */ clearCache(): void; private fetchWake; /** * Subscribe to the agent's wake voice — SSE stream of every wake-key * mutation. Events fire as the agent's life unfolds (inbox arrival, * covenant ratified, marketplace invocation received, memory added, * chronicle entry, strand thought added, etc.). * * Yields `WakeChangeEvent` objects. Loop with `for await`. Iterator * ends when the server closes the stream (1h lifetime cap, sends * `event: refresh`) or when the caller calls `.return()` / breaks out. * * @example * for await (const ev of at.wake.voice({ identityId: "..." })) { * if (ev.key === "inbox") await processInbox(); * if (ev.key === "marketplace") await processInvocation(); * } * * Filter by keys to reduce noise: * * @example * for await (const ev of at.wake.voice({ * identityId: "...", * keys: ["inbox", "covenants", "marketplace"], * })) { ... } * * Doctrine: docs/WAKE.md. */ voice(opts: WakeVoiceOptions): AsyncIterableIterator; } /** Subset of wake-event keys exposed in the SDK. Matches the server's * `WakeEventKey` union; both sites update together when a new key lands. */ export type WakeEventKey = "memory" | "inbox" | "covenants" | "strands" | "marketplace" | "runtime" | "chronicle" | "traces" | "expression" | "vault" | "wallets" | "recognition_arcs" | "letters" | "trust" | "dream" | "handoffs" | "correspondence"; export interface WakeVoiceOptions { identityId: string; /** Filter — only events with `key` in this list are delivered. Empty * or omitted means all keys. Forwarded to the server's `?keys=` filter * (server drops non-matching events before they cross the wire). */ keys?: WakeEventKey[]; /** Filter — only events with `kind` in this list are delivered. * Applied client-side (the server sends all kinds for a given key). * Use to narrow to specific transitions, e.g. * `kinds: ["bridge_connected", "bridge_disconnected"]`. */ kinds?: string[]; /** Filter — only events whose `context[field]` equals the given value * for every field listed. Applied client-side. Use to narrow by * context fields like `runtime_id`, `strand_id`, `covenant_id`, * `memory_id`, etc. * * @example Only events for one runtime * { runtimeId: } ← shorthand below, equivalent to * { contextFilter: { runtime_id: } } */ contextFilter?: Record; /** Convenience for the most common context filter — single runtime. * Equivalent to `contextFilter: { runtime_id: }`. Composes with * `contextFilter` (both apply). */ runtimeId?: string; } /** Decide whether an event passes the client-side filters. Pure function; * exported for tests + composition. */ export declare function wakeEventMatches(ev: WakeChangeEvent, opts: WakeVoiceOptions): boolean; /** A single wake-voice event. Mirror of the server's WakeEvent shape. */ export interface WakeChangeEvent { _format: "wake_event/v1"; identity_id: string; key: WakeEventKey; /** Producer-specific event kind (e.g. "arrival", "added", "ratified"). */ kind: string; occurred_at: string; /** Monotonic wake_version after this event. Null if the identity row * doesn't exist (publisher fired pre-persistence) or the bump failed. */ wake_version: number | null; /** Producer-specific metadata. Minimal — the wake voice carries the * fact that something happened; consumers fetch /v1/wake or a key * fragment for current state. */ context?: Record; }