@ai-setting/roy-agent-core 1.4.10 → 1.4.12
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 +23 -0
- package/dist/env/agent/index.js +3035 -0
- package/dist/env/commands/index.js +1685 -0
- package/dist/env/debug/formatters/index.js +639 -0
- package/dist/env/debug/index.js +2300 -0
- package/dist/env/hook/index.js +273 -0
- package/dist/env/index.js +12591 -0
- package/dist/env/llm/index.js +2736 -0
- package/dist/env/log-trace/index.js +1779 -0
- package/dist/env/mcp/index.js +2173 -0
- package/dist/env/mcp/tool/index.js +1149 -0
- package/dist/env/memory/built-in/index.js +225 -0
- package/dist/env/memory/index.js +2171 -0
- package/dist/env/memory/plugin/index.js +1263 -0
- package/dist/env/prompt/index.js +2107 -0
- package/dist/env/session/index.js +3594 -0
- package/dist/env/session/storage/index.js +2049 -0
- package/dist/env/skill/index.js +1635 -0
- package/dist/env/skill/tool/index.js +114 -0
- package/dist/env/task/delegate/index.js +1844 -0
- package/dist/env/task/hooks/index.js +67 -0
- package/dist/env/task/index.js +3578 -0
- package/dist/env/task/plugins/index.js +1626 -0
- package/dist/env/task/storage/index.js +1464 -0
- package/dist/env/task/tools/index.js +344 -0
- package/dist/env/task/tools/operation/index.js +270 -0
- package/dist/env/tool/built-in/index.js +1151 -0
- package/dist/env/tool/index.js +2284 -0
- package/dist/env/workflow/decorators/index.js +449 -0
- package/dist/env/workflow/engine/index.js +4391 -0
- package/dist/env/workflow/index.js +6214 -0
- package/dist/env/workflow/nodes/index.js +650 -0
- package/dist/env/workflow/service/index.js +262 -0
- package/dist/env/workflow/storage/index.js +1236 -0
- package/dist/env/workflow/tools/index.js +1081 -0
- package/dist/env/workflow/types/index.js +479 -0
- package/dist/env/workflow/utils/index.js +1631 -0
- package/dist/index.js +15006 -14265
- package/package.json +2 -2
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
function __accessProp(key) {
|
|
7
|
+
return this[key];
|
|
8
|
+
}
|
|
9
|
+
var __toCommonJS = (from) => {
|
|
10
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
11
|
+
if (entry)
|
|
12
|
+
return entry;
|
|
13
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (var key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(entry, key))
|
|
17
|
+
__defProp(entry, key, {
|
|
18
|
+
get: __accessProp.bind(from, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
__moduleCache.set(from, entry);
|
|
23
|
+
return entry;
|
|
24
|
+
};
|
|
25
|
+
var __moduleCache;
|
|
26
|
+
var __returnValue = (v) => v;
|
|
27
|
+
function __exportSetter(name, newValue) {
|
|
28
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
29
|
+
}
|
|
30
|
+
var __export = (target, all) => {
|
|
31
|
+
for (var name in all)
|
|
32
|
+
__defProp(target, name, {
|
|
33
|
+
get: all[name],
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
set: __exportSetter.bind(all, name)
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
40
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
41
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
42
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
43
|
+
else
|
|
44
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
45
|
+
if (d = decorators[i])
|
|
46
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
47
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
48
|
+
};
|
|
49
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
50
|
+
var __require = import.meta.require;
|
|
51
|
+
|
|
52
|
+
// packages/core/src/env/hook/types.ts
|
|
53
|
+
function createHook(meta, fn) {
|
|
54
|
+
return {
|
|
55
|
+
...meta,
|
|
56
|
+
execute: fn
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function createPriorityHook(name, fn, priority) {
|
|
60
|
+
return createHook({ name, priority }, fn);
|
|
61
|
+
}
|
|
62
|
+
// packages/core/src/env/hook/hook-manager.ts
|
|
63
|
+
class HookManager {
|
|
64
|
+
_hooks = new Map;
|
|
65
|
+
componentName;
|
|
66
|
+
componentVersion;
|
|
67
|
+
defaultPriority;
|
|
68
|
+
constructor(options = {}) {
|
|
69
|
+
this.componentName = options.componentName ?? "unknown";
|
|
70
|
+
this.componentVersion = options.componentVersion ?? "0.0.0";
|
|
71
|
+
this.defaultPriority = options.defaultPriority ?? 0;
|
|
72
|
+
}
|
|
73
|
+
register(hookPoint, hook) {
|
|
74
|
+
const hooks = this.getOrCreateHooks(hookPoint);
|
|
75
|
+
hooks.push(hook);
|
|
76
|
+
}
|
|
77
|
+
registerMany(hookPoint, hooks) {
|
|
78
|
+
const hookList = this.getOrCreateHooks(hookPoint);
|
|
79
|
+
hookList.push(...hooks);
|
|
80
|
+
}
|
|
81
|
+
unregister(hookPoint, name) {
|
|
82
|
+
const hooks = this._hooks.get(hookPoint);
|
|
83
|
+
if (!hooks)
|
|
84
|
+
return false;
|
|
85
|
+
const index = hooks.findIndex((h) => h.name === name);
|
|
86
|
+
if (index === -1)
|
|
87
|
+
return false;
|
|
88
|
+
hooks.splice(index, 1);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
unregisterAll(hookPoint) {
|
|
92
|
+
this._hooks.delete(hookPoint);
|
|
93
|
+
}
|
|
94
|
+
async execute(hookPoint, data, metadata = {}) {
|
|
95
|
+
const hooks = this._hooks.get(hookPoint);
|
|
96
|
+
if (!hooks || hooks.length === 0)
|
|
97
|
+
return;
|
|
98
|
+
const sortedHooks = this.sortHooks(hooks);
|
|
99
|
+
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
100
|
+
for (const hook of sortedHooks) {
|
|
101
|
+
await this.safeExecute(hook, ctx);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async executeAndCollect(hookPoint, data, metadata = {}) {
|
|
105
|
+
const hooks = this._hooks.get(hookPoint);
|
|
106
|
+
if (!hooks || hooks.length === 0)
|
|
107
|
+
return [];
|
|
108
|
+
const sortedHooks = this.sortHooks(hooks);
|
|
109
|
+
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
110
|
+
const results = [];
|
|
111
|
+
for (const hook of sortedHooks) {
|
|
112
|
+
const result = await this.safeExecuteAndReturn(hook, ctx);
|
|
113
|
+
if (result !== undefined) {
|
|
114
|
+
results.push(result);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return results;
|
|
118
|
+
}
|
|
119
|
+
count(hookPoint) {
|
|
120
|
+
return this._hooks.get(hookPoint)?.length ?? 0;
|
|
121
|
+
}
|
|
122
|
+
clear() {
|
|
123
|
+
this._hooks.clear();
|
|
124
|
+
}
|
|
125
|
+
getHookPoints() {
|
|
126
|
+
return Array.from(this._hooks.keys());
|
|
127
|
+
}
|
|
128
|
+
hasHooks(hookPoint) {
|
|
129
|
+
return this.count(hookPoint) > 0;
|
|
130
|
+
}
|
|
131
|
+
setComponentInfo(name, version) {
|
|
132
|
+
this.componentName = name;
|
|
133
|
+
this.componentVersion = version;
|
|
134
|
+
}
|
|
135
|
+
get hooks() {
|
|
136
|
+
return this._hooks;
|
|
137
|
+
}
|
|
138
|
+
async executeWithIntervention(hookPoint, data, metadata = {}) {
|
|
139
|
+
const hooks = this._hooks.get(hookPoint);
|
|
140
|
+
if (!hooks || hooks.length === 0) {
|
|
141
|
+
return { stopped: false, results: [] };
|
|
142
|
+
}
|
|
143
|
+
const sortedHooks = this.sortHooks(hooks);
|
|
144
|
+
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
145
|
+
const results = [];
|
|
146
|
+
let stopped = false;
|
|
147
|
+
let action;
|
|
148
|
+
for (const hook of sortedHooks) {
|
|
149
|
+
if (stopped)
|
|
150
|
+
break;
|
|
151
|
+
const result = await this.safeExecuteAndReturn(hook, ctx);
|
|
152
|
+
results.push(result);
|
|
153
|
+
if (result && typeof result === "object" && "stopped" in result) {
|
|
154
|
+
const hookResult = result;
|
|
155
|
+
if (hookResult.stopped) {
|
|
156
|
+
stopped = true;
|
|
157
|
+
action = hookResult.action;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return { stopped, action, results };
|
|
162
|
+
}
|
|
163
|
+
getOrCreateHooks(hookPoint) {
|
|
164
|
+
let hooks = this._hooks.get(hookPoint);
|
|
165
|
+
if (!hooks) {
|
|
166
|
+
hooks = [];
|
|
167
|
+
this._hooks.set(hookPoint, hooks);
|
|
168
|
+
}
|
|
169
|
+
return hooks;
|
|
170
|
+
}
|
|
171
|
+
sortHooks(hooks) {
|
|
172
|
+
return [...hooks].sort((a, b) => {
|
|
173
|
+
const priorityA = a.priority ?? this.defaultPriority;
|
|
174
|
+
const priorityB = b.priority ?? this.defaultPriority;
|
|
175
|
+
return priorityA - priorityB;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
createContext(hookPoint, data, metadata, phase) {
|
|
179
|
+
return {
|
|
180
|
+
component: {
|
|
181
|
+
name: this.componentName,
|
|
182
|
+
version: this.componentVersion
|
|
183
|
+
},
|
|
184
|
+
data,
|
|
185
|
+
metadata,
|
|
186
|
+
phase,
|
|
187
|
+
hookPoint
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
async safeExecute(hook, ctx) {
|
|
191
|
+
try {
|
|
192
|
+
await hook.execute(ctx);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.error(`Hook "${hook.name}" failed:`, error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async safeExecuteAndReturn(hook, ctx) {
|
|
198
|
+
try {
|
|
199
|
+
return await hook.execute(ctx);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error(`Hook "${hook.name}" failed:`, error);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// packages/core/src/env/hook/global-hook-manager.ts
|
|
207
|
+
var globalHookManager = new HookManager;
|
|
208
|
+
var AgentHookPoints = {
|
|
209
|
+
BEFORE_START: "agent:before.start",
|
|
210
|
+
BEFORE_LLM: "agent:before.llm",
|
|
211
|
+
AFTER_LLM: "agent:after.llm",
|
|
212
|
+
BEFORE_TOOL: "agent:before.tool",
|
|
213
|
+
AFTER_TOOL: "agent:after.tool",
|
|
214
|
+
ON_ITERATION: "agent:on.iteration",
|
|
215
|
+
ON_THRESHOLD: "agent:on.threshold",
|
|
216
|
+
AFTER_COMPLETE: "agent:after.complete",
|
|
217
|
+
ON_ERROR: "agent:on.error"
|
|
218
|
+
};
|
|
219
|
+
var LLMHookPoints = {
|
|
220
|
+
BEFORE_INVOKE: "llm:before.invoke",
|
|
221
|
+
AFTER_INVOKE: "llm:after.invoke",
|
|
222
|
+
ON_STREAM: "llm:on.stream"
|
|
223
|
+
};
|
|
224
|
+
var ToolHookPoints = {
|
|
225
|
+
BEFORE_EXECUTE: "tool:before.execute",
|
|
226
|
+
AFTER_EXECUTE: "tool:after.execute",
|
|
227
|
+
BEFORE_REGISTER: "tool:before.register",
|
|
228
|
+
AFTER_REGISTER: "tool:after.register",
|
|
229
|
+
ON_ERROR: "tool:on.error"
|
|
230
|
+
};
|
|
231
|
+
var hookPointAliases = {
|
|
232
|
+
"before.tool": "tool:before.execute",
|
|
233
|
+
"after.tool": "tool:after.execute",
|
|
234
|
+
"llm.before-invoke": "llm:before.invoke",
|
|
235
|
+
"llm.after-invoke": "llm:after.invoke",
|
|
236
|
+
"llm.stream": "llm:on.stream"
|
|
237
|
+
};
|
|
238
|
+
function setupAliasHooks() {
|
|
239
|
+
const originalRegister = globalHookManager.register.bind(globalHookManager);
|
|
240
|
+
globalHookManager.register = function(hookPoint, hook) {
|
|
241
|
+
originalRegister(hookPoint, hook);
|
|
242
|
+
const alias = hookPointAliases[hookPoint];
|
|
243
|
+
if (alias) {
|
|
244
|
+
originalRegister(alias, hook);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
setupAliasHooks();
|
|
249
|
+
async function executeAgentHook(hookPoint, data, metadata = {}) {
|
|
250
|
+
await globalHookManager.execute(hookPoint, data, metadata);
|
|
251
|
+
}
|
|
252
|
+
async function executeAgentHookWithIntervention(hookPoint, data, metadata = {}) {
|
|
253
|
+
return globalHookManager.executeWithIntervention(hookPoint, data, metadata);
|
|
254
|
+
}
|
|
255
|
+
async function executeLLMHook(hookPoint, data, metadata = {}) {
|
|
256
|
+
await globalHookManager.execute(hookPoint, data, metadata);
|
|
257
|
+
}
|
|
258
|
+
async function executeToolHook(hookPoint, data, metadata = {}) {
|
|
259
|
+
await globalHookManager.execute(hookPoint, data, metadata);
|
|
260
|
+
}
|
|
261
|
+
export {
|
|
262
|
+
globalHookManager,
|
|
263
|
+
executeToolHook,
|
|
264
|
+
executeLLMHook,
|
|
265
|
+
executeAgentHookWithIntervention,
|
|
266
|
+
executeAgentHook,
|
|
267
|
+
createPriorityHook,
|
|
268
|
+
createHook,
|
|
269
|
+
ToolHookPoints,
|
|
270
|
+
LLMHookPoints,
|
|
271
|
+
HookManager,
|
|
272
|
+
AgentHookPoints
|
|
273
|
+
};
|