dp-worker 0.1.6 → 0.1.8

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.
Files changed (125) hide show
  1. package/builtin-skills/x.md +36 -28
  2. package/config.example.json +2 -0
  3. package/dist/agent/agent.js +1 -1
  4. package/dist/agent/agent.js.map +1 -1
  5. package/dist/agent/chat-engine.js +36 -13
  6. package/dist/agent/chat-engine.js.map +1 -1
  7. package/dist/agent/context.d.ts +2 -0
  8. package/dist/agent/context.js +4 -2
  9. package/dist/agent/context.js.map +1 -1
  10. package/dist/agent/task-runner.js +17 -16
  11. package/dist/agent/task-runner.js.map +1 -1
  12. package/dist/agent/tool-loop-detection.js +7 -3
  13. package/dist/agent/tool-loop-detection.js.map +1 -1
  14. package/dist/agent/tool-runner.js +2 -2
  15. package/dist/browser/actions.d.ts +26 -1
  16. package/dist/browser/actions.js +493 -242
  17. package/dist/browser/actions.js.map +1 -1
  18. package/dist/browser/chrome-process.d.ts +25 -3
  19. package/dist/browser/chrome-process.js +67 -13
  20. package/dist/browser/chrome-process.js.map +1 -1
  21. package/dist/browser/cloakbrowser-backend.d.ts +39 -0
  22. package/dist/browser/cloakbrowser-backend.js +243 -0
  23. package/dist/browser/cloakbrowser-backend.js.map +1 -0
  24. package/dist/browser/dispatch.js +32 -8
  25. package/dist/browser/dispatch.js.map +1 -1
  26. package/dist/browser/expect.d.ts +6 -1
  27. package/dist/browser/expect.js +32 -10
  28. package/dist/browser/expect.js.map +1 -1
  29. package/dist/browser/extension-relay.d.ts +9 -0
  30. package/dist/browser/extension-relay.js +579 -0
  31. package/dist/browser/extension-relay.js.map +1 -0
  32. package/dist/browser/humanize.d.ts +3 -0
  33. package/dist/browser/humanize.js +52 -7
  34. package/dist/browser/humanize.js.map +1 -1
  35. package/dist/browser/manager.d.ts +50 -0
  36. package/dist/browser/manager.js +210 -33
  37. package/dist/browser/manager.js.map +1 -1
  38. package/dist/browser/page-outline.d.ts +36 -0
  39. package/dist/browser/page-outline.js +703 -0
  40. package/dist/browser/page-outline.js.map +1 -0
  41. package/dist/browser/script-runner.js +4 -2
  42. package/dist/browser/script-runner.js.map +1 -1
  43. package/dist/browser/selectors.js +10 -3
  44. package/dist/browser/selectors.js.map +1 -1
  45. package/dist/browser/snapshot.d.ts +19 -1
  46. package/dist/browser/snapshot.js +145 -24
  47. package/dist/browser/snapshot.js.map +1 -1
  48. package/dist/chrome-extension/omni-flow/background.js +304 -21
  49. package/dist/chrome-extension/omni-flow/connect.html +81 -0
  50. package/dist/chrome-extension/omni-flow/connect.js +43 -0
  51. package/dist/chrome-extension/omni-flow/content.js +13 -21
  52. package/dist/chrome-extension/omni-flow/inject.js +77 -56
  53. package/dist/chrome-extension/omni-flow/manifest.json +6 -3
  54. package/dist/config/center-config.js +5 -0
  55. package/dist/config/center-config.js.map +1 -1
  56. package/dist/config/types.d.ts +21 -2
  57. package/dist/config/types.js +35 -1
  58. package/dist/config/types.js.map +1 -1
  59. package/dist/index.js +15 -1
  60. package/dist/index.js.map +1 -1
  61. package/dist/llm/live-tool-result-guard.d.ts +16 -0
  62. package/dist/llm/live-tool-result-guard.js +57 -0
  63. package/dist/llm/live-tool-result-guard.js.map +1 -0
  64. package/dist/llm/message-optimizer.d.ts +10 -0
  65. package/dist/llm/message-optimizer.js +12 -0
  66. package/dist/llm/message-optimizer.js.map +1 -1
  67. package/dist/llm/tools.js +37 -11
  68. package/dist/llm/tools.js.map +1 -1
  69. package/dist/render/ffmpeg-compose.d.ts +25 -0
  70. package/dist/render/ffmpeg-compose.js +141 -0
  71. package/dist/render/ffmpeg-compose.js.map +1 -0
  72. package/dist/render/ffmpeg-merge.d.ts +5 -0
  73. package/dist/render/ffmpeg-merge.js +61 -0
  74. package/dist/render/ffmpeg-merge.js.map +1 -0
  75. package/dist/render/font.d.ts +1 -0
  76. package/dist/render/font.js +61 -0
  77. package/dist/render/font.js.map +1 -0
  78. package/dist/render/image-gen.d.ts +11 -0
  79. package/dist/render/image-gen.js +42 -0
  80. package/dist/render/image-gen.js.map +1 -0
  81. package/dist/render/render-frontend.d.ts +46 -0
  82. package/dist/render/render-frontend.js +156 -0
  83. package/dist/render/render-frontend.js.map +1 -0
  84. package/dist/render/render-runner.d.ts +30 -0
  85. package/dist/render/render-runner.js +115 -0
  86. package/dist/render/render-runner.js.map +1 -0
  87. package/dist/render/tts.d.ts +15 -0
  88. package/dist/render/tts.js +35 -0
  89. package/dist/render/tts.js.map +1 -0
  90. package/node_modules/dp-shared/dist/db-rows.d.ts +4 -0
  91. package/node_modules/dp-shared/dist/db-rows.d.ts.map +1 -1
  92. package/node_modules/dp-shared/dist/db-rows.js +6 -0
  93. package/node_modules/dp-shared/dist/db-rows.js.map +1 -1
  94. package/node_modules/dp-shared/dist/fingerprint.d.ts +14 -0
  95. package/node_modules/dp-shared/dist/fingerprint.d.ts.map +1 -0
  96. package/node_modules/dp-shared/dist/fingerprint.js +22 -0
  97. package/node_modules/dp-shared/dist/fingerprint.js.map +1 -0
  98. package/node_modules/dp-shared/dist/index.d.ts +1 -0
  99. package/node_modules/dp-shared/dist/index.d.ts.map +1 -1
  100. package/node_modules/dp-shared/dist/index.js +1 -0
  101. package/node_modules/dp-shared/dist/index.js.map +1 -1
  102. package/node_modules/dp-shared/dist/rest-contracts.d.ts +4 -0
  103. package/node_modules/dp-shared/dist/rest-contracts.d.ts.map +1 -1
  104. package/node_modules/dp-shared/dist/rest-contracts.js +8 -0
  105. package/node_modules/dp-shared/dist/rest-contracts.js.map +1 -1
  106. package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts +8 -0
  107. package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts.map +1 -1
  108. package/node_modules/dp-shared/dist/worker-detail-contracts.js +2 -0
  109. package/node_modules/dp-shared/dist/worker-detail-contracts.js.map +1 -1
  110. package/node_modules/dp-shared/src/admin-broadcast.ts +38 -0
  111. package/node_modules/dp-shared/src/audit-contracts.ts +33 -0
  112. package/node_modules/dp-shared/src/configs-contracts.ts +211 -0
  113. package/node_modules/dp-shared/src/db-rows.ts +286 -0
  114. package/node_modules/dp-shared/src/deploy-contracts.ts +38 -0
  115. package/node_modules/dp-shared/src/domain.ts +124 -0
  116. package/node_modules/dp-shared/src/fingerprint.ts +21 -0
  117. package/node_modules/dp-shared/src/identities.ts +38 -0
  118. package/node_modules/dp-shared/src/index.ts +26 -0
  119. package/node_modules/dp-shared/src/omni-flow-session.ts +79 -0
  120. package/node_modules/dp-shared/src/rest-contracts.ts +417 -0
  121. package/node_modules/dp-shared/src/task-history-contracts.ts +118 -0
  122. package/node_modules/dp-shared/src/worker-detail-contracts.ts +232 -0
  123. package/node_modules/dp-shared/src/ws-protocol.ts +435 -0
  124. package/package.json +8 -2
  125. package/scripts/install-cloakbrowser.mjs +46 -0
@@ -0,0 +1,286 @@
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
+ ...Timestamps,
60
+ });
61
+
62
+ export const LlmProfileRow = z.object({
63
+ id: Uuid,
64
+ name: z.string().min(1),
65
+ protocol: LlmProtocol,
66
+ base_url: z.string().min(1),
67
+ api_key: z.string().min(1),
68
+ model: z.string().min(1),
69
+ image_model: z.string().optional(),
70
+ image_api_key: z.string().optional(),
71
+ image_size: z.string().optional(),
72
+ ...Timestamps,
73
+ });
74
+
75
+ export const DirectorRow = z.object({
76
+ id: Uuid,
77
+ name: z.string().min(1),
78
+ api_key: z.string().min(1),
79
+ host_label: z.string().min(1),
80
+ max_concurrent_tasks: z.number().int().nonnegative().default(0),
81
+ last_heartbeat_at: z.string().datetime().optional(),
82
+ version: z.string().optional(),
83
+ dp_worker_version: z.string().optional(),
84
+ dp_worker_latest_version: z.string().optional(),
85
+ dp_worker_runtime_mode: DpWorkerRuntimeMode.optional(),
86
+ dp_worker_upgrade_status: DpWorkerUpgradeStatus.optional(),
87
+ dp_worker_upgrade_message: z.string().optional(),
88
+ dp_worker_upgrade_started_at: z.string().datetime().optional(),
89
+ dp_worker_upgrade_finished_at: z.string().datetime().optional(),
90
+ ...Timestamps,
91
+ });
92
+
93
+ export const WorkerRow = z.object({
94
+ id: Uuid,
95
+ name: z.string().min(1),
96
+ director_id: Uuid.optional(),
97
+ api_key: z.string().min(1),
98
+ llm_profile_id: Uuid,
99
+ proxy_id: Uuid.optional(),
100
+ /**
101
+ * Per-dp-worker Chrome headless flag (M6). Defaults to false at the schema
102
+ * level; operators flip it via Web UI.
103
+ */
104
+ headless: z.boolean().default(false),
105
+ /**
106
+ * Browser automation backend (cs). "chrome" = real Chrome + CDP + OmniFlow;
107
+ * "cloakbrowser" = patched stealth Chromium via the cloakbrowser package.
108
+ * Operators pick this at worker creation; PATCHable later.
109
+ */
110
+ browser_automation_mode: z.enum(["chrome", "cloakbrowser"]).default("chrome"),
111
+ identity_id: Uuid.nullable().optional(),
112
+ process_status: ProcessStatus,
113
+ process_observed_at: z.string().datetime().optional(),
114
+ runtime_status: RuntimeStatus,
115
+ runtime_observed_at: z.string().datetime().optional(),
116
+ last_heartbeat_at: z.string().datetime().optional(),
117
+ current_task_id: Uuid.optional(),
118
+ config_etag: ConfigEtag,
119
+ session_content_hash: ContentHash.optional(),
120
+ telegram_bot_token: z.string().optional(),
121
+ telegram_allowed_users: z.array(z.number().int()).optional(),
122
+ ...Timestamps,
123
+ });
124
+
125
+ export const SocialAccountRow = z.object({
126
+ id: Uuid,
127
+ identity_id: Uuid,
128
+ platform: SocialPlatform,
129
+ profile_name: z.string().default(""),
130
+ login_type: z.enum(["password", "oauth"]).default("password"),
131
+ username: z.string().nullable(),
132
+ email: z.string().nullable(),
133
+ password: z.string().nullable(),
134
+ /** NULL = inherit identity.persona_text; non-null = own persona. */
135
+ persona_text: z.string().nullable(),
136
+ persona_other_json: z.record(z.string(), z.unknown()).optional(),
137
+ enabled: z.boolean().default(true),
138
+ ...Timestamps,
139
+ });
140
+
141
+ export const WorkerGroupRow = z.object({
142
+ id: Uuid,
143
+ name: z.string().min(1),
144
+ description: z.string().optional(),
145
+ ...Timestamps,
146
+ });
147
+
148
+ export const WorkerGroupMemberRow = z.object({
149
+ group_id: Uuid,
150
+ worker_id: Uuid,
151
+ added_at: z.string().datetime(),
152
+ });
153
+
154
+ export const ChromeSessionRow = z.object({
155
+ id: Uuid,
156
+ identity_id: Uuid,
157
+ r2_object_key: z.string().min(1),
158
+ content_hash: ContentHash,
159
+ size_bytes: z.number().int().positive(),
160
+ uploaded_by: Uuid,
161
+ uploaded_at: z.string().datetime(),
162
+ note: z.string().optional(),
163
+ });
164
+
165
+ export const ScheduledTaskRow = z.object({
166
+ id: Uuid,
167
+ worker_id: Uuid,
168
+ name: z.string().min(1),
169
+ cron: z.string().min(1),
170
+ timezone: z.string().optional(),
171
+ prompt: z.string().min(1),
172
+ random_delay_seconds: z.number().int().nonnegative().default(0),
173
+ enabled: z.boolean(),
174
+ last_run_at: z.string().datetime().optional(),
175
+ last_status: z.enum(["ok", "error"]).optional(),
176
+ run_count: z.number().int().nonnegative().default(0),
177
+ success_count: z.number().int().nonnegative().default(0),
178
+ created_by: Uuid.optional(),
179
+ ...Timestamps,
180
+ });
181
+
182
+ export const TaskRunRow = z.object({
183
+ id: Uuid,
184
+ worker_id: Uuid,
185
+ scheduled_task_id: Uuid.optional(),
186
+ source: TaskSource,
187
+ prompt: z.string().min(1),
188
+ target_descriptor_json: z.record(z.string(), z.unknown()).optional(),
189
+ status: TaskRunStatus,
190
+ dispatched_at: z.string().datetime().optional(),
191
+ started_at: z.string().datetime().optional(),
192
+ finished_at: z.string().datetime().optional(),
193
+ result_summary: z.string().optional(),
194
+ error: z.string().optional(),
195
+ randomized_delay_ms: z.number().int().nonnegative().default(0),
196
+ scheduled_fire_at: z.string().datetime().optional(),
197
+ created_by: Uuid.optional(),
198
+ parent_adhoc_task_id: Uuid.optional(),
199
+ ...Timestamps,
200
+ });
201
+
202
+ export const AdhocTaskBatchRow = z.object({
203
+ id: Uuid,
204
+ name: z.string().min(1),
205
+ prompt: z.string().min(1),
206
+ target_descriptor_json: z.record(z.string(), z.unknown()),
207
+ random_delay_seconds: z.number().int().nonnegative().default(0),
208
+ dispatch_window_seconds: z.number().int().nonnegative().default(0),
209
+ created_by: Uuid.optional(),
210
+ created_at: z.string().datetime(),
211
+ summary_stats_json: z.record(z.string(), z.unknown()).optional(),
212
+ });
213
+
214
+ export const TaskDispatchQueueRow = z.object({
215
+ id: Uuid,
216
+ worker_id: Uuid,
217
+ task_run_id: Uuid,
218
+ eta: z.string().datetime(),
219
+ priority: z.number().int().default(0),
220
+ attempts: z.number().int().nonnegative().default(0),
221
+ ...Timestamps,
222
+ });
223
+
224
+ export const ChatRow = z.object({
225
+ id: Uuid,
226
+ scope_type: ChatScopeType,
227
+ scope_id: Uuid,
228
+ last_message_at: z.string().datetime().optional(),
229
+ ...Timestamps,
230
+ });
231
+
232
+ export const ChatMessageRow = z.object({
233
+ id: Uuid,
234
+ chat_id: Uuid,
235
+ role: z.string().min(1),
236
+ content_json: z.unknown(),
237
+ attachment_ids: z.array(Uuid).default([]),
238
+ task_run_id: Uuid.optional(),
239
+ sender_user_id: Uuid.optional(),
240
+ created_at: z.string().datetime(),
241
+ });
242
+
243
+ export const AttachmentRow = z.object({
244
+ id: Uuid,
245
+ chat_id: Uuid.optional(),
246
+ r2_object_key: z.string().min(1),
247
+ filename: z.string().min(1),
248
+ mime: z.string().optional(),
249
+ size: z.number().int().positive(),
250
+ uploaded_by: Uuid,
251
+ created_at: z.string().datetime(),
252
+ });
253
+
254
+ export const AuditLogRow = z.object({
255
+ id: Uuid,
256
+ actor_user_id: Uuid.optional(),
257
+ actor_machine_id: Uuid.optional(),
258
+ action: z.string().min(1),
259
+ target_type: z.string().min(1),
260
+ target_id: z.string().min(1),
261
+ payload_json: z.record(z.string(), z.unknown()).optional(),
262
+ created_at: z.string().datetime(),
263
+ });
264
+
265
+ /* ============================================================================
266
+ * Inferred row types — what DAL functions return.
267
+ * ============================================================================ */
268
+
269
+ export type TenantRow = z.infer<typeof TenantRow>;
270
+ export type UserRow = z.infer<typeof UserRow>;
271
+ export type ProxyRow = z.infer<typeof ProxyRow>;
272
+ export type LlmProfileRow = z.infer<typeof LlmProfileRow>;
273
+ export type DirectorRow = z.infer<typeof DirectorRow>;
274
+ export type WorkerRow = z.infer<typeof WorkerRow>;
275
+ export type SocialAccountRow = z.infer<typeof SocialAccountRow>;
276
+ export type WorkerGroupRow = z.infer<typeof WorkerGroupRow>;
277
+ export type WorkerGroupMemberRow = z.infer<typeof WorkerGroupMemberRow>;
278
+ export type ChromeSessionRow = z.infer<typeof ChromeSessionRow>;
279
+ export type ScheduledTaskRow = z.infer<typeof ScheduledTaskRow>;
280
+ export type TaskRunRow = z.infer<typeof TaskRunRow>;
281
+ export type AdhocTaskBatchRow = z.infer<typeof AdhocTaskBatchRow>;
282
+ export type TaskDispatchQueueRow = z.infer<typeof TaskDispatchQueueRow>;
283
+ export type ChatRow = z.infer<typeof ChatRow>;
284
+ export type ChatMessageRow = z.infer<typeof ChatMessageRow>;
285
+ export type AttachmentRow = z.infer<typeof AttachmentRow>;
286
+ 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,21 @@
1
+ /**
2
+ * CloakBrowser per-worker fingerprint seed — single source of truth.
3
+ *
4
+ * Deterministic function of a stable key (the worker_id in cs mode). The worker
5
+ * passes the result as `--fingerprint=<seed>` to CloakBrowser; the web admin
6
+ * computes the SAME value to display it. Using one shared function guarantees
7
+ * "what the web shows" == "what the browser launches with".
8
+ *
9
+ * Pure JS (FNV-1a 32-bit, no node:crypto) so it runs identically in Node (the
10
+ * worker) and in the browser bundle (the web). Maps into CloakBrowser's 5-digit
11
+ * seed space (10000-99999).
12
+ */
13
+ export function cloakFingerprintSeed(key: string): number {
14
+ const s = `dipclaw:fp:${key}`;
15
+ let h = 0x811c9dc5; // FNV offset basis
16
+ for (let i = 0; i < s.length; i++) {
17
+ h ^= s.charCodeAt(i);
18
+ h = Math.imul(h, 0x01000193); // FNV prime
19
+ }
20
+ return 10000 + ((h >>> 0) % 90000);
21
+ }
@@ -0,0 +1,38 @@
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
+ bound_worker_id: Uuid.optional(),
20
+ bound_worker_name: z.string().optional(),
21
+ created_at: z.string().datetime(),
22
+ updated_at: z.string().datetime(),
23
+ });
24
+ export type IdentityRow = z.infer<typeof IdentityRow>;
25
+
26
+ export const CreateIdentityBody = z.object({
27
+ name: z.string().min(1).max(120),
28
+ email: z.string().email(),
29
+ password: z.string().min(1).nullable().optional(),
30
+ proxy_id: Uuid.nullable().optional(),
31
+ persona_text: z.string().default(""),
32
+ /** Optional UI-provided preview for create-time session/proxy validation. */
33
+ session_preview: OmniFlowSessionSummarySchema.optional(),
34
+ });
35
+ export type CreateIdentityBody = z.infer<typeof CreateIdentityBody>;
36
+
37
+ export const PatchIdentityBody = CreateIdentityBody.partial();
38
+ export type PatchIdentityBody = z.infer<typeof PatchIdentityBody>;
@@ -0,0 +1,26 @@
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";
26
+ export * from "./fingerprint.js";
@@ -0,0 +1,79 @@
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
+ }