dp-worker 0.1.7 → 0.1.9

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 (63) hide show
  1. package/dist/browser/chrome-process.js +16 -0
  2. package/dist/browser/chrome-process.js.map +1 -1
  3. package/dist/browser/cloakbrowser-backend.d.ts +39 -0
  4. package/dist/browser/cloakbrowser-backend.js +243 -0
  5. package/dist/browser/cloakbrowser-backend.js.map +1 -0
  6. package/dist/browser/humanize.d.ts +3 -0
  7. package/dist/browser/humanize.js +52 -7
  8. package/dist/browser/humanize.js.map +1 -1
  9. package/dist/browser/manager.d.ts +39 -0
  10. package/dist/browser/manager.js +109 -12
  11. package/dist/browser/manager.js.map +1 -1
  12. package/dist/chrome-extension/omni-flow/background.js +19 -40
  13. package/dist/chrome-extension/omni-flow/connect.html +8 -1
  14. package/dist/chrome-extension/omni-flow/connect.js +13 -0
  15. package/dist/chrome-extension/omni-flow/content.js +23 -16
  16. package/dist/chrome-extension/omni-flow/inject.js +32 -73
  17. package/dist/chrome-extension/omni-flow/manifest.json +1 -1
  18. package/dist/chrome-extension/omni-flow/popup.css +7 -1
  19. package/dist/chrome-extension/omni-flow/popup.html +1 -0
  20. package/dist/chrome-extension/omni-flow/popup.js +13 -0
  21. package/dist/config/center-config.js +3 -0
  22. package/dist/config/center-config.js.map +1 -1
  23. package/dist/config/types.d.ts +5 -0
  24. package/dist/config/types.js +14 -0
  25. package/dist/config/types.js.map +1 -1
  26. package/dist/index.js +5 -1
  27. package/dist/index.js.map +1 -1
  28. package/node_modules/dp-shared/dist/db-rows.d.ts +4 -0
  29. package/node_modules/dp-shared/dist/db-rows.d.ts.map +1 -1
  30. package/node_modules/dp-shared/dist/db-rows.js +6 -0
  31. package/node_modules/dp-shared/dist/db-rows.js.map +1 -1
  32. package/node_modules/dp-shared/dist/fingerprint.d.ts +14 -0
  33. package/node_modules/dp-shared/dist/fingerprint.d.ts.map +1 -0
  34. package/node_modules/dp-shared/dist/fingerprint.js +22 -0
  35. package/node_modules/dp-shared/dist/fingerprint.js.map +1 -0
  36. package/node_modules/dp-shared/dist/index.d.ts +1 -0
  37. package/node_modules/dp-shared/dist/index.d.ts.map +1 -1
  38. package/node_modules/dp-shared/dist/index.js +1 -0
  39. package/node_modules/dp-shared/dist/index.js.map +1 -1
  40. package/node_modules/dp-shared/dist/rest-contracts.d.ts +4 -0
  41. package/node_modules/dp-shared/dist/rest-contracts.d.ts.map +1 -1
  42. package/node_modules/dp-shared/dist/rest-contracts.js +8 -0
  43. package/node_modules/dp-shared/dist/rest-contracts.js.map +1 -1
  44. package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts +8 -0
  45. package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts.map +1 -1
  46. package/node_modules/dp-shared/dist/worker-detail-contracts.js +2 -0
  47. package/node_modules/dp-shared/dist/worker-detail-contracts.js.map +1 -1
  48. package/node_modules/dp-shared/src/admin-broadcast.ts +38 -0
  49. package/node_modules/dp-shared/src/audit-contracts.ts +33 -0
  50. package/node_modules/dp-shared/src/configs-contracts.ts +211 -0
  51. package/node_modules/dp-shared/src/db-rows.ts +286 -0
  52. package/node_modules/dp-shared/src/deploy-contracts.ts +38 -0
  53. package/node_modules/dp-shared/src/domain.ts +124 -0
  54. package/node_modules/dp-shared/src/fingerprint.ts +21 -0
  55. package/node_modules/dp-shared/src/identities.ts +38 -0
  56. package/node_modules/dp-shared/src/index.ts +26 -0
  57. package/node_modules/dp-shared/src/omni-flow-session.ts +79 -0
  58. package/node_modules/dp-shared/src/rest-contracts.ts +417 -0
  59. package/node_modules/dp-shared/src/task-history-contracts.ts +118 -0
  60. package/node_modules/dp-shared/src/worker-detail-contracts.ts +232 -0
  61. package/node_modules/dp-shared/src/ws-protocol.ts +435 -0
  62. package/package.json +8 -2
  63. package/scripts/install-cloakbrowser.mjs +46 -0
@@ -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
+ }