Skip to content

Commit 3c8f4ff

Browse files
Fix #973 - Refine support for http calls on func (#974)
* Fix #973 - Refine support for http calls on func Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Added openapi support Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Add use, secrets, auth Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> --------- Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
1 parent b5d748d commit 3c8f4ff

File tree

51 files changed

+2479
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2479
-357
lines changed

experimental/fluent/agentic/src/main/java/io/serverlessworkflow/fluent/agentic/AgentDoTaskBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public AgentDoTaskBuilder parallel(String name, Object... agents) {
7070
}
7171

7272
@Override
73-
public AgentDoTaskBuilder callFn(String name, Consumer<FuncCallTaskBuilder> cfg) {
74-
this.listBuilder().callFn(name, cfg);
73+
public AgentDoTaskBuilder function(String name, Consumer<FuncCallTaskBuilder> cfg) {
74+
this.listBuilder().function(name, cfg);
7575
return self();
7676
}
7777

experimental/fluent/agentic/src/main/java/io/serverlessworkflow/fluent/agentic/AgentTaskItemListBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public AgentTaskItemListBuilder agent(String name, Object agent) {
5656
AgentAdapters.toExecutors(agent)
5757
.forEach(
5858
exec ->
59-
this.delegate.callFn(
59+
this.delegate.function(
6060
name,
6161
fn -> fn.function(AgentAdapters.toFunction(exec), DefaultAgenticScope.class)));
6262
return self();
@@ -103,8 +103,8 @@ public AgentTaskItemListBuilder parallel(String name, Object... agents) {
103103
}
104104

105105
@Override
106-
public AgentTaskItemListBuilder callFn(String name, Consumer<FuncCallTaskBuilder> cfg) {
107-
this.delegate.callFn(name, cfg);
106+
public AgentTaskItemListBuilder function(String name, Consumer<FuncCallTaskBuilder> cfg) {
107+
this.delegate.function(name, cfg);
108108
return self();
109109
}
110110

experimental/fluent/agentic/src/main/java/io/serverlessworkflow/fluent/agentic/LoopAgentsBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public LoopAgentsBuilder subAgents(String baseName, Object... agents) {
4949
forEachIndexed(
5050
execs,
5151
(exec, idx) ->
52-
funcDelegate.callFn(
52+
funcDelegate.function(
5353
baseName + "-" + idx, fn -> fn.function(AgentAdapters.toFunction(exec))));
5454
return this;
5555
}

experimental/fluent/agentic/src/main/java/io/serverlessworkflow/fluent/agentic/dsl/AgenticDSL.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ public static Consumer<AgentDoTaskBuilder> doTasks(AgentTaskConfigurer... steps)
143143
}
144144

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

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

154154
public static AgentTaskConfigurer agent(Object agent) {

experimental/fluent/agentic/src/test/java/io/serverlessworkflow/fluent/agentic/AgentDslWorkflowTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void assertSequentialAgents(Workflow wf) {
6868
void dslCallFnBare() {
6969
Workflow wf =
7070
workflow("beanCall")
71-
.tasks(tasks -> tasks.callFn("plainCall", fn -> fn.function(ctx -> "pong")))
71+
.tasks(tasks -> tasks.function("plainCall", fn -> fn.function(ctx -> "pong")))
7272
.build();
7373

7474
List<TaskItem> items = wf.getDo();

experimental/fluent/agentic/src/test/java/io/serverlessworkflow/fluent/agentic/AgentWorkflowBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void parallelAgents() {
177177
void testWorkflowCallFnBare() {
178178
Workflow wf =
179179
AgentWorkflowBuilder.workflow()
180-
.tasks(d -> d.callFn("myCall", fn -> fn.function(ctx -> "hello")))
180+
.tasks(d -> d.function("myCall", fn -> fn.function(ctx -> "hello")))
181181
.build();
182182

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

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

199199
TaskItem ti = wf.getDo().get(0);

experimental/fluent/agentic/src/test/java/io/serverlessworkflow/fluent/agentic/EmailDrafterIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void email_drafter_agent() {
6262
tasks ->
6363
tasks
6464
.agent("agentEmailDrafter", emailDrafter)
65-
.callFn("parseDraft", fn(EmailDrafts::parse, String.class))
66-
.callFn("policyCheck", fn(EmailPolicies::policyCheck, EmailDraft.class))
65+
.function("parseDraft", fn(EmailDrafts::parse, String.class))
66+
.function("policyCheck", fn(EmailPolicies::policyCheck, EmailDraft.class))
6767
.switchCase(
6868
"needsHumanReview?",
6969
cases(
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.fluent.func;
17+
18+
import io.serverlessworkflow.api.types.CallHTTP;
19+
import io.serverlessworkflow.api.types.HTTPArguments;
20+
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
21+
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
22+
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
23+
import io.serverlessworkflow.fluent.spec.spi.CallHttpTaskFluent;
24+
25+
public class FuncCallHttpTaskBuilder extends TaskBaseBuilder<FuncCallHttpTaskBuilder>
26+
implements CallHttpTaskFluent<FuncCallHttpTaskBuilder>,
27+
FuncTaskTransformations<FuncCallHttpTaskBuilder>,
28+
ConditionalTaskBuilder<FuncCallHttpTaskBuilder> {
29+
30+
FuncCallHttpTaskBuilder() {
31+
super.setTask(new CallHTTP().withWith(new HTTPArguments()));
32+
}
33+
34+
@Override
35+
public FuncCallHttpTaskBuilder self() {
36+
return this;
37+
}
38+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.fluent.func;
17+
18+
import io.serverlessworkflow.api.types.CallOpenAPI;
19+
import io.serverlessworkflow.api.types.OpenAPIArguments;
20+
import io.serverlessworkflow.api.types.WithOpenAPIParameters;
21+
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
22+
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
23+
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
24+
import io.serverlessworkflow.fluent.spec.spi.CallOpenAPITaskFluent;
25+
26+
public class FuncCallOpenAPITaskBuilder extends TaskBaseBuilder<FuncCallOpenAPITaskBuilder>
27+
implements CallOpenAPITaskFluent<FuncCallOpenAPITaskBuilder>,
28+
FuncTaskTransformations<FuncCallOpenAPITaskBuilder>,
29+
ConditionalTaskBuilder<FuncCallOpenAPITaskBuilder> {
30+
31+
FuncCallOpenAPITaskBuilder() {
32+
final CallOpenAPI callOpenAPI = new CallOpenAPI();
33+
callOpenAPI.setWith(new OpenAPIArguments().withParameters(new WithOpenAPIParameters()));
34+
super.setTask(callOpenAPI);
35+
}
36+
37+
@Override
38+
public FuncCallOpenAPITaskBuilder self() {
39+
return this;
40+
}
41+
}

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncDoTaskBuilder.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public FuncDoTaskBuilder switchCase(
7373
}
7474

7575
@Override
76-
public FuncDoTaskBuilder callFn(String name, Consumer<FuncCallTaskBuilder> cfg) {
77-
this.listBuilder().callFn(name, cfg);
76+
public FuncDoTaskBuilder function(String name, Consumer<FuncCallTaskBuilder> cfg) {
77+
this.listBuilder().function(name, cfg);
7878
return this;
7979
}
8080

@@ -83,4 +83,17 @@ public FuncDoTaskBuilder fork(String name, Consumer<FuncForkTaskBuilder> itemsCo
8383
this.listBuilder().fork(name, itemsConfigurer);
8484
return this;
8585
}
86+
87+
@Override
88+
public FuncDoTaskBuilder http(String name, Consumer<FuncCallHttpTaskBuilder> itemsConfigurer) {
89+
this.listBuilder().http(name, itemsConfigurer);
90+
return this;
91+
}
92+
93+
@Override
94+
public FuncDoTaskBuilder openapi(
95+
String name, Consumer<FuncCallOpenAPITaskBuilder> itemsConfigurer) {
96+
this.listBuilder().openapi(name, itemsConfigurer);
97+
return this;
98+
}
8699
}

0 commit comments

Comments
 (0)