evo360-types 1.3.141 → 1.3.144

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,141 @@
1
+ import type { IFireDoc } from "../shared";
2
+ import type {
3
+ TaskAutoHandler,
4
+ TaskExecutionStatus,
5
+ TaskRetryStrategy,
6
+ } from "../evo-task";
7
+
8
+ // ======================================================
9
+ // evo-task-runner (Task Runner)
10
+ //
11
+ // This module defines the contracts used by the Task Runner to:
12
+ // - pick due AUTO tasks
13
+ // - dispatch execution requests to handler executors (notifications, ai_agent, ...)
14
+ // - receive async execution reports
15
+ //
16
+ // NOTE:
17
+ // - Task payload schemas live in their respective modules.
18
+ // - This contract is handler-agnostic and safe to share between backend/frontend.
19
+ // ======================================================
20
+
21
+ // ----- Pub/Sub topic suggestions (logical names)
22
+ export const TaskRunnerTopics = {
23
+ Tick: "task_runner.tick",
24
+ ExecuteRequests: "task_runner.execute_requests",
25
+ ExecutionReports: "task_runner.execution_reports",
26
+ } as const;
27
+
28
+ export type TaskRunnerTopic =
29
+ (typeof TaskRunnerTopics)[keyof typeof TaskRunnerTopics];
30
+
31
+ // ----- Runner tick messages (optional)
32
+ export const TaskRunnerTickReasonEnum = {
33
+ Schedule: "schedule",
34
+ Manual: "manual",
35
+ Recovery: "recovery",
36
+ } as const;
37
+
38
+ export type TaskRunnerTickReason =
39
+ (typeof TaskRunnerTickReasonEnum)[keyof typeof TaskRunnerTickReasonEnum];
40
+
41
+ export interface ITaskRunnerTick {
42
+ tenant: string;
43
+ reason: TaskRunnerTickReason;
44
+ requested_at: Date;
45
+ // Useful for batch processing controls
46
+ max_to_claim?: number;
47
+ look_ahead_seconds?: number; // if you want to include "execute_at <= now + lookahead"
48
+ [key: string]: unknown;
49
+ }
50
+
51
+ // ----- Execution request (Runner -> Handler Executor)
52
+ // This message must be idempotent and safe to deliver at-least-once.
53
+ export interface ITaskExecuteRequest {
54
+ tenant: string;
55
+
56
+ // Task identity
57
+ task_id: string;
58
+ task_path?: string; // optional Firestore path for convenience
59
+
60
+ // What to execute
61
+ handler: TaskAutoHandler;
62
+ kind: string; // mirrors task.auto.kind
63
+ version?: number | string; // mirrors task.auto.version
64
+
65
+ // Attempting/Idempotency
66
+ attempt: number; // 0-based attempt
67
+ idempotency_key?: string; // should be stable for "same attempt" dispatch
68
+
69
+ // Payload (handler-specific)
70
+ payload: Record<string, unknown>;
71
+
72
+ // Correlation / tracing
73
+ correlation_id?: string;
74
+ requested_at: Date;
75
+
76
+ // Optional execution constraints
77
+ timeout_ms?: number;
78
+ [key: string]: unknown;
79
+ }
80
+
81
+ // ----- Execution report (Handler Executor -> Runner)
82
+ // Handler executors should emit a report for every request (success/failure).
83
+ export interface ITaskExecutionReport {
84
+ tenant: string;
85
+
86
+ // Task identity
87
+ task_id: string;
88
+
89
+ // Execution identity
90
+ handler: TaskAutoHandler;
91
+ kind: string;
92
+ attempt: number;
93
+ correlation_id?: string;
94
+
95
+ // Status/result
96
+ status: TaskExecutionStatus; // success | error | retry
97
+
98
+ started_at: Date;
99
+ completed_at: Date;
100
+
101
+ // Retry hints (Runner remains the source of truth)
102
+ suggested_retry?: {
103
+ // If handler believes the error is retryable, it can suggest.
104
+ // Runner may override based on task.retry policy.
105
+ retryable: boolean;
106
+ code?: string | number;
107
+ message?: string;
108
+ next_attempt_at?: Date;
109
+ strategy?: TaskRetryStrategy;
110
+ backoff_seconds?: number;
111
+ [key: string]: unknown;
112
+ };
113
+
114
+ // Handler-specific result data
115
+ result?: Record<string, unknown>;
116
+
117
+ // Error data (when status is error/retry)
118
+ error?: {
119
+ message: string;
120
+ code?: string | number;
121
+ details?: Record<string, unknown>;
122
+ };
123
+
124
+ // Optional provider metadata (e.g. WhatsApp provider message id)
125
+ provider?: {
126
+ name?: string;
127
+ message_id?: string;
128
+ [key: string]: unknown;
129
+ };
130
+
131
+ [key: string]: unknown;
132
+ }
133
+
134
+ // ----- Optional: runner audit doc (if you want a central collection for runner events)
135
+ export interface ITaskRunnerEvent extends IFireDoc {
136
+ tenant: string;
137
+ type: "tick" | "dispatch" | "report";
138
+ at: Date;
139
+ data?: Record<string, unknown>;
140
+ [key: string]: unknown;
141
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evo360-types",
3
- "version": "1.3.141",
3
+ "version": "1.3.144",
4
4
  "description": "HREVO360 Shared Types",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",