|
| 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.impl.expressions.agentic; |
| 17 | + |
| 18 | +import dev.langchain4j.agentic.cognisphere.Cognisphere; |
| 19 | +import dev.langchain4j.agentic.cognisphere.CognisphereRegistry; |
| 20 | +import io.cloudevents.CloudEvent; |
| 21 | +import io.cloudevents.CloudEventData; |
| 22 | +import io.serverlessworkflow.impl.WorkflowModel; |
| 23 | +import io.serverlessworkflow.impl.WorkflowModelCollection; |
| 24 | +import io.serverlessworkflow.impl.WorkflowModelFactory; |
| 25 | +import java.time.OffsetDateTime; |
| 26 | +import java.util.Map; |
| 27 | + |
| 28 | +class AgenticModelFactory implements WorkflowModelFactory { |
| 29 | + private final Cognisphere cognisphere = CognisphereRegistry.createEphemeralCognisphere(); |
| 30 | + |
| 31 | + private final AgenticModel TrueModel = new AgenticModel(Boolean.TRUE, cognisphere); |
| 32 | + private final AgenticModel FalseModel = new AgenticModel(Boolean.FALSE, cognisphere); |
| 33 | + private final AgenticModel NullModel = new AgenticModel(null, cognisphere); |
| 34 | + |
| 35 | + @Override |
| 36 | + public WorkflowModel combine(Map<String, WorkflowModel> workflowVariables) { |
| 37 | + return new AgenticModel(workflowVariables, cognisphere); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public WorkflowModelCollection createCollection() { |
| 42 | + return new AgenticModelCollection(cognisphere); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public WorkflowModel from(boolean value) { |
| 47 | + return value ? TrueModel : FalseModel; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public WorkflowModel from(Number value) { |
| 52 | + return new AgenticModel(value, cognisphere); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public WorkflowModel from(String value) { |
| 57 | + return new AgenticModel(value, cognisphere); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public WorkflowModel from(CloudEvent ce) { |
| 62 | + return new AgenticModel(ce, cognisphere); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public WorkflowModel from(CloudEventData ce) { |
| 67 | + return new AgenticModel(ce, cognisphere); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public WorkflowModel from(OffsetDateTime value) { |
| 72 | + return new AgenticModel(value, cognisphere); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public WorkflowModel from(Map<String, Object> map) { |
| 77 | + cognisphere.writeStates(map); |
| 78 | + return new AgenticModel(map, cognisphere); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public WorkflowModel fromNull() { |
| 83 | + return NullModel; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public WorkflowModel fromOther(Object value) { |
| 88 | + return new AgenticModel(value, cognisphere); |
| 89 | + } |
| 90 | +} |
0 commit comments