refactor: remove legacy workspace runtime branches
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { validateWorkspaceDescriptor } from "./schema.js";
|
||||
import type { DwhTransport, VectorTransport, WorkspaceDescriptor } from "./schema.js";
|
||||
import type { DeprecatedV2Descriptor } from "./deprecated-v2-descriptor.js";
|
||||
import type { DwhTransport, WorkspaceDescriptor } from "./schema.js";
|
||||
|
||||
export type InstallationRole = "DWH" | "VECTOR" | "VECTOR_WRITER" | "EMBEDDING" | "EVIDENCE";
|
||||
export type InstallationRole = "DWH" | "EVIDENCE";
|
||||
export type InstallationSuffix =
|
||||
| "TRANSPORT"
|
||||
| "HOST"
|
||||
@@ -24,7 +23,7 @@ export type InstallationSuffix =
|
||||
| "SECRET_KEY_FILE"
|
||||
| "SESSION_TOKEN_FILE";
|
||||
|
||||
type ConnectorTransport = DwhTransport | VectorTransport;
|
||||
type ConnectorTransport = DwhTransport;
|
||||
|
||||
export interface InstallationVariable {
|
||||
name: string;
|
||||
@@ -67,12 +66,6 @@ const SSH_SUFFIXES: readonly InstallationSuffix[] = [
|
||||
"SSH_TARGET_PORT",
|
||||
];
|
||||
|
||||
const EMBEDDING_SUFFIXES: readonly InstallationSuffix[] = [
|
||||
"BASE_URL",
|
||||
"API_KEY_FILE",
|
||||
"TLS_CA_FILE",
|
||||
];
|
||||
|
||||
function namespaceFor(workspace: WorkspaceDescriptor): string {
|
||||
return workspace.workspace.id.replaceAll("-", "_").toUpperCase();
|
||||
}
|
||||
@@ -94,11 +87,10 @@ function createVariable(
|
||||
|
||||
function connectorVariables(
|
||||
namespace: string,
|
||||
role: "DWH" | "VECTOR",
|
||||
transports: readonly ConnectorTransport[],
|
||||
transports: readonly DwhTransport[],
|
||||
): InstallationVariable[] {
|
||||
const suffixTransports = new Map<InstallationSuffix, ConnectorTransport[]>();
|
||||
const add = (suffixes: readonly InstallationSuffix[], transport: ConnectorTransport) => {
|
||||
const suffixTransports = new Map<InstallationSuffix, DwhTransport[]>();
|
||||
const add = (suffixes: readonly InstallationSuffix[], transport: DwhTransport) => {
|
||||
for (const suffix of suffixes) {
|
||||
const applicable = suffixTransports.get(suffix) ?? [];
|
||||
applicable.push(transport);
|
||||
@@ -107,7 +99,7 @@ function connectorVariables(
|
||||
};
|
||||
|
||||
for (const transport of transports) {
|
||||
if (transport === "postgres_direct" || transport === "pgvector_direct") {
|
||||
if (transport === "postgres_direct") {
|
||||
add(DIRECT_SUFFIXES, transport);
|
||||
} else if (transport === "rest_api") {
|
||||
add(REST_SUFFIXES, transport);
|
||||
@@ -117,9 +109,9 @@ function connectorVariables(
|
||||
}
|
||||
|
||||
return [
|
||||
createVariable(namespace, role, "TRANSPORT", transports),
|
||||
createVariable(namespace, "DWH", "TRANSPORT", transports),
|
||||
...[...suffixTransports.entries()].map(([suffix, applicable]) => (
|
||||
createVariable(namespace, role, suffix, applicable)
|
||||
createVariable(namespace, "DWH", suffix, applicable)
|
||||
)),
|
||||
];
|
||||
}
|
||||
@@ -143,30 +135,27 @@ function evidenceVariables(
|
||||
return [];
|
||||
}
|
||||
|
||||
function requireSupportedDescriptor(workspace: unknown): void {
|
||||
if (typeof workspace !== "object" || workspace === null) {
|
||||
throw new Error("Installation contract supports only workspace schema version 3");
|
||||
}
|
||||
const metadata = Reflect.get(workspace, "workspace");
|
||||
if (typeof metadata !== "object" || metadata === null
|
||||
|| Reflect.get(metadata, "schema_version") !== 3) {
|
||||
throw new Error("Installation contract supports only workspace schema version 3");
|
||||
}
|
||||
}
|
||||
|
||||
export function buildInstallationContract(workspace: WorkspaceDescriptor): InstallationContract {
|
||||
requireSupportedDescriptor(workspace);
|
||||
const descriptor = validateWorkspaceDescriptor(workspace);
|
||||
const namespace = namespaceFor(descriptor);
|
||||
const schemaVersion = Number(descriptor.workspace.schema_version);
|
||||
const legacy = descriptor as unknown as DeprecatedV2Descriptor;
|
||||
|
||||
return {
|
||||
workspaceId: descriptor.workspace.id,
|
||||
namespace,
|
||||
variables: [
|
||||
...connectorVariables(namespace, "DWH", descriptor.dwh.supported_transports),
|
||||
...(schemaVersion === 2
|
||||
? connectorVariables(
|
||||
namespace,
|
||||
"VECTOR",
|
||||
legacy.semantic_index.vector_store.supported_transports,
|
||||
)
|
||||
: []),
|
||||
...(schemaVersion === 2 && legacy.semantic_index.vector_writer
|
||||
? [createVariable(namespace, "VECTOR_WRITER", "API_KEY_FILE")]
|
||||
: []),
|
||||
...(schemaVersion === 2
|
||||
? EMBEDDING_SUFFIXES.map((suffix) => createVariable(namespace, "EMBEDDING", suffix))
|
||||
: []),
|
||||
...connectorVariables(namespace, descriptor.dwh.supported_transports),
|
||||
...evidenceVariables(namespace, descriptor),
|
||||
],
|
||||
};
|
||||
@@ -276,10 +265,10 @@ export function renderWorkspaceDocs(workspace: WorkspaceDescriptor): { envExampl
|
||||
"",
|
||||
"Use the following UI fields as installation bindings. Secret fields always contain file paths, never secret values.",
|
||||
"",
|
||||
...(["DWH", "VECTOR", "VECTOR_WRITER", "EMBEDDING", "EVIDENCE"] as const)
|
||||
...(["DWH", "EVIDENCE"] as const)
|
||||
.filter((role) => variablesByRole.has(role))
|
||||
.flatMap((role) => [
|
||||
`## ${role === "DWH" ? "Data warehouse" : role === "VECTOR" ? "Vector store" : role === "VECTOR_WRITER" ? "Vector writer" : role === "EMBEDDING" ? "Embedding service" : "Evidence"}`,
|
||||
`## ${role === "DWH" ? "Data warehouse" : "Evidence"}`,
|
||||
"",
|
||||
...(variablesByRole.get(role) ?? []).map((variable) => (
|
||||
`- \`${variable.name}\`${variable.transports ? ` (for: ${variable.transports.join(", ")})` : ""}`
|
||||
|
||||
Reference in New Issue
Block a user