@yeaft/webchat-agent 1.0.269 → 1.0.271
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 +16 -9
- package/index.js +6 -5
- package/local-run.js +4 -7
- package/local-runtime/server/session-catalog.js +11 -2
- package/local-runtime/version.json +1 -1
- package/local-runtime/web/app.bundle.js +51 -43
- package/local-runtime/web/app.bundle.js.gz +0 -0
- package/local-runtime/web/index.html +2 -2
- package/local-runtime/web/style.bundle.css +1 -1
- package/local-runtime/web/style.bundle.css.gz +0 -0
- package/package.json +1 -1
- package/service/config.js +71 -30
- package/service/doctor.js +11 -10
- package/service/index.js +11 -7
- package/service.js +4 -0
|
Binary file
|
package/package.json
CHANGED
package/service/config.js
CHANGED
|
@@ -3,13 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
|
|
5
5
|
import { join, dirname } from 'path';
|
|
6
|
-
import { platform, homedir } from 'os';
|
|
6
|
+
import { platform, homedir, hostname } from 'os';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
|
|
9
9
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
10
|
export const SERVICE_NAME = 'yeaft-agent';
|
|
11
11
|
export const DEFAULT_INSTANCE_ID = 'default';
|
|
12
12
|
|
|
13
|
+
export function getDefaultAgentName(machineName = hostname()) {
|
|
14
|
+
const raw = String(machineName || '');
|
|
15
|
+
if (!raw) return DEFAULT_INSTANCE_ID;
|
|
16
|
+
return raw.replace(/[^A-Za-z0-9._-]/gu, '-');
|
|
17
|
+
}
|
|
18
|
+
|
|
13
19
|
/**
|
|
14
20
|
* Load .env file from agent directory (or cwd) into process.env
|
|
15
21
|
* Only sets vars that are not already set (won't override existing env)
|
|
@@ -58,45 +64,73 @@ export function validateInstanceId(instanceId) {
|
|
|
58
64
|
return normalized;
|
|
59
65
|
}
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
let
|
|
63
|
-
let
|
|
67
|
+
function readIdentityArgs(args = []) {
|
|
68
|
+
let deprecatedInstanceId = null;
|
|
69
|
+
let explicitName = null;
|
|
64
70
|
for (let i = 0; i < args.length; i++) {
|
|
65
71
|
const arg = args[i];
|
|
66
72
|
const next = args[i + 1];
|
|
67
|
-
if (arg
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
} else if (arg === '--name' && next) {
|
|
71
|
-
agentName = next;
|
|
72
|
-
i++;
|
|
73
|
+
if (arg !== '--instance' && arg !== '--name') continue;
|
|
74
|
+
if (!next || next.startsWith('-')) {
|
|
75
|
+
throw new Error(`${arg} requires a value`);
|
|
73
76
|
}
|
|
77
|
+
if (arg === '--name') {
|
|
78
|
+
explicitName = validateInstanceId(next);
|
|
79
|
+
} else {
|
|
80
|
+
deprecatedInstanceId = validateInstanceId(next);
|
|
81
|
+
}
|
|
82
|
+
i++;
|
|
74
83
|
}
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
return { deprecatedInstanceId, explicitName };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function resolveDisplayName(args = [], env = process.env, fallbackName = getDefaultAgentName()) {
|
|
88
|
+
const { explicitName } = readIdentityArgs(args);
|
|
89
|
+
return explicitName
|
|
79
90
|
|| env.AGENT_NAME
|
|
80
|
-
||
|
|
81
|
-
|
|
91
|
+
|| fallbackName
|
|
92
|
+
|| getDefaultAgentName();
|
|
82
93
|
}
|
|
83
94
|
|
|
84
|
-
export function
|
|
85
|
-
|
|
95
|
+
export function resolveRuntimeIdentity(fileConfig = {}, env = process.env) {
|
|
96
|
+
const agentName = resolveDisplayName([], env, fileConfig.agentName || getDefaultAgentName());
|
|
97
|
+
const instanceId = validateInstanceId(env.YEAFT_AGENT_INSTANCE || fileConfig.instanceId || DEFAULT_INSTANCE_ID);
|
|
98
|
+
return { agentName, instanceId };
|
|
99
|
+
}
|
|
86
100
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
export function resolveServiceInstanceId(args = [], env = process.env, options = {}) {
|
|
102
|
+
const { deprecatedInstanceId, explicitName } = readIdentityArgs(args);
|
|
103
|
+
if (explicitName) return explicitName;
|
|
104
|
+
if (deprecatedInstanceId) return deprecatedInstanceId;
|
|
105
|
+
if (env.YEAFT_AGENT_INSTANCE) return validateInstanceId(env.YEAFT_AGENT_INSTANCE);
|
|
106
|
+
if (options.management) return DEFAULT_INSTANCE_ID;
|
|
107
|
+
if (env.AGENT_NAME) return validateInstanceId(env.AGENT_NAME);
|
|
108
|
+
return validateInstanceId(options.fallbackName || getDefaultAgentName());
|
|
109
|
+
}
|
|
93
110
|
|
|
94
|
-
|
|
111
|
+
/** Legacy alias for resolveServiceInstanceId(). */
|
|
112
|
+
export function getInstanceIdFromArgs(args = [], env = process.env, options = {}) {
|
|
113
|
+
return resolveServiceInstanceId(args, env, options);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function applyAgentIdentityToEnv(args = [], env = process.env) {
|
|
117
|
+
const { deprecatedInstanceId, explicitName } = readIdentityArgs(args);
|
|
118
|
+
if (explicitName) {
|
|
119
|
+
env.YEAFT_AGENT_INSTANCE = explicitName;
|
|
120
|
+
env.AGENT_NAME = explicitName;
|
|
121
|
+
} else if (deprecatedInstanceId) {
|
|
122
|
+
env.YEAFT_AGENT_INSTANCE = deprecatedInstanceId;
|
|
123
|
+
} else if (!env.YEAFT_AGENT_INSTANCE && env.AGENT_NAME) {
|
|
124
|
+
env.YEAFT_AGENT_INSTANCE = validateInstanceId(env.AGENT_NAME);
|
|
125
|
+
} else if (env.YEAFT_AGENT_INSTANCE) {
|
|
126
|
+
env.YEAFT_AGENT_INSTANCE = validateInstanceId(env.YEAFT_AGENT_INSTANCE);
|
|
127
|
+
}
|
|
128
|
+
return env.YEAFT_AGENT_INSTANCE || null;
|
|
95
129
|
}
|
|
96
130
|
|
|
97
131
|
export function warnDeprecatedInstanceArg(args = [], warn = console.warn) {
|
|
98
132
|
if (args.includes('--instance')) {
|
|
99
|
-
warn('Warning: --instance is deprecated; use --name instead.
|
|
133
|
+
warn('Warning: --instance is deprecated; use --name instead. --name takes precedence when both are provided.');
|
|
100
134
|
}
|
|
101
135
|
}
|
|
102
136
|
|
|
@@ -184,12 +218,20 @@ export function parseServiceArgs(args) {
|
|
|
184
218
|
// Load .env if available (for dev / source-based usage)
|
|
185
219
|
loadDotenv();
|
|
186
220
|
|
|
187
|
-
const instanceId =
|
|
221
|
+
const instanceId = resolveServiceInstanceId(args, process.env, { management: true });
|
|
188
222
|
const existing = loadServiceConfig(instanceId) || {};
|
|
223
|
+
const explicitIdentity = args.includes('--name') || args.includes('--instance');
|
|
224
|
+
const fallbackName = explicitIdentity
|
|
225
|
+
? instanceId
|
|
226
|
+
: existing.agentName || getDefaultAgentName();
|
|
189
227
|
const config = {
|
|
190
228
|
instanceId,
|
|
191
229
|
serverUrl: existing.serverUrl || '',
|
|
192
|
-
agentName:
|
|
230
|
+
agentName: resolveDisplayName(
|
|
231
|
+
args,
|
|
232
|
+
explicitIdentity ? { ...process.env, AGENT_NAME: '' } : process.env,
|
|
233
|
+
fallbackName,
|
|
234
|
+
),
|
|
193
235
|
agentSecret: existing.agentSecret || '',
|
|
194
236
|
workDir: existing.workDir || '',
|
|
195
237
|
yeaftDir: existing.yeaftDir || '',
|
|
@@ -197,7 +239,6 @@ export function parseServiceArgs(args) {
|
|
|
197
239
|
|
|
198
240
|
// Environment variables override saved config
|
|
199
241
|
if (process.env.SERVER_URL) config.serverUrl = process.env.SERVER_URL;
|
|
200
|
-
if (process.env.AGENT_NAME) config.agentName = process.env.AGENT_NAME;
|
|
201
242
|
if (process.env.AGENT_SECRET) config.agentSecret = process.env.AGENT_SECRET;
|
|
202
243
|
if (process.env.WORK_DIR) config.workDir = process.env.WORK_DIR;
|
|
203
244
|
if (process.env.YEAFT_DIR) config.yeaftDir = process.env.YEAFT_DIR;
|
|
@@ -209,7 +250,7 @@ export function parseServiceArgs(args) {
|
|
|
209
250
|
switch (arg) {
|
|
210
251
|
case '--instance': if (next) { i++; } break;
|
|
211
252
|
case '--server': if (next) { config.serverUrl = next; i++; } break;
|
|
212
|
-
case '--name': if (next) {
|
|
253
|
+
case '--name': if (next) { i++; } break;
|
|
213
254
|
case '--secret': if (next) { config.agentSecret = next; i++; } break;
|
|
214
255
|
case '--work-dir': if (next) { config.workDir = next; i++; } break;
|
|
215
256
|
case '--yeaft-dir': if (next) { config.yeaftDir = next; i++; } break;
|
package/service/doctor.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { execSync } from 'child_process';
|
|
8
8
|
import { existsSync, readFileSync, statSync } from 'fs';
|
|
9
9
|
import { platform, homedir } from 'os';
|
|
10
|
-
import { getNodePath } from './config.js';
|
|
10
|
+
import { getNodePath, resolveServiceInstanceId } from './config.js';
|
|
11
11
|
import { getLaunchdPlistPath, getMacServiceStatus } from './macos.js';
|
|
12
12
|
import { getSystemdServicePath, getLinuxServiceStatus } from './linux.js';
|
|
13
13
|
import { getEcosystemPath, getWinServiceStatus } from './windows.js';
|
|
@@ -112,8 +112,9 @@ function tildeify(filePath) {
|
|
|
112
112
|
|
|
113
113
|
// ── Main doctor logic ──────────────────────────────────────────────────────
|
|
114
114
|
|
|
115
|
-
export function doctor() {
|
|
115
|
+
export function doctor(args = []) {
|
|
116
116
|
const os = platform();
|
|
117
|
+
const instanceId = resolveServiceInstanceId(args, process.env, { management: true });
|
|
117
118
|
let configPath = null;
|
|
118
119
|
let parsePaths = null;
|
|
119
120
|
let getServiceStatus = null;
|
|
@@ -122,17 +123,17 @@ export function doctor() {
|
|
|
122
123
|
|
|
123
124
|
// 1. Determine platform and config path
|
|
124
125
|
if (os === 'darwin') {
|
|
125
|
-
configPath = getLaunchdPlistPath();
|
|
126
|
+
configPath = getLaunchdPlistPath(instanceId);
|
|
126
127
|
parsePaths = parseMacPaths;
|
|
127
|
-
getServiceStatus = getMacServiceStatus;
|
|
128
|
+
getServiceStatus = () => getMacServiceStatus(instanceId);
|
|
128
129
|
} else if (os === 'linux') {
|
|
129
|
-
configPath = getSystemdServicePath();
|
|
130
|
+
configPath = getSystemdServicePath(instanceId);
|
|
130
131
|
parsePaths = parseLinuxPaths;
|
|
131
|
-
getServiceStatus = getLinuxServiceStatus;
|
|
132
|
+
getServiceStatus = () => getLinuxServiceStatus(instanceId);
|
|
132
133
|
} else if (os === 'win32') {
|
|
133
|
-
configPath = getEcosystemPath();
|
|
134
|
+
configPath = getEcosystemPath(instanceId);
|
|
134
135
|
parsePaths = parseWindowsPaths;
|
|
135
|
-
getServiceStatus = getWinServiceStatus;
|
|
136
|
+
getServiceStatus = () => getWinServiceStatus(instanceId);
|
|
136
137
|
} else {
|
|
137
138
|
console.log(`\u26a0\ufe0f Unsupported platform: ${os}`);
|
|
138
139
|
console.log(` The doctor command supports macOS, Linux, and Windows.`);
|
|
@@ -143,7 +144,7 @@ export function doctor() {
|
|
|
143
144
|
// 2. Check if service config exists
|
|
144
145
|
if (!existsSync(configPath)) {
|
|
145
146
|
console.log(`\u26a0\ufe0f No service configuration found.`);
|
|
146
|
-
console.log(` Run 'yeaft-agent install --server <url> --
|
|
147
|
+
console.log(` Run 'yeaft-agent install --server <url> --secret <secret>' to set up.`);
|
|
147
148
|
console.log('');
|
|
148
149
|
return;
|
|
149
150
|
}
|
|
@@ -209,7 +210,7 @@ export function doctor() {
|
|
|
209
210
|
if (hasErrors) {
|
|
210
211
|
console.log('Fix: Run the following commands:');
|
|
211
212
|
console.log(' npm install -g @yeaft/webchat-agent');
|
|
212
|
-
console.log(' yeaft-agent install --server <your-server-url> --
|
|
213
|
+
console.log(' yeaft-agent install --server <your-server-url> --secret <your-secret>');
|
|
213
214
|
} else {
|
|
214
215
|
console.log('All checks passed.');
|
|
215
216
|
}
|
package/service/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { platform } from 'os';
|
|
|
8
8
|
import {
|
|
9
9
|
getConfigDir, getLogDir, getConfigPath,
|
|
10
10
|
saveServiceConfig, loadServiceConfig,
|
|
11
|
-
parseServiceArgs, validateConfig,
|
|
11
|
+
parseServiceArgs, validateConfig, resolveServiceInstanceId, getDefaultYeaftDir
|
|
12
12
|
} from './config.js';
|
|
13
13
|
import { initYeaftDir } from '../yeaft/init.js';
|
|
14
14
|
import { DEFAULT_GITHUB_COPILOT_MODEL, tryAutoConfigureGitHubCopilot } from '../llm-config-cli.js';
|
|
@@ -25,6 +25,10 @@ export {
|
|
|
25
25
|
export {
|
|
26
26
|
SERVICE_NAME,
|
|
27
27
|
DEFAULT_INSTANCE_ID,
|
|
28
|
+
getDefaultAgentName,
|
|
29
|
+
resolveDisplayName,
|
|
30
|
+
resolveRuntimeIdentity,
|
|
31
|
+
resolveServiceInstanceId,
|
|
28
32
|
normalizeInstanceId,
|
|
29
33
|
isDefaultInstance,
|
|
30
34
|
validateInstanceId,
|
|
@@ -105,7 +109,7 @@ export async function install(args) {
|
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
export function uninstall(args = []) {
|
|
108
|
-
const instanceId =
|
|
112
|
+
const instanceId = resolveServiceInstanceId(args, process.env, { management: true });
|
|
109
113
|
console.log(`Uninstalling yeaft-agent service (${instanceId})...`);
|
|
110
114
|
if (os === 'linux') linuxUninstall(instanceId);
|
|
111
115
|
else if (os === 'darwin') macUninstall(instanceId);
|
|
@@ -114,7 +118,7 @@ export function uninstall(args = []) {
|
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
export function start(args = []) {
|
|
117
|
-
const instanceId =
|
|
121
|
+
const instanceId = resolveServiceInstanceId(args, process.env, { management: true });
|
|
118
122
|
ensureInstalled(instanceId);
|
|
119
123
|
if (os === 'linux') linuxStart(instanceId);
|
|
120
124
|
else if (os === 'darwin') macStart(instanceId);
|
|
@@ -122,7 +126,7 @@ export function start(args = []) {
|
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
export function stop(args = []) {
|
|
125
|
-
const instanceId =
|
|
129
|
+
const instanceId = resolveServiceInstanceId(args, process.env, { management: true });
|
|
126
130
|
ensureInstalled(instanceId);
|
|
127
131
|
if (os === 'linux') linuxStop(instanceId);
|
|
128
132
|
else if (os === 'darwin') macStop(instanceId);
|
|
@@ -130,7 +134,7 @@ export function stop(args = []) {
|
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
export function restart(args = []) {
|
|
133
|
-
const instanceId =
|
|
137
|
+
const instanceId = resolveServiceInstanceId(args, process.env, { management: true });
|
|
134
138
|
ensureInstalled(instanceId);
|
|
135
139
|
if (os === 'linux') linuxRestart(instanceId);
|
|
136
140
|
else if (os === 'darwin') macRestart(instanceId);
|
|
@@ -138,14 +142,14 @@ export function restart(args = []) {
|
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
export function status(args = []) {
|
|
141
|
-
const instanceId =
|
|
145
|
+
const instanceId = resolveServiceInstanceId(args, process.env, { management: true });
|
|
142
146
|
if (os === 'linux') linuxStatus(instanceId);
|
|
143
147
|
else if (os === 'darwin') macStatus(instanceId);
|
|
144
148
|
else if (os === 'win32') winStatus(instanceId);
|
|
145
149
|
}
|
|
146
150
|
|
|
147
151
|
export function logs(args = []) {
|
|
148
|
-
const instanceId =
|
|
152
|
+
const instanceId = resolveServiceInstanceId(args, process.env, { management: true });
|
|
149
153
|
if (os === 'linux') linuxLogs(instanceId);
|
|
150
154
|
else if (os === 'darwin') macLogs(instanceId);
|
|
151
155
|
else if (os === 'win32') winLogs(instanceId);
|
package/service.js
CHANGED