@adea-ai/spatial-protocol 0.15.3 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Entitlement gate and loading contract for the Agent Sim engine.
3
+ *
4
+ * The engine (models, textures, audio, runtime code) lives in the private
5
+ * agent-sim repo and never ships in this public one. The shell may only
6
+ * resolve the engine remote when the deployment is entitled to it:
7
+ *
8
+ * - Web: the site is served from an official Adea domain (adea.dev /
9
+ * adea.io, including subdomains). Forked deployments on other origins
10
+ * are refused before any engine fetch happens.
11
+ * - Desktop / any build: an official build packs the engine into its own
12
+ * assets at build time (see scripts/pack-agent-sim.mjs, wired into the
13
+ * release lanes). The pack writes a manifest at a well-known same-origin
14
+ * URL; plain checkouts and fork builds simply do not have it.
15
+ *
16
+ * Both signals are checked; the engine is fetched only when both pass, so
17
+ * copying engine assets into a forked website still fails the host gate.
18
+ */
19
+ export declare const OFFICIAL_AGENT_SIM_WEB_HOSTS: readonly ["adea.dev", "adea.io"];
20
+ export type AgentSimWebPlatform = 'web' | 'desktop';
21
+ export type AgentSimEngineManifest = {
22
+ /**
23
+ * Same-origin ES module URL of the engine entry. The entry must register
24
+ * the `window.__adeaAgentSim` mount API documented in the package README
25
+ * before its load event resolves.
26
+ */
27
+ entryUrl: string;
28
+ /** Engine pack version (agent-sim repo release). Diagnostics only. */
29
+ version: string;
30
+ };
31
+ /** Well-known same-origin URL the official pack lane writes the manifest to. */
32
+ export declare function agentSimEngineManifestUrl(origin: string): string;
33
+ /**
34
+ * Parse and validate an engine manifest fetched from a trusted origin.
35
+ * Rejects payloads that would point the loader off the deployment's own
36
+ * origin — the engine ships with the site, never from third parties.
37
+ */
38
+ export declare function parseAgentSimEngineManifest(value: unknown, origin: string): {
39
+ ok: true;
40
+ manifest: AgentSimEngineManifest;
41
+ } | {
42
+ ok: false;
43
+ };
44
+ /**
45
+ * Whether a web origin is an official Adea deployment allowed to resolve the
46
+ * Agent Sim engine remote. Desktop builds skip this check: they are gated by
47
+ * the packed engine manifest instead.
48
+ */
49
+ export declare function isOfficialAgentSimWebOrigin(origin: string): boolean;
50
+ /**
51
+ * Hosts where a developer runs the shell locally. Local development is
52
+ * entitled only when the engine was explicitly packed into the local build
53
+ * (engine manifest present); the host check alone never entitles it.
54
+ */
55
+ export declare function isLocalDevHost(hostname: string): boolean;
package/dist/engine.js ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Entitlement gate and loading contract for the Agent Sim engine.
3
+ *
4
+ * The engine (models, textures, audio, runtime code) lives in the private
5
+ * agent-sim repo and never ships in this public one. The shell may only
6
+ * resolve the engine remote when the deployment is entitled to it:
7
+ *
8
+ * - Web: the site is served from an official Adea domain (adea.dev /
9
+ * adea.io, including subdomains). Forked deployments on other origins
10
+ * are refused before any engine fetch happens.
11
+ * - Desktop / any build: an official build packs the engine into its own
12
+ * assets at build time (see scripts/pack-agent-sim.mjs, wired into the
13
+ * release lanes). The pack writes a manifest at a well-known same-origin
14
+ * URL; plain checkouts and fork builds simply do not have it.
15
+ *
16
+ * Both signals are checked; the engine is fetched only when both pass, so
17
+ * copying engine assets into a forked website still fails the host gate.
18
+ */
19
+ export const OFFICIAL_AGENT_SIM_WEB_HOSTS = ['adea.dev', 'adea.io'];
20
+ /** Known-public hostname suffixes never treated as official even if they embed an official host. */
21
+ const NON_OFFICIAL_SUFFIXES = ['.local', '.localhost', '.internal'];
22
+ const OFFICIAL_LOCAL_HOSTS = ['localhost', '127.0.0.1', '[::1]'];
23
+ /** Well-known same-origin URL the official pack lane writes the manifest to. */
24
+ export function agentSimEngineManifestUrl(origin) {
25
+ return new URL('/assets/agent-sim/engine.json', origin).toString();
26
+ }
27
+ /**
28
+ * Parse and validate an engine manifest fetched from a trusted origin.
29
+ * Rejects payloads that would point the loader off the deployment's own
30
+ * origin — the engine ships with the site, never from third parties.
31
+ */
32
+ export function parseAgentSimEngineManifest(value, origin) {
33
+ if (typeof value !== 'object' || value === null)
34
+ return { ok: false };
35
+ const entryUrl = value.engine?.entryUrl;
36
+ const version = value.engine?.version;
37
+ if (typeof entryUrl !== 'string' || entryUrl.length === 0)
38
+ return { ok: false };
39
+ if (typeof version !== 'string' || version.length === 0)
40
+ return { ok: false };
41
+ let resolved;
42
+ try {
43
+ resolved = new URL(entryUrl, origin);
44
+ }
45
+ catch {
46
+ return { ok: false };
47
+ }
48
+ if (resolved.origin !== new URL(origin).origin)
49
+ return { ok: false };
50
+ if (!resolved.pathname.endsWith('.js'))
51
+ return { ok: false };
52
+ return { ok: true, manifest: { entryUrl: resolved.toString(), version } };
53
+ }
54
+ /**
55
+ * Whether a web origin is an official Adea deployment allowed to resolve the
56
+ * Agent Sim engine remote. Desktop builds skip this check: they are gated by
57
+ * the packed engine manifest instead.
58
+ */
59
+ export function isOfficialAgentSimWebOrigin(origin) {
60
+ let url;
61
+ try {
62
+ url = new URL(origin);
63
+ }
64
+ catch {
65
+ return false;
66
+ }
67
+ if (url.protocol !== 'https:')
68
+ return false;
69
+ const host = url.hostname.toLowerCase();
70
+ if (NON_OFFICIAL_SUFFIXES.some((suffix) => host.endsWith(suffix)))
71
+ return false;
72
+ return OFFICIAL_AGENT_SIM_WEB_HOSTS.some((official) => host === official || host.endsWith(`.${official}`));
73
+ }
74
+ /**
75
+ * Hosts where a developer runs the shell locally. Local development is
76
+ * entitled only when the engine was explicitly packed into the local build
77
+ * (engine manifest present); the host check alone never entitles it.
78
+ */
79
+ export function isLocalDevHost(hostname) {
80
+ const host = hostname.toLowerCase();
81
+ return OFFICIAL_LOCAL_HOSTS.includes(host) || host.endsWith('.localhost');
82
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { SceneManifest, SceneStartPosition, SceneZone } from '@adea-ai/asset-manifests';
2
+ export { agentSimEngineManifestUrl, isLocalDevHost, isOfficialAgentSimWebOrigin, parseAgentSimEngineManifest, OFFICIAL_AGENT_SIM_WEB_HOSTS, type AgentSimEngineManifest, } from './engine';
2
3
  export { hqHomeManifest, hqWorkManifest } from './manifests';
3
4
  export { appRouteHref, encodeSceneStartPosition, portalNavigationHref, readSceneStartPosition, type PortalNavigation, type SceneApp, } from './scene-spawn';
4
5
  export { createSceneTelemetryEnvelope, MAX_SCENE_TELEMETRY_BYTES, onRouterTransitionStart, parseScenePerformanceReport, recordNavigation, SCENE_TELEMETRY_LOG_PREFIX, type SceneNavigationType, type ScenePerformanceReport, type SceneRuntimeStats, type SceneTelemetryEnvelope, } from './telemetry';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { agentSimEngineManifestUrl, isLocalDevHost, isOfficialAgentSimWebOrigin, parseAgentSimEngineManifest, OFFICIAL_AGENT_SIM_WEB_HOSTS, } from './engine';
1
2
  export { hqHomeManifest, hqWorkManifest } from './manifests';
2
3
  export { appRouteHref, encodeSceneStartPosition, portalNavigationHref, readSceneStartPosition, } from './scene-spawn';
3
4
  export { createSceneTelemetryEnvelope, MAX_SCENE_TELEMETRY_BYTES, onRouterTransitionStart, parseScenePerformanceReport, recordNavigation, SCENE_TELEMETRY_LOG_PREFIX, } from './telemetry';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/spatial-protocol",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "description": "Shell↔engine contract for the Adea spatial view: scene mount manifests, spawn URL helpers, and scene telemetry schemas. Pure types — no rendering, no binaries.",
5
5
  "keywords": [
6
6
  "manifest",
@@ -42,6 +42,6 @@
42
42
  "typecheck": "tsc -p tsconfig.json --noEmit"
43
43
  },
44
44
  "dependencies": {
45
- "@adea-ai/asset-manifests": "^0.15.3"
45
+ "@adea-ai/asset-manifests": "^0.16.0"
46
46
  }
47
47
  }
package/src/engine.ts ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Entitlement gate and loading contract for the Agent Sim engine.
3
+ *
4
+ * The engine (models, textures, audio, runtime code) lives in the private
5
+ * agent-sim repo and never ships in this public one. The shell may only
6
+ * resolve the engine remote when the deployment is entitled to it:
7
+ *
8
+ * - Web: the site is served from an official Adea domain (adea.dev /
9
+ * adea.io, including subdomains). Forked deployments on other origins
10
+ * are refused before any engine fetch happens.
11
+ * - Desktop / any build: an official build packs the engine into its own
12
+ * assets at build time (see scripts/pack-agent-sim.mjs, wired into the
13
+ * release lanes). The pack writes a manifest at a well-known same-origin
14
+ * URL; plain checkouts and fork builds simply do not have it.
15
+ *
16
+ * Both signals are checked; the engine is fetched only when both pass, so
17
+ * copying engine assets into a forked website still fails the host gate.
18
+ */
19
+
20
+ export const OFFICIAL_AGENT_SIM_WEB_HOSTS = ['adea.dev', 'adea.io'] as const
21
+
22
+ /** Known-public hostname suffixes never treated as official even if they embed an official host. */
23
+ const NON_OFFICIAL_SUFFIXES = ['.local', '.localhost', '.internal']
24
+ const OFFICIAL_LOCAL_HOSTS = ['localhost', '127.0.0.1', '[::1]']
25
+
26
+ export type AgentSimWebPlatform = 'web' | 'desktop'
27
+
28
+ export type AgentSimEngineManifest = {
29
+ /**
30
+ * Same-origin ES module URL of the engine entry. The entry must register
31
+ * the `window.__adeaAgentSim` mount API documented in the package README
32
+ * before its load event resolves.
33
+ */
34
+ entryUrl: string
35
+ /** Engine pack version (agent-sim repo release). Diagnostics only. */
36
+ version: string
37
+ }
38
+
39
+ /** Well-known same-origin URL the official pack lane writes the manifest to. */
40
+ export function agentSimEngineManifestUrl(origin: string): string {
41
+ return new URL('/assets/agent-sim/engine.json', origin).toString()
42
+ }
43
+
44
+ /**
45
+ * Parse and validate an engine manifest fetched from a trusted origin.
46
+ * Rejects payloads that would point the loader off the deployment's own
47
+ * origin — the engine ships with the site, never from third parties.
48
+ */
49
+ export function parseAgentSimEngineManifest(
50
+ value: unknown,
51
+ origin: string
52
+ ): { ok: true; manifest: AgentSimEngineManifest } | { ok: false } {
53
+ if (typeof value !== 'object' || value === null) return { ok: false }
54
+ const entryUrl = (value as { engine?: { entryUrl?: unknown } }).engine?.entryUrl
55
+ const version = (value as { engine?: { version?: unknown } }).engine?.version
56
+ if (typeof entryUrl !== 'string' || entryUrl.length === 0) return { ok: false }
57
+ if (typeof version !== 'string' || version.length === 0) return { ok: false }
58
+ let resolved: URL
59
+ try {
60
+ resolved = new URL(entryUrl, origin)
61
+ } catch {
62
+ return { ok: false }
63
+ }
64
+ if (resolved.origin !== new URL(origin).origin) return { ok: false }
65
+ if (!resolved.pathname.endsWith('.js')) return { ok: false }
66
+ return { ok: true, manifest: { entryUrl: resolved.toString(), version } }
67
+ }
68
+
69
+ /**
70
+ * Whether a web origin is an official Adea deployment allowed to resolve the
71
+ * Agent Sim engine remote. Desktop builds skip this check: they are gated by
72
+ * the packed engine manifest instead.
73
+ */
74
+ export function isOfficialAgentSimWebOrigin(origin: string): boolean {
75
+ let url: URL
76
+ try {
77
+ url = new URL(origin)
78
+ } catch {
79
+ return false
80
+ }
81
+ if (url.protocol !== 'https:') return false
82
+ const host = url.hostname.toLowerCase()
83
+ if (NON_OFFICIAL_SUFFIXES.some((suffix) => host.endsWith(suffix))) return false
84
+ return OFFICIAL_AGENT_SIM_WEB_HOSTS.some(
85
+ (official) => host === official || host.endsWith(`.${official}`)
86
+ )
87
+ }
88
+
89
+ /**
90
+ * Hosts where a developer runs the shell locally. Local development is
91
+ * entitled only when the engine was explicitly packed into the local build
92
+ * (engine manifest present); the host check alone never entitles it.
93
+ */
94
+ export function isLocalDevHost(hostname: string): boolean {
95
+ const host = hostname.toLowerCase()
96
+ return OFFICIAL_LOCAL_HOSTS.includes(host) || host.endsWith('.localhost')
97
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,12 @@
1
1
  export type { SceneManifest, SceneStartPosition, SceneZone } from '@adea-ai/asset-manifests'
2
+ export {
3
+ agentSimEngineManifestUrl,
4
+ isLocalDevHost,
5
+ isOfficialAgentSimWebOrigin,
6
+ parseAgentSimEngineManifest,
7
+ OFFICIAL_AGENT_SIM_WEB_HOSTS,
8
+ type AgentSimEngineManifest,
9
+ } from './engine'
2
10
  export { hqHomeManifest, hqWorkManifest } from './manifests'
3
11
  export {
4
12
  appRouteHref,