engine-launch.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // ============================================================
  2. // run-launched:发起 run 那一轮的宿主元数据 → 事件
  3. // ============================================================
  4. // 引擎不读这些元数据(锚点、阶段表、并行表、子代理选型),只在建 run 那一世紧跟首条
  5. // `run-started` 逐字转录一次(engine.ts)。构造独立成模块,engine.ts 与 types.ts 才都留在
  6. // 400 行的 lint 上限之内——它们是两侧同时增长的文件。
  7. import type { RunEvent } from "./types.js";
  8. /**
  9. * 发起 run 那一轮随 `run-launched` 同车的宿主元数据(EngineConfig.launch):锚点 `inputId`、
  10. * 脚本声明的阶段表 `phaseNames`、与之按位置对齐的 `phaseAlongside`、本 run 子代理的选型
  11. * `subagentModel` 与权限模式 `subagentPermissionMode`、脚本点名的模型绑定表 `modelBindings`、脚本来自
  12. * 哪个文件 `scriptPath`,以及留白下标表 `holes`。八者引擎都不读——字段语义见 types.ts 里
  13. * `run-launched` 的注释。
  14. */
  15. export interface RunLaunchConfig {
  16. inputId: string;
  17. phaseNames?: string[];
  18. subagentModel?: string;
  19. /** 脚本点名的模型名(逐字)→ 规范串(docs/dynamic-workflow/launch.md「Models the script names」)。 */
  20. modelBindings?: Record<string, string>;
  21. /**
  22. * 本 run 子代理的权限模式(docs/dynamic-workflow/launch.md「Permissions inside a run」):
  23. * 发起会话的权限模式名。引擎不读,按不透明串记下;宿主读回时校验。
  24. */
  25. subagentPermissionMode?: string;
  26. /** 本 run 脚本文件的绝对路径(docs/dynamic-workflow/launch.md「Script files」)。 */
  27. scriptPath?: string;
  28. phaseAlongside?: number[][];
  29. /** `phaseNames` 里未补全留白的下标(docs/execution-engine.md「Holes」),同车同规。 */
  30. holes?: number[];
  31. }
  32. /**
  33. * 把 launch 元数据转录成 `run-launched`。未设的键**缺席**而不是落成 undefined 值:读侧
  34. * (AmendWorkflow 的三态、投影)把「没设」与「设了个空」当两件事。
  35. */
  36. export function runLaunchedEvent(
  37. launch: RunLaunchConfig,
  38. origin: { toolCallId?: string | undefined; parentSessionId?: string | undefined },
  39. ): RunEvent {
  40. const {
  41. inputId,
  42. phaseNames,
  43. subagentModel,
  44. subagentPermissionMode,
  45. modelBindings,
  46. scriptPath,
  47. phaseAlongside,
  48. holes,
  49. } = launch;
  50. return {
  51. type: "run-launched",
  52. inputId,
  53. ...(origin.toolCallId === undefined ? {} : { toolCallId: origin.toolCallId }),
  54. ...(origin.parentSessionId === undefined ? {} : { parentSessionId: origin.parentSessionId }),
  55. ...(phaseNames === undefined ? {} : { phaseNames }),
  56. ...(subagentModel === undefined ? {} : { subagentModel }),
  57. ...(subagentPermissionMode === undefined ? {} : { subagentPermissionMode }),
  58. ...(modelBindings === undefined ? {} : { modelBindings }),
  59. ...(scriptPath === undefined ? {} : { scriptPath }),
  60. ...(phaseAlongside === undefined ? {} : { phaseAlongside }),
  61. ...(holes === undefined ? {} : { holes }),
  62. };
  63. }