import type { TriggerConfig } from "./triggers-api"; import type { EdgeDefinition } from "./types"; /** * Interface for an agent instance that can receive credentials. * This matches the Agent class from @openserv-labs/sdk. */ export interface AgentInstance { /** * Set credentials for this agent instance. * Called by provision() to bind the agent to its platform credentials. */ setCredentials(credentials: { apiKey: string; authToken?: string; }): void; } /** * Configuration for provisioning an agent and workflow. * * @example * ```typescript * const config: ProvisionConfig = { * agent: { * name: 'my-agent', * description: 'Handles API requests' * }, * workflow: { * name: 'API Agent Pro', * goal: 'Process API requests and return responses', * trigger: triggers.webhook({ waitForCompletion: true }), * task: { * description: 'Process incoming requests', * body: 'Handle the webhook payload' * } * } * }; * * // With agent instance binding: * const agent = new Agent({ systemPrompt: '...' }); * const config: ProvisionConfig = { * agent: { * instance: agent, // Bind credentials to this agent * name: 'my-agent', * description: 'Handles API requests' * }, * // ... * }; * ``` */ interface ProvisionConfigBase { /** Agent configuration */ agent: { /** * Optional agent instance to bind credentials to. * When provided, provision() will call instance.setCredentials() with the API key. * This allows defining the agent before calling provision(). */ instance?: AgentInstance; /** Unique name for the agent */ name: string; /** Description of the agent's capabilities */ description: string; /** * URL where the agent is hosted. * Optional - when using @openserv-labs/sdk v2.0.0+, the endpoint is automatically * set to https://agents-proxy.openserv.ai when run(agent) is called. * Only provide this if your agent runs with a different publicly accessible URL. */ endpointUrl?: string; /** * Optional model parameters for the agent. * Controls which LLM model the runtime uses when executing tasks. * If not provided, the platform default (gpt-5-mini) is used. * * @example * ```typescript * model_parameters: { model: "gpt-5", verbosity: "medium", reasoning_effort: "high" } * model_parameters: { model: "gpt-4o", temperature: 0.5, parallel_tool_calls: false } * ``` */ model_parameters?: Record; }; /** Workflow configuration */ workflow: { /** Name for the workflow. Also used as the agent name in ERC-8004. */ name: string; /** Goal/description of what the workflow should accomplish */ goal: string; /** Trigger configuration (use triggers factory) */ trigger: TriggerConfig; /** Single task shorthand (backward compat). Omit agentId to assign to the provisioned agent. */ task?: { /** Task description */ description?: string; /** Detailed task body */ body?: string; }; /** * Multi-task support. Each task can specify an agentId (marketplace agent). * Omit agentId to assign to the provisioned agent. * When provided, takes precedence over `task`. */ tasks?: Array<{ name: string; description: string; body?: string; input?: string; /** Agent ID to assign the task to. Omit for the provisioned agent. */ agentId?: number; }>; /** Custom edges between trigger and tasks. If omitted, sequential edges are auto-generated. */ edges?: EdgeDefinition[]; /** Additional agent IDs to include in the workspace beyond those in tasks (e.g., observers). */ agentIds?: number[]; }; } /** * Pre-created user API key to skip SIWE authentication. * When the workflow trigger is x402, walletAddress is also required * so the platform knows which wallet to use for payments. */ interface ProvisionConfigWithCredentials extends ProvisionConfigBase { userApiKey: string; walletAddress?: string; } export type ProvisionConfig = ProvisionConfigWithCredentials | ProvisionConfigBase; /** * Result from provisioning an agent and workflow. */ export interface ProvisionResult { /** The created agent's ID */ agentId: number; /** API key for the agent */ apiKey: string; /** Auth token for securing agent requests (if generated) */ authToken?: string; /** The created workflow's ID */ workflowId: number; /** The created trigger's ID */ triggerId: string; /** Token for the trigger (used in URLs) */ triggerToken: string; /** Paywall URL for x402 triggers */ paywallUrl?: string; /** API endpoint URL for webhook and x402 triggers */ apiEndpoint?: string; } /** * Logger interface for provision operations. * Implement this to customize logging behavior. */ export interface Logger { /** Log informational messages */ info: (...args: unknown[]) => void; /** Log warning messages */ warn: (...args: unknown[]) => void; /** Log error messages */ error: (...args: unknown[]) => void; } /** * Set a custom logger for provision operations. * * @param customLogger - Logger implementation to use * * @example * ```typescript * setLogger({ * info: (...args) => myLogger.info(...args), * warn: (...args) => myLogger.warn(...args), * error: (...args) => myLogger.error(...args) * }); * ``` */ export declare function setLogger(customLogger: Logger): void; /** * Provision an agent and workflow on the OpenServ platform. * * **This function is idempotent** - you can call it multiple times with the same * config and it will update existing resources rather than create duplicates. * There's no need to check `isProvisioned()` before calling this function. * * This function handles: * - Wallet creation/retrieval * - Platform authentication (with session persistence) * - Agent registration/update (creates if new, updates if exists) * - Workflow creation/update (creates if new, updates if exists) * - State persistence to .openserv.json * * @param config - Provisioning configuration * @returns Provision result with IDs and URLs * * @example * ```ts * import { provision, triggers } from '@openserv-labs/client'; * * // Just call provision - it handles create vs update automatically * const result = await provision({ * agent: { * name: 'my-agent', * description: 'My autonomous agent', * }, * workflow: { * name: 'default', * trigger: triggers.webhook(), * task: { * description: 'Process incoming requests', * }, * }, * }); * * console.log('Agent ID:', result.agentId); * console.log('API Endpoint:', result.apiEndpoint); * ``` */ export declare function provision(config: ProvisionConfig): Promise; /** * Check if an agent and workflow are already provisioned. * * This checks the local `.openserv.json` state file. * * **Note:** Since `provision()` is idempotent, you typically don't need to call * this before provisioning. This function is useful for: * - Skipping setup logs/messages on subsequent runs * - Checking status without making API calls * - Conditional logic based on provisioning state * * @param agentName - Name of the agent to check * @param workflowName - Name of the workflow (defaults to "default") * @returns True if both agent and workflow are provisioned * * @example * ```typescript * // Optional: use for conditional logging * if (!isProvisioned('my-agent', 'api-workflow')) { * console.log('First-time setup...'); * } * * // provision() is idempotent - safe to call regardless * await provision(config); * ``` */ export declare function isProvisioned(agentName: string, workflowName?: string): boolean; /** * Get provisioned workflow info from the local state file. * * @param agentName - Name of the agent * @param workflowName - Name of the workflow (defaults to "default") * @returns Object with agent and workflow details, or null if not provisioned * * @example * ```typescript * const info = getProvisionedInfo('my-agent', 'api-workflow'); * if (info) { * console.log('Agent ID:', info.agentId); * console.log('Workflow ID:', info.workflowId); * } * ``` */ export declare function getProvisionedInfo(agentName: string, workflowName?: string): { agentId?: number; apiKey?: string; authToken?: string; workflowId?: number; triggerId?: string; triggerToken?: string; } | null; /** * Clear all provisioned state. * * This deletes the `.openserv.json` file. Useful for testing or resetting. * Note: This does not delete resources from the platform, only the local state file. * * @example * ```typescript * clearProvisionedState(); * // Now provision will create new resources * await provision(config); * ``` */ export declare function clearProvisionedState(): void; export {}; //# sourceMappingURL=provision.d.ts.map