dp-worker 0.1.0 → 0.1.2
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/actions.d.ts +1 -1
- package/dist/browser/actions.js.map +1 -1
- package/dist/browser/builtin-page-cleanups.d.ts +1 -1
- package/dist/browser/chrome-process.d.ts +3 -0
- package/dist/browser/chrome-process.js +101 -13
- package/dist/browser/chrome-process.js.map +1 -1
- package/dist/browser/dom-helpers.d.ts +1 -1
- package/dist/browser/expect.d.ts +1 -1
- package/dist/browser/expect.js.map +1 -1
- package/dist/browser/humanize.d.ts +1 -1
- package/dist/browser/locator-resolver.d.ts +1 -1
- package/dist/browser/manager.d.ts +5 -5
- package/dist/browser/manager.js +95 -45
- package/dist/browser/manager.js.map +1 -1
- package/dist/browser/snapshot.d.ts +1 -1
- package/dist/center/session-sync.d.ts +16 -77
- package/dist/center/session-sync.js +58 -303
- 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 +6 -8
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import {
|
|
3
|
+
ConfigEtag,
|
|
4
|
+
ContentHash,
|
|
5
|
+
EffectiveWorkerStatus,
|
|
6
|
+
EffectiveDirectorStatus,
|
|
7
|
+
IanaTimezone,
|
|
8
|
+
ProcessStatus,
|
|
9
|
+
ProxyProtocol,
|
|
10
|
+
RuntimeStatus,
|
|
11
|
+
SocialPlatform,
|
|
12
|
+
Uuid,
|
|
13
|
+
} from "./domain.js";
|
|
14
|
+
import { IdentityRow } from "./identities.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* REST contracts for the Web-UI /workers/:id detail surface (wave 1 Agent B).
|
|
18
|
+
*
|
|
19
|
+
* Split out from rest-contracts.ts to keep the existing wire surface stable
|
|
20
|
+
* while the dp-worker detail tabs land; everything here is browser-facing and
|
|
21
|
+
* never reaches the dp-worker or dp-director.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* ============================================================================
|
|
25
|
+
* dp-worker create / detail
|
|
26
|
+
* ============================================================================ */
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Body for POST /api/workers. The api_key may be supplied by the caller (64
|
|
30
|
+
* lowercase hex chars — 32 crypto-random bytes) or omitted to have the
|
|
31
|
+
* server generate one. The column is stored plaintext per v2.13, so the
|
|
32
|
+
* operator can read or reset it later from the dp-worker detail surface.
|
|
33
|
+
*/
|
|
34
|
+
export const WorkerCreateRequestSchema = z.object({
|
|
35
|
+
name: z.string().min(1).max(120),
|
|
36
|
+
director_id: Uuid.optional(),
|
|
37
|
+
llm_profile_id: Uuid,
|
|
38
|
+
proxy_id: Uuid.optional(),
|
|
39
|
+
identity_id: Uuid.nullable().optional(),
|
|
40
|
+
/** Pre-generated 64-char hex api_key from the UI. Server generates one if absent. */
|
|
41
|
+
api_key: z
|
|
42
|
+
.string()
|
|
43
|
+
.regex(/^[0-9a-f]{64}$/, "api_key must be 64 lowercase hex chars")
|
|
44
|
+
.optional(),
|
|
45
|
+
telegram_bot_token: z.string().min(1).optional(),
|
|
46
|
+
telegram_allowed_users: z.array(z.number().int()).optional(),
|
|
47
|
+
headless: z.boolean().optional(),
|
|
48
|
+
});
|
|
49
|
+
export type WorkerCreateRequest = z.infer<typeof WorkerCreateRequestSchema>;
|
|
50
|
+
|
|
51
|
+
/** The plaintext api_key wire shape returned after create. */
|
|
52
|
+
export const WorkerCreateResponseSchema = z.object({
|
|
53
|
+
id: Uuid,
|
|
54
|
+
name: z.string(),
|
|
55
|
+
api_key: z.string().min(1),
|
|
56
|
+
config_etag: ConfigEtag,
|
|
57
|
+
});
|
|
58
|
+
export type WorkerCreateResponse = z.infer<typeof WorkerCreateResponseSchema>;
|
|
59
|
+
|
|
60
|
+
const ProxyJoinSchema = z.object({
|
|
61
|
+
id: Uuid,
|
|
62
|
+
label: z.string(),
|
|
63
|
+
protocol: ProxyProtocol,
|
|
64
|
+
host: z.string(),
|
|
65
|
+
port: z.number().int().positive(),
|
|
66
|
+
username: z.string(),
|
|
67
|
+
timezone: IanaTimezone,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const LlmProfileJoinSchema = z.object({
|
|
71
|
+
id: Uuid,
|
|
72
|
+
name: z.string(),
|
|
73
|
+
model: z.string(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const DirectorJoinSchema = z.object({
|
|
77
|
+
id: Uuid,
|
|
78
|
+
name: z.string(),
|
|
79
|
+
host_label: z.string(),
|
|
80
|
+
status: EffectiveDirectorStatus,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const SessionHeadSchema = z.object({
|
|
84
|
+
id: Uuid,
|
|
85
|
+
content_hash: ContentHash,
|
|
86
|
+
size_bytes: z.number().int().positive(),
|
|
87
|
+
uploaded_at: z.string().datetime(),
|
|
88
|
+
uploaded_by: Uuid,
|
|
89
|
+
r2_object_key: z.string(),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const WorkerDetailResponseSchema = z.object({
|
|
93
|
+
id: Uuid,
|
|
94
|
+
name: z.string(),
|
|
95
|
+
director_id: Uuid.optional(),
|
|
96
|
+
director: DirectorJoinSchema.optional(),
|
|
97
|
+
status: EffectiveWorkerStatus,
|
|
98
|
+
process_status: ProcessStatus.optional(),
|
|
99
|
+
runtime_status: RuntimeStatus.optional(),
|
|
100
|
+
process_observed_at: z.string().datetime().optional(),
|
|
101
|
+
runtime_observed_at: z.string().datetime().optional(),
|
|
102
|
+
last_heartbeat_at: z.string().datetime().optional(),
|
|
103
|
+
effective_status: EffectiveWorkerStatus.optional(),
|
|
104
|
+
current_task_id: Uuid.optional(),
|
|
105
|
+
config_etag: ConfigEtag,
|
|
106
|
+
headless: z.boolean(),
|
|
107
|
+
identity_id: Uuid.nullable().optional(),
|
|
108
|
+
telegram_bot_token: z.string().nullable(),
|
|
109
|
+
telegram_allowed_users: z.array(z.number().int()).optional(),
|
|
110
|
+
created_at: z.string().datetime(),
|
|
111
|
+
updated_at: z.string().datetime(),
|
|
112
|
+
proxy: ProxyJoinSchema.optional(),
|
|
113
|
+
llm_profile: LlmProfileJoinSchema,
|
|
114
|
+
social_accounts_count: z.number().int().nonnegative(),
|
|
115
|
+
scheduled_tasks_count: z.number().int().nonnegative(),
|
|
116
|
+
current_session: SessionHeadSchema.optional(),
|
|
117
|
+
/**
|
|
118
|
+
* Plaintext dp-worker api_key. Surfaced read-only on the detail page so the
|
|
119
|
+
* operator can copy it into an dp-director spawn command or re-paste during
|
|
120
|
+
* fleet migration. Per v2.13 (internal-use stance,
|
|
121
|
+
* feedback_security_simple memory) the key is stored plaintext in
|
|
122
|
+
* `dp_workers.api_key`, so re-displaying it carries no
|
|
123
|
+
* additional disclosure risk.
|
|
124
|
+
*/
|
|
125
|
+
api_key: z.string().min(1),
|
|
126
|
+
/**
|
|
127
|
+
* Full identity row when the dp-worker is bound to an identity; null otherwise.
|
|
128
|
+
* Populated via LEFT JOIN in getWorkerDetail (M3.T2).
|
|
129
|
+
*/
|
|
130
|
+
identity: IdentityRow.nullable().optional(),
|
|
131
|
+
});
|
|
132
|
+
export type WorkerDetailResponse = z.infer<typeof WorkerDetailResponseSchema>;
|
|
133
|
+
|
|
134
|
+
/* ============================================================================
|
|
135
|
+
* Social accounts CRUD
|
|
136
|
+
* ============================================================================ */
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Sub-account model:
|
|
140
|
+
* - One row per (identity, platform) — enforced by UNIQUE.
|
|
141
|
+
* - UI restricts to platform ∈ {x, youtube, reddit}; the DB enum stays
|
|
142
|
+
* wider for backward compat but the API rejects others.
|
|
143
|
+
* - login_type='password' carries email + optional username (handle) +
|
|
144
|
+
* password; login_type='oauth' carries no secrets (assumed pre-logged-in
|
|
145
|
+
* in the Chrome profile).
|
|
146
|
+
* - persona_text=null means "inherit from identity.persona_text". The
|
|
147
|
+
* bootstrap composer resolves this before handing config to dp-worker.
|
|
148
|
+
*/
|
|
149
|
+
const SubAccountPlatform = z.enum(["x", "youtube", "reddit"]);
|
|
150
|
+
|
|
151
|
+
export const SocialAccountBodySchema = z.object({
|
|
152
|
+
platform: SubAccountPlatform,
|
|
153
|
+
profile_name: z.string().min(1).max(120),
|
|
154
|
+
login_type: z.enum(["password", "oauth"]),
|
|
155
|
+
username: z.string().min(1).max(120).optional(),
|
|
156
|
+
email: z.string().email().optional(),
|
|
157
|
+
password: z.string().min(1).optional(),
|
|
158
|
+
/** Omit / null → inherit identity persona. */
|
|
159
|
+
persona_text: z.string().max(4000).nullable().optional(),
|
|
160
|
+
persona_other_json: z.record(z.string(), z.unknown()).optional(),
|
|
161
|
+
enabled: z.boolean().default(true),
|
|
162
|
+
});
|
|
163
|
+
export type SocialAccountBody = z.infer<typeof SocialAccountBodySchema>;
|
|
164
|
+
|
|
165
|
+
export const SocialAccountPatchSchema = z
|
|
166
|
+
.object({
|
|
167
|
+
profile_name: z.string().min(1).max(120).optional(),
|
|
168
|
+
login_type: z.enum(["password", "oauth"]).optional(),
|
|
169
|
+
username: z.string().min(1).max(120).nullable().optional(),
|
|
170
|
+
email: z.string().email().nullable().optional(),
|
|
171
|
+
password: z.string().min(1).nullable().optional(),
|
|
172
|
+
persona_text: z.string().max(4000).nullable().optional(),
|
|
173
|
+
persona_other_json: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
174
|
+
enabled: z.boolean().optional(),
|
|
175
|
+
})
|
|
176
|
+
.refine((v) => Object.keys(v).length > 0, {
|
|
177
|
+
message: "patch body must contain at least one field",
|
|
178
|
+
});
|
|
179
|
+
export type SocialAccountPatch = z.infer<typeof SocialAccountPatchSchema>;
|
|
180
|
+
|
|
181
|
+
export const SocialAccountResponseSchema = z.object({
|
|
182
|
+
id: Uuid,
|
|
183
|
+
identity_id: Uuid,
|
|
184
|
+
platform: SocialPlatform,
|
|
185
|
+
profile_name: z.string(),
|
|
186
|
+
login_type: z.enum(["password", "oauth"]),
|
|
187
|
+
username: z.string().nullable(),
|
|
188
|
+
email: z.string().nullable(),
|
|
189
|
+
password: z.string().nullable(),
|
|
190
|
+
persona_text: z.string().nullable(),
|
|
191
|
+
persona_other_json: z.record(z.string(), z.unknown()).optional(),
|
|
192
|
+
enabled: z.boolean(),
|
|
193
|
+
created_at: z.string().datetime(),
|
|
194
|
+
updated_at: z.string().datetime(),
|
|
195
|
+
});
|
|
196
|
+
export type SocialAccountResponse = z.infer<typeof SocialAccountResponseSchema>;
|
|
197
|
+
|
|
198
|
+
/* ============================================================================
|
|
199
|
+
* Chrome sessions history list
|
|
200
|
+
*
|
|
201
|
+
* GET /api/workers/:id/sessions returns past chrome_sessions newest-first with
|
|
202
|
+
* opaque cursor pagination, mirroring the `task-history.ts` shape. The
|
|
203
|
+
* `is_current` flag is true for the single row whose content_hash matches
|
|
204
|
+
* `dp_workers.session_content_hash` — the SessionTab uses it to render
|
|
205
|
+
* a "current" badge without a second round-trip to /api/workers/:id detail.
|
|
206
|
+
*
|
|
207
|
+
* Named `ChromeSessionListRow*` to avoid a name collision with the
|
|
208
|
+
* existing `ChromeSessionRow` postgres-row schema in `db-rows.ts` — they
|
|
209
|
+
* describe different surfaces (DB row vs. browser-facing list row + flag).
|
|
210
|
+
* ============================================================================ */
|
|
211
|
+
|
|
212
|
+
export const ChromeSessionListRowSchema = z.object({
|
|
213
|
+
id: Uuid,
|
|
214
|
+
content_hash: ContentHash,
|
|
215
|
+
size_bytes: z.number().int().positive(),
|
|
216
|
+
uploaded_at: z.string().datetime(),
|
|
217
|
+
uploaded_by: Uuid,
|
|
218
|
+
r2_object_key: z.string(),
|
|
219
|
+
note: z.string().optional(),
|
|
220
|
+
is_current: z.boolean(),
|
|
221
|
+
});
|
|
222
|
+
export type ChromeSessionListRow = z.infer<typeof ChromeSessionListRowSchema>;
|
|
223
|
+
|
|
224
|
+
export const ListChromeSessionsResponseSchema = z.object({
|
|
225
|
+
items: z.array(ChromeSessionListRowSchema),
|
|
226
|
+
next_cursor: z.string().nullable(),
|
|
227
|
+
});
|
|
228
|
+
export type ListChromeSessionsResponse = z.infer<
|
|
229
|
+
typeof ListChromeSessionsResponseSchema
|
|
230
|
+
>;
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import {
|
|
3
|
+
ConfigEtag,
|
|
4
|
+
DpWorkerRuntimeMode,
|
|
5
|
+
DpWorkerUpgradeStatus,
|
|
6
|
+
RuntimeStatus,
|
|
7
|
+
ShortId,
|
|
8
|
+
TaskRunStatus,
|
|
9
|
+
Uuid,
|
|
10
|
+
} from "./domain.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* WebSocket message envelopes.
|
|
14
|
+
*
|
|
15
|
+
* Every message that crosses the wire has the same outer shape; the inner
|
|
16
|
+
* `type` discriminates the payload. Senders that need a reply set `id`;
|
|
17
|
+
* receivers reply with `ack { ref_id: <that id> }`.
|
|
18
|
+
*
|
|
19
|
+
* See docs/architecture.md §Communication protocols → WebSocket for the
|
|
20
|
+
* authoritative list of message types per channel.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const Envelope = <T extends z.ZodType>(type: string, payload: T) =>
|
|
24
|
+
z.object({
|
|
25
|
+
/** Sender-assigned message id (typically uuid). Required when an ack is expected. */
|
|
26
|
+
id: z.string().min(1).optional(),
|
|
27
|
+
type: z.literal(type),
|
|
28
|
+
/** Unix ms at send time. */
|
|
29
|
+
ts: z.number().int().positive(),
|
|
30
|
+
payload,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/* ============================================================================
|
|
34
|
+
* Generic envelope (every channel)
|
|
35
|
+
* ============================================================================ */
|
|
36
|
+
|
|
37
|
+
export const AckMessage = Envelope(
|
|
38
|
+
"ack",
|
|
39
|
+
z.object({
|
|
40
|
+
/** id of the message being acknowledged. */
|
|
41
|
+
ref_id: z.string().min(1),
|
|
42
|
+
/** Optional outcome — for "dispatched_ack" style acks the dp-worker reports back its current state. */
|
|
43
|
+
status: z.string().optional(),
|
|
44
|
+
error: z.string().optional(),
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export const PingRequestMessage = Envelope(
|
|
49
|
+
"ping_request",
|
|
50
|
+
z.object({
|
|
51
|
+
ref_id: z.string().min(1),
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const PongMessage = Envelope(
|
|
56
|
+
"pong",
|
|
57
|
+
z.object({
|
|
58
|
+
ref_id: z.string().min(1),
|
|
59
|
+
status: RuntimeStatus.optional(),
|
|
60
|
+
current_task_id: Uuid.optional(),
|
|
61
|
+
chrome_uptime_ms: z.number().int().nonnegative().optional(),
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
/* ============================================================================
|
|
66
|
+
* center ↔ dp-worker
|
|
67
|
+
* ============================================================================ */
|
|
68
|
+
|
|
69
|
+
export const TaskDispatchMessage = Envelope(
|
|
70
|
+
"task_dispatch",
|
|
71
|
+
z.object({
|
|
72
|
+
task_run_id: Uuid,
|
|
73
|
+
prompt: z.string().min(1),
|
|
74
|
+
randomized_delay_ms: z.number().int().nonnegative().default(0),
|
|
75
|
+
deadline_ms: z.number().int().positive().optional(),
|
|
76
|
+
attachments: z
|
|
77
|
+
.array(
|
|
78
|
+
z.object({
|
|
79
|
+
r2_object_key: z.string().min(1),
|
|
80
|
+
filename: z.string().min(1),
|
|
81
|
+
mime: z.string().optional(),
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
.optional(),
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
export const ChatUserMessage = Envelope(
|
|
89
|
+
"chat_user_message",
|
|
90
|
+
z.object({
|
|
91
|
+
chat_id: Uuid,
|
|
92
|
+
message_id: Uuid,
|
|
93
|
+
content: z.union([
|
|
94
|
+
z.string(),
|
|
95
|
+
z.array(
|
|
96
|
+
z.object({
|
|
97
|
+
type: z.string(),
|
|
98
|
+
text: z.string().optional(),
|
|
99
|
+
attachment_id: Uuid.optional(),
|
|
100
|
+
filename: z.string().optional(),
|
|
101
|
+
mime: z.string().optional(),
|
|
102
|
+
size_bytes: z.number().int().positive().optional(),
|
|
103
|
+
url: z.string().url().optional(),
|
|
104
|
+
})
|
|
105
|
+
),
|
|
106
|
+
]),
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
export const ConfigInvalidateMessage = Envelope(
|
|
111
|
+
"config_invalidate",
|
|
112
|
+
z.object({
|
|
113
|
+
which: z.array(z.enum(["llm", "proxy", "persona", "session", "telegram", "social_accounts"])),
|
|
114
|
+
new_config_etag: ConfigEtag,
|
|
115
|
+
})
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
export const CancelTaskMessage = Envelope(
|
|
119
|
+
"cancel_task",
|
|
120
|
+
z.object({
|
|
121
|
+
task_run_id: Uuid,
|
|
122
|
+
reason: z.string().optional(),
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
export const WorkerHelloMessage = Envelope(
|
|
127
|
+
"hello",
|
|
128
|
+
z.object({
|
|
129
|
+
worker_id: Uuid,
|
|
130
|
+
version: z.string().min(1),
|
|
131
|
+
config_etag: ConfigEtag,
|
|
132
|
+
current_status: RuntimeStatus,
|
|
133
|
+
current_task_id: Uuid.optional(),
|
|
134
|
+
})
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
export const StatusChangeMessage = Envelope(
|
|
138
|
+
"status_change",
|
|
139
|
+
z.object({
|
|
140
|
+
status: RuntimeStatus,
|
|
141
|
+
current_task_id: Uuid.optional(),
|
|
142
|
+
chrome_uptime_ms: z.number().int().nonnegative().optional(),
|
|
143
|
+
reason: z.string().optional(),
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
/** Periodic 30s liveness ping from dp-worker to center. Empty payload —
|
|
148
|
+
* the envelope's arrival is the signal. */
|
|
149
|
+
export const WorkerHeartbeatMessage = Envelope(
|
|
150
|
+
"worker_heartbeat",
|
|
151
|
+
z.object({}),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
export const TaskEventMessage = Envelope(
|
|
155
|
+
"task_event",
|
|
156
|
+
z.object({
|
|
157
|
+
task_run_id: Uuid,
|
|
158
|
+
event: z.enum(["dispatched_ack", "started", "step_log", "finished"]),
|
|
159
|
+
status: TaskRunStatus.optional(),
|
|
160
|
+
error: z.string().optional(),
|
|
161
|
+
result_summary: z.string().optional(),
|
|
162
|
+
step_index: z.number().int().nonnegative().optional(),
|
|
163
|
+
step_log: z.string().optional(),
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
export const ChatMessageChunkMessage = Envelope(
|
|
168
|
+
"chat_message_chunk",
|
|
169
|
+
z.object({
|
|
170
|
+
chat_id: Uuid,
|
|
171
|
+
message_id: Uuid,
|
|
172
|
+
delta: z.string(),
|
|
173
|
+
done: z.boolean(),
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
export const ChatMessageFinalizedMessage = Envelope(
|
|
178
|
+
"chat_message_finalized",
|
|
179
|
+
z.object({
|
|
180
|
+
chat_id: Uuid,
|
|
181
|
+
message_id: Uuid,
|
|
182
|
+
role: z.string(),
|
|
183
|
+
content: z.string(),
|
|
184
|
+
tool_traces: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
/** Returned by dp-worker when a chat arrives while BrowserLock is held by a task. */
|
|
189
|
+
export const ChatMessageQueuedMessage = Envelope(
|
|
190
|
+
"chat_message_queued",
|
|
191
|
+
z.object({
|
|
192
|
+
chat_id: Uuid,
|
|
193
|
+
message_id: Uuid,
|
|
194
|
+
queue_position: z.number().int().nonnegative(),
|
|
195
|
+
})
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
export const AttachmentUploadRequestMessage = Envelope(
|
|
199
|
+
"attachment_upload",
|
|
200
|
+
z.object({
|
|
201
|
+
request_id: ShortId,
|
|
202
|
+
filename: z.string().min(1),
|
|
203
|
+
mime: z.string().optional(),
|
|
204
|
+
size_bytes: z.number().int().positive(),
|
|
205
|
+
})
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
export const ErrorReportMessage = Envelope(
|
|
209
|
+
"error_report",
|
|
210
|
+
z.object({
|
|
211
|
+
code: z.string().min(1),
|
|
212
|
+
message: z.string().min(1),
|
|
213
|
+
stack: z.string().optional(),
|
|
214
|
+
})
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
/* ----- Payload type aliases ----- *
|
|
218
|
+
* TypeScript's `Extract<UnionType, { type: "x" }>` is fragile on inferred
|
|
219
|
+
* discriminated unions whose variants share structural shape (all wrap
|
|
220
|
+
* `{ id?, type, ts, payload }`). Re-exporting payload types directly per
|
|
221
|
+
* message keeps consumers from having to fight that pattern.
|
|
222
|
+
*/
|
|
223
|
+
export type TaskDispatchPayload = z.infer<typeof TaskDispatchMessage>["payload"];
|
|
224
|
+
export type ChatUserMessagePayload = z.infer<typeof ChatUserMessage>["payload"];
|
|
225
|
+
export type ConfigInvalidatePayload = z.infer<typeof ConfigInvalidateMessage>["payload"];
|
|
226
|
+
export type CancelTaskPayload = z.infer<typeof CancelTaskMessage>["payload"];
|
|
227
|
+
export type PingRequestPayload = z.infer<typeof PingRequestMessage>["payload"];
|
|
228
|
+
export type PongPayload = z.infer<typeof PongMessage>["payload"];
|
|
229
|
+
export type WorkerHelloPayload = z.infer<typeof WorkerHelloMessage>["payload"];
|
|
230
|
+
export type StatusChangePayload = z.infer<typeof StatusChangeMessage>["payload"];
|
|
231
|
+
export type TaskEventPayload = z.infer<typeof TaskEventMessage>["payload"];
|
|
232
|
+
export type ChatMessageChunkPayload = z.infer<typeof ChatMessageChunkMessage>["payload"];
|
|
233
|
+
export type ChatMessageFinalizedPayload = z.infer<typeof ChatMessageFinalizedMessage>["payload"];
|
|
234
|
+
export type ChatMessageQueuedPayload = z.infer<typeof ChatMessageQueuedMessage>["payload"];
|
|
235
|
+
export type WorkerHeartbeatPayload = z.infer<typeof WorkerHeartbeatMessage>["payload"];
|
|
236
|
+
|
|
237
|
+
/** Union of every message that may travel on a center↔dp-worker WebSocket. */
|
|
238
|
+
export const CenterWorkerWsMessage = z.discriminatedUnion("type", [
|
|
239
|
+
AckMessage,
|
|
240
|
+
PingRequestMessage,
|
|
241
|
+
PongMessage,
|
|
242
|
+
// center → dp-worker
|
|
243
|
+
TaskDispatchMessage,
|
|
244
|
+
ChatUserMessage,
|
|
245
|
+
ConfigInvalidateMessage,
|
|
246
|
+
CancelTaskMessage,
|
|
247
|
+
// dp-worker → center
|
|
248
|
+
WorkerHelloMessage,
|
|
249
|
+
StatusChangeMessage,
|
|
250
|
+
WorkerHeartbeatMessage,
|
|
251
|
+
TaskEventMessage,
|
|
252
|
+
ChatMessageChunkMessage,
|
|
253
|
+
ChatMessageFinalizedMessage,
|
|
254
|
+
ChatMessageQueuedMessage,
|
|
255
|
+
AttachmentUploadRequestMessage,
|
|
256
|
+
ErrorReportMessage,
|
|
257
|
+
]);
|
|
258
|
+
export type CenterWorkerWsMessage = z.infer<typeof CenterWorkerWsMessage>;
|
|
259
|
+
|
|
260
|
+
/* ============================================================================
|
|
261
|
+
* center ↔ dp-director
|
|
262
|
+
* ============================================================================ */
|
|
263
|
+
|
|
264
|
+
export const SpawnWorkerMessage = Envelope(
|
|
265
|
+
"spawn_worker",
|
|
266
|
+
z.object({
|
|
267
|
+
worker_id: Uuid,
|
|
268
|
+
api_key: z.string().min(1),
|
|
269
|
+
center_url: z.string().url(),
|
|
270
|
+
version: z.string().optional(),
|
|
271
|
+
workspace_path: z.string().optional(),
|
|
272
|
+
})
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
export const StopWorkerMessage = Envelope(
|
|
276
|
+
"stop_worker",
|
|
277
|
+
z.object({
|
|
278
|
+
worker_id: Uuid,
|
|
279
|
+
graceful: z.boolean().default(true),
|
|
280
|
+
})
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
export const RestartWorkerMessage = Envelope(
|
|
284
|
+
"restart_worker",
|
|
285
|
+
z.object({
|
|
286
|
+
worker_id: Uuid,
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
export const UpgradeDpWorkerMessage = Envelope(
|
|
291
|
+
"upgrade_dp_worker",
|
|
292
|
+
z.object({
|
|
293
|
+
request_id: z.string().min(1),
|
|
294
|
+
})
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
export const QueryWorkerStatusMessage = Envelope(
|
|
298
|
+
"query_worker_status",
|
|
299
|
+
z.object({
|
|
300
|
+
worker_ids: z.array(Uuid).min(1),
|
|
301
|
+
})
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
export const ReconcileWorkersMessage = Envelope(
|
|
305
|
+
"reconcile_workers",
|
|
306
|
+
z.object({
|
|
307
|
+
generation: z.string().min(1),
|
|
308
|
+
workers: z.array(
|
|
309
|
+
z.object({
|
|
310
|
+
worker_id: Uuid,
|
|
311
|
+
api_key: z.string().min(1),
|
|
312
|
+
center_url: z.string().url(),
|
|
313
|
+
workspace_path: z.string().optional(),
|
|
314
|
+
})
|
|
315
|
+
),
|
|
316
|
+
stop_unlisted: z.boolean().default(true),
|
|
317
|
+
})
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
export const DirectorHelloMessage = Envelope(
|
|
321
|
+
"hello",
|
|
322
|
+
z.object({
|
|
323
|
+
director_id: Uuid,
|
|
324
|
+
host_label: z.string().min(1).optional(),
|
|
325
|
+
version: z.string().min(1),
|
|
326
|
+
worker_pids: z.record(Uuid, z.number().int().positive()),
|
|
327
|
+
capabilities: z.array(z.string()).default([]),
|
|
328
|
+
dp_worker_runtime_mode: DpWorkerRuntimeMode.optional(),
|
|
329
|
+
dp_worker_version: z.string().min(1).optional(),
|
|
330
|
+
dp_worker_latest_version: z.string().min(1).optional(),
|
|
331
|
+
dp_worker_upgrade_status: DpWorkerUpgradeStatus.optional(),
|
|
332
|
+
})
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Sent by DirectorConnection DO to the dp-director immediately after the WS upgrade so
|
|
337
|
+
* the dp-director learns its own canonical director_id (the DO resolved it from the
|
|
338
|
+
* api_key during the upgrade and knows the authoritative value). The dp-director
|
|
339
|
+
* waits for this before sending `hello`.
|
|
340
|
+
*/
|
|
341
|
+
export const WelcomeMessage = Envelope(
|
|
342
|
+
"welcome",
|
|
343
|
+
z.object({
|
|
344
|
+
director_id: Uuid,
|
|
345
|
+
})
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
export const WorkerStateChangeMessage = Envelope(
|
|
349
|
+
"worker_state_change",
|
|
350
|
+
z.object({
|
|
351
|
+
worker_id: Uuid,
|
|
352
|
+
state: z.enum(["running", "stopped", "crashed", "crashed_loop"]),
|
|
353
|
+
pid: z.number().int().positive().optional(),
|
|
354
|
+
exit_code: z.number().int().optional(),
|
|
355
|
+
})
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
export const DirectorHeartbeatMessage = Envelope(
|
|
359
|
+
"director_heartbeat",
|
|
360
|
+
z.object({
|
|
361
|
+
running_workers: z.array(Uuid),
|
|
362
|
+
cpu: z.number().nonnegative().optional(),
|
|
363
|
+
mem: z.number().nonnegative().optional(),
|
|
364
|
+
})
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
export const DpWorkerUpgradeStatusMessage = Envelope(
|
|
368
|
+
"dp_worker_upgrade_status",
|
|
369
|
+
z.object({
|
|
370
|
+
request_id: z.string().min(1),
|
|
371
|
+
status: DpWorkerUpgradeStatus,
|
|
372
|
+
runtime_mode: DpWorkerRuntimeMode,
|
|
373
|
+
current_version: z.string().min(1).optional(),
|
|
374
|
+
latest_version: z.string().min(1).optional(),
|
|
375
|
+
message: z.string().optional(),
|
|
376
|
+
})
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
export type SpawnWorkerPayload = z.infer<typeof SpawnWorkerMessage>["payload"];
|
|
380
|
+
export type StopWorkerPayload = z.infer<typeof StopWorkerMessage>["payload"];
|
|
381
|
+
export type RestartWorkerPayload = z.infer<typeof RestartWorkerMessage>["payload"];
|
|
382
|
+
export type UpgradeDpWorkerPayload = z.infer<typeof UpgradeDpWorkerMessage>["payload"];
|
|
383
|
+
export type QueryWorkerStatusPayload = z.infer<typeof QueryWorkerStatusMessage>["payload"];
|
|
384
|
+
export type ReconcileWorkersPayload = z.infer<typeof ReconcileWorkersMessage>["payload"];
|
|
385
|
+
export type DirectorHelloPayload = z.infer<typeof DirectorHelloMessage>["payload"];
|
|
386
|
+
export type WorkerStateChangePayload = z.infer<typeof WorkerStateChangeMessage>["payload"];
|
|
387
|
+
export type DirectorHeartbeatPayload = z.infer<typeof DirectorHeartbeatMessage>["payload"];
|
|
388
|
+
export type WelcomePayload = z.infer<typeof WelcomeMessage>["payload"];
|
|
389
|
+
export type DpWorkerUpgradeStatusPayload = z.infer<typeof DpWorkerUpgradeStatusMessage>["payload"];
|
|
390
|
+
|
|
391
|
+
/** Union of every message that may travel on a center↔dp-director WebSocket. */
|
|
392
|
+
export const CenterDirectorWsMessage = z.discriminatedUnion("type", [
|
|
393
|
+
AckMessage,
|
|
394
|
+
PingRequestMessage,
|
|
395
|
+
PongMessage,
|
|
396
|
+
// center → dp-director
|
|
397
|
+
SpawnWorkerMessage,
|
|
398
|
+
StopWorkerMessage,
|
|
399
|
+
RestartWorkerMessage,
|
|
400
|
+
UpgradeDpWorkerMessage,
|
|
401
|
+
QueryWorkerStatusMessage,
|
|
402
|
+
ReconcileWorkersMessage,
|
|
403
|
+
WelcomeMessage,
|
|
404
|
+
// dp-director → center
|
|
405
|
+
DirectorHelloMessage,
|
|
406
|
+
WorkerStateChangeMessage,
|
|
407
|
+
DirectorHeartbeatMessage,
|
|
408
|
+
DpWorkerUpgradeStatusMessage,
|
|
409
|
+
]);
|
|
410
|
+
export type CenterDirectorWsMessage = z.infer<typeof CenterDirectorWsMessage>;
|
|
411
|
+
|
|
412
|
+
/* ============================================================================
|
|
413
|
+
* Web UI ↔ ChatBroadcast DO
|
|
414
|
+
* ============================================================================ */
|
|
415
|
+
|
|
416
|
+
/** UI sends to subscribe to a chat (auth is via JWT in connect URL). */
|
|
417
|
+
export const ChatSubscribeMessage = Envelope(
|
|
418
|
+
"subscribe",
|
|
419
|
+
z.object({
|
|
420
|
+
chat_id: Uuid,
|
|
421
|
+
since_message_id: Uuid.optional(),
|
|
422
|
+
})
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
/** ChatBroadcast pushes the same chunks dp-worker emits, plus user-side echoes. */
|
|
426
|
+
export const ChatBroadcastChunkMessage = ChatMessageChunkMessage;
|
|
427
|
+
export const ChatBroadcastFinalizedMessage = ChatMessageFinalizedMessage;
|
|
428
|
+
|
|
429
|
+
export const CenterWebChatWsMessage = z.discriminatedUnion("type", [
|
|
430
|
+
AckMessage,
|
|
431
|
+
ChatSubscribeMessage,
|
|
432
|
+
ChatBroadcastChunkMessage,
|
|
433
|
+
ChatBroadcastFinalizedMessage,
|
|
434
|
+
]);
|
|
435
|
+
export type CenterWebChatWsMessage = z.infer<typeof CenterWebChatWsMessage>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dp-worker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Dipclaw Worker (worker) — browser automation agent with scheduling, skills, and LLM integration. Connects to dp-center via center mode or runs standalone.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"prebuild": "npm --prefix ../dp-shared run build",
|
|
16
|
-
"build": "tsc",
|
|
16
|
+
"build": "tsc && node scripts/copy-chrome-extension.mjs && chmod +x dist/index.js",
|
|
17
17
|
"predev": "npm --prefix ../dp-shared run build",
|
|
18
18
|
"dev": "tsx src/index.ts",
|
|
19
19
|
"start": "node dist/index.js",
|
|
@@ -43,24 +43,22 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@anthropic-ai/sdk": "^0.86.1",
|
|
46
|
-
"@types/ws": "^8.18.1",
|
|
47
|
-
"adm-zip": "^0.5.17",
|
|
48
46
|
"commander": "^14.0.3",
|
|
49
47
|
"dp-shared": "file:../dp-shared",
|
|
50
48
|
"grammy": "^1.42.0",
|
|
51
49
|
"node-cron": "^4.2.1",
|
|
52
50
|
"openai": "^6.34.0",
|
|
53
|
-
"playwright": "^1.59.1",
|
|
51
|
+
"playwright-core": "^1.59.1",
|
|
54
52
|
"sharp": "^0.34.5",
|
|
55
|
-
"tsx": "^4.21.0",
|
|
56
|
-
"typescript": "^6.0.2",
|
|
57
53
|
"ws": "^8.20.1",
|
|
58
54
|
"zod": "^4.3.6"
|
|
59
55
|
},
|
|
60
56
|
"devDependencies": {
|
|
61
|
-
"@types/adm-zip": "^0.5.8",
|
|
62
57
|
"@types/node": "^25.5.2",
|
|
63
58
|
"@types/node-cron": "^3.0.11",
|
|
59
|
+
"@types/ws": "^8.18.1",
|
|
60
|
+
"tsx": "^4.21.0",
|
|
61
|
+
"typescript": "^6.0.2",
|
|
64
62
|
"vitest": "^4.1.5"
|
|
65
63
|
},
|
|
66
64
|
"bundledDependencies": [
|