dp-worker 0.1.18 → 0.1.20
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/builtin-skills/x.md +27 -0
- package/dist/bird/bird-frontend.d.ts +33 -0
- package/dist/bird/bird-frontend.js +68 -0
- package/dist/bird/bird-frontend.js.map +1 -0
- package/dist/bird/credentials.d.ts +36 -0
- package/dist/bird/credentials.js +82 -0
- package/dist/bird/credentials.js.map +1 -0
- package/dist/bird/ops.d.ts +103 -0
- package/dist/bird/ops.js +523 -0
- package/dist/bird/ops.js.map +1 -0
- package/dist/bird/sidecar-entry.d.ts +25 -0
- package/dist/bird/sidecar-entry.js +192 -0
- package/dist/bird/sidecar-entry.js.map +1 -0
- package/dist/bird/sidecar-host.d.ts +54 -0
- package/dist/bird/sidecar-host.js +318 -0
- package/dist/bird/sidecar-host.js.map +1 -0
- package/dist/bird/socks-connector.d.ts +26 -0
- package/dist/bird/socks-connector.js +49 -0
- package/dist/bird/socks-connector.js.map +1 -0
- package/dist/chrome-extension/omni-flow/manifest.json +1 -1
- package/dist/config/center-config.d.ts +8 -0
- package/dist/config/center-config.js +1 -0
- package/dist/config/center-config.js.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/node_modules/dp-shared/dist/admin-broadcast.d.ts +1 -1
- package/node_modules/dp-shared/dist/admin-broadcast.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.d.ts +483 -0
- package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -0
- package/node_modules/dp-shared/dist/bird-contracts.js +372 -0
- package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -0
- package/node_modules/dp-shared/dist/configs-contracts.d.ts +11 -1
- package/node_modules/dp-shared/dist/configs-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/configs-contracts.js +43 -0
- package/node_modules/dp-shared/dist/configs-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/index.d.ts +2 -0
- package/node_modules/dp-shared/dist/index.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/index.js +2 -0
- package/node_modules/dp-shared/dist/index.js.map +1 -1
- package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts +9 -3
- package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/post-drafts-contracts.js +34 -0
- package/node_modules/dp-shared/dist/post-drafts-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/promo-contracts.d.ts +651 -0
- package/node_modules/dp-shared/dist/promo-contracts.d.ts.map +1 -0
- package/node_modules/dp-shared/dist/promo-contracts.js +566 -0
- package/node_modules/dp-shared/dist/promo-contracts.js.map +1 -0
- package/node_modules/dp-shared/dist/rest-contracts.d.ts +73 -0
- package/node_modules/dp-shared/dist/rest-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/rest-contracts.js +70 -0
- package/node_modules/dp-shared/dist/rest-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/smart-money-contracts.d.ts +86 -0
- package/node_modules/dp-shared/dist/smart-money-contracts.d.ts.map +1 -0
- package/node_modules/dp-shared/dist/smart-money-contracts.js +71 -0
- package/node_modules/dp-shared/dist/smart-money-contracts.js.map +1 -0
- package/node_modules/dp-shared/dist/task-history-contracts.d.ts +2 -0
- package/node_modules/dp-shared/dist/task-history-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/task-history-contracts.js +2 -0
- package/node_modules/dp-shared/dist/task-history-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts +7 -0
- package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/worker-detail-contracts.js +9 -0
- package/node_modules/dp-shared/dist/worker-detail-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/ws-protocol.d.ts +52 -0
- package/node_modules/dp-shared/dist/ws-protocol.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/ws-protocol.js +37 -0
- package/node_modules/dp-shared/dist/ws-protocol.js.map +1 -1
- package/package.json +4 -1
- package/node_modules/dp-shared/src/admin-broadcast.ts +0 -41
- package/node_modules/dp-shared/src/audit-contracts.ts +0 -33
- package/node_modules/dp-shared/src/auto-post-contracts.ts +0 -206
- package/node_modules/dp-shared/src/cloak-contracts.ts +0 -110
- package/node_modules/dp-shared/src/configs-contracts.ts +0 -249
- package/node_modules/dp-shared/src/db-rows.ts +0 -303
- package/node_modules/dp-shared/src/deploy-contracts.ts +0 -38
- package/node_modules/dp-shared/src/domain.ts +0 -124
- package/node_modules/dp-shared/src/fingerprint.ts +0 -21
- package/node_modules/dp-shared/src/identities.ts +0 -38
- package/node_modules/dp-shared/src/index.ts +0 -30
- package/node_modules/dp-shared/src/omni-flow-cookie.ts +0 -272
- package/node_modules/dp-shared/src/omni-flow-session.ts +0 -79
- package/node_modules/dp-shared/src/post-drafts-contracts.ts +0 -807
- package/node_modules/dp-shared/src/rest-contracts.ts +0 -592
- package/node_modules/dp-shared/src/task-history-contracts.ts +0 -124
- package/node_modules/dp-shared/src/worker-detail-contracts.ts +0 -236
- package/node_modules/dp-shared/src/ws-protocol.ts +0 -495
|
@@ -1,124 +0,0 @@
|
|
|
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>;
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
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>;
|
|
@@ -1,30 +0,0 @@
|
|
|
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 "./omni-flow-cookie.js";
|
|
18
|
-
export * from "./ws-protocol.js";
|
|
19
|
-
export * from "./rest-contracts.js";
|
|
20
|
-
export * from "./db-rows.js";
|
|
21
|
-
export * from "./task-history-contracts.js";
|
|
22
|
-
export * from "./worker-detail-contracts.js";
|
|
23
|
-
export * from "./configs-contracts.js";
|
|
24
|
-
export * from "./audit-contracts.js";
|
|
25
|
-
export * from "./deploy-contracts.js";
|
|
26
|
-
export * from "./admin-broadcast.js";
|
|
27
|
-
export * from "./fingerprint.js";
|
|
28
|
-
export * from "./post-drafts-contracts.js";
|
|
29
|
-
export * from "./auto-post-contracts.js";
|
|
30
|
-
export * from "./cloak-contracts.js";
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OmniFlow ⇄ Playwright cookie/routing mapping — single source of truth.
|
|
3
|
-
*
|
|
4
|
-
* The养号 session blob ({@link OmniFlowSessionExport}) is the interchange format
|
|
5
|
-
* shared by the OmniFlow extension, dp-worker's CloakBrowser backend, and the
|
|
6
|
-
* dp-cloak desktop app. Converting between that blob and Playwright's native
|
|
7
|
-
* cookie/proxy shapes is pure data mapping, so it lives here rather than being
|
|
8
|
-
* copied per-consumer — a change to the mapping (new sameSite value, partition
|
|
9
|
-
* key, …) then updates every tier at once.
|
|
10
|
-
*
|
|
11
|
-
* dp-worker's `cloakbrowser-backend.ts` originally owned the FORWARD direction
|
|
12
|
-
* (blob → Playwright, for injection). dp-cloak needs the REVERSE too (live
|
|
13
|
-
* `context.cookies()` → blob, for export back to a worker). Both directions are
|
|
14
|
-
* here and are tested to round-trip losslessly.
|
|
15
|
-
*
|
|
16
|
-
* No runtime dependency on playwright-core: the Playwright cookie shapes are
|
|
17
|
-
* described structurally below. `context.cookies()` output and `addCookies()`
|
|
18
|
-
* input both satisfy these, so consumers pass Playwright values directly.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import type {
|
|
22
|
-
OmniFlowCookie,
|
|
23
|
-
OmniFlowProxyConfig,
|
|
24
|
-
OmniFlowSessionExport,
|
|
25
|
-
} from "./omni-flow-session.js";
|
|
26
|
-
|
|
27
|
-
/** Playwright `SameSite` enum (the only three values Chromium emits/accepts). */
|
|
28
|
-
export type PlaywrightSameSite = "Strict" | "Lax" | "None";
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Shape accepted by Playwright's `BrowserContext.addCookies()` (a subset of its
|
|
32
|
-
* params — the fields we actually set). Structurally compatible with the real
|
|
33
|
-
* type, so callers can pass the array straight to `addCookies`.
|
|
34
|
-
*/
|
|
35
|
-
export interface PlaywrightCookieParam {
|
|
36
|
-
name: string;
|
|
37
|
-
value: string;
|
|
38
|
-
domain: string;
|
|
39
|
-
path: string;
|
|
40
|
-
expires?: number;
|
|
41
|
-
secure?: boolean;
|
|
42
|
-
httpOnly?: boolean;
|
|
43
|
-
sameSite?: PlaywrightSameSite;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Shape returned by Playwright's `BrowserContext.cookies()`. Same fields, but
|
|
48
|
-
* `expires` is always present (`-1` denotes a session cookie) — that `-1`
|
|
49
|
-
* sentinel is the single trickiest part of the reverse mapping.
|
|
50
|
-
*/
|
|
51
|
-
export interface PlaywrightCookie {
|
|
52
|
-
name: string;
|
|
53
|
-
value: string;
|
|
54
|
-
domain: string;
|
|
55
|
-
path: string;
|
|
56
|
-
expires: number;
|
|
57
|
-
httpOnly: boolean;
|
|
58
|
-
secure: boolean;
|
|
59
|
-
sameSite: PlaywrightSameSite;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
// sameSite — bidirectional
|
|
64
|
-
// ---------------------------------------------------------------------------
|
|
65
|
-
|
|
66
|
-
/** Map a Chrome-exported cookie's sameSite string to Playwright's enum. */
|
|
67
|
-
export function mapSameSiteToPlaywright(
|
|
68
|
-
v?: string
|
|
69
|
-
): PlaywrightSameSite | undefined {
|
|
70
|
-
switch ((v ?? "").toLowerCase()) {
|
|
71
|
-
case "no_restriction":
|
|
72
|
-
case "none":
|
|
73
|
-
return "None";
|
|
74
|
-
case "lax":
|
|
75
|
-
return "Lax";
|
|
76
|
-
case "strict":
|
|
77
|
-
return "Strict";
|
|
78
|
-
default:
|
|
79
|
-
return undefined; // 'unspecified' / unknown -> let Playwright default
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Map Playwright's sameSite enum back to the OmniFlow/Chrome string form. */
|
|
84
|
-
export function mapSameSiteToOmniFlow(
|
|
85
|
-
v?: PlaywrightSameSite
|
|
86
|
-
): string | undefined {
|
|
87
|
-
switch (v) {
|
|
88
|
-
case "None":
|
|
89
|
-
return "no_restriction";
|
|
90
|
-
case "Lax":
|
|
91
|
-
return "lax";
|
|
92
|
-
case "Strict":
|
|
93
|
-
return "strict";
|
|
94
|
-
default:
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
// cookie — forward (blob → Playwright)
|
|
101
|
-
// ---------------------------------------------------------------------------
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Convert an OmniFlow-exported cookie to Playwright's addCookies shape, or null
|
|
105
|
-
* if it lacks the required name/domain. Persistent cookies carry an absolute
|
|
106
|
-
* expiry (Unix seconds); session cookies omit it so Playwright treats them as
|
|
107
|
-
* session-scoped.
|
|
108
|
-
*/
|
|
109
|
-
export function omniFlowCookieToPlaywright(
|
|
110
|
-
c: OmniFlowCookie
|
|
111
|
-
): PlaywrightCookieParam | null {
|
|
112
|
-
if (!c.name || !c.domain) return null;
|
|
113
|
-
const out: PlaywrightCookieParam = {
|
|
114
|
-
name: c.name,
|
|
115
|
-
value: c.value ?? "",
|
|
116
|
-
domain: c.domain,
|
|
117
|
-
path: c.path || "/",
|
|
118
|
-
};
|
|
119
|
-
if (typeof c.secure === "boolean") out.secure = c.secure;
|
|
120
|
-
if (typeof c.httpOnly === "boolean") out.httpOnly = c.httpOnly;
|
|
121
|
-
if (!c.session && typeof c.expirationDate === "number") {
|
|
122
|
-
out.expires = Math.floor(c.expirationDate);
|
|
123
|
-
}
|
|
124
|
-
const sameSite = mapSameSiteToPlaywright(c.sameSite);
|
|
125
|
-
if (sameSite) {
|
|
126
|
-
out.sameSite = sameSite;
|
|
127
|
-
// Chrome/Playwright require SameSite=None cookies to be Secure.
|
|
128
|
-
if (sameSite === "None") out.secure = true;
|
|
129
|
-
}
|
|
130
|
-
return out;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// ---------------------------------------------------------------------------
|
|
134
|
-
// cookie — reverse (Playwright → blob)
|
|
135
|
-
// ---------------------------------------------------------------------------
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Convert a live Playwright cookie (from `context.cookies()`) into an OmniFlow
|
|
139
|
-
* cookie for export. Inverse of {@link omniFlowCookieToPlaywright}.
|
|
140
|
-
*
|
|
141
|
-
* The `expires` sentinel is the crux: Playwright uses `-1` (and we also treat a
|
|
142
|
-
* missing/non-positive value) to mean "session cookie", which OmniFlow encodes
|
|
143
|
-
* as `session: true` with NO `expirationDate`. A real future expiry becomes
|
|
144
|
-
* `session: false` + `expirationDate`.
|
|
145
|
-
*/
|
|
146
|
-
export function playwrightCookieToOmniFlow(
|
|
147
|
-
c: PlaywrightCookie
|
|
148
|
-
): OmniFlowCookie {
|
|
149
|
-
const isSession = !(typeof c.expires === "number" && c.expires > 0);
|
|
150
|
-
const out: OmniFlowCookie = {
|
|
151
|
-
name: c.name,
|
|
152
|
-
value: c.value ?? "",
|
|
153
|
-
domain: c.domain,
|
|
154
|
-
path: c.path || "/",
|
|
155
|
-
session: isSession,
|
|
156
|
-
};
|
|
157
|
-
if (typeof c.secure === "boolean") out.secure = c.secure;
|
|
158
|
-
if (typeof c.httpOnly === "boolean") out.httpOnly = c.httpOnly;
|
|
159
|
-
if (!isSession) out.expirationDate = Math.floor(c.expires);
|
|
160
|
-
const sameSite = mapSameSiteToOmniFlow(c.sameSite);
|
|
161
|
-
if (sameSite) out.sameSite = sameSite;
|
|
162
|
-
return out;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// ---------------------------------------------------------------------------
|
|
166
|
-
// routing (proxy + timezone) resolved from a session blob
|
|
167
|
-
// ---------------------------------------------------------------------------
|
|
168
|
-
|
|
169
|
-
/** A CloakBrowser proxy option (URL string form fed to `--proxy-server`). */
|
|
170
|
-
export interface CloakProxy {
|
|
171
|
-
server: string;
|
|
172
|
-
username?: string;
|
|
173
|
-
password?: string;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export interface ResolvedRouting {
|
|
177
|
-
proxy?: CloakProxy;
|
|
178
|
-
timezone?: string;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** Convert an OmniFlow proxy config into cloakbrowser's proxy option. */
|
|
182
|
-
export function omniFlowProxyToCloak(
|
|
183
|
-
pc: OmniFlowProxyConfig | null | undefined
|
|
184
|
-
): CloakProxy | undefined {
|
|
185
|
-
if (!pc || !pc.host || !pc.port) return undefined;
|
|
186
|
-
return {
|
|
187
|
-
// OmniFlow stores `type` as 'socks5' | 'http' etc., port as string|number.
|
|
188
|
-
server: `${String(pc.type).toLowerCase()}://${pc.host}:${pc.port}`,
|
|
189
|
-
...(pc.username ? { username: pc.username } : {}),
|
|
190
|
-
...(pc.password ? { password: pc.password } : {}),
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Pull proxy + timezone out of a session blob (the blob branch of dp-worker's
|
|
196
|
-
* `resolveRouting`, minus the DipclawConfig fallback — that is worker-only).
|
|
197
|
-
* A disabled timezone (`timezoneEnabled === false`) resolves to no timezone.
|
|
198
|
-
*/
|
|
199
|
-
export function resolveRoutingFromBlob(
|
|
200
|
-
blob: OmniFlowSessionExport
|
|
201
|
-
): ResolvedRouting {
|
|
202
|
-
const storage = blob.extensionStorage;
|
|
203
|
-
const proxy = omniFlowProxyToCloak(storage.proxyConfig);
|
|
204
|
-
const timezone =
|
|
205
|
-
storage.timezoneEnabled === false
|
|
206
|
-
? undefined
|
|
207
|
-
: storage.spoofTimezone || undefined;
|
|
208
|
-
return { ...(proxy ? { proxy } : {}), ...(timezone ? { timezone } : {}) };
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// ---------------------------------------------------------------------------
|
|
212
|
-
// timezone → locale
|
|
213
|
-
// ---------------------------------------------------------------------------
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Best-effort IANA timezone -> BCP-47 locale. We feed our own per-proxy
|
|
217
|
-
* timezone (no geoip), and a locale that roughly matches keeps the two
|
|
218
|
-
* consistent for fingerprinting. Unknown zones fall back to en-US, which is
|
|
219
|
-
* also CloakBrowser's default.
|
|
220
|
-
*/
|
|
221
|
-
export function localeFromTimezone(timezone: string | undefined): string {
|
|
222
|
-
if (!timezone) return "en-US";
|
|
223
|
-
const map: Record<string, string> = {
|
|
224
|
-
"Asia/Shanghai": "zh-CN",
|
|
225
|
-
"Asia/Hong_Kong": "zh-HK",
|
|
226
|
-
"Asia/Taipei": "zh-TW",
|
|
227
|
-
"Asia/Tokyo": "ja-JP",
|
|
228
|
-
"Asia/Seoul": "ko-KR",
|
|
229
|
-
"Asia/Singapore": "en-SG",
|
|
230
|
-
"Europe/London": "en-GB",
|
|
231
|
-
"Europe/Paris": "fr-FR",
|
|
232
|
-
"Europe/Berlin": "de-DE",
|
|
233
|
-
"Europe/Madrid": "es-ES",
|
|
234
|
-
"Europe/Moscow": "ru-RU",
|
|
235
|
-
"America/Sao_Paulo": "pt-BR",
|
|
236
|
-
};
|
|
237
|
-
if (map[timezone]) return map[timezone];
|
|
238
|
-
if (timezone.startsWith("America/")) return "en-US";
|
|
239
|
-
if (timezone.startsWith("Australia/")) return "en-AU";
|
|
240
|
-
return "en-US";
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// ---------------------------------------------------------------------------
|
|
244
|
-
// blob assembly (for export)
|
|
245
|
-
// ---------------------------------------------------------------------------
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Assemble a dp-worker-compatible OmniFlow session blob from a proxy/timezone
|
|
249
|
-
* config plus exported cookies. Mirrors what the extension writes and what
|
|
250
|
-
* `readSessionBlob` in the worker expects, so the output drops straight into a
|
|
251
|
-
* worker's `<workspace>/.dipclaw/omni-flow-session.json`.
|
|
252
|
-
*/
|
|
253
|
-
export function buildOmniFlowSession(params: {
|
|
254
|
-
proxy: OmniFlowProxyConfig | null;
|
|
255
|
-
timezone: string | null;
|
|
256
|
-
timezoneEnabled?: boolean;
|
|
257
|
-
cookies: OmniFlowCookie[];
|
|
258
|
-
timestamp?: number;
|
|
259
|
-
}): OmniFlowSessionExport {
|
|
260
|
-
const { proxy, timezone, cookies } = params;
|
|
261
|
-
const timezoneEnabled = params.timezoneEnabled ?? Boolean(timezone);
|
|
262
|
-
return {
|
|
263
|
-
app: "OmniFlow",
|
|
264
|
-
...(params.timestamp != null ? { timestamp: params.timestamp } : {}),
|
|
265
|
-
extensionStorage: {
|
|
266
|
-
proxyConfig: proxy ?? null,
|
|
267
|
-
timezoneEnabled,
|
|
268
|
-
spoofTimezone: timezoneEnabled ? timezone ?? "" : "",
|
|
269
|
-
},
|
|
270
|
-
cookies,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
}
|