@ai-setting/roy-agent-core 1.5.14-test → 1.5.15-test
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/package.json +1 -1
- package/dist/config/index.d.ts +0 -1250
- package/dist/config/index.js +0 -32
- package/dist/env/agent/index.d.ts +0 -2279
- package/dist/env/agent/index.js +0 -24
- package/dist/env/commands/index.d.ts +0 -1131
- package/dist/env/commands/index.js +0 -14
- package/dist/env/debug/formatters/index.d.ts +0 -236
- package/dist/env/debug/formatters/index.js +0 -11
- package/dist/env/debug/index.d.ts +0 -1652
- package/dist/env/debug/index.js +0 -26
- package/dist/env/hook/index.d.ts +0 -279
- package/dist/env/hook/index.js +0 -29
- package/dist/env/index.d.ts +0 -3481
- package/dist/env/index.js +0 -82
- package/dist/env/llm/index.d.ts +0 -1760
- package/dist/env/llm/index.js +0 -40
- package/dist/env/log-trace/index.d.ts +0 -1574
- package/dist/env/log-trace/index.js +0 -83
- package/dist/env/mcp/index.d.ts +0 -1331
- package/dist/env/mcp/index.js +0 -39
- package/dist/env/mcp/tool/index.d.ts +0 -183
- package/dist/env/mcp/tool/index.js +0 -14
- package/dist/env/memory/built-in/index.d.ts +0 -232
- package/dist/env/memory/built-in/index.js +0 -11
- package/dist/env/memory/index.d.ts +0 -1799
- package/dist/env/memory/index.js +0 -56
- package/dist/env/memory/plugin/index.d.ts +0 -747
- package/dist/env/memory/plugin/index.js +0 -36
- package/dist/env/prompt/index.d.ts +0 -1164
- package/dist/env/prompt/index.js +0 -20
- package/dist/env/session/index.d.ts +0 -1908
- package/dist/env/session/index.js +0 -25
- package/dist/env/session/storage/index.d.ts +0 -564
- package/dist/env/session/storage/index.js +0 -18
- package/dist/env/skill/index.d.ts +0 -1266
- package/dist/env/skill/index.js +0 -34
- package/dist/env/skill/tool/index.d.ts +0 -193
- package/dist/env/skill/tool/index.js +0 -9
- package/dist/env/task/delegate/index.d.ts +0 -1612
- package/dist/env/task/delegate/index.js +0 -18
- package/dist/env/task/events/index.d.ts +0 -171
- package/dist/env/task/events/index.js +0 -7
- package/dist/env/task/hooks/index.d.ts +0 -624
- package/dist/env/task/hooks/index.js +0 -7
- package/dist/env/task/index.d.ts +0 -1553
- package/dist/env/task/index.js +0 -34
- package/dist/env/task/plugins/index.d.ts +0 -466
- package/dist/env/task/plugins/index.js +0 -23
- package/dist/env/task/storage/index.d.ts +0 -241
- package/dist/env/task/storage/index.js +0 -14
- package/dist/env/task/tools/index.d.ts +0 -1485
- package/dist/env/task/tools/index.js +0 -17
- package/dist/env/task/tools/operation/index.d.ts +0 -1484
- package/dist/env/task/tools/operation/index.js +0 -15
- package/dist/env/tool/built-in/index.d.ts +0 -218
- package/dist/env/tool/built-in/index.js +0 -25
- package/dist/env/tool/index.d.ts +0 -1396
- package/dist/env/tool/index.js +0 -39
- package/dist/env/workflow/decorators/index.d.ts +0 -2161
- package/dist/env/workflow/decorators/index.js +0 -27
- package/dist/env/workflow/engine/index.d.ts +0 -3453
- package/dist/env/workflow/engine/index.js +0 -28
- package/dist/env/workflow/index.d.ts +0 -3546
- package/dist/env/workflow/index.js +0 -136
- package/dist/env/workflow/nodes/index.d.ts +0 -2092
- package/dist/env/workflow/nodes/index.js +0 -19
- package/dist/env/workflow/service/index.d.ts +0 -227
- package/dist/env/workflow/service/index.js +0 -13
- package/dist/env/workflow/storage/index.d.ts +0 -165
- package/dist/env/workflow/storage/index.js +0 -27
- package/dist/env/workflow/tools/index.d.ts +0 -416
- package/dist/env/workflow/tools/index.js +0 -159
- package/dist/env/workflow/types/index.d.ts +0 -2255
- package/dist/env/workflow/types/index.js +0 -98
- package/dist/env/workflow/utils/index.d.ts +0 -2031
- package/dist/env/workflow/utils/index.js +0 -637
- package/dist/index.d.ts +0 -7858
- package/dist/index.js +0 -399
- package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +0 -258
- package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
- package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +0 -349
- package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +0 -117
- package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +0 -11
- package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +0 -393
- package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +0 -200
- package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +0 -299
- package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
- package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +0 -393
- package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +0 -350
- package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +0 -180
- package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +0 -408
- package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +0 -284
- package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +0 -762
- package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +0 -10
- package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +0 -14
- package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +0 -922
- package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +0 -15
- package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +0 -1130
- package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
- package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +0 -653
- package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +0 -93
- package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +0 -872
- package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
- package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +0 -64
- package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +0 -378
- package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +0 -492
- package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +0 -52
- package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +0 -171
- package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +0 -862
- package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +0 -1387
- package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +0 -208
- package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +0 -139
- package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +0 -534
- package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +0 -204
- package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +0 -603
- package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +0 -97
- package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +0 -587
- package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +0 -176
- package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +0 -60
- package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +0 -442
- package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +0 -57
- package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +0 -66
- package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +0 -10
- package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +0 -267
- package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +0 -584
- package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +0 -102
- package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +0 -549
- package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +0 -15
- package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
- package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +0 -812
- package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +0 -1316
- package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +0 -1205
- package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +0 -328
- package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +0 -20
- package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +0 -2098
- package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +0 -419
- package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +0 -368
- package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +0 -377
- package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +0 -172
- package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +0 -103
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
// src/env/hook/hook-manager.ts
|
|
2
|
-
class HookManager {
|
|
3
|
-
_hooks = new Map;
|
|
4
|
-
componentName;
|
|
5
|
-
componentVersion;
|
|
6
|
-
defaultPriority;
|
|
7
|
-
constructor(options = {}) {
|
|
8
|
-
this.componentName = options.componentName ?? "unknown";
|
|
9
|
-
this.componentVersion = options.componentVersion ?? "0.0.0";
|
|
10
|
-
this.defaultPriority = options.defaultPriority ?? 0;
|
|
11
|
-
}
|
|
12
|
-
register(hookPoint, hook) {
|
|
13
|
-
const hooks = this.getOrCreateHooks(hookPoint);
|
|
14
|
-
hooks.push(hook);
|
|
15
|
-
}
|
|
16
|
-
registerMany(hookPoint, hooks) {
|
|
17
|
-
const hookList = this.getOrCreateHooks(hookPoint);
|
|
18
|
-
hookList.push(...hooks);
|
|
19
|
-
}
|
|
20
|
-
unregister(hookPoint, name) {
|
|
21
|
-
const hooks = this._hooks.get(hookPoint);
|
|
22
|
-
if (!hooks)
|
|
23
|
-
return false;
|
|
24
|
-
const index = hooks.findIndex((h) => h.name === name);
|
|
25
|
-
if (index === -1)
|
|
26
|
-
return false;
|
|
27
|
-
hooks.splice(index, 1);
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
unregisterAll(hookPoint) {
|
|
31
|
-
this._hooks.delete(hookPoint);
|
|
32
|
-
}
|
|
33
|
-
async execute(hookPoint, data, metadata = {}) {
|
|
34
|
-
const hooks = this._hooks.get(hookPoint);
|
|
35
|
-
if (!hooks || hooks.length === 0)
|
|
36
|
-
return;
|
|
37
|
-
const sortedHooks = this.sortHooks(hooks);
|
|
38
|
-
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
39
|
-
for (const hook of sortedHooks) {
|
|
40
|
-
await this.safeExecute(hook, ctx);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async executeAndCollect(hookPoint, data, metadata = {}) {
|
|
44
|
-
const hooks = this._hooks.get(hookPoint);
|
|
45
|
-
if (!hooks || hooks.length === 0)
|
|
46
|
-
return [];
|
|
47
|
-
const sortedHooks = this.sortHooks(hooks);
|
|
48
|
-
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
49
|
-
const results = [];
|
|
50
|
-
for (const hook of sortedHooks) {
|
|
51
|
-
const result = await this.safeExecuteAndReturn(hook, ctx);
|
|
52
|
-
if (result !== undefined) {
|
|
53
|
-
results.push(result);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return results;
|
|
57
|
-
}
|
|
58
|
-
count(hookPoint) {
|
|
59
|
-
return this._hooks.get(hookPoint)?.length ?? 0;
|
|
60
|
-
}
|
|
61
|
-
clear() {
|
|
62
|
-
this._hooks.clear();
|
|
63
|
-
}
|
|
64
|
-
getHookPoints() {
|
|
65
|
-
return Array.from(this._hooks.keys());
|
|
66
|
-
}
|
|
67
|
-
hasHooks(hookPoint) {
|
|
68
|
-
return this.count(hookPoint) > 0;
|
|
69
|
-
}
|
|
70
|
-
setComponentInfo(name, version) {
|
|
71
|
-
this.componentName = name;
|
|
72
|
-
this.componentVersion = version;
|
|
73
|
-
}
|
|
74
|
-
get hooks() {
|
|
75
|
-
return this._hooks;
|
|
76
|
-
}
|
|
77
|
-
async executeWithIntervention(hookPoint, data, metadata = {}) {
|
|
78
|
-
const hooks = this._hooks.get(hookPoint);
|
|
79
|
-
if (!hooks || hooks.length === 0) {
|
|
80
|
-
return { stopped: false, results: [] };
|
|
81
|
-
}
|
|
82
|
-
const sortedHooks = this.sortHooks(hooks);
|
|
83
|
-
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
84
|
-
const results = [];
|
|
85
|
-
let stopped = false;
|
|
86
|
-
let action;
|
|
87
|
-
for (const hook of sortedHooks) {
|
|
88
|
-
if (stopped)
|
|
89
|
-
break;
|
|
90
|
-
const result = await this.safeExecuteAndReturn(hook, ctx);
|
|
91
|
-
results.push(result);
|
|
92
|
-
if (result && typeof result === "object" && "stopped" in result) {
|
|
93
|
-
const hookResult = result;
|
|
94
|
-
if (hookResult.stopped) {
|
|
95
|
-
stopped = true;
|
|
96
|
-
action = hookResult.action;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return { stopped, action, results };
|
|
101
|
-
}
|
|
102
|
-
getOrCreateHooks(hookPoint) {
|
|
103
|
-
let hooks = this._hooks.get(hookPoint);
|
|
104
|
-
if (!hooks) {
|
|
105
|
-
hooks = [];
|
|
106
|
-
this._hooks.set(hookPoint, hooks);
|
|
107
|
-
}
|
|
108
|
-
return hooks;
|
|
109
|
-
}
|
|
110
|
-
sortHooks(hooks) {
|
|
111
|
-
return [...hooks].sort((a, b) => {
|
|
112
|
-
const priorityA = a.priority ?? this.defaultPriority;
|
|
113
|
-
const priorityB = b.priority ?? this.defaultPriority;
|
|
114
|
-
return priorityA - priorityB;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
createContext(hookPoint, data, metadata, phase) {
|
|
118
|
-
return {
|
|
119
|
-
component: {
|
|
120
|
-
name: this.componentName,
|
|
121
|
-
version: this.componentVersion
|
|
122
|
-
},
|
|
123
|
-
data,
|
|
124
|
-
metadata,
|
|
125
|
-
phase,
|
|
126
|
-
hookPoint
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
async safeExecute(hook, ctx) {
|
|
130
|
-
try {
|
|
131
|
-
await hook.execute(ctx);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
console.error(`Hook "${hook.name}" failed:`, error);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async safeExecuteAndReturn(hook, ctx) {
|
|
137
|
-
try {
|
|
138
|
-
return await hook.execute(ctx);
|
|
139
|
-
} catch (error) {
|
|
140
|
-
console.error(`Hook "${hook.name}" failed:`, error);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// src/env/hook/global-hook-manager.ts
|
|
147
|
-
var globalHookManager = new HookManager;
|
|
148
|
-
var AgentHookPoints = {
|
|
149
|
-
BEFORE_START: "agent:before.start",
|
|
150
|
-
BEFORE_LLM: "agent:before.llm",
|
|
151
|
-
AFTER_LLM: "agent:after.llm",
|
|
152
|
-
BEFORE_TOOL: "agent:before.tool",
|
|
153
|
-
AFTER_TOOL: "agent:after.tool",
|
|
154
|
-
ON_ITERATION: "agent:on.iteration",
|
|
155
|
-
ON_THRESHOLD: "agent:on.threshold",
|
|
156
|
-
AFTER_COMPLETE: "agent:after.complete",
|
|
157
|
-
ON_ERROR: "agent:on.error"
|
|
158
|
-
};
|
|
159
|
-
var LLMHookPoints = {
|
|
160
|
-
BEFORE_INVOKE: "llm:before.invoke",
|
|
161
|
-
AFTER_INVOKE: "llm:after.invoke",
|
|
162
|
-
ON_STREAM: "llm:on.stream"
|
|
163
|
-
};
|
|
164
|
-
var ToolHookPoints = {
|
|
165
|
-
BEFORE_EXECUTE: "tool:before.execute",
|
|
166
|
-
AFTER_EXECUTE: "tool:after.execute",
|
|
167
|
-
BEFORE_REGISTER: "tool:before.register",
|
|
168
|
-
AFTER_REGISTER: "tool:after.register",
|
|
169
|
-
ON_ERROR: "tool:on.error"
|
|
170
|
-
};
|
|
171
|
-
var hookPointAliases = {
|
|
172
|
-
"before.tool": "tool:before.execute",
|
|
173
|
-
"after.tool": "tool:after.execute",
|
|
174
|
-
"llm.before-invoke": "llm:before.invoke",
|
|
175
|
-
"llm.after-invoke": "llm:after.invoke",
|
|
176
|
-
"llm.stream": "llm:on.stream",
|
|
177
|
-
"prompt.before-render": "prompt:before.render",
|
|
178
|
-
"prompt.after-render": "prompt:after.render",
|
|
179
|
-
"prompt:before.render": "prompt.before-render",
|
|
180
|
-
"prompt:after.render": "prompt.after-render",
|
|
181
|
-
"prompt:after-render": "prompt.after-render",
|
|
182
|
-
"prompt:before-render": "prompt.before-render"
|
|
183
|
-
};
|
|
184
|
-
function setupAliasHooks() {
|
|
185
|
-
const originalRegister = globalHookManager.register.bind(globalHookManager);
|
|
186
|
-
globalHookManager.register = function(hookPoint, hook) {
|
|
187
|
-
originalRegister(hookPoint, hook);
|
|
188
|
-
const alias = hookPointAliases[hookPoint];
|
|
189
|
-
if (alias) {
|
|
190
|
-
originalRegister(alias, hook);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
setupAliasHooks();
|
|
195
|
-
async function executeAgentHook(hookPoint, data, metadata = {}) {
|
|
196
|
-
await globalHookManager.execute(hookPoint, data, metadata);
|
|
197
|
-
}
|
|
198
|
-
async function executeAgentHookWithIntervention(hookPoint, data, metadata = {}) {
|
|
199
|
-
return globalHookManager.executeWithIntervention(hookPoint, data, metadata);
|
|
200
|
-
}
|
|
201
|
-
async function executeLLMHook(hookPoint, data, metadata = {}) {
|
|
202
|
-
await globalHookManager.execute(hookPoint, data, metadata);
|
|
203
|
-
}
|
|
204
|
-
async function executeToolHook(hookPoint, data, metadata = {}) {
|
|
205
|
-
await globalHookManager.execute(hookPoint, data, metadata);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export { HookManager, globalHookManager, AgentHookPoints, LLMHookPoints, ToolHookPoints, executeAgentHook, executeAgentHookWithIntervention, executeLLMHook, executeToolHook };
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__esm
|
|
3
|
-
} from "./roy-agent-core-fs0mn2jk.js";
|
|
4
|
-
|
|
5
|
-
// src/env/workflow/utils/session-recovery.ts
|
|
6
|
-
function inferNextNode(messages, definition) {
|
|
7
|
-
if (messages.length === 0) {
|
|
8
|
-
return { type: "entry_node", nodeId: definition.entryNode };
|
|
9
|
-
}
|
|
10
|
-
const lastMessage = messages[messages.length - 1];
|
|
11
|
-
const metadata = lastMessage.metadata;
|
|
12
|
-
switch (metadata?.type) {
|
|
13
|
-
case "workflow.node.start":
|
|
14
|
-
return {
|
|
15
|
-
type: "resume_node",
|
|
16
|
-
nodeId: metadata.workflowNodeId,
|
|
17
|
-
agentSessionId: metadata.agentSessionId
|
|
18
|
-
};
|
|
19
|
-
case "workflow.node.interrupt":
|
|
20
|
-
return {
|
|
21
|
-
type: "ask_user",
|
|
22
|
-
nodeId: metadata.workflowNodeId,
|
|
23
|
-
agentSessionId: metadata.agentSessionId
|
|
24
|
-
};
|
|
25
|
-
case "workflow.node.end":
|
|
26
|
-
return getNextNodes(metadata.workflowNodeId, definition);
|
|
27
|
-
default:
|
|
28
|
-
const lastStart = findLastStartMessage(messages);
|
|
29
|
-
if (lastStart) {
|
|
30
|
-
const startMetadata = lastStart.metadata;
|
|
31
|
-
return {
|
|
32
|
-
type: "resume_node",
|
|
33
|
-
nodeId: startMetadata.workflowNodeId,
|
|
34
|
-
agentSessionId: startMetadata.agentSessionId
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return { type: "entry_node", nodeId: definition.entryNode };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function getNextNodes(completedNodeId, definition) {
|
|
41
|
-
if (!definition.edges) {
|
|
42
|
-
return { type: "next_nodes", nodeIds: [] };
|
|
43
|
-
}
|
|
44
|
-
const nextNodeIds = definition.edges.filter((edge) => edge.from === completedNodeId).map((edge) => edge.to);
|
|
45
|
-
return { type: "next_nodes", nodeIds: nextNodeIds };
|
|
46
|
-
}
|
|
47
|
-
function findLastInterruptMessage(messages) {
|
|
48
|
-
for (let i = messages.length - 1;i >= 0; i--) {
|
|
49
|
-
const msg = messages[i];
|
|
50
|
-
if (msg.metadata?.type === "workflow.node.interrupt") {
|
|
51
|
-
return msg;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
function findLastStartMessage(messages) {
|
|
57
|
-
for (let i = messages.length - 1;i >= 0; i--) {
|
|
58
|
-
const msg = messages[i];
|
|
59
|
-
if (msg.metadata?.type === "workflow.node.start") {
|
|
60
|
-
return msg;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
function parseNodeOutputs(messages) {
|
|
66
|
-
const outputs = new Map;
|
|
67
|
-
let lastStartNodeId = null;
|
|
68
|
-
for (const msg of messages) {
|
|
69
|
-
const metadata = msg.metadata;
|
|
70
|
-
if (metadata?.type === "workflow.node.start") {
|
|
71
|
-
lastStartNodeId = metadata.workflowNodeId;
|
|
72
|
-
} else if (metadata?.type === "workflow.node.end" && lastStartNodeId) {
|
|
73
|
-
try {
|
|
74
|
-
outputs.set(lastStartNodeId, JSON.parse(msg.content));
|
|
75
|
-
} catch {
|
|
76
|
-
outputs.set(lastStartNodeId, msg.content);
|
|
77
|
-
}
|
|
78
|
-
lastStartNodeId = null;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return outputs;
|
|
82
|
-
}
|
|
83
|
-
function hasPendingAskUser(messages) {
|
|
84
|
-
if (messages.length === 0)
|
|
85
|
-
return false;
|
|
86
|
-
const lastMessage = messages[messages.length - 1];
|
|
87
|
-
const metadata = lastMessage.metadata;
|
|
88
|
-
return metadata?.type === "workflow.node.interrupt";
|
|
89
|
-
}
|
|
90
|
-
function getAgentSessionIdFromInterrupt(messages) {
|
|
91
|
-
const lastInterrupt = findLastInterruptMessage(messages);
|
|
92
|
-
if (!lastInterrupt)
|
|
93
|
-
return null;
|
|
94
|
-
const metadata = lastInterrupt.metadata;
|
|
95
|
-
return metadata?.agentSessionId || null;
|
|
96
|
-
}
|
|
97
|
-
function extractResumeInfo(messages) {
|
|
98
|
-
const nodeOutputs = parseNodeOutputs(messages);
|
|
99
|
-
let pendingNodeId;
|
|
100
|
-
let agentSessionId;
|
|
101
|
-
let hasInterrupt = false;
|
|
102
|
-
let lastInterruptQuery;
|
|
103
|
-
for (const msg of messages) {
|
|
104
|
-
const metadata = msg.metadata;
|
|
105
|
-
if (metadata?.type === "workflow.node.start") {
|
|
106
|
-
pendingNodeId = metadata.workflowNodeId;
|
|
107
|
-
if (metadata?.agentSessionId && !agentSessionId) {
|
|
108
|
-
agentSessionId = metadata.agentSessionId;
|
|
109
|
-
}
|
|
110
|
-
} else if (metadata?.type === "workflow.node.end") {
|
|
111
|
-
pendingNodeId = undefined;
|
|
112
|
-
agentSessionId = undefined;
|
|
113
|
-
} else if (metadata?.type === "workflow.node.interrupt") {
|
|
114
|
-
pendingNodeId = metadata.workflowNodeId;
|
|
115
|
-
agentSessionId = metadata.agentSessionId;
|
|
116
|
-
hasInterrupt = true;
|
|
117
|
-
lastInterruptQuery = msg.content;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
pendingNodeId,
|
|
122
|
-
agentSessionId,
|
|
123
|
-
hasInterrupt,
|
|
124
|
-
nodeOutputs,
|
|
125
|
-
lastInterruptQuery
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
var init_session_recovery = () => {};
|
|
129
|
-
init_session_recovery();
|
|
130
|
-
|
|
131
|
-
export {
|
|
132
|
-
parseNodeOutputs,
|
|
133
|
-
inferNextNode,
|
|
134
|
-
hasPendingAskUser,
|
|
135
|
-
getAgentSessionIdFromInterrupt,
|
|
136
|
-
findLastStartMessage,
|
|
137
|
-
findLastInterruptMessage,
|
|
138
|
-
extractResumeInfo
|
|
139
|
-
};
|