22/* tslint:disable */
33/* eslint-disable */
44
5- import { Task } from './Task' ;
5+ import type { Task } from './Task' ;
6+ import type { Workflow } from './Workflow' ;
67
7- export interface SignalResponse {
8- // Common fields in all responses
8+ /**
9+ * SignalResponse represents a unified response from the signal API
10+ */
11+ export class SignalResponse {
12+ // ========== COMMON FIELDS IN ALL RESPONSES ==========
13+
14+ /** Type of response based on return strategy */
915 responseType ?: string ;
16+
17+ /** ID of the target workflow */
1018 targetWorkflowId ?: string ;
19+
20+ /** Status of the target workflow */
1121 targetWorkflowStatus ?: string ;
22+
23+ /** ID of the workflow */
1224 workflowId ?: string ;
25+
26+ /** Input data for the workflow/task */
1327 input ?: Record < string , any > ;
28+
29+ /** Output data from the workflow/task */
1430 output ?: Record < string , any > ;
31+
32+ /** Priority of the workflow */
1533 priority ?: number ;
34+
35+ /** Workflow variables */
1636 variables ?: Record < string , any > ;
1737
18- // Fields specific to TARGET_WORKFLOW & BLOCKING_WORKFLOW
38+ // ========== FIELDS SPECIFIC TO TARGET_WORKFLOW & BLOCKING_WORKFLOW ==========
39+
40+ /** Array of tasks in the workflow */
1941 tasks ?: Array < Task > ;
42+
43+ /** User who created the workflow */
2044 createdBy ?: string ;
45+
46+ /** Timestamp when workflow was created */
2147 createTime ?: number ;
48+
49+ /** Current status of the workflow */
2250 status ?: string ;
51+
52+ /** Timestamp when workflow was last updated */
2353 updateTime ?: number ;
2454
25- // Fields specific to BLOCKING_TASK & BLOCKING_TASK_INPUT
55+ // ========== FIELDS SPECIFIC TO BLOCKING_TASK & BLOCKING_TASK_INPUT ==========
56+
57+ /** Type of the blocking task */
2658 taskType ?: string ;
59+
60+ /** ID of the blocking task */
2761 taskId ?: string ;
62+
63+ /** Reference name of the blocking task */
2864 referenceTaskName ?: string ;
65+
66+ /** Number of retries for the task */
2967 retryCount ?: number ;
68+
69+ /** Definition name of the task */
3070 taskDefName ?: string ;
71+
72+ /** Type of the workflow containing the task */
3173 workflowType ?: string ;
74+
75+ // ========== CHECK METHODS ==========
76+
77+ /**
78+ * Returns true if the response contains target workflow details
79+ */
80+ isTargetWorkflow ( ) : boolean {
81+ return this . responseType === 'TARGET_WORKFLOW' ;
82+ }
83+
84+ /**
85+ * Returns true if the response contains blocking workflow details
86+ */
87+ isBlockingWorkflow ( ) : boolean {
88+ return this . responseType === 'BLOCKING_WORKFLOW' ;
89+ }
90+
91+ /**
92+ * Returns true if the response contains blocking task details
93+ */
94+ isBlockingTask ( ) : boolean {
95+ return this . responseType === 'BLOCKING_TASK' ;
96+ }
97+
98+ /**
99+ * Returns true if the response contains blocking task input
100+ */
101+ isBlockingTaskInput ( ) : boolean {
102+ return this . responseType === 'BLOCKING_TASK_INPUT' ;
103+ }
104+
105+ // ========== EXTRACTION METHODS ==========
106+
107+ /**
108+ * Extracts workflow details from a SignalResponse
109+ * @throws Error if the response type doesn't contain workflow details
110+ */
111+ getWorkflow ( ) : Workflow {
112+ if ( ! this . isTargetWorkflow ( ) && ! this . isBlockingWorkflow ( ) ) {
113+ throw new Error (
114+ `Response type ${ this . responseType } does not contain workflow details`
115+ ) ;
116+ }
117+
118+ return {
119+ workflowId : this . workflowId ! ,
120+ status : this . status ! ,
121+ tasks : this . tasks || [ ] ,
122+ createdBy : this . createdBy ,
123+ createTime : this . createTime ,
124+ updateTime : this . updateTime ,
125+ input : this . input || { } ,
126+ output : this . output || { } ,
127+ variables : this . variables || { } ,
128+ priority : this . priority
129+ } as Workflow ;
130+ }
131+
132+ /**
133+ * Extracts task details from a SignalResponse
134+ * @throws Error if the response type doesn't contain task details
135+ */
136+ getBlockingTask ( ) : Task {
137+ if ( ! this . isBlockingTask ( ) && ! this . isBlockingTaskInput ( ) ) {
138+ throw new Error (
139+ `Response type ${ this . responseType } does not contain task details`
140+ ) ;
141+ }
142+
143+ return {
144+ taskId : this . taskId ! ,
145+ taskType : this . taskType ! ,
146+ taskDefName : this . taskDefName ! ,
147+ referenceTaskName : this . referenceTaskName ! ,
148+ retryCount : this . retryCount || 0 ,
149+ status : this . status ,
150+ inputData : this . input || { } ,
151+ outputData : this . output || { } ,
152+ workflowInstanceId : this . workflowId ! ,
153+ workflowType : this . workflowType !
154+ } as Task ;
155+ }
156+
157+ /**
158+ * Extracts task input from a SignalResponse
159+ * Only valid for BLOCKING_TASK_INPUT responses
160+ * @throws Error if the response type doesn't contain task input details
161+ */
162+ getTaskInput ( ) : Record < string , any > {
163+ if ( ! this . isBlockingTaskInput ( ) ) {
164+ throw new Error (
165+ `Response type ${ this . responseType } does not contain task input details`
166+ ) ;
167+ }
168+
169+ return this . input || { } ;
170+ }
171+
172+ // ========== UTILITY METHODS ==========
173+
174+ /**
175+ * Get the workflow ID from the response
176+ */
177+ getWorkflowId ( ) : string {
178+ return this . workflowId || this . targetWorkflowId || '' ;
179+ }
180+
181+ /**
182+ * Get the target workflow ID from the response
183+ */
184+ getTargetWorkflowId ( ) : string {
185+ return this . targetWorkflowId || this . workflowId || '' ;
186+ }
187+
188+ /**
189+ * Check if the response has workflow data
190+ */
191+ hasWorkflowData ( ) : boolean {
192+ return this . isTargetWorkflow ( ) || this . isBlockingWorkflow ( ) ;
193+ }
194+
195+ /**
196+ * Check if the response has task data
197+ */
198+ hasTaskData ( ) : boolean {
199+ return this . isBlockingTask ( ) || this . isBlockingTaskInput ( ) ;
200+ }
201+
202+ /**
203+ * Get response type as string
204+ */
205+ getResponseType ( ) : string {
206+ return this . responseType || '' ;
207+ }
208+
209+ /**
210+ * Check if the workflow/task is in a terminal state
211+ */
212+ isTerminal ( ) : boolean {
213+ const terminalStates = [ 'COMPLETED' , 'FAILED' , 'TERMINATED' , 'TIMED_OUT' ] ;
214+ return terminalStates . includes ( this . status || '' ) ;
215+ }
216+
217+ /**
218+ * Check if the workflow/task is currently running
219+ */
220+ isRunning ( ) : boolean {
221+ return this . status === 'RUNNING' ;
222+ }
223+
224+ /**
225+ * Check if the workflow/task is paused
226+ */
227+ isPaused ( ) : boolean {
228+ return this . status === 'PAUSED' ;
229+ }
230+
231+ /**
232+ * Get a summary of the response for logging
233+ */
234+ getSummary ( ) : string {
235+ const parts = [
236+ `type=${ this . responseType } ` ,
237+ `workflowId=${ this . workflowId } ` ,
238+ `status=${ this . status } `
239+ ] ;
240+
241+ if ( this . hasTaskData ( ) ) {
242+ parts . push ( `taskId=${ this . taskId } ` ) ;
243+ parts . push ( `taskType=${ this . taskType } ` ) ;
244+ }
245+
246+ if ( this . hasWorkflowData ( ) && this . tasks ) {
247+ parts . push ( `tasksCount=${ this . tasks . length } ` ) ;
248+ }
249+
250+ return `SignalResponse{${ parts . join ( ', ' ) } }` ;
251+ }
252+
253+ /**
254+ * Convert to JSON for debugging (excludes large objects)
255+ */
256+ toDebugJSON ( ) : Record < string , any > {
257+ return {
258+ responseType : this . responseType ,
259+ workflowId : this . workflowId ,
260+ targetWorkflowId : this . targetWorkflowId ,
261+ targetWorkflowStatus : this . targetWorkflowStatus ,
262+ status : this . status ,
263+ taskId : this . taskId ,
264+ taskType : this . taskType ,
265+ referenceTaskName : this . referenceTaskName ,
266+ createTime : this . createTime ,
267+ updateTime : this . updateTime ,
268+ priority : this . priority ,
269+ retryCount : this . retryCount ,
270+ tasksCount : this . tasks ?. length ,
271+ hasInput : Boolean ( this . input && Object . keys ( this . input ) . length > 0 ) ,
272+ hasOutput : Boolean ( this . output && Object . keys ( this . output ) . length > 0 ) ,
273+ hasVariables : Boolean ( this . variables && Object . keys ( this . variables ) . length > 0 )
274+ } ;
275+ }
276+
277+ /**
278+ * String representation for debugging
279+ */
280+ toString ( ) : string {
281+ return this . getSummary ( ) ;
282+ }
32283}
0 commit comments