Skip to content

An open-source, self-hosted system for apps built with web technologies.

Align System with unified Program contracts

zohayrslileh7cee6db1b3fc
diff --git a/scripts/contracts/gateway.ts b/scripts/contracts/gateway.ts
index ffa5faa..f7ecc65 100644
--- a/scripts/contracts/gateway.ts
+++ b/scripts/contracts/gateway.ts
@@ -19,6 +19,7 @@ const forkedEntry = {
const programSnapshot = {
reference: "example-reference",
identity: "example",
+ assetId: "00000000-0000-4000-8000-000000000000",
name: "Example",
version: "1.0.0",
description: null,
@@ -108,6 +109,7 @@ try {
program: {
reference: "example-reference",
identity: "example",
+ assetId: "00000000-0000-4000-8000-000000000000",
name: "Example",
version: "1.0.0",
description: null,
diff --git a/scripts/contracts/program-development.ts b/scripts/contracts/program-development.ts
index 5f0f512..1f441dc 100644
--- a/scripts/contracts/program-development.ts
+++ b/scripts/contracts/program-development.ts
@@ -13,10 +13,10 @@ const target = developmentTarget(
development,
- "http://localhost:4300/program/example/assets/main.ts?direct"
+ `http://localhost:4300/program/${development.assetId}/assets/main.ts?direct`
)
-assert.equal(target?.href, "http://localhost:5173/program/example/assets/main.ts?direct")
+assert.equal(target?.href, `http://localhost:5173/program/${development.assetId}/assets/main.ts?direct`)
const production = new Program({
@@ -25,4 +25,4 @@ const production = new Program({
client: { location: "dist/client" }
})
-assert.equal(developmentTarget(production, "http://localhost:4300/program/example/assets/"), null)
+assert.equal(developmentTarget(production, `http://localhost:4300/program/${production.assetId}/assets/`), null)
diff --git a/scripts/contracts/program-frame.tsx b/scripts/contracts/program-frame.tsx
index 8f1af54..4dcf490 100644
--- a/scripts/contracts/program-frame.tsx
+++ b/scripts/contracts/program-frame.tsx
@@ -8,6 +8,7 @@ const record = { identity: "process", program: "program" } as Process
const client = { sameOrigin: false, window: { location: "/" } } as ClientState
const common = {
record,
+ assetId: "00000000-0000-4000-8000-000000000000",
client,
title: "Program",
door: "/program",
@@ -27,4 +28,4 @@ assert.match(dark, /style="color-scheme:dark"/)
assert.match(light, /style="color-scheme:light"/)
assert.match(dark, /sandbox="allow-scripts allow-forms"/)
assert.match(fullAccess, /sandbox="allow-scripts allow-forms allow-same-origin"/)
-assert.match(fullAccess, /src="\/program\/program\/assets\/"/)
+assert.match(fullAccess, /src="\/program\/00000000-0000-4000-8000-000000000000\/assets\/"/)
diff --git a/source/client/core/link-manager/auth-manager/program-manager/program.ts b/source/client/core/link-manager/auth-manager/program-manager/program.ts
index 7fdb222..9d55f2c 100644
--- a/source/client/core/link-manager/auth-manager/program-manager/program.ts
+++ b/source/client/core/link-manager/auth-manager/program-manager/program.ts
@@ -17,6 +17,8 @@ export default class Program {
public readonly identity: string
+ public readonly assetId: string
+
/** Opaque identity of this runtime Program entity. */
public readonly reference: string
@@ -40,6 +42,8 @@ export default class Program {
this.identity = payload.identity
+ this.assetId = payload.assetId
+
this.reference = payload.reference
this.installed = payload.installed
diff --git a/source/client/view/components/desktop-host/sdk-records.ts b/source/client/view/components/desktop-host/sdk-records.ts
index e85c603..46b1312 100644
--- a/source/client/view/components/desktop-host/sdk-records.ts
+++ b/source/client/view/components/desktop-host/sdk-records.ts
@@ -2,6 +2,7 @@ export interface SdkProgramSource {
reference: string
identity: string
+ assetId: string
installed: boolean
name: string
version: string | null
@@ -39,6 +40,8 @@ export function sdkProgram(program: SdkProgramSource) {
identity: program.identity,
+ assetId: program.assetId,
+
installed: program.installed,
name: program.name,
diff --git a/source/client/view/components/program-frame.tsx b/source/client/view/components/program-frame.tsx
index 6c82b2e..be0d6a8 100644
--- a/source/client/view/components/program-frame.tsx
+++ b/source/client/view/components/program-frame.tsx
@@ -4,13 +4,13 @@ import { blockedProgramDocument, type ProgramAccess } from "./program-access"
import { type Theme } from "@phreshos/core"
import { type ReactEventHandler, useCallback } from "react"
-export function programFrameSource(record: Process, client: ClientState, door: string) {
+export function programFrameSource(assetId: string, client: ClientState, door: string) {
- return `${door}/${record.program}/assets/${client.window.location.slice(1)}`
+ return `${door}/${assetId}/assets/${client.window.location.slice(1)}`
}
/** The document representation shared by every Client role. */
-export default function ProgramFrame({ record, client, title, door, access, theme, className = "size-full border-0", onFrame, onLoad }: ProgramFrameProps) {
+export default function ProgramFrame({ record, assetId, client, title, door, access, theme, className = "size-full border-0", onFrame, onLoad }: ProgramFrameProps) {
const source = useCallback((element: HTMLIFrameElement | null) => onFrame(record.identity, element), [onFrame, record.identity])
@@ -30,7 +30,7 @@ export default function ProgramFrame({ record, client, title, door, access, them
style={{ colorScheme: theme }}
- src={programFrameSource(record, client, door)}
+ src={programFrameSource(assetId, client, door)}
title={title}
@@ -49,6 +49,8 @@ interface ProgramFrameProps {
record: Process
+ assetId: string
+
client: ClientState
title: string
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index bb12fa4..d9f962d 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -93,7 +93,16 @@ export default function Workspace() {
function icon(record: { program: string }) {
- return programIcon(application.doors.program, record.program)
+ return programIcon(application.doors.program, program(record.program).assetId)
+ }
+
+ function program(identity: string) {
+
+ const found = authManager.programManager.programs.get(identity)
+
+ if (!found) throw new Error(`The Program "${identity}" does not exist`)
+
+ return found
}
function renderWindows(layer: Layer) {
@@ -106,6 +115,8 @@ export default function Workspace() {
record={record}
+ assetId={program(record.program).assetId}
+
client={client}
title={local.title}
diff --git a/source/client/view/structure/desktop/programs/program-icon.ts b/source/client/view/structure/desktop/programs/program-icon.ts
index 3de0244..18f4650 100644
--- a/source/client/view/structure/desktop/programs/program-icon.ts
+++ b/source/client/view/structure/desktop/programs/program-icon.ts
@@ -1,7 +1,7 @@
const icon = "icons/medium.png"
/** The one browser location used for a program's desktop representation. */
-export default function programIcon(door: string, identity: string) {
+export default function programIcon(door: string, assetId: string) {
- return `${door}/${identity}/${icon}`
+ return `${door}/${assetId}/${icon}`
}
diff --git a/source/client/view/structure/desktop/taskbar/launcher/programs-section.tsx b/source/client/view/structure/desktop/taskbar/launcher/programs-section.tsx
index 7a65122..687f698 100644
--- a/source/client/view/structure/desktop/taskbar/launcher/programs-section.tsx
+++ b/source/client/view/structure/desktop/taskbar/launcher/programs-section.tsx
@@ -26,7 +26,7 @@ export default function ProgramsSection({ onChoose }: ProgramsSectionProps) {
key={record.identity}
- icon={programIcon(application.doors.program, record.identity)}
+ icon={programIcon(application.doors.program, record.assetId)}
record={record}
diff --git a/source/client/view/structure/desktop/windows/process-window.tsx b/source/client/view/structure/desktop/windows/process-window.tsx
index d840425..38beedb 100644
--- a/source/client/view/structure/desktop/windows/process-window.tsx
+++ b/source/client/view/structure/desktop/windows/process-window.tsx
@@ -17,7 +17,7 @@ const settleDelay = 80
* props so memoization can see which process actually changed even though
* the peer deliberately keeps each Process instance alive and mutates it.
*/
-export default memo(function ({ identity, record, client, title, icon, position, size, localSurface, geometryAnimation, onLocalAnimationComplete, onLocalRepresentation, paintSurfaceSize, depth, active, minimized, closing, stopping, entering, bare, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {
+export default memo(function ({ identity, record, assetId, client, title, icon, position, size, localSurface, geometryAnimation, onLocalAnimationComplete, onLocalRepresentation, paintSurfaceSize, depth, active, minimized, closing, stopping, entering, bare, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {
const activate = useCallback(() => onRaise(record), [onRaise, record])
@@ -39,7 +39,7 @@ export default memo(function ({ identity, record, client, title, icon, position,
const represent = useCallback((reader: LocalGeometryReader | null) => onLocalRepresentation(record.identity, reader), [onLocalRepresentation, record])
- const frameSource = programFrameSource(record, client, door)
+ const frameSource = programFrameSource(assetId, client, door)
const [loading, setLoading] = useState<LoadingState>({ source: null, phase: "loading" })
@@ -150,6 +150,8 @@ export default memo(function ({ identity, record, client, title, icon, position,
record={record}
+ assetId={assetId}
+
client={client}
title={title}
@@ -194,6 +196,8 @@ interface ProcessWindowProps {
record: Process
+ assetId: string
+
client: ClientState
title: string
diff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
index a70111a..cc7acef 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
@@ -252,6 +252,12 @@ export default class ProgramManager extends TheLink {
return this.programs.get(identity)?.program ?? null
}
+ /** Resolves the runtime Program that owns one browser asset address. */
+ public fromAsset(assetId: string) {
+
+ return [...this.programs.values()].find(entry => entry.program.assetId === assetId)?.program ?? null
+ }
+
/** Resolve an exact runtime Program handle without retargeting a replacement. */
public held(value: unknown) {
diff --git a/source/server/core/link-manager/auth-manager/program-manager/program.ts b/source/server/core/link-manager/auth-manager/program-manager/program.ts
index c7a8ef4..0d2d82c 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/program.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/program.ts
@@ -25,9 +25,8 @@ import { permissionCatalog } from "@server/core/permissions"
* question, asked when the system is told to rely on it, and asked
* again by whatever uses it, because the world moves in between.
*
- * Identity is the program's one public address, whether or not it is
- * installed. The browser asset view uses that same domain address rather
- * than inventing a second identity for the same Program.
+ * Identity is the program's stable public address, whether or not it is
+ * installed. Browser assets use a separate runtime identity.
*/
export default class Program {
@@ -36,6 +35,9 @@ export default class Program {
/** Opaque identity of this runtime Program entity. */
public readonly reference = randomUUID()
+ /** Runtime identity of this Program's browser assets. */
+ public readonly assetId = randomUUID()
+
/** Changes whenever this runtime Program is replaced in place. */
public revision = 0
@@ -199,6 +201,8 @@ export default class Program {
identity: this.identity,
+ assetId: this.assetId,
+
name: this.name,
version: version ?? null,
diff --git a/source/server/core/system.ts b/source/server/core/system.ts
index c94ddd3..f93d2e6 100644
--- a/source/server/core/system.ts
+++ b/source/server/core/system.ts
@@ -267,6 +267,7 @@ export default class System {
return Object.freeze({
reference: program.reference,
identity: program.identity,
+ assetId: program.assetId,
name: program.name,
version: program.config.version ?? null,
description: program.config.description ?? null,
@@ -308,6 +309,7 @@ export default class System {
programSnapshot: Object.freeze({
reference: owner.reference,
identity: owner.identity,
+ assetId: owner.assetId,
name: owner.name,
version: owner.version,
description: owner.description,
diff --git a/source/server/view/program.ts b/source/server/view/program.ts
index 4a36bcd..073abd7 100644
--- a/source/server/view/program.ts
+++ b/source/server/view/program.ts
@@ -9,9 +9,9 @@ import { developmentResponse, developmentSocket, developmentTarget } from "./pro
/**
* The browser representation of one Program domain.
*
- * Every Client document uses `/program/<identity>/assets`, independently of
+ * Every Client document uses `/program/<assetId>/assets`, independently of
* whether its source is an installed directory or a live development server.
- * Icons use the same Program identity beneath `/program/<identity>/icons`.
+ * Icons use the same asset identity beneath `/program/<assetId>/icons`.
*/
export default function (application: Application) {
@@ -36,15 +36,15 @@ export default function (application: Application) {
return context.text("Program assets are available")
})
- program.get("/:identity/assets", context => context.redirect(`${new URL(context.req.url).pathname}/`))
+ program.get("/:assetId{[0-9a-f-]{36}}/assets", context => context.redirect(`${new URL(context.req.url).pathname}/`))
// A development Client's WebSocket is the same asset source as its HTTP
// documents. Bridging it here keeps HMR beneath the Program asset address.
- program.use("/:identity/assets/:path{.*}", async (context, next) => {
+ program.use("/:assetId{[0-9a-f-]{36}}/assets/:path{.*}", async (context, next) => {
if (context.req.header("upgrade")?.toLowerCase() !== "websocket") return await next()
- const found = programManager.reach(context.req.param("identity"))
+ const found = programManager.fromAsset(context.req.param("assetId") ?? "")
if (!found) return context.text("Unknown program", 404)
@@ -55,11 +55,11 @@ export default function (application: Application) {
return developmentSocket(context, target)
})
- program.all("/:identity/assets/:path{.*}", async context => {
+ program.all("/:assetId{[0-9a-f-]{36}}/assets/:path{.*}", async context => {
- const identity = context.req.param("identity")
+ const assetId = context.req.param("assetId") ?? ""
- const found = programManager.reach(identity)
+ const found = programManager.fromAsset(assetId)
if (!found) return context.text("Unknown program", 404)
@@ -76,14 +76,14 @@ export default function (application: Application) {
root,
- rewriteRequestPath: path => path.slice(`${doors.program}/${identity}/assets`.length)
+ rewriteRequestPath: path => path.slice(`${doors.program}/${assetId}/assets`.length)
})(context, async () => undefined)
})
- program.get("/:identity/icons/:file", async context => {
+ program.get("/:assetId{[0-9a-f-]{36}}/icons/:file", async context => {
- const found = programManager.reach(context.req.param("identity"))
+ const found = programManager.fromAsset(context.req.param("assetId") ?? "")
if (!found) return context.text("Unknown program", 404)