@ganziliang/kb-model-setup 0.1.0
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/dist/index.d.ts +24 -0
- package/dist/index.js +44 -0
- package/package.json +25 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type ApiProtocol = "openai-responses" | "anthropic-messages";
|
|
2
|
+
export type ModelConfig = {
|
|
3
|
+
provider: string;
|
|
4
|
+
api: ApiProtocol;
|
|
5
|
+
model: string;
|
|
6
|
+
baseURL: string;
|
|
7
|
+
apiKey: string;
|
|
8
|
+
};
|
|
9
|
+
export type ModelConfigStore = {
|
|
10
|
+
load(): Promise<ModelConfig[]>;
|
|
11
|
+
save(models: ModelConfig[]): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
export type SetupPrompter = {
|
|
14
|
+
ask(question: string, initial?: string): Promise<string>;
|
|
15
|
+
select(question: string, choices: string[], initial?: number): Promise<number>;
|
|
16
|
+
confirm(question: string): Promise<boolean>;
|
|
17
|
+
notice(message: string): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
export type ModelSetupExtension = {
|
|
20
|
+
configure(prompter: SetupPrompter, existing?: ModelConfig): Promise<ModelConfig>;
|
|
21
|
+
validate(config: ModelConfig): string[];
|
|
22
|
+
};
|
|
23
|
+
export declare function createModelSetupExtension(): ModelSetupExtension;
|
|
24
|
+
export declare function configFromEnvironment(env?: NodeJS.ProcessEnv): ModelConfig | undefined;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const protocols = ["openai-responses", "anthropic-messages"];
|
|
2
|
+
export function createModelSetupExtension() {
|
|
3
|
+
return {
|
|
4
|
+
async configure(prompter, existing) {
|
|
5
|
+
const provider = await prompter.ask("Provider", existing?.provider ?? "");
|
|
6
|
+
const apiIndex = await prompter.select("API protocol", protocols, Math.max(0, protocols.indexOf(existing?.api ?? protocols[0])));
|
|
7
|
+
const model = await prompter.ask("Model", existing?.model ?? "");
|
|
8
|
+
const baseURL = await prompter.ask("Base URL", existing?.baseURL ?? "");
|
|
9
|
+
const apiKey = await prompter.ask("API key", existing?.apiKey ?? "");
|
|
10
|
+
const config = { provider, api: protocols[apiIndex], model, baseURL, apiKey };
|
|
11
|
+
const errors = this.validate(config);
|
|
12
|
+
if (errors.length) {
|
|
13
|
+
await prompter.notice(errors.join("\n"));
|
|
14
|
+
return this.configure(prompter, config);
|
|
15
|
+
}
|
|
16
|
+
return config;
|
|
17
|
+
},
|
|
18
|
+
validate(config) {
|
|
19
|
+
const errors = [];
|
|
20
|
+
if (!config.provider.trim())
|
|
21
|
+
errors.push("Provider is required.");
|
|
22
|
+
if (!protocols.includes(config.api))
|
|
23
|
+
errors.push("API protocol is invalid.");
|
|
24
|
+
if (!config.model.trim())
|
|
25
|
+
errors.push("Model is required.");
|
|
26
|
+
if (!config.baseURL.trim())
|
|
27
|
+
errors.push("Base URL is required.");
|
|
28
|
+
if (!config.apiKey.trim())
|
|
29
|
+
errors.push("API key is required.");
|
|
30
|
+
return errors;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function configFromEnvironment(env = process.env) {
|
|
35
|
+
const provider = env.KB_PROVIDER;
|
|
36
|
+
const api = env.KB_API;
|
|
37
|
+
const model = env.KB_MODEL;
|
|
38
|
+
const baseURL = env.KB_BASE_URL;
|
|
39
|
+
const apiKey = env.KB_API_KEY;
|
|
40
|
+
if (!provider || !api || !model || !baseURL || !apiKey)
|
|
41
|
+
return undefined;
|
|
42
|
+
const config = { provider, api, model, baseURL, apiKey };
|
|
43
|
+
return createModelSetupExtension().validate(config).length ? undefined : config;
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ganziliang/kb-model-setup",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Interactive model configuration for the kb local knowledge base agent",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
18
|
+
"test": "npm run build && node --test"
|
|
19
|
+
},
|
|
20
|
+
"engines": { "node": ">=22.5.0" },
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.10.0",
|
|
23
|
+
"typescript": "^5.7.2"
|
|
24
|
+
}
|
|
25
|
+
}
|