dp-worker 0.1.19 → 0.1.21

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 (92) hide show
  1. package/builtin-skills/x.md +27 -0
  2. package/dist/bird/bird-frontend.d.ts +58 -0
  3. package/dist/bird/bird-frontend.js +110 -0
  4. package/dist/bird/bird-frontend.js.map +1 -0
  5. package/dist/bird/credentials.d.ts +36 -0
  6. package/dist/bird/credentials.js +82 -0
  7. package/dist/bird/credentials.js.map +1 -0
  8. package/dist/bird/ops.d.ts +103 -0
  9. package/dist/bird/ops.js +523 -0
  10. package/dist/bird/ops.js.map +1 -0
  11. package/dist/bird/sidecar-entry.d.ts +25 -0
  12. package/dist/bird/sidecar-entry.js +192 -0
  13. package/dist/bird/sidecar-entry.js.map +1 -0
  14. package/dist/bird/sidecar-host.d.ts +54 -0
  15. package/dist/bird/sidecar-host.js +318 -0
  16. package/dist/bird/sidecar-host.js.map +1 -0
  17. package/dist/bird/socks-connector.d.ts +26 -0
  18. package/dist/bird/socks-connector.js +49 -0
  19. package/dist/bird/socks-connector.js.map +1 -0
  20. package/dist/browser/cloakbrowser-backend.js +10 -27
  21. package/dist/browser/cloakbrowser-backend.js.map +1 -1
  22. package/dist/chrome-extension/omni-flow/manifest.json +1 -1
  23. package/dist/config/center-config.d.ts +8 -0
  24. package/dist/config/center-config.js +1 -0
  25. package/dist/config/center-config.js.map +1 -1
  26. package/dist/index.js +25 -0
  27. package/dist/index.js.map +1 -1
  28. package/node_modules/dp-shared/dist/admin-broadcast.d.ts +1 -1
  29. package/node_modules/dp-shared/dist/admin-broadcast.d.ts.map +1 -1
  30. package/node_modules/dp-shared/dist/bird-contracts.d.ts +487 -0
  31. package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -0
  32. package/node_modules/dp-shared/dist/bird-contracts.js +381 -0
  33. package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -0
  34. package/node_modules/dp-shared/dist/configs-contracts.d.ts +11 -1
  35. package/node_modules/dp-shared/dist/configs-contracts.d.ts.map +1 -1
  36. package/node_modules/dp-shared/dist/configs-contracts.js +43 -0
  37. package/node_modules/dp-shared/dist/configs-contracts.js.map +1 -1
  38. package/node_modules/dp-shared/dist/index.d.ts +2 -0
  39. package/node_modules/dp-shared/dist/index.d.ts.map +1 -1
  40. package/node_modules/dp-shared/dist/index.js +2 -0
  41. package/node_modules/dp-shared/dist/index.js.map +1 -1
  42. package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts +9 -3
  43. package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts.map +1 -1
  44. package/node_modules/dp-shared/dist/post-drafts-contracts.js +34 -0
  45. package/node_modules/dp-shared/dist/post-drafts-contracts.js.map +1 -1
  46. package/node_modules/dp-shared/dist/promo-contracts.d.ts +651 -0
  47. package/node_modules/dp-shared/dist/promo-contracts.d.ts.map +1 -0
  48. package/node_modules/dp-shared/dist/promo-contracts.js +566 -0
  49. package/node_modules/dp-shared/dist/promo-contracts.js.map +1 -0
  50. package/node_modules/dp-shared/dist/rest-contracts.d.ts +73 -0
  51. package/node_modules/dp-shared/dist/rest-contracts.d.ts.map +1 -1
  52. package/node_modules/dp-shared/dist/rest-contracts.js +70 -0
  53. package/node_modules/dp-shared/dist/rest-contracts.js.map +1 -1
  54. package/node_modules/dp-shared/dist/smart-money-contracts.d.ts +86 -0
  55. package/node_modules/dp-shared/dist/smart-money-contracts.d.ts.map +1 -0
  56. package/node_modules/dp-shared/dist/smart-money-contracts.js +71 -0
  57. package/node_modules/dp-shared/dist/smart-money-contracts.js.map +1 -0
  58. package/node_modules/dp-shared/dist/task-history-contracts.d.ts +2 -0
  59. package/node_modules/dp-shared/dist/task-history-contracts.d.ts.map +1 -1
  60. package/node_modules/dp-shared/dist/task-history-contracts.js +2 -0
  61. package/node_modules/dp-shared/dist/task-history-contracts.js.map +1 -1
  62. package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts +7 -0
  63. package/node_modules/dp-shared/dist/worker-detail-contracts.d.ts.map +1 -1
  64. package/node_modules/dp-shared/dist/worker-detail-contracts.js +9 -0
  65. package/node_modules/dp-shared/dist/worker-detail-contracts.js.map +1 -1
  66. package/node_modules/dp-shared/dist/ws-protocol.d.ts +52 -0
  67. package/node_modules/dp-shared/dist/ws-protocol.d.ts.map +1 -1
  68. package/node_modules/dp-shared/dist/ws-protocol.js +37 -0
  69. package/node_modules/dp-shared/dist/ws-protocol.js.map +1 -1
  70. package/package.json +9 -4
  71. package/scripts/prepack-bundle-shared.mjs +67 -0
  72. package/dist/browser/proxy-relay.d.ts +0 -50
  73. package/dist/browser/proxy-relay.js +0 -50
  74. package/dist/browser/proxy-relay.js.map +0 -1
  75. package/node_modules/dp-shared/src/admin-broadcast.ts +0 -41
  76. package/node_modules/dp-shared/src/audit-contracts.ts +0 -33
  77. package/node_modules/dp-shared/src/auto-post-contracts.ts +0 -206
  78. package/node_modules/dp-shared/src/cloak-contracts.ts +0 -110
  79. package/node_modules/dp-shared/src/configs-contracts.ts +0 -249
  80. package/node_modules/dp-shared/src/db-rows.ts +0 -303
  81. package/node_modules/dp-shared/src/deploy-contracts.ts +0 -38
  82. package/node_modules/dp-shared/src/domain.ts +0 -124
  83. package/node_modules/dp-shared/src/fingerprint.ts +0 -21
  84. package/node_modules/dp-shared/src/identities.ts +0 -38
  85. package/node_modules/dp-shared/src/index.ts +0 -30
  86. package/node_modules/dp-shared/src/omni-flow-cookie.ts +0 -272
  87. package/node_modules/dp-shared/src/omni-flow-session.ts +0 -79
  88. package/node_modules/dp-shared/src/post-drafts-contracts.ts +0 -807
  89. package/node_modules/dp-shared/src/rest-contracts.ts +0 -592
  90. package/node_modules/dp-shared/src/task-history-contracts.ts +0 -124
  91. package/node_modules/dp-shared/src/worker-detail-contracts.ts +0 -236
  92. package/node_modules/dp-shared/src/ws-protocol.ts +0 -495
@@ -1,206 +0,0 @@
1
- import { z } from "zod/v4";
2
- import { Uuid } from "./domain.js";
3
-
4
- /**
5
- * 自动运营(Auto-Pilot Content Ops)— 一卡一号(campaign)模型。
6
- *
7
- * 一张「运营卡片」= 只服务一个垂直账号(worker):一套主题/风格/排期/阈值。到点时该
8
- * 账号从共享池按主题(同义词扩展 + LLM 相关性)挑一篇够质量、没发过、够新鲜的文章,
9
- * 按 persona + 卡片风格(钩子/语气/自由说明)洗稿后自动发帖。可建多张卡;一个账号至多
10
- * 属于一张卡。
11
- *
12
- * 发送复用现有 insertContentPostDispatch + post_dispatch_log;主题匹配、源文章级去重
13
- * (worker_article_log)、风格洗稿是本模块新增。dry_run 默认开(先预演),enabled 默认关。
14
- */
15
-
16
- /** 一次自动运营触发的结局。 */
17
- export const AutoPostRunStatus = z.enum([
18
- "running", // 已抢占 slot、处理中(短暂中间态)
19
- "posted",
20
- "dry_run",
21
- "skipped_no_match",
22
- "skipped_capped",
23
- "skipped_unavailable",
24
- "error",
25
- ]);
26
- export type AutoPostRunStatus = z.infer<typeof AutoPostRunStatus>;
27
-
28
- /** 卡片的配置字段(不含账号/名称/id),create/patch 共用。 */
29
- const campaignConfigFields = {
30
- /** 默认每天 5 次(9/12/15/18/21,账号当地时间),像真人分散在白天。 */
31
- cron: z.string().default("0 9,12,15,18,21 * * *"),
32
- timezone: z.string().nullable().default(null),
33
- /** 文章形态偏好:short 只发短推 / long 只发长文 / both 都可(默认)。 */
34
- format: z.enum(["short", "long", "both"]).default("both"),
35
- interest_tags: z.array(z.string()).default([]),
36
- extra_keywords: z.string().default(""),
37
- /** 账号风格 — 钩子风格预设(null=自动),同草稿箱的钩子风格维度。 */
38
- hook_style: z.string().nullable().default(null),
39
- /** 账号风格 — 语气(null=自动):casual 更口语 / professional 更专业。 */
40
- tone: z.enum(["casual", "professional"]).nullable().default(null),
41
- /** 账号风格 — 一条自由风格说明,拼进洗稿 prompt。 */
42
- style_note: z.string().default(""),
43
- /* ── 发帖后水军互动(默认关)────────────────────────────────────── */
44
- /** 1=发帖成功后从水军群抽号互动。 */
45
- engage_enabled: z.boolean().default(false),
46
- /** 水军群 id;null=没选=不互动。@deprecated 用 engage_group_ids。 */
47
- engage_group_id: z.string().nullable().default(null),
48
- /** 水军群 id 列表:从这些群的并集里随机抽号(扩充水军)。空=回退到 engage_group_id。 */
49
- engage_group_ids: z.array(z.string()).default([]),
50
- /** 每次抽多少个水军(N)。 */
51
- engage_count: z.number().int().min(1).max(50).default(5),
52
- /** 互动动作集。 */
53
- engage_actions: z.array(z.enum(["like", "repost", "reply", "quote", "follow"])).default(["like", "repost", "reply"]),
54
- /** N 中额外做评论的个数(其余只赞+转),≤N。 */
55
- engage_reply_count: z.number().int().min(0).max(50).default(2),
56
- /** 评论文案来源:fast=水军自写 / llm=中心生成。 */
57
- engage_reply_mode: z.enum(["fast", "llm"]).default("fast"),
58
- /** 错峰窗口(分钟)。 */
59
- engage_window_minutes: z.number().int().min(1).max(1440).default(30),
60
- relevance_floor: z.number().int().min(0).max(100).default(60),
61
- quality_floor: z.number().int().min(0).max(100).default(55),
62
- /** 默认每天 5 篇,对齐 5 次触发(真人活跃账号量级)。 */
63
- daily_cap: z.number().int().min(1).max(20).default(5),
64
- /** 默认 2h:必须 < cron 触发间隔(3h),否则会挡掉后续触发。 */
65
- min_interval_minutes: z.number().int().min(0).max(10080).default(120),
66
- freshness_max_hours: z.number().int().min(1).max(720).default(72),
67
- /** 精确匹配:兴趣标签按字面匹配,关闭同义词/LLM/模糊扩展。用于垂类精确号
68
- * (如链上安全/资金流/AI 基建股)—— 只吃自己那类文章,不越界到通用池。 */
69
- exact_match: z.boolean().default(false),
70
- diversify: z.boolean().default(true),
71
- allow_shared_article: z.boolean().default(true),
72
- dry_run: z.boolean().default(true),
73
- /** 默认 60 秒错峰(同时区一批号不完全同秒发);号多想更分散可调大。 */
74
- random_delay_seconds: z.number().int().min(0).max(86400).default(60),
75
- llm_profile_id: z.string().nullable().default(null),
76
- };
77
-
78
- /** 完整卡片(GET 详情)。一卡一号 → 直接带上所属账号。 */
79
- export const AutoPostCampaignSchema = z.object({
80
- id: z.string(),
81
- name: z.string(),
82
- enabled: z.boolean().default(false),
83
- ...campaignConfigFields,
84
- /** 这张卡服务的账号(worker)。 */
85
- worker_id: z.string().nullable().default(null),
86
- worker_name: z.string().nullable().default(null),
87
- username: z.string().nullable().default(null),
88
- /** 创建者 user id(归属:只有创建者或管理员能改)。 */
89
- created_by: z.string().nullable().default(null),
90
- /* GET-only 观测 */
91
- worker_count: z.number().int().default(0),
92
- /** 下次触发的样例(按账号时区算,概览用)。 */
93
- next_fire_at: z.string().nullable().optional(),
94
- created_at: z.string().optional(),
95
- updated_at: z.string().optional(),
96
- });
97
- export type AutoPostCampaign = z.infer<typeof AutoPostCampaignSchema>;
98
-
99
- /** 新建 / 全量更新卡片的请求体(单账号)。 */
100
- export const AutoPostCampaignUpsertSchema = z.object({
101
- name: z.string().min(1).max(120),
102
- enabled: z.boolean().optional(),
103
- ...campaignConfigFields,
104
- /** 这张卡服务的账号(worker)。选进来即从它原来的卡移出(一号一卡)。 */
105
- worker_id: Uuid,
106
- });
107
- export type AutoPostCampaignUpsert = z.infer<typeof AutoPostCampaignUpsertSchema>;
108
-
109
- /** 列表项(自动运营页卡片)。 */
110
- export const AutoPostCampaignListItemSchema = z.object({
111
- id: z.string(),
112
- name: z.string(),
113
- enabled: z.boolean(),
114
- dry_run: z.boolean(),
115
- cron: z.string(),
116
- interest_tags: z.array(z.string()).default([]),
117
- format: z.enum(["short", "long", "both"]).default("both"),
118
- hook_style: z.string().nullable().default(null),
119
- tone: z.enum(["casual", "professional"]).nullable().default(null),
120
- engage_enabled: z.boolean().default(false),
121
- engage_count: z.number().int().default(5),
122
- worker_id: z.string().nullable().default(null),
123
- worker_name: z.string().nullable().default(null),
124
- username: z.string().nullable().default(null),
125
- created_by: z.string().nullable().default(null),
126
- worker_count: z.number().int().default(0),
127
- /** 今日已发(该账号 24h)。 */
128
- posted_today: z.number().int().default(0),
129
- last_status: AutoPostRunStatus.nullable().default(null),
130
- last_ran_at: z.string().nullable().default(null),
131
- next_fire_at: z.string().nullable().default(null),
132
- });
133
- export type AutoPostCampaignListItem = z.infer<typeof AutoPostCampaignListItemSchema>;
134
-
135
- export const AutoPostCampaignListResponseSchema = z.object({
136
- items: z.array(AutoPostCampaignListItemSchema),
137
- });
138
- export type AutoPostCampaignListResponse = z.infer<typeof AutoPostCampaignListResponseSchema>;
139
-
140
- /** 一次自动运营触发的审计记录。 */
141
- export const AutoPostRunSchema = z.object({
142
- id: z.number().int(),
143
- campaign_id: z.string().nullable().default(null),
144
- worker_id: z.string(),
145
- worker_name: z.string().nullable().default(null),
146
- fire_at: z.string(),
147
- ran_at: z.string(),
148
- status: AutoPostRunStatus,
149
- selected_draft_id: z.string().nullable().default(null),
150
- selected_source_url: z.string().nullable().default(null),
151
- selected_hook: z.string().nullable().default(null),
152
- relevance_score: z.number().int().nullable().default(null),
153
- quality_score: z.number().int().nullable().default(null),
154
- degrade_level: z.number().int().default(0),
155
- candidates_scanned: z.number().int().default(0),
156
- task_run_id: z.string().nullable().default(null),
157
- /** 发出去那条推的链接(发帖成功后从 agent 回报解析)。 */
158
- posted_url: z.string().nullable().default(null),
159
- note: z.string().nullable().default(null),
160
- });
161
- export type AutoPostRun = z.infer<typeof AutoPostRunSchema>;
162
-
163
- export const AutoPostRunsResponseSchema = z.object({ runs: z.array(AutoPostRunSchema) });
164
- export type AutoPostRunsResponse = z.infer<typeof AutoPostRunsResponseSchema>;
165
-
166
- /** 预演:现在跑一遍某 worker 的选文+洗稿,返回"会发什么",不派发。 */
167
- export const AutoPostPreviewResultSchema = z.object({
168
- matched: z.boolean(),
169
- selected_draft_id: z.string().nullable().default(null),
170
- source_url: z.string().nullable().default(null),
171
- source_name: z.string().nullable().default(null),
172
- hook_title: z.string().nullable().default(null),
173
- tailored_text: z.string().nullable().default(null),
174
- relevance_score: z.number().int().nullable().default(null),
175
- quality_score: z.number().int().nullable().default(null),
176
- degrade_level: z.number().int().default(0),
177
- candidates_scanned: z.number().int().default(0),
178
- note: z.string().nullable().default(null),
179
- });
180
- export type AutoPostPreviewResult = z.infer<typeof AutoPostPreviewResultSchema>;
181
-
182
- /** 一个可选的主题标签(供任务主题多选做候选建议)。 */
183
- export const TagSuggestionSchema = z.object({
184
- slug: z.string(),
185
- name: z.string(),
186
- kind: z.string(),
187
- count: z.number().int().default(0),
188
- });
189
- export type TagSuggestion = z.infer<typeof TagSuggestionSchema>;
190
-
191
- export const TagSuggestionsResponseSchema = z.object({ tags: z.array(TagSuggestionSchema) });
192
- export type TagSuggestionsResponse = z.infer<typeof TagSuggestionsResponseSchema>;
193
-
194
- /** 供任务编辑器挑选 worker 的候选。campaigns = 该号当前所属的任务(可多个)。 */
195
- export const AutoPostWorkerOptionSchema = z.object({
196
- worker_id: z.string(),
197
- worker_name: z.string().nullable().default(null),
198
- username: z.string().nullable().default(null),
199
- campaigns: z.array(z.object({ id: z.string(), name: z.string() })).default([]),
200
- });
201
- export type AutoPostWorkerOption = z.infer<typeof AutoPostWorkerOptionSchema>;
202
-
203
- export const AutoPostWorkerOptionsResponseSchema = z.object({
204
- workers: z.array(AutoPostWorkerOptionSchema),
205
- });
206
- export type AutoPostWorkerOptionsResponse = z.infer<typeof AutoPostWorkerOptionsResponseSchema>;
@@ -1,110 +0,0 @@
1
- import { z } from "zod/v4";
2
- import { ContentHash, Uuid } from "./domain.js";
3
-
4
- /**
5
- * dp-cloak ↔ dp-center contracts.
6
- *
7
- * dp-cloak is the desktop fingerprint browser. In "cs mode" it logs in with the
8
- * same dipclaw-cs user account (POST /api/auth/login → HS256 bearer, reused as-is)
9
- * and pulls a worker's browser session on demand. The session is delivered
10
- * ENCRYPTED and only ever decrypted in the sidecar's memory — it is never written
11
- * to disk and cannot be exported.
12
- *
13
- * Envelope-encryption scheme (per pull, ephemeral keys both sides):
14
- * 1. dp-cloak generates an ephemeral X25519 keypair, sends the raw public key.
15
- * 2. center generates its own ephemeral X25519 keypair, does ECDH with the
16
- * client key, HKDF-SHA256 → 32-byte AES key, AES-256-GCM encrypts the
17
- * OmniFlow session JSON.
18
- * 3. center returns its ephemeral public key + nonce + ciphertext; the client
19
- * derives the same key and decrypts in memory.
20
- * The key never lands on disk and is scoped to one pull. This protects the
21
- * session at rest (dp-cloak disk), in transit (beyond TLS), and lets center
22
- * refuse issuance when the account is disabled. It does NOT (and cannot) stop a
23
- * local machine-owner from dumping process memory — that is out of scope.
24
- */
25
-
26
- /** HKDF `info` string binding the derived key to this protocol version. */
27
- export const CLOAK_SESSION_HKDF_INFO = "dipclaw:cloak:session:v1";
28
-
29
- /** Algorithm identifier echoed in the pull response. */
30
- export const CLOAK_SESSION_ALG = "x25519-hkdf-sha256-aes256gcm";
31
-
32
- /* ============================================================================
33
- * GET /api/cloak/workers — list workers dp-cloak can pull
34
- * (requireUser; any authenticated non-disabled account sees all workers)
35
- * ============================================================================ */
36
-
37
- export const CloakWorkerListItemSchema = z.object({
38
- worker_id: Uuid,
39
- name: z.string(),
40
- /** Bound identity (the persona the worker logs in as); absent if unbound. */
41
- identity_name: z.string().optional(),
42
- identity_email: z.string().optional(),
43
- /** True when a browser session blob exists for this worker's identity. */
44
- has_session: z.boolean(),
45
- /** Current session content hash (sha256 hex), if any. Lets a client detect a
46
- * rotation (hash changed) it may have missed while its WS was down. */
47
- content_hash: z.string().optional(),
48
- /** Effective proxy egress timezone (IANA), from the bound proxy — the region
49
- * the browser will spoof. Display only. */
50
- timezone: z.string().optional(),
51
- /** Bound proxy host (IP or hostname) and port — display only, no credentials. */
52
- proxy_host: z.string().optional(),
53
- proxy_port: z.number().int().optional(),
54
- /** Effective fingerprint seed = cloakFingerprintSeed(worker_id); same device as cloud. */
55
- fingerprint_seed: z.number().int(),
56
- /** Effective worker status string, for display only. */
57
- status: z.string().optional(),
58
- });
59
- export type CloakWorkerListItem = z.infer<typeof CloakWorkerListItemSchema>;
60
-
61
- export const CloakWorkerListResponseSchema = z.object({
62
- items: z.array(CloakWorkerListItemSchema),
63
- });
64
- export type CloakWorkerListResponse = z.infer<typeof CloakWorkerListResponseSchema>;
65
-
66
- /* ============================================================================
67
- * POST /api/cloak/session/pull — encrypted session delivery
68
- * ============================================================================ */
69
-
70
- export const CloakSessionPullRequestSchema = z.object({
71
- worker_id: Uuid,
72
- /** Base64 of the raw 32-byte X25519 public key generated for this pull. */
73
- client_ephemeral_pubkey: z.string().min(1),
74
- });
75
- export type CloakSessionPullRequest = z.infer<typeof CloakSessionPullRequestSchema>;
76
-
77
- export const CloakSessionPullResponseSchema = z.object({
78
- worker_id: Uuid,
79
- worker_name: z.string(),
80
- /** Display label for the account/identity behind this session. */
81
- identity_label: z.string().optional(),
82
- alg: z.literal(CLOAK_SESSION_ALG),
83
- /** Base64 of center's raw 32-byte X25519 ephemeral public key. */
84
- server_ephemeral_pubkey: z.string().min(1),
85
- /** Base64 of the 12-byte AES-GCM nonce. */
86
- nonce: z.string().min(1),
87
- /** Base64 of AES-256-GCM ciphertext (GCM tag appended) over the OmniFlow JSON. */
88
- ciphertext: z.string().min(1),
89
- /** SHA-256 hex of the plaintext OmniFlow JSON, for post-decrypt integrity check. */
90
- content_hash: ContentHash,
91
- /** Same seed the cloud worker launches with — dp-cloak passes --fingerprint=<this>. */
92
- fingerprint_seed: z.number().int(),
93
- });
94
- export type CloakSessionPullResponse = z.infer<typeof CloakSessionPullResponseSchema>;
95
-
96
- /* ============================================================================
97
- * GET /api/cloak/heartbeat — poll fallback for revocation
98
- * (requireUser; returns 403 user_disabled / 401 invalid_jwt once the account is
99
- * disabled or deleted, which dp-cloak treats as "wipe everything + logout")
100
- * ============================================================================ */
101
-
102
- export const CloakHeartbeatResponseSchema = z.object({
103
- ok: z.literal(true),
104
- user: z.object({
105
- id: Uuid,
106
- email: z.string(),
107
- role: z.string(),
108
- }),
109
- });
110
- export type CloakHeartbeatResponse = z.infer<typeof CloakHeartbeatResponseSchema>;
@@ -1,249 +0,0 @@
1
- import { z } from "zod/v4";
2
- import {
3
- DpWorkerRuntimeMode,
4
- DpWorkerUpgradeStatus,
5
- EffectiveDirectorStatus,
6
- IanaTimezone,
7
- LlmProtocol,
8
- ProxyProtocol,
9
- } from "./domain.js";
10
-
11
- /**
12
- * Request/response contracts for the `/configs/*` REST family — LLM profile
13
- * and proxy CRUD that the Web UI drives. Kept distinct from
14
- * `rest-contracts.ts` so the wave-1 UI work doesn't touch the
15
- * already-stable bootstrap/task schemas.
16
- *
17
- * Notes:
18
- * - LLM profile responses include `api_key` / `image_api_key` in plaintext
19
- * for the admin UI's reveal/copy affordance (internal-use project; see
20
- * CLAUDE.md). dp-worker bootstrap reads the same secrets via a separate
21
- * schema (`LlmProfileSchema` in rest-contracts.ts).
22
- * - Proxy responses include `password` in plaintext for the same reason
23
- * (admin UI reveal/copy).
24
- * - `base_url` is sanitized server-side per the project convention (strip
25
- * trailing `/v1`); the client can send either form.
26
- */
27
-
28
- /* ============================================================================
29
- * LLM profiles
30
- * ============================================================================ */
31
-
32
- export const LlmProfileBodySchema = z.object({
33
- name: z.string().min(1).max(120),
34
- protocol: LlmProtocol,
35
- base_url: z.string().min(1).max(500),
36
- api_key: z.string().min(1),
37
- model: z.string().min(1).max(120),
38
- image_model: z.string().min(1).max(120).optional(),
39
- image_api_key: z.string().min(1).optional(),
40
- image_size: z.string().min(1).max(40).optional(),
41
- });
42
- export type LlmProfileBody = z.infer<typeof LlmProfileBodySchema>;
43
-
44
- export const LlmProfilePatchSchema = z
45
- .object({
46
- name: z.string().min(1).max(120).optional(),
47
- protocol: LlmProtocol.optional(),
48
- base_url: z.string().min(1).max(500).optional(),
49
- api_key: z.string().min(1).optional(),
50
- model: z.string().min(1).max(120).optional(),
51
- image_model: z.string().min(1).max(120).nullable().optional(),
52
- image_api_key: z.string().min(1).nullable().optional(),
53
- image_size: z.string().min(1).max(40).nullable().optional(),
54
- })
55
- .refine((v) => Object.keys(v).length > 0, {
56
- message: "patch body must contain at least one field",
57
- });
58
- export type LlmProfilePatch = z.infer<typeof LlmProfilePatchSchema>;
59
-
60
- export const LlmProfileListItemSchema = z.object({
61
- id: z.string().uuid(),
62
- name: z.string(),
63
- protocol: LlmProtocol,
64
- base_url: z.string(),
65
- api_key: z.string(),
66
- model: z.string(),
67
- image_model: z.string().optional(),
68
- image_api_key: z.string().optional(),
69
- image_size: z.string().optional(),
70
- in_use_by_worker_count: z.number().int().nonnegative(),
71
- created_at: z.string().datetime(),
72
- updated_at: z.string().datetime(),
73
- });
74
- export type LlmProfileListItem = z.infer<typeof LlmProfileListItemSchema>;
75
-
76
- export const LlmProfileTestResultSchema = z.object({
77
- ok: z.boolean(),
78
- latency_ms: z.number().int().nonnegative(),
79
- detail: z.string(),
80
- });
81
- export type LlmProfileTestResult = z.infer<
82
- typeof LlmProfileTestResultSchema
83
- >;
84
-
85
- /* ============================================================================
86
- * Proxies
87
- * ============================================================================ */
88
-
89
- export const ProxyBodySchema = z.object({
90
- label: z.string().min(1).max(120),
91
- protocol: ProxyProtocol,
92
- host: z.string().min(1).max(255),
93
- port: z.number().int().positive().max(65535),
94
- username: z.string().min(1).max(255),
95
- password: z.string().min(1),
96
- timezone: IanaTimezone,
97
- note: z.string().max(2000).optional(),
98
- });
99
- export type ProxyBody = z.infer<typeof ProxyBodySchema>;
100
-
101
- export const ProxyPatchSchema = z
102
- .object({
103
- label: z.string().min(1).max(120).optional(),
104
- protocol: ProxyProtocol.optional(),
105
- host: z.string().min(1).max(255).optional(),
106
- port: z.number().int().positive().max(65535).optional(),
107
- username: z.string().min(1).max(255).optional(),
108
- password: z.string().min(1).optional(),
109
- timezone: IanaTimezone.optional(),
110
- note: z.string().max(2000).nullable().optional(),
111
- })
112
- .refine((v) => Object.keys(v).length > 0, {
113
- message: "patch body must contain at least one field",
114
- });
115
- export type ProxyPatch = z.infer<typeof ProxyPatchSchema>;
116
-
117
- export const ProxyListItemSchema = z.object({
118
- id: z.string().uuid(),
119
- label: z.string(),
120
- protocol: ProxyProtocol,
121
- host: z.string(),
122
- port: z.number().int().positive(),
123
- username: z.string(),
124
- password: z.string(),
125
- timezone: IanaTimezone,
126
- note: z.string().optional(),
127
- in_use_by_worker_id: z.string().uuid().optional(),
128
- in_use_by_worker_name: z.string().optional(),
129
- bound_worker_id: z.string().uuid().optional(),
130
- bound_worker_name: z.string().optional(),
131
- bound_identity_id: z.string().uuid().optional(),
132
- bound_identity_name: z.string().optional(),
133
- /** How many identities currently have this proxy bound. */
134
- bound_identity_count: z.number().int().nonnegative().default(0),
135
- created_at: z.string().datetime(),
136
- updated_at: z.string().datetime(),
137
- });
138
- export type ProxyListItem = z.infer<typeof ProxyListItemSchema>;
139
-
140
- export const ProxyTestResultSchema = z.object({
141
- ok: z.boolean(),
142
- latency_ms: z.number().int().nonnegative(),
143
- detail: z.string(),
144
- });
145
- export type ProxyTestResult = z.infer<typeof ProxyTestResultSchema>;
146
-
147
- /**
148
- * Auto-detect timezone for a (not-yet-saved) proxy. The center worker first
149
- * routes a geo-IP lookup *through* the proxy to learn its real exit IP/zone,
150
- * falling back to a direct lookup of the entered host. Body carries connection
151
- * details inline because detection happens in the create/edit drawer before the
152
- * proxy is persisted.
153
- */
154
- export const DetectTimezoneBodySchema = z.object({
155
- protocol: ProxyProtocol,
156
- host: z.string().min(1).max(255),
157
- port: z.number().int().positive().max(65535),
158
- username: z.string().min(1).max(255),
159
- password: z.string().min(1),
160
- });
161
- export type DetectTimezoneBody = z.infer<typeof DetectTimezoneBodySchema>;
162
-
163
- export const DetectTimezoneResultSchema = z.object({
164
- ok: z.boolean(),
165
- /** IANA zone, e.g. "Asia/Tokyo". */
166
- timezone: z.string().optional(),
167
- /** Exit IP seen by the geo-IP service (only meaningful for source="proxy"). */
168
- exit_ip: z.string().optional(),
169
- /** ISO country code, e.g. "JP". */
170
- country: z.string().optional(),
171
- /** Where the zone came from: through the proxy, the entered host, or nothing. */
172
- source: z.enum(["proxy", "host", "none"]),
173
- /** One-line diagnostic. */
174
- detail: z.string(),
175
- });
176
- export type DetectTimezoneResult = z.infer<typeof DetectTimezoneResultSchema>;
177
-
178
- /* ============================================================================
179
- * dp-directors
180
- * ============================================================================ */
181
-
182
- export const DirectorListItemSchema = z.object({
183
- id: z.string().uuid(),
184
- name: z.string(),
185
- host_label: z.string(),
186
- // Optional: the server strips api_key for non-admins on protected directors.
187
- api_key: z.string().optional(),
188
- status: EffectiveDirectorStatus,
189
- // Admin-lock: when true only admins may edit/delete/upgrade or read api_key.
190
- is_protected: z.boolean().default(false),
191
- max_concurrent_tasks: z.number().int().nonnegative().default(0),
192
- last_heartbeat_at: z.string().datetime().optional(),
193
- version: z.string().optional(),
194
- dp_worker_version: z.string().optional(),
195
- dp_worker_latest_version: z.string().optional(),
196
- dp_worker_runtime_mode: DpWorkerRuntimeMode.optional(),
197
- dp_worker_upgrade_status: DpWorkerUpgradeStatus.optional(),
198
- dp_worker_upgrade_message: z.string().optional(),
199
- dp_worker_upgrade_started_at: z.string().datetime().optional(),
200
- dp_worker_upgrade_finished_at: z.string().datetime().optional(),
201
- created_at: z.string().datetime(),
202
- updated_at: z.string().datetime(),
203
- });
204
- export type DirectorListItem = z.infer<typeof DirectorListItemSchema>;
205
-
206
- export const DirectorCreateBodySchema = z.object({
207
- name: z.string().trim().min(1),
208
- host_label: z.string().trim().min(1),
209
- api_key: z.string().trim().min(1).optional(),
210
- max_concurrent_tasks: z.number().int().nonnegative().default(0),
211
- // Admin-only in effect: the handler forces false for non-admin callers.
212
- is_protected: z.boolean().optional(),
213
- });
214
- export type DirectorCreateBody = z.infer<typeof DirectorCreateBodySchema>;
215
-
216
- export const DirectorPatchSchema = z
217
- .object({
218
- name: z.string().trim().min(1).optional(),
219
- host_label: z.string().trim().min(1).optional(),
220
- api_key: z.string().trim().min(1).optional(),
221
- max_concurrent_tasks: z.number().int().nonnegative().optional(),
222
- // Admin-only toggle (enforced in the handler, not here).
223
- is_protected: z.boolean().optional(),
224
- })
225
- .refine((v) => Object.keys(v).length > 0, {
226
- message: "patch body must contain at least one field",
227
- });
228
- export type DirectorPatch = z.infer<typeof DirectorPatchSchema>;
229
-
230
- /* ============================================================================
231
- * Dispatch settings
232
- * ============================================================================ */
233
-
234
- export const DispatchSettingsSchema = z.object({
235
- global_max_concurrent_tasks: z.number().int().nonnegative().default(0),
236
- updated_at: z.string().datetime(),
237
- });
238
- export type DispatchSettings = z.infer<typeof DispatchSettingsSchema>;
239
-
240
- export const DispatchSettingsPatchSchema = z
241
- .object({
242
- global_max_concurrent_tasks: z.number().int().nonnegative().optional(),
243
- })
244
- .refine((v) => Object.keys(v).length > 0, {
245
- message: "patch body must contain at least one field",
246
- });
247
- export type DispatchSettingsPatch = z.infer<
248
- typeof DispatchSettingsPatchSchema
249
- >;