@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/CHANGELOG.md +9 -0
- package/LICENSE +37 -0
- package/dist/index.cjs +175 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +254 -62
- package/dist/index.d.ts +254 -62
- package/dist/index.js +173 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +1 -0
- package/src/workflowAuthoring/WorkflowAgentNodeFactory.types.ts +34 -0
- package/src/workflowAuthoring/WorkflowAuthoringBuilder.types.ts +43 -0
- package/src/workflowAuthoring/WorkflowAuthoringOptions.types.ts +14 -0
- package/src/workflowAuthoring/WorkflowBranchBuilder.types.ts +85 -0
- package/src/workflowAuthoring/WorkflowChain.types.ts +132 -0
- package/src/workflowAuthoring/WorkflowChatModelFactory.types.ts +15 -0
- package/src/workflowAuthoring/WorkflowDefinedNodeResolver.types.ts +16 -0
- package/src/workflowAuthoring/WorkflowDurationParser.types.ts +26 -0
- package/src/workflowAuthoring.types.ts +10 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AIAgent } from "../nodes/AIAgentConfig";
|
|
3
|
+
import type { WorkflowAgentOptions } from "./WorkflowAuthoringOptions.types";
|
|
4
|
+
import { WorkflowChatModelFactory } from "./WorkflowChatModelFactory.types";
|
|
5
|
+
|
|
6
|
+
export class WorkflowAgentNodeFactory {
|
|
7
|
+
static create<TCurrentJson, TOutputSchema extends z.ZodTypeAny | undefined>(
|
|
8
|
+
nameOrOptions: string | WorkflowAgentOptions<TCurrentJson, TOutputSchema>,
|
|
9
|
+
optionsOrUndefined?: WorkflowAgentOptions<TCurrentJson, TOutputSchema>,
|
|
10
|
+
): AIAgent<TCurrentJson, TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>> {
|
|
11
|
+
const options = typeof nameOrOptions === "string" ? optionsOrUndefined! : nameOrOptions;
|
|
12
|
+
const name = typeof nameOrOptions === "string" ? nameOrOptions : "AI agent";
|
|
13
|
+
const prompt = options.prompt;
|
|
14
|
+
const messages = [
|
|
15
|
+
{
|
|
16
|
+
role: "user" as const,
|
|
17
|
+
content:
|
|
18
|
+
typeof prompt === "function" ? ({ item }: { item: { json: TCurrentJson } }) => prompt(item.json) : prompt,
|
|
19
|
+
},
|
|
20
|
+
] as const;
|
|
21
|
+
return new AIAgent<
|
|
22
|
+
TCurrentJson,
|
|
23
|
+
TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>
|
|
24
|
+
>({
|
|
25
|
+
name,
|
|
26
|
+
messages,
|
|
27
|
+
chatModel: WorkflowChatModelFactory.create(options.model),
|
|
28
|
+
tools: options.tools,
|
|
29
|
+
id: options.id,
|
|
30
|
+
retryPolicy: options.retryPolicy,
|
|
31
|
+
guardrails: options.guardrails,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ChainCursor } from "@codemation/core";
|
|
2
|
+
import { ManualTrigger } from "../nodes/ManualTriggerFactory";
|
|
3
|
+
import { createWorkflowBuilder } from "../workflowBuilder.types";
|
|
4
|
+
import { WorkflowChain } from "./WorkflowChain.types";
|
|
5
|
+
|
|
6
|
+
export class WorkflowAuthoringBuilder {
|
|
7
|
+
constructor(
|
|
8
|
+
private readonly id: string,
|
|
9
|
+
private readonly workflowName: string = id,
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
name(name: string): WorkflowAuthoringBuilder {
|
|
13
|
+
return new WorkflowAuthoringBuilder(this.id, name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
manualTrigger<TOutputJson>(defaultItems: TOutputJson | ReadonlyArray<TOutputJson>): WorkflowChain<TOutputJson>;
|
|
17
|
+
manualTrigger<TOutputJson>(
|
|
18
|
+
name: string,
|
|
19
|
+
defaultItems?: TOutputJson | ReadonlyArray<TOutputJson>,
|
|
20
|
+
id?: string,
|
|
21
|
+
): WorkflowChain<TOutputJson>;
|
|
22
|
+
manualTrigger<TOutputJson>(
|
|
23
|
+
nameOrDefaultItems: string | TOutputJson | ReadonlyArray<TOutputJson>,
|
|
24
|
+
defaultItemsOrUndefined?: TOutputJson | ReadonlyArray<TOutputJson>,
|
|
25
|
+
id?: string,
|
|
26
|
+
): WorkflowChain<TOutputJson> {
|
|
27
|
+
const builder = createWorkflowBuilder({ id: this.id, name: this.workflowName });
|
|
28
|
+
if (typeof nameOrDefaultItems === "string") {
|
|
29
|
+
return new WorkflowChain(
|
|
30
|
+
builder.trigger(
|
|
31
|
+
new ManualTrigger<TOutputJson>(
|
|
32
|
+
nameOrDefaultItems,
|
|
33
|
+
defaultItemsOrUndefined as TOutputJson | ReadonlyArray<TOutputJson>,
|
|
34
|
+
id,
|
|
35
|
+
),
|
|
36
|
+
) as ChainCursor<TOutputJson>,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return new WorkflowChain(
|
|
40
|
+
builder.trigger(new ManualTrigger<TOutputJson>("Manual trigger", nameOrDefaultItems)) as ChainCursor<TOutputJson>,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AgentGuardrailConfig, ChatModelConfig, RunnableNodeConfig, ToolConfig } from "@codemation/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export type WorkflowAgentPrompt<TCurrentJson> = string | ((item: TCurrentJson) => string);
|
|
5
|
+
|
|
6
|
+
export interface WorkflowAgentOptions<TCurrentJson, TOutputSchema extends z.ZodTypeAny | undefined = undefined> {
|
|
7
|
+
readonly prompt: WorkflowAgentPrompt<TCurrentJson>;
|
|
8
|
+
readonly model: string | ChatModelConfig;
|
|
9
|
+
readonly tools?: ReadonlyArray<ToolConfig>;
|
|
10
|
+
readonly outputSchema?: TOutputSchema;
|
|
11
|
+
readonly retryPolicy?: RunnableNodeConfig["retryPolicy"];
|
|
12
|
+
readonly guardrails?: AgentGuardrailConfig;
|
|
13
|
+
readonly id?: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { AnyRunnableNodeConfig, DefinedNode, RunnableNodeConfig, RunnableNodeOutputJson } from "@codemation/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { MapData } from "../nodes/mapData";
|
|
4
|
+
import { Wait } from "../nodes/wait";
|
|
5
|
+
import type { WorkflowAgentOptions } from "./WorkflowAuthoringOptions.types";
|
|
6
|
+
import { WorkflowAgentNodeFactory } from "./WorkflowAgentNodeFactory.types";
|
|
7
|
+
import { WorkflowDefinedNodeResolver } from "./WorkflowDefinedNodeResolver.types";
|
|
8
|
+
import { WorkflowDurationParser } from "./WorkflowDurationParser.types";
|
|
9
|
+
|
|
10
|
+
export class WorkflowBranchBuilder<TCurrentJson> {
|
|
11
|
+
constructor(private readonly steps: ReadonlyArray<AnyRunnableNodeConfig> = []) {}
|
|
12
|
+
|
|
13
|
+
then<TConfig extends RunnableNodeConfig<TCurrentJson, any>>(
|
|
14
|
+
config: TConfig,
|
|
15
|
+
): WorkflowBranchBuilder<RunnableNodeOutputJson<TConfig>> {
|
|
16
|
+
return new WorkflowBranchBuilder<RunnableNodeOutputJson<TConfig>>([...this.steps, config]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
map<TNextJson>(mapper: (item: TCurrentJson) => TNextJson): WorkflowBranchBuilder<TNextJson>;
|
|
20
|
+
map<TNextJson>(
|
|
21
|
+
name: string,
|
|
22
|
+
mapper: (item: TCurrentJson) => TNextJson,
|
|
23
|
+
id?: string,
|
|
24
|
+
): WorkflowBranchBuilder<TNextJson>;
|
|
25
|
+
map<TNextJson>(
|
|
26
|
+
nameOrMapper: string | ((item: TCurrentJson) => TNextJson),
|
|
27
|
+
mapperOrUndefined?: (item: TCurrentJson) => TNextJson,
|
|
28
|
+
id?: string,
|
|
29
|
+
): WorkflowBranchBuilder<TNextJson> {
|
|
30
|
+
const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
|
|
31
|
+
const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined! : nameOrMapper;
|
|
32
|
+
return this.then(
|
|
33
|
+
new MapData<TCurrentJson, TNextJson>(name, (item) => mapper(item.json as TCurrentJson), id),
|
|
34
|
+
) as WorkflowBranchBuilder<TNextJson>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
wait(duration: number | string): WorkflowBranchBuilder<TCurrentJson>;
|
|
38
|
+
wait(name: string, duration: number | string, id?: string): WorkflowBranchBuilder<TCurrentJson>;
|
|
39
|
+
wait(
|
|
40
|
+
nameOrDuration: string | number,
|
|
41
|
+
durationOrUndefined?: string | number,
|
|
42
|
+
id?: string,
|
|
43
|
+
): WorkflowBranchBuilder<TCurrentJson> {
|
|
44
|
+
const name = typeof nameOrDuration === "string" && durationOrUndefined !== undefined ? nameOrDuration : "Wait";
|
|
45
|
+
const duration = durationOrUndefined ?? nameOrDuration;
|
|
46
|
+
return this.then(
|
|
47
|
+
new Wait<TCurrentJson>(name, WorkflowDurationParser.parse(duration), id),
|
|
48
|
+
) as WorkflowBranchBuilder<TCurrentJson>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
agent<TOutputSchema extends z.ZodTypeAny>(
|
|
52
|
+
options: WorkflowAgentOptions<TCurrentJson, TOutputSchema>,
|
|
53
|
+
): WorkflowBranchBuilder<z.output<TOutputSchema>>;
|
|
54
|
+
agent(options: WorkflowAgentOptions<TCurrentJson, undefined>): WorkflowBranchBuilder<Record<string, unknown>>;
|
|
55
|
+
agent<TOutputSchema extends z.ZodTypeAny>(
|
|
56
|
+
name: string,
|
|
57
|
+
options: WorkflowAgentOptions<TCurrentJson, TOutputSchema | undefined>,
|
|
58
|
+
): WorkflowBranchBuilder<TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>>;
|
|
59
|
+
agent<TOutputSchema extends z.ZodTypeAny>(
|
|
60
|
+
nameOrOptions: string | WorkflowAgentOptions<TCurrentJson, TOutputSchema | undefined>,
|
|
61
|
+
optionsOrUndefined?: WorkflowAgentOptions<TCurrentJson, TOutputSchema | undefined>,
|
|
62
|
+
): WorkflowBranchBuilder<TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>> {
|
|
63
|
+
return this.then(WorkflowAgentNodeFactory.create(nameOrOptions, optionsOrUndefined)) as WorkflowBranchBuilder<
|
|
64
|
+
TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>
|
|
65
|
+
>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
node<TConfig extends Record<string, unknown>, TOutputJson>(
|
|
69
|
+
definitionOrKey: DefinedNode<string, TConfig, TCurrentJson, TOutputJson> | string,
|
|
70
|
+
config: TConfig,
|
|
71
|
+
name?: string,
|
|
72
|
+
id?: string,
|
|
73
|
+
): WorkflowBranchBuilder<TOutputJson> {
|
|
74
|
+
const definition = WorkflowDefinedNodeResolver.resolve(
|
|
75
|
+
definitionOrKey as DefinedNode<string, Record<string, unknown>, unknown, unknown> | string,
|
|
76
|
+
) as DefinedNode<string, TConfig, TCurrentJson, TOutputJson>;
|
|
77
|
+
return this.then(
|
|
78
|
+
definition.create(config, name, id) as RunnableNodeConfig<TCurrentJson, TOutputJson>,
|
|
79
|
+
) as WorkflowBranchBuilder<TOutputJson>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getSteps(): ReadonlyArray<AnyRunnableNodeConfig> {
|
|
83
|
+
return this.steps;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { DefinedNode, RunnableNodeConfig, RunnableNodeOutputJson, WorkflowDefinition } from "@codemation/core";
|
|
2
|
+
import { ChainCursor } from "@codemation/core";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { If } from "../nodes/if";
|
|
5
|
+
import { MapData } from "../nodes/mapData";
|
|
6
|
+
import { Wait } from "../nodes/wait";
|
|
7
|
+
import type { WorkflowAgentOptions } from "./WorkflowAuthoringOptions.types";
|
|
8
|
+
import { WorkflowAgentNodeFactory } from "./WorkflowAgentNodeFactory.types";
|
|
9
|
+
import { WorkflowBranchBuilder } from "./WorkflowBranchBuilder.types";
|
|
10
|
+
import { WorkflowDefinedNodeResolver } from "./WorkflowDefinedNodeResolver.types";
|
|
11
|
+
import { WorkflowDurationParser } from "./WorkflowDurationParser.types";
|
|
12
|
+
|
|
13
|
+
type BranchCallback<TCurrentJson, TNextJson> = (
|
|
14
|
+
branch: WorkflowBranchBuilder<TCurrentJson>,
|
|
15
|
+
) => WorkflowBranchBuilder<TNextJson>;
|
|
16
|
+
type BranchOutputMatch<TLeft, TRight> = [TLeft] extends [TRight] ? ([TRight] extends [TLeft] ? true : false) : false;
|
|
17
|
+
|
|
18
|
+
export class WorkflowChain<TCurrentJson> {
|
|
19
|
+
constructor(private readonly chain: ChainCursor<TCurrentJson>) {}
|
|
20
|
+
|
|
21
|
+
then<TConfig extends RunnableNodeConfig<TCurrentJson, any>>(
|
|
22
|
+
config: TConfig,
|
|
23
|
+
): WorkflowChain<RunnableNodeOutputJson<TConfig>> {
|
|
24
|
+
return new WorkflowChain(this.chain.then(config));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
map<TNextJson>(mapper: (item: TCurrentJson) => TNextJson): WorkflowChain<TNextJson>;
|
|
28
|
+
map<TNextJson>(name: string, mapper: (item: TCurrentJson) => TNextJson, id?: string): WorkflowChain<TNextJson>;
|
|
29
|
+
map<TNextJson>(
|
|
30
|
+
nameOrMapper: string | ((item: TCurrentJson) => TNextJson),
|
|
31
|
+
mapperOrUndefined?: (item: TCurrentJson) => TNextJson,
|
|
32
|
+
id?: string,
|
|
33
|
+
): WorkflowChain<TNextJson> {
|
|
34
|
+
const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
|
|
35
|
+
const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined! : nameOrMapper;
|
|
36
|
+
return this.then(
|
|
37
|
+
new MapData<TCurrentJson, TNextJson>(name, (item) => mapper(item.json as TCurrentJson), id),
|
|
38
|
+
) as WorkflowChain<TNextJson>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
wait(duration: number | string): WorkflowChain<TCurrentJson>;
|
|
42
|
+
wait(name: string, duration: number | string, id?: string): WorkflowChain<TCurrentJson>;
|
|
43
|
+
wait(
|
|
44
|
+
nameOrDuration: string | number,
|
|
45
|
+
durationOrUndefined?: string | number,
|
|
46
|
+
id?: string,
|
|
47
|
+
): WorkflowChain<TCurrentJson> {
|
|
48
|
+
const name = typeof nameOrDuration === "string" && durationOrUndefined !== undefined ? nameOrDuration : "Wait";
|
|
49
|
+
const duration = durationOrUndefined ?? nameOrDuration;
|
|
50
|
+
return this.then(
|
|
51
|
+
new Wait<TCurrentJson>(name, WorkflowDurationParser.parse(duration), id),
|
|
52
|
+
) as WorkflowChain<TCurrentJson>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if<TBranchJson>(
|
|
56
|
+
predicate: (item: TCurrentJson) => boolean,
|
|
57
|
+
branches: Readonly<{
|
|
58
|
+
true?: BranchCallback<TCurrentJson, TBranchJson>;
|
|
59
|
+
false?: BranchCallback<TCurrentJson, TBranchJson>;
|
|
60
|
+
}>,
|
|
61
|
+
): WorkflowChain<TBranchJson>;
|
|
62
|
+
if<TBranchJson>(
|
|
63
|
+
name: string,
|
|
64
|
+
predicate: (item: TCurrentJson) => boolean,
|
|
65
|
+
branches: Readonly<{
|
|
66
|
+
true?: BranchCallback<TCurrentJson, TBranchJson>;
|
|
67
|
+
false?: BranchCallback<TCurrentJson, TBranchJson>;
|
|
68
|
+
}>,
|
|
69
|
+
): WorkflowChain<TBranchJson>;
|
|
70
|
+
if<TTrueJson, TFalseJson>(
|
|
71
|
+
nameOrPredicate: string | ((item: TCurrentJson) => boolean),
|
|
72
|
+
predicateOrBranches:
|
|
73
|
+
| ((item: TCurrentJson) => boolean)
|
|
74
|
+
| Readonly<{ true?: BranchCallback<TCurrentJson, TTrueJson>; false?: BranchCallback<TCurrentJson, TFalseJson> }>,
|
|
75
|
+
branchesOrUndefined?: Readonly<{
|
|
76
|
+
true?: BranchCallback<TCurrentJson, TTrueJson>;
|
|
77
|
+
false?: BranchCallback<TCurrentJson, TFalseJson>;
|
|
78
|
+
}>,
|
|
79
|
+
): WorkflowChain<BranchOutputMatch<TTrueJson, TFalseJson> extends true ? TTrueJson : never> {
|
|
80
|
+
const name = typeof nameOrPredicate === "string" ? nameOrPredicate : "If";
|
|
81
|
+
const predicate =
|
|
82
|
+
typeof nameOrPredicate === "string" ? (predicateOrBranches as (item: TCurrentJson) => boolean) : nameOrPredicate;
|
|
83
|
+
const branches = (typeof nameOrPredicate === "string" ? branchesOrUndefined : predicateOrBranches) as Readonly<{
|
|
84
|
+
true?: BranchCallback<TCurrentJson, TTrueJson>;
|
|
85
|
+
false?: BranchCallback<TCurrentJson, TFalseJson>;
|
|
86
|
+
}>;
|
|
87
|
+
const cursor = this.chain.then(new If<TCurrentJson>(name, (item) => predicate(item.json as TCurrentJson)));
|
|
88
|
+
const trueSteps = branches.true?.(new WorkflowBranchBuilder<TCurrentJson>()).getSteps();
|
|
89
|
+
const falseSteps = branches.false?.(new WorkflowBranchBuilder<TCurrentJson>()).getSteps();
|
|
90
|
+
return new WorkflowChain(
|
|
91
|
+
cursor.when({
|
|
92
|
+
true: trueSteps,
|
|
93
|
+
false: falseSteps,
|
|
94
|
+
}),
|
|
95
|
+
) as WorkflowChain<BranchOutputMatch<TTrueJson, TFalseJson> extends true ? TTrueJson : never>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
agent<TOutputSchema extends z.ZodTypeAny>(
|
|
99
|
+
options: WorkflowAgentOptions<TCurrentJson, TOutputSchema>,
|
|
100
|
+
): WorkflowChain<z.output<TOutputSchema>>;
|
|
101
|
+
agent(options: WorkflowAgentOptions<TCurrentJson, undefined>): WorkflowChain<Record<string, unknown>>;
|
|
102
|
+
agent<TOutputSchema extends z.ZodTypeAny>(
|
|
103
|
+
name: string,
|
|
104
|
+
options: WorkflowAgentOptions<TCurrentJson, TOutputSchema | undefined>,
|
|
105
|
+
): WorkflowChain<TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>>;
|
|
106
|
+
agent<TOutputSchema extends z.ZodTypeAny>(
|
|
107
|
+
nameOrOptions: string | WorkflowAgentOptions<TCurrentJson, TOutputSchema | undefined>,
|
|
108
|
+
optionsOrUndefined?: WorkflowAgentOptions<TCurrentJson, TOutputSchema | undefined>,
|
|
109
|
+
): WorkflowChain<TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>> {
|
|
110
|
+
return this.then(WorkflowAgentNodeFactory.create(nameOrOptions, optionsOrUndefined)) as WorkflowChain<
|
|
111
|
+
TOutputSchema extends z.ZodTypeAny ? z.output<TOutputSchema> : Record<string, unknown>
|
|
112
|
+
>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
node<TConfig extends Record<string, unknown>, TOutputJson>(
|
|
116
|
+
definitionOrKey: DefinedNode<string, TConfig, TCurrentJson, TOutputJson> | string,
|
|
117
|
+
config: TConfig,
|
|
118
|
+
name?: string,
|
|
119
|
+
id?: string,
|
|
120
|
+
): WorkflowChain<TOutputJson> {
|
|
121
|
+
const definition = WorkflowDefinedNodeResolver.resolve(
|
|
122
|
+
definitionOrKey as DefinedNode<string, Record<string, unknown>, unknown, unknown> | string,
|
|
123
|
+
) as DefinedNode<string, TConfig, TCurrentJson, TOutputJson>;
|
|
124
|
+
return this.then(
|
|
125
|
+
definition.create(config, name, id) as RunnableNodeConfig<TCurrentJson, TOutputJson>,
|
|
126
|
+
) as WorkflowChain<TOutputJson>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
build(): WorkflowDefinition {
|
|
130
|
+
return this.chain.build();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChatModelConfig } from "@codemation/core";
|
|
2
|
+
import { OpenAIChatModelConfig } from "../chatModels/openAiChatModelConfig";
|
|
3
|
+
|
|
4
|
+
export class WorkflowChatModelFactory {
|
|
5
|
+
static create(model: string | ChatModelConfig): ChatModelConfig {
|
|
6
|
+
if (typeof model !== "string") {
|
|
7
|
+
return model;
|
|
8
|
+
}
|
|
9
|
+
const [provider, resolvedModel] = model.includes(":") ? model.split(":", 2) : ["openai", model];
|
|
10
|
+
if (provider !== "openai") {
|
|
11
|
+
throw new Error(`Unsupported workflow().agent() model provider "${provider}".`);
|
|
12
|
+
}
|
|
13
|
+
return new OpenAIChatModelConfig("OpenAI", resolvedModel);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DefinedNodeRegistry, type DefinedNode } from "@codemation/core";
|
|
2
|
+
|
|
3
|
+
export class WorkflowDefinedNodeResolver {
|
|
4
|
+
static resolve(
|
|
5
|
+
definitionOrKey: DefinedNode<string, Record<string, unknown>, unknown, unknown> | string,
|
|
6
|
+
): DefinedNode<string, Record<string, unknown>, unknown, unknown> {
|
|
7
|
+
if (typeof definitionOrKey !== "string") {
|
|
8
|
+
return definitionOrKey;
|
|
9
|
+
}
|
|
10
|
+
const definition = DefinedNodeRegistry.resolve(definitionOrKey);
|
|
11
|
+
if (!definition) {
|
|
12
|
+
throw new Error(`No helper-defined node with key "${definitionOrKey}" is registered in this module graph.`);
|
|
13
|
+
}
|
|
14
|
+
return definition;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class WorkflowDurationParser {
|
|
2
|
+
static parse(duration: number | string): number {
|
|
3
|
+
if (typeof duration === "number") {
|
|
4
|
+
return Number.isFinite(duration) && duration > 0 ? Math.floor(duration) : 0;
|
|
5
|
+
}
|
|
6
|
+
const normalized = duration.trim().toLowerCase();
|
|
7
|
+
const match = normalized.match(/^(\d+)(ms|s|m|h)$/);
|
|
8
|
+
if (!match) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
`Unsupported wait duration "${duration}". Use a number of milliseconds or values like "500ms", "2s", "5m".`,
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const value = Number(match[1]);
|
|
14
|
+
const unit = match[2];
|
|
15
|
+
if (unit === "ms") {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
if (unit === "s") {
|
|
19
|
+
return value * 1000;
|
|
20
|
+
}
|
|
21
|
+
if (unit === "m") {
|
|
22
|
+
return value * 60_000;
|
|
23
|
+
}
|
|
24
|
+
return value * 3_600_000;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { WorkflowAgentOptions } from "./workflowAuthoring/WorkflowAuthoringOptions.types";
|
|
2
|
+
export { WorkflowAuthoringBuilder } from "./workflowAuthoring/WorkflowAuthoringBuilder.types";
|
|
3
|
+
export { WorkflowBranchBuilder } from "./workflowAuthoring/WorkflowBranchBuilder.types";
|
|
4
|
+
export { WorkflowChain } from "./workflowAuthoring/WorkflowChain.types";
|
|
5
|
+
|
|
6
|
+
import { WorkflowAuthoringBuilder } from "./workflowAuthoring/WorkflowAuthoringBuilder.types";
|
|
7
|
+
|
|
8
|
+
export function workflow(id: string): WorkflowAuthoringBuilder {
|
|
9
|
+
return new WorkflowAuthoringBuilder(id);
|
|
10
|
+
}
|