/** * API execution context factory. * * Creates the context object that is passed to user API functions, * providing access to integrations, logging, and environment. */ import type { IntegrationDeclaration } from "../integrations/declarations.js"; import { type TraceMetadata } from "../integrations/registry.js"; import type { IntegrationConfig } from "../integrations/types.js"; import type { ApiContext, ApiUser, Logger, AnyIntegrationRef } from "../types.js"; /** * Options for creating an API execution context. */ export interface CreateContextOptions { /** Available integration configurations keyed by id */ integrations: Map; /** * Declared integrations from the API config. * * These are the integrations specified in the `integrations` field of the API config. * The context will only expose these declared integrations via `ctx.integrations`. */ integrationDeclarations: IntegrationDeclaration[]; /** * Function to execute integration operations. * * For language plugins (JavaScript), pass the bindings parameter * to the API execution request as `input` field for binding resolution. */ executeQuery: (integrationId: string, request: Record, bindings?: Record, metadata?: TraceMetadata) => Promise; /** Execution ID for logging correlation */ executionId: string; /** Environment variables */ env: Record; /** * Server-resolved data tag key. * * Optional for compatibility with execution wrappers from older agents. */ dataTag?: string; /** User information from JWT */ user: ApiUser; /** Optional custom logger */ logger?: Logger; } /** * Creates an API execution context. * * The context provides user code with access to: * - Integration clients (built from declarations) * - Logging utilities * - Environment variables * * @param options - Context creation options * @returns The API context for user code execution * * @example * ```typescript * const ctx = createApiContext({ * integrations: new Map([ * ['int_1', { id: 'int_1', name: 'Production Postgres', pluginId: 'postgres', configuration: {} }], * ]), * integrationDeclarations: [ * { key: 'db', pluginId: 'postgres', id: 'int_1' }, * ], * executeQuery: orchestratorExecutor, * executionId: 'exec_abc', * env: { NODE_ENV: 'production' }, * }); * * // User code can access: ctx.integrations.db (typed as PostgresClient) * ``` */ export declare function createApiContext(options: CreateContextOptions): ApiContext>; //# sourceMappingURL=context.d.ts.map