|
| 1 | +/** |
| 2 | + * RPA Activity Types |
| 3 | + * |
| 4 | + * Type definitions and runtime functions for RPA activities. |
| 5 | + */ |
| 6 | + |
| 7 | +export type ActivityType = |
| 8 | + | 'sync' |
| 9 | + | 'condition' |
| 10 | + | 'loop' |
| 11 | + | 'container' |
| 12 | + | 'async' |
| 13 | + | 'error_handler' |
| 14 | + | 'code' |
| 15 | + | 'sub_diagram'; |
| 16 | + |
| 17 | +export type ActivityParamType = |
| 18 | + | 'string' |
| 19 | + | 'integer' |
| 20 | + | 'float' |
| 21 | + | 'boolean' |
| 22 | + | 'variable' |
| 23 | + | 'expression' |
| 24 | + | 'secret' |
| 25 | + | 'code' |
| 26 | + | 'list' |
| 27 | + | 'dict' |
| 28 | + | 'dataframe'; |
| 29 | + |
| 30 | +export interface ActivityParam { |
| 31 | + name: string; |
| 32 | + type: ActivityParamType; |
| 33 | + label: string; |
| 34 | + description: string; |
| 35 | + required: boolean; |
| 36 | + default?: unknown; |
| 37 | + options: string[]; |
| 38 | + variadic?: boolean; |
| 39 | +} |
| 40 | + |
| 41 | +export interface ActivityBuiltinSettings { |
| 42 | + timeout_ms: number; |
| 43 | + has_retry: boolean; |
| 44 | + has_continue_on_error: boolean; |
| 45 | +} |
| 46 | + |
| 47 | +export interface ActivityBridgePayload { |
| 48 | + id?: string; |
| 49 | + name: string; |
| 50 | + library: string; |
| 51 | + type?: string; |
| 52 | + category: string; |
| 53 | + description: string; |
| 54 | + tags?: string[]; |
| 55 | + timeout_ms?: number; |
| 56 | + has_retry?: boolean; |
| 57 | + has_continue_on_error?: boolean; |
| 58 | + params?: ActivityParam[]; |
| 59 | +} |
| 60 | + |
| 61 | +export interface Activity { |
| 62 | + id: string; |
| 63 | + name: string; |
| 64 | + library: string; |
| 65 | + type: ActivityType; |
| 66 | + category: string; |
| 67 | + description: string; |
| 68 | + tags: string[]; |
| 69 | + timeout_ms: number; |
| 70 | + has_retry: boolean; |
| 71 | + has_continue_on_error: boolean; |
| 72 | + params: ActivityParam[]; |
| 73 | + has_output: boolean; |
| 74 | + output_description: string; |
| 75 | +} |
| 76 | + |
| 77 | +export const DEFAULT_BUILTIN_SETTINGS: ActivityBuiltinSettings = { |
| 78 | + timeout_ms: 30000, |
| 79 | + has_retry: false, |
| 80 | + has_continue_on_error: false, |
| 81 | +}; |
| 82 | + |
| 83 | +function normalizeActivityParam(param: Partial<ActivityParam>): ActivityParam { |
| 84 | + return { |
| 85 | + name: param.name || '', |
| 86 | + type: (param.type || 'string') as ActivityParamType, |
| 87 | + label: param.label || param.name || '', |
| 88 | + description: param.description || '', |
| 89 | + required: param.required ?? true, |
| 90 | + default: param.default, |
| 91 | + options: param.options || [], |
| 92 | + variadic: param.variadic ?? false, |
| 93 | + }; |
| 94 | +} |
| 95 | + |
| 96 | +export function normalizeLibraryName(rawLibrary: string): string { |
| 97 | + if (!rawLibrary) return 'BuiltIn'; |
| 98 | + return rawLibrary.replace(/^RPAForge\./, '').replace(/^rpaforge_libraries\./, ''); |
| 99 | +} |
| 100 | + |
| 101 | +export function normalizeActivity(payload: ActivityBridgePayload): Activity { |
| 102 | + return { |
| 103 | + id: payload.id || `${payload.library}.${payload.name}`.replace(/\s+/g, '_').toLowerCase(), |
| 104 | + name: payload.name, |
| 105 | + library: normalizeLibraryName(payload.library), |
| 106 | + type: (payload.type as ActivityType) || 'sync', |
| 107 | + category: payload.category || 'Other', |
| 108 | + description: payload.description || '', |
| 109 | + tags: payload.tags || [], |
| 110 | + timeout_ms: payload.timeout_ms ?? DEFAULT_BUILTIN_SETTINGS.timeout_ms, |
| 111 | + has_retry: payload.has_retry ?? DEFAULT_BUILTIN_SETTINGS.has_retry, |
| 112 | + has_continue_on_error: payload.has_continue_on_error ?? DEFAULT_BUILTIN_SETTINGS.has_continue_on_error, |
| 113 | + params: (payload.params || []).map(normalizeActivityParam), |
| 114 | + has_output: (payload as { has_output?: boolean }).has_output ?? false, |
| 115 | + output_description: (payload as { output_description?: string }).output_description ?? '', |
| 116 | + }; |
| 117 | +} |
0 commit comments