dp-worker 0.1.1 → 0.1.3
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/agent/agent.d.ts +6 -13
- package/dist/agent/agent.js +9 -19
- package/dist/agent/agent.js.map +1 -1
- package/dist/browser/chrome-process.d.ts +3 -0
- package/dist/browser/chrome-process.js +174 -25
- package/dist/browser/chrome-process.js.map +1 -1
- package/dist/browser/manager.d.ts +4 -4
- package/dist/browser/manager.js +94 -44
- package/dist/browser/manager.js.map +1 -1
- package/dist/center/session-sync.d.ts +16 -77
- package/dist/center/session-sync.js +62 -302
- package/dist/center/session-sync.js.map +1 -1
- package/dist/chrome-extension/omni-flow/background.js +561 -0
- package/dist/chrome-extension/omni-flow/content.js +29 -0
- package/dist/chrome-extension/omni-flow/icon.png +0 -0
- package/dist/chrome-extension/omni-flow/inject.js +173 -0
- package/dist/chrome-extension/omni-flow/manifest.json +44 -0
- package/dist/chrome-extension/omni-flow/popup.css +819 -0
- package/dist/chrome-extension/omni-flow/popup.html +284 -0
- package/dist/chrome-extension/omni-flow/popup.js +1021 -0
- package/dist/chrome-extension/omni-flow/usage_guide.md +139 -0
- package/dist/index.js +15 -45
- package/dist/index.js.map +1 -1
- package/node_modules/dp-shared/dist/domain.d.ts +4 -4
- package/node_modules/dp-shared/dist/domain.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/domain.js +4 -4
- package/node_modules/dp-shared/dist/domain.js.map +1 -1
- package/node_modules/dp-shared/dist/identities.d.ts +22 -0
- package/node_modules/dp-shared/dist/identities.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/identities.js +3 -0
- package/node_modules/dp-shared/dist/identities.js.map +1 -1
- package/node_modules/dp-shared/dist/index.d.ts +1 -0
- package/node_modules/dp-shared/dist/index.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/index.js +1 -0
- package/node_modules/dp-shared/dist/index.js.map +1 -1
- package/node_modules/dp-shared/dist/omni-flow-session.d.ts +85 -0
- package/node_modules/dp-shared/dist/omni-flow-session.d.ts.map +1 -0
- package/node_modules/dp-shared/dist/omni-flow-session.js +59 -0
- package/node_modules/dp-shared/dist/omni-flow-session.js.map +1 -0
- package/node_modules/dp-shared/dist/rest-contracts.d.ts +12 -1
- package/node_modules/dp-shared/dist/rest-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/rest-contracts.js +5 -3
- package/node_modules/dp-shared/dist/rest-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/ws-protocol.d.ts +4 -4
- package/node_modules/dp-shared/src/admin-broadcast.ts +38 -0
- package/node_modules/dp-shared/src/audit-contracts.ts +33 -0
- package/node_modules/dp-shared/src/configs-contracts.ts +206 -0
- package/node_modules/dp-shared/src/db-rows.ts +280 -0
- package/node_modules/dp-shared/src/deploy-contracts.ts +38 -0
- package/node_modules/dp-shared/src/domain.ts +124 -0
- package/node_modules/dp-shared/src/identities.ts +36 -0
- package/node_modules/dp-shared/src/index.ts +25 -0
- package/node_modules/dp-shared/src/omni-flow-session.ts +80 -0
- package/node_modules/dp-shared/src/rest-contracts.ts +409 -0
- package/node_modules/dp-shared/src/task-history-contracts.ts +115 -0
- package/node_modules/dp-shared/src/worker-detail-contracts.ts +230 -0
- package/node_modules/dp-shared/src/ws-protocol.ts +435 -0
- package/package.json +2 -4
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import {
|
|
3
|
+
ProcessStatus,
|
|
4
|
+
RuntimeStatus,
|
|
5
|
+
ChatScopeType,
|
|
6
|
+
ConfigEtag,
|
|
7
|
+
ContentHash,
|
|
8
|
+
DpWorkerRuntimeMode,
|
|
9
|
+
DpWorkerUpgradeStatus,
|
|
10
|
+
IanaTimezone,
|
|
11
|
+
LlmProtocol,
|
|
12
|
+
ProxyProtocol,
|
|
13
|
+
SocialPlatform,
|
|
14
|
+
TaskRunStatus,
|
|
15
|
+
TaskSource,
|
|
16
|
+
UserRole,
|
|
17
|
+
Uuid,
|
|
18
|
+
} from "./domain.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Database row schemas — mirror the Postgres tables described in
|
|
22
|
+
* docs/architecture.md §Data model. These are the canonical TypeScript shapes
|
|
23
|
+
* that DAL code (Workers `src/lib/db.ts`) returns; do not hand-roll row types
|
|
24
|
+
* elsewhere.
|
|
25
|
+
*
|
|
26
|
+
* All timestamps are ISO-8601 strings here (postgres.js returns Date but we
|
|
27
|
+
* normalize at the DAL boundary). Nullable columns are modelled with .optional().
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const Timestamps = {
|
|
31
|
+
created_at: z.string().datetime(),
|
|
32
|
+
updated_at: z.string().datetime(),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const TenantRow = z.object({
|
|
36
|
+
id: Uuid,
|
|
37
|
+
name: z.string().min(1),
|
|
38
|
+
...Timestamps,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const UserRow = z.object({
|
|
42
|
+
id: Uuid,
|
|
43
|
+
email: z.string().email(),
|
|
44
|
+
role: UserRole,
|
|
45
|
+
...Timestamps,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const ProxyRow = z.object({
|
|
49
|
+
id: Uuid,
|
|
50
|
+
label: z.string().min(1),
|
|
51
|
+
protocol: ProxyProtocol,
|
|
52
|
+
host: z.string().min(1),
|
|
53
|
+
port: z.number().int().positive(),
|
|
54
|
+
username: z.string().min(1),
|
|
55
|
+
password: z.string().min(1),
|
|
56
|
+
/** IANA timezone of the proxy egress. Required since v2.1 of the plan. */
|
|
57
|
+
timezone: IanaTimezone,
|
|
58
|
+
note: z.string().optional(),
|
|
59
|
+
in_use_by_worker_id: Uuid.optional(),
|
|
60
|
+
...Timestamps,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export const LlmProfileRow = z.object({
|
|
64
|
+
id: Uuid,
|
|
65
|
+
name: z.string().min(1),
|
|
66
|
+
protocol: LlmProtocol,
|
|
67
|
+
base_url: z.string().min(1),
|
|
68
|
+
api_key: z.string().min(1),
|
|
69
|
+
model: z.string().min(1),
|
|
70
|
+
image_model: z.string().optional(),
|
|
71
|
+
image_api_key: z.string().optional(),
|
|
72
|
+
image_size: z.string().optional(),
|
|
73
|
+
...Timestamps,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const DirectorRow = z.object({
|
|
77
|
+
id: Uuid,
|
|
78
|
+
name: z.string().min(1),
|
|
79
|
+
api_key: z.string().min(1),
|
|
80
|
+
host_label: z.string().min(1),
|
|
81
|
+
max_concurrent_tasks: z.number().int().nonnegative().default(0),
|
|
82
|
+
last_heartbeat_at: z.string().datetime().optional(),
|
|
83
|
+
version: z.string().optional(),
|
|
84
|
+
dp_worker_version: z.string().optional(),
|
|
85
|
+
dp_worker_latest_version: z.string().optional(),
|
|
86
|
+
dp_worker_runtime_mode: DpWorkerRuntimeMode.optional(),
|
|
87
|
+
dp_worker_upgrade_status: DpWorkerUpgradeStatus.optional(),
|
|
88
|
+
dp_worker_upgrade_message: z.string().optional(),
|
|
89
|
+
dp_worker_upgrade_started_at: z.string().datetime().optional(),
|
|
90
|
+
dp_worker_upgrade_finished_at: z.string().datetime().optional(),
|
|
91
|
+
...Timestamps,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export const WorkerRow = z.object({
|
|
95
|
+
id: Uuid,
|
|
96
|
+
name: z.string().min(1),
|
|
97
|
+
director_id: Uuid.optional(),
|
|
98
|
+
api_key: z.string().min(1),
|
|
99
|
+
llm_profile_id: Uuid,
|
|
100
|
+
proxy_id: Uuid.optional(),
|
|
101
|
+
/**
|
|
102
|
+
* Per-dp-worker Chrome headless flag (M6). Defaults to false at the schema
|
|
103
|
+
* level; operators flip it via Web UI.
|
|
104
|
+
*/
|
|
105
|
+
headless: z.boolean().default(false),
|
|
106
|
+
identity_id: Uuid.nullable().optional(),
|
|
107
|
+
process_status: ProcessStatus,
|
|
108
|
+
process_observed_at: z.string().datetime().optional(),
|
|
109
|
+
runtime_status: RuntimeStatus,
|
|
110
|
+
runtime_observed_at: z.string().datetime().optional(),
|
|
111
|
+
last_heartbeat_at: z.string().datetime().optional(),
|
|
112
|
+
current_task_id: Uuid.optional(),
|
|
113
|
+
config_etag: ConfigEtag,
|
|
114
|
+
session_content_hash: ContentHash.optional(),
|
|
115
|
+
telegram_bot_token: z.string().optional(),
|
|
116
|
+
telegram_allowed_users: z.array(z.number().int()).optional(),
|
|
117
|
+
...Timestamps,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
export const SocialAccountRow = z.object({
|
|
121
|
+
id: Uuid,
|
|
122
|
+
identity_id: Uuid,
|
|
123
|
+
platform: SocialPlatform,
|
|
124
|
+
profile_name: z.string().default(""),
|
|
125
|
+
login_type: z.enum(["password", "oauth"]).default("password"),
|
|
126
|
+
username: z.string().nullable(),
|
|
127
|
+
email: z.string().nullable(),
|
|
128
|
+
password: z.string().nullable(),
|
|
129
|
+
/** NULL = inherit identity.persona_text; non-null = own persona. */
|
|
130
|
+
persona_text: z.string().nullable(),
|
|
131
|
+
persona_other_json: z.record(z.string(), z.unknown()).optional(),
|
|
132
|
+
enabled: z.boolean().default(true),
|
|
133
|
+
...Timestamps,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export const WorkerGroupRow = z.object({
|
|
137
|
+
id: Uuid,
|
|
138
|
+
name: z.string().min(1),
|
|
139
|
+
description: z.string().optional(),
|
|
140
|
+
...Timestamps,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
export const WorkerGroupMemberRow = z.object({
|
|
144
|
+
group_id: Uuid,
|
|
145
|
+
worker_id: Uuid,
|
|
146
|
+
added_at: z.string().datetime(),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
export const ChromeSessionRow = z.object({
|
|
150
|
+
id: Uuid,
|
|
151
|
+
identity_id: Uuid,
|
|
152
|
+
r2_object_key: z.string().min(1),
|
|
153
|
+
content_hash: ContentHash,
|
|
154
|
+
size_bytes: z.number().int().positive(),
|
|
155
|
+
uploaded_by: Uuid,
|
|
156
|
+
uploaded_at: z.string().datetime(),
|
|
157
|
+
note: z.string().optional(),
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
export const ScheduledTaskRow = z.object({
|
|
161
|
+
id: Uuid,
|
|
162
|
+
worker_id: Uuid,
|
|
163
|
+
name: z.string().min(1),
|
|
164
|
+
cron: z.string().min(1),
|
|
165
|
+
timezone: z.string().optional(),
|
|
166
|
+
prompt: z.string().min(1),
|
|
167
|
+
random_delay_seconds: z.number().int().nonnegative().default(0),
|
|
168
|
+
enabled: z.boolean(),
|
|
169
|
+
last_run_at: z.string().datetime().optional(),
|
|
170
|
+
last_status: z.enum(["ok", "error"]).optional(),
|
|
171
|
+
run_count: z.number().int().nonnegative().default(0),
|
|
172
|
+
success_count: z.number().int().nonnegative().default(0),
|
|
173
|
+
created_by: Uuid.optional(),
|
|
174
|
+
...Timestamps,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export const TaskRunRow = z.object({
|
|
178
|
+
id: Uuid,
|
|
179
|
+
worker_id: Uuid,
|
|
180
|
+
scheduled_task_id: Uuid.optional(),
|
|
181
|
+
source: TaskSource,
|
|
182
|
+
prompt: z.string().min(1),
|
|
183
|
+
target_descriptor_json: z.record(z.string(), z.unknown()).optional(),
|
|
184
|
+
status: TaskRunStatus,
|
|
185
|
+
dispatched_at: z.string().datetime().optional(),
|
|
186
|
+
started_at: z.string().datetime().optional(),
|
|
187
|
+
finished_at: z.string().datetime().optional(),
|
|
188
|
+
result_summary: z.string().optional(),
|
|
189
|
+
error: z.string().optional(),
|
|
190
|
+
randomized_delay_ms: z.number().int().nonnegative().default(0),
|
|
191
|
+
created_by: Uuid.optional(),
|
|
192
|
+
parent_adhoc_task_id: Uuid.optional(),
|
|
193
|
+
...Timestamps,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
export const AdhocTaskBatchRow = z.object({
|
|
197
|
+
id: Uuid,
|
|
198
|
+
name: z.string().min(1),
|
|
199
|
+
prompt: z.string().min(1),
|
|
200
|
+
target_descriptor_json: z.record(z.string(), z.unknown()),
|
|
201
|
+
random_delay_seconds: z.number().int().nonnegative().default(0),
|
|
202
|
+
dispatch_window_seconds: z.number().int().nonnegative().default(0),
|
|
203
|
+
created_by: Uuid.optional(),
|
|
204
|
+
created_at: z.string().datetime(),
|
|
205
|
+
summary_stats_json: z.record(z.string(), z.unknown()).optional(),
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
export const TaskDispatchQueueRow = z.object({
|
|
209
|
+
id: Uuid,
|
|
210
|
+
worker_id: Uuid,
|
|
211
|
+
task_run_id: Uuid,
|
|
212
|
+
eta: z.string().datetime(),
|
|
213
|
+
priority: z.number().int().default(0),
|
|
214
|
+
attempts: z.number().int().nonnegative().default(0),
|
|
215
|
+
...Timestamps,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
export const ChatRow = z.object({
|
|
219
|
+
id: Uuid,
|
|
220
|
+
scope_type: ChatScopeType,
|
|
221
|
+
scope_id: Uuid,
|
|
222
|
+
last_message_at: z.string().datetime().optional(),
|
|
223
|
+
...Timestamps,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
export const ChatMessageRow = z.object({
|
|
227
|
+
id: Uuid,
|
|
228
|
+
chat_id: Uuid,
|
|
229
|
+
role: z.string().min(1),
|
|
230
|
+
content_json: z.unknown(),
|
|
231
|
+
attachment_ids: z.array(Uuid).default([]),
|
|
232
|
+
task_run_id: Uuid.optional(),
|
|
233
|
+
sender_user_id: Uuid.optional(),
|
|
234
|
+
created_at: z.string().datetime(),
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
export const AttachmentRow = z.object({
|
|
238
|
+
id: Uuid,
|
|
239
|
+
chat_id: Uuid.optional(),
|
|
240
|
+
r2_object_key: z.string().min(1),
|
|
241
|
+
filename: z.string().min(1),
|
|
242
|
+
mime: z.string().optional(),
|
|
243
|
+
size: z.number().int().positive(),
|
|
244
|
+
uploaded_by: Uuid,
|
|
245
|
+
created_at: z.string().datetime(),
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
export const AuditLogRow = z.object({
|
|
249
|
+
id: Uuid,
|
|
250
|
+
actor_user_id: Uuid.optional(),
|
|
251
|
+
actor_machine_id: Uuid.optional(),
|
|
252
|
+
action: z.string().min(1),
|
|
253
|
+
target_type: z.string().min(1),
|
|
254
|
+
target_id: z.string().min(1),
|
|
255
|
+
payload_json: z.record(z.string(), z.unknown()).optional(),
|
|
256
|
+
created_at: z.string().datetime(),
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
/* ============================================================================
|
|
260
|
+
* Inferred row types — what DAL functions return.
|
|
261
|
+
* ============================================================================ */
|
|
262
|
+
|
|
263
|
+
export type TenantRow = z.infer<typeof TenantRow>;
|
|
264
|
+
export type UserRow = z.infer<typeof UserRow>;
|
|
265
|
+
export type ProxyRow = z.infer<typeof ProxyRow>;
|
|
266
|
+
export type LlmProfileRow = z.infer<typeof LlmProfileRow>;
|
|
267
|
+
export type DirectorRow = z.infer<typeof DirectorRow>;
|
|
268
|
+
export type WorkerRow = z.infer<typeof WorkerRow>;
|
|
269
|
+
export type SocialAccountRow = z.infer<typeof SocialAccountRow>;
|
|
270
|
+
export type WorkerGroupRow = z.infer<typeof WorkerGroupRow>;
|
|
271
|
+
export type WorkerGroupMemberRow = z.infer<typeof WorkerGroupMemberRow>;
|
|
272
|
+
export type ChromeSessionRow = z.infer<typeof ChromeSessionRow>;
|
|
273
|
+
export type ScheduledTaskRow = z.infer<typeof ScheduledTaskRow>;
|
|
274
|
+
export type TaskRunRow = z.infer<typeof TaskRunRow>;
|
|
275
|
+
export type AdhocTaskBatchRow = z.infer<typeof AdhocTaskBatchRow>;
|
|
276
|
+
export type TaskDispatchQueueRow = z.infer<typeof TaskDispatchQueueRow>;
|
|
277
|
+
export type ChatRow = z.infer<typeof ChatRow>;
|
|
278
|
+
export type ChatMessageRow = z.infer<typeof ChatMessageRow>;
|
|
279
|
+
export type AttachmentRow = z.infer<typeof AttachmentRow>;
|
|
280
|
+
export type AuditLogRow = z.infer<typeof AuditLogRow>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { Uuid } from "./domain.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* dp-worker lifecycle deploy / restart / stop contracts (M-X wave 2 Agent A).
|
|
6
|
+
*
|
|
7
|
+
* The UI button hits dp-center-worker; dp-center-worker RPCs the DirectorConnection DO,
|
|
8
|
+
* which forwards a `spawn_worker` / `restart_worker` / `stop_worker` envelope
|
|
9
|
+
* (defined in ws-protocol.ts) over the hibernating WS to the dp-director. The
|
|
10
|
+
* dp-director's `worker_state_change` flows back asynchronously — the REST call
|
|
11
|
+
* just confirms the envelope was queued for delivery.
|
|
12
|
+
*
|
|
13
|
+
* Request bodies are intentionally thin: the WS envelope is assembled
|
|
14
|
+
* server-side from the dp-worker row (api_key, director_id, …) so callers never
|
|
15
|
+
* see the api_key in the wire path.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** No body. The deploy envelope is constructed entirely server-side. */
|
|
19
|
+
export const DeployRequestSchema = z.object({});
|
|
20
|
+
export type DeployRequest = z.infer<typeof DeployRequestSchema>;
|
|
21
|
+
|
|
22
|
+
/** Same shape used by all three lifecycle endpoints on the 202 path. */
|
|
23
|
+
export const DeployResponseSchema = z.object({
|
|
24
|
+
accepted: z.literal(true),
|
|
25
|
+
envelope_id: Uuid,
|
|
26
|
+
director_id: Uuid,
|
|
27
|
+
});
|
|
28
|
+
export type DeployResponse = z.infer<typeof DeployResponseSchema>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Optional `graceful` flag on stop. When `false` the dp-director SIGKILLs instead
|
|
32
|
+
* of giving the dp-worker process its normal SIGTERM grace window. Defaults to
|
|
33
|
+
* true (graceful) when the body is omitted.
|
|
34
|
+
*/
|
|
35
|
+
export const StopRequestSchema = z.object({
|
|
36
|
+
graceful: z.boolean().optional(),
|
|
37
|
+
});
|
|
38
|
+
export type StopRequest = z.infer<typeof StopRequestSchema>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cross-tier primitives — identity, status enums, opaque IDs.
|
|
5
|
+
*
|
|
6
|
+
* Anything that appears in WS messages, REST bodies, AND DB rows lives here so
|
|
7
|
+
* the three contract files don't drift from each other.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const Uuid = z.string().uuid();
|
|
11
|
+
export type Uuid = z.infer<typeof Uuid>;
|
|
12
|
+
|
|
13
|
+
/** Short opaque ID like the existing src/agent/scheduler.ts uses (8 hex chars). */
|
|
14
|
+
export const ShortId = z.string().regex(/^[a-z0-9-]{6,32}$/);
|
|
15
|
+
export type ShortId = z.infer<typeof ShortId>;
|
|
16
|
+
|
|
17
|
+
/** Identifier used by Agent.registerFrontend in dp-worker (see §dp-worker-A in architecture.md). */
|
|
18
|
+
export const FrontendId = z.enum(["telegram", "center", "tui", "legacy"]);
|
|
19
|
+
export type FrontendId = z.infer<typeof FrontendId>;
|
|
20
|
+
|
|
21
|
+
export const LlmProtocol = z.enum(["openai", "claude"]);
|
|
22
|
+
export type LlmProtocol = z.infer<typeof LlmProtocol>;
|
|
23
|
+
|
|
24
|
+
export const ProxyProtocol = z.enum(["socks5", "socks4", "http", "https"]);
|
|
25
|
+
export type ProxyProtocol = z.infer<typeof ProxyProtocol>;
|
|
26
|
+
|
|
27
|
+
export const SocialPlatform = z.enum(["x", "youtube", "reddit", "instagram", "tiktok"]);
|
|
28
|
+
export type SocialPlatform = z.infer<typeof SocialPlatform>;
|
|
29
|
+
|
|
30
|
+
/** Process-axis status — written exclusively by dp-director (via PM events / heartbeat). */
|
|
31
|
+
export const ProcessStatus = z.enum(["running", "stopped", "crashed", "unknown"]);
|
|
32
|
+
export type ProcessStatus = z.infer<typeof ProcessStatus>;
|
|
33
|
+
|
|
34
|
+
/** Runtime/business-axis status — written exclusively by dp-worker (status_change). */
|
|
35
|
+
export const RuntimeStatus = z.enum(["idle", "busy", "error", "unknown"]);
|
|
36
|
+
export type RuntimeStatus = z.infer<typeof RuntimeStatus>;
|
|
37
|
+
|
|
38
|
+
/** Read-time derived status surfaced by the API; never stored. */
|
|
39
|
+
export const EffectiveWorkerStatus = z.enum([
|
|
40
|
+
"offline", "crashed", "error", "busy", "idle", "unknown",
|
|
41
|
+
]);
|
|
42
|
+
export type EffectiveWorkerStatus = z.infer<typeof EffectiveWorkerStatus>;
|
|
43
|
+
|
|
44
|
+
export const EffectiveDirectorStatus = z.enum(["online", "offline"]);
|
|
45
|
+
export type EffectiveDirectorStatus = z.infer<typeof EffectiveDirectorStatus>;
|
|
46
|
+
|
|
47
|
+
export const DpWorkerRuntimeMode = z.enum(["npm", "dev-dist"]);
|
|
48
|
+
export type DpWorkerRuntimeMode = z.infer<typeof DpWorkerRuntimeMode>;
|
|
49
|
+
|
|
50
|
+
export const DpWorkerUpgradeStatus = z.enum([
|
|
51
|
+
"idle",
|
|
52
|
+
"checking",
|
|
53
|
+
"installing",
|
|
54
|
+
"building",
|
|
55
|
+
"restarting",
|
|
56
|
+
"success",
|
|
57
|
+
"skipped",
|
|
58
|
+
"failed",
|
|
59
|
+
]);
|
|
60
|
+
export type DpWorkerUpgradeStatus = z.infer<typeof DpWorkerUpgradeStatus>;
|
|
61
|
+
|
|
62
|
+
export const TaskSource = z.enum(["scheduled", "ad_hoc", "chat_replay"]);
|
|
63
|
+
export type TaskSource = z.infer<typeof TaskSource>;
|
|
64
|
+
|
|
65
|
+
export const TaskRunStatus = z.enum([
|
|
66
|
+
"queued",
|
|
67
|
+
"dispatched",
|
|
68
|
+
"running",
|
|
69
|
+
"success",
|
|
70
|
+
"failed",
|
|
71
|
+
"cancelled",
|
|
72
|
+
"timeout",
|
|
73
|
+
]);
|
|
74
|
+
export type TaskRunStatus = z.infer<typeof TaskRunStatus>;
|
|
75
|
+
|
|
76
|
+
export const UserRole = z.enum(["admin", "operator", "viewer"]);
|
|
77
|
+
export type UserRole = z.infer<typeof UserRole>;
|
|
78
|
+
|
|
79
|
+
export const ChatScopeType = z.enum(["worker", "group"]);
|
|
80
|
+
export type ChatScopeType = z.infer<typeof ChatScopeType>;
|
|
81
|
+
|
|
82
|
+
export const ChatMessageRole = z.enum(["user", "assistant", "system", "tool"]);
|
|
83
|
+
export type ChatMessageRole = z.infer<typeof ChatMessageRole>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Opaque etag — dp-worker caches the latest etag locally; center bumps it whenever any
|
|
87
|
+
* field a dp-worker would care about changes. dp-worker compares against its cached value
|
|
88
|
+
* to decide whether to re-bootstrap.
|
|
89
|
+
*/
|
|
90
|
+
export const ConfigEtag = z.string().min(1);
|
|
91
|
+
export type ConfigEtag = z.infer<typeof ConfigEtag>;
|
|
92
|
+
|
|
93
|
+
/** Hex-encoded SHA-256 of the canonical session artifact; 64 chars. */
|
|
94
|
+
export const ContentHash = z.string().regex(/^[a-f0-9]{64}$/);
|
|
95
|
+
export type ContentHash = z.infer<typeof ContentHash>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* An IANA-zone name string (e.g. "America/New_York", "Asia/Tokyo", "UTC").
|
|
99
|
+
* Validated via the runtime `Intl.DateTimeFormat` constructor, which is
|
|
100
|
+
* available in every target runtime: Node, browsers, and Cloudflare Workers
|
|
101
|
+
* (V8 isolate). Invalid zone names throw RangeError on construction.
|
|
102
|
+
*
|
|
103
|
+
* Proxies carry one of these; a dp-worker bound to a proxy uses it as the
|
|
104
|
+
* default cron timezone, while Chrome timezone spoofing is handled inside
|
|
105
|
+
* the OmniFlow extension session imported into that browser profile.
|
|
106
|
+
*/
|
|
107
|
+
export const IanaTimezone = z
|
|
108
|
+
.string()
|
|
109
|
+
.min(1)
|
|
110
|
+
.refine(
|
|
111
|
+
(tz) => {
|
|
112
|
+
try {
|
|
113
|
+
new Intl.DateTimeFormat(undefined, { timeZone: tz });
|
|
114
|
+
return true;
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
message:
|
|
121
|
+
"must be a valid IANA timezone name (e.g. 'America/New_York', 'Asia/Tokyo', 'UTC')",
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
export type IanaTimezone = z.infer<typeof IanaTimezone>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { Uuid } from "./domain.js";
|
|
3
|
+
import { OmniFlowSessionSummarySchema } from "./omni-flow-session.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Identity == a Chrome persona owned by the org. Holds the primary
|
|
7
|
+
* email/password the dp-worker uses for Gmail / Google flows, plus an
|
|
8
|
+
* optional egress proxy. Per-platform sub-accounts (X / YouTube / Reddit)
|
|
9
|
+
* live in the `social_accounts` table and inherit `persona_text` by default.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const IdentityRow = z.object({
|
|
13
|
+
id: Uuid,
|
|
14
|
+
name: z.string(),
|
|
15
|
+
email: z.string().email(),
|
|
16
|
+
password: z.string().nullable(),
|
|
17
|
+
proxy_id: Uuid.nullable(),
|
|
18
|
+
persona_text: z.string(),
|
|
19
|
+
created_at: z.string().datetime(),
|
|
20
|
+
updated_at: z.string().datetime(),
|
|
21
|
+
});
|
|
22
|
+
export type IdentityRow = z.infer<typeof IdentityRow>;
|
|
23
|
+
|
|
24
|
+
export const CreateIdentityBody = z.object({
|
|
25
|
+
name: z.string().min(1).max(120),
|
|
26
|
+
email: z.string().email(),
|
|
27
|
+
password: z.string().min(1).nullable().optional(),
|
|
28
|
+
proxy_id: Uuid.nullable().optional(),
|
|
29
|
+
persona_text: z.string().default(""),
|
|
30
|
+
/** Optional UI-provided preview for create-time session/proxy validation. */
|
|
31
|
+
session_preview: OmniFlowSessionSummarySchema.optional(),
|
|
32
|
+
});
|
|
33
|
+
export type CreateIdentityBody = z.infer<typeof CreateIdentityBody>;
|
|
34
|
+
|
|
35
|
+
export const PatchIdentityBody = CreateIdentityBody.partial();
|
|
36
|
+
export type PatchIdentityBody = z.infer<typeof PatchIdentityBody>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dp-shared
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for cross-tier contracts:
|
|
5
|
+
* - WebSocket message envelopes and discriminated unions
|
|
6
|
+
* - REST request/response shapes
|
|
7
|
+
* - Postgres row types
|
|
8
|
+
*
|
|
9
|
+
* dp-worker, dp-director, dp-center-worker, and dp-center-web all import from
|
|
10
|
+
* here. Any change to the wire format starts in this package; the consumers
|
|
11
|
+
* fail to compile until they're updated.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export * from "./domain.js";
|
|
15
|
+
export * from "./identities.js";
|
|
16
|
+
export * from "./omni-flow-session.js";
|
|
17
|
+
export * from "./ws-protocol.js";
|
|
18
|
+
export * from "./rest-contracts.js";
|
|
19
|
+
export * from "./db-rows.js";
|
|
20
|
+
export * from "./task-history-contracts.js";
|
|
21
|
+
export * from "./worker-detail-contracts.js";
|
|
22
|
+
export * from "./configs-contracts.js";
|
|
23
|
+
export * from "./audit-contracts.js";
|
|
24
|
+
export * from "./deploy-contracts.js";
|
|
25
|
+
export * from "./admin-broadcast.js";
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
const StringOrNumber = z.union([z.string(), z.number()]);
|
|
4
|
+
|
|
5
|
+
export const OmniFlowProxyConfigSchema = z.object({
|
|
6
|
+
type: z.string().min(1),
|
|
7
|
+
host: z.string().min(1),
|
|
8
|
+
port: StringOrNumber,
|
|
9
|
+
username: z.string().optional().default(""),
|
|
10
|
+
password: z.string().optional().default(""),
|
|
11
|
+
});
|
|
12
|
+
export type OmniFlowProxyConfig = z.infer<typeof OmniFlowProxyConfigSchema>;
|
|
13
|
+
|
|
14
|
+
export const OmniFlowExtensionStorageSchema = z
|
|
15
|
+
.object({
|
|
16
|
+
proxyConfig: OmniFlowProxyConfigSchema.optional().nullable(),
|
|
17
|
+
timezoneEnabled: z.boolean().optional(),
|
|
18
|
+
spoofTimezone: z.string().optional().default(""),
|
|
19
|
+
webrtcDisabled: z.boolean().optional(),
|
|
20
|
+
languagesEnabled: z.boolean().optional(),
|
|
21
|
+
hardwareMaskingEnabled: z.boolean().optional(),
|
|
22
|
+
antiBotEnabled: z.boolean().optional(),
|
|
23
|
+
})
|
|
24
|
+
.passthrough();
|
|
25
|
+
export type OmniFlowExtensionStorage = z.infer<
|
|
26
|
+
typeof OmniFlowExtensionStorageSchema
|
|
27
|
+
>;
|
|
28
|
+
|
|
29
|
+
export const OmniFlowCookieSchema = z
|
|
30
|
+
.object({
|
|
31
|
+
name: z.string().min(1),
|
|
32
|
+
value: z.string(),
|
|
33
|
+
domain: z.string().min(1),
|
|
34
|
+
path: z.string().default("/"),
|
|
35
|
+
secure: z.boolean().optional(),
|
|
36
|
+
httpOnly: z.boolean().optional(),
|
|
37
|
+
sameSite: z.string().optional(),
|
|
38
|
+
expirationDate: z.number().optional(),
|
|
39
|
+
session: z.boolean().optional(),
|
|
40
|
+
storeId: z.string().optional(),
|
|
41
|
+
})
|
|
42
|
+
.passthrough();
|
|
43
|
+
export type OmniFlowCookie = z.infer<typeof OmniFlowCookieSchema>;
|
|
44
|
+
|
|
45
|
+
export const OmniFlowSessionExportSchema = z
|
|
46
|
+
.object({
|
|
47
|
+
app: z.literal("OmniFlow"),
|
|
48
|
+
version: z.string().optional(),
|
|
49
|
+
timestamp: z.number().optional(),
|
|
50
|
+
extensionStorage: OmniFlowExtensionStorageSchema,
|
|
51
|
+
cookies: z.array(OmniFlowCookieSchema).default([]),
|
|
52
|
+
})
|
|
53
|
+
.passthrough();
|
|
54
|
+
export type OmniFlowSessionExport = z.infer<
|
|
55
|
+
typeof OmniFlowSessionExportSchema
|
|
56
|
+
>;
|
|
57
|
+
|
|
58
|
+
export const OmniFlowSessionSummarySchema = z.object({
|
|
59
|
+
proxy: OmniFlowProxyConfigSchema.nullable(),
|
|
60
|
+
timezone: z.string().optional().default(""),
|
|
61
|
+
cookie_count: z.number().int().nonnegative().default(0),
|
|
62
|
+
});
|
|
63
|
+
export type OmniFlowSessionSummary = z.infer<
|
|
64
|
+
typeof OmniFlowSessionSummarySchema
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
export function summarizeOmniFlowSession(
|
|
68
|
+
payload: OmniFlowSessionExport
|
|
69
|
+
): OmniFlowSessionSummary {
|
|
70
|
+
const storage = payload.extensionStorage;
|
|
71
|
+
const proxy = storage.proxyConfig ?? null;
|
|
72
|
+
const timezone =
|
|
73
|
+
storage.timezoneEnabled === false ? "" : storage.spoofTimezone ?? "";
|
|
74
|
+
return {
|
|
75
|
+
proxy,
|
|
76
|
+
timezone,
|
|
77
|
+
cookie_count: payload.cookies.length,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|