/** * `@guuey/state` — open-source KV client for MCP servers * hosted on guuey.com. * * Scope: every operation runs inside one `(userId, mcpId)` namespace. * The MCP server holds no data of its own; data ownership stays * with the user (export + delete in the guuey console). * * Two import shapes: * * **Explicit** (test-friendly, no AsyncLocalStorage): * ```ts * import { createGuueyState } from '@guuey/state'; * * const kv = createGuueyState({ * context: { userId: 'u_abc', mcpId: 'mcp_xyz' }, * }); * await kv.set('hello', 'world', { ttl: 60 }); * ``` * * **Implicit via middleware** (production MCP servers): * ```ts * import { withGuueyContext } from '@guuey/state/context'; * import { kv } from '@guuey/state'; * * // Inside your tool handler, the surrounding middleware has set * // the AsyncLocalStorage context from the request headers. * await kv.set('hello', 'world', { ttl: 60 }); * ``` * * The hard caps + design rationale live in * `docs/principles/mcp-hosting-policy.md`. */ import type { CreateGuueyStateOptions, Kv } from "./types.js"; export type { CreateGuueyStateOptions, IncrementOptions, KeysPage, Kv, ScopeContext, ScopeInfo, SetOptions, } from "./types.js"; export { GuueyStateError, InvalidArgumentError, InvalidContextError, InvalidKeyError, InvalidTtlError, MissingContextError, QuotaExceededError, TransportError, TypeMismatchError, ValueTooLargeError, } from "./errors.js"; export { withGuueyContext, getCurrentContext, mcpIdFromResourceUrl, scopeFromAuthorization, validateContext, } from "./context.js"; export { HttpKv } from "./http.js"; /** * Create a KV instance bound to the given scope context. * * Binding selection: * * 1. `options.bindingUrl` or `GUUEY_KV_URL` env → the hosted HTTP * binding (`HttpKv`). Requires a token — `options.authToken`, * `GUUEY_KV_TOKEN` env, or `context.token` (from * `scopeFromAuthorization`), checked in that order — or this * throws `InvalidContextError` rather than silently handing back * a non-durable in-memory store to a caller who explicitly asked * for the hosted one (data would vanish on pod restart with zero * signal). * 2. Otherwise → in-memory binding with a one-time warning. * Suitable for tests and `guuey dev` runs. */ export declare function createGuueyState(opts: CreateGuueyStateOptions): Kv; /** * Convenience: the barrel-exported `kv` reads the current scope * context from AsyncLocalStorage on every call. Use this when * your MCP server framework has installed `withGuueyContext` as * middleware. * * Throws `MissingContextError` if called outside a context. */ export declare const kv: Kv; //# sourceMappingURL=index.d.ts.map