Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/hub/src/live-app/host-report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { type } from "arktype";

export const HostReport = type({
state: "'starting'",
phase: "'installing' | 'starting'",
log: "string[]",
})
.or({ state: "'running'", url: "string" })
.or({ state: "'failed'", error: "string", log: "string[]" });
export type HostReport = typeof HostReport.infer;
5 changes: 1 addition & 4 deletions apps/hub/src/live-app/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { type } from "arktype";
import { hasCode } from "@intx/types";
import { liveAppWording } from "../config/live-app.ts";
import { errorCode } from "../request-error.ts";
import type { HostReport } from "./host-report.ts";
import { parseJson } from "../lib/json.ts";
import { writeBundle } from "../artifacts/design-tools.ts";
import { bundleFiles, collectApp } from "../builds/app-snapshot.ts";
Expand All @@ -21,10 +22,6 @@ import {
IGNORED_CHANGES,
} from "../builds/posix-sandbox.ts";

export type HostReport =
| { state: "starting"; phase: "installing" | "starting"; log: string[] }
| { state: "running"; url: string }
| { state: "failed"; error: string; log: string[] };
export const HostSource = type({ dir: "string > 0" }).or({
files: { "[string]": "string" },
"binary?": { "[string]": "string" },
Expand Down
5 changes: 3 additions & 2 deletions apps/hub/src/live-app/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { fileURLToPath } from "node:url";
import { getLogger } from "@intx/log";
import { errorCode, requestErrorMetadata } from "../request-error.ts";
import { liveAppWording } from "../config/live-app.ts";
import type { HostReport, HostSource } from "./host.ts";
import type { HostSource } from "./host.ts";
import { HostReport } from "./host-report.ts";
import type { createLiveAppProxy } from "./proxy.ts";

const log = getLogger(["corbits-builder", "hub", "live-app"]);
Expand Down Expand Up @@ -66,7 +67,7 @@ export function createLiveAppRunner(options: {
end !== -1;
end = pending.indexOf("\n")
) {
run.state = JSON.parse(pending.slice(0, end)) as HostReport;
run.state = HostReport.assert(JSON.parse(pending.slice(0, end)));
pending = pending.slice(end + 1);
}
}
Expand Down
15 changes: 8 additions & 7 deletions apps/hub/src/sidecar/manifest-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { type } from "arktype";
import { errorText } from "./error-text.ts";
import { hasCode, type CredentialCipher } from "@intx/types";

const LocalSidecarManifestSchema = type({
sidecarId: "string",
hubWebSocketUrl: "string",
dataDir: "string",
token: "string",
});
/** The hub's one local sidecar: the identity it authenticates with and where it keeps its state. */
export type LocalSidecarManifest = {
readonly sidecarId: string;
readonly hubWebSocketUrl: string;
readonly dataDir: string;
readonly token: string;
};
export type LocalSidecarManifest = typeof LocalSidecarManifestSchema.infer;

/** An allocation the sidecar hosts, at the generation and under the identity the hub offered for it. */
const LocalSidecarHold = type({
Expand Down Expand Up @@ -106,7 +107,7 @@ export function createLocalSidecarManifestStore({
const text = await readOptional(manifestFile);
if (text === null) return null;
try {
const stored = JSON.parse(text) as LocalSidecarManifest;
const stored = LocalSidecarManifestSchema.assert(JSON.parse(text));
return {
...stored,
token: await cipher.decrypt(
Expand Down