@yeaft/webchat-agent 0.1.246 → 0.1.247
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/connection/message-router.js +4 -1
- package/conversation.js +50 -1
- package/crew/session.js +9 -0
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
createConversation, resumeConversation, deleteConversation,
|
|
13
13
|
handleRefreshConversation, handleCancelExecution,
|
|
14
14
|
handleUserInput, handleUpdateConversationSettings, handleAskUserAnswer,
|
|
15
|
-
sendConversationList, handleBtwQuestion
|
|
15
|
+
sendConversationList, handleBtwQuestion, preloadSlashCommands
|
|
16
16
|
} from '../conversation.js';
|
|
17
17
|
import {
|
|
18
18
|
createCrewSession, handleCrewHumanInput, handleCrewControl,
|
|
@@ -65,6 +65,9 @@ export async function handleMessage(msg) {
|
|
|
65
65
|
if (ctx.mcpServers.length > 0) {
|
|
66
66
|
sendToServer({ type: 'mcp_servers_list', servers: ctx.mcpServers });
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
// ★ Preload slash commands for immediate skill availability in new sessions
|
|
70
|
+
preloadSlashCommands().catch(() => {});
|
|
68
71
|
break;
|
|
69
72
|
|
|
70
73
|
case 'create_conversation':
|
package/conversation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ctx from './context.js';
|
|
2
|
-
import { query } from './sdk/index.js';
|
|
2
|
+
import { query, Stream } from './sdk/index.js';
|
|
3
3
|
import { loadSessionHistory } from './history.js';
|
|
4
4
|
import { startClaudeQuery } from './claude.js';
|
|
5
5
|
import { crewSessions, loadCrewIndex } from './crew.js';
|
|
@@ -21,6 +21,55 @@ function prestartClaude(conversationId, workDir, resumeSessionId) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Preload slash commands from Claude CLI (fire-and-forget).
|
|
26
|
+
* Spawns a minimal CLI process to capture the system init message,
|
|
27
|
+
* then aborts immediately (no API tokens consumed — init is local).
|
|
28
|
+
*
|
|
29
|
+
* @param {string} [workDir] - Project directory (default: agent workDir)
|
|
30
|
+
* @param {string} [targetId] - conversationId to key the update to
|
|
31
|
+
* ('__preload__' for agent-level, or crewSessionId)
|
|
32
|
+
*/
|
|
33
|
+
export async function preloadSlashCommands(workDir, targetId = '__preload__') {
|
|
34
|
+
const effectiveWorkDir = workDir || ctx.CONFIG.workDir;
|
|
35
|
+
try {
|
|
36
|
+
const abortController = new AbortController();
|
|
37
|
+
const inputStream = new Stream();
|
|
38
|
+
const claudeQuery = query({
|
|
39
|
+
prompt: inputStream,
|
|
40
|
+
options: {
|
|
41
|
+
cwd: effectiveWorkDir,
|
|
42
|
+
permissionMode: 'bypassPermissions',
|
|
43
|
+
abort: abortController.signal,
|
|
44
|
+
maxTurns: 1
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
for await (const message of claudeQuery) {
|
|
48
|
+
if (message.type === 'system' && message.subtype === 'init') {
|
|
49
|
+
const slashCommands = message.slash_commands || [];
|
|
50
|
+
if (slashCommands.length > 0) {
|
|
51
|
+
// Update agent-level cache if this is the first load
|
|
52
|
+
if (ctx.slashCommands.length === 0) {
|
|
53
|
+
ctx.slashCommands = [...slashCommands];
|
|
54
|
+
}
|
|
55
|
+
ctx.sendToServer({
|
|
56
|
+
type: 'slash_commands_update',
|
|
57
|
+
conversationId: targetId,
|
|
58
|
+
slashCommands
|
|
59
|
+
});
|
|
60
|
+
console.log(`[Preload] ${targetId}: loaded ${slashCommands.length} slash commands from ${effectiveWorkDir}`);
|
|
61
|
+
}
|
|
62
|
+
abortController.abort();
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} catch (err) {
|
|
67
|
+
if (err.name !== 'AbortError') {
|
|
68
|
+
console.warn(`[Preload] Failed for ${targetId}: ${err.message}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
24
73
|
/**
|
|
25
74
|
* 解析斜杠命令
|
|
26
75
|
* @param {string} message - 用户消息
|
package/crew/session.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
loadSessionMeta, saveSessionMeta, loadSessionMessages, getMaxShardIndex
|
|
13
13
|
} from './persistence.js';
|
|
14
14
|
import { sendCrewMessage, sendCrewOutput, sendStatusUpdate } from './ui-messages.js';
|
|
15
|
+
import { preloadSlashCommands } from '../conversation.js';
|
|
15
16
|
|
|
16
17
|
// =====================================================================
|
|
17
18
|
// Data Structures
|
|
@@ -295,6 +296,9 @@ export async function createCrewSession(msg) {
|
|
|
295
296
|
});
|
|
296
297
|
}
|
|
297
298
|
|
|
299
|
+
// ★ Preload project-level skills for crew session input autocomplete
|
|
300
|
+
preloadSlashCommands(projectDir, sessionId).catch(() => {});
|
|
301
|
+
|
|
298
302
|
return session;
|
|
299
303
|
}
|
|
300
304
|
|
|
@@ -463,6 +467,8 @@ export async function resumeCrewSession(msg) {
|
|
|
463
467
|
hasOlderMessages
|
|
464
468
|
});
|
|
465
469
|
sendStatusUpdate(session);
|
|
470
|
+
// ★ Preload project-level skills for crew session input autocomplete
|
|
471
|
+
preloadSlashCommands(session.projectDir, sessionId).catch(() => {});
|
|
466
472
|
return;
|
|
467
473
|
}
|
|
468
474
|
|
|
@@ -540,6 +546,9 @@ export async function resumeCrewSession(msg) {
|
|
|
540
546
|
await upsertCrewIndex(session);
|
|
541
547
|
await saveSessionMeta(session);
|
|
542
548
|
|
|
549
|
+
// ★ Preload project-level skills for crew session input autocomplete
|
|
550
|
+
preloadSlashCommands(session.projectDir, sessionId).catch(() => {});
|
|
551
|
+
|
|
543
552
|
console.log(`[Crew] Session ${sessionId} resumed, waiting for human input`);
|
|
544
553
|
}
|
|
545
554
|
|