@brainpilot/web 0.0.10 → 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.
package/src/utils/api.ts CHANGED
@@ -790,6 +790,7 @@ export const api = {
790
790
  ocrLimit?: number;
791
791
  skip?: Array<"ocr" | "extract" | "chunk" | "vectorize">;
792
792
  only?: Array<"ocr" | "extract" | "chunk" | "vectorize">;
793
+ hfMirror?: string;
793
794
  }): Promise<{ ok: boolean; startedAt?: number; error?: string }> {
794
795
  const res = await apiFetch(`${API_BASE}/kb/build`, {
795
796
  method: "POST",
@@ -853,6 +854,68 @@ export const api = {
853
854
  return handleJson(res);
854
855
  },
855
856
 
857
+ // Download bge-m3 + bge-reranker-v2-m3 model weights (~2.5 GB) via
858
+ // `scripts/setup_models.py`. Independent slot from setupEnv — the two
859
+ // can run concurrently, and setupFull() chains them.
860
+ async setupModels(opts: {
861
+ hfMirror?: string;
862
+ kbRoot?: string;
863
+ } = {}): Promise<{ ok: boolean; startedAt?: number; error?: string }> {
864
+ const res = await apiFetch(`${API_BASE}/kb/setup-models`, {
865
+ method: "POST",
866
+ headers: { "content-type": "application/json" },
867
+ body: JSON.stringify(opts),
868
+ });
869
+ if (!res.ok) {
870
+ const body = await res.json().catch(() => ({}));
871
+ return { ok: false, error: body.error || `setup-models failed (${res.status})` };
872
+ }
873
+ return handleJson(res);
874
+ },
875
+
876
+ // One-click orchestration: create venv, then download models when venv
877
+ // exits 0. Preferred entry point from the KB panel — one button, two
878
+ // progress rows in the UI.
879
+ async setupFull(opts: {
880
+ python?: string;
881
+ reinstall?: boolean;
882
+ hfMirror?: string;
883
+ kbRoot?: string;
884
+ } = {}): Promise<{ ok: boolean; startedAt?: number; error?: string }> {
885
+ const res = await apiFetch(`${API_BASE}/kb/setup-full`, {
886
+ method: "POST",
887
+ headers: { "content-type": "application/json" },
888
+ body: JSON.stringify(opts),
889
+ });
890
+ if (!res.ok) {
891
+ const body = await res.json().catch(() => ({}));
892
+ return { ok: false, error: body.error || `setup-full failed (${res.status})` };
893
+ }
894
+ return handleJson(res);
895
+ },
896
+
897
+ // Persisted KB API config (SiliconFlow OCR key today). Backend never
898
+ // returns the plaintext — only a masked preview + boolean — so the
899
+ // browser can indicate "already saved" without ever holding the secret.
900
+ async getApiConfig(): Promise<{ hasOcrApiKey: boolean; ocrApiKeyPreview: string }> {
901
+ const res = await apiFetch(`${API_BASE}/kb/api-config`);
902
+ if (!res.ok) return { hasOcrApiKey: false, ocrApiKeyPreview: "" };
903
+ return handleJson(res);
904
+ },
905
+
906
+ async saveApiConfig(patch: { ocrApiKey?: string }): Promise<{ ok: boolean; error?: string }> {
907
+ const res = await apiFetch(`${API_BASE}/kb/api-config`, {
908
+ method: "PUT",
909
+ headers: { "content-type": "application/json" },
910
+ body: JSON.stringify(patch),
911
+ });
912
+ if (!res.ok) {
913
+ const body = await res.json().catch(() => ({}));
914
+ return { ok: false, error: body.error || `save failed (${res.status})` };
915
+ }
916
+ return handleJson(res);
917
+ },
918
+
856
919
  eventsUrl(): string {
857
920
  return `${API_BASE}/kb/events`;
858
921
  },