@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
package/cli.js
CHANGED
|
@@ -48,7 +48,7 @@ const subArgs = args.slice(1);
|
|
|
48
48
|
const SERVICE_COMMANDS = ['install', 'uninstall', 'start', 'stop', 'restart', 'status', 'logs'];
|
|
49
49
|
|
|
50
50
|
if (command === 'doctor') {
|
|
51
|
-
await handleDoctorCommand();
|
|
51
|
+
await handleDoctorCommand(subArgs);
|
|
52
52
|
} else if (command === 'llm') {
|
|
53
53
|
await handleLlmCommand(subArgs);
|
|
54
54
|
} else if (command === 'local') {
|
|
@@ -78,7 +78,7 @@ function printHelp() {
|
|
|
78
78
|
|
|
79
79
|
Usage:
|
|
80
80
|
yeaft-agent [options] Run agent in foreground
|
|
81
|
-
yeaft-agent local
|
|
81
|
+
yeaft-agent local [options] Run local Web UI, server, and agent
|
|
82
82
|
yeaft-agent install [options] Install as system service
|
|
83
83
|
yeaft-agent uninstall [options] Remove system service
|
|
84
84
|
yeaft-agent start [options] Start installed service
|
|
@@ -94,7 +94,7 @@ function printHelp() {
|
|
|
94
94
|
Options:
|
|
95
95
|
--instance <id> Deprecated alias for the local service instance id
|
|
96
96
|
--server <url> WebSocket server URL (default: ws://localhost:3456)
|
|
97
|
-
--name <name> Agent name and instance id (
|
|
97
|
+
--name <name> Agent name and instance id (default: computer name; invalid chars become -)
|
|
98
98
|
--port <port> Local server port (local command only; default: 6868)
|
|
99
99
|
--secret <secret> Agent secret for authentication
|
|
100
100
|
--work-dir <dir> Default working directory (default: cwd)
|
|
@@ -104,13 +104,13 @@ function printHelp() {
|
|
|
104
104
|
Environment variables (alternative to flags):
|
|
105
105
|
YEAFT_AGENT_INSTANCE Deprecated local service instance id override
|
|
106
106
|
SERVER_URL WebSocket server URL
|
|
107
|
-
AGENT_NAME Agent name and instance id
|
|
107
|
+
AGENT_NAME Agent name and instance id override
|
|
108
108
|
AGENT_SECRET Agent secret
|
|
109
109
|
WORK_DIR Working directory
|
|
110
110
|
YEAFT_DIR Yeaft data directory
|
|
111
111
|
|
|
112
112
|
Examples:
|
|
113
|
-
yeaft-agent local
|
|
113
|
+
yeaft-agent local
|
|
114
114
|
yeaft-agent local --name my-worker --port 7000
|
|
115
115
|
yeaft-agent --server wss://your-server.com --name my-worker --secret xxx
|
|
116
116
|
yeaft-agent install --server wss://your-server.com --name my-worker --secret xxx
|
|
@@ -415,14 +415,21 @@ async function handleServiceCommand(command, args) {
|
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
|
|
418
|
-
async function handleDoctorCommand() {
|
|
418
|
+
async function handleDoctorCommand(args) {
|
|
419
|
+
warnDeprecatedInstanceArg(args);
|
|
419
420
|
const { doctor } = await import('./service.js');
|
|
420
|
-
doctor();
|
|
421
|
+
doctor(args);
|
|
421
422
|
}
|
|
422
423
|
|
|
423
424
|
function parseAndStart(args) {
|
|
424
|
-
|
|
425
|
-
|
|
425
|
+
try {
|
|
426
|
+
warnDeprecatedInstanceArg(args);
|
|
427
|
+
applyAgentIdentityToEnv(args);
|
|
428
|
+
} catch (err) {
|
|
429
|
+
console.error(`Error: ${err.message}`);
|
|
430
|
+
process.exit(1);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
426
433
|
|
|
427
434
|
// Parse non-identity flags. Saved environment remains the fallback for these options.
|
|
428
435
|
for (let i = 0; i < args.length; i++) {
|
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 {
|
|
5
|
+
import { homedir } from 'os';
|
|
6
6
|
import { createAssetOutbox } from './yeaft/asset-outbox.js';
|
|
7
7
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, cpSync, chmodSync, readdirSync } from 'fs';
|
|
8
8
|
import { join, dirname } from 'path';
|
|
@@ -10,7 +10,7 @@ import { exec } from 'child_process';
|
|
|
10
10
|
import { promisify } from 'util';
|
|
11
11
|
import { fileURLToPath } from 'url';
|
|
12
12
|
import ctx from './context.js';
|
|
13
|
-
import {
|
|
13
|
+
import { getDefaultAgentName, getDefaultYeaftDir, resolveRuntimeIdentity, getConfigPath, loadServiceConfig } from './service.js';
|
|
14
14
|
import { loadNodePty } from './terminal.js';
|
|
15
15
|
import { connect } from './connection.js';
|
|
16
16
|
import { loadMcpServers } from './mcp.js';
|
|
@@ -33,12 +33,13 @@ ctx.pkgName = pkg.name;
|
|
|
33
33
|
// 配置文件路径(向后兼容:先查当前目录 .claude-agent.json)
|
|
34
34
|
const LOCAL_CONFIG_FILE = join(process.cwd(), '.claude-agent.json');
|
|
35
35
|
const IS_LOCAL_RUN = process.env.YEAFT_LOCAL_RUN === 'true';
|
|
36
|
+
const DEFAULT_AGENT_NAME = getDefaultAgentName();
|
|
36
37
|
|
|
37
38
|
// 加载或创建配置
|
|
38
39
|
function loadConfig() {
|
|
39
40
|
const defaults = {
|
|
40
41
|
serverUrl: 'ws://localhost:3456',
|
|
41
|
-
agentName:
|
|
42
|
+
agentName: DEFAULT_AGENT_NAME,
|
|
42
43
|
workDir: process.cwd(),
|
|
43
44
|
reconnectInterval: 5000,
|
|
44
45
|
agentSecret: 'agent-shared-secret'
|
|
@@ -74,7 +75,7 @@ function saveConfig(config) {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
const fileConfig = loadConfig();
|
|
77
|
-
const INSTANCE_ID =
|
|
78
|
+
const { agentName: AGENT_NAME, instanceId: INSTANCE_ID } = resolveRuntimeIdentity(fileConfig);
|
|
78
79
|
|
|
79
80
|
// task-fix (5-bugs): the Yeaft web-bridge reads `ctx.CONFIG.yeaftDir`
|
|
80
81
|
// for every group / VP / memory operation. If unset, `path.join(undefined, …)`
|
|
@@ -95,7 +96,7 @@ try {
|
|
|
95
96
|
const CONFIG = {
|
|
96
97
|
instanceId: INSTANCE_ID,
|
|
97
98
|
serverUrl: process.env.SERVER_URL || fileConfig.serverUrl,
|
|
98
|
-
agentName:
|
|
99
|
+
agentName: AGENT_NAME,
|
|
99
100
|
workDir: process.env.WORK_DIR || fileConfig.workDir || process.cwd(),
|
|
100
101
|
yeaftDir: YEAFT_DIR,
|
|
101
102
|
reconnectInterval: fileConfig.reconnectInterval,
|
package/local-run.js
CHANGED
|
@@ -5,18 +5,18 @@ import { createServer } from 'net';
|
|
|
5
5
|
import { dirname, join } from 'path';
|
|
6
6
|
import { fileURLToPath } from 'url';
|
|
7
7
|
import { WebSocket } from 'ws';
|
|
8
|
+
import { resolveDisplayName, validateInstanceId } from './service/config.js';
|
|
8
9
|
|
|
9
10
|
const DEFAULT_PORT = 6868;
|
|
10
11
|
const LOCAL_HOST = '127.0.0.1';
|
|
11
12
|
|
|
12
|
-
export function parseLocalArgs(args) {
|
|
13
|
-
const options = { name:
|
|
13
|
+
export function parseLocalArgs(args, env = process.env) {
|
|
14
|
+
const options = { name: resolveDisplayName(args, env), port: DEFAULT_PORT };
|
|
14
15
|
for (let i = 0; i < args.length; i++) {
|
|
15
16
|
const arg = args[i];
|
|
16
17
|
const value = args[i + 1];
|
|
17
18
|
if (arg === '--name') {
|
|
18
19
|
if (!value || value.startsWith('-')) throw new Error('--name requires a value');
|
|
19
|
-
options.name = value;
|
|
20
20
|
i++;
|
|
21
21
|
} else if (arg === '--port') {
|
|
22
22
|
if (!value || value.startsWith('-')) throw new Error('--port requires a value');
|
|
@@ -28,10 +28,7 @@ export function parseLocalArgs(args) {
|
|
|
28
28
|
throw new Error(`Unknown local option: ${arg}`);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
if (!/^[A-Za-z0-9._-]+$/.test(options.name)) {
|
|
33
|
-
throw new Error('Invalid name: use only letters, numbers, dot, underscore, or hyphen');
|
|
34
|
-
}
|
|
31
|
+
validateInstanceId(options.name);
|
|
35
32
|
return options;
|
|
36
33
|
}
|
|
37
34
|
|
|
@@ -20,6 +20,15 @@ export function yeaftCatalogKey(agentId, sessionId) {
|
|
|
20
20
|
return `yeaft:${agentId}:${sessionId}`;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function timestampValue(value) {
|
|
24
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : 0;
|
|
25
|
+
if (typeof value !== 'string' || !value) return 0;
|
|
26
|
+
const numeric = Number(value);
|
|
27
|
+
if (Number.isFinite(numeric)) return numeric;
|
|
28
|
+
const parsed = Date.parse(value);
|
|
29
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
export function projectSessionCatalog({
|
|
24
33
|
chatSessions = [],
|
|
25
34
|
yeaftSessions = [],
|
|
@@ -75,8 +84,8 @@ export function projectSessionCatalog({
|
|
|
75
84
|
const leftRank = Number.isFinite(left.sortRank) ? left.sortRank : Number.MAX_SAFE_INTEGER;
|
|
76
85
|
const rightRank = Number.isFinite(right.sortRank) ? right.sortRank : Number.MAX_SAFE_INTEGER;
|
|
77
86
|
if (leftRank !== rightRank) return leftRank - rightRank;
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
87
|
+
const creationDelta = timestampValue(right.createdAt) - timestampValue(left.createdAt);
|
|
88
|
+
if (creationDelta !== 0) return creationDelta;
|
|
80
89
|
return left.catalogKey.localeCompare(right.catalogKey);
|
|
81
90
|
});
|
|
82
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
1
|
+
{"version":"1.0.271"}
|