{"version":3,"sources":["../src/client-sdk/services/experiments/run-status.ts","../src/cli/commands/experiment/resolve-run.ts"],"sourcesContent":["// Experiment runs are stored as a timestamp-driven state in ClickHouse: a run\n// is \"completed\" once finishedAt is set, \"stopped\" once stoppedAt is set, and\n// otherwise still \"running\". A run that stopped emitting updates a while ago\n// without ever finishing is reported as \"interrupted\": the SDK process likely\n// died before sending finished_at/stopped_at.\n\nexport const INTERRUPTED_THRESHOLD_MS = 5 * 60 * 1000;\n\nexport type RunStatus = \"completed\" | \"stopped\" | \"running\" | \"interrupted\";\n\nexport interface RunTimestamps {\n  createdAt?: number | null;\n  updatedAt?: number | null;\n  finishedAt?: number | null;\n  stoppedAt?: number | null;\n}\n\nexport const deriveRunStatus = (\n  timestamps: RunTimestamps,\n  now: number = Date.now(),\n): RunStatus => {\n  if (timestamps.stoppedAt != null) return \"stopped\";\n  if (timestamps.finishedAt != null) return \"completed\";\n  if (\n    timestamps.updatedAt != null &&\n    now - timestamps.updatedAt > INTERRUPTED_THRESHOLD_MS\n  ) {\n    return \"interrupted\";\n  }\n  return \"running\";\n};\n\nexport const isTerminalStatus = (status: RunStatus): boolean =>\n  status === \"completed\" || status === \"stopped\";\n","import { ExperimentsApiService } from \"@/client-sdk/services/experiments/experiments-api.service\";\n\n// Resolve which run an experiment subcommand should act on: an explicit\n// --run-id when given, otherwise the latest run for the experiment. The runs\n// list is returned newest-first by the API, so the first entry is the latest.\nexport const resolveRunId = async ({\n  service,\n  experimentSlug,\n  runId,\n}: {\n  service: ExperimentsApiService;\n  experimentSlug: string;\n  runId?: string;\n}): Promise<string> => {\n  const explicit = runId?.trim();\n  if (explicit) return explicit;\n\n  const { runs } = await service.listRuns({ experimentSlug, pageSize: 1 });\n  const latest = runs?.[0];\n  if (!latest) {\n    throw new Error(\n      `No runs found for experiment \"${experimentSlug}\". Start one first, or pass --run-id <id>.`,\n    );\n  }\n  return latest.runId;\n};\n"],"mappings":";AAMO,IAAM,2BAA2B,IAAI,KAAK;AAW1C,IAAM,kBAAkB,CAC7B,YACA,MAAc,KAAK,IAAI,MACT;AACd,MAAI,WAAW,aAAa,KAAM,QAAO;AACzC,MAAI,WAAW,cAAc,KAAM,QAAO;AAC1C,MACE,WAAW,aAAa,QACxB,MAAM,WAAW,YAAY,0BAC7B;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,IAAM,mBAAmB,CAAC,WAC/B,WAAW,eAAe,WAAW;;;AC5BhC,IAAM,eAAe,OAAO;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF,MAIuB;AACrB,QAAM,WAAW,+BAAO;AACxB,MAAI,SAAU,QAAO;AAErB,QAAM,EAAE,KAAK,IAAI,MAAM,QAAQ,SAAS,EAAE,gBAAgB,UAAU,EAAE,CAAC;AACvE,QAAM,SAAS,6BAAO;AACtB,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR,iCAAiC,cAAc;AAAA,IACjD;AAAA,EACF;AACA,SAAO,OAAO;AAChB;","names":[]}