wauldo 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -919,6 +919,135 @@ declare class AgentsClient {
919
919
  streamTask(taskId: string): AsyncGenerator<StateTransition>;
920
920
  }
921
921
 
922
+ /**
923
+ * Workflows API client — Wauldo Workflow Runtime (Step Functions style).
924
+ *
925
+ * State-machine workflows authored as `Task` / `Choice` / `Wait` / `Pass` /
926
+ * `Fail` / `Succeed` states. Runs are async: `startRun` returns an
927
+ * `execution_id`, then poll `getRun` (or use `waitForRun`) until a terminal
928
+ * status.
929
+ *
930
+ * @example
931
+ * ```ts
932
+ * import { WorkflowsClient } from "wauldo/workflows";
933
+ * const wf = new WorkflowsClient({ baseUrl: "https://api.wauldo.com", apiKey: "..." });
934
+ * const created = await wf.create({
935
+ * name: "triage",
936
+ * startAt: "Compute",
937
+ * states: {
938
+ * Compute: { type: "Task", resource: "tool:calculator", next: "Done" },
939
+ * Done: { type: "Succeed" },
940
+ * },
941
+ * });
942
+ * const run = await wf.startRun(created.id, { operation: "add", a: 21, b: 21 });
943
+ * const final = await wf.waitForRun(created.id, run.execution_id);
944
+ * console.log(final.status, final.output);
945
+ * ```
946
+ */
947
+ interface WorkflowsClientConfig {
948
+ baseUrl: string;
949
+ apiKey?: string;
950
+ /** Tenant identifier forwarded via x-rapidapi-user header. */
951
+ tenant?: string;
952
+ /** Per-request timeout in ms. Default 120_000. */
953
+ timeoutMs?: number;
954
+ }
955
+ /** A workflow definition. */
956
+ interface Workflow {
957
+ id: string;
958
+ tenant_id: string;
959
+ name: string;
960
+ description?: string;
961
+ start_at: string;
962
+ states: Record<string, unknown>;
963
+ version: string;
964
+ created_at: number;
965
+ updated_at: number;
966
+ }
967
+ interface CreateWorkflowInput {
968
+ name: string;
969
+ startAt: string;
970
+ states: Record<string, unknown>;
971
+ description?: string;
972
+ }
973
+ interface WorkflowListResponse {
974
+ workflows: Workflow[];
975
+ }
976
+ /** 202 response from `POST /v1/workflows/:id/runs`. */
977
+ interface StartRunResponse {
978
+ execution_id: string;
979
+ workflow_id: string;
980
+ status: string;
981
+ }
982
+ /**
983
+ * A workflow execution record. `status` is one of `running`, `succeeded`,
984
+ * `failed`, `timed_out`. `output` is populated on success; `error` on
985
+ * terminal failure.
986
+ */
987
+ interface WorkflowExecution {
988
+ id: string;
989
+ workflow_id: string;
990
+ tenant_id: string;
991
+ status: string;
992
+ current_state?: string | null;
993
+ input: unknown;
994
+ output?: unknown;
995
+ started_at: number;
996
+ ended_at?: number | null;
997
+ error?: string | null;
998
+ }
999
+ declare const TERMINAL_WORKFLOW_STATUSES: readonly ["succeeded", "failed", "timed_out"];
1000
+ declare function isWorkflowRunTerminal(status: string): boolean;
1001
+ declare class WorkflowsClient {
1002
+ private readonly config;
1003
+ constructor(config: WorkflowsClientConfig);
1004
+ private headers;
1005
+ private request;
1006
+ /**
1007
+ * `POST /v1/workflows` — create a workflow definition.
1008
+ *
1009
+ * The server validates cycles, transition targets, choice operators,
1010
+ * and the per-tenant cap (100) before returning 201.
1011
+ */
1012
+ create(input: CreateWorkflowInput): Promise<Workflow>;
1013
+ /**
1014
+ * `PATCH /v1/workflows/:id` — replace the workflow definition in place.
1015
+ *
1016
+ * Body shape is identical to {@link create} (`CreateWorkflowInput`). The
1017
+ * server keeps the workflow id, tenant_id, and created_at ; refreshes
1018
+ * name/description/start_at/states ; bumps `updated_at` and the monotonic
1019
+ * `version` int. Same validations as create — cycles, transition targets,
1020
+ * choice operators. Returns the updated workflow.
1021
+ */
1022
+ update(workflowId: string, input: CreateWorkflowInput): Promise<Workflow>;
1023
+ /** `GET /v1/workflows` — list workflows for the calling tenant. */
1024
+ list(): Promise<WorkflowListResponse>;
1025
+ /** `GET /v1/workflows/:id` */
1026
+ get(workflowId: string): Promise<Workflow>;
1027
+ /** `DELETE /v1/workflows/:id` */
1028
+ delete(workflowId: string): Promise<void>;
1029
+ /**
1030
+ * `POST /v1/workflows/:id/runs` — start an async execution.
1031
+ *
1032
+ * Returns 202 with an `execution_id` immediately. Poll {@link getRun}
1033
+ * or use {@link waitForRun} to await completion.
1034
+ */
1035
+ startRun(workflowId: string, input?: unknown): Promise<StartRunResponse>;
1036
+ /** `GET /v1/workflows/:id/runs/:execution_id` — fetch one execution. */
1037
+ getRun(workflowId: string, executionId: string): Promise<WorkflowExecution>;
1038
+ /**
1039
+ * Poll {@link getRun} until the run reaches a terminal status.
1040
+ *
1041
+ * Rejects with an error if the run hasn't terminated within
1042
+ * `timeoutMs`. The server enforces its own 60s wall-clock cap per run,
1043
+ * so a timeout larger than ~75_000 is just slack for polling overhead.
1044
+ */
1045
+ waitForRun(workflowId: string, executionId: string, opts?: {
1046
+ timeoutMs?: number;
1047
+ pollIntervalMs?: number;
1048
+ }): Promise<WorkflowExecution>;
1049
+ }
1050
+
922
1051
  /**
923
1052
  * History API client — Wauldo Funnel #1 audit log.
924
1053
  *
@@ -1027,4 +1156,4 @@ declare class HistoryClient {
1027
1156
  deleteTask(taskId: string): Promise<number>;
1028
1157
  }
1029
1158
 
1030
- export { type A2aResponse, AgentClient, type AgentListResponse, type AgentRevision, type AgentRunResponse, AgentsClient, type AgentsClientConfig, type CallToolResponse, type ChatChoice, type ChatClientLike, type ChatMessage, type ChatRequest, type ChatResponse, type ChatUsage, type Chunk, type ChunkResult, type ClientOptions, type Concept, type ConceptResult, ConnectionError, Conversation, type CreateAgentInput, type CreateRevisionInput, type CreateRevisionResponse, type DeployedAgent, type DetailLevel, type EmbeddingData, type EmbeddingResponse, type EmbeddingUsage, type GraphNode, type GuardClaim, type GuardMode, type GuardResponse, HistoryClient, type HistoryClientConfig, type ExportOptions as HistoryExportOptions, type ListOptions as HistoryListOptions, type HistoryListResponse, HttpClient, type HttpClientConfig, HttpError, type KnowledgeGraphResult, type ListRevisionsResponse, type LogLevel, MockHttpClient, type ModelInfo, type ModelList, type OrchestratorResponse, type PlanOptions, type PlanResult, type PlanStep, type RagAuditInfo, type RagQueryResponse, type RagSource, type RagUploadResponse, type ReasoningOptions, type ReasoningResult, type RequestOptions, type RetrievalResult, ServerError, type SourceType, type StateTransition, type Task, type TaskClaim, type TaskHistoryEntry, type TaskStatus, type TaskVerification, TimeoutError, type ToolContent, type ToolDefinition, ToolNotFoundError, type UpdateAgentPatch, ValidationError, type Verdict, WauldoError, chatContent, guardIsBlocked, guardIsSafe, isTerminalStatus, supportScore };
1159
+ export { type A2aResponse, AgentClient, type AgentListResponse, type AgentRevision, type AgentRunResponse, AgentsClient, type AgentsClientConfig, type CallToolResponse, type ChatChoice, type ChatClientLike, type ChatMessage, type ChatRequest, type ChatResponse, type ChatUsage, type Chunk, type ChunkResult, type ClientOptions, type Concept, type ConceptResult, ConnectionError, Conversation, type CreateAgentInput, type CreateRevisionInput, type CreateRevisionResponse, type CreateWorkflowInput, type DeployedAgent, type DetailLevel, type EmbeddingData, type EmbeddingResponse, type EmbeddingUsage, type GraphNode, type GuardClaim, type GuardMode, type GuardResponse, HistoryClient, type HistoryClientConfig, type ExportOptions as HistoryExportOptions, type ListOptions as HistoryListOptions, type HistoryListResponse, HttpClient, type HttpClientConfig, HttpError, type KnowledgeGraphResult, type ListRevisionsResponse, type LogLevel, MockHttpClient, type ModelInfo, type ModelList, type OrchestratorResponse, type PlanOptions, type PlanResult, type PlanStep, type RagAuditInfo, type RagQueryResponse, type RagSource, type RagUploadResponse, type ReasoningOptions, type ReasoningResult, type RequestOptions, type RetrievalResult, ServerError, type SourceType, type StartRunResponse, type StateTransition, TERMINAL_WORKFLOW_STATUSES, type Task, type TaskClaim, type TaskHistoryEntry, type TaskStatus, type TaskVerification, TimeoutError, type ToolContent, type ToolDefinition, ToolNotFoundError, type UpdateAgentPatch, ValidationError, type Verdict, WauldoError, type Workflow, type WorkflowExecution, type WorkflowListResponse, WorkflowsClient, type WorkflowsClientConfig, chatContent, guardIsBlocked, guardIsSafe, isTerminalStatus, isWorkflowRunTerminal, supportScore };
package/dist/index.d.ts CHANGED
@@ -919,6 +919,135 @@ declare class AgentsClient {
919
919
  streamTask(taskId: string): AsyncGenerator<StateTransition>;
920
920
  }
921
921
 
922
+ /**
923
+ * Workflows API client — Wauldo Workflow Runtime (Step Functions style).
924
+ *
925
+ * State-machine workflows authored as `Task` / `Choice` / `Wait` / `Pass` /
926
+ * `Fail` / `Succeed` states. Runs are async: `startRun` returns an
927
+ * `execution_id`, then poll `getRun` (or use `waitForRun`) until a terminal
928
+ * status.
929
+ *
930
+ * @example
931
+ * ```ts
932
+ * import { WorkflowsClient } from "wauldo/workflows";
933
+ * const wf = new WorkflowsClient({ baseUrl: "https://api.wauldo.com", apiKey: "..." });
934
+ * const created = await wf.create({
935
+ * name: "triage",
936
+ * startAt: "Compute",
937
+ * states: {
938
+ * Compute: { type: "Task", resource: "tool:calculator", next: "Done" },
939
+ * Done: { type: "Succeed" },
940
+ * },
941
+ * });
942
+ * const run = await wf.startRun(created.id, { operation: "add", a: 21, b: 21 });
943
+ * const final = await wf.waitForRun(created.id, run.execution_id);
944
+ * console.log(final.status, final.output);
945
+ * ```
946
+ */
947
+ interface WorkflowsClientConfig {
948
+ baseUrl: string;
949
+ apiKey?: string;
950
+ /** Tenant identifier forwarded via x-rapidapi-user header. */
951
+ tenant?: string;
952
+ /** Per-request timeout in ms. Default 120_000. */
953
+ timeoutMs?: number;
954
+ }
955
+ /** A workflow definition. */
956
+ interface Workflow {
957
+ id: string;
958
+ tenant_id: string;
959
+ name: string;
960
+ description?: string;
961
+ start_at: string;
962
+ states: Record<string, unknown>;
963
+ version: string;
964
+ created_at: number;
965
+ updated_at: number;
966
+ }
967
+ interface CreateWorkflowInput {
968
+ name: string;
969
+ startAt: string;
970
+ states: Record<string, unknown>;
971
+ description?: string;
972
+ }
973
+ interface WorkflowListResponse {
974
+ workflows: Workflow[];
975
+ }
976
+ /** 202 response from `POST /v1/workflows/:id/runs`. */
977
+ interface StartRunResponse {
978
+ execution_id: string;
979
+ workflow_id: string;
980
+ status: string;
981
+ }
982
+ /**
983
+ * A workflow execution record. `status` is one of `running`, `succeeded`,
984
+ * `failed`, `timed_out`. `output` is populated on success; `error` on
985
+ * terminal failure.
986
+ */
987
+ interface WorkflowExecution {
988
+ id: string;
989
+ workflow_id: string;
990
+ tenant_id: string;
991
+ status: string;
992
+ current_state?: string | null;
993
+ input: unknown;
994
+ output?: unknown;
995
+ started_at: number;
996
+ ended_at?: number | null;
997
+ error?: string | null;
998
+ }
999
+ declare const TERMINAL_WORKFLOW_STATUSES: readonly ["succeeded", "failed", "timed_out"];
1000
+ declare function isWorkflowRunTerminal(status: string): boolean;
1001
+ declare class WorkflowsClient {
1002
+ private readonly config;
1003
+ constructor(config: WorkflowsClientConfig);
1004
+ private headers;
1005
+ private request;
1006
+ /**
1007
+ * `POST /v1/workflows` — create a workflow definition.
1008
+ *
1009
+ * The server validates cycles, transition targets, choice operators,
1010
+ * and the per-tenant cap (100) before returning 201.
1011
+ */
1012
+ create(input: CreateWorkflowInput): Promise<Workflow>;
1013
+ /**
1014
+ * `PATCH /v1/workflows/:id` — replace the workflow definition in place.
1015
+ *
1016
+ * Body shape is identical to {@link create} (`CreateWorkflowInput`). The
1017
+ * server keeps the workflow id, tenant_id, and created_at ; refreshes
1018
+ * name/description/start_at/states ; bumps `updated_at` and the monotonic
1019
+ * `version` int. Same validations as create — cycles, transition targets,
1020
+ * choice operators. Returns the updated workflow.
1021
+ */
1022
+ update(workflowId: string, input: CreateWorkflowInput): Promise<Workflow>;
1023
+ /** `GET /v1/workflows` — list workflows for the calling tenant. */
1024
+ list(): Promise<WorkflowListResponse>;
1025
+ /** `GET /v1/workflows/:id` */
1026
+ get(workflowId: string): Promise<Workflow>;
1027
+ /** `DELETE /v1/workflows/:id` */
1028
+ delete(workflowId: string): Promise<void>;
1029
+ /**
1030
+ * `POST /v1/workflows/:id/runs` — start an async execution.
1031
+ *
1032
+ * Returns 202 with an `execution_id` immediately. Poll {@link getRun}
1033
+ * or use {@link waitForRun} to await completion.
1034
+ */
1035
+ startRun(workflowId: string, input?: unknown): Promise<StartRunResponse>;
1036
+ /** `GET /v1/workflows/:id/runs/:execution_id` — fetch one execution. */
1037
+ getRun(workflowId: string, executionId: string): Promise<WorkflowExecution>;
1038
+ /**
1039
+ * Poll {@link getRun} until the run reaches a terminal status.
1040
+ *
1041
+ * Rejects with an error if the run hasn't terminated within
1042
+ * `timeoutMs`. The server enforces its own 60s wall-clock cap per run,
1043
+ * so a timeout larger than ~75_000 is just slack for polling overhead.
1044
+ */
1045
+ waitForRun(workflowId: string, executionId: string, opts?: {
1046
+ timeoutMs?: number;
1047
+ pollIntervalMs?: number;
1048
+ }): Promise<WorkflowExecution>;
1049
+ }
1050
+
922
1051
  /**
923
1052
  * History API client — Wauldo Funnel #1 audit log.
924
1053
  *
@@ -1027,4 +1156,4 @@ declare class HistoryClient {
1027
1156
  deleteTask(taskId: string): Promise<number>;
1028
1157
  }
1029
1158
 
1030
- export { type A2aResponse, AgentClient, type AgentListResponse, type AgentRevision, type AgentRunResponse, AgentsClient, type AgentsClientConfig, type CallToolResponse, type ChatChoice, type ChatClientLike, type ChatMessage, type ChatRequest, type ChatResponse, type ChatUsage, type Chunk, type ChunkResult, type ClientOptions, type Concept, type ConceptResult, ConnectionError, Conversation, type CreateAgentInput, type CreateRevisionInput, type CreateRevisionResponse, type DeployedAgent, type DetailLevel, type EmbeddingData, type EmbeddingResponse, type EmbeddingUsage, type GraphNode, type GuardClaim, type GuardMode, type GuardResponse, HistoryClient, type HistoryClientConfig, type ExportOptions as HistoryExportOptions, type ListOptions as HistoryListOptions, type HistoryListResponse, HttpClient, type HttpClientConfig, HttpError, type KnowledgeGraphResult, type ListRevisionsResponse, type LogLevel, MockHttpClient, type ModelInfo, type ModelList, type OrchestratorResponse, type PlanOptions, type PlanResult, type PlanStep, type RagAuditInfo, type RagQueryResponse, type RagSource, type RagUploadResponse, type ReasoningOptions, type ReasoningResult, type RequestOptions, type RetrievalResult, ServerError, type SourceType, type StateTransition, type Task, type TaskClaim, type TaskHistoryEntry, type TaskStatus, type TaskVerification, TimeoutError, type ToolContent, type ToolDefinition, ToolNotFoundError, type UpdateAgentPatch, ValidationError, type Verdict, WauldoError, chatContent, guardIsBlocked, guardIsSafe, isTerminalStatus, supportScore };
1159
+ export { type A2aResponse, AgentClient, type AgentListResponse, type AgentRevision, type AgentRunResponse, AgentsClient, type AgentsClientConfig, type CallToolResponse, type ChatChoice, type ChatClientLike, type ChatMessage, type ChatRequest, type ChatResponse, type ChatUsage, type Chunk, type ChunkResult, type ClientOptions, type Concept, type ConceptResult, ConnectionError, Conversation, type CreateAgentInput, type CreateRevisionInput, type CreateRevisionResponse, type CreateWorkflowInput, type DeployedAgent, type DetailLevel, type EmbeddingData, type EmbeddingResponse, type EmbeddingUsage, type GraphNode, type GuardClaim, type GuardMode, type GuardResponse, HistoryClient, type HistoryClientConfig, type ExportOptions as HistoryExportOptions, type ListOptions as HistoryListOptions, type HistoryListResponse, HttpClient, type HttpClientConfig, HttpError, type KnowledgeGraphResult, type ListRevisionsResponse, type LogLevel, MockHttpClient, type ModelInfo, type ModelList, type OrchestratorResponse, type PlanOptions, type PlanResult, type PlanStep, type RagAuditInfo, type RagQueryResponse, type RagSource, type RagUploadResponse, type ReasoningOptions, type ReasoningResult, type RequestOptions, type RetrievalResult, ServerError, type SourceType, type StartRunResponse, type StateTransition, TERMINAL_WORKFLOW_STATUSES, type Task, type TaskClaim, type TaskHistoryEntry, type TaskStatus, type TaskVerification, TimeoutError, type ToolContent, type ToolDefinition, ToolNotFoundError, type UpdateAgentPatch, ValidationError, type Verdict, WauldoError, type Workflow, type WorkflowExecution, type WorkflowListResponse, WorkflowsClient, type WorkflowsClientConfig, chatContent, guardIsBlocked, guardIsSafe, isTerminalStatus, isWorkflowRunTerminal, supportScore };
package/dist/index.js CHANGED
@@ -29,14 +29,17 @@ __export(index_exports, {
29
29
  HttpError: () => HttpError,
30
30
  MockHttpClient: () => MockHttpClient,
31
31
  ServerError: () => ServerError,
32
+ TERMINAL_WORKFLOW_STATUSES: () => TERMINAL_WORKFLOW_STATUSES,
32
33
  TimeoutError: () => TimeoutError,
33
34
  ToolNotFoundError: () => ToolNotFoundError,
34
35
  ValidationError: () => ValidationError,
35
36
  WauldoError: () => WauldoError,
37
+ WorkflowsClient: () => WorkflowsClient,
36
38
  chatContent: () => chatContent,
37
39
  guardIsBlocked: () => guardIsBlocked,
38
40
  guardIsSafe: () => guardIsSafe,
39
41
  isTerminalStatus: () => isTerminalStatus,
42
+ isWorkflowRunTerminal: () => isWorkflowRunTerminal,
40
43
  supportScore: () => supportScore
41
44
  });
42
45
  module.exports = __toCommonJS(index_exports);
@@ -1599,6 +1602,156 @@ var AgentsClient = class {
1599
1602
  }
1600
1603
  };
1601
1604
 
1605
+ // src/workflows.ts
1606
+ var TERMINAL_WORKFLOW_STATUSES = [
1607
+ "succeeded",
1608
+ "failed",
1609
+ "timed_out"
1610
+ ];
1611
+ function isWorkflowRunTerminal(status) {
1612
+ return TERMINAL_WORKFLOW_STATUSES.includes(status);
1613
+ }
1614
+ var WorkflowsClient = class {
1615
+ constructor(config) {
1616
+ this.config = config;
1617
+ if (!config.baseUrl) throw new Error("baseUrl is required");
1618
+ }
1619
+ headers() {
1620
+ const h = { "Content-Type": "application/json" };
1621
+ if (this.config.apiKey) h["Authorization"] = `Bearer ${this.config.apiKey}`;
1622
+ if (this.config.tenant) h["x-rapidapi-user"] = this.config.tenant;
1623
+ return h;
1624
+ }
1625
+ async request(method, path, body) {
1626
+ const url = this.config.baseUrl.replace(/\/$/, "") + path;
1627
+ const controller = new AbortController();
1628
+ const timeout = setTimeout(
1629
+ () => controller.abort(),
1630
+ this.config.timeoutMs ?? 12e4
1631
+ );
1632
+ try {
1633
+ const init = {
1634
+ method,
1635
+ headers: this.headers(),
1636
+ signal: controller.signal
1637
+ };
1638
+ if (body !== void 0) init.body = JSON.stringify(body);
1639
+ const resp = await fetch(url, init);
1640
+ if (resp.status === 204) return null;
1641
+ const bytes = await _boundedRead(resp, MAX_RESPONSE_SIZE);
1642
+ const text = new TextDecoder().decode(bytes);
1643
+ if (!resp.ok) {
1644
+ throw new HttpError(resp.status, resp.statusText, text);
1645
+ }
1646
+ return text ? JSON.parse(text) : null;
1647
+ } finally {
1648
+ clearTimeout(timeout);
1649
+ }
1650
+ }
1651
+ // ── CRUD ──────────────────────────────────────────────────────────
1652
+ /**
1653
+ * `POST /v1/workflows` — create a workflow definition.
1654
+ *
1655
+ * The server validates cycles, transition targets, choice operators,
1656
+ * and the per-tenant cap (100) before returning 201.
1657
+ */
1658
+ async create(input) {
1659
+ const body = {
1660
+ name: input.name,
1661
+ start_at: input.startAt,
1662
+ states: input.states
1663
+ };
1664
+ if (input.description !== void 0) body.description = input.description;
1665
+ const env = await this.request("POST", "/v1/workflows", body);
1666
+ return env.workflow;
1667
+ }
1668
+ /**
1669
+ * `PATCH /v1/workflows/:id` — replace the workflow definition in place.
1670
+ *
1671
+ * Body shape is identical to {@link create} (`CreateWorkflowInput`). The
1672
+ * server keeps the workflow id, tenant_id, and created_at ; refreshes
1673
+ * name/description/start_at/states ; bumps `updated_at` and the monotonic
1674
+ * `version` int. Same validations as create — cycles, transition targets,
1675
+ * choice operators. Returns the updated workflow.
1676
+ */
1677
+ async update(workflowId, input) {
1678
+ const body = {
1679
+ name: input.name,
1680
+ start_at: input.startAt,
1681
+ states: input.states
1682
+ };
1683
+ if (input.description !== void 0) body.description = input.description;
1684
+ const env = await this.request(
1685
+ "PATCH",
1686
+ `/v1/workflows/${workflowId}`,
1687
+ body
1688
+ );
1689
+ return env.workflow;
1690
+ }
1691
+ /** `GET /v1/workflows` — list workflows for the calling tenant. */
1692
+ async list() {
1693
+ return await this.request("GET", "/v1/workflows");
1694
+ }
1695
+ /** `GET /v1/workflows/:id` */
1696
+ async get(workflowId) {
1697
+ const env = await this.request(
1698
+ "GET",
1699
+ `/v1/workflows/${workflowId}`
1700
+ );
1701
+ return env.workflow;
1702
+ }
1703
+ /** `DELETE /v1/workflows/:id` */
1704
+ async delete(workflowId) {
1705
+ await this.request("DELETE", `/v1/workflows/${workflowId}`);
1706
+ }
1707
+ // ── Runs ──────────────────────────────────────────────────────────
1708
+ /**
1709
+ * `POST /v1/workflows/:id/runs` — start an async execution.
1710
+ *
1711
+ * Returns 202 with an `execution_id` immediately. Poll {@link getRun}
1712
+ * or use {@link waitForRun} to await completion.
1713
+ */
1714
+ async startRun(workflowId, input) {
1715
+ const body = {};
1716
+ if (input !== void 0) body.input = input;
1717
+ return await this.request(
1718
+ "POST",
1719
+ `/v1/workflows/${workflowId}/runs`,
1720
+ body
1721
+ );
1722
+ }
1723
+ /** `GET /v1/workflows/:id/runs/:execution_id` — fetch one execution. */
1724
+ async getRun(workflowId, executionId) {
1725
+ const env = await this.request(
1726
+ "GET",
1727
+ `/v1/workflows/${workflowId}/runs/${executionId}`
1728
+ );
1729
+ return env.execution;
1730
+ }
1731
+ /**
1732
+ * Poll {@link getRun} until the run reaches a terminal status.
1733
+ *
1734
+ * Rejects with an error if the run hasn't terminated within
1735
+ * `timeoutMs`. The server enforces its own 60s wall-clock cap per run,
1736
+ * so a timeout larger than ~75_000 is just slack for polling overhead.
1737
+ */
1738
+ async waitForRun(workflowId, executionId, opts = {}) {
1739
+ const timeoutMs = opts.timeoutMs ?? 9e4;
1740
+ const pollIntervalMs = opts.pollIntervalMs ?? 1e3;
1741
+ const deadline = Date.now() + timeoutMs;
1742
+ while (true) {
1743
+ const execution = await this.getRun(workflowId, executionId);
1744
+ if (isWorkflowRunTerminal(execution.status)) return execution;
1745
+ if (Date.now() >= deadline) {
1746
+ throw new Error(
1747
+ `workflow run ${executionId} did not terminate within ${timeoutMs}ms (last status: ${execution.status})`
1748
+ );
1749
+ }
1750
+ await new Promise((r) => setTimeout(r, pollIntervalMs));
1751
+ }
1752
+ }
1753
+ };
1754
+
1602
1755
  // src/history.ts
1603
1756
  var HistoryClient = class {
1604
1757
  constructor(config) {
@@ -1718,13 +1871,16 @@ var HistoryClient = class {
1718
1871
  HttpError,
1719
1872
  MockHttpClient,
1720
1873
  ServerError,
1874
+ TERMINAL_WORKFLOW_STATUSES,
1721
1875
  TimeoutError,
1722
1876
  ToolNotFoundError,
1723
1877
  ValidationError,
1724
1878
  WauldoError,
1879
+ WorkflowsClient,
1725
1880
  chatContent,
1726
1881
  guardIsBlocked,
1727
1882
  guardIsSafe,
1728
1883
  isTerminalStatus,
1884
+ isWorkflowRunTerminal,
1729
1885
  supportScore
1730
1886
  });
package/dist/index.mjs CHANGED
@@ -1556,6 +1556,156 @@ var AgentsClient = class {
1556
1556
  }
1557
1557
  };
1558
1558
 
1559
+ // src/workflows.ts
1560
+ var TERMINAL_WORKFLOW_STATUSES = [
1561
+ "succeeded",
1562
+ "failed",
1563
+ "timed_out"
1564
+ ];
1565
+ function isWorkflowRunTerminal(status) {
1566
+ return TERMINAL_WORKFLOW_STATUSES.includes(status);
1567
+ }
1568
+ var WorkflowsClient = class {
1569
+ constructor(config) {
1570
+ this.config = config;
1571
+ if (!config.baseUrl) throw new Error("baseUrl is required");
1572
+ }
1573
+ headers() {
1574
+ const h = { "Content-Type": "application/json" };
1575
+ if (this.config.apiKey) h["Authorization"] = `Bearer ${this.config.apiKey}`;
1576
+ if (this.config.tenant) h["x-rapidapi-user"] = this.config.tenant;
1577
+ return h;
1578
+ }
1579
+ async request(method, path, body) {
1580
+ const url = this.config.baseUrl.replace(/\/$/, "") + path;
1581
+ const controller = new AbortController();
1582
+ const timeout = setTimeout(
1583
+ () => controller.abort(),
1584
+ this.config.timeoutMs ?? 12e4
1585
+ );
1586
+ try {
1587
+ const init = {
1588
+ method,
1589
+ headers: this.headers(),
1590
+ signal: controller.signal
1591
+ };
1592
+ if (body !== void 0) init.body = JSON.stringify(body);
1593
+ const resp = await fetch(url, init);
1594
+ if (resp.status === 204) return null;
1595
+ const bytes = await _boundedRead(resp, MAX_RESPONSE_SIZE);
1596
+ const text = new TextDecoder().decode(bytes);
1597
+ if (!resp.ok) {
1598
+ throw new HttpError(resp.status, resp.statusText, text);
1599
+ }
1600
+ return text ? JSON.parse(text) : null;
1601
+ } finally {
1602
+ clearTimeout(timeout);
1603
+ }
1604
+ }
1605
+ // ── CRUD ──────────────────────────────────────────────────────────
1606
+ /**
1607
+ * `POST /v1/workflows` — create a workflow definition.
1608
+ *
1609
+ * The server validates cycles, transition targets, choice operators,
1610
+ * and the per-tenant cap (100) before returning 201.
1611
+ */
1612
+ async create(input) {
1613
+ const body = {
1614
+ name: input.name,
1615
+ start_at: input.startAt,
1616
+ states: input.states
1617
+ };
1618
+ if (input.description !== void 0) body.description = input.description;
1619
+ const env = await this.request("POST", "/v1/workflows", body);
1620
+ return env.workflow;
1621
+ }
1622
+ /**
1623
+ * `PATCH /v1/workflows/:id` — replace the workflow definition in place.
1624
+ *
1625
+ * Body shape is identical to {@link create} (`CreateWorkflowInput`). The
1626
+ * server keeps the workflow id, tenant_id, and created_at ; refreshes
1627
+ * name/description/start_at/states ; bumps `updated_at` and the monotonic
1628
+ * `version` int. Same validations as create — cycles, transition targets,
1629
+ * choice operators. Returns the updated workflow.
1630
+ */
1631
+ async update(workflowId, input) {
1632
+ const body = {
1633
+ name: input.name,
1634
+ start_at: input.startAt,
1635
+ states: input.states
1636
+ };
1637
+ if (input.description !== void 0) body.description = input.description;
1638
+ const env = await this.request(
1639
+ "PATCH",
1640
+ `/v1/workflows/${workflowId}`,
1641
+ body
1642
+ );
1643
+ return env.workflow;
1644
+ }
1645
+ /** `GET /v1/workflows` — list workflows for the calling tenant. */
1646
+ async list() {
1647
+ return await this.request("GET", "/v1/workflows");
1648
+ }
1649
+ /** `GET /v1/workflows/:id` */
1650
+ async get(workflowId) {
1651
+ const env = await this.request(
1652
+ "GET",
1653
+ `/v1/workflows/${workflowId}`
1654
+ );
1655
+ return env.workflow;
1656
+ }
1657
+ /** `DELETE /v1/workflows/:id` */
1658
+ async delete(workflowId) {
1659
+ await this.request("DELETE", `/v1/workflows/${workflowId}`);
1660
+ }
1661
+ // ── Runs ──────────────────────────────────────────────────────────
1662
+ /**
1663
+ * `POST /v1/workflows/:id/runs` — start an async execution.
1664
+ *
1665
+ * Returns 202 with an `execution_id` immediately. Poll {@link getRun}
1666
+ * or use {@link waitForRun} to await completion.
1667
+ */
1668
+ async startRun(workflowId, input) {
1669
+ const body = {};
1670
+ if (input !== void 0) body.input = input;
1671
+ return await this.request(
1672
+ "POST",
1673
+ `/v1/workflows/${workflowId}/runs`,
1674
+ body
1675
+ );
1676
+ }
1677
+ /** `GET /v1/workflows/:id/runs/:execution_id` — fetch one execution. */
1678
+ async getRun(workflowId, executionId) {
1679
+ const env = await this.request(
1680
+ "GET",
1681
+ `/v1/workflows/${workflowId}/runs/${executionId}`
1682
+ );
1683
+ return env.execution;
1684
+ }
1685
+ /**
1686
+ * Poll {@link getRun} until the run reaches a terminal status.
1687
+ *
1688
+ * Rejects with an error if the run hasn't terminated within
1689
+ * `timeoutMs`. The server enforces its own 60s wall-clock cap per run,
1690
+ * so a timeout larger than ~75_000 is just slack for polling overhead.
1691
+ */
1692
+ async waitForRun(workflowId, executionId, opts = {}) {
1693
+ const timeoutMs = opts.timeoutMs ?? 9e4;
1694
+ const pollIntervalMs = opts.pollIntervalMs ?? 1e3;
1695
+ const deadline = Date.now() + timeoutMs;
1696
+ while (true) {
1697
+ const execution = await this.getRun(workflowId, executionId);
1698
+ if (isWorkflowRunTerminal(execution.status)) return execution;
1699
+ if (Date.now() >= deadline) {
1700
+ throw new Error(
1701
+ `workflow run ${executionId} did not terminate within ${timeoutMs}ms (last status: ${execution.status})`
1702
+ );
1703
+ }
1704
+ await new Promise((r) => setTimeout(r, pollIntervalMs));
1705
+ }
1706
+ }
1707
+ };
1708
+
1559
1709
  // src/history.ts
1560
1710
  var HistoryClient = class {
1561
1711
  constructor(config) {
@@ -1674,13 +1824,16 @@ export {
1674
1824
  HttpError,
1675
1825
  MockHttpClient,
1676
1826
  ServerError,
1827
+ TERMINAL_WORKFLOW_STATUSES,
1677
1828
  TimeoutError,
1678
1829
  ToolNotFoundError,
1679
1830
  ValidationError,
1680
1831
  WauldoError,
1832
+ WorkflowsClient,
1681
1833
  chatContent,
1682
1834
  guardIsBlocked,
1683
1835
  guardIsSafe,
1684
1836
  isTerminalStatus,
1837
+ isWorkflowRunTerminal,
1685
1838
  supportScore
1686
1839
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wauldo",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Official TypeScript SDK for Wauldo — Verified AI answers from your documents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",