/** * AgentCoreStore — AWS Bedrock **AgentCore Memory** adapter * (peer-dep `@aws-sdk/client-bedrock-agentcore`). * * import { AgentCoreStore } from 'agentfootprint/memory-providers'; * * const store = new AgentCoreStore({ * memoryId: 'arn:aws:bedrock-agentcore:us-west-2:...:memory/my-mem', * region: 'us-west-2', * }); * * Pattern: Adapter (GoF) — maps the `MemoryStore` interface onto AgentCore Memory's * data-plane **event** model (`CreateEvent` / `GetEvent` / `ListEvents` / * `DeleteEvent`, `@aws-sdk/client-bedrock-agentcore`): * MemoryIdentity.{tenant,principal} ↔ AgentCore `actorId` * MemoryIdentity.conversationId ↔ AgentCore `sessionId` * MemoryEntry ↔ one event whose `payload` is a single * `blob` document holding the entry * * **AgentCore Memory is an append-only event log, not a key-value store.** The server * assigns each event's `eventId` on `CreateEvent` (you cannot choose it), and there is no * "delete the whole session" call. This shapes the adapter: * * • `put` → `CreateEvent` (append; `actorId` + `eventTimestamp` are required). O(1) * • `list` → `ListEvents` (paginated, `includePayloads`). ← window / episodic memory. O(page) * • `get(id)` / `delete(id)` → list-then-find by the entry id stored in the blob, since * AgentCore's ids are server-assigned. **O(events in session)** — fine for typical * window sizes; if you need O(1) keyed access at scale, use RedisStore. * • `forget` → `ListEvents` + `DeleteEvent` per event (no `DeleteSession` on AgentCore). * • `search` → still unwired (AgentCore's `RetrieveMemoryRecords` lands as a later helper). * • `putIfVersion` / `seen` / `feedback` → in-process emulation (AgentCore has no native * CAS / dedup / feedback primitive; these don't survive process restart). * * Role: Outer ring. Lazy-requires the AWS SDK; zero runtime cost when another adapter is * in use. Emits: N/A (storage adapters don't emit). */ import type { ListOptions, ListResult, MemoryStore, PutIfVersionResult } from '../../memory/store/types.js'; import type { MemoryEntry } from '../../memory/entry/index.js'; import type { MemoryIdentity } from '../../memory/identity/index.js'; /** One event as the adapter cares about it: AgentCore's id + the decoded entry. */ export interface AgentCoreEvent { /** AgentCore server-assigned event id (needed to delete it). */ readonly eventId: string; /** The MemoryEntry decoded from the event's blob payload (null if unparseable). */ readonly entry: MemoryEntry | null; } /** * Minimal, entry-semantic surface the store uses. The real implementation * (`createAgentCoreClient`) maps these onto `CreateEvent` / `ListEvents` / * `DeleteEvent`; tests inject a mock via `_client`. */ export interface AgentCoreLikeClient { /** Append one entry as an event (server assigns the eventId). */ createEvent(input: { memoryId: string; actorId: string; sessionId: string; entry: MemoryEntry; }): Promise; /** One page of the session's events (newest-first is AgentCore's default). */ listEvents(input: { memoryId: string; actorId: string; sessionId: string; maxResults?: number; nextToken?: string; }): Promise<{ events: readonly AgentCoreEvent[]; nextToken?: string; }>; /** Delete one event by its AgentCore eventId. */ deleteEvent(input: { memoryId: string; actorId: string; sessionId: string; eventId: string; }): Promise; } export interface AgentCoreStoreOptions { /** AgentCore Memory ARN or id. Required. */ readonly memoryId: string; /** AWS region. Required when constructing the SDK client internally. */ readonly region?: string; /** Pre-built AgentCore client (shares one SDK config across the host app). */ readonly client?: AgentCoreLikeClient; /** Page size for `listEvents`. Default 100. */ readonly pageSize?: number; /** @internal Test injection — skips the SDK require entirely. */ readonly _client?: AgentCoreLikeClient; /** @internal Test injection — the AWS SDK module (to exercise the real shim with a mock SDK). */ readonly _sdk?: BedrockAgentCoreSdkModule; } /** * AgentCore Memory-backed `MemoryStore`. Implements every method except `search()`. * * @throws when `@aws-sdk/client-bedrock-agentcore` is not installed and no `_client`/`_sdk` * is supplied. */ export declare class AgentCoreStore implements MemoryStore { private readonly client; private readonly memoryId; private readonly pageSize; private closed; private readonly signatures; private readonly feedbackBag; constructor(options: AgentCoreStoreOptions); private actorId; private sessionId; private scope; private shadowKey; private feedbackKey; /** Walk every event in the session (paginated). */ private eachEvent; get(identity: MemoryIdentity, id: string): Promise | null>; put(identity: MemoryIdentity, entry: MemoryEntry): Promise; putMany(identity: MemoryIdentity, entries: readonly MemoryEntry[]): Promise; /** * Emulated optimistic concurrency. AgentCore appends unconditionally; we read-then-write * inside a JS critical section — adequate for single-writer-per-session deployments. */ putIfVersion(identity: MemoryIdentity, entry: MemoryEntry, expectedVersion: number): Promise; list(identity: MemoryIdentity, options?: ListOptions): Promise>; delete(identity: MemoryIdentity, id: string): Promise; seen(identity: MemoryIdentity, signature: string): Promise; recordSignature(identity: MemoryIdentity, signature: string): Promise; feedback(identity: MemoryIdentity, id: string, usefulness: number): Promise; getFeedback(identity: MemoryIdentity, id: string): Promise<{ average: number; count: number; } | null>; /** GDPR "everything for this identity, gone." No DeleteSession on AgentCore → delete every event. */ forget(identity: MemoryIdentity): Promise; close(): Promise; private ensureOpen; } /** The slice of `@aws-sdk/client-bedrock-agentcore` the shim touches. */ export interface BedrockAgentCoreSdkModule { readonly BedrockAgentCoreClient?: new (config: { region?: string; }) => { send(cmd: unknown): Promise; }; readonly CreateEventCommand?: new (input: unknown) => unknown; readonly ListEventsCommand?: new (input: unknown) => unknown; readonly DeleteEventCommand?: new (input: unknown) => unknown; }