-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask-handler.ts
83 lines (78 loc) · 2.26 KB
/
task-handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Task, Workflow } from './workflow';
import { AppContext } from './app-context';
import { ExecutionSession } from './execution-session';
import type Joi from 'joi';
/**
* Interface representing the input for a task handler.
*/
export interface TaskHandlerInput {
/** The workflow associated with the task. */
workflow: Workflow;
/** The task to be handled. */
task: Task;
/** The application context. */
context: AppContext;
/** The execution session. */
session: ExecutionSession;
}
/**
* Interface representing a task handler.
* Keeps the logic stateless because it will be recalled multiple times with different task data.
*/
export interface TaskHandler<T = any> {
/**
* The name of the task handler.
* This name should be unique across all task handlers of the same {@link TaskGroup}.
*/
name?: string;
/**
* The display name of the task handler.
* If not provided, the name will be used as the display name.
* This name is used for displaying the task handler in the UI such as the Studio.
*/
displayName?: string;
/** The version of the task handler. */
version?: string;
/** Optional description of the task handler. */
description?: string;
/**
* The icon url of the task handler.
*/
icon?: string;
/**
* Optional keywords to match against when filtering.
*/
keywords?: string[];
/**
* An object that describes the input parameters of the task for showing help.
* If the task does not require any input, set this to null.
*/
parameters?: Joi.Description | null;
/**
* An object that describes the output of the task for showing help.
* If the task does not return anything, set this to null.
*/
output?: Joi.Description | null;
/**
* Handles the task.
* @param input - The input for the task handler.
* @returns A promise that resolves to the output of the task handler.
*/
handle(input: TaskHandlerInput): Promise<T> | T;
}
export interface TaskHandlerConstructor {
new (): TaskHandler;
}
/**
* Metadata for describing a task.
*/
export interface TaskMetadata {
name: string;
displayName?: string;
version?: string;
description?: string;
keywords?: string[];
icon?: string;
parameters?: Joi.Description | null;
output?: Joi.Description | null;
}