workflow-run-settings-command.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // ============================================================
  2. // amendWorkflowRunSettings:从 GUI 改一个 run 的两项设置
  3. // ============================================================
  4. // 从 command.ts 拆出(max-lines 门):载荷、accepted 结果与拒绝词表三件同属一个命令,
  5. // bootstrap 铸 fault code、UI 反查文案,两侧共享这一份词表避免漂移。
  6. import { z } from "zod";
  7. import { WORKFLOW_RUNS_LIMITS } from "./workflow-runs.js";
  8. /**
  9. * 命令载荷。两项设置守工具的同一条三态规则:省略 = 沿用,`null` = 回到默认(会话模型 / 默认并发),
  10. * 值 = 设定。GUI 只发用户改过的那几项。刻意不携 baseRevision:与 cancelBackgroundWork /
  11. * resumeWorkflowRun 同类(workflowRuns 面免 revision)。
  12. */
  13. export const amendWorkflowRunSettingsPayloadSchema = z.object({
  14. /** ≡ runId,与取消、恢复同一个身份等式。 */
  15. workId: z.string(),
  16. /** 规范串 `providerId/modelId[$level]`;`null` = 子代理回到会话模型。 */
  17. subagentModel: z
  18. .string()
  19. .min(1)
  20. .max(WORKFLOW_RUNS_LIMITS.maxSubagentModelLength)
  21. .nullable()
  22. .optional(),
  23. /** 同时运行的子代理上限;`null` = 解除本 run 自己的界(回到默认并发)。没有上限:高于默认也行。 */
  24. maxConcurrency: z.number().int().min(1).nullable().optional(),
  25. });
  26. export type AmendWorkflowRunSettingsPayload = z.infer<typeof amendWorkflowRunSettingsPayloadSchema>;
  27. /**
  28. * accepted ACK 的结果。`runId` / `toolCallId` 指**新** run(toolCallId = `settings-<uuid>`,
  29. * 联接设置轮的 run 卡与详情页);`supersededRunId` 只在旧 run 仍在飞、被这次调整停下时在场。
  30. */
  31. export const amendWorkflowRunSettingsResultSchema = z.object({
  32. type: z.literal("amendWorkflowRunSettings"),
  33. runId: z.string().min(1),
  34. toolCallId: z.string().min(1),
  35. supersededRunId: z.string().min(1).optional(),
  36. });
  37. /**
  38. * 拒绝词表。所有拒绝都发生在停下或新建任何东西之前:
  39. * not_found / not_configurable / unchanged / script_missing / model_unavailable / compile_failed
  40. * 是命令自己的检查,missing_boundaries 是端口预检,start_failed 是端口缺席或抛错。
  41. */
  42. export const workflowRunSettingsRejectionReasonSchema = z.enum([
  43. "not_found",
  44. "not_configurable",
  45. "unchanged",
  46. "script_missing",
  47. "model_unavailable",
  48. "compile_failed",
  49. "missing_boundaries",
  50. "start_failed",
  51. ]);
  52. export type WorkflowRunSettingsRejectionReason = z.infer<
  53. typeof workflowRunSettingsRejectionReasonSchema
  54. >;
  55. /** 完整 fault code = 前缀 + reason;与 workflowRunResumeRejected 同族。 */
  56. export const WORKFLOW_RUN_SETTINGS_REJECTED_FAULT_PREFIX =
  57. "fault.command.workflowRunSettingsRejected." as const;