import type { PlatformClient } from "./client"; import type { CallableTrigger, Trigger } from "./types"; /** * Defines a single property in an input schema. */ export interface InputSchemaProperty { type: "string" | "number" | "boolean" | "object" | "array"; title?: string; description?: string; enum?: string[]; default?: unknown; } /** * Schema defining input fields for a trigger. */ export interface InputSchema { [key: string]: InputSchemaProperty; } /** * Configuration for a webhook trigger. * Discriminated on `type: "webhook"`. */ export interface WebhookTriggerConfig { type: "webhook"; /** Trigger ID (used when syncing existing triggers) */ id?: string; /** Display name for the trigger (shown in listings and UI) */ name?: string; /** Description of what this trigger does */ description?: string; /** Whether to wait for workflow completion before responding */ waitForCompletion?: boolean; /** Timeout in seconds (default: 600) */ timeout?: number; /** JSON Schema for webhook payload validation */ inputSchema?: Record; } /** * Configuration for an x402 (paid) trigger. * Discriminated on `type: "x402"`. */ export interface X402TriggerConfig { type: "x402"; /** Trigger ID (used when syncing existing triggers) */ id?: string; /** Display name for the service (e.g., "AI Research Assistant") - shown in x402-services listing */ name?: string; /** Description of what this service does - shown in x402-services listing */ description?: string; /** Price in USD (e.g., "0.01") */ x402Pricing: string; /** Wallet address to receive payments */ x402WalletAddress?: string; /** Timeout in seconds (default: 600) */ timeout?: number; /** JSON Schema for request validation */ inputSchema?: Record; /** x402 triggers always wait for completion */ waitForCompletion: true; } /** * Configuration for a cron (scheduled) trigger. * Discriminated on `type: "cron"`. */ export interface CronTriggerConfig { type: "cron"; /** Trigger ID (used when syncing existing triggers) */ id?: string; /** Display name for the trigger (shown in listings and UI) */ name?: string; /** Description of what this trigger does */ description?: string; /** Cron expression (e.g., "0 9 * * *" for daily at 9 AM) */ schedule: string; /** Timezone as IANA time zone name (default: "UTC") */ timezone: string; } /** * Configuration for a manual trigger. * Discriminated on `type: "manual"`. */ export interface ManualTriggerConfig { type: "manual"; /** Trigger ID (used when syncing existing triggers) */ id?: string; /** Display name for the trigger (shown in listings and UI) */ name?: string; /** Description of what this trigger does */ description?: string; } /** * Discriminated union of all trigger configurations. * Discriminate on the `type` field to narrow to a specific trigger type. */ export type TriggerConfig = WebhookTriggerConfig | X402TriggerConfig | CronTriggerConfig | ManualTriggerConfig; /** * Factory functions for creating type-safe trigger configurations. * Each factory accepts user-friendly parameters and returns a flat, * properly typed config with API-ready field names. * * @example * ```typescript * import { triggers } from '@openserv-labs/client'; * * const webhook = triggers.webhook({ waitForCompletion: true }); * // { type: 'webhook', waitForCompletion: true, timeout: 600 } * * const x402 = triggers.x402({ price: '0.01' }); * // { type: 'x402', x402Pricing: '0.01', timeout: 600 } * ``` */ export declare const triggers: { /** * Create a webhook trigger configuration. * @param opts - Options for the webhook trigger * @returns Webhook trigger configuration */ webhook: (opts?: { name?: string; description?: string; input?: InputSchema; waitForCompletion?: boolean; timeout?: number; }) => WebhookTriggerConfig; /** * Create an x402 (paid) trigger configuration. * @param opts - Options for the x402 trigger * @param opts.name - Display name for the service (e.g., "AI Research Assistant") * @param opts.description - Description of what this service does * @param opts.price - Price in USD (e.g., "0.01") * @returns x402 trigger configuration */ x402: (opts: { name?: string; description?: string; price: string; input?: InputSchema; timeout?: number; walletAddress?: string; }) => X402TriggerConfig; /** * Create a cron (scheduled) trigger configuration. * @param opts - Options for the cron trigger * @param opts.schedule - Cron expression * @param opts.timezone - Timezone (default: "UTC") * @returns Cron trigger configuration */ cron: (opts: { name?: string; description?: string; schedule: string; timezone?: string; }) => CronTriggerConfig; /** * Create a manual trigger configuration. * @param opts - Optional settings for the manual trigger * @returns Manual trigger configuration */ manual: (opts?: { name?: string; description?: string; }) => ManualTriggerConfig; }; /** * Convert an InputSchema to JSON Schema format. * @param input - The input schema to convert * @returns JSON Schema compliant object */ export declare function inputSchemaToJsonSchema(input: InputSchema): Record; /** * API for managing workflow triggers. * * @example * ```typescript * const client = new PlatformClient({ apiKey: 'your-key' }); * * // Get integration connection ID * const connId = await client.integrations.getOrCreateConnection('webhook-trigger'); * * // Create a trigger * const trigger = await client.triggers.create({ * workflowId: 123, * name: 'My Webhook', * integrationConnectionId: connId, * props: { waitForCompletion: true } * }); * * // Activate the trigger * await client.triggers.activate({ workflowId: 123, id: trigger.id }); * ``` */ export declare class TriggersAPI { private client; constructor(client: PlatformClient); /** * Create a new trigger in a workflow. * @param params - Parameters object * @param params.workflowId - The workflow ID * @param params.name - Display name for the trigger (e.g., "AI Research Assistant") * @param params.description - Description of what this trigger does * @param params.integrationConnectionId - Integration connection ID (e.g., from getOrCreateConnection) * @param params.props - Trigger properties * @param params.trigger_name - Optional specific trigger name * @returns The created trigger */ create(params: { workflowId: number | string; name: string; description?: string; integrationConnectionId: string; props?: Record; trigger_name?: string; }): Promise; /** * Get a trigger by ID. * @param params - Parameters object * @param params.workflowId - The workflow ID * @param params.id - The trigger ID * @returns The trigger */ get(params: { workflowId: number | string; id: string; }): Promise; /** * List all triggers in a workflow. * @param params - Parameters object * @param params.workflowId - The workflow ID * @returns Array of triggers */ list(params: { workflowId: number | string; }): Promise; /** * Update an existing trigger. * @param params - Parameters object * @param params.workflowId - The workflow ID * @param params.id - The trigger ID to update * @param params.props - New properties (optional) * @param params.name - New name (optional) * @param params.description - New description (optional) * @returns The updated trigger */ update(params: { workflowId: number | string; id: string; props?: Record; name?: string; description?: string; }): Promise; /** * Delete a trigger. * @param params - Parameters object * @param params.workflowId - The workflow ID * @param params.id - The trigger ID to delete */ delete(params: { workflowId: number | string; id: string; }): Promise; /** * Activate a trigger so it can receive events. * @param params - Parameters object * @param params.workflowId - The workflow ID * @param params.id - The trigger ID to activate */ activate(params: { workflowId: number | string; id: string; }): Promise; /** * Fire a trigger manually (for testing or manual invocation). * @param params - Parameters object * @param params.workflowId - The workflow ID * @param params.id - The trigger ID to fire * @param params.input - Optional input data as JSON string * @returns Response from the trigger */ fire(params: { workflowId: number | string; id: string; input?: string; }): Promise; /** * Fire a webhook trigger by workflow ID or direct URL. * * When `workflowId` is provided, the method automatically resolves the * webhook trigger token by listing the workflow's triggers and finding * the first non-x402 trigger with a token. You can narrow which trigger * to use by also passing `triggerId` or `triggerName`. * * @param params - Parameters * @param params.workflowId - The workflow ID (recommended - resolves webhook URL automatically) * @param params.triggerUrl - Direct webhook URL (alternative to workflowId) * @param params.triggerId - Specific trigger ID within the workflow (optional, used with workflowId) * @param params.triggerName - Specific trigger name within the workflow (optional, used with workflowId) * @param params.input - Input data to pass to the workflow * @returns The webhook response data * * @example * ```typescript * // By workflow ID (recommended) * const result = await client.triggers.fireWebhook({ * workflowId: 123, * input: { query: 'hello world' } * }); * * // By workflow ID + trigger name * const result = await client.triggers.fireWebhook({ * workflowId: 123, * triggerName: 'My Webhook', * input: { query: 'hello world' } * }); * * // By direct URL * const result = await client.triggers.fireWebhook({ * triggerUrl: 'https://api.openserv.ai/webhooks/trigger/TOKEN', * input: { query: 'hello world' } * }); * ``` */ fireWebhook(params: { workflowId?: number; triggerUrl?: string; triggerId?: string; triggerName?: string; input?: Record; }): Promise; /** * Resolve a webhook trigger token from workflowId. */ private resolveWebhookToken; /** * Get callable triggers for a workspace. * * Returns the list of triggers that can be called externally, along with * their input schemas and endpoint URLs. This is used during ERC-8004 * deployment to register the agent's available services on-chain. * * @param params - Parameters * @param params.workflowId - The workflow (workspace) ID * @returns Array of callable triggers with their schemas and endpoints * * @example * ```typescript * const triggers = await client.triggers.getCallableTriggers({ workflowId: 123 }); * for (const trigger of triggers) { * console.log(trigger.name, trigger.webEndpoint); * } * ``` */ getCallableTriggers(params: { workflowId: number; }): Promise; } //# sourceMappingURL=triggers-api.d.ts.map