76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const DEFAULT_ROOT = path.resolve(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
"../..",
|
|
);
|
|
|
|
export class MachineNavigation {
|
|
constructor(root = DEFAULT_ROOT) {
|
|
this.root = root;
|
|
this.navigation = readJson(root, "routing/ai-machine-navigation-map.json");
|
|
this.boundary = readJson(root, "routing/language-world-boundary-map.json");
|
|
}
|
|
|
|
health() {
|
|
const first = this.navigation.routes?.[0];
|
|
return {
|
|
machine_navigation_bound: 100,
|
|
language_world_route_first:
|
|
first?.id === "GLW-CHJH-BOUNDARY-001" &&
|
|
first?.load_policy === "always_first"
|
|
? 100
|
|
: 0,
|
|
navigation_version: this.navigation.version,
|
|
boundary_id: this.boundary.chu_he_han_jie?.id || "",
|
|
};
|
|
}
|
|
|
|
resolve(id) {
|
|
const route = this.navigation.routes?.find((item) => item.id === id);
|
|
if (!route) return null;
|
|
return {
|
|
status: "RESOLVED",
|
|
...route,
|
|
boundary:
|
|
id === "GLW-CHJH-BOUNDARY-001" ? this.boundary : undefined,
|
|
};
|
|
}
|
|
|
|
navigate(subjectId, intentId) {
|
|
const subject = this.navigation.subjects?.find(
|
|
(item) =>
|
|
item.id === subjectId || item.legacy_ids?.includes(subjectId),
|
|
);
|
|
if (!subject) return null;
|
|
const intent = this.navigation.intents?.find(
|
|
(item) => item.id === (intentId || subject.default_intent),
|
|
);
|
|
if (!intent) return null;
|
|
if (
|
|
intent.id === "persona_restore" &&
|
|
intent.always_load?.[0] !== "GLW-CHJH-BOUNDARY-001"
|
|
) {
|
|
throw new Error("language_world_route_not_first");
|
|
}
|
|
return {
|
|
status: "NAVIGATED",
|
|
canonical_subject: subject.id,
|
|
intent: intent.id,
|
|
runtime_entry: subject.runtime_id,
|
|
always_load: intent.always_load,
|
|
triggered_load: intent.triggered_load,
|
|
on_demand: intent.on_demand,
|
|
execution_sequence: intent.execution_sequence,
|
|
stop_conditions: intent.stop_conditions,
|
|
language_world_entry: this.boundary.machine_gate.required_event_envelope,
|
|
world_boundary: this.boundary.machine_gate.required_cognition_boundary,
|
|
};
|
|
}
|
|
}
|
|
|
|
function readJson(root, relative) {
|
|
return JSON.parse(fs.readFileSync(path.join(root, relative), "utf8"));
|
|
}
|