/** * Workflows Resource * * Resource manager for workflows and workflow variables. * Workflows define triggers and visual graphs for the monitoring engine. */ import type { ApiEndpointResponse, CreateApiEndpointInput, CreateWorkflowInput, ListApiEndpointsInput, ListApiEndpointsResult, ListOptions, PaginatedResponse, ResourceTagResponse, RevokeApiEndpointInput, TriggerWorkflowExecutionInput, TriggerWorkflowExecutionResponse, UpdateApiEndpointLabelInput, UpdateWorkflowInput, WorkflowFilter, WorkflowSort } from "@artu-ai/shared"; import { Workflow } from "../models/Workflow"; import { BaseResource, type ResourceConfig } from "./base"; import { WorkflowExecutionsResource } from "./workflow-executions"; import { WorkflowLinksResource } from "./workflow-links"; import { WorkflowTemplatesResource } from "./workflow-templates"; import { WorkflowVariablesResource } from "./workflow-variables"; /** * Workflows resource manager. * * Provides CRUD operations for monitoring workflows and access to workflow variables. * * @example * ```typescript * // Create a workflow * const workflow = await sdk.workflows.create({ * name: "High-value transaction alert", * trigger: { type: "event", entity: "transaction", events: ["created"] }, * workflow: { nodes: [], edges: [] }, * }); * * // List workflows * const { data: workflows } = await sdk.workflows.list({ filter: { status: "active" } }); * * // Access variables through the workflows namespace * const { data: variables } = await sdk.workflows.variables.list(); * ``` */ export declare class WorkflowsResource extends BaseResource { /** * Workflow variables resource. */ readonly variables: WorkflowVariablesResource; /** * Workflow executions resource (read-only). */ readonly executions: WorkflowExecutionsResource; /** * Workflow links resource. * Provides create, list, and revoke operations for shareable workflow links. */ readonly links: WorkflowLinksResource; /** * Workflow templates resource. * Provides CRUD and import/publish operations for reusable workflow blueprints. */ readonly templates: WorkflowTemplatesResource; constructor(config: ResourceConfig); /** * Create a new workflow. */ create(data: CreateWorkflowInput): Promise; /** * Retrieve a workflow by ID. */ retrieve(id: string): Promise; /** * Update a workflow. */ update(id: string, data: UpdateWorkflowInput): Promise; /** * Delete a workflow. */ delete(id: string): Promise; /** * List workflows with optional filtering and pagination. */ list(options?: ListOptions): Promise>; /** * List workflows ordered by the timestamp of their most recent execution * (most-recently-run first; never-run workflows appear last). Returns each * workflow augmented with a `lastExecutedAt` field. * * @example * ```typescript * const { data } = await sdk.workflows.listRecent({ limit: 10 }); * data.forEach((wf) => console.log(wf.name, wf.lastExecutedAt)); * ``` */ listRecent(options?: { limit?: number; cursor?: string; includeTotalCount?: boolean; }): Promise>; /** * Count workflows matching the given filter. */ count(filter?: WorkflowFilter): Promise; /** * Fire a workflow execution. Returns `status: "queued"` immediately; the * execution runs in the background. Use `runAndWait` if you want to * block until the run finishes. * * @example * ```typescript * const result = await sdk.workflows.run({ * id: workflowId, * triggerType: "manual", * }); * if (result.ok) { * console.log("Queued:", result.executionId); * } * ``` */ run(input: TriggerWorkflowExecutionInput): Promise; /** * Fire a workflow execution and wait for it to reach a stopping state. * Blocks for up to `options.timeoutMs` (default 30000, server-capped at * 60000). * * Possible outcomes: * - `status: "completed"` — the run finished (success or soft failure; * check `error`). `producedRecords` lists every record the run * created/updated (alerts, upserted clients/transactions, * subresources; capped per type) and `alertIds` is its alert subset. * `producedFiles` lists the files the run produced (descriptors * only — fetch contents via `executions.getFileDownloadUrl`). * - `status: "waiting_for_input"` — the run hit a human-in-loop step * (e.g. `form.choice`) and is paused waiting for a person to act on * it. The run won't finish without that, so the caller is returned * immediately instead of timing out. Surface the `executionId` to * your user (or display the workflow execution page) so they can * complete it. * - `status: "queued"` — the wait window elapsed before either of the * above. The caller can poll `executions.wait(id)` later. * * @example * ```typescript * const result = await sdk.workflows.runAndWait( * { id: workflowId, triggerType: "manual" }, * { timeoutMs: 10000 }, * ); * if (result.ok) { * switch (result.status) { * case "completed": console.log("Done:", result.alertIds); break; * case "waiting_for_input": console.log("Needs human:", result.executionId); break; * case "queued": console.log("Still running:", result.executionId); break; * } * } * ``` */ runAndWait(input: TriggerWorkflowExecutionInput, options?: { timeoutMs?: number; }): Promise; /** * Manually trigger execution of a workflow. * * @deprecated Use `run` for fire-and-forget or `runAndWait` for sync * semantics. This method now wraps `runAndWait` to preserve the * pre-async-dispatch contract — note that API triggers, which * previously returned `queued` from `triggerExecution`, now wait by * default; switch to `run` if you want the old API-trigger behavior. */ triggerExecution(input: TriggerWorkflowExecutionInput): Promise; /** * Mint a public URL for a trigger.api node. The returned `friendlyId` * is the path slug for `POST /v1/triggers/{friendlyId}`. */ createApiEndpoint(input: CreateApiEndpointInput): Promise; listApiEndpoints(input: ListApiEndpointsInput): Promise; updateApiEndpointLabel(input: UpdateApiEndpointLabelInput): Promise; revokeApiEndpoint(input: RevokeApiEndpointInput): Promise; getFileUploadUrl(input: { id: string; filename: string; contentType: string; }): Promise<{ uploadUrl: string; uploadId: string; }>; /** * Duplicate a workflow into the test environment. * * Creates a copy of the workflow as a draft in the test environment. * Can be called from either test or live environment. * * @example * ```typescript * const duplicate = await sdk.workflows.duplicate(workflowId); * console.log(duplicate.name); // "Original Name (Copy)" * console.log(duplicate.status); // "draft" * ``` */ duplicate(id: string): Promise; /** * Promote a workflow from test to live environment. * * Copies the workflow configuration to a live workflow (created as draft). * Must be called from a test environment SDK instance. * * @example * ```typescript * const { testWorkflow, liveWorkflow } = await sdk.workflows.promote(workflowId); * console.log(liveWorkflow.status); // "draft" * ``` */ promote(id: string): Promise<{ testWorkflow: Workflow; liveWorkflow: Workflow; }>; /** * Recreate the test counterpart for a live workflow that has none. * * Live workflows are config-immutable — you edit in test and re-promote. * When a live workflow's test counterpart was deleted, this recreates a * draft test workflow from the live config and links the two, so a later * {@link promote} updates this same live workflow. Idempotent: returns the * existing test counterpart if one already exists. Must be called from a * live environment SDK instance. * * @example * ```typescript * const testWorkflow = await sdk.workflows.recreateInTest(liveWorkflowId); * console.log(testWorkflow.status); // "draft" * ``` */ recreateInTest(id: string): Promise; /** * Adds tags to a workflow. */ addTags(id: string, tagIds: string[]): Promise; /** * Removes tags from a workflow. */ removeTags(id: string, tagIds: string[]): Promise; /** * Replaces all tags on a workflow. */ setTags(id: string, tagIds: string[]): Promise; /** * Lists all tags on a workflow. */ listTags(id: string): Promise; } export { WorkflowExecutionsResource } from "./workflow-executions"; export { WorkflowLinksResource } from "./workflow-links"; export { WorkflowTemplatesResource } from "./workflow-templates"; export { WorkflowVariablesResource } from "./workflow-variables";