@ai-setting/roy-agent-core 1.5.44 → 1.5.45
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/dist/config/index.js +5 -5
- package/dist/env/agent/index.js +5 -5
- package/dist/env/commands/index.js +5 -5
- package/dist/env/context/index.js +4 -1
- package/dist/env/debug/index.js +5 -5
- package/dist/env/event-source/index.js +7 -7
- package/dist/env/hook/index.js +3 -3
- package/dist/env/index.js +19 -16
- package/dist/env/llm/index.js +5 -5
- package/dist/env/log-trace/index.js +5 -5
- package/dist/env/mcp/index.js +20 -6
- package/dist/env/memory/index.js +5 -5
- package/dist/env/plugin/index.js +5 -5
- package/dist/env/prompt/index.js +5 -5
- package/dist/env/session/index.js +6 -6
- package/dist/env/session/storage/index.js +1 -1
- package/dist/env/skill/index.js +5 -5
- package/dist/env/task/delegate/index.js +3 -3
- package/dist/env/task/index.js +6 -6
- package/dist/env/task/plugins/index.js +2 -2
- package/dist/env/tool/index.js +5 -5
- package/dist/env/workflow/engine/index.js +7 -2
- package/dist/env/workflow/index.js +10 -7
- package/dist/env/workflow/tools/index.js +14 -0
- package/dist/index.js +29 -26
- package/dist/shared/@ai-setting/{roy-agent-core-kajktp3d.js → roy-agent-core-20fm423j.js} +47 -26
- package/dist/shared/@ai-setting/{roy-agent-core-23gw9c4s.js → roy-agent-core-2vhsccvz.js} +52 -10
- package/dist/shared/@ai-setting/{roy-agent-core-69jskqjg.js → roy-agent-core-44g4dhzg.js} +75 -7
- package/dist/shared/@ai-setting/{roy-agent-core-e9fdm13a.js → roy-agent-core-4gmxjdhn.js} +4 -2
- package/dist/shared/@ai-setting/{roy-agent-core-b4wd9tn6.js → roy-agent-core-4k9a823d.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-68qy97r3.js +31 -0
- package/dist/shared/@ai-setting/roy-agent-core-6atd905e.js +42 -0
- package/dist/shared/@ai-setting/{roy-agent-core-4jqq077c.js → roy-agent-core-6e3wz81d.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-pwkk12p4.js → roy-agent-core-6mcb7nqa.js} +60 -0
- package/dist/shared/@ai-setting/{roy-agent-core-9p43ap7h.js → roy-agent-core-8y804aat.js} +4 -2
- package/dist/shared/@ai-setting/{roy-agent-core-r6rwsr54.js → roy-agent-core-9p604xjf.js} +29 -9
- package/dist/shared/@ai-setting/{roy-agent-core-z1xf2fdk.js → roy-agent-core-a67e90d1.js} +6 -4
- package/dist/shared/@ai-setting/{roy-agent-core-xkb264a8.js → roy-agent-core-bp3xggmb.js} +192 -26
- package/dist/shared/@ai-setting/{roy-agent-core-zrja5v78.js → roy-agent-core-ce9w0j8n.js} +10 -2
- package/dist/shared/@ai-setting/{roy-agent-core-2ms7296b.js → roy-agent-core-cr8xer31.js} +12 -5
- package/dist/shared/@ai-setting/roy-agent-core-dbxm76wf.js +190 -0
- package/dist/shared/@ai-setting/{roy-agent-core-nj8yerg9.js → roy-agent-core-eftqdsy5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-psvwzdhj.js → roy-agent-core-hdszq729.js} +9 -5
- package/dist/shared/@ai-setting/{roy-agent-core-dxbsc1zy.js → roy-agent-core-ja9qhg6d.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-cevpwnq7.js → roy-agent-core-mjbfgqen.js} +5 -3
- package/dist/shared/@ai-setting/roy-agent-core-nhfy3p8q.js +132 -0
- package/dist/shared/@ai-setting/{roy-agent-core-38dkek2y.js → roy-agent-core-nn9dmffw.js} +325 -114
- package/dist/shared/@ai-setting/{roy-agent-core-ee6nnnqw.js → roy-agent-core-r9hq4cjx.js} +8 -1
- package/dist/shared/@ai-setting/{roy-agent-core-jqy2mdyq.js → roy-agent-core-rgj6hq15.js} +52 -41
- package/dist/shared/@ai-setting/{roy-agent-core-z33en0cz.js → roy-agent-core-rm3hay00.js} +15 -2
- package/dist/shared/@ai-setting/{roy-agent-core-ryw3ckfy.js → roy-agent-core-rx74rye7.js} +5 -3
- package/dist/shared/@ai-setting/{roy-agent-core-pxcrzyv9.js → roy-agent-core-sk535ft2.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-2dhd60aw.js → roy-agent-core-vdwvamre.js} +10 -0
- package/dist/shared/@ai-setting/{roy-agent-core-1zq3p19q.js → roy-agent-core-w64zachx.js} +8 -4
- package/dist/shared/@ai-setting/roy-agent-core-ye0z728h.js +18 -0
- package/dist/shared/@ai-setting/{roy-agent-core-eg6nv09z.js → roy-agent-core-ztx5eh72.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-nqgrjja0.js → roy-agent-core-zwq6vhpj.js} +1 -1
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__esm
|
|
3
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
4
|
+
|
|
5
|
+
// src/env/workflow/utils/workflow-message-metadata.ts
|
|
6
|
+
function getWorkflowNodeIdFromMetadata(metadata) {
|
|
7
|
+
if (!metadata) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const nodeId = metadata.nodeId;
|
|
11
|
+
const workflowNodeId = metadata.workflowNodeId;
|
|
12
|
+
return nodeId ?? workflowNodeId;
|
|
13
|
+
}
|
|
14
|
+
function buildWorkflowNodeMetadata(type, nodeId, nodeType, extra) {
|
|
15
|
+
return {
|
|
16
|
+
_workflowNodeMetadata: true,
|
|
17
|
+
type,
|
|
18
|
+
nodeId,
|
|
19
|
+
workflowNodeId: nodeId,
|
|
20
|
+
workflowNodeType: nodeType,
|
|
21
|
+
...extra
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function patchAgentSessionIdOnMessage(metadata, parts, agentSessionId) {
|
|
25
|
+
const nextMetadata = {
|
|
26
|
+
...metadata ?? {},
|
|
27
|
+
agentSessionId
|
|
28
|
+
};
|
|
29
|
+
if (!parts?.length) {
|
|
30
|
+
return { metadata: nextMetadata, parts };
|
|
31
|
+
}
|
|
32
|
+
const nextParts = parts.map((part) => {
|
|
33
|
+
if (part && typeof part === "object" && "nodeId" in part) {
|
|
34
|
+
return { ...part, agentSessionId };
|
|
35
|
+
}
|
|
36
|
+
return part;
|
|
37
|
+
});
|
|
38
|
+
return { metadata: nextMetadata, parts: nextParts };
|
|
39
|
+
}
|
|
40
|
+
var init_workflow_message_metadata = () => {};
|
|
41
|
+
|
|
42
|
+
export { getWorkflowNodeIdFromMetadata, buildWorkflowNodeMetadata, patchAgentSessionIdOnMessage, init_workflow_message_metadata };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createHook
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-vdwvamre.js";
|
|
4
4
|
import {
|
|
5
5
|
HookManager
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-rgj6hq15.js";
|
|
7
7
|
|
|
8
8
|
// src/env/component.ts
|
|
9
9
|
class BaseComponent {
|
|
@@ -138,6 +138,28 @@ class MemorySessionStore {
|
|
|
138
138
|
session.updatedAt = Date.now();
|
|
139
139
|
return msg.id;
|
|
140
140
|
}
|
|
141
|
+
async updateMessage(sessionId, messageId, updates) {
|
|
142
|
+
const sessionMessages = this.messages.get(sessionId);
|
|
143
|
+
if (!sessionMessages) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const index = sessionMessages.findIndex((m) => m.id === messageId);
|
|
147
|
+
if (index < 0) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const current = sessionMessages[index];
|
|
151
|
+
sessionMessages[index] = {
|
|
152
|
+
...current,
|
|
153
|
+
...updates.content !== undefined ? { content: updates.content } : {},
|
|
154
|
+
...updates.metadata !== undefined ? { metadata: updates.metadata } : {},
|
|
155
|
+
...updates.parts !== undefined ? { parts: updates.parts } : {}
|
|
156
|
+
};
|
|
157
|
+
const session = this.sessions.get(sessionId);
|
|
158
|
+
if (session) {
|
|
159
|
+
session.updatedAt = Date.now();
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
141
163
|
async getMessages(sessionId, offset = 0, limit = 50, options) {
|
|
142
164
|
let messages = this.messages.get(sessionId) ?? [];
|
|
143
165
|
if (!options?.includeArchived) {
|
|
@@ -589,6 +611,44 @@ class SQLiteSessionStore {
|
|
|
589
611
|
this.sessionsCache.set(sessionId, session);
|
|
590
612
|
return msg.id;
|
|
591
613
|
}
|
|
614
|
+
async updateMessage(sessionId, messageId, updates) {
|
|
615
|
+
await this.initialize();
|
|
616
|
+
const row = this.db.prepare("SELECT id FROM message WHERE id = ? AND session_id = ?").get(messageId, sessionId);
|
|
617
|
+
if (!row) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
const sets = [];
|
|
621
|
+
const values = [];
|
|
622
|
+
if (updates.content !== undefined) {
|
|
623
|
+
sets.push("content = ?");
|
|
624
|
+
values.push(updates.content);
|
|
625
|
+
}
|
|
626
|
+
if (updates.parts !== undefined) {
|
|
627
|
+
sets.push("parts = ?");
|
|
628
|
+
values.push(JSON.stringify(updates.parts));
|
|
629
|
+
}
|
|
630
|
+
if (updates.metadata !== undefined) {
|
|
631
|
+
sets.push("metadata = ?");
|
|
632
|
+
values.push(JSON.stringify(updates.metadata));
|
|
633
|
+
}
|
|
634
|
+
if (sets.length === 0) {
|
|
635
|
+
return true;
|
|
636
|
+
}
|
|
637
|
+
values.push(messageId, sessionId);
|
|
638
|
+
this.db.prepare(`UPDATE message SET ${sets.join(", ")} WHERE id = ? AND session_id = ?`).run(...values);
|
|
639
|
+
const messages = this.messagesCache.get(sessionId) ?? [];
|
|
640
|
+
const index = messages.findIndex((m) => m.id === messageId);
|
|
641
|
+
if (index >= 0) {
|
|
642
|
+
messages[index] = {
|
|
643
|
+
...messages[index],
|
|
644
|
+
...updates.content !== undefined ? { content: updates.content } : {},
|
|
645
|
+
...updates.metadata !== undefined ? { metadata: updates.metadata } : {},
|
|
646
|
+
...updates.parts !== undefined ? { parts: updates.parts } : {}
|
|
647
|
+
};
|
|
648
|
+
this.messagesCache.set(sessionId, messages);
|
|
649
|
+
}
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
592
652
|
async getMessages(sessionId, offset = 0, limit = 50, options) {
|
|
593
653
|
await this.initialize();
|
|
594
654
|
let sql = "SELECT * FROM message WHERE session_id = ?";
|
|
@@ -5,8 +5,9 @@ import {
|
|
|
5
5
|
TaskHookPoints
|
|
6
6
|
} from "./roy-agent-core-92z6t4he.js";
|
|
7
7
|
import {
|
|
8
|
-
globalHookManager
|
|
9
|
-
|
|
8
|
+
globalHookManager,
|
|
9
|
+
init_global_hook_manager
|
|
10
|
+
} from "./roy-agent-core-rgj6hq15.js";
|
|
10
11
|
import {
|
|
11
12
|
createLogger,
|
|
12
13
|
init_logger
|
|
@@ -73,6 +74,7 @@ function listKnownSubagentDescriptions(registry) {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
// src/env/task/delegate/delegate-tool.ts
|
|
77
|
+
init_global_hook_manager();
|
|
76
78
|
var logger = createLogger("task:delegate");
|
|
77
79
|
var BackgroundTaskEventTypes = {
|
|
78
80
|
STARTED: "task.background.started",
|
|
@@ -17,13 +17,15 @@ import {
|
|
|
17
17
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
18
18
|
import {
|
|
19
19
|
BaseComponent
|
|
20
|
-
} from "./roy-agent-core-
|
|
20
|
+
} from "./roy-agent-core-6e3wz81d.js";
|
|
21
21
|
import {
|
|
22
|
-
globalHookManager
|
|
23
|
-
|
|
22
|
+
globalHookManager,
|
|
23
|
+
init_global_hook_manager
|
|
24
|
+
} from "./roy-agent-core-rgj6hq15.js";
|
|
24
25
|
import {
|
|
26
|
+
init_context,
|
|
25
27
|
runWithEnvContextAsync
|
|
26
|
-
} from "./roy-agent-core-
|
|
28
|
+
} from "./roy-agent-core-rm3hay00.js";
|
|
27
29
|
import {
|
|
28
30
|
createLogger,
|
|
29
31
|
init_logger
|
|
@@ -67,6 +69,8 @@ var AGENT_CONFIG_REGISTRATION = {
|
|
|
67
69
|
|
|
68
70
|
// src/env/agent/agent-component.ts
|
|
69
71
|
init_decorator();
|
|
72
|
+
init_global_hook_manager();
|
|
73
|
+
init_context();
|
|
70
74
|
init_workflow_hil();
|
|
71
75
|
var logger = createLogger("agent:component");
|
|
72
76
|
function toLLMMessage(msg) {
|
|
@@ -579,10 +583,12 @@ class AgentComponent extends BaseComponent {
|
|
|
579
583
|
model: effectiveContext.model
|
|
580
584
|
}
|
|
581
585
|
});
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
+
if (query) {
|
|
587
|
+
this.pushMessage(hookCtx, {
|
|
588
|
+
role: "user",
|
|
589
|
+
content: query
|
|
590
|
+
});
|
|
591
|
+
}
|
|
586
592
|
await this.executePluginHooks(agent, "agent:before.start", hookCtx);
|
|
587
593
|
if (hookCtx._stopped) {
|
|
588
594
|
return this.finalizeResult(result, hookCtx);
|
|
@@ -877,6 +883,7 @@ class AgentComponent extends BaseComponent {
|
|
|
877
883
|
if (iteration >= agent.config.maxIterations && !result.finalText) {
|
|
878
884
|
result.finalText = "Maximum iterations reached.";
|
|
879
885
|
}
|
|
886
|
+
const newMessages = hookCtx.messages.slice(historyMessageCount);
|
|
880
887
|
const reactContext = {
|
|
881
888
|
messages: hookCtx.messages,
|
|
882
889
|
sessionId: effectiveContext.sessionId,
|
|
@@ -886,6 +893,9 @@ class AgentComponent extends BaseComponent {
|
|
|
886
893
|
...hookCtx,
|
|
887
894
|
...reactContext
|
|
888
895
|
});
|
|
896
|
+
if (hookCtx.structuredOutputExtracted) {
|
|
897
|
+
result.structuredOutput = hookCtx.structuredOutputExtracted;
|
|
898
|
+
}
|
|
889
899
|
await this.executePluginHooks(agent, "agent:after.complete", hookCtx);
|
|
890
900
|
if (this.aborted.get(runId) === true || hookCtx._stopped) {
|
|
891
901
|
agent.status = "stopped";
|
|
@@ -913,7 +923,6 @@ class AgentComponent extends BaseComponent {
|
|
|
913
923
|
}
|
|
914
924
|
});
|
|
915
925
|
}
|
|
916
|
-
let newMessages = hookCtx.messages.slice(historyMessageCount);
|
|
917
926
|
logger.info(`Agent run completed: ${agentName}`, {
|
|
918
927
|
iterations: result.iterations,
|
|
919
928
|
hasError: !!result.error,
|
|
@@ -1030,6 +1039,14 @@ ${ctx.context.additionInfo}`
|
|
|
1030
1039
|
};
|
|
1031
1040
|
}
|
|
1032
1041
|
try {
|
|
1042
|
+
this.pushEnvEvent({
|
|
1043
|
+
type: "tool.call",
|
|
1044
|
+
payload: {
|
|
1045
|
+
id: toolCall.id,
|
|
1046
|
+
name: toolName,
|
|
1047
|
+
arguments: toolCall.arguments
|
|
1048
|
+
}
|
|
1049
|
+
});
|
|
1033
1050
|
const toolContext = {
|
|
1034
1051
|
session_id: ctx.context.sessionId,
|
|
1035
1052
|
message_id: ctx.context.messageId,
|
|
@@ -1169,6 +1186,9 @@ ${ctx.context.additionInfo}`
|
|
|
1169
1186
|
if (msg.role === "system") {
|
|
1170
1187
|
continue;
|
|
1171
1188
|
}
|
|
1189
|
+
if (msg.role === "user" && this.isEmptyMessage(msg.content)) {
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1172
1192
|
if (msg.role === "assistant" || msg.role === "tool") {
|
|
1173
1193
|
if (this.isEmptyMessage(msg.content)) {
|
|
1174
1194
|
continue;
|
|
@@ -7,13 +7,14 @@ import {
|
|
|
7
7
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
8
8
|
import {
|
|
9
9
|
BaseComponent
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-6e3wz81d.js";
|
|
11
11
|
import {
|
|
12
12
|
createHook
|
|
13
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-vdwvamre.js";
|
|
14
14
|
import {
|
|
15
|
-
globalHookManager
|
|
16
|
-
|
|
15
|
+
globalHookManager,
|
|
16
|
+
init_global_hook_manager
|
|
17
|
+
} from "./roy-agent-core-rgj6hq15.js";
|
|
17
18
|
import {
|
|
18
19
|
createLogger,
|
|
19
20
|
init_logger
|
|
@@ -692,6 +693,7 @@ var PROMPT_CONFIG_REGISTRATION = {
|
|
|
692
693
|
};
|
|
693
694
|
|
|
694
695
|
// src/env/prompt/prompt-component.ts
|
|
696
|
+
init_global_hook_manager();
|
|
695
697
|
var logger2 = createLogger("prompt");
|
|
696
698
|
|
|
697
699
|
class PromptComponent extends BaseComponent {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
11
11
|
import {
|
|
12
12
|
BaseComponent
|
|
13
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-6e3wz81d.js";
|
|
14
14
|
import {
|
|
15
15
|
createLogger,
|
|
16
16
|
init_logger
|
|
@@ -21,6 +21,7 @@ import { z } from "zod";
|
|
|
21
21
|
var McpServerLocalConfigSchema = z.object({
|
|
22
22
|
type: z.literal("local"),
|
|
23
23
|
command: z.array(z.string()).min(1),
|
|
24
|
+
cwd: z.string().optional(),
|
|
24
25
|
environment: z.record(z.string(), z.string()).optional(),
|
|
25
26
|
enabled: z.boolean().optional().default(true),
|
|
26
27
|
timeout: z.number().int().positive().optional()
|
|
@@ -84,8 +85,148 @@ init_logger();
|
|
|
84
85
|
|
|
85
86
|
// src/env/mcp/scanner.ts
|
|
86
87
|
init_logger();
|
|
87
|
-
import
|
|
88
|
+
import fs3 from "fs/promises";
|
|
89
|
+
import path4 from "path";
|
|
90
|
+
|
|
91
|
+
// src/env/mcp/command-resolver.ts
|
|
92
|
+
import fs2 from "fs";
|
|
93
|
+
import path3 from "path";
|
|
94
|
+
|
|
95
|
+
// src/env/mcp/npm-prefix.ts
|
|
96
|
+
import fs from "fs";
|
|
97
|
+
import { execSync } from "child_process";
|
|
98
|
+
import os2 from "os";
|
|
88
99
|
import path2 from "path";
|
|
100
|
+
function pathExistsSync(p) {
|
|
101
|
+
try {
|
|
102
|
+
fs.accessSync(p, fs.constants.F_OK);
|
|
103
|
+
return true;
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function getFallbackNpmPrefixPath() {
|
|
109
|
+
return path2.join(os2.homedir(), ".local", "share", "roy-agent", "npm-prefix");
|
|
110
|
+
}
|
|
111
|
+
function isUsableNpmPrefix(prefix) {
|
|
112
|
+
return pathExistsSync(path2.join(prefix, "lib")) || pathExistsSync(path2.join(prefix, "bin"));
|
|
113
|
+
}
|
|
114
|
+
function ensureNpmPrefixDirs(prefix) {
|
|
115
|
+
fs.mkdirSync(path2.join(prefix, "lib"), { recursive: true });
|
|
116
|
+
fs.mkdirSync(path2.join(prefix, "bin"), { recursive: true });
|
|
117
|
+
}
|
|
118
|
+
function ensureFallbackNpmPrefix() {
|
|
119
|
+
const fallback = getFallbackNpmPrefixPath();
|
|
120
|
+
ensureNpmPrefixDirs(fallback);
|
|
121
|
+
return fallback;
|
|
122
|
+
}
|
|
123
|
+
function readNpmConfigPrefix() {
|
|
124
|
+
try {
|
|
125
|
+
const prefix = execSync("npm config get prefix", {
|
|
126
|
+
encoding: "utf8",
|
|
127
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
128
|
+
}).trim();
|
|
129
|
+
return prefix || undefined;
|
|
130
|
+
} catch {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function resolveNpmPrefix() {
|
|
135
|
+
const candidates = [
|
|
136
|
+
process.env.NPM_CONFIG_PREFIX,
|
|
137
|
+
process.env.npm_config_prefix,
|
|
138
|
+
readNpmConfigPrefix(),
|
|
139
|
+
path2.join(os2.homedir(), ".npm-global")
|
|
140
|
+
].filter(Boolean);
|
|
141
|
+
for (const prefix of candidates) {
|
|
142
|
+
if (isUsableNpmPrefix(prefix)) {
|
|
143
|
+
return prefix;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return ensureFallbackNpmPrefix();
|
|
147
|
+
}
|
|
148
|
+
function resolveGlobalNodeModulesPath() {
|
|
149
|
+
return path2.join(resolveNpmPrefix(), "lib", "node_modules");
|
|
150
|
+
}
|
|
151
|
+
function resolveGlobalBinPath() {
|
|
152
|
+
return path2.join(resolveNpmPrefix(), "bin");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/env/mcp/command-resolver.ts
|
|
156
|
+
var PACKAGE_RUNNERS = new Set(["npx", "npm", "bunx", "yarn"]);
|
|
157
|
+
function pathExistsSync2(p) {
|
|
158
|
+
try {
|
|
159
|
+
fs2.accessSync(p, fs2.constants.F_OK);
|
|
160
|
+
return true;
|
|
161
|
+
} catch {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function extractPackageName(command) {
|
|
166
|
+
if (command.length < 2) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const runner = path3.basename(command[0]);
|
|
170
|
+
if (runner === "npx" || runner === "bunx") {
|
|
171
|
+
return command[1];
|
|
172
|
+
}
|
|
173
|
+
if (runner === "npm" && command[1] === "exec") {
|
|
174
|
+
const separatorIndex = command.indexOf("--");
|
|
175
|
+
if (separatorIndex >= 0) {
|
|
176
|
+
return command[separatorIndex + 1];
|
|
177
|
+
}
|
|
178
|
+
return command[2];
|
|
179
|
+
}
|
|
180
|
+
if (runner === "yarn" && command[1] === "dlx") {
|
|
181
|
+
return command[2];
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
function isPackageRunnerCommand(command) {
|
|
186
|
+
if (command.length < 2) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
const runner = path3.basename(command[0]);
|
|
190
|
+
if (!PACKAGE_RUNNERS.has(runner)) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
if (runner === "npm") {
|
|
194
|
+
return command[1] === "exec";
|
|
195
|
+
}
|
|
196
|
+
if (runner === "yarn") {
|
|
197
|
+
return command[1] === "dlx";
|
|
198
|
+
}
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
function resolvePackageRunnerCommand(command, serverDir) {
|
|
202
|
+
if (!isPackageRunnerCommand(command)) {
|
|
203
|
+
return command;
|
|
204
|
+
}
|
|
205
|
+
const packageName = extractPackageName(command);
|
|
206
|
+
if (!packageName) {
|
|
207
|
+
return command;
|
|
208
|
+
}
|
|
209
|
+
const localBin = path3.join(serverDir, "node_modules", ".bin", packageName);
|
|
210
|
+
if (pathExistsSync2(localBin)) {
|
|
211
|
+
return [localBin];
|
|
212
|
+
}
|
|
213
|
+
return command;
|
|
214
|
+
}
|
|
215
|
+
function augmentNpmEnvForPackageRunner(command, env) {
|
|
216
|
+
if (!isPackageRunnerCommand(command)) {
|
|
217
|
+
return env;
|
|
218
|
+
}
|
|
219
|
+
const prefix = env.NPM_CONFIG_PREFIX ?? process.env.NPM_CONFIG_PREFIX ?? process.env.npm_config_prefix;
|
|
220
|
+
if (prefix && isUsableNpmPrefix(prefix)) {
|
|
221
|
+
return env;
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
...env,
|
|
225
|
+
NPM_CONFIG_PREFIX: ensureFallbackNpmPrefix()
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/env/mcp/scanner.ts
|
|
89
230
|
var logger = createLogger("mcp-scanner");
|
|
90
231
|
var ENTRY_SCRIPT_CANDIDATES = [
|
|
91
232
|
"server.mjs",
|
|
@@ -104,13 +245,13 @@ var ENTRY_SCRIPT_CANDIDATES = [
|
|
|
104
245
|
function expandPath(inputPath) {
|
|
105
246
|
if (inputPath.startsWith("~/")) {
|
|
106
247
|
const home = process.env.HOME || process.env.USERPROFILE || "";
|
|
107
|
-
return
|
|
248
|
+
return path4.join(home, inputPath.slice(2));
|
|
108
249
|
}
|
|
109
|
-
return
|
|
250
|
+
return path4.resolve(inputPath);
|
|
110
251
|
}
|
|
111
252
|
async function pathExists(p) {
|
|
112
253
|
try {
|
|
113
|
-
await
|
|
254
|
+
await fs3.access(p);
|
|
114
255
|
return true;
|
|
115
256
|
} catch {
|
|
116
257
|
return false;
|
|
@@ -118,7 +259,7 @@ async function pathExists(p) {
|
|
|
118
259
|
}
|
|
119
260
|
async function parseConfigJsonc(configPath) {
|
|
120
261
|
try {
|
|
121
|
-
const configContent = await
|
|
262
|
+
const configContent = await fs3.readFile(configPath, "utf-8");
|
|
122
263
|
const cleaned = configContent.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
|
|
123
264
|
return JSON.parse(cleaned);
|
|
124
265
|
} catch (error) {
|
|
@@ -126,6 +267,12 @@ async function parseConfigJsonc(configPath) {
|
|
|
126
267
|
return;
|
|
127
268
|
}
|
|
128
269
|
}
|
|
270
|
+
function relativeCommandMatchesEntry(cmdPath, entryPath, serverDir) {
|
|
271
|
+
if (path4.resolve(serverDir, cmdPath) === entryPath) {
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
return ENTRY_SCRIPT_CANDIDATES.some((candidate) => cmdPath === candidate && entryPath === path4.join(serverDir, candidate));
|
|
275
|
+
}
|
|
129
276
|
function buildDefaultCommand(entryPath, directoryConfig, serverDir) {
|
|
130
277
|
if (directoryConfig?.command) {
|
|
131
278
|
const cmd = directoryConfig.command;
|
|
@@ -134,15 +281,14 @@ function buildDefaultCommand(entryPath, directoryConfig, serverDir) {
|
|
|
134
281
|
return cmd;
|
|
135
282
|
}
|
|
136
283
|
if (cmdPath && entryPath) {
|
|
137
|
-
|
|
138
|
-
if (resolvedConfigPath === entryPath || cmdPath === "src/index.ts" || cmdPath === "src/index.js") {
|
|
284
|
+
if (relativeCommandMatchesEntry(cmdPath, entryPath, serverDir)) {
|
|
139
285
|
return ["bun", "run", entryPath];
|
|
140
286
|
}
|
|
141
287
|
}
|
|
142
288
|
if (entryPath) {
|
|
143
289
|
return ["bun", "run", entryPath];
|
|
144
290
|
}
|
|
145
|
-
return cmd;
|
|
291
|
+
return resolvePackageRunnerCommand(cmd, serverDir);
|
|
146
292
|
}
|
|
147
293
|
return entryPath ? ["bun", "run", entryPath] : undefined;
|
|
148
294
|
}
|
|
@@ -170,10 +316,10 @@ class McpScanner {
|
|
|
170
316
|
}
|
|
171
317
|
logger.info(`[McpScanner] Scanning: ${expandedPath}`);
|
|
172
318
|
try {
|
|
173
|
-
const entries = await
|
|
319
|
+
const entries = await fs3.readdir(expandedPath, { withFileTypes: true });
|
|
174
320
|
for (const entry of entries) {
|
|
175
|
-
const fullPath =
|
|
176
|
-
const stat = await
|
|
321
|
+
const fullPath = path4.join(expandedPath, entry.name);
|
|
322
|
+
const stat = await fs3.stat(fullPath);
|
|
177
323
|
if (!stat.isDirectory())
|
|
178
324
|
continue;
|
|
179
325
|
await this.discoverServer(entry.name, fullPath, mcpPath.type);
|
|
@@ -184,8 +330,8 @@ class McpScanner {
|
|
|
184
330
|
}
|
|
185
331
|
async discoverServer(name, serverDir, sourceType) {
|
|
186
332
|
const entryPath = await this.findEntryScript(serverDir);
|
|
187
|
-
const configPath =
|
|
188
|
-
const packagePath =
|
|
333
|
+
const configPath = path4.join(serverDir, "config.jsonc");
|
|
334
|
+
const packagePath = path4.join(serverDir, "package.json");
|
|
189
335
|
let directoryConfig;
|
|
190
336
|
if (await pathExists(configPath)) {
|
|
191
337
|
directoryConfig = await parseConfigJsonc(configPath);
|
|
@@ -193,6 +339,7 @@ class McpScanner {
|
|
|
193
339
|
const defaultCommand = buildDefaultCommand(entryPath, directoryConfig, serverDir);
|
|
194
340
|
const server = {
|
|
195
341
|
name,
|
|
342
|
+
serverDir,
|
|
196
343
|
entryPath: entryPath || undefined,
|
|
197
344
|
configPath: await pathExists(configPath) ? configPath : undefined,
|
|
198
345
|
packagePath: await pathExists(packagePath) ? packagePath : undefined,
|
|
@@ -208,7 +355,7 @@ class McpScanner {
|
|
|
208
355
|
}
|
|
209
356
|
async findEntryScript(serverDir) {
|
|
210
357
|
for (const candidate of ENTRY_SCRIPT_CANDIDATES) {
|
|
211
|
-
const entryPath =
|
|
358
|
+
const entryPath = path4.join(serverDir, candidate);
|
|
212
359
|
if (await pathExists(entryPath)) {
|
|
213
360
|
return entryPath;
|
|
214
361
|
}
|
|
@@ -222,14 +369,14 @@ class McpScanner {
|
|
|
222
369
|
|
|
223
370
|
// src/env/mcp/loader.ts
|
|
224
371
|
init_logger();
|
|
225
|
-
import
|
|
226
|
-
import
|
|
227
|
-
import
|
|
372
|
+
import fs4 from "fs/promises";
|
|
373
|
+
import path5 from "path";
|
|
374
|
+
import os3 from "os";
|
|
228
375
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
229
376
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
230
377
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
231
378
|
var logger2 = createLogger("mcp-loader");
|
|
232
|
-
var AUTH_JSON_PATH =
|
|
379
|
+
var AUTH_JSON_PATH = path5.join(os3.homedir(), ".roy-agent", "auth.json");
|
|
233
380
|
|
|
234
381
|
class McpLoader {
|
|
235
382
|
clients = new Map;
|
|
@@ -252,6 +399,7 @@ class McpLoader {
|
|
|
252
399
|
const localConfig = {
|
|
253
400
|
type: "local",
|
|
254
401
|
command,
|
|
402
|
+
...server.serverDir ? { cwd: server.serverDir } : {},
|
|
255
403
|
environment: server.directoryConfig?.environment,
|
|
256
404
|
enabled: server.directoryConfig?.enabled ?? true,
|
|
257
405
|
timeout: server.directoryConfig?.timeout ?? this.defaultTimeout
|
|
@@ -290,13 +438,16 @@ class McpLoader {
|
|
|
290
438
|
let transport;
|
|
291
439
|
if (config.type === "local") {
|
|
292
440
|
const localConfig = config;
|
|
293
|
-
const env = { ...localConfig.environment };
|
|
441
|
+
const env = augmentNpmEnvForPackageRunner(localConfig.command, { ...localConfig.environment });
|
|
294
442
|
await this.injectMinimaxEnv(env);
|
|
295
443
|
transport = new StdioClientTransport({
|
|
296
444
|
command: localConfig.command[0],
|
|
297
445
|
args: localConfig.command.slice(1),
|
|
298
|
-
env
|
|
446
|
+
env,
|
|
447
|
+
...localConfig.cwd ? { cwd: localConfig.cwd } : {},
|
|
448
|
+
stderr: "pipe"
|
|
299
449
|
});
|
|
450
|
+
this.attachStderrDrain(name, transport);
|
|
300
451
|
client = new Client({ name, version: "1.0.0" });
|
|
301
452
|
await client.connect(transport);
|
|
302
453
|
} else {
|
|
@@ -325,6 +476,21 @@ class McpLoader {
|
|
|
325
476
|
this.clients.delete(name);
|
|
326
477
|
logger2.info(`[McpLoader] Disconnected from ${name}`);
|
|
327
478
|
}
|
|
479
|
+
attachStderrDrain(serverName, transport) {
|
|
480
|
+
const stderrStream = transport.stderr;
|
|
481
|
+
if (!stderrStream) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
stderrStream.on("data", (chunk) => {
|
|
485
|
+
const text = chunk.toString().trim();
|
|
486
|
+
if (text) {
|
|
487
|
+
logger2.debug(`[McpLoader] ${serverName} stderr: ${text}`);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
stderrStream.on("error", (error) => {
|
|
491
|
+
logger2.debug(`[McpLoader] ${serverName} stderr stream error`, { error });
|
|
492
|
+
});
|
|
493
|
+
}
|
|
328
494
|
async closeTransport(transport, name) {
|
|
329
495
|
try {
|
|
330
496
|
const transportAny = transport;
|
|
@@ -355,7 +521,7 @@ class McpLoader {
|
|
|
355
521
|
}
|
|
356
522
|
async loadMinimaxApiKey() {
|
|
357
523
|
try {
|
|
358
|
-
const content = await
|
|
524
|
+
const content = await fs4.readFile(AUTH_JSON_PATH, "utf-8");
|
|
359
525
|
const auth = JSON.parse(content);
|
|
360
526
|
return auth.providers?.minimax?.apiKey;
|
|
361
527
|
} catch (error) {
|
|
@@ -376,15 +542,15 @@ class McpLoader {
|
|
|
376
542
|
}
|
|
377
543
|
|
|
378
544
|
// src/env/mcp/mcp-config-registration.ts
|
|
379
|
-
import
|
|
380
|
-
import
|
|
545
|
+
import path6 from "path";
|
|
546
|
+
import os4 from "os";
|
|
381
547
|
var MCP_DEFAULTS = {
|
|
382
548
|
"mcp.enabled": true,
|
|
383
549
|
"mcp.timeout": 30000,
|
|
384
550
|
"mcp.mcpPaths": [
|
|
385
551
|
{
|
|
386
552
|
type: "user",
|
|
387
|
-
path:
|
|
553
|
+
path: path6.join(os4.homedir(), ".config", "roy-agent", "mcp")
|
|
388
554
|
},
|
|
389
555
|
{
|
|
390
556
|
type: "project",
|
|
@@ -625,4 +791,4 @@ class McpComponent extends BaseComponent {
|
|
|
625
791
|
await this.loadServers();
|
|
626
792
|
}
|
|
627
793
|
}
|
|
628
|
-
export { McpServerLocalConfigSchema, McpServerRemoteConfigSchema, McpServerConfigSchema, DEFAULT_MCP_CONFIG, MCP_CONFIG_KEYS, getMcpPathPriority, McpScanner, McpLoader, McpComponent };
|
|
794
|
+
export { McpServerLocalConfigSchema, McpServerRemoteConfigSchema, McpServerConfigSchema, DEFAULT_MCP_CONFIG, MCP_CONFIG_KEYS, getMcpPathPriority, isUsableNpmPrefix, ensureFallbackNpmPrefix, resolveNpmPrefix, resolveGlobalNodeModulesPath, resolveGlobalBinPath, resolvePackageRunnerCommand, augmentNpmEnvForPackageRunner, McpScanner, McpLoader, McpComponent };
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
16
16
|
import {
|
|
17
17
|
BaseComponent
|
|
18
|
-
} from "./roy-agent-core-
|
|
18
|
+
} from "./roy-agent-core-6e3wz81d.js";
|
|
19
19
|
import {
|
|
20
20
|
createLogger,
|
|
21
21
|
init_logger
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
MemorySessionStore,
|
|
25
25
|
SQLiteSessionStore
|
|
26
|
-
} from "./roy-agent-core-
|
|
26
|
+
} from "./roy-agent-core-6mcb7nqa.js";
|
|
27
27
|
import {
|
|
28
28
|
__legacyDecorateClassTS
|
|
29
29
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -341,6 +341,14 @@ class SessionComponent extends BaseComponent {
|
|
|
341
341
|
const messages = await this.store?.getMessages(sessionId, options?.offset, options?.limit);
|
|
342
342
|
return messages ?? [];
|
|
343
343
|
}
|
|
344
|
+
async updateMessage(sessionId, messageId, updates) {
|
|
345
|
+
try {
|
|
346
|
+
return await this.store?.updateMessage(sessionId, messageId, updates) ?? false;
|
|
347
|
+
} catch (error) {
|
|
348
|
+
logger.error(`[SessionComponent] Failed to update message: ${error}`);
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
344
352
|
async getMessageCount(sessionId, includeArchived) {
|
|
345
353
|
return this.store?.getMessageCount(sessionId, includeArchived) ?? 0;
|
|
346
354
|
}
|