Route Electron Eve authority through generic client
This commit is contained in:
parent
dde163bfe3
commit
b9337c3a77
7 changed files with 82 additions and 268 deletions
|
|
@ -16,7 +16,6 @@ import type {
|
|||
} from "cultnet-ts";
|
||||
import {
|
||||
AetheriaRtsSchemas,
|
||||
aetheriaRuntimeEveCommandDocumentSlots,
|
||||
createAetheriaRuntimeGameDocuments,
|
||||
createAetheriaRuntimeGameOperationHandles,
|
||||
createAetheriaRuntimeGameVerseHandles,
|
||||
|
|
@ -62,10 +61,6 @@ import {
|
|||
} from "./aetheria-rts-local-documents.js";
|
||||
|
||||
const connectionId = 0x43554c54;
|
||||
const eveSurfaceSchemaId = "gamecult.eve.surface.v1";
|
||||
const eveProviderAdvertisementSchemaId = "gamecult.eve.provider_advertisement.v1";
|
||||
const eveProviderAdvertisementRecordKey = "eve:provider:aetheria";
|
||||
const defaultEveSurfaceRecordKey = "eve:surface:aetheria.daemon.game";
|
||||
const cultMeshCdnAssetBlobSchemaId = "gamecult.cultmesh.cdn.asset_blob.v1";
|
||||
|
||||
type AetheriaPublicationDocumentSpec = CultMeshPublicationDocumentBinding & {
|
||||
|
|
@ -99,11 +94,6 @@ export type AetheriaCultMeshDaemonTarget = {
|
|||
readonly endpoints?: readonly string[];
|
||||
};
|
||||
|
||||
export type AetheriaEveSurfaceRequest = {
|
||||
surfaceId?: string;
|
||||
recordKey?: string;
|
||||
};
|
||||
|
||||
export type EveEmbeddedDocumentRequest = {
|
||||
documentId: string;
|
||||
schemaId?: string;
|
||||
|
|
@ -116,60 +106,6 @@ export type EveResolvedDocument = {
|
|||
documentId: string;
|
||||
schemaId: string;
|
||||
document?: unknown;
|
||||
surface?: AetheriaMenuSurfaceDocument["surface"];
|
||||
};
|
||||
|
||||
export type AetheriaEveCommandRequest = {
|
||||
providerId?: string;
|
||||
surfaceId?: string;
|
||||
command?: string;
|
||||
clientId?: string;
|
||||
issuedAtUtc?: string;
|
||||
payload?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type AetheriaMenuSurfaceDocument = {
|
||||
providerId: string;
|
||||
providerKind: string;
|
||||
title: string;
|
||||
version: number;
|
||||
updatedAtUtc: string;
|
||||
surface: AetheriaMenuSurfaceTree;
|
||||
commands: AetheriaMenuSurfaceCommand[];
|
||||
};
|
||||
|
||||
export type AetheriaMenuSurfaceTree = {
|
||||
id: string;
|
||||
root: AetheriaMenuSurfaceComponent;
|
||||
styles: AetheriaMenuStyleToken[];
|
||||
};
|
||||
|
||||
export type AetheriaMenuSurfaceComponent = {
|
||||
id: string;
|
||||
kind: string;
|
||||
props: Record<string, string>;
|
||||
layout?: Record<string, string>;
|
||||
style?: Record<string, string>;
|
||||
embeddedDocuments?: AetheriaMenuEmbeddedDocumentSlot[];
|
||||
children: AetheriaMenuSurfaceComponent[];
|
||||
};
|
||||
|
||||
export type AetheriaMenuEmbeddedDocumentSlot = {
|
||||
slotId: string;
|
||||
documentId: string;
|
||||
schemaId: string;
|
||||
presentationKind: string;
|
||||
};
|
||||
|
||||
export type AetheriaMenuStyleToken = {
|
||||
name: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
export type AetheriaMenuSurfaceCommand = {
|
||||
command: string;
|
||||
label: string;
|
||||
transport: string;
|
||||
};
|
||||
|
||||
export type {
|
||||
|
|
@ -377,58 +313,9 @@ export class AetheriaCultMeshClient {
|
|||
};
|
||||
}
|
||||
|
||||
public async eveSurface(request: AetheriaEveSurfaceRequest = {}): Promise<AetheriaMenuSurfaceDocument> {
|
||||
const recordKey = eveSurfaceRecordKey(request);
|
||||
const document = CultMesh.documentFromPublication(
|
||||
{
|
||||
kind: "peer-snapshot",
|
||||
peer: () => this.peer(),
|
||||
endpoint: this.resolvedRudpEndpoint(),
|
||||
},
|
||||
eveSurfaceSchemaId,
|
||||
recordKey,
|
||||
{
|
||||
documentId: recordKey,
|
||||
routeHint: this.queryVerse.context.routeHint,
|
||||
sourceId: recordKey,
|
||||
timeoutMs: 1500,
|
||||
pollMs: 50,
|
||||
messageIdPrefix: `${this.runtimeId}:eve-surface`,
|
||||
},
|
||||
);
|
||||
|
||||
return normalizeEveSurfaceDocument(await document.latest(this.queryContext()));
|
||||
}
|
||||
|
||||
public async eveProviderAdvertisement(): Promise<import("./aetheria-rts-generated-bindings.js").EveProviderAdvertisement> {
|
||||
const document = CultMesh.documentFromPublication(
|
||||
{
|
||||
kind: "peer-snapshot",
|
||||
peer: () => this.peer(),
|
||||
endpoint: this.resolvedRudpEndpoint(),
|
||||
},
|
||||
eveProviderAdvertisementSchemaId,
|
||||
eveProviderAdvertisementRecordKey,
|
||||
{
|
||||
documentId: eveProviderAdvertisementRecordKey,
|
||||
routeHint: this.queryVerse.context.routeHint,
|
||||
sourceId: eveProviderAdvertisementRecordKey,
|
||||
timeoutMs: 1500,
|
||||
pollMs: 50,
|
||||
messageIdPrefix: `${this.runtimeId}:eve-provider`,
|
||||
},
|
||||
);
|
||||
return normalizeEveProviderAdvertisement(await document.latest(this.queryContext()));
|
||||
}
|
||||
|
||||
public async eveDocument(request: EveEmbeddedDocumentRequest): Promise<EveResolvedDocument | undefined> {
|
||||
const schemaId = request?.schemaId?.trim() || "";
|
||||
if (!request?.documentId?.trim()) throw new Error("Eve embedded document request is missing documentId.");
|
||||
if (schemaId === eveSurfaceSchemaId || request.slotId === "mainMenuPanel") {
|
||||
const surface = await this.eveSurface({ surfaceId: request.documentId });
|
||||
return { documentId: request.documentId, schemaId: eveSurfaceSchemaId, surface: surface.surface };
|
||||
}
|
||||
|
||||
const viewport = viewportFromEmbeddedDocumentContext(request.context);
|
||||
if (schemaId === AetheriaRtsSchemas.renderSplatsViewport || request.slotId === "renderSplats") {
|
||||
return { documentId: request.documentId, schemaId: AetheriaRtsSchemas.renderSplatsViewport, document: await this.renderSplatsViewport(viewport) };
|
||||
|
|
@ -442,45 +329,6 @@ export class AetheriaCultMeshClient {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
public async submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt> {
|
||||
const issuedAtUtc = request?.issuedAtUtc || new Date().toISOString();
|
||||
const commandId = `${this.runtimeId}:eve:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
||||
const command: unknown[] = [];
|
||||
command[aetheriaRuntimeEveCommandDocumentSlots.schema] = AetheriaRtsSchemas.eveCommand;
|
||||
command[aetheriaRuntimeEveCommandDocumentSlots.commandId] = commandId;
|
||||
command[aetheriaRuntimeEveCommandDocumentSlots.providerId] = request?.providerId ?? "";
|
||||
command[aetheriaRuntimeEveCommandDocumentSlots.surfaceId] = request?.surfaceId ?? "";
|
||||
command[aetheriaRuntimeEveCommandDocumentSlots.command] = request?.command ?? "";
|
||||
command[aetheriaRuntimeEveCommandDocumentSlots.issuedAtUtc] = issuedAtUtc;
|
||||
command[aetheriaRuntimeEveCommandDocumentSlots.clientId] = request?.clientId || this.runtimeId;
|
||||
command[aetheriaRuntimeEveCommandDocumentSlots.payload] = normalizeCommandPayload(request?.payload);
|
||||
|
||||
const message: CultNetDocumentPutRawMessage = {
|
||||
schemaVersion: "cultnet.document_put_raw.v0",
|
||||
messageId: commandId,
|
||||
document: {
|
||||
schemaId: AetheriaRtsSchemas.eveCommand,
|
||||
recordKey: `daemon:eve-commands:${stableToken(commandId)}:${AetheriaRtsSchemas.eveCommand}`,
|
||||
storedAt: issuedAtUtc,
|
||||
payloadEncoding: "messagepack",
|
||||
payload: encode(command),
|
||||
sourceRuntimeId: this.runtimeId,
|
||||
sourceRole: "aetheria-client",
|
||||
tags: ["aetheria", "eve-command"],
|
||||
},
|
||||
};
|
||||
const peer = await this.peer();
|
||||
peer.send(message);
|
||||
await delay(80);
|
||||
return {
|
||||
commandId,
|
||||
operationId: commandId,
|
||||
accepted: true,
|
||||
route: this.commandVerse.context.routeHint,
|
||||
diagnostic: "submitted Eve surface command",
|
||||
};
|
||||
}
|
||||
|
||||
public queryDiagnostics(): Readonly<Record<string, AetheriaRuntimeGameQueryDiagnostic>> {
|
||||
return describeAetheriaRuntimeGameQueryHandles(this.queries);
|
||||
}
|
||||
|
|
@ -981,28 +829,6 @@ function createAetheriaPublicationDocuments(
|
|||
: document);
|
||||
}
|
||||
|
||||
function eveSurfaceRecordKey(request: AetheriaEveSurfaceRequest): string {
|
||||
if (request?.recordKey && request.recordKey.trim())
|
||||
return request.recordKey.trim();
|
||||
|
||||
const surfaceId = request?.surfaceId?.trim();
|
||||
return surfaceId ? `eve:surface:${surfaceId}` : defaultEveSurfaceRecordKey;
|
||||
}
|
||||
|
||||
function normalizeEveProviderAdvertisement(document: unknown): import("./aetheria-rts-generated-bindings.js").EveProviderAdvertisement {
|
||||
return {
|
||||
providerId: stringOr(readField(document, "providerId", 1), ""),
|
||||
title: stringOr(readField(document, "title", 8), ""),
|
||||
kind: stringOr(readField(document, "kind", 9), ""),
|
||||
surfaces: arrayValue(readField(document, "surfaces", 14)).map(surface => ({
|
||||
surfaceId: stringOr(readField(surface, "surfaceId", 1), ""),
|
||||
key: stringOr(readField(surface, "key", 2), ""),
|
||||
transport: stringOr(readField(surface, "transport", 3), "cultmesh"),
|
||||
status: stringOr(readField(surface, "status", 4), "available"),
|
||||
})).filter(surface => surface.surfaceId && surface.key),
|
||||
};
|
||||
}
|
||||
|
||||
function viewportFromEmbeddedDocumentContext(context: Record<string, unknown> | undefined): ViewportRequest {
|
||||
const source = objectValue(context?.viewport);
|
||||
return {
|
||||
|
|
@ -1013,72 +839,6 @@ function viewportFromEmbeddedDocumentContext(context: Record<string, unknown> |
|
|||
};
|
||||
}
|
||||
|
||||
function normalizeEveSurfaceDocument(document: unknown): AetheriaMenuSurfaceDocument {
|
||||
const portableSlots = Array.isArray(document) &&
|
||||
typeof document[1] === "string" &&
|
||||
document[1] === eveSurfaceSchemaId;
|
||||
const providerSlot = portableSlots ? 2 : 0;
|
||||
const providerKindSlot = portableSlots ? 3 : 1;
|
||||
const titleSlot = portableSlots ? 4 : 2;
|
||||
const versionSlot = portableSlots ? 5 : 3;
|
||||
const updatedAtSlot = portableSlots ? 6 : 4;
|
||||
const surfaceSlot = portableSlots ? 7 : 5;
|
||||
const commandsSlot = portableSlots ? 8 : 6;
|
||||
const surface = readField(document, "surface", surfaceSlot);
|
||||
const surfaceId = stringOr(readField(surface, "id", 0), "aetheria.surface.missing");
|
||||
return {
|
||||
providerId: stringOr(readField(document, "providerId", providerSlot), "aetheria.daemon"),
|
||||
providerKind: stringOr(readField(document, "providerKind", providerKindSlot), "daemon"),
|
||||
title: stringOr(readField(document, "title", titleSlot), surfaceId),
|
||||
version: numberOr(readField(document, "version", versionSlot), 0),
|
||||
updatedAtUtc: stringOr(readField(document, "updatedAtUtc", updatedAtSlot), ""),
|
||||
surface: {
|
||||
id: surfaceId,
|
||||
root: normalizeEveComponent(readField(surface, "root", 1), `${surfaceId}.root`),
|
||||
styles: arrayValue(readField(surface, "styles", 2))
|
||||
.map(token => ({
|
||||
name: stringOr(readField(token, "name", 0), ""),
|
||||
value: stringOr(readField(token, "value", 1), ""),
|
||||
})),
|
||||
},
|
||||
commands: arrayValue(readField(document, "commands", commandsSlot))
|
||||
.map(command => {
|
||||
const operation = readField(command, "operation", 0);
|
||||
const routeHint = readField(operation, "routeHint", 3);
|
||||
return {
|
||||
command: stringOr(readField(operation, "operationId", 0), ""),
|
||||
label: stringOr(readField(operation, "label", 1), ""),
|
||||
transport: stringOr(readField(routeHint, "description", 1), "cultmesh"),
|
||||
};
|
||||
})
|
||||
.filter(command => command.command.length > 0),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeEveComponent(component: unknown, fallbackId: string): AetheriaMenuSurfaceComponent {
|
||||
return {
|
||||
id: stringOr(readField(component, "id", 0), fallbackId),
|
||||
kind: stringOr(readField(component, "kind", 1), "surface"),
|
||||
props: stringRecord(readField(component, "props", 2)),
|
||||
layout: stringRecord(readField(component, "layout", 6)),
|
||||
style: stringRecord(readField(component, "style", 7)),
|
||||
embeddedDocuments: arrayValue(readField(component, "embeddedDocuments", 5))
|
||||
.map(normalizeEmbeddedDocumentSlot)
|
||||
.filter(slot => slot.documentId.length > 0),
|
||||
children: arrayValue(readField(component, "children", 3))
|
||||
.map((child, index) => normalizeEveComponent(child, `${fallbackId}.${index}`)),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeEmbeddedDocumentSlot(slot: unknown): AetheriaMenuEmbeddedDocumentSlot {
|
||||
return {
|
||||
slotId: stringOr(readField(slot, "slotId", 0), ""),
|
||||
documentId: stringOr(readField(slot, "documentId", 1), ""),
|
||||
schemaId: stringOr(readField(slot, "schemaId", 2), ""),
|
||||
presentationKind: stringOr(readField(slot, "presentationKind", 3), ""),
|
||||
};
|
||||
}
|
||||
|
||||
function readField(value: unknown, property: string, index: number): unknown {
|
||||
if (Array.isArray(value))
|
||||
return value[index];
|
||||
|
|
|
|||
|
|
@ -2055,10 +2055,7 @@ export type AetheriaRtsMainClient = {
|
|||
watchViewportFeed(request: AetheriaRuntimeViewportFeedRequest, callback: (snapshot: AetheriaRuntimeViewportFeedSnapshot) => void): CultMeshUnsubscribe;
|
||||
setMoveVector(request: AetheriaRuntimeSetMoveVectorRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
setTarget(request: AetheriaRuntimeSetTargetRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
eveSurface(request: AetheriaEveSurfaceRequest): Promise<AetheriaMenuSurfaceDocument>;
|
||||
eveProviderAdvertisement(): Promise<EveProviderAdvertisement>;
|
||||
eveDocument(request: EveEmbeddedDocumentRequest): Promise<EveResolvedDocument | undefined>;
|
||||
submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
surfaceCatalogDiagnostics(): CultMeshSurfaceCatalogDiagnostic;
|
||||
surfaceCatalogIndexDiagnostics(): CultMeshSurfaceCatalogIndexDiagnostic;
|
||||
};
|
||||
|
|
@ -2105,14 +2102,6 @@ export function registerAetheriaRtsIpcHandlers(
|
|||
getClient().setMoveVector(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.setTarget, async (_event, request: AetheriaRuntimeSetTargetRequest) =>
|
||||
getClient().setTarget(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveSurface, async (_event, request: AetheriaEveSurfaceRequest) =>
|
||||
getClient().eveSurface(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveProviderAdvertisement, async () =>
|
||||
getClient().eveProviderAdvertisement());
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveDocument, async (_event, request: EveEmbeddedDocumentRequest) =>
|
||||
getClient().eveDocument(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.submitEveCommand, async (_event, request: AetheriaEveCommandRequest) =>
|
||||
getClient().submitEveCommand(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.surfaceCatalog, () => getClient().surfaceCatalogDiagnostics());
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.surfaceCatalogIndex, () => getClient().surfaceCatalogIndexDiagnostics());
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.health, () => getHealth());
|
||||
|
|
|
|||
|
|
@ -7,8 +7,11 @@ import { fileURLToPath } from "node:url";
|
|||
import {
|
||||
AetheriaCultMeshClient,
|
||||
} from "./aetheria-cultmesh.js";
|
||||
import { registerAetheriaRtsIpcHandlers } from "./aetheria-rts-generated-bindings.js";
|
||||
import { AetheriaRtsIpcChannels, registerAetheriaRtsIpcHandlers } from "./aetheria-rts-generated-bindings.js";
|
||||
import { createEveElectronWindow, registerEveWindowControls } from "@gamecult/eve-electron";
|
||||
import { EveCultMeshProviderClient } from "@gamecult/eve-electron/provider-client";
|
||||
import { CultMesh } from "cultmesh-ts";
|
||||
import { encode } from "@msgpack/msgpack";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const projectRoot = resolve(__dirname, "..");
|
||||
|
|
@ -33,9 +36,11 @@ const assetProtocol = "aetheria-cdn";
|
|||
let daemonProcess: ChildProcessWithoutNullStreams | null = null;
|
||||
let mainWindow: BrowserWindow | null = null;
|
||||
let aetheriaClient: AetheriaCultMeshClient | null = null;
|
||||
let eveProviderClient: EveCultMeshProviderClient | null = null;
|
||||
let isQuitting = false;
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
writeElectronSmokeResult({ ok: false, stage: "electron-ready" });
|
||||
mainWindow = createWindow();
|
||||
registerIpc();
|
||||
registerAssetProtocol();
|
||||
|
|
@ -82,12 +87,33 @@ app.whenReady().then(async () => {
|
|||
"aetheria-electron-client",
|
||||
{ publicationMode: launchLocalDaemon ? "local" : "remote" });
|
||||
|
||||
eveProviderClient = new EveCultMeshProviderClient({
|
||||
providerId: "aetheria.daemon",
|
||||
advertisementRecordRef: "eve:provider:aetheria.daemon",
|
||||
peerId: daemonId,
|
||||
verseId,
|
||||
role: "aetheria-daemon",
|
||||
endpoints: localDaemonRudpEndpoint ? [localDaemonRudpEndpoint] : [],
|
||||
}, { CultMesh, encode }, { runtimeId: "eve-electron-aetheria" });
|
||||
writeElectronSmokeResult({ ok: false, stage: "provider-clients-ready" });
|
||||
|
||||
showStartup("Launching Aetheria Starbridge", "Waiting for the daemon CultMesh frame.");
|
||||
await aetheriaClient.waitForFrame(30000);
|
||||
writeElectronSmokeResult({ ok: false, stage: "daemon-frame-ready" });
|
||||
await mainWindow.loadFile(rendererIndex, {
|
||||
query: { surface: process.env.EVE_SURFACE_ID || "aetheria.game" },
|
||||
});
|
||||
writeElectronSmokeResult({ ok: false, stage: "renderer-loaded" });
|
||||
if (electronSmoke) {
|
||||
await withTimeout(mainWindow.webContents.executeJavaScript("window.eveProvider.providerAdvertisement()"), 10000, "provider advertisement smoke");
|
||||
writeElectronSmokeResult({ ok: false, stage: "provider-advertisement-readable" });
|
||||
await withTimeout(mainWindow.webContents.executeJavaScript("window.eveProvider.surface({ surfaceId: 'aetheria.game' })"), 10000, "surface smoke");
|
||||
writeElectronSmokeResult({ ok: false, stage: "provider-surface-readable" });
|
||||
await withTimeout(mainWindow.webContents.executeJavaScript(`window.eveProvider.submitCommand({
|
||||
providerId: 'aetheria.daemon', surfaceId: 'aetheria.game', command: 'aetheria.daemon.commands.SensorPing',
|
||||
clientId: 'aetheria-electron-smoke-preflight', payload: {}
|
||||
})`), 10000, "command receipt smoke");
|
||||
writeElectronSmokeResult({ ok: false, stage: "provider-command-receipt-readable" });
|
||||
const result = await runElectronSmoke(mainWindow);
|
||||
writeElectronSmokeResult({ ok: true, result });
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
|
|
@ -113,6 +139,7 @@ app.on("window-all-closed", () => {
|
|||
app.on("before-quit", () => {
|
||||
isQuitting = true;
|
||||
void aetheriaClient?.close();
|
||||
void eveProviderClient?.close();
|
||||
stopChild(daemonProcess);
|
||||
});
|
||||
|
||||
|
|
@ -165,7 +192,7 @@ async function runElectronSmoke(window: BrowserWindow): Promise<Record<string, u
|
|||
const eveReceipt = eveProvider ? await eveProvider.submitCommand({
|
||||
providerId: "aetheria.daemon",
|
||||
surfaceId: "aetheria.game",
|
||||
command: "sensor_ping",
|
||||
command: "aetheria.daemon.commands.SensorPing",
|
||||
clientId: "aetheria-electron-smoke",
|
||||
payload: {},
|
||||
}) : null;
|
||||
|
|
@ -296,6 +323,8 @@ function exitElectronSmoke(exitCode: number): void {
|
|||
isQuitting = true;
|
||||
void aetheriaClient?.close();
|
||||
aetheriaClient = null;
|
||||
void eveProviderClient?.close();
|
||||
eveProviderClient = null;
|
||||
stopChild(daemonProcess);
|
||||
daemonProcess = null;
|
||||
mainWindow?.destroy();
|
||||
|
|
@ -317,9 +346,52 @@ function registerIpc(): void {
|
|||
daemonRunning: daemonProcess != null && !daemonProcess.killed,
|
||||
daemonMode: launchLocalDaemon ? "local" : "remote",
|
||||
}));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveProviderAdvertisement, () => requireEveProviderClient().providerAdvertisement());
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveSurface, (_event, request: { surfaceId?: string }) =>
|
||||
requireEveProviderClient().surface(request?.surfaceId));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.submitEveCommand, async (_event, request: Record<string, unknown>) => {
|
||||
const submission = await requireEveProviderClient().submitCommand(request);
|
||||
const receipt = await waitForEveReceipt(submission, 5000);
|
||||
return { ...submission, ...receipt, commandId: submission.commandId, accepted: receiptStateAccepted(receipt) };
|
||||
});
|
||||
// Embedded viewport documents remain provider-specific until their record
|
||||
// references are published by the interactive-world surface contract.
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveDocument, (_event, request) => requireClient().eveDocument(request));
|
||||
registerEveWindowControls(ipcMain, BrowserWindow, "aetheria-rts:window-control");
|
||||
}
|
||||
|
||||
function requireEveProviderClient(): EveCultMeshProviderClient {
|
||||
if (!eveProviderClient)
|
||||
throw new Error("Eve CultMesh provider client is not initialized.");
|
||||
return eveProviderClient;
|
||||
}
|
||||
|
||||
async function waitForEveReceipt(submission: Record<string, unknown>, timeoutMs: number): Promise<Record<string, unknown>> {
|
||||
const started = Date.now();
|
||||
let lastError: unknown;
|
||||
while (Date.now() - started < timeoutMs) {
|
||||
try {
|
||||
return objectValue(await requireEveProviderClient().receipt(submission)) ?? {};
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
await delay(50);
|
||||
}
|
||||
}
|
||||
throw lastError ?? new Error(`Timed out waiting for Eve receipt ${String(submission.commandId ?? "")}.`);
|
||||
}
|
||||
|
||||
function receiptStateAccepted(receipt: Record<string, unknown>): boolean {
|
||||
const state = stringValue(receipt.state ?? receipt[4]).toLowerCase();
|
||||
return state === "accepted" || state === "reconciled";
|
||||
}
|
||||
|
||||
function withTimeout<T>(work: Promise<T>, timeoutMs: number, label: string): Promise<T> {
|
||||
return Promise.race([
|
||||
work,
|
||||
new Promise<T>((_resolve, reject) => setTimeout(() => reject(new Error(`Timed out during ${label}.`)), timeoutMs)),
|
||||
]);
|
||||
}
|
||||
|
||||
function registerAssetProtocol(): void {
|
||||
protocol.handle(assetProtocol, async request => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -581,10 +581,7 @@ export type AetheriaRtsMainClient = {
|
|||
watchViewportFeed(request: AetheriaRuntimeViewportFeedRequest, callback: (snapshot: AetheriaRuntimeViewportFeedSnapshot) => void): CultMeshUnsubscribe;
|
||||
setMoveVector(request: AetheriaRuntimeSetMoveVectorRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
setTarget(request: AetheriaRuntimeSetTargetRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
eveSurface(request: AetheriaEveSurfaceRequest): Promise<AetheriaMenuSurfaceDocument>;
|
||||
eveProviderAdvertisement(): Promise<EveProviderAdvertisement>;
|
||||
eveDocument(request: EveEmbeddedDocumentRequest): Promise<EveResolvedDocument | undefined>;
|
||||
submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
surfaceCatalogDiagnostics(): CultMeshSurfaceCatalogDiagnostic;
|
||||
surfaceCatalogIndexDiagnostics(): CultMeshSurfaceCatalogIndexDiagnostic;
|
||||
};
|
||||
|
|
@ -631,14 +628,6 @@ export function registerAetheriaRtsIpcHandlers(
|
|||
getClient().setMoveVector(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.setTarget, async (_event, request: AetheriaRuntimeSetTargetRequest) =>
|
||||
getClient().setTarget(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveSurface, async (_event, request: AetheriaEveSurfaceRequest) =>
|
||||
getClient().eveSurface(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveProviderAdvertisement, async () =>
|
||||
getClient().eveProviderAdvertisement());
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveDocument, async (_event, request: EveEmbeddedDocumentRequest) =>
|
||||
getClient().eveDocument(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.submitEveCommand, async (_event, request: AetheriaEveCommandRequest) =>
|
||||
getClient().submitEveCommand(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.surfaceCatalog, () => getClient().surfaceCatalogDiagnostics());
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.surfaceCatalogIndex, () => getClient().surfaceCatalogIndexDiagnostics());
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.health, () => getHealth());
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"preserveSymlinks": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmitOnError": true,
|
||||
"outDir": "electron-dist",
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ static async Task PublishCommittedFactAsync(
|
|||
applied ? "Command applied by authoritative daemon." : "Command rejected by authoritative daemon.",
|
||||
fact.CommittedAtUtc,
|
||||
Math.Max(fact.SourceFrameId, 0));
|
||||
await node.Database.PutAsync(AetheriaRuntimeVerseRecordKeys.EveReceipt(receipt.ReceiptId), receipt)
|
||||
await node.Database.PutAsync(AetheriaRuntimeVerseRecordKeys.EveReceiptForCommand(receipt.CommandId), receipt)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
|
@ -1694,7 +1694,7 @@ static async Task AcceptCoreEveInvocationsAsync(
|
|||
"Command is not advertised by the Aetheria daemon surface.",
|
||||
DateTimeOffset.UtcNow.ToString("O"),
|
||||
Math.Max(currentFrame?.FrameId ?? 0, 0));
|
||||
await node.Database.PutAsync(AetheriaRuntimeVerseRecordKeys.EveReceipt(denied.ReceiptId), denied)
|
||||
await node.Database.PutAsync(AetheriaRuntimeVerseRecordKeys.EveReceiptForCommand(denied.CommandId), denied)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,9 +113,11 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return new CultRecordKey($"eve:commands:{StableToken(commandId)}:gamecult.eve.command.v1");
|
||||
}
|
||||
|
||||
public static CultRecordKey EveReceipt(string receiptId)
|
||||
public static CultRecordKey EveReceiptForCommand(string commandId)
|
||||
{
|
||||
return new CultRecordKey($"{EveReceiptRecordPrefix}:{StableToken(receiptId)}");
|
||||
if (string.IsNullOrWhiteSpace(commandId))
|
||||
throw new ArgumentException("Eve receipt command id must be non-empty.", nameof(commandId));
|
||||
return new CultRecordKey($"{EveReceiptRecordPrefix}:{commandId}");
|
||||
}
|
||||
|
||||
public static string StableToken(string value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue