@codemation/core-nodes 0.1.1 → 0.3.0
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/CHANGELOG.md +46 -0
- package/dist/index.cjs +446 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +175 -66
- package/dist/index.d.ts +175 -66
- package/dist/index.js +430 -140
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/chatModels/OpenAIStructuredOutputMethodFactory.ts +46 -0
- package/src/index.ts +1 -0
- package/src/nodes/AIAgentConfig.ts +3 -0
- package/src/nodes/AIAgentExecutionHelpersFactory.ts +18 -11
- package/src/nodes/AIAgentNode.ts +145 -6
- package/src/nodes/AgentStructuredOutputRepairPromptFactory.ts +61 -0
- package/src/nodes/AgentStructuredOutputRunner.ts +222 -0
- package/src/nodes/NodeBackedToolRuntime.ts +12 -3
- package/src/nodes/aiAgent.ts +2 -0
- package/src/nodes/mapData.ts +15 -2
- package/src/nodes/switch.ts +0 -1
- package/src/workflowAuthoring/WorkflowAgentNodeFactory.types.ts +5 -9
- package/src/workflowAuthoring/WorkflowAuthoringOptions.types.ts +9 -3
- package/src/workflowAuthoring/WorkflowBranchBuilder.types.ts +13 -9
- package/src/workflowAuthoring/WorkflowChain.types.ts +36 -19
- package/src/workflowAuthoring.types.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentConfigInspector, AgentConnectionNodeCollector, AgentGuardrailDefaults, AgentMessageConfigNormalizer, ConnectionInvocationIdFactory, ConnectionNodeIdFactory, CoreTokens, DefinedNodeRegistry, ItemValueResolver, ItemsInputNormalizer, NodeBackedToolConfig, NodeOutputNormalizer, RetryPolicy, WorkflowBuilder, chatModel, emitPorts, getOriginIndexFromItem, inject, injectable, isPortsEmission, node } from "@codemation/core";
|
|
1
|
+
import { AgentConfigInspector, AgentConnectionNodeCollector, AgentGuardrailDefaults, AgentMessageConfigNormalizer, CallableToolConfig, ConnectionInvocationIdFactory, ConnectionNodeIdFactory, CoreTokens, DefinedNodeRegistry, ItemValueResolver, ItemsInputNormalizer, NodeBackedToolConfig, NodeOutputNormalizer, RetryPolicy, RunnableOutputBehaviorResolver, WorkflowBuilder, chatModel, emitPorts, getOriginIndexFromItem, inject, injectable, isPortsEmission, node } from "@codemation/core";
|
|
2
2
|
import { ChatOpenAI } from "@langchain/openai";
|
|
3
3
|
import { AIMessage, HumanMessage, SystemMessage, ToolMessage } from "@langchain/core/messages";
|
|
4
4
|
import { isInteropZodSchema } from "@langchain/core/utils/types";
|
|
@@ -30,6 +30,42 @@ let OpenAIChatModelFactory = class OpenAIChatModelFactory$1 {
|
|
|
30
30
|
};
|
|
31
31
|
OpenAIChatModelFactory = __decorate([chatModel({ packageName: "@codemation/core-nodes" })], OpenAIChatModelFactory);
|
|
32
32
|
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/chatModels/OpenAIStructuredOutputMethodFactory.ts
|
|
35
|
+
var _OpenAIStructuredOutputMethodFactory;
|
|
36
|
+
let OpenAIStructuredOutputMethodFactory = class OpenAIStructuredOutputMethodFactory$1 {
|
|
37
|
+
static {
|
|
38
|
+
_OpenAIStructuredOutputMethodFactory = this;
|
|
39
|
+
}
|
|
40
|
+
static isoDatePattern = /^\d{4}-\d{2}-\d{2}$/;
|
|
41
|
+
create(chatModelConfig) {
|
|
42
|
+
if (chatModelConfig.type !== OpenAIChatModelFactory) return;
|
|
43
|
+
const model = this.readModelName(chatModelConfig);
|
|
44
|
+
if (!model) return {
|
|
45
|
+
method: "functionCalling",
|
|
46
|
+
strict: true
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
method: this.supportsJsonSchema(model) ? "jsonSchema" : "functionCalling",
|
|
50
|
+
strict: true
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
readModelName(chatModelConfig) {
|
|
54
|
+
const candidate = chatModelConfig;
|
|
55
|
+
return typeof candidate.model === "string" ? candidate.model : void 0;
|
|
56
|
+
}
|
|
57
|
+
supportsJsonSchema(model) {
|
|
58
|
+
if (model === "gpt-4o" || model === "gpt-4o-mini") return true;
|
|
59
|
+
return this.supportsSnapshotAtOrAfter(model, "gpt-4o-", "2024-08-06") || this.supportsSnapshotAtOrAfter(model, "gpt-4o-mini-", "2024-07-18");
|
|
60
|
+
}
|
|
61
|
+
supportsSnapshotAtOrAfter(model, prefix, minimumSnapshotDate) {
|
|
62
|
+
if (!model.startsWith(prefix)) return false;
|
|
63
|
+
const snapshotDate = model.slice(prefix.length);
|
|
64
|
+
return _OpenAIStructuredOutputMethodFactory.isoDatePattern.test(snapshotDate) && snapshotDate >= minimumSnapshotDate;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
OpenAIStructuredOutputMethodFactory = _OpenAIStructuredOutputMethodFactory = __decorate([injectable()], OpenAIStructuredOutputMethodFactory);
|
|
68
|
+
|
|
33
69
|
//#endregion
|
|
34
70
|
//#region src/chatModels/openAiChatModelConfig.ts
|
|
35
71
|
var OpenAIChatModelConfig = class {
|
|
@@ -141,14 +177,6 @@ var AgentOutputFactory = class {
|
|
|
141
177
|
}
|
|
142
178
|
};
|
|
143
179
|
|
|
144
|
-
//#endregion
|
|
145
|
-
//#region src/nodes/AgentToolCallPortMapFactory.ts
|
|
146
|
-
var AgentToolCallPortMap = class {
|
|
147
|
-
static fromInput(input) {
|
|
148
|
-
return { in: [{ json: input }] };
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
180
|
//#endregion
|
|
153
181
|
//#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.js
|
|
154
182
|
/** A special constant with type `never` */
|
|
@@ -2040,6 +2068,168 @@ function toJSONSchema(input, params) {
|
|
|
2040
2068
|
return finalize(ctx, input);
|
|
2041
2069
|
}
|
|
2042
2070
|
|
|
2071
|
+
//#endregion
|
|
2072
|
+
//#region src/nodes/ConnectionCredentialExecutionContextFactory.ts
|
|
2073
|
+
/**
|
|
2074
|
+
* Builds a {@link NodeExecutionContext} whose identity for credential binding and `getCredential`
|
|
2075
|
+
* is a **connection-owned** workflow node id (`ConnectionNodeIdFactory` in `@codemation/core`),
|
|
2076
|
+
* not the executing parent node. Use for LLM slots, tool slots, or any connection-scoped owner.
|
|
2077
|
+
*/
|
|
2078
|
+
var ConnectionCredentialExecutionContextFactory = class {
|
|
2079
|
+
credentialResolverFactory;
|
|
2080
|
+
constructor(credentialSessions) {
|
|
2081
|
+
this.credentialResolverFactory = new CredentialResolverFactory(credentialSessions);
|
|
2082
|
+
}
|
|
2083
|
+
forConnectionNode(ctx, args) {
|
|
2084
|
+
const stubConfig = { getCredentialRequirements: args.getCredentialRequirements };
|
|
2085
|
+
const getCredential = this.credentialResolverFactory.create(ctx.workflowId, args.connectionNodeId, stubConfig);
|
|
2086
|
+
return {
|
|
2087
|
+
...ctx,
|
|
2088
|
+
nodeId: args.connectionNodeId,
|
|
2089
|
+
getCredential
|
|
2090
|
+
};
|
|
2091
|
+
}
|
|
2092
|
+
};
|
|
2093
|
+
|
|
2094
|
+
//#endregion
|
|
2095
|
+
//#region src/nodes/AIAgentExecutionHelpersFactory.ts
|
|
2096
|
+
let AIAgentExecutionHelpersFactory = class AIAgentExecutionHelpersFactory$1 {
|
|
2097
|
+
createConnectionCredentialExecutionContextFactory(credentialSessions) {
|
|
2098
|
+
return new ConnectionCredentialExecutionContextFactory(credentialSessions);
|
|
2099
|
+
}
|
|
2100
|
+
createDynamicStructuredTool(entry, toolCredentialContext, item, itemIndex, items) {
|
|
2101
|
+
if (entry.runtime.inputSchema == null) throw new Error(`Cannot create LangChain tool "${entry.config.name}": missing inputSchema (broken tool runtime resolution).`);
|
|
2102
|
+
const schemaForOpenAi = this.createJsonSchemaRecord(entry.runtime.inputSchema, {
|
|
2103
|
+
schemaName: entry.config.name,
|
|
2104
|
+
requireObjectRoot: true
|
|
2105
|
+
});
|
|
2106
|
+
return new DynamicStructuredTool({
|
|
2107
|
+
name: entry.config.name,
|
|
2108
|
+
description: entry.config.description ?? entry.runtime.defaultDescription,
|
|
2109
|
+
schema: schemaForOpenAi,
|
|
2110
|
+
func: async (input) => {
|
|
2111
|
+
const result = await entry.runtime.execute({
|
|
2112
|
+
config: entry.config,
|
|
2113
|
+
input,
|
|
2114
|
+
ctx: toolCredentialContext,
|
|
2115
|
+
item,
|
|
2116
|
+
itemIndex,
|
|
2117
|
+
items
|
|
2118
|
+
});
|
|
2119
|
+
return JSON.stringify(result);
|
|
2120
|
+
}
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Produces a plain JSON Schema object for OpenAI tool parameters and LangChain tool invocation:
|
|
2125
|
+
* - **Zod** → `toJSONSchema(..., { target: "draft-07" })` so shapes match what `@cfworker/json-schema`
|
|
2126
|
+
* expects (`required` must be an array; draft 2020-12 output can break validation).
|
|
2127
|
+
* - Otherwise LangChain `toJsonSchema` (Standard Schema + JSON passthrough); if the result is still Zod
|
|
2128
|
+
* (duplicate `zod` copies), fall back to Zod `toJSONSchema` with draft-07.
|
|
2129
|
+
* - Strip root `$schema` for OpenAI; normalize invalid `required` keywords for cfworker; ensure `properties`.
|
|
2130
|
+
*/
|
|
2131
|
+
createJsonSchemaRecord(inputSchema, options) {
|
|
2132
|
+
const draft07Params = { target: "draft-07" };
|
|
2133
|
+
let converted;
|
|
2134
|
+
if (isInteropZodSchema(inputSchema)) converted = toJSONSchema(inputSchema, draft07Params);
|
|
2135
|
+
else {
|
|
2136
|
+
converted = toJsonSchema(inputSchema);
|
|
2137
|
+
if (isInteropZodSchema(converted)) converted = toJSONSchema(inputSchema, draft07Params);
|
|
2138
|
+
}
|
|
2139
|
+
const { $schema: _draftSchemaOmitted,...rest } = converted;
|
|
2140
|
+
if (options.requireObjectRoot && rest.type !== "object") throw new Error(`Cannot create LangChain tool "${options.schemaName}": tool input schema must be a JSON Schema object type (got type=${String(rest.type)}).`);
|
|
2141
|
+
if (options.requireObjectRoot && rest.properties !== void 0 && (typeof rest.properties !== "object" || Array.isArray(rest.properties))) throw new Error(`Cannot create LangChain tool "${options.schemaName}": tool input schema "properties" must be an object (got ${JSON.stringify(rest.properties)}).`);
|
|
2142
|
+
if (options.requireObjectRoot && rest.properties === void 0) rest.properties = {};
|
|
2143
|
+
this.sanitizeJsonSchemaRequiredKeywordsForCfworker(rest);
|
|
2144
|
+
return rest;
|
|
2145
|
+
}
|
|
2146
|
+
/**
|
|
2147
|
+
* `@cfworker/json-schema` iterates `schema.required` with `for...of`; it must be a string array or absent.
|
|
2148
|
+
*/
|
|
2149
|
+
sanitizeJsonSchemaRequiredKeywordsForCfworker(node$1) {
|
|
2150
|
+
if (!node$1 || typeof node$1 !== "object" || Array.isArray(node$1)) return;
|
|
2151
|
+
const o = node$1;
|
|
2152
|
+
const req = o.required;
|
|
2153
|
+
if (req !== void 0 && !Array.isArray(req)) delete o.required;
|
|
2154
|
+
else if (Array.isArray(req)) {
|
|
2155
|
+
const strings = req.filter((x) => typeof x === "string");
|
|
2156
|
+
if (strings.length === 0) delete o.required;
|
|
2157
|
+
else if (strings.length !== req.length) o.required = strings;
|
|
2158
|
+
}
|
|
2159
|
+
const props = o.properties;
|
|
2160
|
+
if (props && typeof props === "object" && !Array.isArray(props)) for (const v of Object.values(props)) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(v);
|
|
2161
|
+
for (const key of [
|
|
2162
|
+
"allOf",
|
|
2163
|
+
"anyOf",
|
|
2164
|
+
"oneOf"
|
|
2165
|
+
]) {
|
|
2166
|
+
const branch = o[key];
|
|
2167
|
+
if (Array.isArray(branch)) for (const sub of branch) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(sub);
|
|
2168
|
+
}
|
|
2169
|
+
if (o.if) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.if);
|
|
2170
|
+
if (o.then) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.then);
|
|
2171
|
+
if (o.else) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.else);
|
|
2172
|
+
if (o.not) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.not);
|
|
2173
|
+
if (o.items) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.items);
|
|
2174
|
+
if (Array.isArray(o.prefixItems)) for (const sub of o.prefixItems) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(sub);
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
AIAgentExecutionHelpersFactory = __decorate([injectable()], AIAgentExecutionHelpersFactory);
|
|
2178
|
+
|
|
2179
|
+
//#endregion
|
|
2180
|
+
//#region \0@oxc-project+runtime@0.95.0/helpers/decorateMetadata.js
|
|
2181
|
+
function __decorateMetadata(k, v) {
|
|
2182
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
//#endregion
|
|
2186
|
+
//#region \0@oxc-project+runtime@0.95.0/helpers/decorateParam.js
|
|
2187
|
+
function __decorateParam(paramIndex, decorator) {
|
|
2188
|
+
return function(target, key) {
|
|
2189
|
+
decorator(target, key, paramIndex);
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
//#endregion
|
|
2194
|
+
//#region src/nodes/AgentStructuredOutputRepairPromptFactory.ts
|
|
2195
|
+
var _ref$3, _AgentStructuredOutputRepairPromptFactory;
|
|
2196
|
+
let AgentStructuredOutputRepairPromptFactory = class AgentStructuredOutputRepairPromptFactory$1 {
|
|
2197
|
+
static {
|
|
2198
|
+
_AgentStructuredOutputRepairPromptFactory = this;
|
|
2199
|
+
}
|
|
2200
|
+
static maxSchemaLength = 8e3;
|
|
2201
|
+
static maxInvalidContentLength = 4e3;
|
|
2202
|
+
static maxValidationErrorLength = 4e3;
|
|
2203
|
+
constructor(executionHelpers) {
|
|
2204
|
+
this.executionHelpers = executionHelpers;
|
|
2205
|
+
}
|
|
2206
|
+
create(args) {
|
|
2207
|
+
return [{
|
|
2208
|
+
role: "system",
|
|
2209
|
+
content: "Return only JSON that matches the required schema exactly. Do not include markdown fences, commentary, or prose."
|
|
2210
|
+
}, {
|
|
2211
|
+
role: "user",
|
|
2212
|
+
content: JSON.stringify({
|
|
2213
|
+
requiredSchema: this.truncate(JSON.stringify(this.executionHelpers.createJsonSchemaRecord(args.schema, {
|
|
2214
|
+
schemaName: "agent_output",
|
|
2215
|
+
requireObjectRoot: false
|
|
2216
|
+
})), _AgentStructuredOutputRepairPromptFactory.maxSchemaLength),
|
|
2217
|
+
invalidModelOutput: this.truncate(args.invalidContent, _AgentStructuredOutputRepairPromptFactory.maxInvalidContentLength),
|
|
2218
|
+
validationError: this.truncate(args.validationError, _AgentStructuredOutputRepairPromptFactory.maxValidationErrorLength)
|
|
2219
|
+
})
|
|
2220
|
+
}];
|
|
2221
|
+
}
|
|
2222
|
+
truncate(value, maxLength) {
|
|
2223
|
+
if (value.length <= maxLength) return value;
|
|
2224
|
+
return `${value.slice(0, maxLength)}...(truncated)`;
|
|
2225
|
+
}
|
|
2226
|
+
};
|
|
2227
|
+
AgentStructuredOutputRepairPromptFactory = _AgentStructuredOutputRepairPromptFactory = __decorate([
|
|
2228
|
+
injectable(),
|
|
2229
|
+
__decorateParam(0, inject(AIAgentExecutionHelpersFactory)),
|
|
2230
|
+
__decorateMetadata("design:paramtypes", [typeof (_ref$3 = typeof AIAgentExecutionHelpersFactory !== "undefined" && AIAgentExecutionHelpersFactory) === "function" ? _ref$3 : Object])
|
|
2231
|
+
], AgentStructuredOutputRepairPromptFactory);
|
|
2232
|
+
|
|
2043
2233
|
//#endregion
|
|
2044
2234
|
//#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.js
|
|
2045
2235
|
const initializer = (inst, issues) => {
|
|
@@ -2371,132 +2561,140 @@ const describe = describe$1;
|
|
|
2371
2561
|
const meta = meta$1;
|
|
2372
2562
|
|
|
2373
2563
|
//#endregion
|
|
2374
|
-
//#region src/nodes/
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
this.
|
|
2564
|
+
//#region src/nodes/AgentStructuredOutputRunner.ts
|
|
2565
|
+
var _ref$2, _ref2$2, _AgentStructuredOutputRunner;
|
|
2566
|
+
let AgentStructuredOutputRunner = class AgentStructuredOutputRunner$1 {
|
|
2567
|
+
static {
|
|
2568
|
+
_AgentStructuredOutputRunner = this;
|
|
2569
|
+
}
|
|
2570
|
+
static repairAttemptCount = 2;
|
|
2571
|
+
constructor(repairPromptFactory, openAiStructuredOutputMethodFactory) {
|
|
2572
|
+
this.repairPromptFactory = repairPromptFactory;
|
|
2573
|
+
this.openAiStructuredOutputMethodFactory = openAiStructuredOutputMethodFactory;
|
|
2574
|
+
}
|
|
2575
|
+
async resolve(args) {
|
|
2576
|
+
let lastFailure;
|
|
2577
|
+
if (args.rawFinalResponse) {
|
|
2578
|
+
const directResult = this.tryParseAndValidate(AgentMessageFactory.extractContent(args.rawFinalResponse), args.schema);
|
|
2579
|
+
if (directResult.ok) return directResult.value;
|
|
2580
|
+
lastFailure = directResult;
|
|
2581
|
+
} else if (!this.supportsNativeStructuredOutput(args.model)) {
|
|
2582
|
+
const rawResponse = await args.invokeTextModel(args.conversation);
|
|
2583
|
+
const directResult = this.tryParseAndValidate(AgentMessageFactory.extractContent(rawResponse), args.schema);
|
|
2584
|
+
if (directResult.ok) return directResult.value;
|
|
2585
|
+
lastFailure = directResult;
|
|
2586
|
+
}
|
|
2587
|
+
try {
|
|
2588
|
+
const nativeStructuredModel = this.createStructuredOutputModel(args.model, args.chatModelConfig, args.schema);
|
|
2589
|
+
if (nativeStructuredModel) {
|
|
2590
|
+
const nativeResult = this.tryValidateStructuredValue(await args.invokeStructuredModel(nativeStructuredModel, args.conversation), args.schema);
|
|
2591
|
+
if (nativeResult.ok) return nativeResult.value;
|
|
2592
|
+
lastFailure = nativeResult;
|
|
2593
|
+
}
|
|
2594
|
+
} catch (error) {
|
|
2595
|
+
lastFailure = {
|
|
2596
|
+
ok: false,
|
|
2597
|
+
invalidContent: "",
|
|
2598
|
+
validationError: `Native structured output failed: ${this.summarizeError(error)}`
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2601
|
+
return await this.retryWithRepairPrompt({
|
|
2602
|
+
...args,
|
|
2603
|
+
lastFailure: lastFailure ?? {
|
|
2604
|
+
ok: false,
|
|
2605
|
+
invalidContent: "",
|
|
2606
|
+
validationError: "Structured output was required but no valid structured response was produced."
|
|
2607
|
+
}
|
|
2608
|
+
});
|
|
2384
2609
|
}
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2610
|
+
async retryWithRepairPrompt(args) {
|
|
2611
|
+
let failure = args.lastFailure;
|
|
2612
|
+
for (let attempt = 1; attempt <= _AgentStructuredOutputRunner.repairAttemptCount; attempt++) {
|
|
2613
|
+
const repairMessages = [...args.conversation, ...AgentMessageFactory.createPromptMessages(this.repairPromptFactory.create({
|
|
2614
|
+
schema: args.schema,
|
|
2615
|
+
invalidContent: failure.invalidContent,
|
|
2616
|
+
validationError: failure.validationError
|
|
2617
|
+
}))];
|
|
2618
|
+
const repairResponse = await args.invokeTextModel(repairMessages);
|
|
2619
|
+
const repairResult = this.tryParseAndValidate(AgentMessageFactory.extractContent(repairResponse), args.schema);
|
|
2620
|
+
if (repairResult.ok) return repairResult.value;
|
|
2621
|
+
failure = repairResult;
|
|
2622
|
+
}
|
|
2623
|
+
throw new Error(`Structured output required for AIAgent "${args.agentName}" (${args.nodeId}) but validation still failed after ${_AgentStructuredOutputRunner.repairAttemptCount} repair attempts: ${failure.validationError}`);
|
|
2393
2624
|
}
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
let AIAgentExecutionHelpersFactory = class AIAgentExecutionHelpersFactory$1 {
|
|
2399
|
-
createConnectionCredentialExecutionContextFactory(credentialSessions) {
|
|
2400
|
-
return new ConnectionCredentialExecutionContextFactory(credentialSessions);
|
|
2625
|
+
createStructuredOutputModel(model, chatModelConfig, schema) {
|
|
2626
|
+
if (!this.supportsNativeStructuredOutput(model)) return;
|
|
2627
|
+
const options = this.getStructuredOutputOptions(chatModelConfig);
|
|
2628
|
+
return model.withStructuredOutput(schema, options);
|
|
2401
2629
|
}
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
const schemaForOpenAi = this.normalizeToolInputSchemaForOpenAiDynamicStructuredTool(entry.config.name, entry.runtime.inputSchema);
|
|
2405
|
-
return new DynamicStructuredTool({
|
|
2406
|
-
name: entry.config.name,
|
|
2407
|
-
description: entry.config.description ?? entry.runtime.defaultDescription,
|
|
2408
|
-
schema: schemaForOpenAi,
|
|
2409
|
-
func: async (input) => {
|
|
2410
|
-
const result = await entry.runtime.execute({
|
|
2411
|
-
config: entry.config,
|
|
2412
|
-
input,
|
|
2413
|
-
ctx: toolCredentialContext,
|
|
2414
|
-
item,
|
|
2415
|
-
itemIndex,
|
|
2416
|
-
items
|
|
2417
|
-
});
|
|
2418
|
-
return JSON.stringify(result);
|
|
2419
|
-
}
|
|
2420
|
-
});
|
|
2630
|
+
getStructuredOutputOptions(chatModelConfig) {
|
|
2631
|
+
return this.openAiStructuredOutputMethodFactory.create(chatModelConfig) ?? { strict: true };
|
|
2421
2632
|
}
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
else {
|
|
2435
|
-
converted = toJsonSchema(inputSchema);
|
|
2436
|
-
if (isInteropZodSchema(converted)) converted = toJSONSchema(inputSchema, draft07Params);
|
|
2633
|
+
supportsNativeStructuredOutput(model) {
|
|
2634
|
+
return typeof model.withStructuredOutput === "function";
|
|
2635
|
+
}
|
|
2636
|
+
tryParseAndValidate(content, schema) {
|
|
2637
|
+
try {
|
|
2638
|
+
return this.tryValidateStructuredValue(JSON.parse(content), schema, content);
|
|
2639
|
+
} catch (error) {
|
|
2640
|
+
return {
|
|
2641
|
+
ok: false,
|
|
2642
|
+
invalidContent: content,
|
|
2643
|
+
validationError: `Response was not valid JSON: ${this.summarizeError(error)}`
|
|
2644
|
+
};
|
|
2437
2645
|
}
|
|
2438
|
-
const { $schema: _draftSchemaOmitted,...rest } = converted;
|
|
2439
|
-
if (rest.type !== "object") throw new Error(`Cannot create LangChain tool "${toolName}": tool input schema must be a JSON Schema object type (got type=${String(rest.type)}).`);
|
|
2440
|
-
if (rest.properties !== void 0 && (typeof rest.properties !== "object" || Array.isArray(rest.properties))) throw new Error(`Cannot create LangChain tool "${toolName}": tool input schema "properties" must be an object (got ${JSON.stringify(rest.properties)}).`);
|
|
2441
|
-
if (rest.properties === void 0) rest.properties = {};
|
|
2442
|
-
this.sanitizeJsonSchemaRequiredKeywordsForCfworker(rest);
|
|
2443
|
-
return rest;
|
|
2444
2646
|
}
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2647
|
+
tryValidateStructuredValue(value, schema, invalidContent) {
|
|
2648
|
+
try {
|
|
2649
|
+
return {
|
|
2650
|
+
ok: true,
|
|
2651
|
+
value: schema.parse(value)
|
|
2652
|
+
};
|
|
2653
|
+
} catch (error) {
|
|
2654
|
+
return {
|
|
2655
|
+
ok: false,
|
|
2656
|
+
invalidContent: invalidContent ?? this.toJson(value),
|
|
2657
|
+
validationError: this.summarizeError(error)
|
|
2658
|
+
};
|
|
2457
2659
|
}
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2660
|
+
}
|
|
2661
|
+
summarizeError(error) {
|
|
2662
|
+
if (error instanceof ZodError) return error.issues.map((issue$1) => `${issue$1.path.join(".") || "<root>"}: ${issue$1.message}`).join("; ");
|
|
2663
|
+
if (error instanceof Error) return error.message;
|
|
2664
|
+
return String(error);
|
|
2665
|
+
}
|
|
2666
|
+
toJson(value) {
|
|
2667
|
+
try {
|
|
2668
|
+
return JSON.stringify(value);
|
|
2669
|
+
} catch (error) {
|
|
2670
|
+
return `<<unserializable: ${this.summarizeError(error)}>>`;
|
|
2467
2671
|
}
|
|
2468
|
-
if (o.if) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.if);
|
|
2469
|
-
if (o.then) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.then);
|
|
2470
|
-
if (o.else) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.else);
|
|
2471
|
-
if (o.not) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.not);
|
|
2472
|
-
if (o.items) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(o.items);
|
|
2473
|
-
if (Array.isArray(o.prefixItems)) for (const sub of o.prefixItems) this.sanitizeJsonSchemaRequiredKeywordsForCfworker(sub);
|
|
2474
2672
|
}
|
|
2475
2673
|
};
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
}
|
|
2674
|
+
AgentStructuredOutputRunner = _AgentStructuredOutputRunner = __decorate([
|
|
2675
|
+
injectable(),
|
|
2676
|
+
__decorateParam(0, inject(AgentStructuredOutputRepairPromptFactory)),
|
|
2677
|
+
__decorateParam(1, inject(OpenAIStructuredOutputMethodFactory)),
|
|
2678
|
+
__decorateMetadata("design:paramtypes", [typeof (_ref$2 = typeof AgentStructuredOutputRepairPromptFactory !== "undefined" && AgentStructuredOutputRepairPromptFactory) === "function" ? _ref$2 : Object, typeof (_ref2$2 = typeof OpenAIStructuredOutputMethodFactory !== "undefined" && OpenAIStructuredOutputMethodFactory) === "function" ? _ref2$2 : Object])
|
|
2679
|
+
], AgentStructuredOutputRunner);
|
|
2483
2680
|
|
|
2484
2681
|
//#endregion
|
|
2485
|
-
//#region
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
}
|
|
2490
|
-
}
|
|
2682
|
+
//#region src/nodes/AgentToolCallPortMapFactory.ts
|
|
2683
|
+
var AgentToolCallPortMap = class {
|
|
2684
|
+
static fromInput(input) {
|
|
2685
|
+
return { in: [{ json: input }] };
|
|
2686
|
+
}
|
|
2687
|
+
};
|
|
2491
2688
|
|
|
2492
2689
|
//#endregion
|
|
2493
2690
|
//#region src/nodes/NodeBackedToolRuntime.ts
|
|
2494
|
-
var _ref$1, _ref2$1;
|
|
2691
|
+
var _ref$1, _ref2$1, _ref3$1;
|
|
2495
2692
|
let NodeBackedToolRuntime = class NodeBackedToolRuntime$1 {
|
|
2496
|
-
constructor(nodeResolver, itemValueResolver, outputNormalizer) {
|
|
2693
|
+
constructor(nodeResolver, itemValueResolver, outputNormalizer, outputBehaviorResolver) {
|
|
2497
2694
|
this.nodeResolver = nodeResolver;
|
|
2498
2695
|
this.itemValueResolver = itemValueResolver;
|
|
2499
2696
|
this.outputNormalizer = outputNormalizer;
|
|
2697
|
+
this.outputBehaviorResolver = outputBehaviorResolver;
|
|
2500
2698
|
}
|
|
2501
2699
|
async execute(config$1, args) {
|
|
2502
2700
|
const nodeInput = config$1.toNodeItem({
|
|
@@ -2528,7 +2726,7 @@ let NodeBackedToolRuntime = class NodeBackedToolRuntime$1 {
|
|
|
2528
2726
|
if (this.isRunnableNode(resolvedNode)) {
|
|
2529
2727
|
const runnable = resolvedNode;
|
|
2530
2728
|
const runnableConfig = ctx.config;
|
|
2531
|
-
const
|
|
2729
|
+
const behavior = this.outputBehaviorResolver.resolve(runnableConfig);
|
|
2532
2730
|
const parsed = (runnable.inputSchema ?? runnableConfig.inputSchema ?? unknown()).parse(nodeInput.json);
|
|
2533
2731
|
const items = [nodeInput];
|
|
2534
2732
|
const execArgs = {
|
|
@@ -2542,7 +2740,7 @@ let NodeBackedToolRuntime = class NodeBackedToolRuntime$1 {
|
|
|
2542
2740
|
return this.outputNormalizer.normalizeExecuteResult({
|
|
2543
2741
|
baseItem: nodeInput,
|
|
2544
2742
|
raw,
|
|
2545
|
-
|
|
2743
|
+
behavior
|
|
2546
2744
|
});
|
|
2547
2745
|
}
|
|
2548
2746
|
throw new Error(`Node-backed tool expected a runnable node instance for "${ctx.config.name ?? ctx.nodeId}".`);
|
|
@@ -2559,10 +2757,12 @@ NodeBackedToolRuntime = __decorate([
|
|
|
2559
2757
|
__decorateParam(0, inject(CoreTokens.NodeResolver)),
|
|
2560
2758
|
__decorateParam(1, inject(ItemValueResolver)),
|
|
2561
2759
|
__decorateParam(2, inject(NodeOutputNormalizer)),
|
|
2760
|
+
__decorateParam(3, inject(RunnableOutputBehaviorResolver)),
|
|
2562
2761
|
__decorateMetadata("design:paramtypes", [
|
|
2563
2762
|
Object,
|
|
2564
2763
|
typeof (_ref$1 = typeof ItemValueResolver !== "undefined" && ItemValueResolver) === "function" ? _ref$1 : Object,
|
|
2565
|
-
typeof (_ref2$1 = typeof NodeOutputNormalizer !== "undefined" && NodeOutputNormalizer) === "function" ? _ref2$1 : Object
|
|
2764
|
+
typeof (_ref2$1 = typeof NodeOutputNormalizer !== "undefined" && NodeOutputNormalizer) === "function" ? _ref2$1 : Object,
|
|
2765
|
+
typeof (_ref3$1 = typeof RunnableOutputBehaviorResolver !== "undefined" && RunnableOutputBehaviorResolver) === "function" ? _ref3$1 : Object
|
|
2566
2766
|
])
|
|
2567
2767
|
], NodeBackedToolRuntime);
|
|
2568
2768
|
|
|
@@ -2576,7 +2776,7 @@ var AgentItemPortMap = class {
|
|
|
2576
2776
|
|
|
2577
2777
|
//#endregion
|
|
2578
2778
|
//#region src/nodes/AIAgentNode.ts
|
|
2579
|
-
var _ref, _ref2;
|
|
2779
|
+
var _ref, _ref2, _ref3;
|
|
2580
2780
|
let AIAgentNode = class AIAgentNode$1 {
|
|
2581
2781
|
kind = "node";
|
|
2582
2782
|
outputPorts = ["main"];
|
|
@@ -2589,10 +2789,11 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
2589
2789
|
connectionCredentialExecutionContextFactory;
|
|
2590
2790
|
/** One resolved model/tools bundle per activation context (same ctx across items in a batch). */
|
|
2591
2791
|
preparedByExecutionContext = /* @__PURE__ */ new WeakMap();
|
|
2592
|
-
constructor(nodeResolver, credentialSessions, nodeBackedToolRuntime, executionHelpers) {
|
|
2792
|
+
constructor(nodeResolver, credentialSessions, nodeBackedToolRuntime, executionHelpers, structuredOutputRunner) {
|
|
2593
2793
|
this.nodeResolver = nodeResolver;
|
|
2594
2794
|
this.nodeBackedToolRuntime = nodeBackedToolRuntime;
|
|
2595
2795
|
this.executionHelpers = executionHelpers;
|
|
2796
|
+
this.structuredOutputRunner = structuredOutputRunner;
|
|
2596
2797
|
this.connectionCredentialExecutionContextFactory = this.executionHelpers.createConnectionCredentialExecutionContextFactory(credentialSessions);
|
|
2597
2798
|
}
|
|
2598
2799
|
async execute(args) {
|
|
@@ -2644,6 +2845,19 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
2644
2845
|
const itemInputsByPort = AgentItemPortMap.fromItem(item);
|
|
2645
2846
|
const itemScopedTools = this.createItemScopedTools(prepared.resolvedTools, ctx, item, itemIndex, items);
|
|
2646
2847
|
const conversation = [...this.createPromptMessages(item, itemIndex, items, ctx)];
|
|
2848
|
+
if (ctx.config.outputSchema && itemScopedTools.length === 0) {
|
|
2849
|
+
const structuredOutput = await this.structuredOutputRunner.resolve({
|
|
2850
|
+
model: prepared.model,
|
|
2851
|
+
chatModelConfig: ctx.config.chatModel,
|
|
2852
|
+
schema: ctx.config.outputSchema,
|
|
2853
|
+
conversation,
|
|
2854
|
+
agentName: this.getAgentDisplayName(ctx),
|
|
2855
|
+
nodeId: ctx.nodeId,
|
|
2856
|
+
invokeTextModel: async (messages) => await this.invokeModel(prepared.model, prepared.languageModelConnectionNodeId, messages, ctx, itemInputsByPort, prepared.guardrails.modelInvocationOptions),
|
|
2857
|
+
invokeStructuredModel: async (structuredModel, messages) => await this.invokeStructuredModel(structuredModel, prepared.languageModelConnectionNodeId, messages, ctx, itemInputsByPort, prepared.guardrails.modelInvocationOptions)
|
|
2858
|
+
});
|
|
2859
|
+
return this.buildOutputItem(item, structuredOutput);
|
|
2860
|
+
}
|
|
2647
2861
|
const modelWithTools = this.bindToolsToModel(prepared.model, itemScopedTools);
|
|
2648
2862
|
const finalResponse = await this.runTurnLoopUntilFinalAnswer({
|
|
2649
2863
|
prepared,
|
|
@@ -2652,7 +2866,8 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
2652
2866
|
conversation,
|
|
2653
2867
|
modelWithTools
|
|
2654
2868
|
});
|
|
2655
|
-
|
|
2869
|
+
const outputJson = await this.resolveFinalOutputJson(prepared, itemInputsByPort, conversation, finalResponse, itemScopedTools.length > 0);
|
|
2870
|
+
return this.buildOutputItem(item, outputJson);
|
|
2656
2871
|
}
|
|
2657
2872
|
/**
|
|
2658
2873
|
* Repeatedly invokes the model until it returns without tool calls, or guardrails end the loop.
|
|
@@ -2688,8 +2903,22 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
2688
2903
|
appendAssistantAndToolMessages(conversation, assistantMessage, executedToolCalls) {
|
|
2689
2904
|
conversation.push(assistantMessage, ...executedToolCalls.map((toolCall) => AgentMessageFactory.createToolMessage(toolCall.toolCallId, toolCall.serialized)));
|
|
2690
2905
|
}
|
|
2691
|
-
|
|
2692
|
-
|
|
2906
|
+
async resolveFinalOutputJson(prepared, itemInputsByPort, conversation, finalResponse, wasToolEnabledRun) {
|
|
2907
|
+
if (!prepared.ctx.config.outputSchema) return AgentOutputFactory.fromAgentContent(AgentMessageFactory.extractContent(finalResponse));
|
|
2908
|
+
return await this.structuredOutputRunner.resolve({
|
|
2909
|
+
model: prepared.model,
|
|
2910
|
+
chatModelConfig: prepared.ctx.config.chatModel,
|
|
2911
|
+
schema: prepared.ctx.config.outputSchema,
|
|
2912
|
+
conversation: wasToolEnabledRun ? [...conversation, finalResponse] : conversation,
|
|
2913
|
+
rawFinalResponse: finalResponse,
|
|
2914
|
+
agentName: this.getAgentDisplayName(prepared.ctx),
|
|
2915
|
+
nodeId: prepared.ctx.nodeId,
|
|
2916
|
+
invokeTextModel: async (messages) => await this.invokeModel(prepared.model, prepared.languageModelConnectionNodeId, messages, prepared.ctx, itemInputsByPort, prepared.guardrails.modelInvocationOptions),
|
|
2917
|
+
invokeStructuredModel: async (structuredModel, messages) => await this.invokeStructuredModel(structuredModel, prepared.languageModelConnectionNodeId, messages, prepared.ctx, itemInputsByPort, prepared.guardrails.modelInvocationOptions)
|
|
2918
|
+
});
|
|
2919
|
+
}
|
|
2920
|
+
buildOutputItem(item, outputJson) {
|
|
2921
|
+
return AgentOutputFactory.replaceJson(item, outputJson);
|
|
2693
2922
|
}
|
|
2694
2923
|
bindToolsToModel(model, itemScopedTools) {
|
|
2695
2924
|
if (itemScopedTools.length === 0 || !model.bindTools) return model;
|
|
@@ -2755,6 +2984,40 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
2755
2984
|
throw await this.failTrackedNodeInvocation(error, nodeId, ctx, inputsByPort, this.summarizeLlmMessages(messages));
|
|
2756
2985
|
}
|
|
2757
2986
|
}
|
|
2987
|
+
async invokeStructuredModel(model, nodeId, messages, ctx, inputsByPort, options) {
|
|
2988
|
+
await ctx.nodeState?.markQueued({
|
|
2989
|
+
nodeId,
|
|
2990
|
+
activationId: ctx.activationId,
|
|
2991
|
+
inputsByPort
|
|
2992
|
+
});
|
|
2993
|
+
await ctx.nodeState?.markRunning({
|
|
2994
|
+
nodeId,
|
|
2995
|
+
activationId: ctx.activationId,
|
|
2996
|
+
inputsByPort
|
|
2997
|
+
});
|
|
2998
|
+
try {
|
|
2999
|
+
const response = await model.invoke(messages, options);
|
|
3000
|
+
await ctx.nodeState?.markCompleted({
|
|
3001
|
+
nodeId,
|
|
3002
|
+
activationId: ctx.activationId,
|
|
3003
|
+
inputsByPort,
|
|
3004
|
+
outputs: AgentOutputFactory.fromUnknown(response)
|
|
3005
|
+
});
|
|
3006
|
+
await ctx.nodeState?.appendConnectionInvocation({
|
|
3007
|
+
invocationId: ConnectionInvocationIdFactory.create(),
|
|
3008
|
+
connectionNodeId: nodeId,
|
|
3009
|
+
parentAgentNodeId: ctx.nodeId,
|
|
3010
|
+
parentAgentActivationId: ctx.activationId,
|
|
3011
|
+
status: "completed",
|
|
3012
|
+
managedInput: this.summarizeLlmMessages(messages),
|
|
3013
|
+
managedOutput: this.resultToJsonValue(response),
|
|
3014
|
+
finishedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3015
|
+
});
|
|
3016
|
+
return response;
|
|
3017
|
+
} catch (error) {
|
|
3018
|
+
throw await this.failTrackedNodeInvocation(error, nodeId, ctx, inputsByPort, this.summarizeLlmMessages(messages));
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
2758
3021
|
async markQueuedTools(plannedToolCalls, ctx) {
|
|
2759
3022
|
for (const plannedToolCall of plannedToolCalls) await ctx.nodeState?.markQueued({
|
|
2760
3023
|
nodeId: plannedToolCall.nodeId,
|
|
@@ -2884,6 +3147,18 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
2884
3147
|
execute: async (args) => await this.nodeBackedToolRuntime.execute(config$1, args)
|
|
2885
3148
|
};
|
|
2886
3149
|
}
|
|
3150
|
+
if (this.isCallableToolConfig(config$1)) {
|
|
3151
|
+
const inputSchema = config$1.getInputSchema();
|
|
3152
|
+
if (inputSchema == null) throw new Error(`AIAgent tool "${config$1.name}": callable tool is missing inputSchema (cannot build LangChain tool).`);
|
|
3153
|
+
return {
|
|
3154
|
+
defaultDescription: config$1.description ?? `Callable tool "${config$1.name}".`,
|
|
3155
|
+
inputSchema,
|
|
3156
|
+
execute: async (args) => await config$1.executeTool({
|
|
3157
|
+
...args,
|
|
3158
|
+
config: config$1
|
|
3159
|
+
})
|
|
3160
|
+
};
|
|
3161
|
+
}
|
|
2887
3162
|
const tool = this.nodeResolver.resolve(config$1.type);
|
|
2888
3163
|
if (tool.inputSchema == null) throw new Error(`AIAgent tool "${config$1.name}": plugin tool "${String(config$1.type)}" is missing inputSchema.`);
|
|
2889
3164
|
return {
|
|
@@ -2900,6 +3175,12 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
2900
3175
|
isNodeBackedToolConfig(config$1) {
|
|
2901
3176
|
return config$1 instanceof NodeBackedToolConfig || typeof config$1 === "object" && config$1 !== null && config$1.toolKind === "nodeBacked";
|
|
2902
3177
|
}
|
|
3178
|
+
/**
|
|
3179
|
+
* Callable tools use {@link CallableToolConfig#toolKind} for cross-package / JSON round-trip safety.
|
|
3180
|
+
*/
|
|
3181
|
+
isCallableToolConfig(config$1) {
|
|
3182
|
+
return config$1 instanceof CallableToolConfig || typeof config$1 === "object" && config$1 !== null && config$1.toolKind === "callable";
|
|
3183
|
+
}
|
|
2903
3184
|
resolveGuardrails(guardrails) {
|
|
2904
3185
|
const maxTurns = guardrails?.maxTurns ?? AgentGuardrailDefaults.maxTurns;
|
|
2905
3186
|
if (!Number.isInteger(maxTurns) || maxTurns < 1) throw new Error(`AIAgent maxTurns must be a positive integer. Received: ${String(maxTurns)}`);
|
|
@@ -2909,6 +3190,9 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
2909
3190
|
modelInvocationOptions: guardrails?.modelInvocationOptions
|
|
2910
3191
|
};
|
|
2911
3192
|
}
|
|
3193
|
+
getAgentDisplayName(ctx) {
|
|
3194
|
+
return ctx.config.name ?? ctx.nodeId;
|
|
3195
|
+
}
|
|
2912
3196
|
};
|
|
2913
3197
|
AIAgentNode = __decorate([
|
|
2914
3198
|
node({ packageName: "@codemation/core-nodes" }),
|
|
@@ -2916,11 +3200,13 @@ AIAgentNode = __decorate([
|
|
|
2916
3200
|
__decorateParam(1, inject(CoreTokens.CredentialSessionService)),
|
|
2917
3201
|
__decorateParam(2, inject(NodeBackedToolRuntime)),
|
|
2918
3202
|
__decorateParam(3, inject(AIAgentExecutionHelpersFactory)),
|
|
3203
|
+
__decorateParam(4, inject(AgentStructuredOutputRunner)),
|
|
2919
3204
|
__decorateMetadata("design:paramtypes", [
|
|
2920
3205
|
Object,
|
|
2921
3206
|
Object,
|
|
2922
3207
|
typeof (_ref = typeof NodeBackedToolRuntime !== "undefined" && NodeBackedToolRuntime) === "function" ? _ref : Object,
|
|
2923
|
-
typeof (_ref2 = typeof AIAgentExecutionHelpersFactory !== "undefined" && AIAgentExecutionHelpersFactory) === "function" ? _ref2 : Object
|
|
3208
|
+
typeof (_ref2 = typeof AIAgentExecutionHelpersFactory !== "undefined" && AIAgentExecutionHelpersFactory) === "function" ? _ref2 : Object,
|
|
3209
|
+
typeof (_ref3 = typeof AgentStructuredOutputRunner !== "undefined" && AgentStructuredOutputRunner) === "function" ? _ref3 : Object
|
|
2924
3210
|
])
|
|
2925
3211
|
], AIAgentNode);
|
|
2926
3212
|
|
|
@@ -2943,6 +3229,7 @@ var AIAgent = class {
|
|
|
2943
3229
|
retryPolicy;
|
|
2944
3230
|
guardrails;
|
|
2945
3231
|
inputSchema;
|
|
3232
|
+
outputSchema;
|
|
2946
3233
|
constructor(options) {
|
|
2947
3234
|
this.name = options.name;
|
|
2948
3235
|
this.messages = options.messages;
|
|
@@ -2952,6 +3239,7 @@ var AIAgent = class {
|
|
|
2952
3239
|
this.retryPolicy = options.retryPolicy ?? RetryPolicy.defaultForAiAgent;
|
|
2953
3240
|
this.guardrails = options.guardrails;
|
|
2954
3241
|
this.inputSchema = options.inputSchema;
|
|
3242
|
+
this.outputSchema = options.outputSchema;
|
|
2955
3243
|
}
|
|
2956
3244
|
};
|
|
2957
3245
|
|
|
@@ -3268,7 +3556,6 @@ var Switch = class {
|
|
|
3268
3556
|
type = SwitchNode;
|
|
3269
3557
|
execution = { hint: "local" };
|
|
3270
3558
|
icon = "lucide:git-branch-plus";
|
|
3271
|
-
lineageCarry = "carryThrough";
|
|
3272
3559
|
declaredOutputPorts;
|
|
3273
3560
|
constructor(name, cfg, id) {
|
|
3274
3561
|
this.name = name;
|
|
@@ -3371,10 +3658,15 @@ var MapData = class {
|
|
|
3371
3658
|
execution = { hint: "local" };
|
|
3372
3659
|
/** Zero mapped items should still allow downstream nodes to run. */
|
|
3373
3660
|
continueWhenEmptyOutput = true;
|
|
3374
|
-
|
|
3661
|
+
keepBinaries;
|
|
3662
|
+
constructor(name, map, options = {}) {
|
|
3375
3663
|
this.name = name;
|
|
3376
3664
|
this.map = map;
|
|
3377
|
-
this.
|
|
3665
|
+
this.options = options;
|
|
3666
|
+
this.keepBinaries = options.keepBinaries ?? true;
|
|
3667
|
+
}
|
|
3668
|
+
get id() {
|
|
3669
|
+
return this.options.id;
|
|
3378
3670
|
}
|
|
3379
3671
|
};
|
|
3380
3672
|
|
|
@@ -3683,15 +3975,13 @@ var WorkflowAgentNodeFactory = class {
|
|
|
3683
3975
|
static create(nameOrOptions, optionsOrUndefined) {
|
|
3684
3976
|
const options = typeof nameOrOptions === "string" ? optionsOrUndefined : nameOrOptions;
|
|
3685
3977
|
const name = typeof nameOrOptions === "string" ? nameOrOptions : "AI agent";
|
|
3686
|
-
const
|
|
3978
|
+
const outputSchema = options.outputSchema;
|
|
3687
3979
|
return new AIAgent({
|
|
3688
3980
|
name,
|
|
3689
|
-
messages:
|
|
3690
|
-
role: "user",
|
|
3691
|
-
content: typeof prompt === "function" ? ({ item }) => prompt(item.json) : prompt
|
|
3692
|
-
}],
|
|
3981
|
+
messages: options.messages,
|
|
3693
3982
|
chatModel: WorkflowChatModelFactory.create(options.model),
|
|
3694
3983
|
tools: options.tools,
|
|
3984
|
+
outputSchema,
|
|
3695
3985
|
id: options.id,
|
|
3696
3986
|
retryPolicy: options.retryPolicy,
|
|
3697
3987
|
guardrails: options.guardrails
|
|
@@ -3735,10 +4025,10 @@ var WorkflowBranchBuilder = class WorkflowBranchBuilder {
|
|
|
3735
4025
|
then(config$1) {
|
|
3736
4026
|
return new WorkflowBranchBuilder([...this.steps, config$1]);
|
|
3737
4027
|
}
|
|
3738
|
-
map(nameOrMapper, mapperOrUndefined,
|
|
4028
|
+
map(nameOrMapper, mapperOrUndefined, options) {
|
|
3739
4029
|
const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
|
|
3740
4030
|
const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined : nameOrMapper;
|
|
3741
|
-
return this.then(new MapData(name,
|
|
4031
|
+
return this.then(new MapData(name, mapper, options));
|
|
3742
4032
|
}
|
|
3743
4033
|
wait(nameOrDuration, durationOrUndefined, id) {
|
|
3744
4034
|
const name = typeof nameOrDuration === "string" && durationOrUndefined !== void 0 ? nameOrDuration : "Wait";
|
|
@@ -3781,10 +4071,10 @@ var WorkflowChain = class WorkflowChain {
|
|
|
3781
4071
|
then(config$1) {
|
|
3782
4072
|
return new WorkflowChain(this.chain.then(config$1));
|
|
3783
4073
|
}
|
|
3784
|
-
map(nameOrMapper, mapperOrUndefined,
|
|
4074
|
+
map(nameOrMapper, mapperOrUndefined, options) {
|
|
3785
4075
|
const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
|
|
3786
4076
|
const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined : nameOrMapper;
|
|
3787
|
-
return this.then(new MapData(name,
|
|
4077
|
+
return this.then(new MapData(name, mapper, options));
|
|
3788
4078
|
}
|
|
3789
4079
|
wait(nameOrDuration, durationOrUndefined, id) {
|
|
3790
4080
|
const name = typeof nameOrDuration === "string" && durationOrUndefined !== void 0 ? nameOrDuration : "Wait";
|
|
@@ -3816,7 +4106,7 @@ var WorkflowChain = class WorkflowChain {
|
|
|
3816
4106
|
const name = typeof nameOrPredicate === "string" ? nameOrPredicate : "If";
|
|
3817
4107
|
const predicate = typeof nameOrPredicate === "string" ? predicateOrBranches : nameOrPredicate;
|
|
3818
4108
|
const branches = typeof nameOrPredicate === "string" ? branchesOrUndefined : predicateOrBranches;
|
|
3819
|
-
const cursor = this.chain.then(new If(name, (item) => predicate(item
|
|
4109
|
+
const cursor = this.chain.then(new If(name, (item, _index, _items, ctx) => predicate(item, ctx)));
|
|
3820
4110
|
const trueSteps = branches.true?.(new WorkflowBranchBuilder()).getSteps();
|
|
3821
4111
|
const falseSteps = branches.false?.(new WorkflowBranchBuilder()).getSteps();
|
|
3822
4112
|
return new WorkflowChain(cursor.when({
|
|
@@ -3834,7 +4124,7 @@ var WorkflowChain = class WorkflowChain {
|
|
|
3834
4124
|
return this.then(new Switch(name, {
|
|
3835
4125
|
cases: cfg.cases,
|
|
3836
4126
|
defaultCase: cfg.defaultCase,
|
|
3837
|
-
resolveCaseKey: (item) => cfg.resolveCaseKey(item
|
|
4127
|
+
resolveCaseKey: (item, _index, _items, ctx) => cfg.resolveCaseKey(item, ctx)
|
|
3838
4128
|
}, id)).route(cfg.branches);
|
|
3839
4129
|
}
|
|
3840
4130
|
agent(nameOrOptions, optionsOrUndefined) {
|
|
@@ -3971,5 +4261,5 @@ var ConnectionCredentialNodeConfigFactory = class {
|
|
|
3971
4261
|
};
|
|
3972
4262
|
|
|
3973
4263
|
//#endregion
|
|
3974
|
-
export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentToolCallPortMap, Aggregate, AggregateNode, Callback, CallbackNode, CallbackResultNormalizer, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, Filter, FilterNode, HttpRequest, HttpRequestNode, If, IfNode, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, Merge, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAiChatModelPresets, Split, SplitNode, SubWorkflow, SubWorkflowNode, Switch, SwitchNode, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, WorkflowAuthoringBuilder, WorkflowBranchBuilder, WorkflowChain, createWorkflowBuilder, openAiChatModelPresets, registerCoreNodes, workflow };
|
|
4264
|
+
export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentStructuredOutputRepairPromptFactory, AgentStructuredOutputRunner, AgentToolCallPortMap, Aggregate, AggregateNode, Callback, CallbackNode, CallbackResultNormalizer, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, Filter, FilterNode, HttpRequest, HttpRequestNode, If, IfNode, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, Merge, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAIStructuredOutputMethodFactory, OpenAiChatModelPresets, Split, SplitNode, SubWorkflow, SubWorkflowNode, Switch, SwitchNode, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, WorkflowAuthoringBuilder, WorkflowBranchBuilder, WorkflowChain, createWorkflowBuilder, openAiChatModelPresets, registerCoreNodes, workflow };
|
|
3975
4265
|
//# sourceMappingURL=index.js.map
|