@codemation/core-nodes 0.0.13 → 0.0.15

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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { HumanMessage, SystemMessage, ToolMessage } from "@langchain/core/messages";
1
+ import { AIMessage, BaseMessage, HumanMessage, SystemMessage, ToolMessage } from "@langchain/core/messages";
2
2
  import { DynamicStructuredTool } from "@langchain/core/tools";
3
3
  import { ReadableStream } from "node:stream/web";
4
4
  import { DependencyContainer as Container, InjectionToken as TypeToken } from "tsyringe";
@@ -321,6 +321,7 @@ interface TriggerNodeConfig<TOutputJson$1 = unknown, TSetupState$1 extends JsonV
321
321
  readonly [triggerNodeOutputType]?: TOutputJson$1;
322
322
  readonly [triggerNodeSetupStateType]?: TSetupState$1;
323
323
  }
324
+ type RunnableNodeInputJson<TConfig extends RunnableNodeConfig<any, any>> = TConfig extends RunnableNodeConfig<infer TInputJson, any> ? TInputJson : never;
324
325
  type RunnableNodeOutputJson<TConfig extends RunnableNodeConfig<any, any>> = TConfig extends RunnableNodeConfig<any, infer TOutputJson> ? TOutputJson : never;
325
326
  type TriggerNodeOutputJson<TConfig extends TriggerNodeConfig<any, any>> = TConfig extends TriggerNodeConfig<infer TOutputJson, any> ? TOutputJson : never;
326
327
  type TriggerNodeSetupState<TConfig extends TriggerNodeConfig<any, any>> = TConfig extends TriggerNodeConfig<any, infer TSetupState> ? TSetupState : never;
@@ -508,6 +509,28 @@ declare class WorkflowBuilder {
508
509
  build(): WorkflowDefinition;
509
510
  }
510
511
  //#endregion
512
+ //#region ../core/src/ai/NodeBackedToolConfig.d.ts
513
+ declare class NodeBackedToolConfig<TNodeConfig extends RunnableNodeConfig<any, any>, TInputSchema extends ZodSchemaAny, TOutputSchema extends ZodSchemaAny> implements ToolConfig {
514
+ readonly name: string;
515
+ readonly node: TNodeConfig;
516
+ readonly type: TypeToken<unknown>;
517
+ readonly toolKind: "nodeBacked";
518
+ readonly description?: string;
519
+ readonly presentation?: AgentCanvasPresentation;
520
+ private readonly inputSchemaValue;
521
+ private readonly outputSchemaValue;
522
+ private readonly mapInputValue?;
523
+ private readonly mapOutputValue?;
524
+ constructor(name: string, node: TNodeConfig, options: NodeBackedToolConfigOptions<TNodeConfig, TInputSchema, TOutputSchema>);
525
+ getCredentialRequirements(): ReadonlyArray<CredentialRequirement>;
526
+ getInputSchema(): TInputSchema;
527
+ getOutputSchema(): TOutputSchema;
528
+ toNodeItem(args: NodeBackedToolInputMapperArgs<TNodeConfig, input<TInputSchema>>): Item<RunnableNodeInputJson<TNodeConfig>>;
529
+ toToolOutput(args: NodeBackedToolOutputMapperArgs<TNodeConfig, input<TInputSchema>>): output<TOutputSchema>;
530
+ private readDefaultToolOutput;
531
+ private isItem;
532
+ }
533
+ //#endregion
511
534
  //#region ../core/src/ai/AiHost.d.ts
512
535
  interface AgentCanvasPresentation<TIcon extends string = string> {
513
536
  readonly label?: string;
@@ -515,7 +538,7 @@ interface AgentCanvasPresentation<TIcon extends string = string> {
515
538
  }
516
539
  type ZodSchemaAny = ZodType<any, any, any>;
517
540
  interface ToolConfig {
518
- readonly type: TypeToken<Tool<ToolConfig, ZodSchemaAny, ZodSchemaAny>>;
541
+ readonly type: TypeToken<unknown>;
519
542
  readonly name: string;
520
543
  readonly description?: string;
521
544
  readonly presentation?: AgentCanvasPresentation;
@@ -529,11 +552,41 @@ type ToolExecuteArgs<TConfig extends ToolConfig = ToolConfig, TInput = unknown>
529
552
  itemIndex: number;
530
553
  items: Items;
531
554
  }>;
532
- interface Tool<TConfig extends ToolConfig = ToolConfig, TInputSchema extends ZodSchemaAny = ZodSchemaAny, TOutputSchema extends ZodSchemaAny = ZodSchemaAny> {
533
- readonly defaultDescription: string;
534
- readonly inputSchema: TInputSchema;
535
- readonly outputSchema: TOutputSchema;
536
- execute(args: ToolExecuteArgs<TConfig, input<TInputSchema>>): Promise<output<TOutputSchema>> | output<TOutputSchema>;
555
+ type AgentMessageRole = "system" | "user" | "assistant";
556
+ type AgentMessageBuildArgs<TInputJson$1 = unknown> = Readonly<{
557
+ item: Item<TInputJson$1>;
558
+ itemIndex: number;
559
+ items: Items<TInputJson$1>;
560
+ ctx: NodeExecutionContext<any>;
561
+ }>;
562
+ interface AgentMessageDto {
563
+ readonly role: AgentMessageRole;
564
+ readonly content: string;
565
+ }
566
+ type AgentMessageTemplateContent<TInputJson$1 = unknown> = string | ((args: AgentMessageBuildArgs<TInputJson$1>) => string);
567
+ interface AgentMessageTemplate<TInputJson$1 = unknown> {
568
+ readonly role: AgentMessageRole;
569
+ readonly content: AgentMessageTemplateContent<TInputJson$1>;
570
+ }
571
+ /** A single prompt line: fixed DTO or template with optional function `content`. */
572
+ type AgentMessageLine<TInputJson$1 = unknown> = AgentMessageDto | AgentMessageTemplate<TInputJson$1>;
573
+ /**
574
+ * Message list for an agent. Prefer a **plain array** of `{ role, content }` (optionally with function `content` for templates).
575
+ * Use the object form only when you need `buildMessages` to append messages after optional `prompt` lines.
576
+ */
577
+ type AgentMessageConfig<TInputJson$1 = unknown> = ReadonlyArray<AgentMessageLine<TInputJson$1>> | {
578
+ readonly prompt?: ReadonlyArray<AgentMessageLine<TInputJson$1>>;
579
+ readonly buildMessages?: (args: AgentMessageBuildArgs<TInputJson$1>) => ReadonlyArray<AgentMessageDto>;
580
+ };
581
+ type AgentTurnLimitBehavior = "error" | "respondWithLastMessage";
582
+ interface AgentModelInvocationOptions {
583
+ readonly maxTokens?: number;
584
+ readonly providerOptions?: Readonly<Record<string, JsonValue>>;
585
+ }
586
+ interface AgentGuardrailConfig {
587
+ readonly maxTurns?: number;
588
+ readonly onTurnLimitReached?: AgentTurnLimitBehavior;
589
+ readonly modelInvocationOptions?: AgentModelInvocationOptions;
537
590
  }
538
591
  type AgentToolCall = Readonly<{
539
592
  id?: string;
@@ -556,11 +609,38 @@ interface ChatModelFactory<TConfig extends ChatModelConfig = ChatModelConfig> {
556
609
  ctx: NodeExecutionContext<any>;
557
610
  }>): Promise<LangChainChatModelLike> | LangChainChatModelLike;
558
611
  }
612
+ type NodeBackedToolInputMapperArgs<TNodeConfig extends RunnableNodeConfig<any, any>, TToolInput = unknown> = Readonly<{
613
+ input: TToolInput;
614
+ item: Item;
615
+ itemIndex: number;
616
+ items: Items;
617
+ ctx: NodeExecutionContext<any>;
618
+ node: TNodeConfig;
619
+ }>;
620
+ type NodeBackedToolOutputMapperArgs<TNodeConfig extends RunnableNodeConfig<any, any>, TToolInput = unknown> = Readonly<{
621
+ input: TToolInput;
622
+ item: Item;
623
+ itemIndex: number;
624
+ items: Items;
625
+ ctx: NodeExecutionContext<any>;
626
+ node: TNodeConfig;
627
+ outputs: NodeOutputs;
628
+ }>;
629
+ type NodeBackedToolInputMapper<TNodeConfig extends RunnableNodeConfig<any, any>, TToolInput = unknown> = (args: NodeBackedToolInputMapperArgs<TNodeConfig, TToolInput>) => Item<RunnableNodeInputJson<TNodeConfig>> | RunnableNodeInputJson<TNodeConfig>;
630
+ type NodeBackedToolOutputMapper<TNodeConfig extends RunnableNodeConfig<any, any>, TToolInput = unknown, TToolOutput = unknown> = (args: NodeBackedToolOutputMapperArgs<TNodeConfig, TToolInput>) => TToolOutput;
631
+ type NodeBackedToolConfigOptions<TNodeConfig extends RunnableNodeConfig<any, any>, TInputSchema extends ZodSchemaAny, TOutputSchema extends ZodSchemaAny> = Readonly<{
632
+ description?: string;
633
+ presentation?: AgentCanvasPresentation;
634
+ inputSchema: TInputSchema;
635
+ outputSchema: TOutputSchema;
636
+ mapInput?: NodeBackedToolInputMapper<TNodeConfig, input<TInputSchema>>;
637
+ mapOutput?: NodeBackedToolOutputMapper<TNodeConfig, input<TInputSchema>, output<TOutputSchema>>;
638
+ }>;
559
639
  interface AgentNodeConfig<TInputJson$1 = unknown, TOutputJson$1 = unknown> extends RunnableNodeConfig<TInputJson$1, TOutputJson$1> {
560
- readonly systemMessage: string;
561
- readonly userMessageFormatter: (item: Item<TInputJson$1>, index: number, items: Items<TInputJson$1>, ctx: NodeExecutionContext<any>) => string;
640
+ readonly messages: AgentMessageConfig<TInputJson$1>;
562
641
  readonly chatModel: ChatModelConfig;
563
642
  readonly tools?: ReadonlyArray<ToolConfig>;
643
+ readonly guardrails?: AgentGuardrailConfig;
564
644
  }
565
645
  //#endregion
566
646
  //#region src/chatModels/openAiChatModelConfig.d.ts
@@ -610,12 +690,15 @@ declare const openAiChatModelPresets: OpenAiChatModelPresets;
610
690
  //#endregion
611
691
  //#region src/nodes/AgentMessageFactory.d.ts
612
692
  declare class AgentMessageFactory {
693
+ static createPromptMessages(messages: ReadonlyArray<AgentMessageDto>): ReadonlyArray<BaseMessage>;
613
694
  static createSystemPrompt(systemMessage: string): SystemMessage;
614
695
  static createUserPrompt(prompt: string): HumanMessage;
696
+ static createAssistantPrompt(prompt: string): AIMessage;
615
697
  static createToolMessage(toolCallId: string, content: string): ToolMessage;
616
698
  static extractContent(message: unknown): string;
617
699
  static extractToolCalls(message: unknown): ReadonlyArray<AgentToolCall>;
618
700
  private static isRecord;
701
+ private static createPromptMessage;
619
702
  }
620
703
  //#endregion
621
704
  //#region src/nodes/AgentOutputFactory.d.ts
@@ -631,46 +714,49 @@ declare class AgentToolCallPortMap {
631
714
  }
632
715
  //#endregion
633
716
  //#region src/nodes/AIAgentConfig.d.ts
717
+ interface AIAgentOptions<TInputJson$1 = unknown, _TOutputJson = unknown> {
718
+ readonly name: string;
719
+ readonly messages: AgentMessageConfig<TInputJson$1>;
720
+ readonly chatModel: ChatModelConfig;
721
+ readonly tools?: ReadonlyArray<ToolConfig>;
722
+ readonly id?: string;
723
+ readonly retryPolicy?: RetryPolicySpec;
724
+ readonly guardrails?: AgentGuardrailConfig;
725
+ }
634
726
  /**
635
727
  * AI agent: credential bindings are keyed to connection-owned LLM/tool node ids (ConnectionNodeIdFactory),
636
728
  * not to the agent workflow node id.
637
729
  */
638
730
  declare class AIAgent<TInputJson$1 = unknown, TOutputJson$1 = unknown> implements RunnableNodeConfig<TInputJson$1, TOutputJson$1>, AgentNodeConfig<TInputJson$1, TOutputJson$1> {
639
- readonly name: string;
640
- readonly systemMessage: string;
641
- readonly userMessageFormatter: (item: Item<TInputJson$1>, index: number, items: Items<TInputJson$1>, ctx: NodeExecutionContext<AIAgent<TInputJson$1, TOutputJson$1>>) => string;
642
- readonly chatModel: ChatModelConfig;
643
- readonly tools: ReadonlyArray<ToolConfig>;
644
- readonly id?: string | undefined;
645
- readonly retryPolicy: RetryPolicySpec;
646
731
  readonly kind: "node";
647
732
  readonly type: TypeToken<unknown>;
648
733
  readonly execution: {
649
734
  readonly hint: "local";
650
735
  };
651
736
  readonly icon: "lucide:bot";
652
- constructor(name: string, systemMessage: string, userMessageFormatter: (item: Item<TInputJson$1>, index: number, items: Items<TInputJson$1>, ctx: NodeExecutionContext<AIAgent<TInputJson$1, TOutputJson$1>>) => string, chatModel: ChatModelConfig, tools?: ReadonlyArray<ToolConfig>, id?: string | undefined, retryPolicy?: RetryPolicySpec);
737
+ readonly name: string;
738
+ readonly messages: AgentMessageConfig<TInputJson$1>;
739
+ readonly chatModel: ChatModelConfig;
740
+ readonly tools: ReadonlyArray<ToolConfig>;
741
+ readonly id?: string;
742
+ readonly retryPolicy: RetryPolicySpec;
743
+ readonly guardrails?: AgentGuardrailConfig;
744
+ constructor(options: AIAgentOptions<TInputJson$1, TOutputJson$1>);
653
745
  }
654
746
  //#endregion
655
- //#region src/nodes/AIAgentNodeFactory.d.ts
656
- declare class AIAgentNode implements Node<AIAgent<any, any>> {
657
- private readonly nodeResolver;
658
- kind: "node";
659
- outputPorts: readonly ["main"];
660
- private readonly connectionCredentialExecutionContextFactory;
661
- constructor(nodeResolver: NodeResolver, credentialSessions: CredentialSessionService);
662
- execute(items: Items, ctx: NodeExecutionContext<AIAgent<any, any>>): Promise<NodeOutputs>;
663
- private resolveTools;
664
- private createItemScopedTools;
665
- private invokeModel;
666
- private markQueuedTools;
667
- private executeToolCalls;
668
- private planToolCalls;
669
- private parseToolOutput;
670
- private failTrackedNodeInvocation;
671
- private summarizeLlmMessages;
672
- private toolCallInputToJson;
673
- private resultToJsonValue;
747
+ //#region src/nodes/ConnectionCredentialExecutionContextFactory.d.ts
748
+ /**
749
+ * Builds a {@link NodeExecutionContext} whose identity for credential binding and `getCredential`
750
+ * is a **connection-owned** workflow node id (`ConnectionNodeIdFactory` in `@codemation/core`),
751
+ * not the executing parent node. Use for LLM slots, tool slots, or any connection-scoped owner.
752
+ */
753
+ declare class ConnectionCredentialExecutionContextFactory {
754
+ private readonly credentialResolverFactory;
755
+ constructor(credentialSessions: CredentialSessionService);
756
+ forConnectionNode<TConfig extends NodeConfigBase>(ctx: NodeExecutionContext<TConfig>, args: Readonly<{
757
+ connectionNodeId: NodeId;
758
+ getCredentialRequirements: () => ReadonlyArray<CredentialRequirement>;
759
+ }>): NodeExecutionContext<TConfig>;
674
760
  }
675
761
  //#endregion
676
762
  //#region src/nodes/aiAgentSupport.types.d.ts
@@ -679,7 +765,11 @@ declare class AgentItemPortMap {
679
765
  }
680
766
  type ResolvedTool = Readonly<{
681
767
  config: ToolConfig;
682
- tool: Tool<ToolConfig, ZodSchemaAny, ZodSchemaAny>;
768
+ runtime: Readonly<{
769
+ defaultDescription: string;
770
+ inputSchema: ZodSchemaAny;
771
+ execute(args: ToolExecuteArgs<ToolConfig, unknown>): Promise<unknown>;
772
+ }>;
683
773
  }>;
684
774
  type ItemScopedToolBinding = Readonly<{
685
775
  config: ToolConfig;
@@ -698,6 +788,69 @@ type ExecutedToolCall = Readonly<{
698
788
  serialized: string;
699
789
  }>;
700
790
  //#endregion
791
+ //#region src/nodes/AIAgentExecutionHelpersFactory.d.ts
792
+ /**
793
+ * LangChain adapters and credential context wiring for {@link AIAgentNode}.
794
+ * Lives in a `*Factory.ts` composition-root module so construction stays explicit and testable.
795
+ */
796
+ declare class AIAgentExecutionHelpersFactory {
797
+ createConnectionCredentialExecutionContextFactory(credentialSessions: CredentialSessionService): ConnectionCredentialExecutionContextFactory;
798
+ createDynamicStructuredTool(entry: ResolvedTool, toolCredentialContext: NodeExecutionContext<any>, item: Item, itemIndex: number, items: Items): DynamicStructuredTool;
799
+ }
800
+ //#endregion
801
+ //#region src/nodes/NodeBackedToolRuntime.d.ts
802
+ declare class NodeBackedToolRuntime {
803
+ private readonly nodeResolver;
804
+ constructor(nodeResolver: NodeResolver);
805
+ execute(config: NodeBackedToolConfig<any, ZodSchemaAny, ZodSchemaAny>, args: ToolExecuteArgs): Promise<unknown>;
806
+ private executeResolvedNode;
807
+ private isNode;
808
+ private isMultiInputNode;
809
+ }
810
+ //#endregion
811
+ //#region src/nodes/AIAgentNode.d.ts
812
+ declare class AIAgentNode implements Node<AIAgent<any, any>> {
813
+ private readonly nodeResolver;
814
+ private readonly nodeBackedToolRuntime;
815
+ private readonly executionHelpers;
816
+ kind: "node";
817
+ outputPorts: readonly ["main"];
818
+ private readonly connectionCredentialExecutionContextFactory;
819
+ constructor(nodeResolver: NodeResolver, credentialSessions: CredentialSessionService, nodeBackedToolRuntime: NodeBackedToolRuntime, executionHelpers: AIAgentExecutionHelpersFactory);
820
+ execute(items: Items, ctx: NodeExecutionContext<AIAgent<any, any>>): Promise<NodeOutputs>;
821
+ /**
822
+ * Resolves the chat model and tools once, then returns shared state for every item in the batch.
823
+ */
824
+ private prepareExecution;
825
+ /**
826
+ * One item: build prompts, optionally bind tools, run the multi-turn loop, map the final model message to workflow JSON.
827
+ */
828
+ private runAgentForItem;
829
+ /**
830
+ * Repeatedly invokes the model until it returns without tool calls, or guardrails end the loop.
831
+ */
832
+ private runTurnLoopUntilFinalAnswer;
833
+ private cannotExecuteAnotherToolRound;
834
+ private finishOrThrowWhenTurnCapHitWithToolCalls;
835
+ private appendAssistantAndToolMessages;
836
+ private buildOutputItem;
837
+ private bindToolsToModel;
838
+ private resolveTools;
839
+ private createItemScopedTools;
840
+ private invokeModel;
841
+ private markQueuedTools;
842
+ private executeToolCalls;
843
+ private planToolCalls;
844
+ private parseToolOutput;
845
+ private failTrackedNodeInvocation;
846
+ private summarizeLlmMessages;
847
+ private toolCallInputToJson;
848
+ private resultToJsonValue;
849
+ private createPromptMessages;
850
+ private resolveToolRuntime;
851
+ private resolveGuardrails;
852
+ }
853
+ //#endregion
701
854
  //#region src/nodes/CallbackNode.d.ts
702
855
  declare class CallbackNode implements Node<Callback<any, any>> {
703
856
  kind: "node";
@@ -1072,20 +1225,5 @@ declare class AIAgentConnectionWorkflowExpander {
1072
1225
  private assertNoIdCollision;
1073
1226
  }
1074
1227
  //#endregion
1075
- //#region src/nodes/ConnectionCredentialExecutionContextFactory.d.ts
1076
- /**
1077
- * Builds a {@link NodeExecutionContext} whose identity for credential binding and `getCredential`
1078
- * is a **connection-owned** workflow node id (`ConnectionNodeIdFactory` in `@codemation/core`),
1079
- * not the executing parent node. Use for LLM slots, tool slots, or any connection-scoped owner.
1080
- */
1081
- declare class ConnectionCredentialExecutionContextFactory {
1082
- private readonly credentialResolverFactory;
1083
- constructor(credentialSessions: CredentialSessionService);
1084
- forConnectionNode<TConfig extends NodeConfigBase>(ctx: NodeExecutionContext<TConfig>, args: Readonly<{
1085
- connectionNodeId: NodeId;
1086
- getCredentialRequirements: () => ReadonlyArray<CredentialRequirement>;
1087
- }>): NodeExecutionContext<TConfig>;
1088
- }
1089
- //#endregion
1090
- export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentToolCallPortMap, Callback, CallbackHandler, CallbackNode, CallbackResultNormalizer, CanvasIconName, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, type ExecutedToolCall, HttpRequest, HttpRequestDownloadMode, HttpRequestNode, HttpRequestOutputJson, If, IfNode, type ItemScopedToolBinding, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, Merge, MergeMode, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAiChatModelPresets, OpenAiCredentialSession, type PlannedToolCall, type ResolvedTool, SubWorkflow, SubWorkflowNode, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, createWorkflowBuilder, openAiChatModelPresets, registerCoreNodes };
1228
+ export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentToolCallPortMap, Callback, CallbackHandler, CallbackNode, CallbackResultNormalizer, CanvasIconName, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, type ExecutedToolCall, HttpRequest, HttpRequestDownloadMode, HttpRequestNode, HttpRequestOutputJson, If, IfNode, type ItemScopedToolBinding, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, Merge, MergeMode, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAiChatModelPresets, OpenAiCredentialSession, type PlannedToolCall, type ResolvedTool, SubWorkflow, SubWorkflowNode, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, createWorkflowBuilder, openAiChatModelPresets, registerCoreNodes };
1091
1229
  //# sourceMappingURL=index.d.ts.map