UNPKG

@artinet/sdk

Version:

A TypeScript SDK for building collaborative AI agents.

159 lines (158 loc) 4.39 kB
/** * @fileoverview Global configuration for the Artinet runtime. * * Provides a centralized configuration interface that consumers use to * inject their implementations of observability, storage, and other * platform-specific dependencies. * * Design principles: * - Single configuration point for the entire SDK * - No-op defaults for all optional dependencies * - Type-safe configuration interface * - Configure once at application startup * * @module config * * @example * ```typescript * import { configure, getLogger, getTracer } from '@artinet/armada'; * import pino from 'pino'; * * // Configure at app startup * configure({ * logger: { * debug: (msg, ctx) => pino().debug(ctx, msg), * info: (msg, ctx) => pino().info(ctx, msg), * warn: (msg, ctx) => pino().warn(ctx, msg), * error: (msg, ctx) => pino().error(ctx, msg), * }, * }); * * // Later in your code * const logger = getLogger(); * logger.info('Application started'); * ``` */ import { ILogger } from "./observability.js"; import { Tracer } from "@opentelemetry/api"; /** * Artinet SDK configuration interface. * * All properties are optional - the SDK provides sensible no-op defaults. * Configure only what you need. */ export interface ArtinetConfig { /** * Logger implementation for structured logging. * @default noopLogger (no logging) */ logger?: ILogger; /** * Tracer implementation for distributed tracing. * @default trace.getTracer('artinet') (no tracing) */ tracer?: Tracer; } /** * Configure the Artinet SDK. * * Call this once at application startup to inject your implementations. * Subsequent calls will merge with existing configuration. * * @param config - Configuration options * * @example * ```typescript * // Basic configuration with console * configure({ logger: console }); * ``` * * @example * ```typescript * // Production configuration with Pino and OpenTelemetry * import pino from 'pino'; * import { trace } from '@opentelemetry/api'; * * const pinoLogger = pino(); * * configure({ * logger: { * debug: (msg, ...args) => pinoLogger.debug(Object.assign({}, ...args), msg), * info: (msg, ...args) => pinoLogger.info(Object.assign({}, ...args), msg), * warn: (msg, ...args) => pinoLogger.warn(Object.assign({}, ...args), msg), * error: (msg, ...args) => pinoLogger.error(Object.assign({}, ...args), msg), * }, * tracer: { * startSpan: (name, attrs) => { * const span = trace.getTracer('my-app').startSpan(name); * // ... wrap span * return wrappedSpan; * }, * }, * }); * ``` */ export declare function configure(config: ArtinetConfig): void; /** * Reset configuration to defaults. * * Primarily useful for testing to ensure clean state between tests. * * @example * ```typescript * beforeEach(() => { * resetConfig(); * }); * ``` */ export declare function resetConfig(): void; /** * Get the current configuration. * * Returns a copy to prevent external mutation. * * @returns Current configuration (readonly copy) */ export declare function getConfig(): Readonly<ArtinetConfig>; /** * Get the configured logger or no-op default. * * @returns Logger implementation * * @example * ```typescript * const logger = getLogger(); * logger.info('Processing request', { requestId: '123' }, 'extra data'); * ``` */ export declare function getLogger(): ILogger; /** * Get the configured tracer or no-op default. * * @returns Tracer implementation * * @example * ```typescript * const tracer = getTracer(); * const span = tracer.startSpan('processRequest', { requestId: '123' }); * try { * // ... do work * span.setStatus('ok'); * } catch (error) { * span.setStatus('error', error.message); * throw error; * } finally { * span.end(); * } * ``` */ export declare function getTracer(): Tracer; export declare const logger: { debug: (msg: string, ...args: unknown[]) => void; info: (msg: string, ...args: unknown[]) => void; warn: (msg: string, ...args: unknown[]) => void; error: (msg: string, err: unknown) => void; setLevel: (level: "debug" | "info" | "warn" | "error") => void | undefined; getLevel: () => "error" | "trace" | "verbose" | "debug" | "info" | "warn" | "silent"; child: (context: Record<string, unknown>) => ILogger; };