cli-claw-kit 0.0.1
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/LICENSE +21 -0
- package/README.md +245 -0
- package/config/default-groups.json +1 -0
- package/config/global-agents-md.template.md +37 -0
- package/config/mount-allowlist.json +11 -0
- package/container/Dockerfile +160 -0
- package/container/agent-runner/dist/.tsbuildinfo +1 -0
- package/container/agent-runner/dist/agent-definitions.js +22 -0
- package/container/agent-runner/dist/channel-prefixes.js +16 -0
- package/container/agent-runner/dist/codex-config.js +29 -0
- package/container/agent-runner/dist/image-detector.js +96 -0
- package/container/agent-runner/dist/index.js +2587 -0
- package/container/agent-runner/dist/mcp-tools.js +1076 -0
- package/container/agent-runner/dist/stream-event.types.js +5 -0
- package/container/agent-runner/dist/stream-processor.js +867 -0
- package/container/agent-runner/dist/types.js +6 -0
- package/container/agent-runner/dist/utils.js +115 -0
- package/container/agent-runner/package.json +36 -0
- package/container/agent-runner/prompts/security-rules.md +31 -0
- package/container/agent-runner/src/agent-definitions.ts +27 -0
- package/container/agent-runner/src/channel-prefixes.ts +16 -0
- package/container/agent-runner/src/codex-config.ts +40 -0
- package/container/agent-runner/src/image-detector.ts +116 -0
- package/container/agent-runner/src/index.ts +3107 -0
- package/container/agent-runner/src/mcp-tools.ts +1295 -0
- package/container/agent-runner/src/stream-event.types.ts +10 -0
- package/container/agent-runner/src/stream-processor.ts +932 -0
- package/container/agent-runner/src/types.ts +75 -0
- package/container/agent-runner/src/utils.ts +114 -0
- package/container/agent-runner/tsconfig.json +17 -0
- package/container/build.sh +28 -0
- package/container/entrypoint.sh +64 -0
- package/container/skills/agent-browser/SKILL.md +159 -0
- package/container/skills/install-skill/SKILL.md +64 -0
- package/container/skills/post-test-cleanup/SKILL.md +121 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/agent-output-parser.js +459 -0
- package/dist/app-root.js +52 -0
- package/dist/assistant-meta-footer.js +1 -0
- package/dist/auth.js +91 -0
- package/dist/billing.js +694 -0
- package/dist/channel-prefixes.js +16 -0
- package/dist/cli.js +86 -0
- package/dist/commands.js +79 -0
- package/dist/config.js +120 -0
- package/dist/container-runner.js +981 -0
- package/dist/daily-summary.js +210 -0
- package/dist/db.js +3683 -0
- package/dist/dingtalk.js +1347 -0
- package/dist/feishu-markdown-style.js +97 -0
- package/dist/feishu-streaming-card.js +1875 -0
- package/dist/feishu.js +1628 -0
- package/dist/file-manager.js +270 -0
- package/dist/group-queue.js +1070 -0
- package/dist/group-runtime.js +35 -0
- package/dist/host-workspace-cwd.js +85 -0
- package/dist/im-channel.js +384 -0
- package/dist/im-command-utils.js +142 -0
- package/dist/im-downloader.js +45 -0
- package/dist/im-manager.js +527 -0
- package/dist/im-utils.js +53 -0
- package/dist/image-detector.js +96 -0
- package/dist/index.js +5828 -0
- package/dist/logger.js +22 -0
- package/dist/mcp-utils.js +66 -0
- package/dist/message-attachments.js +69 -0
- package/dist/message-notifier.js +36 -0
- package/dist/middleware/auth.js +85 -0
- package/dist/mount-security.js +315 -0
- package/dist/permissions.js +67 -0
- package/dist/project-memory.js +6 -0
- package/dist/provider-pool.js +189 -0
- package/dist/qq.js +826 -0
- package/dist/reset-admin.js +42 -0
- package/dist/routes/admin.js +543 -0
- package/dist/routes/agent-definitions.js +241 -0
- package/dist/routes/agents.js +533 -0
- package/dist/routes/auth.js +675 -0
- package/dist/routes/billing.js +490 -0
- package/dist/routes/browse.js +210 -0
- package/dist/routes/bug-report.js +387 -0
- package/dist/routes/config.js +1868 -0
- package/dist/routes/files.js +671 -0
- package/dist/routes/groups.js +1367 -0
- package/dist/routes/mcp-servers.js +320 -0
- package/dist/routes/memory.js +523 -0
- package/dist/routes/monitor.js +307 -0
- package/dist/routes/skills.js +777 -0
- package/dist/routes/tasks.js +509 -0
- package/dist/routes/usage.js +64 -0
- package/dist/routes/workspace-config.js +458 -0
- package/dist/runtime-build.js +112 -0
- package/dist/runtime-command-handler.js +189 -0
- package/dist/runtime-command-registry.js +1 -0
- package/dist/runtime-config.js +1777 -0
- package/dist/runtime-identity.js +52 -0
- package/dist/schemas.js +590 -0
- package/dist/script-runner.js +64 -0
- package/dist/sdk-query.js +82 -0
- package/dist/skill-utils.js +145 -0
- package/dist/sqlite-compat.js +19 -0
- package/dist/stream-event.types.js +5 -0
- package/dist/streaming-runtime-meta.js +29 -0
- package/dist/task-scheduler.js +695 -0
- package/dist/task-utils.js +13 -0
- package/dist/telegram-pairing.js +59 -0
- package/dist/telegram.js +897 -0
- package/dist/terminal-manager.js +307 -0
- package/dist/tool-step-display.js +1 -0
- package/dist/types.js +1 -0
- package/dist/utils.js +85 -0
- package/dist/web-context.js +161 -0
- package/dist/web.js +1377 -0
- package/dist/wechat-crypto.js +182 -0
- package/dist/wechat.js +589 -0
- package/dist/workspace-runtime-reset.js +35 -0
- package/package.json +107 -0
- package/shared/assistant-meta-footer.ts +127 -0
- package/shared/channel-prefixes.ts +16 -0
- package/shared/dist/assistant-meta-footer.d.ts +29 -0
- package/shared/dist/assistant-meta-footer.js +85 -0
- package/shared/dist/channel-prefixes.d.ts +4 -0
- package/shared/dist/channel-prefixes.js +16 -0
- package/shared/dist/image-detector.d.ts +20 -0
- package/shared/dist/image-detector.js +96 -0
- package/shared/dist/runtime-command-registry.d.ts +38 -0
- package/shared/dist/runtime-command-registry.js +185 -0
- package/shared/dist/stream-event.d.ts +65 -0
- package/shared/dist/stream-event.js +8 -0
- package/shared/dist/tool-step-display.d.ts +4 -0
- package/shared/dist/tool-step-display.js +11 -0
- package/shared/image-detector.ts +116 -0
- package/shared/runtime-command-registry.ts +252 -0
- package/shared/stream-event.ts +67 -0
- package/shared/tool-step-display.ts +21 -0
- package/shared/tsconfig.json +24 -0
- package/web/dist/assets/BillingPage-B1wBR_o-.js +52 -0
- package/web/dist/assets/ChatPage-6GBZ9nXN.css +32 -0
- package/web/dist/assets/ChatPage-BOJcXtaj.js +161 -0
- package/web/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/web/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/web/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/web/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/web/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/web/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/web/dist/assets/SettingsPage-DoY7FoZ_.js +153 -0
- package/web/dist/assets/ShareImageDialog-C1ga8b7l.js +22 -0
- package/web/dist/assets/TasksPage-CRivnNsx.js +14 -0
- package/web/dist/assets/_basePickBy-Bf-bSoS9.js +1 -0
- package/web/dist/assets/_baseUniq-zAOaCuKw.js +1 -0
- package/web/dist/assets/arc-Dm9mVQ9U.js +1 -0
- package/web/dist/assets/architectureDiagram-2XIMDMQ5-BLmzX1wr.js +36 -0
- package/web/dist/assets/band-CquvqAHh.js +1 -0
- package/web/dist/assets/blockDiagram-WCTKOSBZ-B9pcqm3j.js +132 -0
- package/web/dist/assets/c4Diagram-IC4MRINW-Cytx1q3b.js +10 -0
- package/web/dist/assets/channel-BOVj73LR.js +1 -0
- package/web/dist/assets/channel-meta-CQD0Pei-.js +41 -0
- package/web/dist/assets/chunk-4BX2VUAB-0ToDr6RE.js +1 -0
- package/web/dist/assets/chunk-55IACEB6-DQDjnXfS.js +1 -0
- package/web/dist/assets/chunk-FMBD7UC4-Di8ABm6c.js +15 -0
- package/web/dist/assets/chunk-JSJVCQXG-BZQN6rnX.js +1 -0
- package/web/dist/assets/chunk-KX2RTZJC-zBbcpaN_.js +1 -0
- package/web/dist/assets/chunk-NQ4KR5QH-BCrLoU88.js +220 -0
- package/web/dist/assets/chunk-QZHKN3VN-Bqk8juan.js +1 -0
- package/web/dist/assets/chunk-WL4C6EOR-D2YX-MHY.js +189 -0
- package/web/dist/assets/classDiagram-VBA2DB6C-DUUoMyaK.js +1 -0
- package/web/dist/assets/classDiagram-v2-RAHNMMFH-DUUoMyaK.js +1 -0
- package/web/dist/assets/clone-BmaCesfa.js +1 -0
- package/web/dist/assets/cose-bilkent-S5V4N54A-CTsv6qQA.js +1 -0
- package/web/dist/assets/cytoscape.esm-BQaXIfA_.js +331 -0
- package/web/dist/assets/dagre-KLK3FWXG-Ci4Jh9nu.js +4 -0
- package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/web/dist/assets/diagram-E7M64L7V-BFRnfTI2.js +24 -0
- package/web/dist/assets/diagram-IFDJBPK2-B7Zhnp0b.js +43 -0
- package/web/dist/assets/diagram-P4PSJMXO-BVyP7nwq.js +24 -0
- package/web/dist/assets/erDiagram-INFDFZHY-NorKdTOF.js +70 -0
- package/web/dist/assets/error-CGD5mp5f.js +1 -0
- package/web/dist/assets/flowDiagram-PKNHOUZH-Ch97nABF.js +162 -0
- package/web/dist/assets/ganttDiagram-A5KZAMGK-BQ2pLWsy.js +292 -0
- package/web/dist/assets/gitGraphDiagram-K3NZZRJ6-bcvnBsD2.js +65 -0
- package/web/dist/assets/graph-CeAEckur.js +1 -0
- package/web/dist/assets/index-CPnL1_qC.js +768 -0
- package/web/dist/assets/index-DVevCbcO.css +10 -0
- package/web/dist/assets/infoDiagram-LFFYTUFH-CcsrFdj-.js +2 -0
- package/web/dist/assets/init-Dmth1JHB.js +1 -0
- package/web/dist/assets/ishikawaDiagram-PHBUUO56-1upyMfHN.js +70 -0
- package/web/dist/assets/journeyDiagram-4ABVD52K-CKUi-V0c.js +139 -0
- package/web/dist/assets/kanban-definition-K7BYSVSG-DOnQwXfL.js +89 -0
- package/web/dist/assets/layout-BmMMqTnJ.js +1 -0
- package/web/dist/assets/linear-DiaJloY5.js +1 -0
- package/web/dist/assets/mermaid.core-BWLV1B2v.js +254 -0
- package/web/dist/assets/mindmap-definition-YRQLILUH-BeAKHVWP.js +68 -0
- package/web/dist/assets/ordinal-DILIJJjt.js +1 -0
- package/web/dist/assets/pieDiagram-SKSYHLDU-DfiMSfWo.js +30 -0
- package/web/dist/assets/quadrantDiagram-337W2JSQ-wZxZOJxd.js +7 -0
- package/web/dist/assets/requirementDiagram-Z7DCOOCP-BK4HHm17.js +73 -0
- package/web/dist/assets/sankeyDiagram-WA2Y5GQK-BX6t2avX.js +10 -0
- package/web/dist/assets/sequenceDiagram-2WXFIKYE-BPQlkbAa.js +145 -0
- package/web/dist/assets/sheet-rI0FfB1g.js +6 -0
- package/web/dist/assets/sliders-horizontal-CuijWFNK.js +6 -0
- package/web/dist/assets/sparkles-BsMYXJoT.js +11 -0
- package/web/dist/assets/square-0CqMX1Q3.js +11 -0
- package/web/dist/assets/stateDiagram-RAJIS63D-DxkV0Vwd.js +1 -0
- package/web/dist/assets/stateDiagram-v2-FVOUBMTO-qLYoiOPe.js +1 -0
- package/web/dist/assets/step-D51IIHGA.js +1 -0
- package/web/dist/assets/tasks-D8JjBTwx.js +1 -0
- package/web/dist/assets/time-O8zIGux3.js +1 -0
- package/web/dist/assets/timeline-definition-YZTLITO2-kNp1DyFc.js +61 -0
- package/web/dist/assets/treemap-KZPCXAKY-CkrClVhk.js +162 -0
- package/web/dist/assets/utils-KGAn0XTg.js +11 -0
- package/web/dist/assets/vennDiagram-LZ73GAT5-CgdzEZz4.js +34 -0
- package/web/dist/assets/xychartDiagram-JWTSCODW-DfYGPfNB.js +7 -0
- package/web/dist/assets/zap-_hKJYy7J.js +6 -0
- package/web/dist/favicon.svg +332 -0
- package/web/dist/fonts/AlibabaPuHuiTi-3-55-Regular.woff2 +0 -0
- package/web/dist/fonts/AlibabaPuHuiTi-3-65-Medium.woff2 +0 -0
- package/web/dist/fonts/AlibabaPuHuiTi-3-75-SemiBold.woff2 +0 -0
- package/web/dist/fonts/DMSans-latin-ext.woff2 +0 -0
- package/web/dist/fonts/DMSans-latin.woff2 +0 -0
- package/web/dist/icons/README.md +20 -0
- package/web/dist/icons/apple-touch-icon-180.png +0 -0
- package/web/dist/icons/icon-128.png +0 -0
- package/web/dist/icons/icon-144.png +0 -0
- package/web/dist/icons/icon-152.png +0 -0
- package/web/dist/icons/icon-192.png +0 -0
- package/web/dist/icons/icon-192.svg +332 -0
- package/web/dist/icons/icon-384.png +0 -0
- package/web/dist/icons/icon-48.png +0 -0
- package/web/dist/icons/icon-512-maskable.png +0 -0
- package/web/dist/icons/icon-512.png +0 -0
- package/web/dist/icons/icon-512.svg +332 -0
- package/web/dist/icons/icon-72.png +0 -0
- package/web/dist/icons/icon-96.png +0 -0
- package/web/dist/icons/loading-logo.svg +332 -0
- package/web/dist/icons/logo-1024.png +0 -0
- package/web/dist/icons/logo-icon.svg +332 -0
- package/web/dist/icons/logo-text.svg +332 -0
- package/web/dist/index.html +30 -0
- package/web/dist/manifest.webmanifest +1 -0
- package/web/dist/registerSW.js +1 -0
- package/web/dist/sw.js +1 -0
- package/web/dist/workbox-08d6266a.js +1 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
function normalizeText(value) {
|
|
2
|
+
if (typeof value !== 'string')
|
|
3
|
+
return undefined;
|
|
4
|
+
const trimmed = value.trim();
|
|
5
|
+
return trimmed ? trimmed : undefined;
|
|
6
|
+
}
|
|
7
|
+
export function normalizeRuntimeIdentity(identity) {
|
|
8
|
+
if (!identity)
|
|
9
|
+
return null;
|
|
10
|
+
const model = normalizeText(identity.model);
|
|
11
|
+
const reasoningEffort = normalizeText(identity.reasoningEffort);
|
|
12
|
+
const supportsReasoningEffort = typeof identity.supportsReasoningEffort === 'boolean'
|
|
13
|
+
? identity.supportsReasoningEffort
|
|
14
|
+
: null;
|
|
15
|
+
return {
|
|
16
|
+
agentType: identity.agentType,
|
|
17
|
+
model: model ?? null,
|
|
18
|
+
reasoningEffort: reasoningEffort ?? null,
|
|
19
|
+
supportsReasoningEffort,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function serializeRuntimeIdentity(identity) {
|
|
23
|
+
const normalized = normalizeRuntimeIdentity(identity);
|
|
24
|
+
if (!normalized)
|
|
25
|
+
return null;
|
|
26
|
+
return JSON.stringify(normalized);
|
|
27
|
+
}
|
|
28
|
+
export function parseRuntimeIdentity(value) {
|
|
29
|
+
if (!value)
|
|
30
|
+
return null;
|
|
31
|
+
if (typeof value === 'string') {
|
|
32
|
+
try {
|
|
33
|
+
return normalizeRuntimeIdentity(JSON.parse(value));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return normalizeRuntimeIdentity(value);
|
|
40
|
+
}
|
|
41
|
+
export function formatRuntimeIdentityFooter(identity) {
|
|
42
|
+
const normalized = normalizeRuntimeIdentity(identity);
|
|
43
|
+
if (!normalized?.model)
|
|
44
|
+
return null;
|
|
45
|
+
if (normalized.reasoningEffort) {
|
|
46
|
+
return `${normalized.model} | ${normalized.reasoningEffort}`;
|
|
47
|
+
}
|
|
48
|
+
if (normalized.supportsReasoningEffort === false) {
|
|
49
|
+
return normalized.model;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
// Zod schemas and validation types for API requests
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ALL_PERMISSIONS } from './permissions.js';
|
|
4
|
+
import { MAX_GROUP_NAME_LEN } from './web-context.js';
|
|
5
|
+
export const TaskPatchSchema = z.object({
|
|
6
|
+
prompt: z.string().optional(),
|
|
7
|
+
schedule_type: z.enum(['cron', 'interval', 'once']).optional(),
|
|
8
|
+
schedule_value: z.string().optional(),
|
|
9
|
+
context_mode: z.enum(['group', 'isolated']).optional(),
|
|
10
|
+
execution_type: z.enum(['agent', 'script']).optional(),
|
|
11
|
+
execution_mode: z.enum(['host', 'container']).optional(),
|
|
12
|
+
script_command: z.string().max(4096).nullable().optional(),
|
|
13
|
+
status: z.enum(['active', 'paused']).optional(),
|
|
14
|
+
next_run: z.string().optional(),
|
|
15
|
+
notify_channels: z
|
|
16
|
+
.array(z.enum(['feishu', 'telegram', 'qq', 'wechat', 'dingtalk']))
|
|
17
|
+
.nullable()
|
|
18
|
+
.optional(),
|
|
19
|
+
});
|
|
20
|
+
// Cron 表达式校验:5 段(分 时 日 月 周)或 6 段(秒 分 时 日 月 周)
|
|
21
|
+
// 也允许预定义表达式如 @daily, @hourly 等
|
|
22
|
+
const CRON_REGEX = /^(@(yearly|annually|monthly|weekly|daily|hourly|minutely|secondly)|(\S+\s+){4,5}\S+)$/;
|
|
23
|
+
export const TaskCreateSchema = z
|
|
24
|
+
.object({
|
|
25
|
+
group_folder: z.string().min(1).optional(),
|
|
26
|
+
chat_jid: z.string().min(1).optional(),
|
|
27
|
+
prompt: z.string().optional().default(''),
|
|
28
|
+
schedule_type: z.enum(['cron', 'interval', 'once']),
|
|
29
|
+
schedule_value: z.string().min(1),
|
|
30
|
+
context_mode: z.enum(['group', 'isolated']).optional(),
|
|
31
|
+
execution_type: z.enum(['agent', 'script']).optional(),
|
|
32
|
+
execution_mode: z.enum(['host', 'container']).optional(),
|
|
33
|
+
script_command: z.string().max(4096).optional(),
|
|
34
|
+
notify_channels: z
|
|
35
|
+
.array(z.enum(['feishu', 'telegram', 'qq', 'wechat', 'dingtalk']))
|
|
36
|
+
.nullable()
|
|
37
|
+
.optional(),
|
|
38
|
+
})
|
|
39
|
+
.superRefine((data, ctx) => {
|
|
40
|
+
const execType = data.execution_type || 'agent';
|
|
41
|
+
if (execType === 'agent' && !data.prompt?.trim()) {
|
|
42
|
+
ctx.addIssue({
|
|
43
|
+
code: z.ZodIssueCode.custom,
|
|
44
|
+
path: ['prompt'],
|
|
45
|
+
message: 'Agent 模式下 prompt 为必填项',
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (execType === 'script' && !data.script_command?.trim()) {
|
|
49
|
+
ctx.addIssue({
|
|
50
|
+
code: z.ZodIssueCode.custom,
|
|
51
|
+
path: ['script_command'],
|
|
52
|
+
message: '脚本模式下 script_command 为必填项',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (data.schedule_type === 'cron') {
|
|
56
|
+
if (!CRON_REGEX.test(data.schedule_value.trim())) {
|
|
57
|
+
ctx.addIssue({
|
|
58
|
+
code: z.ZodIssueCode.custom,
|
|
59
|
+
path: ['schedule_value'],
|
|
60
|
+
message: 'Invalid cron expression (expected 5 or 6 fields)',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (data.schedule_type === 'interval') {
|
|
65
|
+
const num = Number(data.schedule_value);
|
|
66
|
+
if (!Number.isFinite(num) || num <= 0) {
|
|
67
|
+
ctx.addIssue({
|
|
68
|
+
code: z.ZodIssueCode.custom,
|
|
69
|
+
path: ['schedule_value'],
|
|
70
|
+
message: 'Interval must be a positive number (milliseconds)',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (data.schedule_type === 'once') {
|
|
75
|
+
const ts = Date.parse(data.schedule_value);
|
|
76
|
+
if (isNaN(ts)) {
|
|
77
|
+
ctx.addIssue({
|
|
78
|
+
code: z.ZodIssueCode.custom,
|
|
79
|
+
path: ['schedule_value'],
|
|
80
|
+
message: 'Once schedule must be a valid ISO 8601 date string',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
// 单张图片附件上限 5MB(base64 编码后约 6.67MB)
|
|
86
|
+
const MAX_IMAGE_BASE64_LENGTH = (5 * 1024 * 1024 * 4) / 3; // ~6.67M chars
|
|
87
|
+
export const MessageAttachmentSchema = z.object({
|
|
88
|
+
type: z.literal('image'),
|
|
89
|
+
data: z.string().min(1).max(MAX_IMAGE_BASE64_LENGTH),
|
|
90
|
+
mimeType: z
|
|
91
|
+
.string()
|
|
92
|
+
.regex(/^image\//)
|
|
93
|
+
.optional(),
|
|
94
|
+
});
|
|
95
|
+
export const MessageCreateSchema = z
|
|
96
|
+
.object({
|
|
97
|
+
chatJid: z.string().min(1),
|
|
98
|
+
content: z.string().optional().default(''),
|
|
99
|
+
attachments: z.array(MessageAttachmentSchema).max(10).optional(),
|
|
100
|
+
})
|
|
101
|
+
.superRefine((data, ctx) => {
|
|
102
|
+
const hasContent = data.content.trim().length > 0;
|
|
103
|
+
const hasAttachments = (data.attachments?.length ?? 0) > 0;
|
|
104
|
+
if (!hasContent && !hasAttachments) {
|
|
105
|
+
ctx.addIssue({
|
|
106
|
+
code: z.ZodIssueCode.custom,
|
|
107
|
+
path: ['content'],
|
|
108
|
+
message: 'content or attachments is required',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
export const GroupCreateSchema = z.object({
|
|
113
|
+
name: z.string().min(1).max(MAX_GROUP_NAME_LEN),
|
|
114
|
+
agent_type: z.enum(['claude', 'codex']).optional(),
|
|
115
|
+
execution_mode: z.enum(['container', 'host']).optional(),
|
|
116
|
+
model: z.string().max(128).optional(),
|
|
117
|
+
reasoning_effort: z.enum(['low', 'medium', 'high', 'xhigh']).optional(),
|
|
118
|
+
custom_cwd: z
|
|
119
|
+
.string()
|
|
120
|
+
.optional()
|
|
121
|
+
.transform((val) => (val && val.trim() ? val.trim() : undefined)),
|
|
122
|
+
init_source_path: z
|
|
123
|
+
.string()
|
|
124
|
+
.optional()
|
|
125
|
+
.transform((val) => (val && val.trim() ? val.trim() : undefined)),
|
|
126
|
+
init_git_url: z
|
|
127
|
+
.string()
|
|
128
|
+
.optional()
|
|
129
|
+
.transform((val) => (val && val.trim() ? val.trim() : undefined)),
|
|
130
|
+
});
|
|
131
|
+
export const GroupMemberAddSchema = z.object({
|
|
132
|
+
user_id: z.string().min(1),
|
|
133
|
+
});
|
|
134
|
+
export const MemoryFileSchema = z.object({
|
|
135
|
+
path: z.string().min(1),
|
|
136
|
+
content: z.string(),
|
|
137
|
+
});
|
|
138
|
+
export const MemoryGlobalSchema = z.object({
|
|
139
|
+
content: z.string(),
|
|
140
|
+
});
|
|
141
|
+
export const ClaudeConfigSchema = z.object({
|
|
142
|
+
anthropicBaseUrl: z.string(),
|
|
143
|
+
anthropicModel: z.string().max(128).optional(),
|
|
144
|
+
});
|
|
145
|
+
export const ClaudeThirdPartyProfileCreateSchema = z.object({
|
|
146
|
+
name: z.string().min(1).max(64),
|
|
147
|
+
anthropicBaseUrl: z.string().max(2000),
|
|
148
|
+
anthropicAuthToken: z.string().max(2000),
|
|
149
|
+
anthropicModel: z.string().max(128).optional(),
|
|
150
|
+
customEnv: z.record(z.string().max(256), z.string().max(4096)).optional(),
|
|
151
|
+
});
|
|
152
|
+
export const ClaudeThirdPartyProfilePatchSchema = z
|
|
153
|
+
.object({
|
|
154
|
+
name: z.string().min(1).max(64).optional(),
|
|
155
|
+
anthropicBaseUrl: z.string().max(2000).optional(),
|
|
156
|
+
anthropicModel: z.string().max(128).optional(),
|
|
157
|
+
customEnv: z.record(z.string().max(256), z.string().max(4096)).optional(),
|
|
158
|
+
})
|
|
159
|
+
.refine((data) => typeof data.name === 'string' ||
|
|
160
|
+
typeof data.anthropicBaseUrl === 'string' ||
|
|
161
|
+
typeof data.anthropicModel === 'string' ||
|
|
162
|
+
data.customEnv !== undefined, { message: 'At least one profile field must be provided' });
|
|
163
|
+
export const ClaudeThirdPartyProfileSecretsSchema = z
|
|
164
|
+
.object({
|
|
165
|
+
anthropicAuthToken: z.string().max(2000).optional(),
|
|
166
|
+
clearAnthropicAuthToken: z.boolean().optional(),
|
|
167
|
+
})
|
|
168
|
+
.refine((data) => typeof data.anthropicAuthToken === 'string' ||
|
|
169
|
+
data.clearAnthropicAuthToken === true, { message: 'At least one secret field must be provided' });
|
|
170
|
+
export const GroupPatchSchema = z.object({
|
|
171
|
+
name: z.string().min(1).max(MAX_GROUP_NAME_LEN).optional(),
|
|
172
|
+
is_pinned: z.boolean().optional(),
|
|
173
|
+
activation_mode: z
|
|
174
|
+
.enum(['auto', 'always', 'when_mentioned', 'disabled'])
|
|
175
|
+
.optional(),
|
|
176
|
+
agent_type: z.enum(['claude', 'codex']).optional(),
|
|
177
|
+
execution_mode: z.enum(['container', 'host']).optional(),
|
|
178
|
+
model: z.string().max(128).nullable().optional(),
|
|
179
|
+
reasoning_effort: z
|
|
180
|
+
.enum(['low', 'medium', 'high', 'xhigh'])
|
|
181
|
+
.nullable()
|
|
182
|
+
.optional(),
|
|
183
|
+
});
|
|
184
|
+
export const LoginSchema = z.object({
|
|
185
|
+
username: z.string().min(1),
|
|
186
|
+
password: z.string().min(1),
|
|
187
|
+
});
|
|
188
|
+
export const RegisterSchema = z.object({
|
|
189
|
+
username: z.string().min(3).max(32),
|
|
190
|
+
password: z.string().min(8).max(128),
|
|
191
|
+
display_name: z.string().max(64).optional(),
|
|
192
|
+
invite_code: z.string().min(1).optional(),
|
|
193
|
+
});
|
|
194
|
+
export const RegistrationConfigSchema = z.object({
|
|
195
|
+
allowRegistration: z.boolean(),
|
|
196
|
+
requireInviteCode: z.boolean(),
|
|
197
|
+
});
|
|
198
|
+
export const SystemSettingsSchema = z.object({
|
|
199
|
+
containerTimeout: z.number().int().min(60000).max(86400000).optional(),
|
|
200
|
+
idleTimeout: z.number().int().min(60000).max(86400000).optional(),
|
|
201
|
+
containerMaxOutputSize: z
|
|
202
|
+
.number()
|
|
203
|
+
.int()
|
|
204
|
+
.min(1048576)
|
|
205
|
+
.max(104857600)
|
|
206
|
+
.optional(),
|
|
207
|
+
maxConcurrentContainers: z.number().int().min(1).max(100).optional(),
|
|
208
|
+
maxConcurrentHostProcesses: z.number().int().min(1).max(50).optional(),
|
|
209
|
+
maxLoginAttempts: z.number().int().min(1).max(100).optional(),
|
|
210
|
+
loginLockoutMinutes: z.number().int().min(1).max(1440).optional(),
|
|
211
|
+
maxConcurrentScripts: z.number().int().min(1).max(50).optional(),
|
|
212
|
+
scriptTimeout: z.number().int().min(5000).max(600000).optional(),
|
|
213
|
+
skillAutoSyncEnabled: z.boolean().optional(),
|
|
214
|
+
skillAutoSyncIntervalMinutes: z.number().int().min(1).max(1440).optional(),
|
|
215
|
+
billingEnabled: z.boolean().optional(),
|
|
216
|
+
billingMode: z.literal('wallet_first').optional(),
|
|
217
|
+
billingMinStartBalanceUsd: z.number().min(0).max(1000000).optional(),
|
|
218
|
+
billingCurrency: z.string().min(1).max(10).optional(),
|
|
219
|
+
billingCurrencyRate: z.number().min(0.0001).max(1000000).optional(),
|
|
220
|
+
});
|
|
221
|
+
export const AppearanceConfigSchema = z.object({
|
|
222
|
+
appName: z.string().max(32).optional(),
|
|
223
|
+
aiName: z.string().min(1).max(32),
|
|
224
|
+
aiAvatarEmoji: z.string().min(1).max(8),
|
|
225
|
+
aiAvatarColor: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
|
226
|
+
});
|
|
227
|
+
export const ChangePasswordSchema = z.object({
|
|
228
|
+
current_password: z.string().min(1),
|
|
229
|
+
new_password: z.string().min(8).max(128),
|
|
230
|
+
});
|
|
231
|
+
export const ProfileUpdateSchema = z.object({
|
|
232
|
+
username: z.string().min(3).max(32).optional(),
|
|
233
|
+
display_name: z.string().max(64).optional(),
|
|
234
|
+
avatar_emoji: z.string().max(8).nullable().optional(),
|
|
235
|
+
avatar_color: z
|
|
236
|
+
.string()
|
|
237
|
+
.regex(/^#[0-9a-fA-F]{6}$/)
|
|
238
|
+
.nullable()
|
|
239
|
+
.optional(),
|
|
240
|
+
avatar_url: z
|
|
241
|
+
.string()
|
|
242
|
+
.max(2048)
|
|
243
|
+
.refine((v) => v.startsWith('/api/auth/avatars/'), 'Invalid avatar URL')
|
|
244
|
+
.nullable()
|
|
245
|
+
.optional(),
|
|
246
|
+
ai_name: z.string().min(1).max(32).nullable().optional(),
|
|
247
|
+
ai_avatar_emoji: z.string().max(8).nullable().optional(),
|
|
248
|
+
ai_avatar_color: z
|
|
249
|
+
.string()
|
|
250
|
+
.regex(/^#[0-9a-fA-F]{6}$/)
|
|
251
|
+
.nullable()
|
|
252
|
+
.optional(),
|
|
253
|
+
ai_avatar_url: z
|
|
254
|
+
.string()
|
|
255
|
+
.max(2048)
|
|
256
|
+
.refine((v) => v.startsWith('/api/auth/avatars/'), 'Invalid avatar URL')
|
|
257
|
+
.nullable()
|
|
258
|
+
.optional(),
|
|
259
|
+
});
|
|
260
|
+
export const PermissionValueSchema = z
|
|
261
|
+
.string()
|
|
262
|
+
.refine((value) => ALL_PERMISSIONS.includes(value), {
|
|
263
|
+
message: 'Invalid permission',
|
|
264
|
+
});
|
|
265
|
+
export const AdminCreateUserSchema = z.object({
|
|
266
|
+
username: z.string().min(3).max(32),
|
|
267
|
+
password: z.string().min(8).max(128),
|
|
268
|
+
display_name: z.string().max(64).optional(),
|
|
269
|
+
role: z.enum(['admin', 'member']).optional(),
|
|
270
|
+
permissions: z
|
|
271
|
+
.array(PermissionValueSchema)
|
|
272
|
+
.max(ALL_PERMISSIONS.length)
|
|
273
|
+
.optional(),
|
|
274
|
+
must_change_password: z.boolean().optional(),
|
|
275
|
+
notes: z.string().max(2000).optional(),
|
|
276
|
+
});
|
|
277
|
+
export const AdminPatchUserSchema = z.object({
|
|
278
|
+
role: z.enum(['admin', 'member']).optional(),
|
|
279
|
+
status: z.enum(['active', 'disabled', 'deleted']).optional(),
|
|
280
|
+
display_name: z.string().max(64).optional(),
|
|
281
|
+
password: z.string().min(8).max(128).optional(),
|
|
282
|
+
permissions: z
|
|
283
|
+
.array(PermissionValueSchema)
|
|
284
|
+
.max(ALL_PERMISSIONS.length)
|
|
285
|
+
.optional(),
|
|
286
|
+
disable_reason: z.string().max(256).nullable().optional(),
|
|
287
|
+
notes: z.string().max(2000).nullable().optional(),
|
|
288
|
+
});
|
|
289
|
+
export const InviteCreateSchema = z.object({
|
|
290
|
+
role: z.enum(['admin', 'member']).optional(),
|
|
291
|
+
permission_template: z
|
|
292
|
+
.enum(['admin_full', 'member_basic', 'ops_manager', 'user_admin'])
|
|
293
|
+
.optional(),
|
|
294
|
+
permissions: z
|
|
295
|
+
.array(PermissionValueSchema)
|
|
296
|
+
.max(ALL_PERMISSIONS.length)
|
|
297
|
+
.optional(),
|
|
298
|
+
max_uses: z.number().int().min(0).max(1000).optional(),
|
|
299
|
+
expires_in_hours: z.number().int().min(1).max(8760).optional(),
|
|
300
|
+
});
|
|
301
|
+
export const ClaudeOAuthCredentialsSchema = z.object({
|
|
302
|
+
accessToken: z.string().min(1),
|
|
303
|
+
refreshToken: z.string().min(1),
|
|
304
|
+
expiresAt: z.number(),
|
|
305
|
+
scopes: z.array(z.string()).default([]),
|
|
306
|
+
subscriptionType: z.string().optional(),
|
|
307
|
+
});
|
|
308
|
+
export const ClaudeSecretsSchema = z
|
|
309
|
+
.object({
|
|
310
|
+
anthropicAuthToken: z.string().optional(),
|
|
311
|
+
clearAnthropicAuthToken: z.boolean().optional(),
|
|
312
|
+
anthropicApiKey: z.string().optional(),
|
|
313
|
+
clearAnthropicApiKey: z.boolean().optional(),
|
|
314
|
+
claudeCodeOauthToken: z.string().optional(),
|
|
315
|
+
clearClaudeCodeOauthToken: z.boolean().optional(),
|
|
316
|
+
claudeOAuthCredentials: ClaudeOAuthCredentialsSchema.optional(),
|
|
317
|
+
clearClaudeOAuthCredentials: z.boolean().optional(),
|
|
318
|
+
})
|
|
319
|
+
.refine((data) => {
|
|
320
|
+
const hasAnthropicAuthToken = typeof data.anthropicAuthToken === 'string' ||
|
|
321
|
+
data.clearAnthropicAuthToken === true;
|
|
322
|
+
const hasAnthropicApiKey = typeof data.anthropicApiKey === 'string' ||
|
|
323
|
+
data.clearAnthropicApiKey === true;
|
|
324
|
+
const hasClaudeCodeOauthToken = typeof data.claudeCodeOauthToken === 'string' ||
|
|
325
|
+
data.clearClaudeCodeOauthToken === true;
|
|
326
|
+
const hasClaudeOAuthCredentials = data.claudeOAuthCredentials !== undefined ||
|
|
327
|
+
data.clearClaudeOAuthCredentials === true;
|
|
328
|
+
return (hasAnthropicAuthToken ||
|
|
329
|
+
hasAnthropicApiKey ||
|
|
330
|
+
hasClaudeCodeOauthToken ||
|
|
331
|
+
hasClaudeOAuthCredentials);
|
|
332
|
+
}, { message: 'At least one secret field must be provided' });
|
|
333
|
+
export const FeishuConfigSchema = z
|
|
334
|
+
.object({
|
|
335
|
+
appId: z.string().max(2000).optional(),
|
|
336
|
+
appSecret: z.string().max(2000).optional(),
|
|
337
|
+
clearAppSecret: z.boolean().optional(),
|
|
338
|
+
enabled: z.boolean().optional(),
|
|
339
|
+
})
|
|
340
|
+
.refine((data) => typeof data.appId === 'string' ||
|
|
341
|
+
typeof data.appSecret === 'string' ||
|
|
342
|
+
data.clearAppSecret === true ||
|
|
343
|
+
typeof data.enabled === 'boolean', { message: 'At least one config field must be provided' });
|
|
344
|
+
export const TelegramConfigSchema = z
|
|
345
|
+
.object({
|
|
346
|
+
botToken: z.string().max(2000).optional(),
|
|
347
|
+
clearBotToken: z.boolean().optional(),
|
|
348
|
+
proxyUrl: z.string().max(2000).optional(),
|
|
349
|
+
clearProxyUrl: z.boolean().optional(),
|
|
350
|
+
enabled: z.boolean().optional(),
|
|
351
|
+
})
|
|
352
|
+
.refine((data) => typeof data.botToken === 'string' ||
|
|
353
|
+
data.clearBotToken === true ||
|
|
354
|
+
typeof data.proxyUrl === 'string' ||
|
|
355
|
+
data.clearProxyUrl === true ||
|
|
356
|
+
typeof data.enabled === 'boolean', { message: 'At least one config field must be provided' });
|
|
357
|
+
export const QQConfigSchema = z
|
|
358
|
+
.object({
|
|
359
|
+
appId: z.string().max(2000).optional(),
|
|
360
|
+
appSecret: z.string().max(2000).optional(),
|
|
361
|
+
clearAppSecret: z.boolean().optional(),
|
|
362
|
+
enabled: z.boolean().optional(),
|
|
363
|
+
})
|
|
364
|
+
.refine((data) => typeof data.appId === 'string' ||
|
|
365
|
+
typeof data.appSecret === 'string' ||
|
|
366
|
+
data.clearAppSecret === true ||
|
|
367
|
+
typeof data.enabled === 'boolean', { message: 'At least one config field must be provided' });
|
|
368
|
+
export const ClaudeCustomEnvSchema = z.object({
|
|
369
|
+
customEnv: z.record(z.string().max(256), z.string().max(4096)),
|
|
370
|
+
});
|
|
371
|
+
export const ContainerEnvSchema = z.object({
|
|
372
|
+
anthropicBaseUrl: z.string().max(2000).optional(),
|
|
373
|
+
anthropicAuthToken: z.string().max(2000).optional(),
|
|
374
|
+
anthropicApiKey: z.string().max(2000).optional(),
|
|
375
|
+
claudeCodeOauthToken: z.string().max(2000).optional(),
|
|
376
|
+
anthropicModel: z.string().max(128).optional(),
|
|
377
|
+
customEnv: z
|
|
378
|
+
.record(z.string().max(256), z.string().max(4096))
|
|
379
|
+
.optional()
|
|
380
|
+
.refine((env) => !env || Object.keys(env).length <= 50, {
|
|
381
|
+
message: 'customEnv must have at most 50 entries',
|
|
382
|
+
}),
|
|
383
|
+
});
|
|
384
|
+
// Terminal WebSocket message schemas
|
|
385
|
+
export const TerminalStartSchema = z.object({
|
|
386
|
+
chatJid: z.string().min(1),
|
|
387
|
+
cols: z.number().int().optional(),
|
|
388
|
+
rows: z.number().int().optional(),
|
|
389
|
+
});
|
|
390
|
+
export const TerminalInputSchema = z.object({
|
|
391
|
+
chatJid: z.string().min(1),
|
|
392
|
+
data: z.string().min(1).max(8192),
|
|
393
|
+
});
|
|
394
|
+
export const TerminalResizeSchema = z.object({
|
|
395
|
+
chatJid: z.string().min(1),
|
|
396
|
+
cols: z.number().int().optional(),
|
|
397
|
+
rows: z.number().int().optional(),
|
|
398
|
+
});
|
|
399
|
+
export const TerminalStopSchema = z.object({
|
|
400
|
+
chatJid: z.string().min(1),
|
|
401
|
+
});
|
|
402
|
+
// --- Billing schemas ---
|
|
403
|
+
export const BillingPlanCreateSchema = z.object({
|
|
404
|
+
id: z
|
|
405
|
+
.string()
|
|
406
|
+
.min(1)
|
|
407
|
+
.max(64)
|
|
408
|
+
.regex(/^[\w-]+$/, 'ID must be alphanumeric with hyphens/underscores'),
|
|
409
|
+
name: z.string().min(1).max(64),
|
|
410
|
+
description: z.string().max(500).nullable().optional(),
|
|
411
|
+
tier: z.number().int().min(0).max(100).optional(),
|
|
412
|
+
monthly_cost_usd: z.number().min(0).optional(),
|
|
413
|
+
monthly_token_quota: z.number().int().min(0).nullable().optional(),
|
|
414
|
+
monthly_cost_quota: z.number().min(0).nullable().optional(),
|
|
415
|
+
daily_cost_quota: z.number().min(0).nullable().optional(),
|
|
416
|
+
weekly_cost_quota: z.number().min(0).nullable().optional(),
|
|
417
|
+
daily_token_quota: z.number().int().min(0).nullable().optional(),
|
|
418
|
+
weekly_token_quota: z.number().int().min(0).nullable().optional(),
|
|
419
|
+
rate_multiplier: z.number().min(0.01).max(100).optional(),
|
|
420
|
+
trial_days: z.number().int().min(1).max(365).nullable().optional(),
|
|
421
|
+
sort_order: z.number().int().min(0).max(9999).optional(),
|
|
422
|
+
display_price: z.string().max(64).nullable().optional(),
|
|
423
|
+
highlight: z.boolean().optional(),
|
|
424
|
+
max_groups: z.number().int().min(0).nullable().optional(),
|
|
425
|
+
max_concurrent_containers: z.number().int().min(0).nullable().optional(),
|
|
426
|
+
max_im_channels: z.number().int().min(0).nullable().optional(),
|
|
427
|
+
max_mcp_servers: z.number().int().min(0).nullable().optional(),
|
|
428
|
+
max_storage_mb: z.number().int().min(0).nullable().optional(),
|
|
429
|
+
allow_overage: z.boolean().optional(),
|
|
430
|
+
features: z.array(z.string().max(64)).max(50).optional(),
|
|
431
|
+
is_default: z.boolean().optional(),
|
|
432
|
+
is_active: z.boolean().optional(),
|
|
433
|
+
});
|
|
434
|
+
export const BillingPlanPatchSchema = BillingPlanCreateSchema.omit({
|
|
435
|
+
id: true,
|
|
436
|
+
}).partial();
|
|
437
|
+
export const AssignPlanSchema = z.object({
|
|
438
|
+
plan_id: z.string().min(1),
|
|
439
|
+
duration_days: z.number().int().min(1).max(3650).optional(),
|
|
440
|
+
});
|
|
441
|
+
export const AdjustBalanceSchema = z.object({
|
|
442
|
+
amount_usd: z.number().refine((v) => v !== 0, 'Amount cannot be zero'),
|
|
443
|
+
description: z.string().min(1).max(500),
|
|
444
|
+
idempotency_key: z.string().min(1).max(64).optional(),
|
|
445
|
+
});
|
|
446
|
+
export const BatchAssignPlanSchema = z.object({
|
|
447
|
+
user_ids: z.array(z.string().min(1)).min(1).max(100),
|
|
448
|
+
plan_id: z.string().min(1),
|
|
449
|
+
duration_days: z.number().int().min(1).max(3650).optional(),
|
|
450
|
+
});
|
|
451
|
+
export const RedeemCodeCreateSchema = z
|
|
452
|
+
.object({
|
|
453
|
+
type: z.enum(['balance', 'subscription', 'trial']),
|
|
454
|
+
value_usd: z.number().min(0.01).optional(),
|
|
455
|
+
plan_id: z.string().min(1).optional(),
|
|
456
|
+
duration_days: z.number().int().min(1).max(3650).optional(),
|
|
457
|
+
max_uses: z.number().int().min(1).max(10000).optional(),
|
|
458
|
+
count: z.number().int().min(1).max(100).optional(), // 批量生成数量
|
|
459
|
+
prefix: z
|
|
460
|
+
.string()
|
|
461
|
+
.max(16)
|
|
462
|
+
.regex(/^[\w-]*$/)
|
|
463
|
+
.optional(), // 兑换码前缀
|
|
464
|
+
expires_in_hours: z.number().int().min(1).max(87600).optional(),
|
|
465
|
+
notes: z.string().max(500).optional(),
|
|
466
|
+
})
|
|
467
|
+
.superRefine((data, ctx) => {
|
|
468
|
+
if (data.type === 'balance' && (!data.value_usd || data.value_usd <= 0)) {
|
|
469
|
+
ctx.addIssue({
|
|
470
|
+
code: z.ZodIssueCode.custom,
|
|
471
|
+
path: ['value_usd'],
|
|
472
|
+
message: 'Balance type requires a positive value_usd',
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
if (data.type === 'subscription' && !data.plan_id) {
|
|
476
|
+
ctx.addIssue({
|
|
477
|
+
code: z.ZodIssueCode.custom,
|
|
478
|
+
path: ['plan_id'],
|
|
479
|
+
message: 'Subscription type requires a plan_id',
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
if (data.type === 'trial' &&
|
|
483
|
+
(!data.duration_days || data.duration_days <= 0)) {
|
|
484
|
+
ctx.addIssue({
|
|
485
|
+
code: z.ZodIssueCode.custom,
|
|
486
|
+
path: ['duration_days'],
|
|
487
|
+
message: 'Trial type requires a positive duration_days',
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
export const RedeemCodeSchema = z.object({
|
|
492
|
+
code: z.string().min(1).max(64),
|
|
493
|
+
});
|
|
494
|
+
// --- Bug Report schemas ---
|
|
495
|
+
// 单张截图上限 5MB(base64 编码后约 6.67MB)
|
|
496
|
+
const MAX_SCREENSHOT_BASE64_LENGTH = (5 * 1024 * 1024 * 4) / 3;
|
|
497
|
+
export const BugReportGenerateSchema = z.object({
|
|
498
|
+
description: z.string().min(1).max(5000),
|
|
499
|
+
screenshots: z
|
|
500
|
+
.array(z.string().max(MAX_SCREENSHOT_BASE64_LENGTH))
|
|
501
|
+
.max(3)
|
|
502
|
+
.optional(),
|
|
503
|
+
});
|
|
504
|
+
export const BugReportSubmitSchema = z.object({
|
|
505
|
+
title: z.string().min(1).max(256),
|
|
506
|
+
body: z.string().min(1).max(65536),
|
|
507
|
+
});
|
|
508
|
+
// ─── 统一供应商 (V4) ────────────────────────────────────────
|
|
509
|
+
export const UnifiedProviderCreateSchema = z
|
|
510
|
+
.object({
|
|
511
|
+
name: z.string().min(1).max(64),
|
|
512
|
+
type: z.enum(['official', 'third_party']),
|
|
513
|
+
anthropicBaseUrl: z.string().max(2000).optional(),
|
|
514
|
+
anthropicAuthToken: z.string().max(2000).optional(),
|
|
515
|
+
anthropicModel: z.string().max(128).optional(),
|
|
516
|
+
anthropicApiKey: z.string().max(2000).optional(),
|
|
517
|
+
claudeCodeOauthToken: z.string().max(2000).optional(),
|
|
518
|
+
claudeOAuthCredentials: ClaudeOAuthCredentialsSchema.optional(),
|
|
519
|
+
customEnv: z.record(z.string().max(256), z.string().max(4096)).optional(),
|
|
520
|
+
weight: z.number().int().min(1).max(100).optional(),
|
|
521
|
+
enabled: z.boolean().optional(),
|
|
522
|
+
})
|
|
523
|
+
.superRefine((data, ctx) => {
|
|
524
|
+
if (data.type === 'third_party' &&
|
|
525
|
+
!data.anthropicBaseUrl?.trim() &&
|
|
526
|
+
!data.anthropicAuthToken?.trim()) {
|
|
527
|
+
ctx.addIssue({
|
|
528
|
+
code: z.ZodIssueCode.custom,
|
|
529
|
+
path: ['anthropicBaseUrl'],
|
|
530
|
+
message: '第三方供应商需要提供 Base URL 或 Auth Token',
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
export const UnifiedProviderPatchSchema = z
|
|
535
|
+
.object({
|
|
536
|
+
name: z.string().min(1).max(64).optional(),
|
|
537
|
+
anthropicBaseUrl: z.string().max(2000).optional(),
|
|
538
|
+
anthropicModel: z.string().max(128).optional(),
|
|
539
|
+
customEnv: z.record(z.string().max(256), z.string().max(4096)).optional(),
|
|
540
|
+
weight: z.number().int().min(1).max(100).optional(),
|
|
541
|
+
})
|
|
542
|
+
.refine((data) => data.name !== undefined ||
|
|
543
|
+
data.anthropicBaseUrl !== undefined ||
|
|
544
|
+
data.anthropicModel !== undefined ||
|
|
545
|
+
data.customEnv !== undefined ||
|
|
546
|
+
data.weight !== undefined, { message: 'At least one field must be provided' });
|
|
547
|
+
export const UnifiedProviderSecretsSchema = z
|
|
548
|
+
.object({
|
|
549
|
+
anthropicAuthToken: z.string().max(2000).optional(),
|
|
550
|
+
clearAnthropicAuthToken: z.boolean().optional(),
|
|
551
|
+
anthropicApiKey: z.string().max(2000).optional(),
|
|
552
|
+
clearAnthropicApiKey: z.boolean().optional(),
|
|
553
|
+
claudeCodeOauthToken: z.string().max(2000).optional(),
|
|
554
|
+
clearClaudeCodeOauthToken: z.boolean().optional(),
|
|
555
|
+
claudeOAuthCredentials: ClaudeOAuthCredentialsSchema.optional(),
|
|
556
|
+
clearClaudeOAuthCredentials: z.boolean().optional(),
|
|
557
|
+
})
|
|
558
|
+
.refine((data) => {
|
|
559
|
+
return (typeof data.anthropicAuthToken === 'string' ||
|
|
560
|
+
data.clearAnthropicAuthToken === true ||
|
|
561
|
+
typeof data.anthropicApiKey === 'string' ||
|
|
562
|
+
data.clearAnthropicApiKey === true ||
|
|
563
|
+
typeof data.claudeCodeOauthToken === 'string' ||
|
|
564
|
+
data.clearClaudeCodeOauthToken === true ||
|
|
565
|
+
data.claudeOAuthCredentials !== undefined ||
|
|
566
|
+
data.clearClaudeOAuthCredentials === true);
|
|
567
|
+
}, { message: 'At least one secret field must be provided' });
|
|
568
|
+
export const BalancingConfigSchema = z.object({
|
|
569
|
+
strategy: z
|
|
570
|
+
.enum(['round-robin', 'weighted-round-robin', 'failover'])
|
|
571
|
+
.optional(),
|
|
572
|
+
unhealthyThreshold: z.number().int().min(1).max(20).optional(),
|
|
573
|
+
recoveryIntervalMs: z.number().int().min(30000).max(3600000).optional(),
|
|
574
|
+
});
|
|
575
|
+
export const WeChatConfigSchema = z.object({
|
|
576
|
+
enabled: z.boolean().optional(),
|
|
577
|
+
clearBotToken: z.boolean().optional(),
|
|
578
|
+
bypassProxy: z.boolean().optional(),
|
|
579
|
+
});
|
|
580
|
+
export const DingTalkConfigSchema = z
|
|
581
|
+
.object({
|
|
582
|
+
clientId: z.string().max(2000).optional(),
|
|
583
|
+
clientSecret: z.string().max(2000).optional(),
|
|
584
|
+
clearClientSecret: z.boolean().optional(),
|
|
585
|
+
enabled: z.boolean().optional(),
|
|
586
|
+
})
|
|
587
|
+
.refine((data) => typeof data.clientId === 'string' ||
|
|
588
|
+
typeof data.clientSecret === 'string' ||
|
|
589
|
+
data.clearClientSecret === true ||
|
|
590
|
+
typeof data.enabled === 'boolean', { message: 'At least one config field must be provided' });
|