Initial commit: one_os_compositor Odoo 20 addon — core OWL library + backend models + JWT auth

Includes:
- compositor.app, compositor.session, compositor.session.app, compositor.audit.log models
- /web/compositor/{token,apps,launch,audit} HTTP controllers with JWT (HS256)
- CompositorService OWL service (reusable via useService('compositor'))
- CompositorCanvas OWL component (reusable canvas wrapper)
- Security: compositor_group_user, compositor_group_manager groups + ir.access.csv rules
- 5 demo apps pre-loaded (gnome-calculator, xterm, gtk4-demo, glxgears, featherpad)
- Audit log capturing JWT issuance + app launch events
- Stub mode: launching apps returns a stub SurfaceHandle when proxy isn't connected
- Tested against Odoo 20 + PostgreSQL 17

Author: 1bspace.com
Parent company: 1B Global
License: Proprietary (1B Space internal use)
This commit is contained in:
1b-agent committed 2026-10-08 08:48:46 +00:00
commit 93a5a0a221
32 files changed
+2497

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="compositor_module_desc" name="1B Space Compositor Core">
<img class="oe_image" src="/one_os_compositor/static/img/icon.png"/>
<h2>1B Space Compositor Core</h2>
<p>Wayland-to-HTML5 compositor foundation — OWL library + backend models
for running real Linux apps inside Odoo natively.</p>
<p>Author: <strong>1bspace.com</strong> · Parent: <strong>1B Global</strong></p>
</template>
</data>
</odoo>
Binary file not shown.

After

Width:  |  Height:  |  Size: 179 B

@@ -0,0 +1,60 @@
/**
* 1B Space Compositor — Reusable Canvas Component
* ===============================================
*
* This is the OWL component other addons use to embed a Wayland surface
* inside the Odoo web client.
*
* Usage:
*
* <CompositorCanvas surface.bind="surface" />
*
* Or as a target for attachTo():
*
* const surface = await compositor.launchApp("gnome-calculator");
* surface.attachTo(this.canvasRef.el);
*/
import { Component, useRef, onMounted, onWillUnmount, useEffect } from "@odoo/owl";
export class CompositorCanvas extends Component {
setup() {
this.canvasRef = useRef("canvas");
this.compositor = this.env.services.compositor;
onMounted(() => this._attach());
onWillUnmount(() => this._detach());
// Re-attach if the surface prop changes
useEffect(
() => {
this._detach();
this._attach();
},
() => [this.props.surface]
);
}
_attach() {
const surface = this.props.surface;
if (surface && this.canvasRef.el) {
surface.attachTo(this.canvasRef.el);
}
}
_detach() {
const surface = this.props.surface;
if (surface) {
surface.detach();
}
}
}
CompositorCanvas.template = "one_os_compositor.CompositorCanvas";
CompositorCanvas.props = {
surface: { type: Object, optional: true },
className: { type: String, optional: true },
style: { type: String, optional: true },
};
export default CompositorCanvas;
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="one_os_compositor.CompositorCanvas">
<div class="o_compositor_canvas_wrapper" t-att-class="props.className" t-att-style="props.style">
<canvas t-ref="canvas" class="o_compositor_canvas" tabindex="1"/>
</div>
</t>
</templates>
+30
View File
@@ -0,0 +1,30 @@
// 1B Space Compositor styles
// ============================
.o_compositor_canvas_wrapper {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
.o_compositor_canvas {
display: block;
width: 100%;
height: 100%;
background: #000;
outline: none;
&:focus {
outline: 2px solid #6f42c1;
}
}
}
// Compositor menu icon
.o_compositor_menu_icon {
&:before {
content: "\f108";
font-family: "FontAwesome";
margin-right: 8px;
}
}
+372
View File
@@ -0,0 +1,372 @@
/**
* 1B Space Compositor Service
* ===========================
*
* The single integration point between Odoo and the Wayland compositor.
*
* Architecture
* ------------
* The browser-side compositor (custom TypeScript library, to be built
* clean-room per the MIT analysis) connects to the Python compositor proxy
* via WebSocket + KCP-over-WebSocket. This service wraps that connection
* so other Odoo addons can use it without knowing about Wayland.
*
* Lifecycle
* ---------
* 1. ``init()`` — called when the service is first used. Fetches a JWT
* from the Odoo backend via ``rpc("/web/compositor/token")``.
* 2. ``connect()`` — opens a WebSocket to the proxy URL returned with the JWT.
* 3. ``launchApp(appId)`` — calls ``rpc("/web/compositor/launch")`` which
* tells Odoo to tell the proxy to spawn a sandboxed app.
* 4. The proxy returns a ``signal_url`` which the browser opens as a
* separate WebSocket for control messages.
* 5. ``attachSurface(surfaceId, canvasEl)`` — binds a Wayland surface to
* an HTML5 canvas element for rendering.
*
* Status: STUB
* ------------
* This is the public API stub. The actual Wayland wire protocol,
* WebGL2 rendering, etc. is implemented in the ``compositor_lib`` folder
* (to be built clean-room).
*/
import { useService } from "@web/core/utils/hooks";
export class CompositorService {
constructor() {
this._jwt = null;
this._proxyUrl = null;
this._compositorSessionId = null;
this._sessionDbId = null;
this._jwtExpiresAt = null;
this._connected = false;
this._controlSocket = null;
this._surfaces = new Map();
this._eventListeners = new Map();
this._refreshTimer = null;
this._rpc = null; // Set on init
}
// ──────────────────────────────────────────────────────────────────
// Lifecycle
// ──────────────────────────────────────────────────────────────────
/**
* Initialize the service. Called automatically by OWL when first used.
*
* @param {Object} env — OWL environment (provides services)
* @param {Object} services — { rpc }
*/
start(env, services) {
this._env = env;
this._rpc = services.rpc;
// Auto-connect on first use
return this._ensureToken();
}
/**
* Ensure we have a valid JWT. Refreshes if expired.
* @private
*/
async _ensureToken() {
if (this._jwt && this._jwtExpiresAt && Date.now() < this._jwtExpiresAt.getTime() - 60000) {
return; // Still valid (with 1-min safety margin)
}
const result = await this._rpc("/web/compositor/token");
this._jwt = result.jwt;
this._proxyUrl = result.proxy_url;
this._compositorSessionId = result.compositor_session_id;
this._sessionDbId = result.session_db_id;
this._jwtExpiresAt = new Date(result.expires_at);
// Schedule refresh 1 minute before expiry
if (this._refreshTimer) clearTimeout(this._refreshTimer);
const refreshIn = this._jwtExpiresAt.getTime() - Date.now() - 60000;
this._refreshTimer = setTimeout(() => this._ensureToken(), Math.max(refreshIn, 5000));
}
// ──────────────────────────────────────────────────────────────────
// Public API
// ──────────────────────────────────────────────────────────────────
/**
* List apps the current user is allowed to launch.
* @returns {Promise<Array<{app_id, name, description, icon, color, running_session_count}>>}
*/
async listApps() {
const result = await this._rpc("/web/compositor/apps");
return result.apps;
}
/**
* Launch an app.
*
* Tells Odoo backend → tells Python proxy → spawns sandboxed app.
* Returns a SurfaceHandle that can be attached to a canvas.
*
* @param {string} appId — e.g. "gnome-calculator"
* @returns {Promise<SurfaceHandle>}
*/
async launchApp(appId) {
await this._ensureToken();
const result = await this._rpc("/web/compositor/launch", { app_id: appId });
if (result.stub) {
// Proxy not yet connected — return a stub surface for dev
return this._createStubSurface(result.compositor_surface_id, appId);
}
// Open the signal WebSocket
await this._openControlSocket(result.signal_url);
return this._createSurface(result.compositor_surface_id, appId, result.app_instance_db_id);
}
/**
* Terminate an app.
*
* @param {SurfaceHandle} surface — the surface returned by launchApp
* @param {boolean} force — if True, send SIGKILL instead of SIGTERM
*/
async terminateApp(surface, force = false) {
if (!surface || !surface.appInstanceDbId) return;
await this._rpc("/web/compositor/terminate", {
app_instance_db_id: surface.appInstanceDbId,
force,
});
this._surfaces.delete(surface.surfaceId);
this._emit("surfaceDestroyed", surface);
}
/**
* Subscribe to compositor events.
*
* @param {string} eventName — one of: surfaceCreated, surfaceDestroyed,
* surfaceTitleUpdated, surfaceActivationUpdated, surfaceStateChanged,
* clientCreated, clientDestroyed, clientUnresponsiveUpdated
* @param {Function} callback
* @returns {Function} unsubscribe function
*/
on(eventName, callback) {
if (!this._eventListeners.has(eventName)) {
this._eventListeners.set(eventName, new Set());
}
this._eventListeners.get(eventName).add(callback);
return () => this._eventListeners.get(eventName).delete(callback);
}
/**
* Get a list of currently active surfaces.
* @returns {Array<SurfaceHandle>}
*/
getActiveSurfaces() {
return Array.from(this._surfaces.values());
}
/**
* Focus a surface (bring to front).
* @param {SurfaceHandle} surface
*/
async focusSurface(surface) {
if (!surface) return;
// TODO: send wl_surface.activate via the control socket
// For now, just emit a local event
this._emit("surfaceActivationUpdated", { surface, active: true });
}
// ──────────────────────────────────────────────────────────────────
// Internal: WebSocket control
// ──────────────────────────────────────────────────────────────────
async _openControlSocket(signalUrl) {
if (this._controlSocket && this._controlSocket.readyState === WebSocket.OPEN) {
return;
}
// The signal URL includes a `key` query param for auth. We also
// pass the JWT as a Sec-WebSocket-Protocol subprotocol.
const ws = new WebSocket(signalUrl, ["compositor", `bearer.${this._jwt}`]);
ws.binaryType = "arraybuffer";
ws.onopen = () => {
this._connected = true;
this._emit("connected", {});
};
ws.onclose = (ev) => {
this._connected = false;
this._emit("disconnected", { code: ev.code, reason: ev.reason });
// Auto-reconnect with exponential backoff (3s, 6s, 12s, 24s, 30s cap)
if (!this._reconnectTimer) {
this._reconnectAttempts = 0;
this._scheduleReconnect(signalUrl);
}
};
ws.onmessage = (ev) => this._handleControlMessage(ev.data);
ws.onerror = (err) => {
console.error("[one_os_compositor] control socket error:", err);
};
this._controlSocket = ws;
}
_scheduleReconnect(signalUrl) {
const delays = [3000, 6000, 12000, 24000, 30000];
const delay = delays[Math.min(this._reconnectAttempts, delays.length - 1)];
this._reconnectAttempts++;
this._reconnectTimer = setTimeout(async () => {
this._reconnectTimer = null;
try {
await this._ensureToken();
await this._openControlSocket(signalUrl);
this._reconnectAttempts = 0;
} catch (err) {
console.error("[one_os_compositor] reconnect failed:", err);
this._scheduleReconnect(signalUrl);
}
}, delay);
}
_handleControlMessage(data) {
// Control messages are JSON; surface frames are binary on a separate channel.
try {
const msg = JSON.parse(typeof data === "string" ? data : new TextDecoder().decode(data));
switch (msg.type) {
case "CONNECT_CHANNEL":
// Proxy is asking us to open a new data channel WebSocket
this._openDataChannel(msg.url, msg.desc);
break;
case "APP_TERMINATED":
this._handleAppTerminated(msg);
break;
case "PING":
// Heartbeat — respond with PONG
if (this._controlSocket.readyState === WebSocket.OPEN) {
this._controlSocket.send(JSON.stringify({ type: "PONG" }));
}
break;
default:
console.debug("[one_os_compositor] unhandled control message:", msg);
}
} catch (e) {
console.error("[one_os_compositor] failed to parse control message:", e);
}
}
_openDataChannel(url, desc) {
// TODO: open the per-surface data WebSocket for encoded frame streaming
// The actual KCP-over-WebSocket layer is implemented in compositor_lib/
console.debug("[one_os_compositor] opening data channel:", url, desc);
}
_handleAppTerminated(msg) {
const surface = this._surfaces.get(msg.compositor_surface_id);
if (surface) {
this._surfaces.delete(msg.compositor_surface_id);
this._emit("surfaceDestroyed", surface);
}
}
// ──────────────────────────────────────────────────────────────────
// Internal: surface management
// ──────────────────────────────────────────────────────────────────
_createSurface(surfaceId, appId, appInstanceDbId) {
const surface = {
surfaceId,
appId,
appInstanceDbId,
title: "(no title)",
appIdStr: appId,
width: 800,
height: 600,
isMaximized: false,
isFullscreen: false,
isMinimized: false,
isActive: false,
// Attach this surface to a canvas element for rendering
attachTo: (canvasEl) => this._attachSurfaceToCanvas(surface, canvasEl),
// Detach from current canvas
detach: () => this._detachSurfaceFromCanvas(surface),
// Update window state
setState: (state) => this._setSurfaceState(surface, state),
};
this._surfaces.set(surfaceId, surface);
this._emit("surfaceCreated", surface);
return surface;
}
_createStubSurface(surfaceId, appId) {
// For dev — when the proxy isn't connected yet, return a surface
// that renders a placeholder so the OWL shell can be developed.
const surface = this._createSurface(surfaceId, appId, null);
surface.stub = true;
return surface;
}
_attachSurfaceToCanvas(surface, canvasEl) {
// TODO: bind this surface to the canvas via the compositor_lib renderer
// For now, just store a reference and emit an event
surface.canvasEl = canvasEl;
if (surface.stub) {
this._renderStub(canvasEl, surface);
}
this._emit("surfaceAttached", surface);
}
_detachSurfaceFromCanvas(surface) {
if (surface.canvasEl) {
const ctx = surface.canvasEl.getContext("2d");
ctx.clearRect(0, 0, surface.canvasEl.width, surface.canvasEl.height);
surface.canvasEl = null;
}
this._emit("surfaceDetached", surface);
}
_renderStub(canvasEl, surface) {
// Render a placeholder so the OWL shell can develop without the proxy
const ctx = canvasEl.getContext("2d");
canvasEl.width = surface.width;
canvasEl.height = surface.height;
ctx.fillStyle = "#1a1a2e";
ctx.fillRect(0, 0, canvasEl.width, canvasEl.height);
ctx.fillStyle = "#e94560";
ctx.font = "bold 24px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(`${surface.appId}`, canvasEl.width / 2, canvasEl.height / 2 - 20);
ctx.fillStyle = "#a0a0a0";
ctx.font = "14px monospace";
ctx.fillText("(stub — install one_os_compositor_proxy to launch real app)", canvasEl.width / 2, canvasEl.height / 2 + 20);
ctx.fillText(`surface id: ${surface.surfaceId}`, canvasEl.width / 2, canvasEl.height / 2 + 50);
}
_setSurfaceState(surface, state) {
Object.assign(surface, state);
this._emit("surfaceStateChanged", surface);
}
// ──────────────────────────────────────────────────────────────────
// Internal: event emitter
// ──────────────────────────────────────────────────────────────────
_emit(eventName, payload) {
const listeners = this._eventListeners.get(eventName);
if (listeners) {
listeners.forEach(cb => {
try {
cb(payload);
} catch (e) {
console.error(`[one_os_compositor] ${eventName} listener error:`, e);
}
});
}
}
}
/**
* @typedef {Object} SurfaceHandle
* @property {string} surfaceId
* @property {string} appId
* @property {number|null} appInstanceDbId
* @property {string} title
* @property {string} appIdStr
* @property {number} width
* @property {number} height
* @property {boolean} isMaximized
* @property {boolean} isFullscreen
* @property {boolean} isMinimized
* @property {boolean} isActive
* @property {boolean} stub — true if the proxy isn't connected yet
* @property {HTMLCanvasElement|null} canvasEl
* @property {Function} attachTo
* @property {Function} detach
* @property {Function} setState
*/
@@ -0,0 +1,39 @@
/**
* 1B Space Compositor — OWL service registry
* ============================================
*
* This file registers the CompositorService as an Odoo OWL service.
* Other addons can use it via:
*
* class MyComponent extends Component {
* setup() {
* this.compositor = useService("compositor");
* }
* async launchApp(appId) {
* const surface = await this.compositor.launchApp(appId);
* surface.attachTo(this.canvasRef.el);
* }
* }
*
* The service handles:
* - JWT auth (issued by Odoo backend, refreshed automatically)
* - WebSocket connection to the Python compositor proxy
* - App launch / terminate / focus
* - Surface lifecycle events (created, destroyed, title-updated, etc.)
*
* License: Proprietary (1B Space internal use)
* Author: 1bspace.com
*/
import { registry } from "@web/core/registry";
import { CompositorService } from "./compositor_service";
// Register the service so it can be used via useService("compositor")
registry.category("services").add("compositor", new CompositorService());
// Also expose on window for debugging in dev mode
if (typeof window !== "undefined" && window.location.search.includes("debug")) {
window.__oneOSCompositor = { CompositorService };
}
export { CompositorService };