Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public AgentDoTaskBuilder parallel(String name, Object... agents) {
}

@Override
public AgentDoTaskBuilder callFn(String name, Consumer<FuncCallTaskBuilder> cfg) {
this.listBuilder().callFn(name, cfg);
public AgentDoTaskBuilder function(String name, Consumer<FuncCallTaskBuilder> cfg) {
this.listBuilder().function(name, cfg);
return self();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public AgentTaskItemListBuilder agent(String name, Object agent) {
AgentAdapters.toExecutors(agent)
.forEach(
exec ->
this.delegate.callFn(
this.delegate.function(
name,
fn -> fn.function(AgentAdapters.toFunction(exec), DefaultAgenticScope.class)));
return self();
Expand Down Expand Up @@ -103,8 +103,8 @@ public AgentTaskItemListBuilder parallel(String name, Object... agents) {
}

@Override
public AgentTaskItemListBuilder callFn(String name, Consumer<FuncCallTaskBuilder> cfg) {
this.delegate.callFn(name, cfg);
public AgentTaskItemListBuilder function(String name, Consumer<FuncCallTaskBuilder> cfg) {
this.delegate.function(name, cfg);
return self();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public LoopAgentsBuilder subAgents(String baseName, Object... agents) {
forEachIndexed(
execs,
(exec, idx) ->
funcDelegate.callFn(
funcDelegate.function(
baseName + "-" + idx, fn -> fn.function(AgentAdapters.toFunction(exec))));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ public static Consumer<AgentDoTaskBuilder> doTasks(AgentTaskConfigurer... steps)
}

public static <T, V> AgentTaskConfigurer function(Function<T, V> function, Class<T> argClass) {
return list -> list.callFn(fn(function, argClass));
return list -> list.function(fn(function, argClass));
}

public static <T, V> AgentTaskConfigurer function(Function<T, V> function) {
Class<T> clazz = ReflectionUtils.inferInputType(function);
return list -> list.callFn(fn(function, clazz));
return list -> list.function(fn(function, clazz));
}

public static AgentTaskConfigurer agent(Object agent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void assertSequentialAgents(Workflow wf) {
void dslCallFnBare() {
Workflow wf =
workflow("beanCall")
.tasks(tasks -> tasks.callFn("plainCall", fn -> fn.function(ctx -> "pong")))
.tasks(tasks -> tasks.function("plainCall", fn -> fn.function(ctx -> "pong")))
.build();

List<TaskItem> items = wf.getDo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void parallelAgents() {
void testWorkflowCallFnBare() {
Workflow wf =
AgentWorkflowBuilder.workflow()
.tasks(d -> d.callFn("myCall", fn -> fn.function(ctx -> "hello")))
.tasks(d -> d.function("myCall", fn -> fn.function(ctx -> "hello")))
.build();

assertThat(wf.getDo()).hasSize(1);
Expand All @@ -193,7 +193,7 @@ void testWorkflowCallFnWithPredicate() {

Workflow wf =
AgentWorkflowBuilder.workflow()
.tasks(d -> d.callFn("guarded", fn -> fn.function(ctx -> "x").when(guard)))
.tasks(d -> d.function("guarded", fn -> fn.function(ctx -> "x").when(guard)))
.build();

TaskItem ti = wf.getDo().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void email_drafter_agent() {
tasks ->
tasks
.agent("agentEmailDrafter", emailDrafter)
.callFn("parseDraft", fn(EmailDrafts::parse, String.class))
.callFn("policyCheck", fn(EmailPolicies::policyCheck, EmailDraft.class))
.function("parseDraft", fn(EmailDrafts::parse, String.class))
.function("policyCheck", fn(EmailPolicies::policyCheck, EmailDraft.class))
.switchCase(
"needsHumanReview?",
cases(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.CallHTTP;
import io.serverlessworkflow.api.types.HTTPArguments;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
import io.serverlessworkflow.fluent.spec.spi.CallHttpTaskFluent;

public class FuncCallHttpTaskBuilder extends TaskBaseBuilder<FuncCallHttpTaskBuilder>
implements CallHttpTaskFluent<FuncCallHttpTaskBuilder>,
FuncTaskTransformations<FuncCallHttpTaskBuilder>,
ConditionalTaskBuilder<FuncCallHttpTaskBuilder> {

FuncCallHttpTaskBuilder() {
super.setTask(new CallHTTP().withWith(new HTTPArguments()));
}

@Override
public FuncCallHttpTaskBuilder self() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.CallOpenAPI;
import io.serverlessworkflow.api.types.OpenAPIArguments;
import io.serverlessworkflow.api.types.WithOpenAPIParameters;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
import io.serverlessworkflow.fluent.spec.spi.CallOpenAPITaskFluent;

public class FuncCallOpenAPITaskBuilder extends TaskBaseBuilder<FuncCallOpenAPITaskBuilder>
implements CallOpenAPITaskFluent<FuncCallOpenAPITaskBuilder>,
FuncTaskTransformations<FuncCallOpenAPITaskBuilder>,
ConditionalTaskBuilder<FuncCallOpenAPITaskBuilder> {

FuncCallOpenAPITaskBuilder() {
final CallOpenAPI callOpenAPI = new CallOpenAPI();
callOpenAPI.setWith(new OpenAPIArguments().withParameters(new WithOpenAPIParameters()));
super.setTask(callOpenAPI);
}

@Override
public FuncCallOpenAPITaskBuilder self() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public FuncDoTaskBuilder switchCase(
}

@Override
public FuncDoTaskBuilder callFn(String name, Consumer<FuncCallTaskBuilder> cfg) {
this.listBuilder().callFn(name, cfg);
public FuncDoTaskBuilder function(String name, Consumer<FuncCallTaskBuilder> cfg) {
this.listBuilder().function(name, cfg);
return this;
}

Expand All @@ -83,4 +83,17 @@ public FuncDoTaskBuilder fork(String name, Consumer<FuncForkTaskBuilder> itemsCo
this.listBuilder().fork(name, itemsConfigurer);
return this;
}

@Override
public FuncDoTaskBuilder http(String name, Consumer<FuncCallHttpTaskBuilder> itemsConfigurer) {
this.listBuilder().http(name, itemsConfigurer);
return this;
}

@Override
public FuncDoTaskBuilder openapi(
String name, Consumer<FuncCallOpenAPITaskBuilder> itemsConfigurer) {
this.listBuilder().openapi(name, itemsConfigurer);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.CallHTTP;
import io.serverlessworkflow.api.types.CallOpenAPI;
import io.serverlessworkflow.api.types.CallTask;
import io.serverlessworkflow.api.types.Task;
import io.serverlessworkflow.api.types.TaskItem;
import io.serverlessworkflow.fluent.func.spi.FuncDoFluent;
Expand Down Expand Up @@ -45,16 +48,16 @@ protected FuncTaskItemListBuilder newItemListBuilder() {
}

@Override
public FuncTaskItemListBuilder callFn(String name, Consumer<FuncCallTaskBuilder> consumer) {
public FuncTaskItemListBuilder function(String name, Consumer<FuncCallTaskBuilder> consumer) {
name = this.defaultNameAndRequireConfig(name, consumer);
final FuncCallTaskBuilder callTaskJavaBuilder = new FuncCallTaskBuilder();
consumer.accept(callTaskJavaBuilder);
return addTaskItem(new TaskItem(name, new Task().withCallTask(callTaskJavaBuilder.build())));
}

@Override
public FuncTaskItemListBuilder callFn(Consumer<FuncCallTaskBuilder> consumer) {
return this.callFn(UUID.randomUUID().toString(), consumer);
public FuncTaskItemListBuilder function(Consumer<FuncCallTaskBuilder> consumer) {
return this.function(UUID.randomUUID().toString(), consumer);
}

@Override
Expand Down Expand Up @@ -116,4 +119,38 @@ public FuncTaskItemListBuilder fork(String name, Consumer<FuncForkTaskBuilder> i
return this.addTaskItem(
new TaskItem(name, new Task().withForkTask(forkTaskJavaBuilder.build())));
}

@Override
public FuncTaskItemListBuilder http(
String name, Consumer<FuncCallHttpTaskBuilder> itemsConfigurer) {
name = this.defaultNameAndRequireConfig(name, itemsConfigurer);

final FuncCallHttpTaskBuilder httpTaskJavaBuilder = new FuncCallHttpTaskBuilder();
itemsConfigurer.accept(httpTaskJavaBuilder);

final CallHTTP callHTTP = httpTaskJavaBuilder.build();
final CallTask callTask = new CallTask();
callTask.setCallHTTP(callHTTP);
final Task task = new Task();
task.setCallTask(callTask);

return this.addTaskItem(new TaskItem(name, task));
}

@Override
public FuncTaskItemListBuilder openapi(
String name, Consumer<FuncCallOpenAPITaskBuilder> itemsConfigurer) {
name = this.defaultNameAndRequireConfig(name, itemsConfigurer);

final FuncCallOpenAPITaskBuilder openAPITaskBuilder = new FuncCallOpenAPITaskBuilder();
itemsConfigurer.accept(openAPITaskBuilder);

final CallOpenAPI callOpenAPI = openAPITaskBuilder.build();
final CallTask callTask = new CallTask();
callTask.setCallOpenAPI(callOpenAPI);
final Task task = new Task();
task.setCallTask(callTask);

return this.addTaskItem(new TaskItem(name, task));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.func.configurers;

import io.serverlessworkflow.fluent.func.FuncCallHttpTaskBuilder;
import java.util.function.Consumer;

@FunctionalInterface
public interface FuncCallHttpConfigurer extends Consumer<FuncCallHttpTaskBuilder> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.func.configurers;

import io.serverlessworkflow.fluent.func.FuncCallOpenAPITaskBuilder;
import java.util.function.Consumer;

@FunctionalInterface
public interface FuncCallOpenAPIConfigurer extends Consumer<FuncCallOpenAPITaskBuilder> {}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public final class ConsumeStep<T> extends Step<ConsumeStep<T>, FuncCallTaskBuild
protected void configure(
FuncTaskItemListBuilder list, java.util.function.Consumer<FuncCallTaskBuilder> post) {
if (name == null) {
list.callFn(
list.function(
cb -> {
// prefer the typed consumer if your builder supports it; otherwise fallback:
if (argClass != null) cb.consumer(consumer, argClass);
else cb.consumer(consumer);
post.accept(cb);
});
} else {
list.callFn(
list.function(
name,
cb -> {
if (argClass != null) cb.consumer(consumer, argClass);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.func.dsl;

import io.serverlessworkflow.fluent.func.FuncCallHttpTaskBuilder;
import io.serverlessworkflow.fluent.func.configurers.FuncCallHttpConfigurer;
import io.serverlessworkflow.fluent.spec.dsl.BaseCallHttpSpec;

public class FuncCallHttpSpec extends BaseCallHttpSpec<FuncCallHttpSpec>
implements FuncCallHttpConfigurer {

@Override
protected FuncCallHttpSpec self() {
return this;
}

@Override
public void accept(FuncCallHttpTaskBuilder funcCallHttpTaskBuilder) {
super.accept(funcCallHttpTaskBuilder);
}
}
Loading