evo360-types 1.3.143 → 1.3.145
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/apps/evo-task/zod-schemas.d.ts +1273 -71
- package/dist/apps/evo-task/zod-schemas.js +157 -48
- package/dist/apps/evo-task/zod-schemas.ts +177 -47
- package/dist/types/evo-notifications/index.d.ts +144 -0
- package/dist/types/evo-notifications/index.js +63 -0
- package/dist/types/evo-notifications/index.ts +261 -0
- package/dist/types/evo-task/index.d.ts +203 -69
- package/dist/types/evo-task/index.js +92 -50
- package/dist/types/evo-task/index.ts +324 -126
- package/dist/types/evo-task-runner/index.d.ts +76 -0
- package/dist/types/evo-task-runner/index.js +27 -0
- package/dist/types/evo-task-runner/index.ts +141 -0
- package/package.json +1 -1
|
@@ -14,54 +14,96 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.TaskExecutionStatusEnum = exports.TaskExternalObjectTypeEnum = exports.TaskDedupWindowEnum = exports.TaskDedupScopeEnum = exports.TaskRetryStrategyEnum = exports.TaskAutoHandlerEnum = exports.TaskModeEnum = exports.TaskSourceEnum = exports.TaskPriorityEnum = exports.TaskStatusEnum = exports.TaskActionEnum = exports.EvoTaskCollections = void 0;
|
|
18
18
|
__exportStar(require("./fb_collections"), exports);
|
|
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
|
-
|
|
19
|
+
// ======================================================
|
|
20
|
+
// evo-task (Tasks)
|
|
21
|
+
//
|
|
22
|
+
// Design goals:
|
|
23
|
+
// - Single, generic Task model used by humans and automation
|
|
24
|
+
// - AUTO tasks are executed by Task Runner (in evo-task-runner)
|
|
25
|
+
// - Payloads for specific handlers (notifications, AI, invoices, etc.)
|
|
26
|
+
// live in their own modules; here we keep the contract generic
|
|
27
|
+
// - Sub-collections (executions/comments/logs) keep lists fast
|
|
28
|
+
// ======================================================
|
|
29
|
+
// ----- Firestore collection conventions (per tenant)
|
|
30
|
+
// Root: /tenants/{tenant}/apps/evo-task/tasks/{taskId}
|
|
31
|
+
exports.EvoTaskCollections = {
|
|
32
|
+
Tasks: "tasks",
|
|
33
|
+
Executions: "executions",
|
|
34
|
+
Comments: "comments",
|
|
35
|
+
Logs: "logs",
|
|
36
|
+
};
|
|
37
|
+
// ----- Activities tracking
|
|
38
|
+
exports.TaskActionEnum = {
|
|
39
|
+
CreateTask: "CREATE_TASK",
|
|
40
|
+
DeleteTask: "DELETE_TASK",
|
|
41
|
+
UpdateTask: "UPDATE_TASK",
|
|
42
|
+
};
|
|
43
|
+
// ----- Task lifecycle status
|
|
44
|
+
// Keep the human-friendly lifecycle states (legacy-friendly): not_started / in_progress.
|
|
45
|
+
exports.TaskStatusEnum = {
|
|
46
|
+
NotStarted: "not_started",
|
|
47
|
+
InProgress: "in_progress",
|
|
48
|
+
Completed: "completed",
|
|
49
|
+
Failed: "failed", // final failure (after retries)
|
|
50
|
+
Cancelled: "cancelled",
|
|
51
|
+
OnHold: "on_hold",
|
|
52
|
+
Suppressed: "suppressed", // intentionally skipped (e.g., dedup)
|
|
53
|
+
};
|
|
54
|
+
// ----- Task priority (human-friendly)
|
|
55
|
+
exports.TaskPriorityEnum = {
|
|
56
|
+
Low: "low",
|
|
57
|
+
Medium: "medium",
|
|
58
|
+
High: "high",
|
|
59
|
+
};
|
|
60
|
+
// ----- Task source (who created it)
|
|
61
|
+
exports.TaskSourceEnum = {
|
|
62
|
+
User: "user",
|
|
63
|
+
AutomationHub: "automation_hub",
|
|
64
|
+
System: "system",
|
|
65
|
+
};
|
|
66
|
+
// ----- Task execution mode
|
|
67
|
+
exports.TaskModeEnum = {
|
|
68
|
+
Human: "human",
|
|
69
|
+
Auto: "auto",
|
|
70
|
+
};
|
|
71
|
+
// ----- AUTO task handler (which executor processes the task)
|
|
72
|
+
// Keep it open for future modules; these are logical handler identifiers.
|
|
73
|
+
exports.TaskAutoHandlerEnum = {
|
|
74
|
+
Notifications: "notifications",
|
|
75
|
+
AIAgent: "ai_agent",
|
|
76
|
+
Invoices: "invoices",
|
|
77
|
+
Webhook: "webhook",
|
|
78
|
+
Custom: "custom",
|
|
79
|
+
};
|
|
80
|
+
// ----- Retry policy
|
|
81
|
+
exports.TaskRetryStrategyEnum = {
|
|
82
|
+
Fixed: "fixed",
|
|
83
|
+
Exponential: "exponential",
|
|
84
|
+
};
|
|
85
|
+
// ----- Dedup / suppression (optional)
|
|
86
|
+
exports.TaskDedupScopeEnum = {
|
|
87
|
+
PerRecipient: "per_recipient",
|
|
88
|
+
PerRecipientAndObject: "per_recipient_and_object",
|
|
89
|
+
Custom: "custom",
|
|
90
|
+
};
|
|
91
|
+
exports.TaskDedupWindowEnum = {
|
|
92
|
+
SameDay: "same_day",
|
|
93
|
+
NHours: "n_hours",
|
|
94
|
+
Custom: "custom",
|
|
95
|
+
};
|
|
96
|
+
// ----- External object links (for unified UI views)
|
|
97
|
+
exports.TaskExternalObjectTypeEnum = {
|
|
98
|
+
CrmLead: "crm_lead",
|
|
99
|
+
MedPatient: "med_patient",
|
|
100
|
+
MedProfessional: "med_professional",
|
|
101
|
+
MedAppointment: "med_appointment",
|
|
102
|
+
ChatContact: "chat_contact",
|
|
103
|
+
};
|
|
104
|
+
// ----- Task execution attempts (sub-collection: tasks/{taskId}/executions)
|
|
105
|
+
exports.TaskExecutionStatusEnum = {
|
|
106
|
+
Success: "success",
|
|
107
|
+
Error: "error",
|
|
108
|
+
Retry: "retry",
|
|
109
|
+
};
|
|
@@ -1,145 +1,343 @@
|
|
|
1
1
|
export * from "./fb_collections";
|
|
2
2
|
import type { FirestoreDocumentReference, IFireDoc, ITag } from "../shared";
|
|
3
|
-
// ----- TaskTypes
|
|
4
|
-
|
|
5
|
-
// Enum for Task Action - used in Activities tracking
|
|
6
|
-
export type TaskAction = "CREATE_TASK" | "DELETE_TASK" | "UPDATE_TASK";
|
|
7
|
-
export enum ITaskAction {
|
|
8
|
-
Create_task = "CREATE_TASK",
|
|
9
|
-
Delete_task = "DELETE_TASK",
|
|
10
|
-
Update_task = "UPDATE_TASK",
|
|
11
|
-
}
|
|
12
3
|
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
// ======================================================
|
|
5
|
+
// evo-task (Tasks)
|
|
6
|
+
//
|
|
7
|
+
// Design goals:
|
|
8
|
+
// - Single, generic Task model used by humans and automation
|
|
9
|
+
// - AUTO tasks are executed by Task Runner (in evo-task-runner)
|
|
10
|
+
// - Payloads for specific handlers (notifications, AI, invoices, etc.)
|
|
11
|
+
// live in their own modules; here we keep the contract generic
|
|
12
|
+
// - Sub-collections (executions/comments/logs) keep lists fast
|
|
13
|
+
// ======================================================
|
|
14
|
+
|
|
15
|
+
// ----- Firestore collection conventions (per tenant)
|
|
16
|
+
// Root: /tenants/{tenant}/apps/evo-task/tasks/{taskId}
|
|
17
|
+
export const EvoTaskCollections = {
|
|
18
|
+
Tasks: "tasks",
|
|
19
|
+
Executions: "executions",
|
|
20
|
+
Comments: "comments",
|
|
21
|
+
Logs: "logs",
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
export type EvoTaskCollectionName =
|
|
25
|
+
(typeof EvoTaskCollections)[keyof typeof EvoTaskCollections];
|
|
26
|
+
|
|
27
|
+
// ----- Activities tracking
|
|
28
|
+
export const TaskActionEnum = {
|
|
29
|
+
CreateTask: "CREATE_TASK",
|
|
30
|
+
DeleteTask: "DELETE_TASK",
|
|
31
|
+
UpdateTask: "UPDATE_TASK",
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
export type TaskAction = (typeof TaskActionEnum)[keyof typeof TaskActionEnum];
|
|
35
|
+
|
|
36
|
+
// ----- Task lifecycle status
|
|
37
|
+
// Keep the human-friendly lifecycle states (legacy-friendly): not_started / in_progress.
|
|
38
|
+
export const TaskStatusEnum = {
|
|
39
|
+
NotStarted: "not_started",
|
|
40
|
+
InProgress: "in_progress",
|
|
41
|
+
Completed: "completed",
|
|
42
|
+
Failed: "failed", // final failure (after retries)
|
|
43
|
+
Cancelled: "cancelled",
|
|
44
|
+
OnHold: "on_hold",
|
|
45
|
+
Suppressed: "suppressed", // intentionally skipped (e.g., dedup)
|
|
46
|
+
} as const;
|
|
47
|
+
|
|
48
|
+
export type TaskStatus = (typeof TaskStatusEnum)[keyof typeof TaskStatusEnum];
|
|
49
|
+
|
|
50
|
+
// ----- Task priority (human-friendly)
|
|
51
|
+
export const TaskPriorityEnum = {
|
|
52
|
+
Low: "low",
|
|
53
|
+
Medium: "medium",
|
|
54
|
+
High: "high",
|
|
55
|
+
} as const;
|
|
56
|
+
|
|
57
|
+
export type TaskPriority =
|
|
58
|
+
(typeof TaskPriorityEnum)[keyof typeof TaskPriorityEnum];
|
|
59
|
+
|
|
60
|
+
// ----- Task source (who created it)
|
|
61
|
+
export const TaskSourceEnum = {
|
|
62
|
+
User: "user",
|
|
63
|
+
AutomationHub: "automation_hub",
|
|
64
|
+
System: "system",
|
|
65
|
+
} as const;
|
|
66
|
+
|
|
67
|
+
export type TaskSource = (typeof TaskSourceEnum)[keyof typeof TaskSourceEnum];
|
|
68
|
+
|
|
69
|
+
// ----- Task execution mode
|
|
70
|
+
export const TaskModeEnum = {
|
|
71
|
+
Human: "human",
|
|
72
|
+
Auto: "auto",
|
|
73
|
+
} as const;
|
|
74
|
+
|
|
75
|
+
export type TaskMode = (typeof TaskModeEnum)[keyof typeof TaskModeEnum];
|
|
76
|
+
|
|
77
|
+
// ----- AUTO task handler (which executor processes the task)
|
|
78
|
+
// Keep it open for future modules; these are logical handler identifiers.
|
|
79
|
+
export const TaskAutoHandlerEnum = {
|
|
80
|
+
Notifications: "notifications",
|
|
81
|
+
AIAgent: "ai_agent",
|
|
82
|
+
Invoices: "invoices",
|
|
83
|
+
Webhook: "webhook",
|
|
84
|
+
Custom: "custom",
|
|
85
|
+
} as const;
|
|
86
|
+
|
|
87
|
+
export type TaskAutoHandler =
|
|
88
|
+
(typeof TaskAutoHandlerEnum)[keyof typeof TaskAutoHandlerEnum];
|
|
89
|
+
|
|
90
|
+
// ----- Retry policy
|
|
91
|
+
export const TaskRetryStrategyEnum = {
|
|
92
|
+
Fixed: "fixed",
|
|
93
|
+
Exponential: "exponential",
|
|
94
|
+
} as const;
|
|
95
|
+
|
|
96
|
+
export type TaskRetryStrategy =
|
|
97
|
+
(typeof TaskRetryStrategyEnum)[keyof typeof TaskRetryStrategyEnum];
|
|
98
|
+
|
|
99
|
+
export interface ITaskRetryPolicy {
|
|
100
|
+
max_attempts: number; // total attempts allowed (including first attempt)
|
|
101
|
+
attempt: number; // 0-based attempt counter
|
|
102
|
+
strategy: TaskRetryStrategy;
|
|
103
|
+
backoff_seconds: number; // base backoff in seconds
|
|
104
|
+
next_attempt_at?: Date; // computed by Task Runner
|
|
105
|
+
last_error?: {
|
|
106
|
+
message: string;
|
|
107
|
+
code?: string | number;
|
|
108
|
+
at: Date;
|
|
109
|
+
details?: Record<string, unknown>;
|
|
110
|
+
};
|
|
111
|
+
[key: string]: unknown;
|
|
28
112
|
}
|
|
29
113
|
|
|
30
|
-
//
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
High = "high",
|
|
114
|
+
// ----- Lock/lease control (to avoid double execution)
|
|
115
|
+
export interface ITaskLock {
|
|
116
|
+
locked_by: string; // worker id / instance id
|
|
117
|
+
lock_until: Date; // lease expiration time
|
|
118
|
+
[key: string]: unknown;
|
|
36
119
|
}
|
|
37
120
|
|
|
38
|
-
//
|
|
39
|
-
export
|
|
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
|
-
SentimentAnalysis = "sentiment_analysis",
|
|
67
|
-
QuestionAnswering = "question_answering",
|
|
68
|
-
SendReminder = "send_reminder",
|
|
69
|
-
RequestContactInfo = "request_contact_info",
|
|
70
|
-
RequestOperatorInfo = "request_operator_info",
|
|
71
|
-
ConfirmAppointment = "confirm_appointment",
|
|
72
|
-
SendDocuments = "send_documents",
|
|
73
|
-
CreateAppointment = "create_appointment",
|
|
74
|
-
RescheduleAppointment = "reschedule_appointment",
|
|
75
|
-
CancelAppointment = "cancel_appointment",
|
|
76
|
-
FinancialCharge = "financial_charge",
|
|
77
|
-
Custom = "custom",
|
|
121
|
+
// ----- Dedup / suppression (optional)
|
|
122
|
+
export const TaskDedupScopeEnum = {
|
|
123
|
+
PerRecipient: "per_recipient",
|
|
124
|
+
PerRecipientAndObject: "per_recipient_and_object",
|
|
125
|
+
Custom: "custom",
|
|
126
|
+
} as const;
|
|
127
|
+
|
|
128
|
+
export type TaskDedupScope =
|
|
129
|
+
(typeof TaskDedupScopeEnum)[keyof typeof TaskDedupScopeEnum];
|
|
130
|
+
|
|
131
|
+
export const TaskDedupWindowEnum = {
|
|
132
|
+
SameDay: "same_day",
|
|
133
|
+
NHours: "n_hours",
|
|
134
|
+
Custom: "custom",
|
|
135
|
+
} as const;
|
|
136
|
+
|
|
137
|
+
export type TaskDedupWindow =
|
|
138
|
+
(typeof TaskDedupWindowEnum)[keyof typeof TaskDedupWindowEnum];
|
|
139
|
+
|
|
140
|
+
export interface ITaskDedup {
|
|
141
|
+
enabled: boolean;
|
|
142
|
+
key: string; // deterministic key used for suppression
|
|
143
|
+
group_key?: string; // e.g. "APPT_REMINDER"
|
|
144
|
+
scope?: TaskDedupScope;
|
|
145
|
+
window?: TaskDedupWindow;
|
|
146
|
+
window_hours?: number; // when window = n_hours
|
|
147
|
+
importance?: number; // numeric tie-breaker (0-100)
|
|
148
|
+
[key: string]: unknown;
|
|
78
149
|
}
|
|
79
150
|
|
|
80
|
-
//
|
|
151
|
+
// ----- External object links (for unified UI views)
|
|
152
|
+
export const TaskExternalObjectTypeEnum = {
|
|
153
|
+
CrmLead: "crm_lead",
|
|
154
|
+
MedPatient: "med_patient",
|
|
155
|
+
MedProfessional: "med_professional",
|
|
156
|
+
MedAppointment: "med_appointment",
|
|
157
|
+
ChatContact: "chat_contact",
|
|
158
|
+
} as const;
|
|
159
|
+
|
|
81
160
|
export type TaskExternalObjectType =
|
|
82
|
-
|
|
83
|
-
| "med_patient"
|
|
84
|
-
| "med_professional"
|
|
85
|
-
| "med_appointment"
|
|
86
|
-
| "chat_contact";
|
|
87
|
-
|
|
88
|
-
export enum ITaskExternalObjectType {
|
|
89
|
-
CrmLead = "crm_lead",
|
|
90
|
-
MedPatient = "med_patient",
|
|
91
|
-
MedProfessional = "med_professional",
|
|
92
|
-
MedAppointment = "med_appointment",
|
|
93
|
-
ChatContact = "chat_contact",
|
|
94
|
-
}
|
|
161
|
+
(typeof TaskExternalObjectTypeEnum)[keyof typeof TaskExternalObjectTypeEnum];
|
|
95
162
|
|
|
96
|
-
// Interface for External Object Link
|
|
97
163
|
export interface ITaskExternalLink {
|
|
98
|
-
type: TaskExternalObjectType;
|
|
99
|
-
id: string;
|
|
100
|
-
|
|
164
|
+
type: TaskExternalObjectType;
|
|
165
|
+
id: string;
|
|
166
|
+
label?: string;
|
|
167
|
+
[key: string]: unknown;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ----- Assignee (human)
|
|
171
|
+
export interface ITaskUserAssignee {
|
|
172
|
+
kind: "user";
|
|
173
|
+
name?: string;
|
|
174
|
+
ref?: FirestoreDocumentReference;
|
|
175
|
+
[key: string]: unknown;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ----- Common schedule fields
|
|
179
|
+
export interface ITaskSchedule {
|
|
180
|
+
execute_at?: Date; // when AUTO tasks should run (Task Runner uses this)
|
|
181
|
+
due_at?: Date; // optional deadline (also used for human tasks)
|
|
182
|
+
timezone?: string; // optional IANA timezone
|
|
183
|
+
[key: string]: unknown;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ----- AUTO execution contract (generic)
|
|
187
|
+
// The concrete payload schema for each handler/kind should live in its own module.
|
|
188
|
+
export interface ITaskAutoSpec {
|
|
189
|
+
handler: TaskAutoHandler;
|
|
190
|
+
kind: string; // e.g. "notification.send", "ai.execute", "invoice.issue"
|
|
191
|
+
version?: number | string;
|
|
192
|
+
payload: Record<string, unknown>;
|
|
193
|
+
idempotency_key?: string; // used by the handler to deduplicate provider calls
|
|
194
|
+
[key: string]: unknown;
|
|
101
195
|
}
|
|
102
196
|
|
|
103
|
-
//
|
|
104
|
-
export interface
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
197
|
+
// ----- Failure handling / handoff (generic)
|
|
198
|
+
export interface ITaskOnFailure {
|
|
199
|
+
// Task Runner can optionally create/convert into a HUMAN task.
|
|
200
|
+
handoff_to_user?: {
|
|
201
|
+
name?: string;
|
|
202
|
+
ref?: FirestoreDocumentReference;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
create_handoff_task?: {
|
|
206
|
+
title?: string;
|
|
207
|
+
description?: string;
|
|
208
|
+
priority?: TaskPriority;
|
|
209
|
+
tags?: ITag[] | null;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// Optional fallbacks the Task Runner may attempt (still AUTO).
|
|
213
|
+
auto_fallbacks?: Array<{
|
|
214
|
+
handler: TaskAutoHandler;
|
|
215
|
+
kind: string;
|
|
216
|
+
payload: Record<string, unknown>;
|
|
217
|
+
}>;
|
|
218
|
+
|
|
219
|
+
[key: string]: unknown;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ----- Base task shape
|
|
223
|
+
export interface ITaskBase extends IFireDoc {
|
|
224
|
+
title: string;
|
|
225
|
+
description?: string;
|
|
226
|
+
status: TaskStatus;
|
|
227
|
+
|
|
228
|
+
// Human-friendly priority + numeric tie-breaker (optional)
|
|
229
|
+
priority?: TaskPriority;
|
|
230
|
+
importance?: number; // 0-100 (recommended for automation tie-breakers)
|
|
231
|
+
|
|
232
|
+
// Who created it
|
|
233
|
+
source: TaskSource;
|
|
234
|
+
creator: {
|
|
235
|
+
name: string;
|
|
236
|
+
ref?: FirestoreDocumentReference;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// Scheduling / deadlines
|
|
240
|
+
schedule?: ITaskSchedule;
|
|
241
|
+
|
|
242
|
+
// Links and taxonomy
|
|
115
243
|
tags?: ITag[] | null;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
244
|
+
externalLinks?: ITaskExternalLink[];
|
|
245
|
+
|
|
246
|
+
// Optional deterministic key to avoid duplicates on rebuild/events
|
|
247
|
+
idempotency_key?: string;
|
|
248
|
+
|
|
249
|
+
// Optional dedup configuration
|
|
250
|
+
dedup?: ITaskDedup;
|
|
251
|
+
|
|
252
|
+
// Free metadata
|
|
253
|
+
metadata?: Record<string, unknown>;
|
|
254
|
+
|
|
255
|
+
[key: string]: unknown;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ----- HUMAN task
|
|
259
|
+
export interface IHumanTask extends ITaskBase {
|
|
260
|
+
mode: "human";
|
|
261
|
+
assignee?: ITaskUserAssignee;
|
|
134
262
|
}
|
|
135
263
|
|
|
136
|
-
//
|
|
264
|
+
// ----- AUTO task
|
|
265
|
+
export interface IAutoTask extends ITaskBase {
|
|
266
|
+
mode: "auto";
|
|
267
|
+
|
|
268
|
+
// Required for AUTO execution
|
|
269
|
+
schedule: ITaskSchedule & {
|
|
270
|
+
execute_at: Date;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// Execution control
|
|
274
|
+
lock?: ITaskLock;
|
|
275
|
+
retry?: ITaskRetryPolicy;
|
|
276
|
+
on_failure?: ITaskOnFailure;
|
|
277
|
+
|
|
278
|
+
// What to execute
|
|
279
|
+
auto: ITaskAutoSpec;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Union task type
|
|
283
|
+
export type ITask = IHumanTask | IAutoTask;
|
|
284
|
+
|
|
285
|
+
// ----- Task execution attempts (sub-collection: tasks/{taskId}/executions)
|
|
286
|
+
export const TaskExecutionStatusEnum = {
|
|
287
|
+
Success: "success",
|
|
288
|
+
Error: "error",
|
|
289
|
+
Retry: "retry",
|
|
290
|
+
} as const;
|
|
291
|
+
|
|
292
|
+
export type TaskExecutionStatus =
|
|
293
|
+
(typeof TaskExecutionStatusEnum)[keyof typeof TaskExecutionStatusEnum];
|
|
294
|
+
|
|
295
|
+
export interface ITaskExecution extends IFireDoc {
|
|
296
|
+
taskId: string;
|
|
297
|
+
handler: TaskAutoHandler;
|
|
298
|
+
kind: string; // mirrors task.auto.kind
|
|
299
|
+
status: TaskExecutionStatus;
|
|
300
|
+
attempt: number;
|
|
301
|
+
started_at: Date;
|
|
302
|
+
completed_at?: Date;
|
|
303
|
+
|
|
304
|
+
// Handler-specific outputs/errors (keep concise)
|
|
305
|
+
result?: Record<string, unknown>;
|
|
306
|
+
error?: {
|
|
307
|
+
message: string;
|
|
308
|
+
code?: string | number;
|
|
309
|
+
details?: Record<string, unknown>;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// Optional provider metadata (e.g. WhatsApp provider message id)
|
|
313
|
+
provider?: {
|
|
314
|
+
name?: string;
|
|
315
|
+
message_id?: string;
|
|
316
|
+
[key: string]: unknown;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
[key: string]: unknown;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ----- Task comments (sub-collection: tasks/{taskId}/comments)
|
|
137
323
|
export interface ITaskComment extends IFireDoc {
|
|
138
|
-
taskId: string;
|
|
139
|
-
text: string;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
324
|
+
taskId: string;
|
|
325
|
+
text: string;
|
|
326
|
+
author: {
|
|
327
|
+
name: string;
|
|
328
|
+
ref?: FirestoreDocumentReference;
|
|
329
|
+
};
|
|
330
|
+
edited?: boolean;
|
|
331
|
+
edited_at?: Date;
|
|
332
|
+
[key: string]: unknown;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ----- Task logs (optional sub-collection: tasks/{taskId}/logs)
|
|
336
|
+
export interface ITaskLog extends IFireDoc {
|
|
337
|
+
taskId: string;
|
|
338
|
+
level: "debug" | "info" | "warn" | "error";
|
|
339
|
+
message: string;
|
|
340
|
+
data?: Record<string, unknown>;
|
|
341
|
+
at: Date;
|
|
342
|
+
[key: string]: unknown;
|
|
145
343
|
}
|