Repository navigation
Expand file tree
/
Copy pathcontext.ts
More file actions
53 lines (46 loc) · 1.24 KB
/
Copy pathcontext.ts
File metadata and controls
53 lines (46 loc) · 1.24 KB
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
import Mixedbread from "@mixedbread/sdk";
import { getJWTToken } from "./auth.js";
import {
type FileSystem,
type FileSystemOptions,
NodeFileSystem,
} from "./file.js";
import { type Git, NodeGit } from "./git.js";
import { MixedbreadStore, type Store, TestStore } from "./store.js";
import { ensureAuthenticated, isDevelopment, isTest } from "./utils.js";
const BASE_URL = isDevelopment()
? "http://localhost:8000"
: "https://api.mixedbread.com";
/**
* Creates an authenticated Store instance
* Supports authentication via MXBAI_API_KEY env var or OAuth token
*/
export async function createStore(): Promise<Store> {
if (isTest) {
return new TestStore();
}
await ensureAuthenticated();
async function createClient() {
const jwtToken = await getJWTToken();
return new Mixedbread({
baseURL: BASE_URL,
apiKey: jwtToken,
});
}
const client = await createClient();
return new MixedbreadStore(client, createClient);
}
/**
* Creates a Git instance
*/
export function createGit(): Git {
return new NodeGit();
}
/**
* Creates a FileSystem instance
*/
export function createFileSystem(
options: FileSystemOptions = { ignorePatterns: [] },
): FileSystem {
return new NodeFileSystem(createGit(), options);
}