@brainpilot/backend-core 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ export interface KbBuildOptions {
2
+ /** Per-run override of the KnowledgeBase root. Falls through to env / default. */
3
+ kbRoot?: string;
4
+ /** SiliconFlow API key for OCR; forwarded as --ocr-api-key. */
5
+ ocrApiKey?: string;
6
+ /** Per-PDF concurrency; forwarded as --ocr-concurrency. */
7
+ ocrConcurrency?: number;
8
+ /** Cap on number of PDFs (smoke testing). */
9
+ ocrLimit?: number;
10
+ /** Metadata-extraction LLM credentials (OpenAI-compatible). */
11
+ metaApiKey?: string;
12
+ metaBaseUrl?: string;
13
+ metaModel?: string;
14
+ /** Stages to skip; mutually exclusive with `only`. */
15
+ skip?: Array<"ocr" | "extract" | "chunk" | "vectorize">;
16
+ /** Stages to run (overrides skip). */
17
+ only?: Array<"ocr" | "extract" | "chunk" | "vectorize">;
18
+ /** HuggingFace mirror URL for auto model download (e.g. https://hf-mirror.com). */
19
+ hfMirror?: string;
20
+ }
21
+ export interface KbBuildEvent {
22
+ ts: string;
23
+ stage: string;
24
+ event: string;
25
+ msg: string;
26
+ [key: string]: unknown;
27
+ }
28
+ export type Listener = (ev: KbBuildEvent) => void;
29
+ export interface StartResult {
30
+ ok: boolean;
31
+ message?: string;
32
+ startedAt?: number;
33
+ }
34
+ /**
35
+ * Bootstrap the KnowledgeBase Python venv via ``scripts/setup_env.py``.
36
+ *
37
+ * Owns SLOTS.envSetup. Can run concurrently with startKbModelSetup (they
38
+ * don't touch the same files); guarded against a second env-setup only.
39
+ * Build refuses to start while env-setup is running via its own check
40
+ * inside startKbBuild.
41
+ *
42
+ * The setup script is **pure stdlib Python**, so we deliberately do NOT
43
+ * resolve via the venv (which doesn't exist yet). Priority for the
44
+ * bootstrap interpreter:
45
+ * 1. ``opts.python`` — explicit override from the UI
46
+ * 2. ``BP_KB_PYTHON`` — env var (probably wrong here, but honour it)
47
+ * 3. ``python3`` / ``python`` on PATH
48
+ */
49
+ export declare function startKbEnvSetup(opts?: {
50
+ python?: string;
51
+ reinstall?: boolean;
52
+ kbRoot?: string;
53
+ }): StartResult;
54
+ /**
55
+ * Download the bge-m3 + bge-reranker-v2-m3 weights (~2.5 GB) via
56
+ * ``scripts/setup_models.py``. Runs in its own SLOTS.modelSetup slot so it
57
+ * can execute concurrently with setup_env — the two don't touch the same
58
+ * files. Reuses the venv's Python if present (needed for huggingface_hub);
59
+ * falls back to system Python otherwise (which will fail loudly if the
60
+ * package isn't there, letting the operator know to run env setup first).
61
+ */
62
+ export declare function startKbModelSetup(opts?: {
63
+ hfMirror?: string;
64
+ kbRoot?: string;
65
+ }): StartResult;
66
+ /**
67
+ * One-click orchestration: start venv setup, then chain model download when
68
+ * (and only when) the venv build exits 0. huggingface_hub lives inside the
69
+ * venv, so kicking off model download before it exists would fail — the
70
+ * chaining is required, not just a nice-to-have.
71
+ *
72
+ * Emits a synthetic ``setup-full`` info event so the frontend can display a
73
+ * single "combined setup" banner and know when the whole thing is done.
74
+ */
75
+ export declare function startKbFullSetup(opts?: {
76
+ python?: string;
77
+ reinstall?: boolean;
78
+ hfMirror?: string;
79
+ kbRoot?: string;
80
+ }): StartResult;
81
+ export declare function startKbBuild(opts?: KbBuildOptions): StartResult;
82
+ export interface KbBuildStatus {
83
+ active: boolean;
84
+ startedAt: number | null;
85
+ finishedAt: number | null;
86
+ exitCode: number | null | undefined;
87
+ error?: string;
88
+ recentEvents: KbBuildEvent[];
89
+ /** Diagnostic info the UI shows in the panel BEFORE a build starts. */
90
+ environment: KbEnvironment;
91
+ }
92
+ export interface KbEnvironment {
93
+ /** Absolute path to the python the build will use. */
94
+ python: string;
95
+ /** True if the chosen python is the bundled venv (recommended). */
96
+ pythonIsVenv: boolean;
97
+ /** Did setup_env.sh ever finish? */
98
+ venvExists: boolean;
99
+ /** Path to the bundled venv even if it doesn't exist yet (for the UI hint). */
100
+ expectedVenvPath: string;
101
+ /** True iff the four pipeline scripts + the orchestrator are all present. */
102
+ scriptsPresent: boolean;
103
+ /** Resolved KnowledgeBase root the backend will use by default. */
104
+ kbRoot: string;
105
+ }
106
+ export declare function findKbRoot(): string;
107
+ export declare function getKbBuildStatus(): KbBuildStatus;
108
+ export interface SubscribeHandle {
109
+ unsubscribe: () => void;
110
+ /** Replay of buffered events for late subscribers. */
111
+ history: KbBuildEvent[];
112
+ /** Resolves when every active slot finishes (or immediately if none is running). */
113
+ done: Promise<void>;
114
+ }
115
+ export declare function subscribeKbBuild(listener: Listener): SubscribeHandle;
116
+ export declare function cancelKbBuild(): {
117
+ ok: boolean;
118
+ message?: string;
119
+ };
120
+ //# sourceMappingURL=kb-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kb-builder.d.ts","sourceRoot":"","sources":["../src/kb-builder.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,cAAc;IAC7B,kFAAkF;IAClF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC,CAAC;IACxD,sCAAsC;IACtC,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC,CAAC;IACxD,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,C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