@ai-setting/roy-agent-core 1.5.84 → 1.5.86
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/agent/index.js +2 -2
- package/dist/env/event-source/index.js +8 -4
- package/dist/env/index.js +10 -11
- package/dist/env/prompt/index.js +1 -1
- package/dist/env/task/delegate/index.js +2 -2
- package/dist/env/task/index.js +3 -3
- package/dist/env/workflow/engine/index.js +3 -4
- package/dist/env/workflow/index.js +4 -5
- package/dist/env/workflow/tools/index.js +1 -1
- package/dist/index.js +17 -14
- package/dist/shared/@ai-setting/{roy-agent-core-whw7jap0.js → roy-agent-core-1db4vpc6.js} +3 -2
- package/dist/shared/@ai-setting/{roy-agent-core-m4qjnhz6.js → roy-agent-core-5kdw0p98.js} +114 -68
- package/dist/shared/@ai-setting/{roy-agent-core-ya1ayt1k.js → roy-agent-core-6mk0m4t3.js} +218 -4
- package/dist/shared/@ai-setting/{roy-agent-core-mbre4fxg.js → roy-agent-core-7z4xtrmw.js} +16 -0
- package/dist/shared/@ai-setting/{roy-agent-core-f6p7wwpd.js → roy-agent-core-bgw4dq11.js} +2 -7
- package/dist/shared/@ai-setting/{roy-agent-core-qjv8537d.js → roy-agent-core-bk5g94yd.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-bt7wezvg.js → roy-agent-core-dp73ghtz.js} +5 -16
- package/dist/shared/@ai-setting/{roy-agent-core-6b0r2e7j.js → roy-agent-core-gttz2jpm.js} +15 -52
- package/dist/shared/@ai-setting/{roy-agent-core-akepggsr.js → roy-agent-core-mmkyydw7.js} +26 -1
- package/dist/shared/@ai-setting/{roy-agent-core-xb4hvk1m.js → roy-agent-core-qhhxx2x2.js} +2 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9mj7vzsm.js → roy-agent-core-vneyghpg.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-nc0n0bdc.js → roy-agent-core-xckhrs2p.js} +2 -3
- package/dist/shared/@ai-setting/{roy-agent-core-015vw11k.js → roy-agent-core-yx0vw1aw.js} +8 -6
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-7z8fzxck.js +0 -265
- package/dist/shared/@ai-setting/roy-agent-core-qf9gvx02.js +0 -39
- /package/dist/shared/@ai-setting/{roy-agent-core-2grcjaad.js → roy-agent-core-4f3976cd.js} +0 -0
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME,
|
|
3
|
-
createSubmitJsonOutputTool,
|
|
4
|
-
init_submit_json_output_tool,
|
|
5
|
-
parseWorkflowJsonOutput
|
|
6
|
-
} from "./roy-agent-core-whw7jap0.js";
|
|
7
|
-
import {
|
|
8
|
-
AskUserError,
|
|
9
|
-
init_workflow_hil
|
|
10
|
-
} from "./roy-agent-core-e25xkv53.js";
|
|
11
|
-
import {
|
|
12
|
-
globalHookManager,
|
|
13
|
-
init_global_hook_manager
|
|
14
|
-
} from "./roy-agent-core-7tp56w6n.js";
|
|
15
|
-
import {
|
|
16
|
-
init_decorator,
|
|
17
|
-
wrapFunction
|
|
18
|
-
} from "./roy-agent-core-k05v31rc.js";
|
|
19
|
-
import {
|
|
20
|
-
createLogger,
|
|
21
|
-
init_logger
|
|
22
|
-
} from "./roy-agent-core-shme7set.js";
|
|
23
|
-
import {
|
|
24
|
-
__esm
|
|
25
|
-
} from "./roy-agent-core-fs0mn2jk.js";
|
|
26
|
-
|
|
27
|
-
// src/env/workflow/utils/output-schema-hint.ts
|
|
28
|
-
function describeOutputSchema(schema) {
|
|
29
|
-
if (!schema || typeof schema !== "object") {
|
|
30
|
-
return "Submit a JSON object matching the configured output schema";
|
|
31
|
-
}
|
|
32
|
-
const obj = schema;
|
|
33
|
-
if (!obj.properties || Object.keys(obj.properties).length === 0) {
|
|
34
|
-
return "Submit a JSON object matching the configured output schema";
|
|
35
|
-
}
|
|
36
|
-
const required = new Set(obj.required ?? []);
|
|
37
|
-
const fields = Object.entries(obj.properties).map(([name, prop]) => {
|
|
38
|
-
const type = prop.type ?? "unknown";
|
|
39
|
-
const req = required.has(name) ? "required" : "optional";
|
|
40
|
-
const desc = prop.description ? ` — ${prop.description}` : "";
|
|
41
|
-
return `${name}: ${type} (${req})${desc}`;
|
|
42
|
-
});
|
|
43
|
-
return `Expected fields: ${fields.join("; ")}`;
|
|
44
|
-
}
|
|
45
|
-
var init_output_schema_hint = () => {};
|
|
46
|
-
|
|
47
|
-
// src/env/workflow/plugins/workflow-json-output-plugin.ts
|
|
48
|
-
function getFallbackModel(hookCtx) {
|
|
49
|
-
const fromMetadata = hookCtx.context.metadata?.workflowJsonOutputFallbackModel;
|
|
50
|
-
if (typeof fromMetadata === "string" && fromMetadata.length > 0)
|
|
51
|
-
return fromMetadata;
|
|
52
|
-
return process.env.WORKFLOW_JSON_OUTPUT_FALLBACK_MODEL || DEFAULT_FALLBACK_MODEL;
|
|
53
|
-
}
|
|
54
|
-
function isWorkflowJsonOutputEnabled(pluginEnabled) {
|
|
55
|
-
return pluginEnabled?.[WORKFLOW_JSON_OUTPUT_PLUGIN_KEY] === true;
|
|
56
|
-
}
|
|
57
|
-
function registerWorkflowJsonOutputPlugin(llmComponent) {
|
|
58
|
-
if (registered) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
registered = true;
|
|
62
|
-
globalHookManager.register(HOOK_POINT, {
|
|
63
|
-
name: HOOK_NAME,
|
|
64
|
-
pluginName: WORKFLOW_JSON_OUTPUT_PLUGIN_NAME,
|
|
65
|
-
sourceId: WORKFLOW_JSON_OUTPUT_SOURCE_ID,
|
|
66
|
-
priority: 100,
|
|
67
|
-
description: "Extract structured JSON after ReAct via a dedicated LLM invoke",
|
|
68
|
-
execute: async (wrapper) => {
|
|
69
|
-
const hookCtx = wrapper.data;
|
|
70
|
-
await tracedRunWorkflowJsonOutputExtraction(hookCtx, llmComponent);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
logger.info("Workflow JSON output plugin registered on agent:after.react");
|
|
74
|
-
}
|
|
75
|
-
function unregisterWorkflowJsonOutputPlugin() {
|
|
76
|
-
globalHookManager.unregister(HOOK_POINT, HOOK_NAME);
|
|
77
|
-
registered = false;
|
|
78
|
-
}
|
|
79
|
-
async function runWorkflowJsonOutputExtraction(hookCtx, llmComponent) {
|
|
80
|
-
const schema = hookCtx.context.metadata?.outputSchema;
|
|
81
|
-
if (!schema) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (hookCtx.error instanceof AskUserError) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (hookCtx.structuredOutputExtracted) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const extracted = extractStructuredJsonFromMessages(hookCtx.messages, schema);
|
|
91
|
-
if (extracted) {
|
|
92
|
-
hookCtx.structuredOutputExtracted = extracted;
|
|
93
|
-
logger.info("Workflow JSON output extracted from ReAct messages (no second LLM invoke)");
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
logger.warn(`Workflow JSON extraction: Phase 1 (ReAct messages) returned no workflow_submit_output. ` + `Attempting Phase 2 fallback with model=${getFallbackModel(hookCtx)}.`);
|
|
97
|
-
try {
|
|
98
|
-
const fallbackExtracted = await extractStructuredJsonViaLlm(llmComponent, hookCtx.messages, schema, {
|
|
99
|
-
model: getFallbackModel(hookCtx),
|
|
100
|
-
sessionId: hookCtx.context.sessionId,
|
|
101
|
-
abortSignal: hookCtx.context.abort
|
|
102
|
-
});
|
|
103
|
-
if (fallbackExtracted) {
|
|
104
|
-
hookCtx.structuredOutputExtracted = fallbackExtracted;
|
|
105
|
-
logger.info(`Workflow JSON output extracted via fallback LLM (${getFallbackModel(hookCtx)})`);
|
|
106
|
-
} else {
|
|
107
|
-
logger.warn(`Workflow JSON extraction: Phase 2 fallback (${getFallbackModel(hookCtx)}) also failed to extract structured output. ` + `Check if the fallback model is available and supports forced toolChoice.`);
|
|
108
|
-
}
|
|
109
|
-
} catch (error) {
|
|
110
|
-
logger.error(`Workflow JSON extraction: Phase 2 fallback (${getFallbackModel(hookCtx)}) threw error`, { error: String(error) });
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function tryExtractToolCall(submitTool, tc) {
|
|
114
|
-
const name = tc.function?.name ?? tc.name;
|
|
115
|
-
if (name !== WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME)
|
|
116
|
-
return;
|
|
117
|
-
const argsRaw = tc.function?.arguments ?? tc.arguments;
|
|
118
|
-
const argsStr = typeof argsRaw === "string" ? argsRaw : JSON.stringify(argsRaw ?? {});
|
|
119
|
-
try {
|
|
120
|
-
return submitTool.parameters.parse(JSON.parse(argsStr));
|
|
121
|
-
} catch {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function extractStructuredJsonFromMessages(messages, schema) {
|
|
126
|
-
const submitTool = createSubmitJsonOutputTool(schema);
|
|
127
|
-
for (let i = messages.length - 1;i >= 0; i--) {
|
|
128
|
-
const msg = messages[i];
|
|
129
|
-
if (msg.role !== "assistant")
|
|
130
|
-
continue;
|
|
131
|
-
const toolCalls = msg.tool_calls ?? msg.toolCalls ?? [];
|
|
132
|
-
if (toolCalls.length) {
|
|
133
|
-
for (let j = toolCalls.length - 1;j >= 0; j--) {
|
|
134
|
-
const result = tryExtractToolCall(submitTool, toolCalls[j]);
|
|
135
|
-
if (result)
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (Array.isArray(msg.content)) {
|
|
140
|
-
for (let k = msg.content.length - 1;k >= 0; k--) {
|
|
141
|
-
const part = msg.content[k];
|
|
142
|
-
if (part?.type !== "tool-call")
|
|
143
|
-
continue;
|
|
144
|
-
const result = tryExtractToolCall(submitTool, {
|
|
145
|
-
name: part.toolName,
|
|
146
|
-
arguments: part.args ?? part.arguments
|
|
147
|
-
});
|
|
148
|
-
if (result)
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
async function extractStructuredJsonViaLlm(llmComponent, historyMessages, schema, options = {}) {
|
|
156
|
-
const submitTool = createSubmitJsonOutputTool(schema);
|
|
157
|
-
const extractionUserMessage = {
|
|
158
|
-
role: "user",
|
|
159
|
-
content: "Based on the conversation above, call workflow_submit_output exactly once with structured JSON. " + `${describeOutputSchema(schema)}.`
|
|
160
|
-
};
|
|
161
|
-
const messages = [...historyMessages, extractionUserMessage].map(toLLMMessage);
|
|
162
|
-
for (let attempt = 0;attempt < 2; attempt++) {
|
|
163
|
-
const msgs = [...messages];
|
|
164
|
-
if (attempt === 1) {
|
|
165
|
-
msgs.push({
|
|
166
|
-
role: "user",
|
|
167
|
-
content: "You MUST call workflow_submit_output now with the structured JSON. Do NOT write text. Only call the tool."
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
const result = await llmComponent.invoke({
|
|
171
|
-
messages: msgs,
|
|
172
|
-
tools: [
|
|
173
|
-
{
|
|
174
|
-
name: submitTool.name,
|
|
175
|
-
description: submitTool.description ?? "",
|
|
176
|
-
parameters: submitTool.parameters
|
|
177
|
-
}
|
|
178
|
-
],
|
|
179
|
-
model: options.model,
|
|
180
|
-
context: {
|
|
181
|
-
sessionId: options.sessionId
|
|
182
|
-
},
|
|
183
|
-
abortSignal: options.abortSignal,
|
|
184
|
-
skipThresholdCheck: true
|
|
185
|
-
});
|
|
186
|
-
const toolCalls = result.output?.toolCalls ?? [];
|
|
187
|
-
for (let i = toolCalls.length - 1;i >= 0; i--) {
|
|
188
|
-
const tc = toolCalls[i];
|
|
189
|
-
const name = tc.function?.name ?? tc.name;
|
|
190
|
-
if (name !== WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME) {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
const argsRaw = tc.function?.arguments ?? tc.arguments;
|
|
194
|
-
const argsStr = typeof argsRaw === "string" ? argsRaw : JSON.stringify(argsRaw ?? {});
|
|
195
|
-
try {
|
|
196
|
-
const parsed = submitTool.parameters.parse(JSON.parse(argsStr));
|
|
197
|
-
return parsed;
|
|
198
|
-
} catch {
|
|
199
|
-
const fromExecute = await submitTool.execute(JSON.parse(argsStr));
|
|
200
|
-
const fromMarker = parseWorkflowJsonOutput(fromExecute.output);
|
|
201
|
-
if (fromMarker) {
|
|
202
|
-
return fromMarker;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
logger.warn("Workflow JSON extraction invoke did not return workflow_submit_output");
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
function toLLMMessage(msg) {
|
|
211
|
-
if (typeof msg.content === "string") {
|
|
212
|
-
return {
|
|
213
|
-
role: msg.role,
|
|
214
|
-
content: msg.content
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
if (Array.isArray(msg.content)) {
|
|
218
|
-
if (msg.role === "tool") {
|
|
219
|
-
const toolResult = msg.content.find((part) => part.type === "tool-result");
|
|
220
|
-
const output = toolResult?.output;
|
|
221
|
-
const content = typeof output === "string" ? output : output && typeof output === "object" && ("value" in output) ? String(output.value ?? "") : JSON.stringify(output ?? "");
|
|
222
|
-
return {
|
|
223
|
-
role: "tool",
|
|
224
|
-
content,
|
|
225
|
-
toolCallId: toolResult?.toolCallId,
|
|
226
|
-
name: toolResult?.toolName
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
const text = msg.content.filter((part) => part.type === "text").map((part) => part.text ?? "").join(`
|
|
230
|
-
`);
|
|
231
|
-
const toolCallParts = msg.content.filter((part) => part.type === "tool-call");
|
|
232
|
-
const toolCalls = msg.role === "assistant" && toolCallParts.length > 0 ? toolCallParts.map((part) => {
|
|
233
|
-
const argsString = typeof part.input === "string" ? part.input : JSON.stringify(part.input ?? {});
|
|
234
|
-
const toolName = part.toolName ?? "unknown";
|
|
235
|
-
return {
|
|
236
|
-
id: part.toolCallId ?? "",
|
|
237
|
-
name: toolName,
|
|
238
|
-
arguments: argsString,
|
|
239
|
-
function: { name: toolName, arguments: argsString }
|
|
240
|
-
};
|
|
241
|
-
}) : undefined;
|
|
242
|
-
return {
|
|
243
|
-
role: msg.role,
|
|
244
|
-
content: text,
|
|
245
|
-
...toolCalls?.length ? { toolCalls } : {}
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
return { role: msg.role, content: "" };
|
|
249
|
-
}
|
|
250
|
-
var logger, WORKFLOW_JSON_OUTPUT_SOURCE_ID = "workflow", WORKFLOW_JSON_OUTPUT_PLUGIN_NAME = "json-output", WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, DEFAULT_FALLBACK_MODEL = "minimax/MiniMax-M3", HOOK_POINT = "agent:after.react", HOOK_NAME, registered = false, tracedRunWorkflowJsonOutputExtraction, tracedExtractStructuredJsonViaLlm;
|
|
251
|
-
var init_workflow_json_output_plugin = __esm(() => {
|
|
252
|
-
init_global_hook_manager();
|
|
253
|
-
init_workflow_hil();
|
|
254
|
-
init_submit_json_output_tool();
|
|
255
|
-
init_output_schema_hint();
|
|
256
|
-
init_logger();
|
|
257
|
-
init_decorator();
|
|
258
|
-
logger = createLogger("WorkflowJsonOutputPlugin");
|
|
259
|
-
WORKFLOW_JSON_OUTPUT_PLUGIN_KEY = `${WORKFLOW_JSON_OUTPUT_SOURCE_ID}:${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}`;
|
|
260
|
-
HOOK_NAME = `${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}:${HOOK_POINT}`;
|
|
261
|
-
tracedRunWorkflowJsonOutputExtraction = wrapFunction(runWorkflowJsonOutputExtraction, "workflow.json_output.extraction", { recordParams: true, recordResult: true, log: true });
|
|
262
|
-
tracedExtractStructuredJsonViaLlm = wrapFunction(extractStructuredJsonViaLlm, "workflow.json_output.extract_via_llm", { recordParams: false, recordResult: true, log: true });
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
export { WORKFLOW_JSON_OUTPUT_SOURCE_ID, WORKFLOW_JSON_OUTPUT_PLUGIN_NAME, WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, isWorkflowJsonOutputEnabled, registerWorkflowJsonOutputPlugin, unregisterWorkflowJsonOutputPlugin, runWorkflowJsonOutputExtraction, extractStructuredJsonFromMessages, extractStructuredJsonViaLlm, tracedRunWorkflowJsonOutputExtraction, tracedExtractStructuredJsonViaLlm, init_workflow_json_output_plugin };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WORKFLOW_JSON_OUTPUT_PLUGIN_KEY,
|
|
3
|
-
WORKFLOW_JSON_OUTPUT_PLUGIN_NAME,
|
|
4
|
-
WORKFLOW_JSON_OUTPUT_SOURCE_ID,
|
|
5
|
-
extractStructuredJsonFromMessages,
|
|
6
|
-
extractStructuredJsonViaLlm,
|
|
7
|
-
init_workflow_json_output_plugin,
|
|
8
|
-
isWorkflowJsonOutputEnabled,
|
|
9
|
-
registerWorkflowJsonOutputPlugin,
|
|
10
|
-
runWorkflowJsonOutputExtraction,
|
|
11
|
-
tracedExtractStructuredJsonViaLlm,
|
|
12
|
-
tracedRunWorkflowJsonOutputExtraction,
|
|
13
|
-
unregisterWorkflowJsonOutputPlugin
|
|
14
|
-
} from "./roy-agent-core-7z8fzxck.js";
|
|
15
|
-
import"./roy-agent-core-whw7jap0.js";
|
|
16
|
-
import"./roy-agent-core-e25xkv53.js";
|
|
17
|
-
import"./roy-agent-core-7tp56w6n.js";
|
|
18
|
-
import"./roy-agent-core-qg4rma4c.js";
|
|
19
|
-
import"./roy-agent-core-y5d04fm3.js";
|
|
20
|
-
import"./roy-agent-core-k05v31rc.js";
|
|
21
|
-
import"./roy-agent-core-shme7set.js";
|
|
22
|
-
import"./roy-agent-core-7z9b1fm8.js";
|
|
23
|
-
import"./roy-agent-core-c6592r3c.js";
|
|
24
|
-
import"./roy-agent-core-fs0mn2jk.js";
|
|
25
|
-
init_workflow_json_output_plugin();
|
|
26
|
-
|
|
27
|
-
export {
|
|
28
|
-
unregisterWorkflowJsonOutputPlugin,
|
|
29
|
-
tracedRunWorkflowJsonOutputExtraction,
|
|
30
|
-
tracedExtractStructuredJsonViaLlm,
|
|
31
|
-
runWorkflowJsonOutputExtraction,
|
|
32
|
-
registerWorkflowJsonOutputPlugin,
|
|
33
|
-
isWorkflowJsonOutputEnabled,
|
|
34
|
-
extractStructuredJsonViaLlm,
|
|
35
|
-
extractStructuredJsonFromMessages,
|
|
36
|
-
WORKFLOW_JSON_OUTPUT_SOURCE_ID,
|
|
37
|
-
WORKFLOW_JSON_OUTPUT_PLUGIN_NAME,
|
|
38
|
-
WORKFLOW_JSON_OUTPUT_PLUGIN_KEY
|
|
39
|
-
};
|
|
File without changes
|