@codemation/core-nodes 0.4.2 → 1.0.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 +51 -0
- package/dist/index.cjs +480 -410
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +220 -116
- package/dist/index.d.ts +220 -116
- package/dist/index.js +476 -403
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/chatModels/OpenAIChatModelFactory.ts +17 -8
- package/src/chatModels/OpenAiStrictJsonSchemaFactory.ts +123 -0
- package/src/index.ts +1 -1
- package/src/nodes/AIAgentExecutionHelpersFactory.ts +45 -59
- package/src/nodes/AIAgentNode.ts +293 -288
- package/src/nodes/AgentMessageFactory.ts +57 -49
- package/src/nodes/AgentStructuredOutputRunner.ts +65 -71
- package/src/nodes/AgentToolExecutionCoordinator.ts +3 -14
- package/src/nodes/aiAgentSupport.types.ts +7 -2
- package/src/chatModels/OpenAIStructuredOutputMethodFactory.ts +0 -46
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
1
|
+
import { AssistantModelMessage, ModelMessage, ToolModelMessage } from "ai";
|
|
3
2
|
import { ReadableStream } from "node:stream/web";
|
|
4
3
|
import { DependencyContainer as Container, InjectionToken as TypeToken } from "tsyringe";
|
|
5
4
|
import { ZodType, input, output, z } from "zod";
|
|
6
5
|
|
|
7
6
|
//#region src/canvasIconName.d.ts
|
|
7
|
+
|
|
8
8
|
/**
|
|
9
9
|
* Canvas / agent presentation:
|
|
10
10
|
* - Lucide: `lucide:<kebab-name>` or legacy kebab name
|
|
@@ -947,25 +947,47 @@ interface ChatModelConfig {
|
|
|
947
947
|
readonly presentation?: AgentCanvasPresentation;
|
|
948
948
|
getCredentialRequirements?(): ReadonlyArray<CredentialRequirement>;
|
|
949
949
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
950
|
+
/**
|
|
951
|
+
* Provider-neutral chat language model wrapper returned by a {@link ChatModelFactory}.
|
|
952
|
+
*
|
|
953
|
+
* Thin adapter around an AI SDK `LanguageModelV2` (from `@ai-sdk/provider`) plus the call-site
|
|
954
|
+
* defaults Codemation needs at every generate/stream: the provider label, the model name used for
|
|
955
|
+
* pricing / telemetry, and the default invocation options (max output tokens, temperature,
|
|
956
|
+
* provider-specific overrides).
|
|
957
|
+
*
|
|
958
|
+
* The consumer (AIAgentNode / AgentStructuredOutputRunner) passes `languageModel` directly into
|
|
959
|
+
* `generateText({ model, ... })` from the `ai` package.
|
|
960
|
+
*/
|
|
961
|
+
interface ChatLanguageModel {
|
|
962
|
+
/** AI SDK `LanguageModelV2` instance (kept `unknown` to avoid leaking the SDK type into `@codemation/core`). */
|
|
963
|
+
readonly languageModel: unknown;
|
|
964
|
+
/** Stable pricing/telemetry key — e.g. `"gpt-4.1-nano"`. */
|
|
965
|
+
readonly modelName: string;
|
|
966
|
+
/** Provider label — e.g. `"openai"`. Used for cost tracking. */
|
|
967
|
+
readonly provider?: string;
|
|
968
|
+
/** Defaults merged into every call. Consumers may override per-invocation. */
|
|
969
|
+
readonly defaultCallOptions?: ChatLanguageModelCallOptions;
|
|
954
970
|
}
|
|
955
|
-
interface
|
|
956
|
-
|
|
971
|
+
interface ChatLanguageModelCallOptions {
|
|
972
|
+
readonly maxOutputTokens?: number;
|
|
973
|
+
readonly temperature?: number;
|
|
974
|
+
readonly providerOptions?: Readonly<Record<string, Readonly<Record<string, JsonValue>>>>;
|
|
957
975
|
}
|
|
958
|
-
|
|
959
|
-
|
|
976
|
+
/**
|
|
977
|
+
* Options for a structured-output generate call. Mirrors
|
|
978
|
+
* `generateText({ output: Output.object(...) })` from the `ai` package.
|
|
979
|
+
*/
|
|
980
|
+
interface StructuredOutputOptions {
|
|
981
|
+
/** Optional schema name — used by some providers as the JSON schema name attribute. */
|
|
982
|
+
readonly schemaName?: string;
|
|
983
|
+
/** When `true`, the consumer should pass a strict-mode-compatible JSON Schema record. */
|
|
960
984
|
readonly strict?: boolean;
|
|
961
|
-
readonly includeRaw?: boolean;
|
|
962
|
-
readonly tools?: ReadonlyArray<unknown>;
|
|
963
985
|
}
|
|
964
986
|
interface ChatModelFactory<TConfig extends ChatModelConfig = ChatModelConfig> {
|
|
965
987
|
create(args: Readonly<{
|
|
966
988
|
config: TConfig;
|
|
967
989
|
ctx: NodeExecutionContext<any>;
|
|
968
|
-
}>): Promise<
|
|
990
|
+
}>): Promise<ChatLanguageModel> | ChatLanguageModel;
|
|
969
991
|
}
|
|
970
992
|
type NodeBackedToolInputMapperArgs<TNodeConfig extends RunnableNodeConfig<any, any>, TToolInput = unknown> = Readonly<{
|
|
971
993
|
input: TToolInput;
|
|
@@ -1058,16 +1080,96 @@ declare class OpenAIChatModelFactory implements ChatModelFactory<OpenAIChatModel
|
|
|
1058
1080
|
create(args: Readonly<{
|
|
1059
1081
|
config: OpenAIChatModelConfig;
|
|
1060
1082
|
ctx: NodeExecutionContext<any>;
|
|
1061
|
-
}>): Promise<
|
|
1083
|
+
}>): Promise<ChatLanguageModel>;
|
|
1062
1084
|
}
|
|
1063
1085
|
//#endregion
|
|
1064
|
-
//#region src/
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1086
|
+
//#region src/nodes/ConnectionCredentialExecutionContextFactory.d.ts
|
|
1087
|
+
/**
|
|
1088
|
+
* Builds a {@link NodeExecutionContext} whose identity for credential binding and `getCredential`
|
|
1089
|
+
* is a **connection-owned** workflow node id (`ConnectionNodeIdFactory` in `@codemation/core`),
|
|
1090
|
+
* not the executing parent node. Use for LLM slots, tool slots, or any connection-scoped owner.
|
|
1091
|
+
*/
|
|
1092
|
+
declare class ConnectionCredentialExecutionContextFactory {
|
|
1093
|
+
private readonly credentialResolverFactory;
|
|
1094
|
+
constructor(credentialSessions: CredentialSessionService);
|
|
1095
|
+
forConnectionNode<TConfig extends NodeConfigBase>(ctx: NodeExecutionContext<TConfig>, args: Readonly<{
|
|
1096
|
+
connectionNodeId: NodeId;
|
|
1097
|
+
getCredentialRequirements: () => ReadonlyArray<CredentialRequirement>;
|
|
1098
|
+
}>): NodeExecutionContext<TConfig>;
|
|
1099
|
+
}
|
|
1100
|
+
//#endregion
|
|
1101
|
+
//#region src/nodes/AIAgentExecutionHelpersFactory.d.ts
|
|
1102
|
+
/**
|
|
1103
|
+
* Helper utilities shared by {@link AIAgentNode} and supporting runners.
|
|
1104
|
+
*
|
|
1105
|
+
* Responsibilities:
|
|
1106
|
+
* - {@link #createConnectionCredentialExecutionContextFactory} centralizes credential-context wiring.
|
|
1107
|
+
* - {@link #createJsonSchemaRecord} is a pure Zod → draft-07 converter used by both
|
|
1108
|
+
* `OpenAiStrictJsonSchemaFactory` (to feed OpenAI-strict structured output) and the
|
|
1109
|
+
* `AgentStructuredOutputRepairPromptFactory` (to show a required-schema reminder).
|
|
1110
|
+
*/
|
|
1111
|
+
declare class AIAgentExecutionHelpersFactory {
|
|
1112
|
+
createConnectionCredentialExecutionContextFactory(credentialSessions: CredentialSessionService): ConnectionCredentialExecutionContextFactory;
|
|
1113
|
+
/**
|
|
1114
|
+
* Produces a plain JSON Schema object (`draft-07`) from a Zod schema, as needed by
|
|
1115
|
+
* OpenAI tool-parameter schemas and the structured-output repair prompt.
|
|
1116
|
+
* - Prefers the schema's **instance** `toJSONSchema(...)` method so we stay inside the Zod
|
|
1117
|
+
* instance that created the schema (works across consumer/framework tsx namespaces — see
|
|
1118
|
+
* {@link ZodInstanceToJsonSchema}). Falls back to the framework-imported module function.
|
|
1119
|
+
* - Strips root `$schema` (OpenAI ignores it).
|
|
1120
|
+
* - Sanitizes `required` for cfworker json-schema compatibility (must be a string array or absent).
|
|
1121
|
+
*/
|
|
1122
|
+
createJsonSchemaRecord(inputSchema: ZodSchemaAny, options: Readonly<{
|
|
1123
|
+
schemaName: string;
|
|
1124
|
+
requireObjectRoot: boolean;
|
|
1125
|
+
}>): Record<string, unknown>;
|
|
1126
|
+
/**
|
|
1127
|
+
* Runs Zod's `toJSONSchema` via the schema's own instance method when available, so consumer
|
|
1128
|
+
* schemas loaded under a different tsx namespace still convert correctly. If the caller handed us
|
|
1129
|
+
* a payload that lacks that method (e.g. a plain JSON Schema record or a Zod instance whose
|
|
1130
|
+
* prototype was stripped), we fall back to the framework-bundled module function.
|
|
1131
|
+
*/
|
|
1132
|
+
private convertZodSchemaToJsonSchema;
|
|
1133
|
+
/**
|
|
1134
|
+
* `@cfworker/json-schema` iterates `schema.required` with `for...of`; it must be a string array or absent.
|
|
1135
|
+
*/
|
|
1136
|
+
private sanitizeJsonSchemaRequiredKeywordsForCfworker;
|
|
1137
|
+
}
|
|
1138
|
+
//#endregion
|
|
1139
|
+
//#region src/chatModels/OpenAiStrictJsonSchemaFactory.d.ts
|
|
1140
|
+
/**
|
|
1141
|
+
* Produces an OpenAI **strict mode**–compliant JSON Schema for an AIAgent `outputSchema`.
|
|
1142
|
+
*
|
|
1143
|
+
* Why this exists: AI SDK's default Zod → JSON Schema conversion (Zod v4's `toJSONSchema`) can
|
|
1144
|
+
* emit `unevaluatedProperties: false` or skip `additionalProperties: false` on object branches.
|
|
1145
|
+
* OpenAI's strict-mode validator rejects anything missing `additionalProperties: false` at
|
|
1146
|
+
* `context=()` (the root) and requires **all properties** in `required`. We convert here so all
|
|
1147
|
+
* legal Zod root shapes work (object, union, discriminated union, nullable-object wrapper, array,
|
|
1148
|
+
* intersection, …) and hand AI SDK a pre-tagged `jsonSchema(...)` record that passes straight
|
|
1149
|
+
* through to the provider.
|
|
1150
|
+
*
|
|
1151
|
+
* Rules enforced on the produced JSON Schema record:
|
|
1152
|
+
* - Every `type: "object"` node (root and nested under `allOf`/`anyOf`/`oneOf`/`items`/`prefixItems`/`$defs`):
|
|
1153
|
+
* - `additionalProperties: false`
|
|
1154
|
+
* - `required` lists **every** key in `properties` (OpenAI strict requires all properties required;
|
|
1155
|
+
* express optionality via `.nullable()` / `z.union([..., z.null()])`).
|
|
1156
|
+
* - `properties` is always an object (empty object allowed).
|
|
1157
|
+
* - `$schema`, `unevaluatedProperties`, and `default` are stripped (OpenAI rejects / ignores them).
|
|
1158
|
+
* - `sanitizeJsonSchemaRequiredKeywordsForCfworker` invariants from
|
|
1159
|
+
* {@link AIAgentExecutionHelpersFactory.createJsonSchemaRecord} are preserved as a starting point.
|
|
1160
|
+
*/
|
|
1161
|
+
declare class OpenAiStrictJsonSchemaFactory {
|
|
1162
|
+
private readonly executionHelpers;
|
|
1163
|
+
constructor(executionHelpers: AIAgentExecutionHelpersFactory);
|
|
1164
|
+
createStructuredOutputRecord(schema: ZodSchemaAny, options: Readonly<{
|
|
1165
|
+
schemaName: string;
|
|
1166
|
+
title?: string;
|
|
1167
|
+
}>): Record<string, unknown>;
|
|
1168
|
+
private strictifyRecursive;
|
|
1169
|
+
private stripOpenAiRejectedKeywords;
|
|
1170
|
+
private isObjectNode;
|
|
1171
|
+
private readPropertiesObject;
|
|
1172
|
+
private recurseIntoComposites;
|
|
1071
1173
|
}
|
|
1072
1174
|
//#endregion
|
|
1073
1175
|
//#region src/chatModels/OpenAiCredentialSession.d.ts
|
|
@@ -1089,41 +1191,6 @@ declare class OpenAiChatModelPresets {
|
|
|
1089
1191
|
}
|
|
1090
1192
|
declare const openAiChatModelPresets: OpenAiChatModelPresets;
|
|
1091
1193
|
//#endregion
|
|
1092
|
-
//#region src/nodes/AgentMessageFactory.d.ts
|
|
1093
|
-
declare class AgentMessageFactory {
|
|
1094
|
-
static createPromptMessages(messages: ReadonlyArray<AgentMessageDto>): ReadonlyArray<BaseMessage>;
|
|
1095
|
-
static createSystemPrompt(systemMessage: string): SystemMessage;
|
|
1096
|
-
static createUserPrompt(prompt: string): HumanMessage;
|
|
1097
|
-
static createAssistantPrompt(prompt: string): AIMessage;
|
|
1098
|
-
static createToolMessage(toolCallId: string, content: string): ToolMessage;
|
|
1099
|
-
static extractContent(message: unknown): string;
|
|
1100
|
-
static extractToolCalls(message: unknown): ReadonlyArray<AgentToolCall>;
|
|
1101
|
-
private static isRecord;
|
|
1102
|
-
private static createPromptMessage;
|
|
1103
|
-
}
|
|
1104
|
-
//#endregion
|
|
1105
|
-
//#region src/nodes/AgentOutputFactory.d.ts
|
|
1106
|
-
declare class AgentOutputFactory {
|
|
1107
|
-
static fromUnknown(value: unknown): NodeOutputs;
|
|
1108
|
-
static replaceJson(item: Item, value: unknown): Item;
|
|
1109
|
-
static fromAgentContent(content: string): unknown;
|
|
1110
|
-
}
|
|
1111
|
-
//#endregion
|
|
1112
|
-
//#region src/nodes/ConnectionCredentialExecutionContextFactory.d.ts
|
|
1113
|
-
/**
|
|
1114
|
-
* Builds a {@link NodeExecutionContext} whose identity for credential binding and `getCredential`
|
|
1115
|
-
* is a **connection-owned** workflow node id (`ConnectionNodeIdFactory` in `@codemation/core`),
|
|
1116
|
-
* not the executing parent node. Use for LLM slots, tool slots, or any connection-scoped owner.
|
|
1117
|
-
*/
|
|
1118
|
-
declare class ConnectionCredentialExecutionContextFactory {
|
|
1119
|
-
private readonly credentialResolverFactory;
|
|
1120
|
-
constructor(credentialSessions: CredentialSessionService);
|
|
1121
|
-
forConnectionNode<TConfig extends NodeConfigBase>(ctx: NodeExecutionContext<TConfig>, args: Readonly<{
|
|
1122
|
-
connectionNodeId: NodeId;
|
|
1123
|
-
getCredentialRequirements: () => ReadonlyArray<CredentialRequirement>;
|
|
1124
|
-
}>): NodeExecutionContext<TConfig>;
|
|
1125
|
-
}
|
|
1126
|
-
//#endregion
|
|
1127
1194
|
//#region src/nodes/aiAgentSupport.types.d.ts
|
|
1128
1195
|
declare class AgentItemPortMap {
|
|
1129
1196
|
static fromItem(item: Item): NodeInputsByPort;
|
|
@@ -1136,9 +1203,15 @@ type ResolvedTool = Readonly<{
|
|
|
1136
1203
|
execute(args: ToolExecuteArgs<ToolConfig, unknown>): Promise<unknown>;
|
|
1137
1204
|
}>;
|
|
1138
1205
|
}>;
|
|
1206
|
+
/**
|
|
1207
|
+
* Per-item binding of a tool: the user config plus the resolved runtime and a snapshot of the
|
|
1208
|
+
* original Zod `inputSchema` used to convert to AI SDK `Tool` + OpenAI-strict JSON Schema for
|
|
1209
|
+
* repair prompts.
|
|
1210
|
+
*/
|
|
1139
1211
|
type ItemScopedToolBinding = Readonly<{
|
|
1140
1212
|
config: ToolConfig;
|
|
1141
|
-
|
|
1213
|
+
inputSchema: ZodSchemaAny;
|
|
1214
|
+
execute(input: unknown): Promise<unknown>;
|
|
1142
1215
|
}>;
|
|
1143
1216
|
type PlannedToolCall = Readonly<{
|
|
1144
1217
|
binding: ItemScopedToolBinding;
|
|
@@ -1153,30 +1226,33 @@ type ExecutedToolCall = Readonly<{
|
|
|
1153
1226
|
serialized: string;
|
|
1154
1227
|
}>;
|
|
1155
1228
|
//#endregion
|
|
1156
|
-
//#region src/nodes/
|
|
1229
|
+
//#region src/nodes/AgentMessageFactory.d.ts
|
|
1157
1230
|
/**
|
|
1158
|
-
*
|
|
1159
|
-
*
|
|
1231
|
+
* AI-SDK-shaped message construction for the AIAgent stack. Emits plain `ModelMessage[]`
|
|
1232
|
+
* ( `{ role: 'system' | 'user' | 'assistant' | 'tool', content: ... }` ) as consumed by
|
|
1233
|
+
* `generateText({ messages })` from the `ai` package.
|
|
1160
1234
|
*/
|
|
1161
|
-
declare class
|
|
1162
|
-
|
|
1163
|
-
createDynamicStructuredTool(entry: ResolvedTool, toolCredentialContext: NodeExecutionContext<any>, item: Item, itemIndex: number, items: Items): DynamicStructuredTool;
|
|
1235
|
+
declare class AgentMessageFactory {
|
|
1236
|
+
static createPromptMessages(messages: ReadonlyArray<AgentMessageDto>): ReadonlyArray<ModelMessage>;
|
|
1164
1237
|
/**
|
|
1165
|
-
*
|
|
1166
|
-
*
|
|
1167
|
-
* expects (`required` must be an array; draft 2020-12 output can break validation).
|
|
1168
|
-
* - Otherwise LangChain `toJsonSchema` (Standard Schema + JSON passthrough); if the result is still Zod
|
|
1169
|
-
* (duplicate `zod` copies), fall back to Zod `toJSONSchema` with draft-07.
|
|
1170
|
-
* - Strip root `$schema` for OpenAI; normalize invalid `required` keywords for cfworker; ensure `properties`.
|
|
1238
|
+
* Builds the assistant message that contains optional text plus one or more tool-call parts,
|
|
1239
|
+
* matching the shape AI SDK emits between steps.
|
|
1171
1240
|
*/
|
|
1172
|
-
|
|
1173
|
-
schemaName: string;
|
|
1174
|
-
requireObjectRoot: boolean;
|
|
1175
|
-
}>): Record<string, unknown>;
|
|
1241
|
+
static createAssistantWithToolCalls(text: string | undefined, toolCalls: ReadonlyArray<AgentToolCall>): AssistantModelMessage;
|
|
1176
1242
|
/**
|
|
1177
|
-
*
|
|
1243
|
+
* Builds the `{ role: "tool", content: [{ type: "tool-result", ... }, ...] }` message returned
|
|
1244
|
+
* to the model after each tool round.
|
|
1178
1245
|
*/
|
|
1179
|
-
|
|
1246
|
+
static createToolResultsMessage(executedToolCalls: ReadonlyArray<ExecutedToolCall>): ToolModelMessage;
|
|
1247
|
+
private static toToolResultJson;
|
|
1248
|
+
private static createPromptMessage;
|
|
1249
|
+
}
|
|
1250
|
+
//#endregion
|
|
1251
|
+
//#region src/nodes/AgentOutputFactory.d.ts
|
|
1252
|
+
declare class AgentOutputFactory {
|
|
1253
|
+
static fromUnknown(value: unknown): NodeOutputs;
|
|
1254
|
+
static replaceJson(item: Item, value: unknown): Item;
|
|
1255
|
+
static fromAgentContent(content: string): unknown;
|
|
1180
1256
|
}
|
|
1181
1257
|
//#endregion
|
|
1182
1258
|
//#region src/nodes/AgentStructuredOutputRepairPromptFactory.d.ts
|
|
@@ -1195,26 +1271,46 @@ declare class AgentStructuredOutputRepairPromptFactory {
|
|
|
1195
1271
|
}
|
|
1196
1272
|
//#endregion
|
|
1197
1273
|
//#region src/nodes/AgentStructuredOutputRunner.d.ts
|
|
1274
|
+
type StructuredOutputSchemaForModel = ZodSchemaAny | Readonly<Record<string, unknown>>;
|
|
1275
|
+
/**
|
|
1276
|
+
* Orchestrates a 2-attempt repair loop on top of `generateText({ output: Output.object(...) })`.
|
|
1277
|
+
*
|
|
1278
|
+
* Strategy:
|
|
1279
|
+
* 1. If the caller already has a raw final text (from a prior tool-calling turn), try parsing it
|
|
1280
|
+
* directly against the schema — fast path for models that already emit strict JSON.
|
|
1281
|
+
* 2. Otherwise, run a native structured-output call via {@link invokeStructuredModel}. For the
|
|
1282
|
+
* OpenAI-strict path, a {@link OpenAiStrictJsonSchemaFactory}-built JSON Schema record is
|
|
1283
|
+
* handed to AI SDK's `jsonSchema(...)` wrapper (preserves `additionalProperties: false` at
|
|
1284
|
+
* every object depth).
|
|
1285
|
+
* 3. If the structured call fails (AI_NoObjectGeneratedError / ZodError / schema reject), run a
|
|
1286
|
+
* text-mode repair prompt with the validation error appended, up to 2 attempts.
|
|
1287
|
+
*/
|
|
1198
1288
|
declare class AgentStructuredOutputRunner {
|
|
1199
1289
|
private readonly repairPromptFactory;
|
|
1200
|
-
private readonly
|
|
1290
|
+
private readonly openAiStrictJsonSchemaFactory;
|
|
1201
1291
|
private static readonly repairAttemptCount;
|
|
1202
|
-
|
|
1292
|
+
private static readonly structuredOutputSchemaName;
|
|
1293
|
+
constructor(repairPromptFactory: AgentStructuredOutputRepairPromptFactory, openAiStrictJsonSchemaFactory: OpenAiStrictJsonSchemaFactory);
|
|
1203
1294
|
resolve<TOutput>(args: Readonly<{
|
|
1204
|
-
model:
|
|
1295
|
+
model: ChatLanguageModel;
|
|
1205
1296
|
chatModelConfig: ChatModelConfig;
|
|
1206
1297
|
schema: ZodSchemaAny;
|
|
1207
|
-
conversation: ReadonlyArray<
|
|
1208
|
-
|
|
1298
|
+
conversation: ReadonlyArray<ModelMessage>;
|
|
1299
|
+
rawFinalText?: string;
|
|
1209
1300
|
agentName: string;
|
|
1210
1301
|
nodeId: string;
|
|
1211
|
-
invokeTextModel: (messages: ReadonlyArray<
|
|
1212
|
-
|
|
1302
|
+
invokeTextModel: (messages: ReadonlyArray<ModelMessage>) => Promise<{
|
|
1303
|
+
text: string;
|
|
1304
|
+
}>;
|
|
1305
|
+
invokeStructuredModel: (schema: StructuredOutputSchemaForModel, messages: ReadonlyArray<ModelMessage>, options: StructuredOutputOptions | undefined) => Promise<unknown>;
|
|
1213
1306
|
}>): Promise<TOutput>;
|
|
1214
1307
|
private retryWithRepairPrompt;
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1308
|
+
/**
|
|
1309
|
+
* Chooses strict mode for OpenAI chat-model configs, off otherwise. Extendable in future for
|
|
1310
|
+
* other providers that adopt the same "supply a JSON Schema record directly" contract.
|
|
1311
|
+
*/
|
|
1312
|
+
private resolveStructuredOutputOptions;
|
|
1313
|
+
private resolveOutputSchemaForModel;
|
|
1218
1314
|
private tryParseAndValidate;
|
|
1219
1315
|
private tryValidateStructuredValue;
|
|
1220
1316
|
private summarizeError;
|
|
@@ -1321,7 +1417,6 @@ declare class AgentToolExecutionCoordinator {
|
|
|
1321
1417
|
private createRepairPayload;
|
|
1322
1418
|
private createRepairDetails;
|
|
1323
1419
|
private createValidationMessage;
|
|
1324
|
-
private parseToolOutput;
|
|
1325
1420
|
private toJsonValue;
|
|
1326
1421
|
private extractErrorDetails;
|
|
1327
1422
|
private serializeIssue;
|
|
@@ -1363,28 +1458,21 @@ declare class AIAgentNode implements RunnableNode<AIAgent<any, any>> {
|
|
|
1363
1458
|
private readonly toolExecutionCoordinator;
|
|
1364
1459
|
kind: "node";
|
|
1365
1460
|
outputPorts: readonly ["main"];
|
|
1366
|
-
/**
|
|
1367
|
-
* Engine validates {@link RunnableNodeConfig.inputSchema} (Zod) on {@code item.json} before enqueue, then resolves
|
|
1368
|
-
* per-item **`itemExpr`** leaves on config before {@link #execute}. Prefer modeling prompts as
|
|
1369
|
-
* {@code { messages: [{ role, content }, ...] }} (on input or config) so persisted inputs are visible in the UI.
|
|
1370
|
-
*/
|
|
1371
1461
|
readonly inputSchema: z.ZodUnknown;
|
|
1372
1462
|
private readonly connectionCredentialExecutionContextFactory;
|
|
1373
|
-
/** One resolved model/tools bundle per activation context (same ctx across items in a batch). */
|
|
1374
1463
|
private readonly preparedByExecutionContext;
|
|
1375
1464
|
constructor(nodeResolver: NodeResolver, credentialSessions: CredentialSessionService, nodeBackedToolRuntime: NodeBackedToolRuntime, executionHelpers: AIAgentExecutionHelpersFactory, structuredOutputRunner: AgentStructuredOutputRunner, toolExecutionCoordinator: AgentToolExecutionCoordinator);
|
|
1376
1465
|
execute(args: RunnableNodeExecuteArgs<AIAgent<any, any>>): Promise<unknown>;
|
|
1377
1466
|
private getOrPrepareExecution;
|
|
1378
|
-
/**
|
|
1379
|
-
* Resolves the chat model and tools once per activation, then reuses for every item in the batch.
|
|
1380
|
-
*/
|
|
1381
1467
|
private prepareExecution;
|
|
1382
|
-
/**
|
|
1383
|
-
* One item: build prompts, optionally bind tools, run the multi-turn loop, map the final model message to workflow JSON.
|
|
1384
|
-
*/
|
|
1385
1468
|
private runAgentForItem;
|
|
1386
1469
|
/**
|
|
1387
|
-
*
|
|
1470
|
+
* Multi-turn loop:
|
|
1471
|
+
* - Each turn is a single `generateText` call with tools exposed but **not auto-executed**
|
|
1472
|
+
* (we control tool dispatch so that {@link AgentToolExecutionCoordinator} drives repair /
|
|
1473
|
+
* connection-invocation recording / transient-error handling exactly like before).
|
|
1474
|
+
* - When the model returns no tool calls the loop ends with the model's text as the final answer.
|
|
1475
|
+
* - Respects `guardrails.maxTurns` and `guardrails.onTurnLimitReached`.
|
|
1388
1476
|
*/
|
|
1389
1477
|
private runTurnLoopUntilFinalAnswer;
|
|
1390
1478
|
private cannotExecuteAnotherToolRound;
|
|
@@ -1392,20 +1480,44 @@ declare class AIAgentNode implements RunnableNode<AIAgent<any, any>> {
|
|
|
1392
1480
|
private appendAssistantAndToolMessages;
|
|
1393
1481
|
private resolveFinalOutputJson;
|
|
1394
1482
|
private buildOutputItem;
|
|
1395
|
-
private bindToolsToModel;
|
|
1396
1483
|
private resolveTools;
|
|
1397
1484
|
private createItemScopedTools;
|
|
1398
|
-
|
|
1399
|
-
|
|
1485
|
+
/**
|
|
1486
|
+
* Builds an AI SDK {@link ToolSet} where every tool ships a pre-converted JSON Schema (via
|
|
1487
|
+
* {@link jsonSchema}) — not the raw Zod schema — and carries **no** `execute`. Two reasons:
|
|
1488
|
+
*
|
|
1489
|
+
* 1. Codemation owns tool dispatch + the per-tool repair loop (see {@link AgentToolExecutionCoordinator}),
|
|
1490
|
+
* so the AI SDK must surface tool calls back to us instead of auto-running them.
|
|
1491
|
+
* 2. The AI SDK's `asSchema` helper discriminates between Zod v3 / Zod v4 / Standard Schema via
|
|
1492
|
+
* runtime feature-detection (`~standard`, `_zod`, etc.). Handing it a pre-built
|
|
1493
|
+
* {@link jsonSchema} record — which is tagged with `Symbol.for('vercel.ai.schema')` — skips all
|
|
1494
|
+
* of that detection and guarantees the provider receives a draft-07 JSON Schema with
|
|
1495
|
+
* `additionalProperties: false` at every object depth (see {@link OpenAiStrictJsonSchemaFactory}
|
|
1496
|
+
* for the same logic applied to structured-output schemas). Codemation still runs its own Zod
|
|
1497
|
+
* validation on tool inputs before execute — the schema handed to the model is advisory.
|
|
1498
|
+
*/
|
|
1499
|
+
private buildToolSet;
|
|
1500
|
+
/**
|
|
1501
|
+
* One `generateText` turn (no auto tool execution) with Codemation-owned child-span telemetry
|
|
1502
|
+
* and connection-invocation state recording.
|
|
1503
|
+
*/
|
|
1504
|
+
private invokeTextTurn;
|
|
1505
|
+
/**
|
|
1506
|
+
* Structured-output turn: runs `generateText({ output: Output.object({ schema }) })` via the
|
|
1507
|
+
* structured-output runner. We keep this as a separate helper because the runner needs the raw
|
|
1508
|
+
* validated value (not just text) back, and must be able to retry on Zod failures.
|
|
1509
|
+
*/
|
|
1510
|
+
private invokeStructuredTurn;
|
|
1511
|
+
private isZodSchema;
|
|
1512
|
+
private resolveCallOptions;
|
|
1513
|
+
private extractTurnResult;
|
|
1514
|
+
private extractAssistantMessage;
|
|
1515
|
+
private extractUsageFromResult;
|
|
1516
|
+
private toFiniteNumber;
|
|
1400
1517
|
private createModelInvocationSpan;
|
|
1401
1518
|
private recordModelUsageMetrics;
|
|
1402
1519
|
private captureCostTrackingUsage;
|
|
1403
1520
|
private resolveChatModelName;
|
|
1404
|
-
private extractModelUsageMetrics;
|
|
1405
|
-
private extractUsageObject;
|
|
1406
|
-
private readUsageNumber;
|
|
1407
|
-
private readNestedUsageValue;
|
|
1408
|
-
private isRecord;
|
|
1409
1521
|
private markQueuedTools;
|
|
1410
1522
|
private planToolCalls;
|
|
1411
1523
|
private failTrackedNodeInvocation;
|
|
@@ -1413,15 +1525,7 @@ declare class AIAgentNode implements RunnableNode<AIAgent<any, any>> {
|
|
|
1413
1525
|
private resultToJsonValue;
|
|
1414
1526
|
private createPromptMessages;
|
|
1415
1527
|
private resolveToolRuntime;
|
|
1416
|
-
/**
|
|
1417
|
-
* Consumer apps can resolve two copies of `@codemation/core`, breaking `instanceof NodeBackedToolConfig` and
|
|
1418
|
-
* sending node-backed tools down the plugin-tool branch with `inputSchema: undefined` (LangChain then crashes in
|
|
1419
|
-
* json-schema validation). {@link NodeBackedToolConfig#toolKind} is stable across copies.
|
|
1420
|
-
*/
|
|
1421
1528
|
private isNodeBackedToolConfig;
|
|
1422
|
-
/**
|
|
1423
|
-
* Callable tools use {@link CallableToolConfig#toolKind} for cross-package / JSON round-trip safety.
|
|
1424
|
-
*/
|
|
1425
1529
|
private isCallableToolConfig;
|
|
1426
1530
|
private resolveGuardrails;
|
|
1427
1531
|
private getAgentDisplayName;
|
|
@@ -2030,5 +2134,5 @@ declare class AIAgentConnectionWorkflowExpander {
|
|
|
2030
2134
|
private assertNoIdCollision;
|
|
2031
2135
|
}
|
|
2032
2136
|
//#endregion
|
|
2033
|
-
export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentStructuredOutputRepairPromptFactory, AgentStructuredOutputRunner, AgentToolCallPortMap, AgentToolErrorClassifier, AgentToolExecutionCoordinator, AgentToolRepairExhaustedError, AgentToolRepairPolicy, Aggregate, AggregateNode, Callback, CallbackHandler, CallbackNode, CallbackOptions, CallbackResultNormalizer, CanvasIconName, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, type ExecutedToolCall, Filter, FilterNode, HttpRequest, HttpRequestDownloadMode, HttpRequestNode, HttpRequestOutputJson, If, IfNode, type ItemScopedToolBinding, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, MapDataOptions, Merge, MergeMode, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory,
|
|
2137
|
+
export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentStructuredOutputRepairPromptFactory, AgentStructuredOutputRunner, AgentToolCallPortMap, AgentToolErrorClassifier, AgentToolExecutionCoordinator, AgentToolRepairExhaustedError, AgentToolRepairPolicy, Aggregate, AggregateNode, Callback, CallbackHandler, CallbackNode, CallbackOptions, CallbackResultNormalizer, CanvasIconName, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, type ExecutedToolCall, Filter, FilterNode, HttpRequest, HttpRequestDownloadMode, HttpRequestNode, HttpRequestOutputJson, If, IfNode, type ItemScopedToolBinding, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, MapDataOptions, Merge, MergeMode, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAiChatModelPresets, OpenAiCredentialSession, OpenAiStrictJsonSchemaFactory, type PlannedToolCall, type ResolvedTool, Split, SplitNode, SubWorkflow, SubWorkflowNode, Switch, SwitchCaseKeyResolver, SwitchNode, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, type WorkflowAgentMessages, type WorkflowAgentOptions, WorkflowAuthoringBuilder, WorkflowBranchBuilder, WorkflowChain, createWorkflowBuilder, openAiChatModelPresets, registerCoreNodes, workflow };
|
|
2034
2138
|
//# sourceMappingURL=index.d.ts.map
|