mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Replace the plaintext pairing exchange with a nonce and HMAC proof plus AES-256-GCM encrypted credentials, bumping links to v2. Track session ownership per linked server so activity, session picker, transcript, MCP and skills views work against remote servers. Share encrypted secret access, event routing and URL helpers across backend, shared and CLI.
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { trimUrlTrailingSlashes } from '@opencode-manager/shared/utils'
|
|
import type { OcmState } from './state.js'
|
|
|
|
export const REMOTE_MANAGER_URL_ENV = 'OCM_REMOTE_MANAGER_URL'
|
|
export const REMOTE_REPO_NAME_ENV = 'OCM_REMOTE_REPO_NAME'
|
|
export const REMOTE_REPO_ID_ENV = 'OCM_REMOTE_REPO_ID'
|
|
|
|
export type RemoteContext = {
|
|
managerUrl: string
|
|
managerHost: string
|
|
repoName?: string
|
|
repoId?: number
|
|
}
|
|
|
|
export function buildRemoteAttachEnv(managerUrl: string, repoName: string, repoId: number): Record<string, string> {
|
|
return {
|
|
[REMOTE_MANAGER_URL_ENV]: managerUrl,
|
|
[REMOTE_REPO_NAME_ENV]: repoName,
|
|
[REMOTE_REPO_ID_ENV]: String(repoId),
|
|
}
|
|
}
|
|
|
|
export function readRemoteContext(env: NodeJS.ProcessEnv): RemoteContext | undefined {
|
|
const urlValue = env[REMOTE_MANAGER_URL_ENV]
|
|
if (!urlValue) return undefined
|
|
|
|
const managerUrl = urlValue.trim()
|
|
|
|
let managerHost: string
|
|
try {
|
|
managerHost = new URL(managerUrl).host
|
|
} catch {
|
|
managerHost = managerUrl
|
|
}
|
|
|
|
const repoName = env[REMOTE_REPO_NAME_ENV] || undefined
|
|
|
|
const repoIdValue = Number(env[REMOTE_REPO_ID_ENV])
|
|
const repoId = Number.isInteger(repoIdValue) && repoIdValue > 0 ? repoIdValue : undefined
|
|
|
|
return { managerUrl, managerHost, repoName, repoId }
|
|
}
|
|
|
|
/** Returns the saved manager name when it belongs to the attached manager, else the manager host. */
|
|
export function remoteDisplayName(remote: RemoteContext, state: OcmState | null): string {
|
|
if (state?.managerName && trimUrlTrailingSlashes(state.managerUrl) === trimUrlTrailingSlashes(remote.managerUrl)) return state.managerName
|
|
return remote.managerHost
|
|
}
|