/** * `@compose-market/sdk` — Official SDK for Compose Market. * * Exposes the canonical header contract (`Authorization: Bearer compose-`, * `x-session-user-address`, `x-network-id`) that powers Compose's first-party * apps (web/, mesh/) and lets any third-party integrator embed: * * - Compose Key lifecycle (create / list / get / revoke, session metadata) * - Multi-provider model catalog (list / listAll / search / get / getParams) * - Native Responses API inference with SSE streaming, * typed tool-call deltas and reasoning deltas, typed cost receipts, and * live session-budget updates emitted on every response. * - x402 facilitator access (supported / chains / verify / settle) and typed * decoders for PAYMENT-REQUIRED, PAYMENT-RESPONSE, X-Receipt. * - Agent-first runtime memory loop (`sdk.memory.context`, * `sdk.memory.recordTurn`, `sdk.memory.remember`, `sdk.memory.loop`) for * compact pre-turn recall, post-turn persistence, and durable facts. * - SSE session events (`sdk.session.events`) for budget depletion and * expiry notifications, dispatched on the typed event bus as well. * - Webhook signature verification (HMAC-SHA256, Stripe-style header). * - Feedback/reputation submission and summaries for x402 flows, endpoints, * models, agents, and workflows without coupling feedback to settlement. * * Design: * - The orchestration client uses platform `fetch`, WebCrypto, TextDecoder, * and ReadableStream. Generated OpenAPI subpath clients use Speakeasy's * Zod-backed runtime validation. * - Identity is whatever the integrator already has. The SDK does NOT call a * wallet, does NOT request signatures, does NOT run KYC. The end-user's * wallet address — produced by whatever auth stack the integrator already * uses — is trusted in the same exact way our first-party apps trust it — * via the `x-session-user-address` header. The Compose Key JWT returned by * `keys.create(...)` is the real cryptographic identity from that point on. * - Every billable call returns a `Completion` carrying the parsed * body, the settlement receipt (if any), the request id, the live session * budget snapshot, the session-invalid reason (if any), and the raw * Response so integrators can read non-standard headers without parsing. * - Persisted session tokens survive page reloads when a storage adapter is * provided (browser `localStorage` is auto-detected). */ import { type FetchLike, type HttpClientOptions, type RetryPolicy } from "./http.js"; import { KeysResource } from "./resources/keys.js"; import { Models } from "./resources/models.js"; import { Inference } from "./resources/inference.js"; import { X402 } from "./resources/x402.js"; import { WebhooksResource } from "./resources/webhooks.js"; import { SessionEventsResource, type SessionEventsOptions } from "./resources/session-events.js"; import { Agent } from "./resources/agent.js"; import { WorkflowResource } from "./resources/workflow.js"; import { Memory } from "./resources/memory.js"; import { FeedbackResource } from "./resources/feedback.js"; import { DirectoryResource } from "./resources/directory.js"; import { SystemResource } from "./resources/system.js"; import { LocalResource } from "./resources/local.js"; import { DispenserResource } from "./resources/dispenser.js"; import { SettlementResource } from "./resources/settlement.js"; import { PermissionsResource } from "./resources/permissions.js"; import { AccountsResource } from "./resources/accounts.js"; import { GatedResource } from "./resources/gated.js"; import { Channels } from "./resources/channels.js"; import { Receipts } from "./resources/receipts.js"; import { Analytics } from "./resources/analytics.js"; import { SvmResource } from "./resources/svm.js"; import { BotchainResource } from "./resources/botchain.js"; import { UserResource } from "./resources/user.js"; import { type EventBus, type EventListener } from "./events.js"; import { type Storage } from "./storage.js"; import type { X402PaymentSigner } from "./types/index.js"; import type { CallOptions } from "./resources/inference.js"; import type { NetworkId } from "./chains/index.js"; export * from "./types/index.js"; export * from "./errors.js"; export type { APIPromise, HeaderBagInput, HttpClientOptions, RequestOptions, RetryPolicy, } from "./http.js"; export type { CallOptions, Completion, InferenceContext, } from "./resources/inference.js"; export type { WebhookEvent, VerifyWebhookInput, } from "./resources/webhooks.js"; export type { BudgetEvent, EventBus, EventListener, EventMap, EventName, ReceiptEvent, SessionInvalidEvent, } from "./events.js"; export type { Storage } from "./storage.js"; export type { SessionEventsOptions } from "./resources/session-events.js"; export type { Agent } from "./resources/agent.js"; export type { WorkflowEvent, WorkflowResource } from "./resources/workflow.js"; export type { Memory } from "./resources/memory.js"; export type { FeedbackResource } from "./resources/feedback.js"; export type { DirectoryResource } from "./resources/directory.js"; export type { SystemResource } from "./resources/system.js"; export type { LocalResource } from "./resources/local.js"; export type { DispenserResource } from "./resources/dispenser.js"; export type { SettlementResource } from "./resources/settlement.js"; export type { PermissionsResource } from "./resources/permissions.js"; export type { AccountsResource } from "./resources/accounts.js"; export type { GatedResource } from "./resources/gated.js"; export type { Channels } from "./resources/channels.js"; export type { Receipts, ReceiptListOptions } from "./resources/receipts.js"; export type { Analytics } from "./resources/analytics.js"; export type { UserResource, WalletPairRecord, UserConsentRecord, RecordConsentInput, ConsentStatusResult } from "./resources/user.js"; export type { EventsOptions } from "./resources/updates.js"; export type * as InferenceAnalytics from "@compose-market/core/analytics/inference"; export * as chains from "./chains/index.js"; export { decodeReceiptHeader, extractReceiptFromResponse, parseReceiptEvent } from "@compose-market/core/sse/receipt"; export { parseSSEStream, parse, format, named, done } from "@compose-market/core/transport"; export type { Frame, SSEFrame } from "@compose-market/core/transport"; export { create as createModelState, decode as decodeModelEvent, reduce as reduceModelState, } from "@compose-market/core/model"; export type { AssetKind, ModelAsset, ModelEvent, ModelState, ModelStatus, } from "@compose-market/core/model"; export { create as createActivityState, decode as decodeActivityEvent, reduce as reduceActivityState, } from "@compose-market/core/activity"; export type { ActivityArtifactPayload, ActivityEvent, ActivityKind, ActivityNode, ActivityState, ActivityStatus, ActivityTarget, Artifact, ArtifactType, } from "@compose-market/core/activity"; export { extractSessionBudgetFromResponse } from "@compose-market/core/sse/budget"; export { streamEvents, createRunProjection, reduceRunProjection } from "@compose-market/core/sse/stream"; export type { RunEvent, RunProjection, RunToolCall, StreamOptions, StreamResult, } from "@compose-market/core/sse/stream"; export { createPrivateKeyX402EvmSigner, createPrivateKeyX402EvmWallet, createX402EvmSigner, encodePaymentPayload, encodePaymentSignature, } from "./resources/x402.js"; export type { SpendControls } from "./resources/x402.js"; export { createMemoryStorage } from "./storage.js"; /** * Constructor options for `ComposeSDK`. */ export interface ComposeSDKOptions { /** API base URL. Defaults to `https://api.compose.market`. */ baseUrl?: string; /** Channels service URL. Defaults to `https://services.compose.market`. */ channelsUrl?: string; /** Custom fetch implementation. Defaults to the global `fetch`. */ fetch?: FetchLike; /** * End-user wallet address. Whatever identity stack you already use produced * this address — pass it through. The SDK relays it exactly as our * first-party apps do, and does not care how you obtained it. */ userAddress?: string; /** * CAIP-2 network identifier (e.g. `"eip155:43113"`). * Required for Compose Key creation, session lookup, and payment routing. * When a Compose Key is present, its JWT `payload.network` takes precedence. */ network?: NetworkId; /** * A previously-issued Compose Key JWT. The SDK stores this in-memory and * attaches it as `Authorization: Bearer compose-` on every call. * * When a `storage` adapter is present, the token is also persisted under * the scoped key `:
:` so that it survives * page reloads. If `key` is omitted at construction, the SDK * attempts to hydrate from storage. */ key?: string; /** Default timeout for each HTTP call, in milliseconds. Default 60_000. */ timeoutMs?: number; /** Retry policy applied to transient errors (5xx, 429, network). */ retry?: Partial; /** Headers merged into every request. */ defaultHeaders?: Record; /** * `User-Agent` suffix so Compose analytics can distinguish integrators. * The base string is `@compose-market/sdk/`. */ userAgent?: string; /** Optional debug/logging hooks. */ logger?: HttpClientOptions["logger"]; /** * Pluggable persistent storage. Auto-detects `globalThis.localStorage` on * browsers/Workers. Pass an explicit adapter on Node/server runtimes if * you want the session token to survive process restarts. */ storage?: Storage; /** * Namespace prefix for persisted tokens. The full key shape is * `::`. Defaults to * `compose.sdk.token`. Bump this only if you need to invalidate every * persisted token at once (e.g. after a breaking server auth change). */ tokenScope?: string; /** * Provider-agnostic x402 signer. The SDK calls this only after receiving a * real PAYMENT-REQUIRED challenge, then retries the request with the * returned PAYMENT-SIGNATURE. Integrators can back this with Thirdweb, * Privy, Dynamic, a browser wallet, a server wallet, or any other signer. */ x402Signer?: X402PaymentSigner; } export declare class ComposeSDK { /** The SDK version, sourced from package.json at build time. */ readonly version: string; /** Resolved API base URL, trimmed of trailing slashes. */ readonly baseUrl: string; /** Resolved channels service URL, trimmed of trailing slashes. */ readonly channelsUrl: string; readonly keys: KeysResource; readonly models: Models; readonly inference: Inference; readonly x402: X402; readonly webhooks: WebhooksResource; readonly session: SessionEventsNamespace; readonly agent: Agent; readonly workflow: WorkflowResource; readonly memory: Memory; readonly feedback: FeedbackResource; readonly directory: DirectoryResource; readonly system: SystemResource; readonly local: LocalResource; readonly dispenser: DispenserResource; readonly settlement: SettlementResource; readonly permissions: PermissionsResource; readonly accounts: AccountsResource; readonly gated: GatedResource; readonly channels: Channels; readonly receipts: Receipts; readonly analytics: Analytics; readonly svm: SvmResource; readonly botchain: BotchainResource; readonly user: UserResource; readonly wallets: { attach: (input: { address: string; network: NetworkId; signer?: X402PaymentSigner; }) => void; current: () => { address: string | null; network: NetworkId | null; }; clear: () => void; }; /** * Typed, in-memory event bus. Listeners registered here receive: * - `budget` — live `x-session-budget-*` snapshot on every billable call. * - `sessionInvalid` — `x-session-invalid` header set by the server. * - `sessionActive` — SSE `session-active` heartbeat from `/api/session/events`. * - `sessionExpired` — SSE `session-expired` frame from `/api/session/events`. * - `receipt` — settlement receipt on every billable response / stream. */ readonly events: EventBus; private readonly http; private readonly storage; private readonly tokenScope; private userAddress; private network; private key; private x402Signer; private readonly rawFetch; private readonly userAgent; constructor(options?: ComposeSDKOptions); private persistToken; private deletePersistedToken; /** * Drop-in `fetch` wrapper that attaches the canonical Compose header * contract (`Authorization`, `x-session-user-address`, `x-network-id`, * SDK client headers) on every request and emits `budget` / `sessionInvalid` / * `receipt` events on every response via the SDK event bus. * * Use this when you need to hit a Compose endpoint that isn't covered * by a typed resource yet (agent/workflow runtime endpoints, workspace * indexing, custom api/ routes). The URL may be absolute or relative to * the SDK's `baseUrl`. * * Non-Compose URLs (absolute URLs whose host differs from `baseUrl`) are * still passed through so this method is safe as a general-purpose fetch * replacement; the budget event extraction is a no-op when the response * doesn't carry `x-session-budget-*` headers. */ fetch(input: RequestInfo | URL, init?: RequestInit & CallOptions): Promise; } /** * Thin ergonomic wrapper around `SessionEventsResource` so callers write * `sdk.session.events({ ... })` with wallet defaults inferred from the SDK * instance. */ declare class SessionEventsNamespace { private readonly resource; private readonly getWalletMaybe; constructor(resource: SessionEventsResource, getWalletMaybe: () => { address: string | null; network: NetworkId | null; }); /** * Subscribe to `/api/session/events`. Yields `SessionActiveEvent` and * `SessionExpiredEvent` until the signal aborts or the server ends the * stream. The same events are also emitted on `sdk.events`. * * When `userAddress` / `network` are omitted, the SDK's currently attached * wallet context is used. Abort via an `AbortController.signal`. */ subscribe(opts?: Partial): AsyncIterable; /** * Shortcut: register a listener on the `sessionActive` + `sessionExpired` * events produced by a subscription. Returns a disposer that aborts the * underlying stream AND removes the listeners. */ on(handlers: { active?: EventListener<"sessionActive">; expired?: EventListener<"sessionExpired">; }, opts?: Partial): () => void; } export default ComposeSDK; //# sourceMappingURL=index.d.ts.map