feat(web): handle one-shot sensitive artifact downloads (#4)
Track sensitive download state per run in the session reducer. Fetch each artifact once into a blob so expired or consumed downloads show HTTP 410 without a separate preflight request. Verify the SSH-key notebook, capture substitution, failure sections and public-key upload provenance through App. Document demo and real terminal workflows.
This commit is contained in:
+29
-1
@@ -1,5 +1,11 @@
|
||||
import type { ServerEvent, StartRunRequest } from "@shellbook/core";
|
||||
|
||||
export type DownloadState =
|
||||
| "downloading"
|
||||
| "downloaded"
|
||||
| "unavailable"
|
||||
| "error";
|
||||
|
||||
export interface RunState {
|
||||
runId: string;
|
||||
notebookPath: string;
|
||||
@@ -9,6 +15,8 @@ export interface RunState {
|
||||
exitCode?: number;
|
||||
durationMs?: number;
|
||||
artifacts: string[];
|
||||
sensitiveArtifacts?: string[];
|
||||
artifactDownloads?: Record<string, DownloadState>;
|
||||
error?: string;
|
||||
hostKey?: Extract<ServerEvent, { type: "run.hostKeyUnknown" }>;
|
||||
}
|
||||
@@ -26,6 +34,12 @@ export const emptySession: Session = {
|
||||
};
|
||||
export const stepKey = (path: string, id: string) => JSON.stringify([path, id]);
|
||||
export type Action =
|
||||
| {
|
||||
type: "artifact.download";
|
||||
runId: string;
|
||||
name: string;
|
||||
state: DownloadState;
|
||||
}
|
||||
| ServerEvent
|
||||
| { type: "requested"; runId: string; request: StartRunRequest };
|
||||
export function eventReducer(state: Session, event: Action): Session {
|
||||
@@ -58,6 +72,15 @@ export function eventReducer(state: Session, event: Action): Session {
|
||||
let updated: RunState = run;
|
||||
let next = state;
|
||||
switch (event.type) {
|
||||
case "artifact.download":
|
||||
updated = {
|
||||
...run,
|
||||
artifactDownloads: {
|
||||
...run.artifactDownloads,
|
||||
[event.name]: event.state,
|
||||
},
|
||||
};
|
||||
break;
|
||||
case "run.output":
|
||||
updated = {
|
||||
...run,
|
||||
@@ -74,7 +97,11 @@ export function eventReducer(state: Session, event: Action): Session {
|
||||
// An attempt aborted for host key confirmation also finishes (exit -1);
|
||||
// keep the prompt open until the user accepts or rejects.
|
||||
if (run.status === "hostKey") {
|
||||
updated = { ...run, exitCode: event.exitCode, durationMs: event.durationMs };
|
||||
updated = {
|
||||
...run,
|
||||
exitCode: event.exitCode,
|
||||
durationMs: event.durationMs,
|
||||
};
|
||||
break;
|
||||
}
|
||||
updated = {
|
||||
@@ -83,6 +110,7 @@ export function eventReducer(state: Session, event: Action): Session {
|
||||
exitCode: event.exitCode,
|
||||
durationMs: event.durationMs,
|
||||
artifacts: event.artifacts,
|
||||
sensitiveArtifacts: event.sensitiveArtifacts ?? [],
|
||||
};
|
||||
if (event.exitCode === 0) {
|
||||
next = {
|
||||
|
||||
Reference in New Issue
Block a user