mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 08:22:20 +02:00
Introduce company-scoped computer attachments, bounded runner and viewer ownership, persistent files and worktrees, Boat ingress, and native and legacy runtime integration behind the experimental Boat flag. Keep desktop UI and extended acceptance cases in the stacked feature branch. Co-Authored-By: Paperclip <noreply@paperclip.ing>
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
import { unprocessable } from "../errors.js";
|
|
|
|
export async function assertEnvironmentSelectionForCompany(
|
|
environmentsSvc: {
|
|
getById(environmentId: string): Promise<{
|
|
id: string;
|
|
driver: string;
|
|
status?: string | null;
|
|
config: Record<string, unknown> | null;
|
|
metadata?: Record<string, unknown> | null;
|
|
} | null>;
|
|
},
|
|
companyId: string,
|
|
environmentId: string | null | undefined,
|
|
options?: {
|
|
allowedDrivers?: string[];
|
|
allowedSandboxProviders?: string[];
|
|
},
|
|
) {
|
|
if (environmentId === undefined || environmentId === null) return;
|
|
const environment = await environmentsSvc.getById(environmentId);
|
|
if (!environment) {
|
|
throw unprocessable("Environment not found.");
|
|
}
|
|
if (environment.driver === "computer" && environment.metadata?.computerCompanyId !== companyId) {
|
|
throw unprocessable("Computer environment is not available in this company.");
|
|
}
|
|
if (environment.status === "archived") {
|
|
throw unprocessable("Environment is archived.");
|
|
}
|
|
if (options?.allowedDrivers && !options.allowedDrivers.includes(environment.driver)) {
|
|
throw unprocessable(
|
|
`Environment driver "${environment.driver}" is not allowed here. Allowed drivers: ${options.allowedDrivers.join(", ")}`,
|
|
);
|
|
}
|
|
if (environment.driver === "sandbox") {
|
|
const config = environment.config && typeof environment.config === "object"
|
|
? environment.config as Record<string, unknown>
|
|
: {};
|
|
const provider = typeof config.provider === "string" ? config.provider : "";
|
|
if (provider === "fake") {
|
|
throw unprocessable(
|
|
`Environment sandbox provider "${provider}" is not allowed here. The built-in fake provider is probe-only and cannot execute runs.`,
|
|
);
|
|
}
|
|
if (
|
|
options?.allowedSandboxProviders
|
|
&& options.allowedSandboxProviders.length > 0
|
|
&& !options.allowedSandboxProviders.includes(provider)
|
|
) {
|
|
throw unprocessable(
|
|
`Environment sandbox provider "${provider || "unknown"}" is not allowed here. Allowed providers: ${options.allowedSandboxProviders.join(", ")}`,
|
|
);
|
|
}
|
|
}
|
|
}
|