fix(aidocs, config): migrate aidocs configuration handling from npmextra to smartconfig

This commit is contained in:
2026-03-24 15:07:49 +00:00
parent fc85f28f69
commit a3a0537ddc
9 changed files with 53 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ import * as aiDocsClasses from './aidocs_classes/index.js';
export class AiDoc {
private openaiToken: string;
public npmextraKV: plugins.npmextra.KeyValueStore;
public smartconfigKV: plugins.npmextra.KeyValueStore;
public qenvInstance: plugins.qenv.Qenv;
public aidocInteract: plugins.smartinteract.SmartInteract;
public model: plugins.smartai.LanguageModelV3;
@@ -38,8 +38,8 @@ export class AiDoc {
if (!(await this.qenvInstance.getEnvVarOnDemand('OPENAI_TOKEN'))) {
// Migrate old KV store path to new path if needed
const homeDir = plugins.smartpath.get.home();
const oldKvPath = plugins.path.join(homeDir, '.npmextra/kv/tsdoc.json');
const newKvDir = plugins.path.join(homeDir, '.npmextra/kv/@git.zone');
const oldKvPath = plugins.path.join(homeDir, '.smartconfig/kv/tsdoc.json');
const newKvDir = plugins.path.join(homeDir, '.smartconfig/kv/@git.zone');
const newKvPath = plugins.path.join(newKvDir, 'tsdoc.json');
if (
await plugins.fsInstance.file(oldKvPath).exists() &&
@@ -52,13 +52,13 @@ export class AiDoc {
console.log('Migration complete: tsdoc.json -> @git.zone/tsdoc.json');
}
this.npmextraKV = new plugins.npmextra.KeyValueStore({
this.smartconfigKV = new plugins.npmextra.KeyValueStore({
typeArg: 'userHomeDir',
identityArg: '@git.zone/tsdoc',
mandatoryKeys: ['OPENAI_TOKEN'],
});
const missingKeys = await this.npmextraKV.getMissingMandatoryKeys();
const missingKeys = await this.smartconfigKV.getMissingMandatoryKeys();
if (missingKeys.length > 0) {
// lets try argv
if (this.argvArg?.OPENAI_TOKEN) {
@@ -77,11 +77,11 @@ export class AiDoc {
}
this.printSanitizedToken();
await this.npmextraKV.writeKey('OPENAI_TOKEN', this.openaiToken);
await this.smartconfigKV.writeKey('OPENAI_TOKEN', this.openaiToken);
}
}
if (!this.openaiToken && this.npmextraKV) {
this.openaiToken = await this.npmextraKV.readKey('OPENAI_TOKEN');
if (!this.openaiToken && this.smartconfigKV) {
this.openaiToken = await this.smartconfigKV.readKey('OPENAI_TOKEN');
}
// Create model using getModel()