-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
32 lines (29 loc) · 1.02 KB
/
Copy pathindex.ts
File metadata and controls
32 lines (29 loc) · 1.02 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
import { resolveApiKey } from "./src/auth.js";
import { CommandCodeLanguageModel } from "./src/model.js";
export interface CommandCodeProviderOptions {
name?: string;
apiKey?: string;
baseURL?: string;
headers?: Record<string, string>;
authPaths?: string[];
}
export function createCommandCode(options: CommandCodeProviderOptions = {}) {
const apiKey = resolveApiKey({ apiKey: options.apiKey, authPaths: options.authPaths });
if (!apiKey) {
throw new Error(
"Command Code API key not found. Set COMMANDCODE_API_KEY env var, create ~/.commandcode/auth.json, or pass apiKey option.",
);
}
return {
languageModel(modelId: string): CommandCodeLanguageModel {
return new CommandCodeLanguageModel(modelId, {
apiKey,
baseURL: typeof options.baseURL === "string" ? options.baseURL : undefined,
headers:
typeof options.headers === "object" && options.headers !== null
? (options.headers as Record<string, string>)
: undefined,
});
},
};
}