diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-21 15:16:23 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-21 15:16:23 +0800 |
| commit | d2a4cb4e645979f20c22a5c46c1c767db460f54a (patch) | |
| tree | 3ffe0d01552a0b4ae66d476ab030e71937191e6b /src/SomhairlesDream.Frontend/App.fs | |
| parent | 26bdd272e3d26040a8c9b64b302fd94d7b6be978 (diff) | |
| download | somhairles-dream-fsharp-d2a4cb4e645979f20c22a5c46c1c767db460f54a.tar.gz | |
feat(ship): HNX-01 crewed starship design branch (7-step ship.py, --design ship, 409 replays completed run history)
Diffstat (limited to 'src/SomhairlesDream.Frontend/App.fs')
| -rw-r--r-- | src/SomhairlesDream.Frontend/App.fs | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/src/SomhairlesDream.Frontend/App.fs b/src/SomhairlesDream.Frontend/App.fs index e6edd51..0e6bcd4 100644 --- a/src/SomhairlesDream.Frontend/App.fs +++ b/src/SomhairlesDream.Frontend/App.fs @@ -707,48 +707,7 @@ let selectionForLiveStart (selection: RunSelection) = else selection -let startRun (selection: RunSelection) = - let requestBody = - createObj - [ "projectId" ==> selection.ProjectId - "runId" ==> selection.RunId - "baseId" ==> selection.BaseId - "targetId" ==> selection.TargetId - "render" ==> selection.Render ] - - let requestOptions = - createObj - [ "method" ==> "POST" - "headers" ==> createObj [ "Content-Type" ==> "application/json" ] - "body" ==> JS.JSON.stringify requestBody ] - - setText "run-message" "正在启动设计运行" - updateStreamState "实时链路 · 等待服务端确认" - - async { - try - let! response = fetch ("/api/runs/start", requestOptions) |> Async.AwaitPromise - - if response.ok then - let! value = response.json() |> Async.AwaitPromise - let payload = value :?> SnapshotPayload - updateState payload - connectToServer selection - updateStreamState "实时链路 · SSE 已连接" - else - setText "run-message" (sprintf "启动失败 · HTTP %d" response.status) - updateStreamState "实时链路 · 启动失败" - with _ -> - setText "run-message" "启动失败 · 无法连接服务端" - updateStreamState "实时链路 · 连接失败" - } - |> Async.StartImmediate - -/// Boot-time historical load: surface the pre-published probe build replay so -/// first-time visitors see the real vehicle instead of an empty placeholder. -/// Any failure leaves the honest placeholder idle state untouched. -let loadBootHistory () = - let selection = selectedRun () +let loadHistoryFor (selection: RunSelection) = let projectId = JS.encodeURIComponent selection.ProjectId let runId = JS.encodeURIComponent selection.RunId let url = sprintf "/api/artifacts/manifest?projectId=%s&runId=%s" projectId runId @@ -793,6 +752,54 @@ let loadBootHistory () = () } |> Async.StartImmediate +let startRun (selection: RunSelection) = + let requestBody = + createObj + [ "projectId" ==> selection.ProjectId + "runId" ==> selection.RunId + "baseId" ==> selection.BaseId + "targetId" ==> selection.TargetId + "render" ==> selection.Render ] + + let requestOptions = + createObj + [ "method" ==> "POST" + "headers" ==> createObj [ "Content-Type" ==> "application/json" ] + "body" ==> JS.JSON.stringify requestBody ] + + setText "run-message" "正在启动设计运行" + updateStreamState "实时链路 · 等待服务端确认" + + async { + try + let! response = fetch ("/api/runs/start", requestOptions) |> Async.AwaitPromise + + if response.ok then + let! value = response.json() |> Async.AwaitPromise + let payload = value :?> SnapshotPayload + updateState payload + connectToServer selection + updateStreamState "实时链路 · SSE 已连接" + elif response.status = 409 then + // The run id already exists on the server. If it completed + // earlier, replay its published history instead of treating + // the submit as a failure. + setText "run-message" "该运行已完成 · 载入历史回放" + loadHistoryFor selection + else + setText "run-message" (sprintf "启动失败 · HTTP %d" response.status) + updateStreamState "实时链路 · 启动失败" + with _ -> + setText "run-message" "启动失败 · 无法连接服务端" + updateStreamState "实时链路 · 连接失败" + } + |> Async.StartImmediate + +/// Boot-time historical load: surface the pre-published probe build replay so +/// first-time visitors see the real vehicle instead of an empty placeholder. +/// Any failure leaves the honest placeholder idle state untouched. +let loadBootHistory () = + loadHistoryFor (selectedRun ()) let boot () = showFrameMetadata frames[0] |
