@code4bug/jarvis-agent 1.0.3 → 1.1.4
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/README.md +63 -0
- package/dist/agents/jarvis.md +11 -0
- package/dist/cli.js +2 -2
- package/dist/commands/index.js +2 -2
- package/dist/commands/init.js +1 -1
- package/dist/components/MessageItem.d.ts +1 -1
- package/dist/components/MessageItem.js +10 -6
- package/dist/components/SlashCommandMenu.d.ts +1 -1
- package/dist/components/StatusBar.d.ts +2 -1
- package/dist/components/StatusBar.js +6 -5
- package/dist/components/StreamingText.js +1 -1
- package/dist/components/WelcomeHeader.js +1 -1
- package/dist/config/constants.js +3 -3
- package/dist/core/AgentMessageBus.d.ts +63 -0
- package/dist/core/AgentMessageBus.js +107 -0
- package/dist/core/AgentRegistry.d.ts +22 -0
- package/dist/core/AgentRegistry.js +16 -0
- package/dist/core/QueryEngine.d.ts +7 -1
- package/dist/core/QueryEngine.js +18 -7
- package/dist/core/SubAgentBridge.d.ts +20 -0
- package/dist/core/SubAgentBridge.js +191 -0
- package/dist/core/WorkerBridge.d.ts +2 -2
- package/dist/core/WorkerBridge.js +68 -0
- package/dist/core/busAccess.d.ts +9 -0
- package/dist/core/busAccess.js +32 -0
- package/dist/core/hint.js +4 -4
- package/dist/core/query.d.ts +4 -0
- package/dist/core/query.js +91 -5
- package/dist/core/queryWorker.d.ts +62 -0
- package/dist/core/queryWorker.js +35 -0
- package/dist/core/spawnRegistry.d.ts +16 -0
- package/dist/core/spawnRegistry.js +32 -0
- package/dist/core/subAgentWorker.d.ts +89 -0
- package/dist/core/subAgentWorker.js +107 -0
- package/dist/core/workerBusProxy.d.ts +10 -0
- package/dist/core/workerBusProxy.js +57 -0
- package/dist/hooks/useSlashMenu.d.ts +7 -5
- package/dist/hooks/useSlashMenu.js +9 -5
- package/dist/hooks/useStreamThrottle.d.ts +1 -1
- package/dist/hooks/useTokenDisplay.d.ts +1 -0
- package/dist/hooks/useTokenDisplay.js +5 -0
- package/dist/index.js +1 -1
- package/dist/screens/repl.js +52 -34
- package/dist/screens/slashCommands.d.ts +1 -1
- package/dist/screens/slashCommands.js +7 -6
- package/dist/services/api/llm.d.ts +4 -2
- package/dist/services/api/llm.js +20 -6
- package/dist/services/api/mock.d.ts +1 -1
- package/dist/skills/index.d.ts +2 -2
- package/dist/skills/index.js +2 -2
- package/dist/tools/createSkill.d.ts +1 -1
- package/dist/tools/createSkill.js +3 -3
- package/dist/tools/index.d.ts +15 -9
- package/dist/tools/index.js +21 -10
- package/dist/tools/listDirectory.d.ts +1 -1
- package/dist/tools/publishMessage.d.ts +8 -0
- package/dist/tools/publishMessage.js +41 -0
- package/dist/tools/readChannel.d.ts +8 -0
- package/dist/tools/readChannel.js +44 -0
- package/dist/tools/readFile.d.ts +1 -1
- package/dist/tools/runAgent.d.ts +11 -0
- package/dist/tools/runAgent.js +111 -0
- package/dist/tools/runCommand.d.ts +1 -1
- package/dist/tools/runCommand.js +1 -1
- package/dist/tools/searchFiles.d.ts +1 -1
- package/dist/tools/semanticSearch.d.ts +1 -1
- package/dist/tools/semanticSearch.js +1 -1
- package/dist/tools/sendToAgent.d.ts +11 -0
- package/dist/tools/sendToAgent.js +35 -0
- package/dist/tools/spawnAgent.d.ts +6 -0
- package/dist/tools/spawnAgent.js +163 -0
- package/dist/tools/subscribeMessage.d.ts +8 -0
- package/dist/tools/subscribeMessage.js +59 -0
- package/dist/tools/writeFile.d.ts +1 -1
- package/dist/tools/writeFile.js +1 -1
- package/dist/types/index.d.ts +49 -1
- package/package.json +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getBus } from '../core/busAccess.js';
|
|
2
|
+
export const subscribeMessage = {
|
|
3
|
+
name: 'subscribe_message',
|
|
4
|
+
description: [
|
|
5
|
+
'订阅指定频道,等待其他 Agent 发布消息后返回内容。',
|
|
6
|
+
'适用场景:',
|
|
7
|
+
' - SubAgent B 等待 SubAgent A 完成并发布结果后再继续执行',
|
|
8
|
+
' - 实现 Agent 间的同步协调(生产者-消费者模式)',
|
|
9
|
+
' - 读取频道最新历史消息(设置 read_latest=true 时不阻塞)',
|
|
10
|
+
'注意:默认超时 30 秒,超时后返回 null,Agent 应处理超时情况。',
|
|
11
|
+
].join('\n'),
|
|
12
|
+
parameters: {
|
|
13
|
+
channel: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
description: '要订阅的频道名称',
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
read_latest: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: '可选。设为 "true" 时,若频道已有历史消息则立即返回最新一条,不阻塞等待。默认 false',
|
|
21
|
+
required: false,
|
|
22
|
+
},
|
|
23
|
+
from_offset: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
description: '可选。从指定位置(0-based)开始消费。若该位置已有消息则立即返回,否则阻塞等待。用于避免错过在订阅前已发布的消息',
|
|
26
|
+
required: false,
|
|
27
|
+
},
|
|
28
|
+
timeout_seconds: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
description: '可选。等待超时秒数,默认 30 秒。超时返回空结果',
|
|
31
|
+
required: false,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
execute: async (args) => {
|
|
35
|
+
const channel = (args.channel || '').trim();
|
|
36
|
+
if (!channel)
|
|
37
|
+
throw new Error('缺少必填参数: channel');
|
|
38
|
+
const readLatest = (args.read_latest || '').toLowerCase() === 'true';
|
|
39
|
+
const timeoutSec = parseInt(args.timeout_seconds || '30', 10);
|
|
40
|
+
const timeoutMs = Math.max(1000, Math.min(timeoutSec * 1000, 300_000));
|
|
41
|
+
const fromOffsetRaw = (args.from_offset || '').trim();
|
|
42
|
+
const fromOffset = fromOffsetRaw !== '' ? parseInt(fromOffsetRaw, 10) : undefined;
|
|
43
|
+
const bus = await getBus();
|
|
44
|
+
if (readLatest) {
|
|
45
|
+
const history = await bus.getHistory(channel, 1);
|
|
46
|
+
if (history.length === 0)
|
|
47
|
+
return `频道 "${channel}" 暂无历史消息`;
|
|
48
|
+
return formatMessage(history[0]);
|
|
49
|
+
}
|
|
50
|
+
const msg = await bus.subscribe(channel, timeoutMs, fromOffset);
|
|
51
|
+
if (!msg)
|
|
52
|
+
return `订阅频道 "${channel}" 超时(${timeoutSec}s),未收到消息`;
|
|
53
|
+
return formatMessage(msg);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
function formatMessage(msg) {
|
|
57
|
+
const time = new Date(msg.timestamp).toISOString();
|
|
58
|
+
return `[频道: ${msg.channel}] [来自: ${msg.from}] [时间: ${time}]\n${msg.payload}`;
|
|
59
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Tool } from '../types/index';
|
|
1
|
+
import { Tool } from '../types/index.js';
|
|
2
2
|
export declare const writeFile: Tool;
|
package/dist/tools/writeFile.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface Message {
|
|
|
24
24
|
abortHint?: string;
|
|
25
25
|
/** 并行执行组 ID,同组工具同时运行 */
|
|
26
26
|
parallelGroupId?: string;
|
|
27
|
+
/** 来源 SubAgent 标识,格式如 "ResearchAgent",用于 UI 前缀展示 */
|
|
28
|
+
subAgentId?: string;
|
|
27
29
|
}
|
|
28
30
|
export type ContentBlock = {
|
|
29
31
|
type: 'text';
|
|
@@ -45,11 +47,18 @@ export interface ToolParameter {
|
|
|
45
47
|
description: string;
|
|
46
48
|
required?: boolean;
|
|
47
49
|
}
|
|
50
|
+
/** 工具执行时可选的额外回调,用于特殊工具(如 dispatch_subagent)向主线程推送实时事件 */
|
|
51
|
+
export interface ToolCallbacks {
|
|
52
|
+
/** SubAgent 产生新消息时推送到主线程 UI */
|
|
53
|
+
onSubAgentMessage?: (msg: Message) => void;
|
|
54
|
+
/** SubAgent 更新已有消息 */
|
|
55
|
+
onSubAgentUpdateMessage?: (id: string, updates: Partial<Message>) => void;
|
|
56
|
+
}
|
|
48
57
|
export interface Tool {
|
|
49
58
|
name: string;
|
|
50
59
|
description: string;
|
|
51
60
|
parameters: Record<string, ToolParameter>;
|
|
52
|
-
execute: (args: Record<string, unknown>, abortSignal?: AbortSignal) => Promise<string>;
|
|
61
|
+
execute: (args: Record<string, unknown>, abortSignal?: AbortSignal, toolCallbacks?: ToolCallbacks) => Promise<string>;
|
|
53
62
|
}
|
|
54
63
|
export interface Session {
|
|
55
64
|
id: string;
|
|
@@ -93,3 +102,42 @@ export interface TranscriptMessage {
|
|
|
93
102
|
export interface LLMService {
|
|
94
103
|
streamMessage: (transcript: TranscriptMessage[], tools: Tool[], callbacks: StreamCallbacks, abortSignal?: AbortSignal) => Promise<void>;
|
|
95
104
|
}
|
|
105
|
+
/** SubAgent 状态 */
|
|
106
|
+
export type SubAgentStatus = 'idle' | 'running' | 'done' | 'error' | 'aborted';
|
|
107
|
+
/** SubAgent 任务描述 */
|
|
108
|
+
export interface SubAgentTask {
|
|
109
|
+
/** 任务唯一 ID */
|
|
110
|
+
taskId: string;
|
|
111
|
+
/** 任务描述(发给 SubAgent 的指令) */
|
|
112
|
+
instruction: string;
|
|
113
|
+
/** 可选:限制 SubAgent 可用的工具名列表(为空则继承全部工具) */
|
|
114
|
+
allowedTools?: string[];
|
|
115
|
+
/** 可选:SubAgent 角色描述,注入 system prompt */
|
|
116
|
+
role?: string;
|
|
117
|
+
/** 可选:初始上下文 transcript */
|
|
118
|
+
contextTranscript?: TranscriptMessage[];
|
|
119
|
+
/** 可选:直接指定 SubAgent 的 system prompt,跳过主 Agent 的 agent 文件加载 */
|
|
120
|
+
systemPrompt?: string;
|
|
121
|
+
}
|
|
122
|
+
/** SubAgent 执行结果 */
|
|
123
|
+
export interface SubAgentResult {
|
|
124
|
+
taskId: string;
|
|
125
|
+
status: 'done' | 'error' | 'aborted';
|
|
126
|
+
/** 最终输出文本 */
|
|
127
|
+
output: string;
|
|
128
|
+
/** 执行过程中产生的消息列表(用于主 Agent 展示) */
|
|
129
|
+
messages: Message[];
|
|
130
|
+
/** 更新后的 transcript */
|
|
131
|
+
transcript: TranscriptMessage[];
|
|
132
|
+
/** 错误信息(status=error 时) */
|
|
133
|
+
error?: string;
|
|
134
|
+
}
|
|
135
|
+
/** AgentManager 向外暴露的任务派发回调 */
|
|
136
|
+
export interface AgentManagerCallbacks {
|
|
137
|
+
/** SubAgent 产生新消息时(用于 UI 展示) */
|
|
138
|
+
onSubAgentMessage: (taskId: string, msg: Message) => void;
|
|
139
|
+
/** SubAgent 状态变更 */
|
|
140
|
+
onSubAgentStatusChange: (taskId: string, status: SubAgentStatus) => void;
|
|
141
|
+
/** 所有 SubAgent 完成后汇总回调 */
|
|
142
|
+
onAllDone: (results: SubAgentResult[]) => void;
|
|
143
|
+
}
|