dp-worker 0.1.3 → 0.1.5

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 (35) hide show
  1. package/dist/browser/chrome-process.js +30 -58
  2. package/dist/browser/chrome-process.js.map +1 -1
  3. package/dist/chrome-extension/omni-flow/background.js +24 -6
  4. package/node_modules/dp-shared/dist/configs-contracts.d.ts +5 -0
  5. package/node_modules/dp-shared/dist/configs-contracts.d.ts.map +1 -1
  6. package/node_modules/dp-shared/dist/configs-contracts.js +5 -0
  7. package/node_modules/dp-shared/dist/configs-contracts.js.map +1 -1
  8. package/node_modules/dp-shared/dist/db-rows.d.ts +1 -1
  9. package/node_modules/dp-shared/dist/db-rows.d.ts.map +1 -1
  10. package/node_modules/dp-shared/dist/db-rows.js +1 -1
  11. package/node_modules/dp-shared/dist/db-rows.js.map +1 -1
  12. package/node_modules/dp-shared/dist/identities.d.ts +2 -0
  13. package/node_modules/dp-shared/dist/identities.d.ts.map +1 -1
  14. package/node_modules/dp-shared/dist/identities.js +2 -0
  15. package/node_modules/dp-shared/dist/identities.js.map +1 -1
  16. package/node_modules/dp-shared/dist/task-history-contracts.d.ts +6 -0
  17. package/node_modules/dp-shared/dist/task-history-contracts.d.ts.map +1 -1
  18. package/node_modules/dp-shared/dist/task-history-contracts.js +3 -0
  19. package/node_modules/dp-shared/dist/task-history-contracts.js.map +1 -1
  20. package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts +2 -0
  21. package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts.map +1 -1
  22. package/package.json +1 -1
  23. package/node_modules/dp-shared/src/admin-broadcast.ts +0 -38
  24. package/node_modules/dp-shared/src/audit-contracts.ts +0 -33
  25. package/node_modules/dp-shared/src/configs-contracts.ts +0 -206
  26. package/node_modules/dp-shared/src/db-rows.ts +0 -280
  27. package/node_modules/dp-shared/src/deploy-contracts.ts +0 -38
  28. package/node_modules/dp-shared/src/domain.ts +0 -124
  29. package/node_modules/dp-shared/src/identities.ts +0 -36
  30. package/node_modules/dp-shared/src/index.ts +0 -25
  31. package/node_modules/dp-shared/src/omni-flow-session.ts +0 -80
  32. package/node_modules/dp-shared/src/rest-contracts.ts +0 -409
  33. package/node_modules/dp-shared/src/task-history-contracts.ts +0 -115
  34. package/node_modules/dp-shared/src/worker-detail-contracts.ts +0 -230
  35. package/node_modules/dp-shared/src/ws-protocol.ts +0 -435
@@ -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,36 +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
- created_at: z.string().datetime(),
20
- updated_at: z.string().datetime(),
21
- });
22
- export type IdentityRow = z.infer<typeof IdentityRow>;
23
-
24
- export const CreateIdentityBody = z.object({
25
- name: z.string().min(1).max(120),
26
- email: z.string().email(),
27
- password: z.string().min(1).nullable().optional(),
28
- proxy_id: Uuid.nullable().optional(),
29
- persona_text: z.string().default(""),
30
- /** Optional UI-provided preview for create-time session/proxy validation. */
31
- session_preview: OmniFlowSessionSummarySchema.optional(),
32
- });
33
- export type CreateIdentityBody = z.infer<typeof CreateIdentityBody>;
34
-
35
- export const PatchIdentityBody = CreateIdentityBody.partial();
36
- export type PatchIdentityBody = z.infer<typeof PatchIdentityBody>;
@@ -1,25 +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 "./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";
@@ -1,80 +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
- }
80
-
@@ -1,409 +0,0 @@
1
- import { z } from "zod/v4";
2
- import {
3
- ConfigEtag,
4
- ContentHash,
5
- EffectiveWorkerStatus,
6
- IanaTimezone,
7
- LlmProtocol,
8
- ProcessStatus,
9
- ProxyProtocol,
10
- RuntimeStatus,
11
- SocialPlatform,
12
- TaskRunStatus,
13
- TaskSource,
14
- Uuid,
15
- } from "./domain.js";
16
- import { OmniFlowSessionSummarySchema } from "./omni-flow-session.js";
17
-
18
- /**
19
- * REST contracts — request bodies and response shapes for the Workers HTTP API.
20
- *
21
- * Keep request types narrow (only what clients actually send); response types
22
- * carry derived fields like timestamps and computed status.
23
- */
24
-
25
- /* ============================================================================
26
- * Bootstrap (dp-worker → center at startup)
27
- *
28
- * dp-worker POSTs with Authorization: Bearer <worker_api_key>, no body required;
29
- * center returns the full operational config + optional session blob pointer.
30
- *
31
- * [FIX from architecture.md §dp-worker-D] center must never include `org` in the response,
32
- * even if the DB has it for some reason. The dp-worker config schema strips it.
33
- * ============================================================================ */
34
-
35
- export const SocialAccountSchema = z.object({
36
- id: Uuid,
37
- platform: SocialPlatform,
38
- profile_name: z.string().default(""),
39
- login_type: z.enum(["password", "oauth"]).default("password"),
40
- /** Platform handle; was historically called `handle`. */
41
- username: z.string().optional(),
42
- email: z.string().optional(),
43
- password: z.string().optional(),
44
- /**
45
- * Already resolved by center: when the row's persona_text is NULL the
46
- * bootstrap fills it from `identity.persona_text`. dp-worker just uses
47
- * this string directly.
48
- */
49
- persona_text: z.string().default(""),
50
- persona_other_json: z.record(z.string(), z.unknown()).optional(),
51
- enabled: z.boolean().default(true),
52
- });
53
- export type SocialAccount = z.infer<typeof SocialAccountSchema>;
54
-
55
- export const ProxyConfigSchema = z.object({
56
- protocol: ProxyProtocol,
57
- host: z.string().min(1),
58
- port: z.number().int().positive(),
59
- username: z.string().min(1),
60
- password: z.string().min(1),
61
- /**
62
- * IANA timezone of the proxy egress location. Required on creation in center.
63
- * Bootstrap returns this on `config.proxy.timezone` and ALSO copies it to
64
- * `config.timezone` so dp-worker can use it as the default scheduler timezone
65
- * (so cron "0 15 * * *" on a NYC-proxy dp-worker
66
- * fires at NYC 15:00 regardless of where the Worker runs).
67
- */
68
- timezone: IanaTimezone,
69
- });
70
- export type ProxyConfigShared = z.infer<typeof ProxyConfigSchema>;
71
-
72
- export const LlmProfileSchema = z.object({
73
- protocol: LlmProtocol,
74
- base_url: z.string().min(1),
75
- api_key: z.string().min(1),
76
- model: z.string().min(1),
77
- image_generation: z
78
- .object({
79
- api_key: z.string().min(1),
80
- model: z.string().min(1),
81
- size: z.string().default("1024x1024"),
82
- timeout_ms: z.number().int().positive().default(120000),
83
- })
84
- .optional(),
85
- });
86
- export type LlmProfile = z.infer<typeof LlmProfileSchema>;
87
-
88
- export const TelegramFrontendSchema = z.object({
89
- bot_token: z.string().min(1),
90
- allowed_users: z.array(z.number().int()),
91
- });
92
- export type TelegramFrontendConfig = z.infer<typeof TelegramFrontendSchema>;
93
-
94
- export const SessionBlobSchema = z.object({
95
- r2_get_url: z.string().url(),
96
- content_hash: ContentHash,
97
- uploaded_at: z.string().datetime(),
98
- size_bytes: z.number().int().positive(),
99
- });
100
- export type SessionBlob = z.infer<typeof SessionBlobSchema>;
101
-
102
- export const WorkerBootstrapResponseSchema = z.object({
103
- config: z.object({
104
- worker_id: Uuid,
105
- name: z.string().min(1),
106
- config_etag: ConfigEtag,
107
- llm: LlmProfileSchema,
108
- proxy: ProxyConfigSchema.optional(),
109
- /**
110
- * Effective timezone for this dp-worker. Derived from `proxy.timezone` —
111
- * since v2.5 the dp-worker row no longer has its own timezone column, and
112
- * proxy.timezone is the single source of truth. Undefined only
113
- * when no proxy is bound (debug mode); dp-worker falls back to system tz
114
- * in that case.
115
- */
116
- timezone: z.string().optional(),
117
- /**
118
- * Chrome headless flag (M6). center-managed: the Web UI controls this
119
- * per dp-worker. The host CLI flag `--headless` is now only a fallback
120
- * for local-mode dp-workers that don't go through center bootstrap.
121
- */
122
- headless: z.boolean().default(false),
123
- social_accounts: z.array(SocialAccountSchema).default([]),
124
- telegram: TelegramFrontendSchema.optional(),
125
- /**
126
- * Limits that center enforces but dp-worker also caches for runtime decisions
127
- * (max iterations, task timeout, etc.).
128
- */
129
- limits: z
130
- .object({
131
- max_iterations: z.number().int().positive().default(90),
132
- task_timeout_ms: z.number().int().positive().default(30 * 60 * 1000),
133
- chrome_max_runtime_ms: z
134
- .number()
135
- .int()
136
- .positive()
137
- .default(24 * 60 * 60 * 1000),
138
- })
139
- .default(() => ({
140
- max_iterations: 90,
141
- task_timeout_ms: 30 * 60 * 1000,
142
- chrome_max_runtime_ms: 24 * 60 * 60 * 1000,
143
- })),
144
- }),
145
- session_blob: SessionBlobSchema.optional(),
146
- });
147
- export type WorkerBootstrapResponse = z.infer<typeof WorkerBootstrapResponseSchema>;
148
-
149
- /* ============================================================================
150
- * dp-director register handshake
151
- * ============================================================================ */
152
-
153
- export const DirectorRegisterHandshakeRequestSchema = z.object({
154
- version: z.string().min(1),
155
- host_label: z.string().min(1),
156
- });
157
-
158
- export const DirectorRegisterHandshakeResponseSchema = z.object({
159
- director_id: Uuid,
160
- short_token: z.string().min(1),
161
- ws_url: z.string().url(),
162
- expires_at: z.string().datetime(),
163
- });
164
- export type DirectorRegisterHandshakeResponse = z.infer<
165
- typeof DirectorRegisterHandshakeResponseSchema
166
- >;
167
-
168
- /* ============================================================================
169
- * R2 presigned URL flows
170
- * ============================================================================ */
171
-
172
- export const SessionUploadPresignRequestSchema = z.object({
173
- size_bytes: z.number().int().positive(),
174
- content_hash: ContentHash,
175
- });
176
- export type SessionUploadPresignRequest = z.infer<
177
- typeof SessionUploadPresignRequestSchema
178
- >;
179
-
180
- export const SessionUploadPresignResponseSchema = z.object({
181
- upload_url: z.string().url(),
182
- object_key: z.string().min(1),
183
- expires_at: z.string().datetime(),
184
- });
185
- export type SessionUploadPresignResponse = z.infer<
186
- typeof SessionUploadPresignResponseSchema
187
- >;
188
-
189
- export const SessionFinalizeRequestSchema = z.object({
190
- object_key: z.string().min(1),
191
- content_hash: ContentHash,
192
- size_bytes: z.number().int().positive(),
193
- note: z.string().optional(),
194
- session_preview: OmniFlowSessionSummarySchema.optional(),
195
- });
196
- export type SessionFinalizeRequest = z.infer<
197
- typeof SessionFinalizeRequestSchema
198
- >;
199
-
200
- export const SessionFinalizeResponseSchema = z.object({
201
- id: Uuid,
202
- content_hash: ContentHash,
203
- new_config_etag: ConfigEtag.optional(),
204
- });
205
- export type SessionFinalizeResponse = z.infer<
206
- typeof SessionFinalizeResponseSchema
207
- >;
208
-
209
- export const AttachmentUploadPresignRequestSchema = z.object({
210
- filename: z.string().min(1),
211
- mime: z.string().optional(),
212
- size_bytes: z.number().int().positive(),
213
- });
214
-
215
- export const AttachmentUploadPresignResponseSchema =
216
- SessionUploadPresignResponseSchema;
217
-
218
- export const AttachmentFinalizeRequestSchema = z.object({
219
- object_key: z.string().min(1),
220
- filename: z.string().min(1),
221
- mime: z.string().optional(),
222
- size_bytes: z.number().int().positive(),
223
- });
224
- export type AttachmentFinalizeRequest = z.infer<
225
- typeof AttachmentFinalizeRequestSchema
226
- >;
227
-
228
- export const AttachmentSchema = z.object({
229
- id: Uuid,
230
- filename: z.string().min(1),
231
- mime: z.string().optional(),
232
- size_bytes: z.number().int().positive(),
233
- created_at: z.string().datetime(),
234
- download_url: z.string().url().optional(),
235
- });
236
- export type Attachment = z.infer<typeof AttachmentSchema>;
237
-
238
- /* ============================================================================
239
- * Tasks
240
- * ============================================================================ */
241
-
242
- export const AdhocTaskTargetSchema = z
243
- .object({
244
- worker_ids: z.array(Uuid).default([]),
245
- group_ids: z.array(Uuid).default([]),
246
- })
247
- .refine((v) => v.worker_ids.length + v.group_ids.length > 0, {
248
- message: "must target at least one dp-worker or group",
249
- });
250
-
251
- export const AdhocTaskRequestSchema = z.object({
252
- name: z.string().min(1),
253
- prompt: z.string().min(1),
254
- target: AdhocTaskTargetSchema,
255
- /**
256
- * 0 means dispatch immediately unless dispatch_window_seconds is set.
257
- * >0 picks rand(0, random_delay_seconds) per target only when no dispatch
258
- * window is set.
259
- */
260
- random_delay_seconds: z.number().int().nonnegative().default(0),
261
- /** 0 means no spreading; >0 spreads targets evenly over this dispatch window. */
262
- dispatch_window_seconds: z.number().int().nonnegative().default(0),
263
- priority: z.number().int().default(100),
264
- });
265
- export type AdhocTaskRequest = z.infer<typeof AdhocTaskRequestSchema>;
266
-
267
- export const AdhocTaskBatchResponseSchema = z.object({
268
- batch_id: Uuid,
269
- task_run_ids: z.array(Uuid).min(1),
270
- });
271
-
272
- export const TaskRunSummarySchema = z.object({
273
- id: Uuid,
274
- worker_id: Uuid,
275
- scheduled_task_id: Uuid.optional(),
276
- source: TaskSource,
277
- status: TaskRunStatus,
278
- dispatched_at: z.string().datetime().optional(),
279
- started_at: z.string().datetime().optional(),
280
- finished_at: z.string().datetime().optional(),
281
- error: z.string().optional(),
282
- result_summary: z.string().optional(),
283
- parent_adhoc_task_id: Uuid.optional(),
284
- });
285
- export type TaskRunSummary = z.infer<typeof TaskRunSummarySchema>;
286
-
287
- export const TaskRunListResponseSchema = z.object({
288
- items: z.array(TaskRunSummarySchema),
289
- next_cursor: z.string().optional(),
290
- });
291
-
292
- /* ============================================================================
293
- * Scheduled tasks CRUD
294
- * ============================================================================ */
295
-
296
- export const ScheduledTaskBodySchema = z.object({
297
- name: z.string().min(1),
298
- cron: z.string().min(1),
299
- timezone: z.string().optional(),
300
- prompt: z.string().min(1),
301
- random_delay_seconds: z.number().int().nonnegative().default(0),
302
- enabled: z.boolean().default(true),
303
- });
304
- export type ScheduledTaskBody = z.infer<typeof ScheduledTaskBodySchema>;
305
-
306
- export const ScheduledTaskResponseSchema = ScheduledTaskBodySchema.extend({
307
- id: Uuid,
308
- worker_id: Uuid,
309
- last_run_at: z.string().datetime().optional(),
310
- last_status: z.enum(["ok", "error"]).optional(),
311
- run_count: z.number().int().nonnegative().default(0),
312
- success_count: z.number().int().nonnegative().default(0),
313
- created_at: z.string().datetime(),
314
- updated_at: z.string().datetime(),
315
- });
316
-
317
- /* ============================================================================
318
- * Chat
319
- * ============================================================================ */
320
-
321
- export const ChatSendRequestSchema = z
322
- .object({
323
- content: z.string().default(""),
324
- attachment_ids: z.array(Uuid).default([]),
325
- })
326
- .refine(
327
- (body) => body.content.trim().length > 0 || body.attachment_ids.length > 0,
328
- {
329
- message: "content or attachment_ids required",
330
- path: ["content"],
331
- }
332
- );
333
-
334
- export const ChatHistoryItemSchema = z.object({
335
- id: Uuid,
336
- chat_id: Uuid,
337
- role: z.string(),
338
- content_json: z.unknown(),
339
- attachment_ids: z.array(Uuid).default([]),
340
- attachments: z.array(AttachmentSchema).default([]),
341
- task_run_id: Uuid.optional(),
342
- sender_user_id: Uuid.optional(),
343
- created_at: z.string().datetime(),
344
- });
345
-
346
- export const ChatHistoryResponseSchema = z.object({
347
- items: z.array(ChatHistoryItemSchema),
348
- next_cursor: z.string().optional(),
349
- });
350
-
351
- /* ============================================================================
352
- * Groups CRUD (M7 Phase A)
353
- * ============================================================================ */
354
-
355
- export const GroupBodySchema = z.object({
356
- name: z.string().min(1).max(120),
357
- description: z.string().max(1000).optional(),
358
- });
359
- export type GroupBody = z.infer<typeof GroupBodySchema>;
360
-
361
- export const GroupPatchSchema = z
362
- .object({
363
- name: z.string().min(1).max(120).optional(),
364
- description: z.string().max(1000).nullable().optional(),
365
- })
366
- .refine((v) => Object.keys(v).length > 0, {
367
- message: "patch body must contain at least one field",
368
- });
369
- export type GroupPatch = z.infer<typeof GroupPatchSchema>;
370
-
371
- export const GroupMemberMutationSchema = z.object({
372
- worker_ids: z.array(Uuid).min(1).max(200),
373
- });
374
- export type GroupMemberMutation = z.infer<typeof GroupMemberMutationSchema>;
375
-
376
- export const GroupListItemSchema = z.object({
377
- id: Uuid,
378
- name: z.string(),
379
- description: z.string().optional(),
380
- member_count: z.number().int().nonnegative(),
381
- created_at: z.string().datetime(),
382
- updated_at: z.string().datetime(),
383
- });
384
-
385
- export const GroupDetailSchema = GroupListItemSchema.extend({
386
- member_worker_ids: z.array(Uuid),
387
- });
388
-
389
- /* ============================================================================
390
- * Status / list endpoints (subset)
391
- * ============================================================================ */
392
-
393
- export const WorkerListItemSchema = z.object({
394
- id: Uuid,
395
- name: z.string(),
396
- director_id: Uuid.optional(),
397
- status: EffectiveWorkerStatus,
398
- current_task_id: Uuid.optional(),
399
- process_status: ProcessStatus.optional(),
400
- runtime_status: RuntimeStatus.optional(),
401
- process_observed_at: z.string().datetime().optional(),
402
- runtime_observed_at: z.string().datetime().optional(),
403
- last_heartbeat_at: z.string().datetime().optional(),
404
- effective_status: EffectiveWorkerStatus.optional(),
405
- });
406
-
407
- export const WorkerListResponseSchema = z.object({
408
- items: z.array(WorkerListItemSchema),
409
- });