wishforge-ide/apps/ide/policy/frontend.cjs
eust-w b47a07e8d2 chore: baseline snapshot of the Codex-delivered code before review
Imports the previously untracked working tree as-is so that the review
changes that follow (requirements -> design -> implementation) can be
reviewed as diffs and reverted if needed. No content changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:18:04 +08:00

47 lines
2.7 KiB
JavaScript

const { ContainerModule, injectable } = require('@theia/core/shared/inversify');
const { CollaborationFrontendContribution } = require('@theia/collaboration/lib/browser/collaboration-frontend-contribution');
const { CollaborationWorkspaceService } = require('@theia/collaboration/lib/browser/collaboration-workspace-service');
const { FrontendApplicationConfigProvider } = require('@theia/core/lib/browser/frontend-application-config-provider');
const { ConnectionProvider, SocketIoTransport } = require('open-collaboration-protocol');
const { io } = require('socket.io-client');
const { collaborationBase, createPrefixConnectionProvider } = require('../collaboration/client-factory.cjs');
Object.defineProperty(exports, '__esModule', { value: true });
// Register room commands only for this workspace's authenticated gateway route.
// An absent/mismatched URL keeps collaboration disabled with no public fallback.
class ScopedCollaborationContribution extends CollaborationFrontendContribution {
async scopedUrl() {
const url = await this.getCollaborationServerUrl();
return collaborationBase(url, window.location.href).href;
}
init() { this.scopedUrl().then(() => this.setStatusBarEntryDefault()).catch(() => {}); }
registerCommands(commands) {
this.scopedUrl().then(() => super.registerCommands(commands)).catch(() => {});
}
async createConnectionProvider() {
const url = await this.scopedUrl();
return createPrefixConnectionProvider({ ConnectionProvider, SocketIoTransport, io }, {
url, browserLocation: window.location.href,
client: FrontendApplicationConfigProvider.get().applicationName,
fetch: window.fetch.bind(window),
authenticationHandler: (token, metadata) => this.handleAuth(url, token, metadata),
// OCT tokens are instance-local; never reuse a different workspace token
// from the upstream global localStorage key.
userToken: undefined,
});
}
}
injectable()(ScopedCollaborationContribution);
// Every backend already belongs to one provisioned project. A guest's virtual
// collaboration URI must not overwrite the backend-wide default for other tabs.
class DedicatedWorkspaceService extends CollaborationWorkspaceService {
isRemoteSession() { return true; }
}
injectable()(DedicatedWorkspaceService);
module.exports.default = new ContainerModule((_bind, _unbind, _isBound, rebind) => {
require('./plugin-install-frontend.cjs').bindManagedExtensionNotice(_bind);
require('./coordination-frontend.cjs').bindCoordination(_bind);
rebind(CollaborationWorkspaceService).to(DedicatedWorkspaceService).inSingletonScope();
rebind(CollaborationFrontendContribution).to(ScopedCollaborationContribution).inSingletonScope();
});