@codemation/core-nodes 0.0.15 → 0.0.18

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
@@ -2,7 +2,7 @@ import { AIMessage, BaseMessage, HumanMessage, SystemMessage, ToolMessage } from
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";
5
- import { ZodType, input, output } from "zod";
5
+ import { ZodType, input, output, z } from "zod";
6
6
 
7
7
  //#region src/canvasIconName.d.ts
8
8
  /**
@@ -114,6 +114,68 @@ interface TriggerInstanceId {
114
114
  nodeId: NodeId;
115
115
  }
116
116
  //#endregion
117
+ //#region ../core/src/workflow/dsl/workflowBuilderTypes.d.ts
118
+ type AnyRunnableNodeConfig = RunnableNodeConfig<any, any>;
119
+ type AnyTriggerNodeConfig = TriggerNodeConfig<any>;
120
+ type ValidStepSequence<TCurrentJson, TSteps extends ReadonlyArray<AnyRunnableNodeConfig>> = TSteps extends readonly [] ? readonly [] : TSteps extends readonly [infer TFirst, ...infer TRest] ? TFirst extends RunnableNodeConfig<TCurrentJson, infer TNextJson> ? TRest extends ReadonlyArray<AnyRunnableNodeConfig> ? readonly [TFirst, ...ValidStepSequence<TNextJson, TRest>] : never : never : TSteps;
121
+ type StepSequenceOutput<TCurrentJson, TSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined> = TSteps extends ReadonlyArray<AnyRunnableNodeConfig> ? TSteps extends readonly [] ? TCurrentJson : TSteps extends readonly [infer TFirst, ...infer TRest] ? TFirst extends RunnableNodeConfig<TCurrentJson, infer TNextJson> ? TRest extends ReadonlyArray<AnyRunnableNodeConfig> ? StepSequenceOutput<TNextJson, TRest> : never : never : TCurrentJson : TCurrentJson;
122
+ type TypesMatch<TLeft, TRight> = [TLeft] extends [TRight] ? ([TRight] extends [TLeft] ? true : false) : false;
123
+ type BranchOutputGuard<TCurrentJson, TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined, TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined> = TypesMatch<StepSequenceOutput<TCurrentJson, TTrueSteps>, StepSequenceOutput<TCurrentJson, TFalseSteps>> extends true ? unknown : never;
124
+ type BranchStepsArg<TCurrentJson, TSteps extends ReadonlyArray<AnyRunnableNodeConfig>> = TSteps & ValidStepSequence<TCurrentJson, TSteps>;
125
+ type BranchMoreArgs<TCurrentJson, TFirstStep extends RunnableNodeConfig<TCurrentJson, any>, TRestSteps extends ReadonlyArray<AnyRunnableNodeConfig>> = TRestSteps & ValidStepSequence<RunnableNodeOutputJson<TFirstStep>, TRestSteps>;
126
+ type BooleanWhenOverloads<TCurrentJson, TReturn> = {
127
+ <TSteps extends ReadonlyArray<AnyRunnableNodeConfig>>(branch: boolean, steps: BranchStepsArg<TCurrentJson, TSteps>): TReturn;
128
+ <TFirstStep extends RunnableNodeConfig<TCurrentJson, any>, TRestSteps extends ReadonlyArray<AnyRunnableNodeConfig>>(branch: boolean, step: TFirstStep, ...more: BranchMoreArgs<TCurrentJson, TFirstStep, TRestSteps>): TReturn;
129
+ };
130
+ //#endregion
131
+ //#region ../core/src/workflow/dsl/WhenBuilder.d.ts
132
+ declare class WhenBuilder<TCurrentJson> {
133
+ private readonly wf;
134
+ private readonly from;
135
+ private readonly branchPort;
136
+ constructor(wf: WorkflowBuilder, from: NodeRef, branchPort: OutputPortKey);
137
+ addBranch<TSteps extends ReadonlyArray<AnyRunnableNodeConfig>>(steps: TSteps & ValidStepSequence<TCurrentJson, TSteps>): this;
138
+ readonly when: BooleanWhenOverloads<TCurrentJson, WhenBuilder<TCurrentJson>>;
139
+ build(): WorkflowDefinition;
140
+ }
141
+ //#endregion
142
+ //#region ../core/src/workflow/dsl/ChainCursorResolver.d.ts
143
+ type ChainCursorWhenOverloads<TCurrentJson> = BooleanWhenOverloads<TCurrentJson, WhenBuilder<TCurrentJson>> & {
144
+ <TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined, TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined>(branches: Readonly<{
145
+ true?: TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> ? BranchStepsArg<TCurrentJson, TTrueSteps> : never;
146
+ false?: TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig> ? BranchStepsArg<TCurrentJson, TFalseSteps> : never;
147
+ }> & BranchOutputGuard<TCurrentJson, TTrueSteps, TFalseSteps>): ChainCursor<StepSequenceOutput<TCurrentJson, TTrueSteps>>;
148
+ };
149
+ declare class ChainCursor<TCurrentJson> {
150
+ private readonly wf;
151
+ private readonly cursor;
152
+ private readonly cursorOutput;
153
+ constructor(wf: WorkflowBuilder, cursor: NodeRef, cursorOutput: OutputPortKey);
154
+ then<TConfig extends RunnableNodeConfig<TCurrentJson, any>>(config: TConfig): ChainCursor<RunnableNodeOutputJson<TConfig>>;
155
+ readonly when: ChainCursorWhenOverloads<TCurrentJson>;
156
+ build(): WorkflowDefinition;
157
+ }
158
+ //#endregion
159
+ //#region ../core/src/workflow/dsl/WorkflowBuilder.d.ts
160
+ declare class WorkflowBuilder {
161
+ private readonly meta;
162
+ private readonly options?;
163
+ private readonly nodes;
164
+ private readonly edges;
165
+ private seq;
166
+ constructor(meta: {
167
+ id: WorkflowId;
168
+ name: string;
169
+ }, options?: Readonly<{
170
+ makeMergeNode?: (name: string) => AnyRunnableNodeConfig;
171
+ }> | undefined);
172
+ private add;
173
+ private connect;
174
+ trigger<TConfig extends AnyTriggerNodeConfig>(config: TConfig): ChainCursor<TriggerNodeOutputJson<TConfig>>;
175
+ start<TConfig extends AnyRunnableNodeConfig>(config: TConfig): ChainCursor<RunnableNodeOutputJson<TConfig>>;
176
+ build(): WorkflowDefinition;
177
+ }
178
+ //#endregion
117
179
  //#region ../core/src/contracts/runtimeTypes.d.ts
118
180
  interface WorkflowRunnerService {
119
181
  runById(args: {
@@ -431,6 +493,28 @@ type NodeErrorHandlerSpec = TypeToken<NodeErrorHandler> | NodeErrorHandler;
431
493
  //#endregion
432
494
  //#region ../core/src/contracts/credentialTypes.d.ts
433
495
  type CredentialTypeId = string;
496
+ type CredentialInstanceId = string;
497
+ type CredentialMaterialSourceKind = "db" | "env" | "code";
498
+ type CredentialSetupStatus = "draft" | "ready";
499
+ type CredentialHealthStatus = "unknown" | "healthy" | "failing";
500
+ type CredentialFieldSchema = Readonly<{
501
+ key: string;
502
+ label: string;
503
+ type: "string" | "password" | "textarea" | "json" | "boolean";
504
+ required?: true;
505
+ order?: number;
506
+ placeholder?: string;
507
+ helpText?: string;
508
+ /** When set, host resolves this field from process.env at runtime; env wins over stored values. */
509
+ envVarName?: string;
510
+ /**
511
+ * When set, the dialog shows a copy action for this exact string (e.g. a static OAuth redirect URI
512
+ * pattern or documentation URL). Do not use for secret values.
513
+ */
514
+ copyValue?: string;
515
+ /** Accessible label for the copy control (default: Copy). */
516
+ copyButtonLabel?: string;
517
+ }>;
434
518
  type CredentialRequirement = Readonly<{
435
519
  slotKey: string;
436
520
  label: string;
@@ -439,6 +523,89 @@ type CredentialRequirement = Readonly<{
439
523
  helpText?: string;
440
524
  helpUrl?: string;
441
525
  }>;
526
+ type CredentialHealth = Readonly<{
527
+ status: CredentialHealthStatus;
528
+ message?: string;
529
+ testedAt?: string;
530
+ expiresAt?: string;
531
+ details?: Readonly<Record<string, unknown>>;
532
+ }>;
533
+ type OAuth2ProviderFromPublicConfig = Readonly<{
534
+ authorizeUrlFieldKey: string;
535
+ tokenUrlFieldKey: string;
536
+ userInfoUrlFieldKey?: string;
537
+ }>;
538
+ type CredentialOAuth2AuthDefinition = Readonly<{
539
+ kind: "oauth2";
540
+ providerId: string;
541
+ scopes: ReadonlyArray<string>;
542
+ clientIdFieldKey?: string;
543
+ clientSecretFieldKey?: string;
544
+ } | {
545
+ kind: "oauth2";
546
+ providerFromPublicConfig: OAuth2ProviderFromPublicConfig;
547
+ scopes: ReadonlyArray<string>;
548
+ clientIdFieldKey?: string;
549
+ clientSecretFieldKey?: string;
550
+ }>;
551
+ type CredentialAuthDefinition = CredentialOAuth2AuthDefinition;
552
+ type CredentialTypeDefinition = Readonly<{
553
+ typeId: CredentialTypeId;
554
+ displayName: string;
555
+ description?: string;
556
+ publicFields?: ReadonlyArray<CredentialFieldSchema>;
557
+ secretFields?: ReadonlyArray<CredentialFieldSchema>;
558
+ supportedSourceKinds?: ReadonlyArray<CredentialMaterialSourceKind>;
559
+ auth?: CredentialAuthDefinition;
560
+ }>;
561
+ /**
562
+ * JSON-shaped credential field bag (public config, resolved secret material, etc.).
563
+ */
564
+ type CredentialJsonRecord = Readonly<Record<string, unknown>>;
565
+ /**
566
+ * Persisted credential instance with typed `publicConfig`.
567
+ * Hosts may specialize `secretRef` with a stricter union while remaining
568
+ * assignable here for session/test callbacks.
569
+ */
570
+ type CredentialInstanceRecord<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord> = Readonly<{
571
+ instanceId: CredentialInstanceId;
572
+ typeId: CredentialTypeId;
573
+ displayName: string;
574
+ sourceKind: CredentialMaterialSourceKind;
575
+ publicConfig: TPublicConfig;
576
+ secretRef: CredentialJsonRecord;
577
+ tags: ReadonlyArray<string>;
578
+ setupStatus: CredentialSetupStatus;
579
+ createdAt: string;
580
+ updatedAt: string;
581
+ }>;
582
+ /**
583
+ * Arguments passed to `CredentialType.createSession` and `CredentialType.test`.
584
+ * Declare `TPublicConfig` / `TMaterial` on `CredentialType` so implementations are checked
585
+ * against your credential shapes (similar to `NodeExecutionContext.config` for nodes).
586
+ */
587
+ type CredentialSessionFactoryArgs<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord, TMaterial extends CredentialJsonRecord = CredentialJsonRecord> = Readonly<{
588
+ instance: CredentialInstanceRecord<TPublicConfig>;
589
+ material: TMaterial;
590
+ publicConfig: TPublicConfig;
591
+ }>;
592
+ type CredentialSessionFactory<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord, TMaterial extends CredentialJsonRecord = CredentialJsonRecord, TSession = unknown> = (args: CredentialSessionFactoryArgs<TPublicConfig, TMaterial>) => Promise<TSession>;
593
+ type CredentialHealthTester<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord, TMaterial extends CredentialJsonRecord = CredentialJsonRecord> = (args: CredentialSessionFactoryArgs<TPublicConfig, TMaterial>) => Promise<CredentialHealth>;
594
+ /**
595
+ * Full credential type implementation: `definition` (UI/schema), `createSession`, and `test`.
596
+ * Use this at registration and config boundaries; `CredentialTypeDefinition` is only the schema slice.
597
+ */
598
+ type CredentialType<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord, TMaterial extends CredentialJsonRecord = CredentialJsonRecord, TSession = unknown> = Readonly<{
599
+ definition: CredentialTypeDefinition;
600
+ createSession: CredentialSessionFactory<TPublicConfig, TMaterial, TSession>;
601
+ test: CredentialHealthTester<TPublicConfig, TMaterial>;
602
+ }>;
603
+ /**
604
+ * Credential type with unspecified generics — used for `CodemationConfig.credentialTypes`, the host registry,
605
+ * and anywhere a concrete `CredentialType<YourPublic, YourMaterial, YourSession>` is placed in a heterogeneous list.
606
+ * Using `any` here avoids unsafe `as` casts while keeping typed `satisfies CredentialType<…>` definitions.
607
+ */
608
+ type AnyCredentialType = CredentialType<any, any, unknown>;
442
609
  interface CredentialSessionService {
443
610
  getSession<TSession = unknown>(args: Readonly<{
444
611
  workflowId: WorkflowId;
@@ -447,66 +614,25 @@ interface CredentialSessionService {
447
614
  }>): Promise<TSession>;
448
615
  }
449
616
  //#endregion
450
- //#region ../core/src/workflow/dsl/workflowBuilderTypes.d.ts
451
- type AnyRunnableNodeConfig = RunnableNodeConfig<any, any>;
452
- type AnyTriggerNodeConfig = TriggerNodeConfig<any>;
453
- type ValidStepSequence<TCurrentJson, TSteps extends ReadonlyArray<AnyRunnableNodeConfig>> = TSteps extends readonly [] ? readonly [] : TSteps extends readonly [infer TFirst, ...infer TRest] ? TFirst extends RunnableNodeConfig<TCurrentJson, infer TNextJson> ? TRest extends ReadonlyArray<AnyRunnableNodeConfig> ? readonly [TFirst, ...ValidStepSequence<TNextJson, TRest>] : never : never : TSteps;
454
- type StepSequenceOutput<TCurrentJson, TSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined> = TSteps extends ReadonlyArray<AnyRunnableNodeConfig> ? TSteps extends readonly [] ? TCurrentJson : TSteps extends readonly [infer TFirst, ...infer TRest] ? TFirst extends RunnableNodeConfig<TCurrentJson, infer TNextJson> ? TRest extends ReadonlyArray<AnyRunnableNodeConfig> ? StepSequenceOutput<TNextJson, TRest> : never : never : TCurrentJson : TCurrentJson;
455
- type TypesMatch<TLeft, TRight> = [TLeft] extends [TRight] ? ([TRight] extends [TLeft] ? true : false) : false;
456
- type BranchOutputGuard<TCurrentJson, TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined, TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined> = TypesMatch<StepSequenceOutput<TCurrentJson, TTrueSteps>, StepSequenceOutput<TCurrentJson, TFalseSteps>> extends true ? unknown : never;
457
- type BranchStepsArg<TCurrentJson, TSteps extends ReadonlyArray<AnyRunnableNodeConfig>> = TSteps & ValidStepSequence<TCurrentJson, TSteps>;
458
- type BranchMoreArgs<TCurrentJson, TFirstStep extends RunnableNodeConfig<TCurrentJson, any>, TRestSteps extends ReadonlyArray<AnyRunnableNodeConfig>> = TRestSteps & ValidStepSequence<RunnableNodeOutputJson<TFirstStep>, TRestSteps>;
459
- type BooleanWhenOverloads<TCurrentJson, TReturn> = {
460
- <TSteps extends ReadonlyArray<AnyRunnableNodeConfig>>(branch: boolean, steps: BranchStepsArg<TCurrentJson, TSteps>): TReturn;
461
- <TFirstStep extends RunnableNodeConfig<TCurrentJson, any>, TRestSteps extends ReadonlyArray<AnyRunnableNodeConfig>>(branch: boolean, step: TFirstStep, ...more: BranchMoreArgs<TCurrentJson, TFirstStep, TRestSteps>): TReturn;
462
- };
463
- //#endregion
464
- //#region ../core/src/workflow/dsl/WhenBuilder.d.ts
465
- declare class WhenBuilder<TCurrentJson> {
466
- private readonly wf;
467
- private readonly from;
468
- private readonly branchPort;
469
- constructor(wf: WorkflowBuilder, from: NodeRef, branchPort: OutputPortKey);
470
- addBranch<TSteps extends ReadonlyArray<AnyRunnableNodeConfig>>(steps: TSteps & ValidStepSequence<TCurrentJson, TSteps>): this;
471
- readonly when: BooleanWhenOverloads<TCurrentJson, WhenBuilder<TCurrentJson>>;
472
- build(): WorkflowDefinition;
473
- }
474
- //#endregion
475
- //#region ../core/src/workflow/dsl/ChainCursorResolver.d.ts
476
- type ChainCursorWhenOverloads<TCurrentJson> = BooleanWhenOverloads<TCurrentJson, WhenBuilder<TCurrentJson>> & {
477
- <TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined, TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined>(branches: Readonly<{
478
- true?: TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> ? BranchStepsArg<TCurrentJson, TTrueSteps> : never;
479
- false?: TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig> ? BranchStepsArg<TCurrentJson, TFalseSteps> : never;
480
- }> & BranchOutputGuard<TCurrentJson, TTrueSteps, TFalseSteps>): ChainCursor<StepSequenceOutput<TCurrentJson, TTrueSteps>>;
481
- };
482
- declare class ChainCursor<TCurrentJson> {
483
- private readonly wf;
484
- private readonly cursor;
485
- private readonly cursorOutput;
486
- constructor(wf: WorkflowBuilder, cursor: NodeRef, cursorOutput: OutputPortKey);
487
- then<TConfig extends RunnableNodeConfig<TCurrentJson, any>>(config: TConfig): ChainCursor<RunnableNodeOutputJson<TConfig>>;
488
- readonly when: ChainCursorWhenOverloads<TCurrentJson>;
489
- build(): WorkflowDefinition;
490
- }
491
- //#endregion
492
- //#region ../core/src/workflow/dsl/WorkflowBuilder.d.ts
493
- declare class WorkflowBuilder {
494
- private readonly meta;
495
- private readonly options?;
496
- private readonly nodes;
497
- private readonly edges;
498
- private seq;
499
- constructor(meta: {
500
- id: WorkflowId;
501
- name: string;
502
- }, options?: Readonly<{
503
- makeMergeNode?: (name: string) => AnyRunnableNodeConfig;
504
- }> | undefined);
505
- private add;
506
- private connect;
507
- trigger<TConfig extends AnyTriggerNodeConfig>(config: TConfig): ChainCursor<TriggerNodeOutputJson<TConfig>>;
508
- start<TConfig extends AnyRunnableNodeConfig>(config: TConfig): ChainCursor<RunnableNodeOutputJson<TConfig>>;
509
- build(): WorkflowDefinition;
617
+ //#region ../core/src/authoring/defineNode.types.d.ts
618
+ type ResolvableCredentialType = AnyCredentialType | CredentialTypeId;
619
+ type DefinedNodeCredentialBinding = ResolvableCredentialType | Readonly<{
620
+ readonly type: ResolvableCredentialType | ReadonlyArray<ResolvableCredentialType>;
621
+ readonly label?: string;
622
+ readonly optional?: true;
623
+ readonly helpText?: string;
624
+ readonly helpUrl?: string;
625
+ }>;
626
+ type DefinedNodeCredentialBindings = Readonly<Record<string, DefinedNodeCredentialBinding>>;
627
+ interface DefinedNode<TKey$1 extends string, TConfig extends CredentialJsonRecord, TInputJson$1, TOutputJson$1, _TBindings extends DefinedNodeCredentialBindings | undefined = undefined> {
628
+ readonly kind: "defined-node";
629
+ readonly key: TKey$1;
630
+ readonly title: string;
631
+ readonly description?: string;
632
+ create(config: TConfig, name?: string, id?: string): RunnableNodeConfig<TInputJson$1, TOutputJson$1>;
633
+ register(context: {
634
+ registerNode<TValue>(token: TypeToken<TValue>, implementation?: TypeToken<TValue>): void;
635
+ }): void;
510
636
  }
511
637
  //#endregion
512
638
  //#region ../core/src/ai/NodeBackedToolConfig.d.ts
@@ -1184,6 +1310,72 @@ declare function createWorkflowBuilder(meta: Readonly<{
1184
1310
  name: string;
1185
1311
  }>): WorkflowBuilder;
1186
1312
  //#endregion
1313
+ //#region src/workflowAuthoring/WorkflowAuthoringOptions.types.d.ts
1314
+ type WorkflowAgentPrompt<TCurrentJson> = string | ((item: TCurrentJson) => string);
1315
+ interface WorkflowAgentOptions<TCurrentJson, TOutputSchema extends z.ZodTypeAny | undefined = undefined> {
1316
+ readonly prompt: WorkflowAgentPrompt<TCurrentJson>;
1317
+ readonly model: string | ChatModelConfig;
1318
+ readonly tools?: ReadonlyArray<ToolConfig>;
1319
+ readonly outputSchema?: TOutputSchema;
1320
+ readonly retryPolicy?: RunnableNodeConfig["retryPolicy"];
1321
+ readonly guardrails?: AgentGuardrailConfig;
1322
+ readonly id?: string;
1323
+ }
1324
+ //#endregion
1325
+ //#region src/workflowAuthoring/WorkflowBranchBuilder.types.d.ts
1326
+ declare class WorkflowBranchBuilder<TCurrentJson> {
1327
+ private readonly steps;
1328
+ constructor(steps?: ReadonlyArray<AnyRunnableNodeConfig>);
1329
+ then<TConfig extends RunnableNodeConfig<TCurrentJson, any>>(config: TConfig): WorkflowBranchBuilder<RunnableNodeOutputJson<TConfig>>;
1330
+ map<TNextJson$1>(mapper: (item: TCurrentJson) => TNextJson$1): WorkflowBranchBuilder<TNextJson$1>;
1331
+ map<TNextJson$1>(name: string, mapper: (item: TCurrentJson) => TNextJson$1, id?: string): WorkflowBranchBuilder<TNextJson$1>;
1332
+ wait(duration: number | string): WorkflowBranchBuilder<TCurrentJson>;
1333
+ wait(name: string, duration: number | string, id?: string): WorkflowBranchBuilder<TCurrentJson>;
1334
+ agent<TOutputSchema extends z.ZodTypeAny>(options: WorkflowAgentOptions<TCurrentJson, TOutputSchema>): WorkflowBranchBuilder<z.output<TOutputSchema>>;
1335
+ agent(options: WorkflowAgentOptions<TCurrentJson, undefined>): WorkflowBranchBuilder<Record<string, unknown>>;
1336
+ agent<TOutputSchema extends z.ZodTypeAny>(name: string, options: WorkflowAgentOptions<TCurrentJson, TOutputSchema | undefined>): WorkflowBranchBuilder<TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>>;
1337
+ node<TConfig extends Record<string, unknown>, TOutputJson$1>(definitionOrKey: DefinedNode<string, TConfig, TCurrentJson, TOutputJson$1> | string, config: TConfig, name?: string, id?: string): WorkflowBranchBuilder<TOutputJson$1>;
1338
+ getSteps(): ReadonlyArray<AnyRunnableNodeConfig>;
1339
+ }
1340
+ //#endregion
1341
+ //#region src/workflowAuthoring/WorkflowChain.types.d.ts
1342
+ type BranchCallback<TCurrentJson, TNextJson$1> = (branch: WorkflowBranchBuilder<TCurrentJson>) => WorkflowBranchBuilder<TNextJson$1>;
1343
+ declare class WorkflowChain<TCurrentJson> {
1344
+ private readonly chain;
1345
+ constructor(chain: ChainCursor<TCurrentJson>);
1346
+ then<TConfig extends RunnableNodeConfig<TCurrentJson, any>>(config: TConfig): WorkflowChain<RunnableNodeOutputJson<TConfig>>;
1347
+ map<TNextJson$1>(mapper: (item: TCurrentJson) => TNextJson$1): WorkflowChain<TNextJson$1>;
1348
+ map<TNextJson$1>(name: string, mapper: (item: TCurrentJson) => TNextJson$1, id?: string): WorkflowChain<TNextJson$1>;
1349
+ wait(duration: number | string): WorkflowChain<TCurrentJson>;
1350
+ wait(name: string, duration: number | string, id?: string): WorkflowChain<TCurrentJson>;
1351
+ if<TBranchJson>(predicate: (item: TCurrentJson) => boolean, branches: Readonly<{
1352
+ true?: BranchCallback<TCurrentJson, TBranchJson>;
1353
+ false?: BranchCallback<TCurrentJson, TBranchJson>;
1354
+ }>): WorkflowChain<TBranchJson>;
1355
+ if<TBranchJson>(name: string, predicate: (item: TCurrentJson) => boolean, branches: Readonly<{
1356
+ true?: BranchCallback<TCurrentJson, TBranchJson>;
1357
+ false?: BranchCallback<TCurrentJson, TBranchJson>;
1358
+ }>): WorkflowChain<TBranchJson>;
1359
+ agent<TOutputSchema extends z.ZodTypeAny>(options: WorkflowAgentOptions<TCurrentJson, TOutputSchema>): WorkflowChain<z.output<TOutputSchema>>;
1360
+ agent(options: WorkflowAgentOptions<TCurrentJson, undefined>): WorkflowChain<Record<string, unknown>>;
1361
+ agent<TOutputSchema extends z.ZodTypeAny>(name: string, options: WorkflowAgentOptions<TCurrentJson, TOutputSchema | undefined>): WorkflowChain<TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>>;
1362
+ node<TConfig extends Record<string, unknown>, TOutputJson$1>(definitionOrKey: DefinedNode<string, TConfig, TCurrentJson, TOutputJson$1> | string, config: TConfig, name?: string, id?: string): WorkflowChain<TOutputJson$1>;
1363
+ build(): WorkflowDefinition;
1364
+ }
1365
+ //#endregion
1366
+ //#region src/workflowAuthoring/WorkflowAuthoringBuilder.types.d.ts
1367
+ declare class WorkflowAuthoringBuilder {
1368
+ private readonly id;
1369
+ private readonly workflowName;
1370
+ constructor(id: string, workflowName?: string);
1371
+ name(name: string): WorkflowAuthoringBuilder;
1372
+ manualTrigger<TOutputJson$1>(defaultItems: TOutputJson$1 | ReadonlyArray<TOutputJson$1>): WorkflowChain<TOutputJson$1>;
1373
+ manualTrigger<TOutputJson$1>(name: string, defaultItems?: TOutputJson$1 | ReadonlyArray<TOutputJson$1>, id?: string): WorkflowChain<TOutputJson$1>;
1374
+ }
1375
+ //#endregion
1376
+ //#region src/workflowAuthoring.types.d.ts
1377
+ declare function workflow(id: string): WorkflowAuthoringBuilder;
1378
+ //#endregion
1187
1379
  //#region src/nodes/ConnectionCredentialNode.d.ts
1188
1380
  /**
1189
1381
  * Placeholder runnable node for connection-owned workflow nodes (LLM/tool slots).
@@ -1225,5 +1417,5 @@ declare class AIAgentConnectionWorkflowExpander {
1225
1417
  private assertNoIdCollision;
1226
1418
  }
1227
1419
  //#endregion
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 };
1420
+ 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, type WorkflowAgentOptions, WorkflowAuthoringBuilder, WorkflowBranchBuilder, WorkflowChain, createWorkflowBuilder, openAiChatModelPresets, registerCoreNodes, workflow };
1229
1421
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AgentConfigInspector, AgentGuardrailDefaults, AgentMessageConfigNormalizer, ConnectionInvocationIdFactory, ConnectionNodeIdFactory, CoreTokens, ItemsInputNormalizer, NodeBackedToolConfig, RetryPolicy, WorkflowBuilder, chatModel, inject, injectable, node } from "@codemation/core";
1
+ import { AgentConfigInspector, AgentGuardrailDefaults, AgentMessageConfigNormalizer, ConnectionInvocationIdFactory, ConnectionNodeIdFactory, CoreTokens, DefinedNodeRegistry, ItemsInputNormalizer, NodeBackedToolConfig, RetryPolicy, WorkflowBuilder, chatModel, inject, injectable, 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 { DynamicStructuredTool } from "@langchain/core/tools";
@@ -1191,6 +1191,166 @@ function createWorkflowBuilder(meta) {
1191
1191
  }) });
1192
1192
  }
1193
1193
 
1194
+ //#endregion
1195
+ //#region src/workflowAuthoring/WorkflowChatModelFactory.types.ts
1196
+ var WorkflowChatModelFactory = class {
1197
+ static create(model) {
1198
+ if (typeof model !== "string") return model;
1199
+ const [provider, resolvedModel] = model.includes(":") ? model.split(":", 2) : ["openai", model];
1200
+ if (provider !== "openai") throw new Error(`Unsupported workflow().agent() model provider "${provider}".`);
1201
+ return new OpenAIChatModelConfig("OpenAI", resolvedModel);
1202
+ }
1203
+ };
1204
+
1205
+ //#endregion
1206
+ //#region src/workflowAuthoring/WorkflowAgentNodeFactory.types.ts
1207
+ var WorkflowAgentNodeFactory = class {
1208
+ static create(nameOrOptions, optionsOrUndefined) {
1209
+ const options = typeof nameOrOptions === "string" ? optionsOrUndefined : nameOrOptions;
1210
+ const name = typeof nameOrOptions === "string" ? nameOrOptions : "AI agent";
1211
+ const prompt = options.prompt;
1212
+ return new AIAgent({
1213
+ name,
1214
+ messages: [{
1215
+ role: "user",
1216
+ content: typeof prompt === "function" ? ({ item }) => prompt(item.json) : prompt
1217
+ }],
1218
+ chatModel: WorkflowChatModelFactory.create(options.model),
1219
+ tools: options.tools,
1220
+ id: options.id,
1221
+ retryPolicy: options.retryPolicy,
1222
+ guardrails: options.guardrails
1223
+ });
1224
+ }
1225
+ };
1226
+
1227
+ //#endregion
1228
+ //#region src/workflowAuthoring/WorkflowDefinedNodeResolver.types.ts
1229
+ var WorkflowDefinedNodeResolver = class {
1230
+ static resolve(definitionOrKey) {
1231
+ if (typeof definitionOrKey !== "string") return definitionOrKey;
1232
+ const definition = DefinedNodeRegistry.resolve(definitionOrKey);
1233
+ if (!definition) throw new Error(`No helper-defined node with key "${definitionOrKey}" is registered in this module graph.`);
1234
+ return definition;
1235
+ }
1236
+ };
1237
+
1238
+ //#endregion
1239
+ //#region src/workflowAuthoring/WorkflowDurationParser.types.ts
1240
+ var WorkflowDurationParser = class {
1241
+ static parse(duration) {
1242
+ if (typeof duration === "number") return Number.isFinite(duration) && duration > 0 ? Math.floor(duration) : 0;
1243
+ const match = duration.trim().toLowerCase().match(/^(\d+)(ms|s|m|h)$/);
1244
+ if (!match) throw new Error(`Unsupported wait duration "${duration}". Use a number of milliseconds or values like "500ms", "2s", "5m".`);
1245
+ const value = Number(match[1]);
1246
+ const unit = match[2];
1247
+ if (unit === "ms") return value;
1248
+ if (unit === "s") return value * 1e3;
1249
+ if (unit === "m") return value * 6e4;
1250
+ return value * 36e5;
1251
+ }
1252
+ };
1253
+
1254
+ //#endregion
1255
+ //#region src/workflowAuthoring/WorkflowBranchBuilder.types.ts
1256
+ var WorkflowBranchBuilder = class WorkflowBranchBuilder {
1257
+ constructor(steps = []) {
1258
+ this.steps = steps;
1259
+ }
1260
+ then(config) {
1261
+ return new WorkflowBranchBuilder([...this.steps, config]);
1262
+ }
1263
+ map(nameOrMapper, mapperOrUndefined, id) {
1264
+ const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
1265
+ const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined : nameOrMapper;
1266
+ return this.then(new MapData(name, (item) => mapper(item.json), id));
1267
+ }
1268
+ wait(nameOrDuration, durationOrUndefined, id) {
1269
+ const name = typeof nameOrDuration === "string" && durationOrUndefined !== void 0 ? nameOrDuration : "Wait";
1270
+ const duration = durationOrUndefined ?? nameOrDuration;
1271
+ return this.then(new Wait(name, WorkflowDurationParser.parse(duration), id));
1272
+ }
1273
+ agent(nameOrOptions, optionsOrUndefined) {
1274
+ return this.then(WorkflowAgentNodeFactory.create(nameOrOptions, optionsOrUndefined));
1275
+ }
1276
+ node(definitionOrKey, config, name, id) {
1277
+ const definition = WorkflowDefinedNodeResolver.resolve(definitionOrKey);
1278
+ return this.then(definition.create(config, name, id));
1279
+ }
1280
+ getSteps() {
1281
+ return this.steps;
1282
+ }
1283
+ };
1284
+
1285
+ //#endregion
1286
+ //#region src/workflowAuthoring/WorkflowChain.types.ts
1287
+ var WorkflowChain = class WorkflowChain {
1288
+ constructor(chain) {
1289
+ this.chain = chain;
1290
+ }
1291
+ then(config) {
1292
+ return new WorkflowChain(this.chain.then(config));
1293
+ }
1294
+ map(nameOrMapper, mapperOrUndefined, id) {
1295
+ const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
1296
+ const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined : nameOrMapper;
1297
+ return this.then(new MapData(name, (item) => mapper(item.json), id));
1298
+ }
1299
+ wait(nameOrDuration, durationOrUndefined, id) {
1300
+ const name = typeof nameOrDuration === "string" && durationOrUndefined !== void 0 ? nameOrDuration : "Wait";
1301
+ const duration = durationOrUndefined ?? nameOrDuration;
1302
+ return this.then(new Wait(name, WorkflowDurationParser.parse(duration), id));
1303
+ }
1304
+ if(nameOrPredicate, predicateOrBranches, branchesOrUndefined) {
1305
+ const name = typeof nameOrPredicate === "string" ? nameOrPredicate : "If";
1306
+ const predicate = typeof nameOrPredicate === "string" ? predicateOrBranches : nameOrPredicate;
1307
+ const branches = typeof nameOrPredicate === "string" ? branchesOrUndefined : predicateOrBranches;
1308
+ const cursor = this.chain.then(new If(name, (item) => predicate(item.json)));
1309
+ const trueSteps = branches.true?.(new WorkflowBranchBuilder()).getSteps();
1310
+ const falseSteps = branches.false?.(new WorkflowBranchBuilder()).getSteps();
1311
+ return new WorkflowChain(cursor.when({
1312
+ true: trueSteps,
1313
+ false: falseSteps
1314
+ }));
1315
+ }
1316
+ agent(nameOrOptions, optionsOrUndefined) {
1317
+ return this.then(WorkflowAgentNodeFactory.create(nameOrOptions, optionsOrUndefined));
1318
+ }
1319
+ node(definitionOrKey, config, name, id) {
1320
+ const definition = WorkflowDefinedNodeResolver.resolve(definitionOrKey);
1321
+ return this.then(definition.create(config, name, id));
1322
+ }
1323
+ build() {
1324
+ return this.chain.build();
1325
+ }
1326
+ };
1327
+
1328
+ //#endregion
1329
+ //#region src/workflowAuthoring/WorkflowAuthoringBuilder.types.ts
1330
+ var WorkflowAuthoringBuilder = class WorkflowAuthoringBuilder {
1331
+ constructor(id, workflowName = id) {
1332
+ this.id = id;
1333
+ this.workflowName = workflowName;
1334
+ }
1335
+ name(name) {
1336
+ return new WorkflowAuthoringBuilder(this.id, name);
1337
+ }
1338
+ manualTrigger(nameOrDefaultItems, defaultItemsOrUndefined, id) {
1339
+ const builder = createWorkflowBuilder({
1340
+ id: this.id,
1341
+ name: this.workflowName
1342
+ });
1343
+ if (typeof nameOrDefaultItems === "string") return new WorkflowChain(builder.trigger(new ManualTrigger(nameOrDefaultItems, defaultItemsOrUndefined, id)));
1344
+ return new WorkflowChain(builder.trigger(new ManualTrigger("Manual trigger", nameOrDefaultItems)));
1345
+ }
1346
+ };
1347
+
1348
+ //#endregion
1349
+ //#region src/workflowAuthoring.types.ts
1350
+ function workflow(id) {
1351
+ return new WorkflowAuthoringBuilder(id);
1352
+ }
1353
+
1194
1354
  //#endregion
1195
1355
  //#region src/workflows/AIAgentConnectionWorkflowExpander.ts
1196
1356
  /**
@@ -1200,18 +1360,18 @@ var AIAgentConnectionWorkflowExpander = class {
1200
1360
  constructor(connectionCredentialNodeConfigFactory) {
1201
1361
  this.connectionCredentialNodeConfigFactory = connectionCredentialNodeConfigFactory;
1202
1362
  }
1203
- expand(workflow) {
1363
+ expand(workflow$1) {
1204
1364
  const existingByParentAndName = /* @__PURE__ */ new Map();
1205
- for (const c of workflow.connections ?? []) existingByParentAndName.set(`${c.parentNodeId}\0${c.connectionName}`, c);
1365
+ for (const c of workflow$1.connections ?? []) existingByParentAndName.set(`${c.parentNodeId}\0${c.connectionName}`, c);
1206
1366
  const extraNodes = [];
1207
1367
  const extraConnections = [];
1208
- for (const node$1 of workflow.nodes) {
1368
+ for (const node$1 of workflow$1.nodes) {
1209
1369
  if (node$1.type !== AIAgentNode || !AgentConfigInspector.isAgentNodeConfig(node$1.config)) continue;
1210
1370
  const agentId = node$1.id;
1211
1371
  const agentConfig = node$1.config;
1212
1372
  if (!existingByParentAndName.has(`${agentId}\0llm`)) {
1213
1373
  const llmId = ConnectionNodeIdFactory.languageModelConnectionNodeId(agentId);
1214
- this.assertNoIdCollision(workflow, extraNodes, llmId);
1374
+ this.assertNoIdCollision(workflow$1, extraNodes, llmId);
1215
1375
  extraNodes.push({
1216
1376
  id: llmId,
1217
1377
  kind: "node",
@@ -1229,7 +1389,7 @@ var AIAgentConnectionWorkflowExpander = class {
1229
1389
  const toolIds = [];
1230
1390
  for (const tool of agentConfig.tools ?? []) {
1231
1391
  const toolId = ConnectionNodeIdFactory.toolConnectionNodeId(agentId, tool.name);
1232
- this.assertNoIdCollision(workflow, extraNodes, toolId);
1392
+ this.assertNoIdCollision(workflow$1, extraNodes, toolId);
1233
1393
  toolIds.push(toolId);
1234
1394
  extraNodes.push({
1235
1395
  id: toolId,
@@ -1246,15 +1406,15 @@ var AIAgentConnectionWorkflowExpander = class {
1246
1406
  });
1247
1407
  }
1248
1408
  }
1249
- if (extraNodes.length === 0) return workflow;
1409
+ if (extraNodes.length === 0) return workflow$1;
1250
1410
  return {
1251
- ...workflow,
1252
- nodes: [...workflow.nodes, ...extraNodes],
1253
- connections: [...workflow.connections ?? [], ...extraConnections]
1411
+ ...workflow$1,
1412
+ nodes: [...workflow$1.nodes, ...extraNodes],
1413
+ connections: [...workflow$1.connections ?? [], ...extraConnections]
1254
1414
  };
1255
1415
  }
1256
- assertNoIdCollision(workflow, pending, id) {
1257
- if (workflow.nodes.some((n) => n.id === id) || pending.some((n) => n.id === id)) throw new Error(`AIAgent connection expansion: node id "${id}" already exists. Rename the conflicting node or adjust the workflow.`);
1416
+ assertNoIdCollision(workflow$1, pending, id) {
1417
+ if (workflow$1.nodes.some((n) => n.id === id) || pending.some((n) => n.id === id)) throw new Error(`AIAgent connection expansion: node id "${id}" already exists. Rename the conflicting node or adjust the workflow.`);
1258
1418
  }
1259
1419
  };
1260
1420
 
@@ -1281,5 +1441,5 @@ var ConnectionCredentialNodeConfigFactory = class {
1281
1441
  };
1282
1442
 
1283
1443
  //#endregion
1284
- export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentToolCallPortMap, Callback, CallbackNode, CallbackResultNormalizer, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, HttpRequest, HttpRequestNode, If, IfNode, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, Merge, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAiChatModelPresets, SubWorkflow, SubWorkflowNode, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, createWorkflowBuilder, openAiChatModelPresets, registerCoreNodes };
1444
+ export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentToolCallPortMap, Callback, CallbackNode, CallbackResultNormalizer, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, HttpRequest, HttpRequestNode, If, IfNode, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, Merge, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAiChatModelPresets, SubWorkflow, SubWorkflowNode, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, WorkflowAuthoringBuilder, WorkflowBranchBuilder, WorkflowChain, createWorkflowBuilder, openAiChatModelPresets, registerCoreNodes, workflow };
1285
1445
  //# sourceMappingURL=index.js.map