@ai-setting/roy-agent-core 1.5.17-beta.1 → 1.5.23
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/env/event-source/index.js +41 -0
- package/dist/env/index.js +24 -10
- package/dist/env/log-trace/index.js +1 -1
- package/dist/env/prompt/index.js +1 -1
- package/dist/env/workflow/engine/index.js +1 -1
- package/dist/env/workflow/index.js +2 -2
- package/dist/index.js +35 -8
- package/dist/shared/@ai-setting/roy-agent-core-2grcjaad.js +0 -0
- package/dist/shared/@ai-setting/{roy-agent-core-xq8hhqb8.js → roy-agent-core-4wjywp3c.js} +4 -2
- package/dist/shared/@ai-setting/roy-agent-core-5ex3za0m.js +817 -0
- package/dist/shared/@ai-setting/roy-agent-core-8jxva565.js +19 -0
- package/dist/shared/@ai-setting/roy-agent-core-avq1x4t7.js +84 -0
- package/dist/shared/@ai-setting/{roy-agent-core-gq20wsgv.js → roy-agent-core-ffb9fq4v.js} +23 -2
- package/dist/shared/@ai-setting/roy-agent-core-j1sr5pk9.js +424 -0
- package/dist/shared/@ai-setting/{roy-agent-core-93zfb3r1.js → roy-agent-core-mrcxzpbg.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-rhmtwnw1.js → roy-agent-core-pw7cv1px.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-wrcy0h6z.js → roy-agent-core-ty94k28r.js} +1 -1
- package/package.json +8 -29
- package/dist/config/index.d.ts +0 -1250
- package/dist/env/agent/index.d.ts +0 -2279
- package/dist/env/commands/index.d.ts +0 -1131
- package/dist/env/debug/formatters/index.d.ts +0 -236
- package/dist/env/debug/index.d.ts +0 -1652
- package/dist/env/hook/index.d.ts +0 -279
- package/dist/env/index.d.ts +0 -3481
- package/dist/env/llm/index.d.ts +0 -1760
- package/dist/env/log-trace/index.d.ts +0 -1574
- package/dist/env/mcp/index.d.ts +0 -1331
- package/dist/env/mcp/tool/index.d.ts +0 -183
- package/dist/env/memory/built-in/index.d.ts +0 -232
- package/dist/env/memory/index.d.ts +0 -1799
- package/dist/env/memory/plugin/index.d.ts +0 -747
- package/dist/env/prompt/index.d.ts +0 -1164
- package/dist/env/session/index.d.ts +0 -1908
- package/dist/env/session/storage/index.d.ts +0 -564
- package/dist/env/skill/index.d.ts +0 -1266
- package/dist/env/skill/tool/index.d.ts +0 -193
- package/dist/env/task/delegate/index.d.ts +0 -1612
- package/dist/env/task/events/index.d.ts +0 -171
- package/dist/env/task/hooks/index.d.ts +0 -624
- package/dist/env/task/index.d.ts +0 -1553
- package/dist/env/task/plugins/index.d.ts +0 -466
- package/dist/env/task/storage/index.d.ts +0 -241
- package/dist/env/task/tools/index.d.ts +0 -1485
- package/dist/env/task/tools/operation/index.d.ts +0 -1484
- package/dist/env/tool/built-in/index.d.ts +0 -218
- package/dist/env/tool/index.d.ts +0 -1396
- package/dist/env/workflow/decorators/index.d.ts +0 -2161
- package/dist/env/workflow/engine/index.d.ts +0 -3453
- package/dist/env/workflow/index.d.ts +0 -3546
- package/dist/env/workflow/nodes/index.d.ts +0 -2092
- package/dist/env/workflow/service/index.d.ts +0 -227
- package/dist/env/workflow/storage/index.d.ts +0 -165
- package/dist/env/workflow/tools/index.d.ts +0 -416
- package/dist/env/workflow/types/index.d.ts +0 -2255
- package/dist/env/workflow/utils/index.d.ts +0 -2031
- package/dist/index.d.ts +0 -7858
- package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +0 -1387
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
3
|
+
BUILT_IN_EVENT_SOURCE_TYPE_LIST,
|
|
4
|
+
EventSourceInitHooks,
|
|
5
|
+
getDefaultConfigForType,
|
|
6
|
+
isBuiltInEventSourceType,
|
|
7
|
+
isValidEventSourceType,
|
|
8
|
+
validateEventSourceConfig
|
|
9
|
+
} from "./roy-agent-core-avq1x4t7.js";
|
|
10
|
+
import"./roy-agent-core-fs0mn2jk.js";
|
|
11
|
+
export {
|
|
12
|
+
validateEventSourceConfig,
|
|
13
|
+
isValidEventSourceType,
|
|
14
|
+
isBuiltInEventSourceType,
|
|
15
|
+
getDefaultConfigForType,
|
|
16
|
+
EventSourceInitHooks,
|
|
17
|
+
BUILT_IN_EVENT_SOURCE_TYPE_LIST,
|
|
18
|
+
BUILT_IN_EVENT_SOURCE_TYPES
|
|
19
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/env/event-source/types.ts
|
|
2
|
+
var BUILT_IN_EVENT_SOURCE_TYPES = {
|
|
3
|
+
LARK_CLI: "lark-cli",
|
|
4
|
+
WEBSOCKET: "websocket",
|
|
5
|
+
TIMER: "timer",
|
|
6
|
+
HTTP_WEBHOOK: "http-webhook",
|
|
7
|
+
FILE_WATCHER: "file-watcher"
|
|
8
|
+
};
|
|
9
|
+
var BUILT_IN_EVENT_SOURCE_TYPE_LIST = Object.values(BUILT_IN_EVENT_SOURCE_TYPES);
|
|
10
|
+
|
|
11
|
+
class EventSourceInitHooks {
|
|
12
|
+
static hooks = new Map;
|
|
13
|
+
static register(name, hook) {
|
|
14
|
+
this.hooks.set(name, hook);
|
|
15
|
+
}
|
|
16
|
+
static unregister(name) {
|
|
17
|
+
this.hooks.delete(name);
|
|
18
|
+
}
|
|
19
|
+
static list() {
|
|
20
|
+
return new Map(this.hooks);
|
|
21
|
+
}
|
|
22
|
+
static async execute(component) {
|
|
23
|
+
for (const [name, hook] of this.hooks) {
|
|
24
|
+
try {
|
|
25
|
+
await hook(component);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
process.stderr.write(`[EventSourceInitHooks] Failed to execute hook "${name}": ${error}
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
static clear() {
|
|
33
|
+
this.hooks.clear();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function isBuiltInEventSourceType(type) {
|
|
37
|
+
return BUILT_IN_EVENT_SOURCE_TYPE_LIST.includes(type);
|
|
38
|
+
}
|
|
39
|
+
function isValidEventSourceType(type) {
|
|
40
|
+
return isBuiltInEventSourceType(type);
|
|
41
|
+
}
|
|
42
|
+
function getDefaultConfigForType(type) {
|
|
43
|
+
switch (type) {
|
|
44
|
+
case BUILT_IN_EVENT_SOURCE_TYPES.TIMER:
|
|
45
|
+
return { interval: 60000 };
|
|
46
|
+
case BUILT_IN_EVENT_SOURCE_TYPES.LARK_CLI:
|
|
47
|
+
return { command: "lark-cli event +subscribe" };
|
|
48
|
+
case BUILT_IN_EVENT_SOURCE_TYPES.WEBSOCKET:
|
|
49
|
+
return {};
|
|
50
|
+
default:
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function validateEventSourceConfig(config, handler) {
|
|
55
|
+
const errors = [];
|
|
56
|
+
if (!config.id) {
|
|
57
|
+
errors.push("EventSource ID is required");
|
|
58
|
+
}
|
|
59
|
+
if (!config.name) {
|
|
60
|
+
errors.push("EventSource name is required");
|
|
61
|
+
}
|
|
62
|
+
if (!config.type) {
|
|
63
|
+
errors.push("EventSource type is required");
|
|
64
|
+
}
|
|
65
|
+
if (handler) {
|
|
66
|
+
const handlerErrors = handler.validateConfig(config);
|
|
67
|
+
errors.push(...handlerErrors);
|
|
68
|
+
} else {
|
|
69
|
+
if (config.type === BUILT_IN_EVENT_SOURCE_TYPES.TIMER) {
|
|
70
|
+
if (!config.interval || config.interval <= 0) {
|
|
71
|
+
errors.push("Timer interval must be a positive number");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (config.type === BUILT_IN_EVENT_SOURCE_TYPES.LARK_CLI && !config.command) {
|
|
75
|
+
errors.push("lark-cli command is required");
|
|
76
|
+
}
|
|
77
|
+
if (config.type === BUILT_IN_EVENT_SOURCE_TYPES.WEBSOCKET && !config.url) {
|
|
78
|
+
errors.push("WebSocket URL is required");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return errors;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { BUILT_IN_EVENT_SOURCE_TYPES, BUILT_IN_EVENT_SOURCE_TYPE_LIST, EventSourceInitHooks, isBuiltInEventSourceType, isValidEventSourceType, getDefaultConfigForType, validateEventSourceConfig };
|
|
@@ -23,6 +23,7 @@ function inferNextNode(messages, definition) {
|
|
|
23
23
|
agentSessionId: metadata.agentSessionId
|
|
24
24
|
};
|
|
25
25
|
case "workflow.node.end":
|
|
26
|
+
case "workflow.node.result":
|
|
26
27
|
return getNextNodes(metadata.workflowNodeId, definition);
|
|
27
28
|
default:
|
|
28
29
|
const lastStart = findLastStartMessage(messages);
|
|
@@ -34,6 +35,15 @@ function inferNextNode(messages, definition) {
|
|
|
34
35
|
agentSessionId: startMetadata.agentSessionId
|
|
35
36
|
};
|
|
36
37
|
}
|
|
38
|
+
const lastCall = findLastCallMessage(messages);
|
|
39
|
+
if (lastCall) {
|
|
40
|
+
const callMetadata = lastCall.metadata;
|
|
41
|
+
return {
|
|
42
|
+
type: "resume_node",
|
|
43
|
+
nodeId: callMetadata.workflowNodeId,
|
|
44
|
+
agentSessionId: callMetadata.agentSessionId
|
|
45
|
+
};
|
|
46
|
+
}
|
|
37
47
|
return { type: "entry_node", nodeId: definition.entryNode };
|
|
38
48
|
}
|
|
39
49
|
}
|
|
@@ -62,14 +72,24 @@ function findLastStartMessage(messages) {
|
|
|
62
72
|
}
|
|
63
73
|
return null;
|
|
64
74
|
}
|
|
75
|
+
function findLastCallMessage(messages) {
|
|
76
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
77
|
+
const msg = messages[i];
|
|
78
|
+
if (msg.metadata?.type === "workflow.node.call") {
|
|
79
|
+
return msg;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
65
84
|
function parseNodeOutputs(messages) {
|
|
66
85
|
const outputs = new Map;
|
|
67
86
|
let lastStartNodeId = null;
|
|
68
87
|
for (const msg of messages) {
|
|
69
88
|
const metadata = msg.metadata;
|
|
70
|
-
|
|
89
|
+
const msgType = metadata?.type;
|
|
90
|
+
if (msgType === "workflow.node.start" || msgType === "workflow.node.call") {
|
|
71
91
|
lastStartNodeId = metadata.workflowNodeId;
|
|
72
|
-
} else if (
|
|
92
|
+
} else if ((msgType === "workflow.node.end" || msgType === "workflow.node.result") && lastStartNodeId) {
|
|
73
93
|
try {
|
|
74
94
|
outputs.set(lastStartNodeId, JSON.parse(msg.content));
|
|
75
95
|
} catch {
|
|
@@ -135,5 +155,6 @@ export {
|
|
|
135
155
|
getAgentSessionIdFromInterrupt,
|
|
136
156
|
findLastStartMessage,
|
|
137
157
|
findLastInterruptMessage,
|
|
158
|
+
findLastCallMessage,
|
|
138
159
|
extractResumeInfo
|
|
139
160
|
};
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContextError,
|
|
3
|
+
ErrorCodes
|
|
4
|
+
} from "./roy-agent-core-ctdhjv68.js";
|
|
5
|
+
import {
|
|
6
|
+
BaseComponent
|
|
7
|
+
} from "./roy-agent-core-kkbwepqb.js";
|
|
8
|
+
import {
|
|
9
|
+
TracedAs,
|
|
10
|
+
init_decorator
|
|
11
|
+
} from "./roy-agent-core-zgypchmt.js";
|
|
12
|
+
import {
|
|
13
|
+
createLogger,
|
|
14
|
+
init_logger
|
|
15
|
+
} from "./roy-agent-core-44hnfb02.js";
|
|
16
|
+
import {
|
|
17
|
+
__legacyDecorateClassTS
|
|
18
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
19
|
+
|
|
20
|
+
// src/env/environment.ts
|
|
21
|
+
init_logger();
|
|
22
|
+
|
|
23
|
+
// src/utils/id.ts
|
|
24
|
+
function generateId(prefix = "id") {
|
|
25
|
+
const timestamp = Date.now().toString(36);
|
|
26
|
+
const random = Math.random().toString(36).substring(2, 11);
|
|
27
|
+
return `${prefix}_${timestamp}_${random}`;
|
|
28
|
+
}
|
|
29
|
+
function generateDescendingId(prefix = "id") {
|
|
30
|
+
const timestamp = (Number.MAX_SAFE_INTEGER - Date.now()).toString(36);
|
|
31
|
+
const random = Math.random().toString(36).substring(2, 11);
|
|
32
|
+
return `${prefix}_${timestamp}_${random}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/env/environment.ts
|
|
36
|
+
init_decorator();
|
|
37
|
+
import * as fsSync from "fs";
|
|
38
|
+
import * as path from "path";
|
|
39
|
+
var logger = createLogger("environment");
|
|
40
|
+
|
|
41
|
+
class BaseEnvironment extends BaseComponent {
|
|
42
|
+
name;
|
|
43
|
+
version;
|
|
44
|
+
components = new Map;
|
|
45
|
+
constructor(config) {
|
|
46
|
+
super();
|
|
47
|
+
this.name = config?.name ?? "base-environment";
|
|
48
|
+
this.version = config?.version ?? "1.0.0";
|
|
49
|
+
this.registerDefaultComponents();
|
|
50
|
+
}
|
|
51
|
+
registerDefaultComponents() {}
|
|
52
|
+
getConfig() {
|
|
53
|
+
return {
|
|
54
|
+
name: this.name,
|
|
55
|
+
version: this.version,
|
|
56
|
+
enabled: true,
|
|
57
|
+
env: this
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
registerComponent(component) {
|
|
61
|
+
this.components.set(component.name, component);
|
|
62
|
+
logger.debug(`Component registered: ${component.name}`);
|
|
63
|
+
}
|
|
64
|
+
unregisterComponent(name) {
|
|
65
|
+
const component = this.components.get(name);
|
|
66
|
+
if (component) {
|
|
67
|
+
this.components.delete(name);
|
|
68
|
+
logger.debug(`Component unregistered: ${name}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
getComponent(name) {
|
|
72
|
+
return this.components.get(name);
|
|
73
|
+
}
|
|
74
|
+
listComponents() {
|
|
75
|
+
return Array.from(this.components.values());
|
|
76
|
+
}
|
|
77
|
+
async handle_query(query, context) {
|
|
78
|
+
const agentComponent = this.getComponent("agent");
|
|
79
|
+
if (!agentComponent) {
|
|
80
|
+
throw new Error("AgentComponent not found. Please register AgentComponent before calling handle_query.");
|
|
81
|
+
}
|
|
82
|
+
let systemPrompt = "You are a helpful assistant.";
|
|
83
|
+
let promptSource = "fallback";
|
|
84
|
+
try {
|
|
85
|
+
const promptComponent = this.getComponent("prompt");
|
|
86
|
+
if (promptComponent) {
|
|
87
|
+
const loadedPrompt = await promptComponent.getPrompt("default");
|
|
88
|
+
if (loadedPrompt) {
|
|
89
|
+
systemPrompt = loadedPrompt;
|
|
90
|
+
promptSource = "PromptComponent";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} catch (err) {
|
|
94
|
+
logger.warn(`[handle_query] Failed to get prompt from PromptComponent: ${err}`);
|
|
95
|
+
}
|
|
96
|
+
logger.info(`[handle_query] Using system prompt from ${promptSource}, length: ${systemPrompt.length}`);
|
|
97
|
+
let finalSystemPrompt = systemPrompt;
|
|
98
|
+
if (systemPrompt.includes("{{memory}}")) {
|
|
99
|
+
try {
|
|
100
|
+
const memoryComponent = this.getComponent("memory");
|
|
101
|
+
if (memoryComponent) {
|
|
102
|
+
const memoryContent = await memoryComponent.recallMemory();
|
|
103
|
+
finalSystemPrompt = systemPrompt.replace("{{memory}}", memoryContent || "(No memory)");
|
|
104
|
+
logger.info(`[handle_query] Injected memory content, length: ${memoryContent.length}`);
|
|
105
|
+
} else {
|
|
106
|
+
finalSystemPrompt = systemPrompt.replace("{{memory}}", "(Memory component not available)");
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
logger.warn(`[handle_query] Failed to load memory content: ${err}`);
|
|
110
|
+
finalSystemPrompt = systemPrompt.replace("{{memory}}", "(Failed to load memory)");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (finalSystemPrompt.includes("{{workspace_dir}}")) {
|
|
114
|
+
const workspaceDir = process.cwd();
|
|
115
|
+
finalSystemPrompt = finalSystemPrompt.replace("{{workspace_dir}}", workspaceDir);
|
|
116
|
+
logger.debug(`[handle_query] Injected workspace_dir: ${workspaceDir}`);
|
|
117
|
+
}
|
|
118
|
+
const agentName = context?.agentType && context.agentType !== "default" ? context.agentType : "default";
|
|
119
|
+
let agent = agentComponent.getAgent(agentName);
|
|
120
|
+
if (!agent) {
|
|
121
|
+
if (agentName !== "default") {
|
|
122
|
+
logger.warn(`[handle_query] Agent "${agentName}" not found, falling back to "default"`);
|
|
123
|
+
}
|
|
124
|
+
agent = agentComponent.getAgent("default");
|
|
125
|
+
}
|
|
126
|
+
if (!agent) {
|
|
127
|
+
agent = agentComponent.registerAgent("default", {
|
|
128
|
+
type: "primary",
|
|
129
|
+
systemPrompt: finalSystemPrompt
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const result = await agentComponent.run(agent.name, query, context);
|
|
133
|
+
if (result.error) {
|
|
134
|
+
const errorMsg = result.error.toLowerCase();
|
|
135
|
+
if (errorMsg.includes("context") || errorMsg.includes("threshold") || errorMsg.includes("token") || result.error.includes("CTX_001")) {
|
|
136
|
+
const usageMatch = result.error.match(/(\d+)\/(\d+)\s*\(([\d.]+)%\)/);
|
|
137
|
+
let usage;
|
|
138
|
+
let contextWindow;
|
|
139
|
+
if (usageMatch) {
|
|
140
|
+
const totalTokens = parseInt(usageMatch[1], 10);
|
|
141
|
+
usage = {
|
|
142
|
+
promptTokens: totalTokens,
|
|
143
|
+
completionTokens: 0,
|
|
144
|
+
totalTokens
|
|
145
|
+
};
|
|
146
|
+
contextWindow = parseInt(usageMatch[2], 10);
|
|
147
|
+
}
|
|
148
|
+
const ctxError = new ContextError(result.error, ErrorCodes.CONTEXT_THRESHOLD_EXCEEDED, context?.sessionId, usage, contextWindow);
|
|
149
|
+
throw ctxError;
|
|
150
|
+
}
|
|
151
|
+
throw new Error(result.error);
|
|
152
|
+
}
|
|
153
|
+
return result.finalText || "";
|
|
154
|
+
}
|
|
155
|
+
async handle_action(action, context) {
|
|
156
|
+
throw new Error("handle_action not implemented. Override in subclass.");
|
|
157
|
+
}
|
|
158
|
+
eventHandlers = new Map;
|
|
159
|
+
wildcardHandlers = new Set;
|
|
160
|
+
subscribe(handler) {
|
|
161
|
+
this.wildcardHandlers.add(handler);
|
|
162
|
+
logger.debug(`EnvEvent handler subscribed (wildcard)`);
|
|
163
|
+
return () => {
|
|
164
|
+
this.wildcardHandlers.delete(handler);
|
|
165
|
+
logger.debug(`EnvEvent handler unsubscribed (wildcard)`);
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
subscribeTo(eventType, handler) {
|
|
169
|
+
const types = Array.isArray(eventType) ? eventType : [eventType];
|
|
170
|
+
for (const type of types) {
|
|
171
|
+
if (!this.eventHandlers.has(type)) {
|
|
172
|
+
this.eventHandlers.set(type, new Set);
|
|
173
|
+
}
|
|
174
|
+
this.eventHandlers.get(type).add(handler);
|
|
175
|
+
}
|
|
176
|
+
logger.debug(`EnvEvent handler subscribed for types: ${types.join(", ")}`);
|
|
177
|
+
return () => {
|
|
178
|
+
for (const type of types) {
|
|
179
|
+
this.eventHandlers.get(type)?.delete(handler);
|
|
180
|
+
}
|
|
181
|
+
logger.debug(`EnvEvent handler unsubscribed for types: ${types.join(", ")}`);
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
subscribeAll(handler) {
|
|
185
|
+
return this.subscribe(handler);
|
|
186
|
+
}
|
|
187
|
+
pushEnvEvent(event) {
|
|
188
|
+
const fullEvent = "id" in event && event.id ? event : {
|
|
189
|
+
id: event.id ?? generateId(),
|
|
190
|
+
type: event.type,
|
|
191
|
+
timestamp: event.timestamp ?? Date.now(),
|
|
192
|
+
metadata: {
|
|
193
|
+
...event.metadata,
|
|
194
|
+
env_name: event.metadata?.env_name ?? this.name
|
|
195
|
+
},
|
|
196
|
+
payload: event.payload ?? {}
|
|
197
|
+
};
|
|
198
|
+
for (const handler of this.wildcardHandlers) {
|
|
199
|
+
try {
|
|
200
|
+
handler(fullEvent);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
logger.error(`Error in EnvEvent handler: ${error}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const handlers = this.eventHandlers.get(fullEvent.type);
|
|
206
|
+
if (handlers) {
|
|
207
|
+
for (const handler of handlers) {
|
|
208
|
+
try {
|
|
209
|
+
handler(fullEvent);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
logger.error(`Error in EnvEvent handler for ${fullEvent.type}: ${error}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
emit(type, payload, metadata) {
|
|
217
|
+
const event = {
|
|
218
|
+
id: generateId(),
|
|
219
|
+
type,
|
|
220
|
+
timestamp: Date.now(),
|
|
221
|
+
metadata: {
|
|
222
|
+
env_name: this.name,
|
|
223
|
+
...metadata
|
|
224
|
+
},
|
|
225
|
+
payload
|
|
226
|
+
};
|
|
227
|
+
this.pushEnvEvent(event);
|
|
228
|
+
}
|
|
229
|
+
async initializeComponents() {
|
|
230
|
+
logger.debug(`Starting component initialization, total: ${this.components.size}`);
|
|
231
|
+
const configComp = this.components.get("config");
|
|
232
|
+
if (configComp && configComp.getStatus() === "created") {
|
|
233
|
+
logger.debug(`Initializing ConfigComponent first...`);
|
|
234
|
+
await configComp.init({
|
|
235
|
+
name: "config",
|
|
236
|
+
version: configComp.version,
|
|
237
|
+
enabled: true,
|
|
238
|
+
env: this
|
|
239
|
+
});
|
|
240
|
+
logger.debug(`ConfigComponent initialized`);
|
|
241
|
+
} else {
|
|
242
|
+
logger.debug(`No ConfigComponent found, skipping first stage`);
|
|
243
|
+
}
|
|
244
|
+
const otherComponents = Array.from(this.components.values()).filter((c) => c.getStatus() === "created");
|
|
245
|
+
if (otherComponents.length > 0) {
|
|
246
|
+
logger.debug(`Initializing ${otherComponents.length} other components...`);
|
|
247
|
+
for (const component of otherComponents) {
|
|
248
|
+
logger.debug(`Initializing component: ${component.name}`);
|
|
249
|
+
await component.init({
|
|
250
|
+
name: component.name,
|
|
251
|
+
version: component.version,
|
|
252
|
+
enabled: true,
|
|
253
|
+
env: this
|
|
254
|
+
});
|
|
255
|
+
logger.debug(`Component initialized: ${component.name}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
logger.debug(`All components initialized`);
|
|
259
|
+
}
|
|
260
|
+
async startComponents() {
|
|
261
|
+
const allComponents = Array.from(this.components.values());
|
|
262
|
+
if (allComponents.length > 0) {
|
|
263
|
+
logger.debug(`Starting ${allComponents.length} components...`);
|
|
264
|
+
for (const component of allComponents) {
|
|
265
|
+
logger.debug(`Starting component: ${component.name} (current status: ${component.getStatus()})`);
|
|
266
|
+
await component.start();
|
|
267
|
+
logger.debug(`Component started: ${component.name}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async stopComponents() {
|
|
272
|
+
const componentsToStop = Array.from(this.components.values()).filter((c) => c.getStatus() !== "stopped");
|
|
273
|
+
if (componentsToStop.length > 0) {
|
|
274
|
+
logger.debug(`Stopping ${componentsToStop.length} components...`);
|
|
275
|
+
for (const component of componentsToStop) {
|
|
276
|
+
logger.debug(`Stopping component: ${component.name}`);
|
|
277
|
+
await component.stop();
|
|
278
|
+
logger.debug(`Component stopped: ${component.name}`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async onInit() {
|
|
283
|
+
await this.initializeComponents();
|
|
284
|
+
logger.info(`Environment "${this.name}" initialized`);
|
|
285
|
+
}
|
|
286
|
+
async onStart() {
|
|
287
|
+
await this.startComponents();
|
|
288
|
+
logger.info(`Environment "${this.name}" started`);
|
|
289
|
+
}
|
|
290
|
+
async onStop() {
|
|
291
|
+
await this.stopComponents();
|
|
292
|
+
this.eventHandlers.clear();
|
|
293
|
+
this.wildcardHandlers.clear();
|
|
294
|
+
logger.info(`Environment "${this.name}" stopped`);
|
|
295
|
+
}
|
|
296
|
+
async init() {
|
|
297
|
+
Object.defineProperty(this, "env", {
|
|
298
|
+
value: this,
|
|
299
|
+
writable: true,
|
|
300
|
+
enumerable: false,
|
|
301
|
+
configurable: true
|
|
302
|
+
});
|
|
303
|
+
this.setStatus("initializing");
|
|
304
|
+
await this.onInit();
|
|
305
|
+
this.setStatus("running");
|
|
306
|
+
}
|
|
307
|
+
async start() {
|
|
308
|
+
if (this._started)
|
|
309
|
+
return;
|
|
310
|
+
this._started = true;
|
|
311
|
+
await this.onStart();
|
|
312
|
+
this.setStatus("running");
|
|
313
|
+
logger.info(`Environment "${this.name}" started`);
|
|
314
|
+
}
|
|
315
|
+
async stop() {
|
|
316
|
+
this.setStatus("stopping");
|
|
317
|
+
await this.onStop();
|
|
318
|
+
this.setStatus("stopped");
|
|
319
|
+
}
|
|
320
|
+
async loadServiceConfig(configPath) {
|
|
321
|
+
const configComponent = this.getComponent("config");
|
|
322
|
+
if (!configComponent) {
|
|
323
|
+
throw new Error("ConfigComponent not found. Please register ConfigComponent before loading service config.");
|
|
324
|
+
}
|
|
325
|
+
const xdgDataHome = configComponent.getXdgDataHome();
|
|
326
|
+
const fullPath = path.resolve(xdgDataHome, configPath);
|
|
327
|
+
if (!fsSync.existsSync(fullPath)) {
|
|
328
|
+
throw new Error(`Service config file not found: ${fullPath}`);
|
|
329
|
+
}
|
|
330
|
+
const content = fsSync.readFileSync(fullPath, "utf-8");
|
|
331
|
+
let config;
|
|
332
|
+
try {
|
|
333
|
+
config = JSON.parse(content);
|
|
334
|
+
} catch (e) {
|
|
335
|
+
throw new Error(`Failed to parse service config: ${e}`);
|
|
336
|
+
}
|
|
337
|
+
logger.debug(`Service config loaded from: ${fullPath}`);
|
|
338
|
+
return config;
|
|
339
|
+
}
|
|
340
|
+
generateComponentOptions(componentName, configEntry) {
|
|
341
|
+
const configComponent = this.getComponent("config");
|
|
342
|
+
if (!configComponent) {
|
|
343
|
+
throw new Error("ConfigComponent not found. Please register ConfigComponent before generating component options.");
|
|
344
|
+
}
|
|
345
|
+
const options = {
|
|
346
|
+
configComponent,
|
|
347
|
+
configPath: configEntry.configPath,
|
|
348
|
+
envPrefix: configEntry.envPrefix,
|
|
349
|
+
config: configEntry.config
|
|
350
|
+
};
|
|
351
|
+
logger.debug(`Generated options for component: ${componentName}`);
|
|
352
|
+
return options;
|
|
353
|
+
}
|
|
354
|
+
async registerComponentWithConfig(component, configEntry) {
|
|
355
|
+
if (!this.components.has(component.name)) {
|
|
356
|
+
this.registerComponent(component);
|
|
357
|
+
}
|
|
358
|
+
const options = this.generateComponentOptions(component.name, configEntry);
|
|
359
|
+
if (component.getStatus() === "running") {
|
|
360
|
+
logger.debug(`Component ${component.name} already initialized, skipping`);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
await component.init({
|
|
364
|
+
name: component.name,
|
|
365
|
+
version: component.version,
|
|
366
|
+
enabled: configEntry.enabled ?? true,
|
|
367
|
+
env: this,
|
|
368
|
+
options
|
|
369
|
+
});
|
|
370
|
+
logger.debug(`Component ${component.name} registered and initialized with config`);
|
|
371
|
+
}
|
|
372
|
+
async initFromConfig(configPath) {
|
|
373
|
+
if (!this.env) {
|
|
374
|
+
Object.defineProperty(this, "env", {
|
|
375
|
+
value: this,
|
|
376
|
+
writable: true,
|
|
377
|
+
enumerable: false,
|
|
378
|
+
configurable: true
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
const serviceConfig = await this.loadServiceConfig(configPath);
|
|
382
|
+
if (serviceConfig.environment) {
|
|
383
|
+
if (serviceConfig.environment.name) {
|
|
384
|
+
this.name = serviceConfig.environment.name;
|
|
385
|
+
}
|
|
386
|
+
if (serviceConfig.environment.version) {
|
|
387
|
+
this.version = serviceConfig.environment.version;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const configComponent = this.getComponent("config");
|
|
391
|
+
if (!configComponent) {
|
|
392
|
+
throw new Error("ConfigComponent not found. Please register ConfigComponent before initFromConfig.");
|
|
393
|
+
}
|
|
394
|
+
if (configComponent.getStatus() === "created") {
|
|
395
|
+
await configComponent.init({
|
|
396
|
+
name: "config",
|
|
397
|
+
version: configComponent.version,
|
|
398
|
+
enabled: true,
|
|
399
|
+
env: this
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
const components = serviceConfig.components || {};
|
|
403
|
+
for (const [componentName, configEntry] of Object.entries(components)) {
|
|
404
|
+
if (configEntry.enabled === false) {
|
|
405
|
+
logger.debug(`Component ${componentName} is disabled, skipping`);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
const component = this.getComponent(componentName);
|
|
409
|
+
if (!component) {
|
|
410
|
+
logger.warn(`Component ${componentName} not registered, skipping`);
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (component.name === "config")
|
|
414
|
+
continue;
|
|
415
|
+
await this.registerComponentWithConfig(component, configEntry);
|
|
416
|
+
}
|
|
417
|
+
this.setStatus("running");
|
|
418
|
+
logger.info(`Environment "${this.name}" initialized from config: ${configPath}`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
__legacyDecorateClassTS([
|
|
422
|
+
TracedAs("env.handle_query", { recordParams: true, recordResult: true, log: true })
|
|
423
|
+
], BaseEnvironment.prototype, "handle_query", null);
|
|
424
|
+
export { generateId, generateDescendingId, BaseEnvironment };
|
|
@@ -142,7 +142,7 @@ Options:
|
|
|
142
142
|
-s, --session <id> Specify session ID
|
|
143
143
|
--model <model> Use specific model
|
|
144
144
|
-C, --config <path> Config file path
|
|
145
|
-
-q, --quiet
|
|
145
|
+
-q, --no-quiet Enable logging (default: quiet mode is on)
|
|
146
146
|
-r, --reasoning Show AI reasoning process
|
|
147
147
|
--tool-calls Show tool calls
|
|
148
148
|
--tool-results Show tool execution results
|
|
@@ -1490,7 +1490,7 @@ var init_engine = __esm(() => {
|
|
|
1490
1490
|
}
|
|
1491
1491
|
}
|
|
1492
1492
|
const messages = this.sessionComponent ? await this.sessionComponent.getMessages(sessionId) : [];
|
|
1493
|
-
const { inferNextNode } = await import("./roy-agent-core-
|
|
1493
|
+
const { inferNextNode } = await import("./roy-agent-core-ffb9fq4v.js");
|
|
1494
1494
|
const entry = workflowDef.entry;
|
|
1495
1495
|
const entryNode = Array.isArray(entry) ? entry[0] : entry;
|
|
1496
1496
|
const resumePoint = inferNextNode(messages, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-setting/roy-agent-core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,38 +27,23 @@
|
|
|
27
27
|
"dist",
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "bunup",
|
|
32
|
+
"build:main": "bunup -- --entry src/index.ts",
|
|
33
|
+
"clean": "rm -rf dist",
|
|
34
|
+
"typecheck": "npx tsc --noEmit --skipLibCheck --project tsconfig.json"
|
|
35
|
+
},
|
|
30
36
|
"dependencies": {
|
|
31
37
|
"@ai-sdk/anthropic": "^3.0.0",
|
|
32
38
|
"@ai-sdk/google": "^3.0.0",
|
|
33
39
|
"@ai-sdk/openai": "^3.0.0",
|
|
34
40
|
"@ai-sdk/openai-compatible": "^2.0.0",
|
|
35
|
-
"@hono/node-server": "^2.0.2",
|
|
36
41
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
37
42
|
"ai": "^6.0.0",
|
|
38
|
-
"ajv": "^8.20.0",
|
|
39
|
-
"ajv-formats": "^3.0.1",
|
|
40
43
|
"better-sqlite3": "^11.10.0",
|
|
41
|
-
"content-type": "^2.0.0",
|
|
42
|
-
"cors": "^2.8.6",
|
|
43
|
-
"deep-equal": "^2.2.3",
|
|
44
|
-
"eventsource": "^4.1.0",
|
|
45
|
-
"express": "^5.2.1",
|
|
46
|
-
"express-rate-limit": "^8.5.1",
|
|
47
|
-
"fast-deep-equal": "^3.1.3",
|
|
48
|
-
"fast-uri": "^3.1.2",
|
|
49
44
|
"glob": "^13.0.6",
|
|
50
|
-
"hono": "^4.12.18",
|
|
51
|
-
"jose": "^6.2.3",
|
|
52
|
-
"json-schema-traverse": "^1.0.0",
|
|
53
|
-
"json-schema-typed": "^8.0.2",
|
|
54
45
|
"jsonc-parser": "^3.2.0",
|
|
55
|
-
"pkce-challenge": "^6.0.0",
|
|
56
|
-
"punycode": "^2.3.1",
|
|
57
|
-
"raw-body": "^3.0.2",
|
|
58
46
|
"reflect-metadata": "^0.2.2",
|
|
59
|
-
"require-from-string": "^2.0.2",
|
|
60
|
-
"uri-js": "^4.4.1",
|
|
61
|
-
"which": "^7.0.0",
|
|
62
47
|
"ws": "^8.16.0",
|
|
63
48
|
"xdg-basedir": "^5.1.0",
|
|
64
49
|
"yaml": "^2.3.0",
|
|
@@ -94,11 +79,5 @@
|
|
|
94
79
|
"license": "MIT",
|
|
95
80
|
"bugs": {
|
|
96
81
|
"url": "https://github.com/ai-setting/roy-agent/issues"
|
|
97
|
-
},
|
|
98
|
-
"scripts": {
|
|
99
|
-
"build": "bunup",
|
|
100
|
-
"build:main": "bunup -- --entry src/index.ts",
|
|
101
|
-
"clean": "rm -rf dist",
|
|
102
|
-
"typecheck": "npx tsc --noEmit --skipLibCheck --project tsconfig.json"
|
|
103
82
|
}
|
|
104
|
-
}
|
|
83
|
+
}
|