Spaces:
Running
Running
File size: 2,912 Bytes
ac68ae4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | import * as p from "@clack/prompts";
import pc from "picocolors";
import { isPromptBack, pickOne, type PromptBack } from "../lib/prompts.js";
import type { DbChoices, ServicesRuntime } from "../types.js";
function nonRedisPicked(dbs: DbChoices): string[] {
const picked: string[] = [];
if (
dbs.vectorDb === "postgresql" ||
dbs.dataDb === "postgresql" ||
dbs.graphDb === "networkx"
) {
picked.push("PostgreSQL");
}
if (dbs.graphDb === "neo4j") picked.push("Neo4j");
if (dbs.vectorDb === "milvus") picked.push("Milvus");
if (dbs.dataDb === "mongo") picked.push("MongoDB");
return picked;
}
export async function askServicesRuntime(
dbs: DbChoices,
opts?: {
allowBack?: false;
initialValue?: ServicesRuntime;
prechosen?: ServicesRuntime;
},
): Promise<ServicesRuntime>;
export async function askServicesRuntime(
dbs: DbChoices,
opts: {
allowBack: true;
backHint?: string;
initialValue?: ServicesRuntime;
prechosen?: ServicesRuntime;
},
): Promise<ServicesRuntime | PromptBack>;
export async function askServicesRuntime(
dbs: DbChoices,
opts?: {
allowBack?: boolean;
backHint?: string;
initialValue?: ServicesRuntime;
prechosen?: ServicesRuntime;
},
): Promise<ServicesRuntime | PromptBack> {
if (opts?.prechosen) {
return opts.prechosen;
}
const sidecars = ["Redis", ...nonRedisPicked(dbs)];
p.note(
[
`BrainAPI needs these backing services for your setup:`,
` ${pc.cyan(sidecars.join(", "))}`,
``,
`You can let BrainAPI manage them via Docker, or run them yourself.`,
].join("\n"),
"Backing services",
);
const picked = opts?.allowBack
? await pickOne<ServicesRuntime>({
message: "How do you want to run them?",
options: [
{
value: "docker",
label: "Docker Compose (recommended)",
hint: "isolated, reproducible, one extra dependency",
},
{
value: "manual",
label: "Manual — I'll install/run them myself",
hint: "no Docker dependency; the TUI just probes for reachability",
},
],
initialValue: opts.initialValue ?? "docker",
allowBack: true,
backHint: opts.backHint,
})
: await pickOne<ServicesRuntime>({
message: "How do you want to run them?",
options: [
{
value: "docker",
label: "Docker Compose (recommended)",
hint: "isolated, reproducible, one extra dependency",
},
{
value: "manual",
label: "Manual — I'll install/run them myself",
hint: "no Docker dependency; the TUI just probes for reachability",
},
],
initialValue: opts?.initialValue ?? "docker",
});
if (isPromptBack(picked)) {
return picked;
}
return picked;
}
|