@yeaft/webchat-agent 1.0.28 → 1.0.30
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/cli.js +9 -9
- package/index.js +1 -1
- package/llm-config-cli.js +48 -0
- package/package.json +1 -1
- package/service/index.js +19 -1
package/cli.js
CHANGED
|
@@ -41,7 +41,7 @@ const subArgs = args.slice(1);
|
|
|
41
41
|
const SERVICE_COMMANDS = ['install', 'uninstall', 'start', 'stop', 'restart', 'status', 'logs'];
|
|
42
42
|
|
|
43
43
|
if (command === 'doctor') {
|
|
44
|
-
handleDoctorCommand();
|
|
44
|
+
await handleDoctorCommand();
|
|
45
45
|
} else if (command === 'llm') {
|
|
46
46
|
await handleLlmCommand(subArgs);
|
|
47
47
|
} else if (command === 'upgrade') {
|
|
@@ -51,7 +51,7 @@ if (command === 'doctor') {
|
|
|
51
51
|
} else if (command === '--help' || command === '-h') {
|
|
52
52
|
printHelp();
|
|
53
53
|
} else if (SERVICE_COMMANDS.includes(command)) {
|
|
54
|
-
handleServiceCommand(command, subArgs);
|
|
54
|
+
await handleServiceCommand(command, subArgs);
|
|
55
55
|
} else {
|
|
56
56
|
// Normal agent startup — parse flags and set env vars
|
|
57
57
|
parseAndStart(args);
|
|
@@ -385,13 +385,13 @@ function parseLlmArgs(args) {
|
|
|
385
385
|
async function handleServiceCommand(command, args) {
|
|
386
386
|
const service = await import('./service.js');
|
|
387
387
|
switch (command) {
|
|
388
|
-
case 'install': service.install(args); break;
|
|
389
|
-
case 'uninstall': service.uninstall(args); break;
|
|
390
|
-
case 'start': service.start(args); break;
|
|
391
|
-
case 'stop': service.stop(args); break;
|
|
392
|
-
case 'restart': service.restart(args); break;
|
|
393
|
-
case 'status': service.status(args); break;
|
|
394
|
-
case 'logs': service.logs(args); break;
|
|
388
|
+
case 'install': await service.install(args); break;
|
|
389
|
+
case 'uninstall': await service.uninstall(args); break;
|
|
390
|
+
case 'start': await service.start(args); break;
|
|
391
|
+
case 'stop': await service.stop(args); break;
|
|
392
|
+
case 'restart': await service.restart(args); break;
|
|
393
|
+
case 'status': await service.status(args); break;
|
|
394
|
+
case 'logs': await service.logs(args); break;
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { assertNodeVersion } from './check-node-version.js';
|
|
|
2
2
|
assertNodeVersion({ component: '@yeaft/webchat-agent' });
|
|
3
3
|
|
|
4
4
|
import 'dotenv/config';
|
|
5
|
-
import { platform } from 'os';
|
|
5
|
+
import { platform, homedir } from 'os';
|
|
6
6
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, cpSync, chmodSync, readdirSync } from 'fs';
|
|
7
7
|
import { join, dirname } from 'path';
|
|
8
8
|
import { exec } from 'child_process';
|
package/llm-config-cli.js
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
modelIdsFromProviderModels,
|
|
9
9
|
} from './llm-model-discovery.js';
|
|
10
10
|
|
|
11
|
+
export const DEFAULT_GITHUB_COPILOT_MODEL = 'gpt-5.5';
|
|
12
|
+
|
|
11
13
|
const VALID_PROTOCOLS = new Set(['anthropic', 'openai-responses']);
|
|
12
14
|
const VALID_CREDENTIAL_PROVIDERS = new Set(['github-copilot']);
|
|
13
15
|
|
|
@@ -230,6 +232,52 @@ export async function useGitHubCopilot(config, options = {}) {
|
|
|
230
232
|
return { config: next, provider, discovery };
|
|
231
233
|
}
|
|
232
234
|
|
|
235
|
+
export function hasLocalLlmConfig(config = {}) {
|
|
236
|
+
const providers = Array.isArray(config.providers) ? config.providers.filter(Boolean) : [];
|
|
237
|
+
return providers.length > 0 || Boolean(config.primaryModel) || Boolean(config.fastModel);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function isDefaultSeedLlmConfig(config = {}) {
|
|
241
|
+
const providers = Array.isArray(config.providers) ? config.providers.filter(Boolean) : [];
|
|
242
|
+
if (providers.length !== 1) return false;
|
|
243
|
+
const provider = providers[0];
|
|
244
|
+
return provider?.name === 'my-proxy'
|
|
245
|
+
&& provider?.baseUrl === 'http://localhost:6628/v1'
|
|
246
|
+
&& provider?.apiKey === 'proxy'
|
|
247
|
+
&& typeof config.primaryModel === 'string'
|
|
248
|
+
&& config.primaryModel.startsWith('my-proxy/');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export async function tryAutoConfigureGitHubCopilot(configPath = getDefaultYeaftConfigPath(), options = {}) {
|
|
252
|
+
let current;
|
|
253
|
+
try {
|
|
254
|
+
current = readLocalLlmConfig(configPath);
|
|
255
|
+
} catch (error) {
|
|
256
|
+
return { configured: false, reason: 'invalid-config', error, config: null };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const allowConfigured = Boolean(options.allowConfigured) || isDefaultSeedLlmConfig(current);
|
|
260
|
+
if (!allowConfigured && hasLocalLlmConfig(current)) {
|
|
261
|
+
return { configured: false, reason: 'already-configured', config: current };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
const result = await useGitHubCopilot(current, {
|
|
266
|
+
...options,
|
|
267
|
+
model: options.model || DEFAULT_GITHUB_COPILOT_MODEL,
|
|
268
|
+
});
|
|
269
|
+
writeLocalLlmConfig(result.config, configPath);
|
|
270
|
+
return { configured: true, reason: 'configured', ...result };
|
|
271
|
+
} catch (error) {
|
|
272
|
+
return {
|
|
273
|
+
configured: false,
|
|
274
|
+
reason: error?.code === 'COPILOT_CREDENTIAL_MISSING' ? 'credential-missing' : 'unavailable',
|
|
275
|
+
error,
|
|
276
|
+
config: current,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
233
281
|
|
|
234
282
|
export async function useOpenAICompatible(config, options = {}, env = process.env) {
|
|
235
283
|
const name = options.name ? String(options.name).trim() : 'openai';
|
package/package.json
CHANGED
package/service/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Routes install/uninstall/start/stop/restart/status/logs to the correct platform module.
|
|
4
4
|
*/
|
|
5
5
|
import { existsSync } from 'fs';
|
|
6
|
+
import { join } from 'path';
|
|
6
7
|
import { platform } from 'os';
|
|
7
8
|
import {
|
|
8
9
|
getConfigDir, getLogDir, getConfigPath,
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
parseServiceArgs, validateConfig, getInstanceIdFromArgs, getDefaultYeaftDir
|
|
11
12
|
} from './config.js';
|
|
12
13
|
import { initYeaftDir } from '../yeaft/init.js';
|
|
14
|
+
import { DEFAULT_GITHUB_COPILOT_MODEL, tryAutoConfigureGitHubCopilot } from '../llm-config-cli.js';
|
|
13
15
|
import { getSystemdServicePath, linuxInstall, linuxUninstall, linuxStart, linuxStop, linuxRestart, linuxStatus, linuxLogs } from './linux.js';
|
|
14
16
|
import { getLaunchdPlistPath, macInstall, macUninstall, macStart, macStop, macRestart, macStatus, macLogs } from './macos.js';
|
|
15
17
|
import { winInstall, winUninstall, winStart, winStop, winRestart, winStatus, winLogs } from './windows.js';
|
|
@@ -35,6 +37,19 @@ export {
|
|
|
35
37
|
|
|
36
38
|
const os = platform();
|
|
37
39
|
|
|
40
|
+
export async function autoConfigureGitHubCopilotIfAvailable(yeaftDir, options = {}) {
|
|
41
|
+
const result = await tryAutoConfigureGitHubCopilot(join(yeaftDir, 'config.json'), options);
|
|
42
|
+
if (result.configured) {
|
|
43
|
+
console.log(`Configured GitHub Copilot provider automatically with ${DEFAULT_GITHUB_COPILOT_MODEL}.`);
|
|
44
|
+
if (result.discovery?.warning) console.log(`Warning: ${result.discovery.warning}`);
|
|
45
|
+
} else if (result.reason === 'already-configured') {
|
|
46
|
+
console.log('LLM config already exists; skipped automatic GitHub Copilot setup.');
|
|
47
|
+
} else if (result.reason === 'invalid-config') {
|
|
48
|
+
console.log('Existing LLM config is invalid; skipped automatic GitHub Copilot setup.');
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
function ensureInstalled(instanceId) {
|
|
39
54
|
if (os === 'linux') {
|
|
40
55
|
if (!existsSync(getSystemdServicePath(instanceId))) {
|
|
@@ -50,7 +65,7 @@ function ensureInstalled(instanceId) {
|
|
|
50
65
|
// Windows check is done inside individual functions
|
|
51
66
|
}
|
|
52
67
|
|
|
53
|
-
export function install(args) {
|
|
68
|
+
export async function install(args) {
|
|
54
69
|
const config = parseServiceArgs(args);
|
|
55
70
|
validateConfig(config);
|
|
56
71
|
saveServiceConfig(config);
|
|
@@ -59,6 +74,9 @@ export function install(args) {
|
|
|
59
74
|
// so `yeaft` CLI is ready to use immediately after install
|
|
60
75
|
const effectiveYeaftDir = config.yeaftDir || getDefaultYeaftDir(config.instanceId);
|
|
61
76
|
const { dir, created } = initYeaftDir(effectiveYeaftDir);
|
|
77
|
+
await autoConfigureGitHubCopilotIfAvailable(dir, {
|
|
78
|
+
allowConfigured: created.includes(join(dir, 'config.json')),
|
|
79
|
+
});
|
|
62
80
|
if (created.length > 0) {
|
|
63
81
|
console.log(`Initialized ${dir}`);
|
|
64
82
|
console.log(` Edit ${dir}/config.json to configure LLM providers.`);
|