@amaster.ai/client 1.0.0-alpha.1

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.
@@ -0,0 +1,142 @@
1
+ /**
2
+ *
3
+ * @module workflow
4
+ */
5
+
6
+ import type { ClientResult } from './common';
7
+
8
+ /**
9
+ * Workflow execution response mode
10
+ * - `blocking`: Wait for workflow completion (default)
11
+ * - `streaming`: Stream workflow execution progress
12
+ */
13
+ export type WorkflowResponseMode = 'blocking' | 'streaming';
14
+
15
+ /**
16
+ * Workflow input value (can be any JSON-serializable type)
17
+ */
18
+ export type WorkflowInputValue =
19
+ | string
20
+ | number
21
+ | boolean
22
+ | null
23
+ | undefined
24
+ | Record<string, unknown>
25
+ | unknown[];
26
+
27
+ /**
28
+ * Workflow file attachment
29
+ *
30
+ */
31
+ export interface WorkflowFile {
32
+ /** File name */
33
+ name?: string;
34
+ /** MIME type */
35
+ type?: string;
36
+ /** File URL */
37
+ url?: string;
38
+ /** Additional metadata */
39
+ [key: string]: unknown;
40
+ }
41
+
42
+ /**
43
+ * Workflow execution request parameters
44
+ *
45
+ * @since 1.0.0
46
+ */
47
+ export interface WorkflowRunRequest {
48
+ /** Input variables for the workflow */
49
+ inputs?: Record<string, WorkflowInputValue>;
50
+ /**
51
+ * Response mode
52
+ * @default 'blocking'
53
+ */
54
+ response_mode?: WorkflowResponseMode;
55
+ /**
56
+ * User identifier
57
+ * @default 'anonymous'
58
+ */
59
+ user?: string;
60
+ /** File attachments */
61
+ files?: WorkflowFile[];
62
+ /** Trace ID for debugging */
63
+ trace_id?: string;
64
+ }
65
+
66
+ /**
67
+ * Workflow execution response
68
+ *
69
+ * @template TOutput - The type of workflow outputs
70
+ *
71
+ */
72
+ export interface WorkflowRunResponse<TOutput = Record<string, unknown>> {
73
+ /** Task ID */
74
+ task_id: string;
75
+ /** Workflow run ID */
76
+ workflow_run_id: string;
77
+ /**
78
+ * Execution status
79
+ */
80
+ status: string;
81
+ /** Workflow output data */
82
+ outputs: TOutput;
83
+ /** Error message (if failed) */
84
+ error: string | null;
85
+ /** Execution time in milliseconds */
86
+ elapsed_time: number;
87
+ /** Total tokens consumed (for LLM workflows) */
88
+ total_tokens: number;
89
+ /** Total workflow steps executed */
90
+ total_steps: number;
91
+ /** Creation timestamp (Unix time in milliseconds) */
92
+ created_at: number;
93
+ /** Completion timestamp (Unix time in milliseconds) */
94
+ finished_at: number;
95
+ }
96
+
97
+ // ==================== Workflow Client API ====================
98
+
99
+ /**
100
+ * Workflow Execution Client API
101
+ *
102
+ * Provides methods for executing Dify-style workflows.
103
+ *
104
+ * @since 1.0.0
105
+ */
106
+ export interface WorkflowClientAPI {
107
+ /**
108
+ * Execute a workflow
109
+ *
110
+ * Runs a workflow with the provided inputs and returns the result.
111
+ * Automatically injects `app_id` from URL if in browser environment.
112
+ *
113
+ * @template TOutput - The type of workflow outputs
114
+ * @param workflowName - Workflow identifier (key/name)
115
+ * @param inputs - Workflow inputs (can be simple object or WorkflowRunRequest)
116
+ * @returns Workflow execution result
117
+ *
118
+ * @example
119
+ * // Simple execution
120
+ * const result = await client.workflow.run('data-processor', {
121
+ * source: 'users',
122
+ * limit: 100
123
+ * });
124
+ *
125
+ * if (result.success) {
126
+ * console.log('Output:', result.data.outputs);
127
+ * }
128
+ *
129
+ * @example
130
+ * // With type safety
131
+ * type Output = { processedCount: number; results: string[] };
132
+ * const result = await client.workflow.run<Output>('batch-processor', {
133
+ * batchSize: 50
134
+ * });
135
+ *
136
+ * @since 1.0.0
137
+ */
138
+ run<TOutput = Record<string, unknown>>(
139
+ workflowName: string,
140
+ inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest
141
+ ): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;
142
+ }