From e3953fe47862ce4ed80ddf0b0e90cfa501b5da25 Mon Sep 17 00:00:00 2001 From: Enrico Olivelli Date: Tue, 3 Oct 2023 17:28:13 +0200 Subject: [PATCH] Move TransformContext to a dedicated module (#519) --- .../langstream-agents-commons/pom.xml | 79 +++++++++++++++++++ .../ai/agents/commons}/AvroUtil.java | 2 +- .../ai/agents/commons}/JsonConverter.java | 19 ++++- .../ai/agents/commons}/JsonRecord.java | 2 +- .../ai/agents/commons}/TransformContext.java | 48 +++++++++-- .../agents/commons}/TransformSchemaType.java | 2 +- .../jstl/DisabledInvocationBeanResolver.java | 2 +- .../agents/commons}/jstl/JstlEvaluator.java | 4 +- .../agents/commons}/jstl/JstlFunctions.java | 6 +- .../jstl/JstlTransformContextAdapter.java | 6 +- .../commons}/jstl/JstlTypeConverter.java | 4 +- .../agents/commons}/jstl/StandardContext.java | 2 +- .../jstl/predicate/JstlPredicate.java | 6 +- .../jstl/predicate/TransformPredicate.java | 4 +- .../langstream-ai-agents/pom.xml | 19 ++--- .../ai/agents/GenAIToolKitAgent.java | 6 +- .../ai/agents/rerank/ReRankAgent.java | 4 +- .../datastax/oss/streaming/ai/CastStep.java | 5 +- .../oss/streaming/ai/ChatCompletionsStep.java | 3 +- .../streaming/ai/ComputeAIEmbeddingsStep.java | 3 +- .../oss/streaming/ai/ComputeStep.java | 7 +- .../oss/streaming/ai/DropFieldStep.java | 1 + .../datastax/oss/streaming/ai/DropStep.java | 2 + .../oss/streaming/ai/FlattenStep.java | 3 +- .../oss/streaming/ai/MergeKeyValueStep.java | 3 +- .../datastax/oss/streaming/ai/QueryStep.java | 3 +- .../predicate => }/StepPredicatePair.java | 4 +- .../oss/streaming/ai/TextCompletionsStep.java | 3 +- .../oss/streaming/ai/TransformStep.java | 1 + .../oss/streaming/ai/UnwrapKeyValueStep.java | 2 + .../oss/streaming/ai/model/ComputeField.java | 2 +- .../streaming/StreamingAnswersConsumer.java | 2 +- .../ai/util/TransformFunctionUtil.java | 46 +---------- .../transforms/TransformFunction.java | 6 +- .../transforms/TransformFunctionTest.java | 2 +- .../oss/streaming/ai/CastStepTest.java | 2 +- .../com/datastax/oss/streaming/ai/Utils.java | 3 +- .../streaming/ai/jstl/JstlEvaluatorTest.java | 4 +- .../streaming/ai/jstl/JstlFunctionsTest.java | 1 + .../jstl/JstlTransformContextAdapterTest.java | 3 +- .../ai/jstl/JstlTypeConverterTest.java | 1 + .../ai/jstl/predicate/JstlPredicateTest.java | 3 +- .../oss/streaming/ai/util/AvroUtilTest.java | 1 + .../agents/vector/QueryVectorDBAgent.java | 4 +- .../agents/vector/jdbc/JdbcWriter.java | 4 +- .../agents/vector/milvus/MilvusWriter.java | 4 +- .../vector/pinecone/PineconeWriter.java | 4 +- langstream-agents/pom.xml | 1 + 48 files changed, 226 insertions(+), 122 deletions(-) create mode 100644 langstream-agents/langstream-agents-commons/pom.xml rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/AvroUtil.java (99%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/JsonConverter.java (95%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/JsonRecord.java (94%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/TransformContext.java (90%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/TransformSchemaType.java (97%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/jstl/DisabledInvocationBeanResolver.java (97%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/jstl/JstlEvaluator.java (98%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/jstl/JstlFunctions.java (98%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/jstl/JstlTransformContextAdapter.java (98%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/jstl/JstlTypeConverter.java (99%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/jstl/StandardContext.java (98%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/jstl/predicate/JstlPredicate.java (90%) rename langstream-agents/{langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai => langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons}/jstl/predicate/TransformPredicate.java (89%) rename langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/{jstl/predicate => }/StepPredicatePair.java (90%) diff --git a/langstream-agents/langstream-agents-commons/pom.xml b/langstream-agents/langstream-agents-commons/pom.xml new file mode 100644 index 000000000..0a5c7d311 --- /dev/null +++ b/langstream-agents/langstream-agents-commons/pom.xml @@ -0,0 +1,79 @@ + + + + + ai.langstream + langstream-agents + 0.0.23-SNAPSHOT + + 4.0.0 + langstream-agents-commons + jar + LangStream - Common Agent utilities + + ${project.build.directory} + + + + ${project.groupId} + langstream-api + ${project.version} + provided + + + com.networknt + json-schema-validator + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + org.apache.avro + avro + + + org.apache.tomcat.embed + tomcat-embed-el + + + org.apache.commons + commons-collections4 + + + com.fasterxml.jackson.core + jackson-databind + + + + org.apache.pulsar + pulsar-client-original + + + io.netty + * + + + io.netty.incubator + * + + + + + diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/AvroUtil.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/AvroUtil.java similarity index 99% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/AvroUtil.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/AvroUtil.java index 3bb13d5e5..8037512b7 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/AvroUtil.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/AvroUtil.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.util; +package ai.langstream.ai.agents.commons; import java.util.ArrayList; import java.util.Collection; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/JsonConverter.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/JsonConverter.java similarity index 95% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/JsonConverter.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/JsonConverter.java index d55b9aee8..7a3fca7a0 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/JsonConverter.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/JsonConverter.java @@ -13,9 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.util; - -import static com.datastax.oss.streaming.ai.util.TransformFunctionUtil.getBytes; +package ai.langstream.ai.agents.commons; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -247,4 +245,19 @@ JsonNode toJson(Schema schema, Object value) { } }); } + + public static byte[] getBytes(ByteBuffer byteBuffer) { + if (byteBuffer == null) { + return null; + } + if (byteBuffer.hasArray() + && byteBuffer.arrayOffset() == 0 + && byteBuffer.array().length == byteBuffer.remaining()) { + return byteBuffer.array(); + } + // Direct buffer is not backed by array and it needs to be read from direct memory + byte[] array = new byte[byteBuffer.remaining()]; + byteBuffer.get(array); + return array; + } } diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/JsonRecord.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/JsonRecord.java similarity index 94% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/JsonRecord.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/JsonRecord.java index 56a8f08b4..7b5af00fc 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/JsonRecord.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/JsonRecord.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.model; +package ai.langstream.ai.agents.commons; import java.util.Map; import lombok.Data; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TransformContext.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/TransformContext.java similarity index 90% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TransformContext.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/TransformContext.java index 568ac37c0..a7e1c02a6 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TransformContext.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/TransformContext.java @@ -13,28 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai; +package ai.langstream.ai.agents.commons; -import static com.datastax.oss.streaming.ai.util.TransformFunctionUtil.safeClone; - -import com.datastax.oss.streaming.ai.model.JsonRecord; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; -import com.datastax.oss.streaming.ai.util.AvroUtil; -import com.datastax.oss.streaming.ai.util.JsonConverter; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Set; import lombok.Data; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.avro.Conversions; import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericDatumWriter; import org.apache.avro.generic.GenericRecord; import org.apache.avro.io.BinaryEncoder; @@ -324,4 +324,38 @@ public void setResultField( } } } + + public static Object safeClone(Object object) { + if (object == null) { + return null; + } + if (object.getClass().isPrimitive() + || object instanceof String + || object instanceof Number + || object instanceof Boolean) { + return object; + } + if (object instanceof Map map) { + HashMap res = new HashMap<>(); + map.forEach((k, v) -> res.put(safeClone(k), safeClone(v))); + return res; + } + if (object instanceof List list) { + List res = new ArrayList<>(); + list.forEach(v -> res.add(safeClone(v))); + return res; + } + if (object instanceof Set set) { + Set res = new HashSet<>(); + set.forEach(v -> res.add(safeClone(v))); + return res; + } + if (object instanceof GenericRecord genericRecord) { + return GenericData.get().deepCopy(genericRecord.getSchema(), genericRecord); + } + if (object instanceof JsonNode jsonNode) { + return jsonNode.deepCopy(); + } + throw new UnsupportedOperationException("Cannot copy a value of " + object.getClass()); + } } diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/TransformSchemaType.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/TransformSchemaType.java similarity index 97% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/TransformSchemaType.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/TransformSchemaType.java index b6891c1d0..9716f640b 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/TransformSchemaType.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/TransformSchemaType.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.model; +package ai.langstream.ai.agents.commons; public enum TransformSchemaType { STRING, diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/DisabledInvocationBeanResolver.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/DisabledInvocationBeanResolver.java similarity index 97% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/DisabledInvocationBeanResolver.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/DisabledInvocationBeanResolver.java index 838f19521..32abe30ad 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/DisabledInvocationBeanResolver.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/DisabledInvocationBeanResolver.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.jstl; +package ai.langstream.ai.agents.commons.jstl; import jakarta.el.BeanELResolver; import jakarta.el.ELContext; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlEvaluator.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlEvaluator.java similarity index 98% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlEvaluator.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlEvaluator.java index 46c43c806..ccff46b0e 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlEvaluator.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlEvaluator.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.jstl; +package ai.langstream.ai.agents.commons.jstl; -import com.datastax.oss.streaming.ai.TransformContext; +import ai.langstream.ai.agents.commons.TransformContext; import jakarta.el.ELContext; import jakarta.el.ExpressionFactory; import jakarta.el.ValueExpression; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlFunctions.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlFunctions.java similarity index 98% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlFunctions.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlFunctions.java index e567fdaa3..a78cc24b2 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlFunctions.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlFunctions.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.jstl; +package ai.langstream.ai.agents.commons.jstl; -import com.datastax.oss.streaming.ai.TransformContext; -import com.datastax.oss.streaming.ai.jstl.predicate.JstlPredicate; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.jstl.predicate.JstlPredicate; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.el.ELException; import java.lang.reflect.Array; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlTransformContextAdapter.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlTransformContextAdapter.java similarity index 98% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlTransformContextAdapter.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlTransformContextAdapter.java index 6aa7832a6..5abd4b2c4 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlTransformContextAdapter.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlTransformContextAdapter.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.jstl; +package ai.langstream.ai.agents.commons.jstl; -import com.datastax.oss.streaming.ai.TransformContext; -import com.datastax.oss.streaming.ai.util.AvroUtil; +import ai.langstream.ai.agents.commons.AvroUtil; +import ai.langstream.ai.agents.commons.TransformContext; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlTypeConverter.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlTypeConverter.java similarity index 99% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlTypeConverter.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlTypeConverter.java index 74ddecf62..6b49389d0 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/JstlTypeConverter.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/JstlTypeConverter.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.jstl; +package ai.langstream.ai.agents.commons.jstl; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import jakarta.el.ELContext; import jakarta.el.ELException; import jakarta.el.TypeConverter; @@ -46,7 +45,6 @@ public class JstlTypeConverter extends TypeConverter { public static final JstlTypeConverter INSTANCE = new JstlTypeConverter(); - @SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL") protected Boolean coerceToBoolean(Object value) { if (value instanceof byte[]) { return Schema.BOOL.decode((byte[]) value); diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/StandardContext.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/StandardContext.java similarity index 98% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/StandardContext.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/StandardContext.java index 75eff0efe..c39989aeb 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/StandardContext.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/StandardContext.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.jstl; +package ai.langstream.ai.agents.commons.jstl; import jakarta.el.ArrayELResolver; import jakarta.el.BeanNameELResolver; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/predicate/JstlPredicate.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/predicate/JstlPredicate.java similarity index 90% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/predicate/JstlPredicate.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/predicate/JstlPredicate.java index 46b00eac3..35c973fdc 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/predicate/JstlPredicate.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/predicate/JstlPredicate.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.jstl.predicate; +package ai.langstream.ai.agents.commons.jstl.predicate; -import com.datastax.oss.streaming.ai.TransformContext; -import com.datastax.oss.streaming.ai.jstl.JstlEvaluator; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.jstl.JstlEvaluator; import jakarta.el.ELException; import jakarta.el.PropertyNotFoundException; import lombok.extern.slf4j.Slf4j; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/predicate/TransformPredicate.java b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/predicate/TransformPredicate.java similarity index 89% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/predicate/TransformPredicate.java rename to langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/predicate/TransformPredicate.java index 698461c07..bcdd4f424 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/predicate/TransformPredicate.java +++ b/langstream-agents/langstream-agents-commons/src/main/java/ai/langstream/ai/agents/commons/jstl/predicate/TransformPredicate.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.jstl.predicate; +package ai.langstream.ai.agents.commons.jstl.predicate; -import com.datastax.oss.streaming.ai.TransformContext; +import ai.langstream.ai.agents.commons.TransformContext; import java.util.function.Predicate; /** diff --git a/langstream-agents/langstream-ai-agents/pom.xml b/langstream-agents/langstream-ai-agents/pom.xml index 679994a51..a1a339402 100644 --- a/langstream-agents/langstream-ai-agents/pom.xml +++ b/langstream-agents/langstream-ai-agents/pom.xml @@ -36,6 +36,12 @@ ${project.version} provided + + ${project.groupId} + langstream-agents-commons + ${project.version} + + com.google.api-client google-api-client @@ -206,18 +212,7 @@ com.samskivert jmustache - - org.apache.tomcat.embed - tomcat-embed-el - - - org.apache.commons - commons-collections4 - - - com.fasterxml.jackson.core - jackson-databind - + org.projectlombok lombok diff --git a/langstream-agents/langstream-ai-agents/src/main/java/ai/langstream/ai/agents/GenAIToolKitAgent.java b/langstream-agents/langstream-ai-agents/src/main/java/ai/langstream/ai/agents/GenAIToolKitAgent.java index 18e61f522..8053584ae 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/ai/langstream/ai/agents/GenAIToolKitAgent.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/ai/langstream/ai/agents/GenAIToolKitAgent.java @@ -15,6 +15,8 @@ */ package ai.langstream.ai.agents; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.TransformSchemaType; import ai.langstream.ai.agents.datasource.DataSourceProviderRegistry; import ai.langstream.ai.agents.services.ServiceProviderRegistry; import ai.langstream.api.runner.code.AbstractAgentCode; @@ -26,11 +28,9 @@ import ai.langstream.api.runner.code.SimpleRecord; import ai.langstream.api.runner.topics.TopicProducer; import ai.langstream.api.runtime.ComponentType; -import com.datastax.oss.streaming.ai.TransformContext; +import com.datastax.oss.streaming.ai.StepPredicatePair; import com.datastax.oss.streaming.ai.TransformStep; import com.datastax.oss.streaming.ai.datasource.QueryStepDataSource; -import com.datastax.oss.streaming.ai.jstl.predicate.StepPredicatePair; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; import com.datastax.oss.streaming.ai.model.config.StepConfig; import com.datastax.oss.streaming.ai.model.config.TransformStepConfig; import com.datastax.oss.streaming.ai.services.ServiceProvider; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/ai/langstream/ai/agents/rerank/ReRankAgent.java b/langstream-agents/langstream-ai-agents/src/main/java/ai/langstream/ai/agents/rerank/ReRankAgent.java index 3f390bfd8..cf47d4c88 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/ai/langstream/ai/agents/rerank/ReRankAgent.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/ai/langstream/ai/agents/rerank/ReRankAgent.java @@ -18,11 +18,11 @@ import static ai.langstream.ai.agents.GenAIToolKitAgent.transformContextToRecord; import ai.langstream.ai.agents.GenAIToolKitAgent; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.jstl.JstlEvaluator; import ai.langstream.api.runner.code.Record; import ai.langstream.api.runner.code.SingleRecordAgentProcessor; import ai.langstream.api.util.ConfigurationUtils; -import com.datastax.oss.streaming.ai.TransformContext; -import com.datastax.oss.streaming.ai.jstl.JstlEvaluator; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/CastStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/CastStep.java index 09c81d3f9..53455b37c 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/CastStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/CastStep.java @@ -17,8 +17,9 @@ import static com.datastax.oss.streaming.ai.util.TransformFunctionUtil.attemptJsonConversion; -import com.datastax.oss.streaming.ai.jstl.JstlTypeConverter; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.TransformSchemaType; +import ai.langstream.ai.agents.commons.jstl.JstlTypeConverter; import java.sql.Time; import java.sql.Timestamp; import java.time.Instant; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ChatCompletionsStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ChatCompletionsStep.java index cab1cd8b3..68a24af90 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ChatCompletionsStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ChatCompletionsStep.java @@ -17,12 +17,13 @@ import static com.datastax.oss.streaming.ai.util.TransformFunctionUtil.convertToMap; +import ai.langstream.ai.agents.commons.JsonRecord; +import ai.langstream.ai.agents.commons.TransformContext; import com.datastax.oss.streaming.ai.completions.ChatChoice; import com.datastax.oss.streaming.ai.completions.ChatCompletions; import com.datastax.oss.streaming.ai.completions.ChatMessage; import com.datastax.oss.streaming.ai.completions.Chunk; import com.datastax.oss.streaming.ai.completions.CompletionsService; -import com.datastax.oss.streaming.ai.model.JsonRecord; import com.datastax.oss.streaming.ai.model.config.ChatCompletionsConfig; import com.datastax.oss.streaming.ai.streaming.StreamingAnswersConsumer; import com.datastax.oss.streaming.ai.streaming.StreamingAnswersConsumerFactory; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ComputeAIEmbeddingsStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ComputeAIEmbeddingsStep.java index 8aacc6f44..bc017984a 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ComputeAIEmbeddingsStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ComputeAIEmbeddingsStep.java @@ -15,9 +15,10 @@ */ package com.datastax.oss.streaming.ai; +import ai.langstream.ai.agents.commons.JsonRecord; +import ai.langstream.ai.agents.commons.TransformContext; import ai.langstream.api.util.OrderedAsyncBatchExecutor; import com.datastax.oss.streaming.ai.embeddings.EmbeddingsService; -import com.datastax.oss.streaming.ai.model.JsonRecord; import com.samskivert.mustache.Mustache; import com.samskivert.mustache.Template; import java.util.ArrayList; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ComputeStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ComputeStep.java index f37f33760..634ac4752 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ComputeStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/ComputeStep.java @@ -15,11 +15,12 @@ */ package com.datastax.oss.streaming.ai; -import com.datastax.oss.streaming.ai.jstl.JstlTypeConverter; +import ai.langstream.ai.agents.commons.AvroUtil; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.TransformSchemaType; +import ai.langstream.ai.agents.commons.jstl.JstlTypeConverter; import com.datastax.oss.streaming.ai.model.ComputeField; import com.datastax.oss.streaming.ai.model.ComputeFieldType; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; -import com.datastax.oss.streaming.ai.util.AvroUtil; import java.math.BigDecimal; import java.nio.ByteBuffer; import java.sql.Time; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/DropFieldStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/DropFieldStep.java index 8f8597f1a..6d4e5a243 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/DropFieldStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/DropFieldStep.java @@ -15,6 +15,7 @@ */ package com.datastax.oss.streaming.ai; +import ai.langstream.ai.agents.commons.TransformContext; import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/DropStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/DropStep.java index 937ebbb20..0d47325d5 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/DropStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/DropStep.java @@ -15,6 +15,8 @@ */ package com.datastax.oss.streaming.ai; +import ai.langstream.ai.agents.commons.TransformContext; + /** * Drops a message from further processing. Works in conjunctions with predicates to selectively * choose which messages to drop diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/FlattenStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/FlattenStep.java index 59ffe160f..b2eb54b96 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/FlattenStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/FlattenStep.java @@ -15,7 +15,8 @@ */ package com.datastax.oss.streaming.ai; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.TransformSchemaType; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/MergeKeyValueStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/MergeKeyValueStep.java index c10d4cee7..15eb31718 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/MergeKeyValueStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/MergeKeyValueStep.java @@ -15,7 +15,8 @@ */ package com.datastax.oss.streaming.ai; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.TransformSchemaType; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/QueryStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/QueryStep.java index e86f928a0..9845e1b77 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/QueryStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/QueryStep.java @@ -15,8 +15,9 @@ */ package com.datastax.oss.streaming.ai; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.TransformSchemaType; import com.datastax.oss.streaming.ai.datasource.QueryStepDataSource; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; import com.fasterxml.jackson.databind.JsonNode; import java.util.ArrayList; import java.util.List; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/predicate/StepPredicatePair.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/StepPredicatePair.java similarity index 90% rename from langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/predicate/StepPredicatePair.java rename to langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/StepPredicatePair.java index 27b057ba5..d59307d88 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/jstl/predicate/StepPredicatePair.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/StepPredicatePair.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.datastax.oss.streaming.ai.jstl.predicate; +package com.datastax.oss.streaming.ai; -import com.datastax.oss.streaming.ai.TransformStep; +import ai.langstream.ai.agents.commons.jstl.predicate.TransformPredicate; import lombok.Data; /** diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TextCompletionsStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TextCompletionsStep.java index e666b83bd..41d4faeb8 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TextCompletionsStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TextCompletionsStep.java @@ -17,9 +17,10 @@ import static com.datastax.oss.streaming.ai.util.TransformFunctionUtil.convertToMap; +import ai.langstream.ai.agents.commons.JsonRecord; +import ai.langstream.ai.agents.commons.TransformContext; import com.datastax.oss.streaming.ai.completions.Chunk; import com.datastax.oss.streaming.ai.completions.CompletionsService; -import com.datastax.oss.streaming.ai.model.JsonRecord; import com.datastax.oss.streaming.ai.model.config.TextCompletionsConfig; import com.datastax.oss.streaming.ai.streaming.StreamingAnswersConsumer; import com.datastax.oss.streaming.ai.streaming.StreamingAnswersConsumerFactory; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TransformStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TransformStep.java index fb69edcab..b33c85e30 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TransformStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/TransformStep.java @@ -15,6 +15,7 @@ */ package com.datastax.oss.streaming.ai; +import ai.langstream.ai.agents.commons.TransformContext; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/UnwrapKeyValueStep.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/UnwrapKeyValueStep.java index ce13ad47d..ae49d8456 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/UnwrapKeyValueStep.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/UnwrapKeyValueStep.java @@ -15,6 +15,8 @@ */ package com.datastax.oss.streaming.ai; +import ai.langstream.ai.agents.commons.TransformContext; + public class UnwrapKeyValueStep implements TransformStep { private final boolean unwrapKey; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/ComputeField.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/ComputeField.java index dabf7c5a5..ecfe60bf5 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/ComputeField.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/model/ComputeField.java @@ -15,7 +15,7 @@ */ package com.datastax.oss.streaming.ai.model; -import com.datastax.oss.streaming.ai.jstl.JstlEvaluator; +import ai.langstream.ai.agents.commons.jstl.JstlEvaluator; import jakarta.el.ELException; import java.math.BigDecimal; import java.sql.Time; diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/streaming/StreamingAnswersConsumer.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/streaming/StreamingAnswersConsumer.java index dd38a3faa..010107495 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/streaming/StreamingAnswersConsumer.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/streaming/StreamingAnswersConsumer.java @@ -15,7 +15,7 @@ */ package com.datastax.oss.streaming.ai.streaming; -import com.datastax.oss.streaming.ai.TransformContext; +import ai.langstream.ai.agents.commons.TransformContext; public interface StreamingAnswersConsumer { void streamAnswerChunk(int index, String message, boolean last, TransformContext outputMessage); diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/TransformFunctionUtil.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/TransformFunctionUtil.java index 75e221526..fd3ec3712 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/TransformFunctionUtil.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/util/TransformFunctionUtil.java @@ -15,6 +15,9 @@ */ package com.datastax.oss.streaming.ai.util; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.TransformSchemaType; +import ai.langstream.ai.agents.commons.jstl.predicate.JstlPredicate; import com.azure.ai.openai.OpenAIAsyncClient; import com.azure.ai.openai.OpenAIClient; import com.azure.ai.openai.OpenAIClientBuilder; @@ -35,19 +38,16 @@ import com.datastax.oss.streaming.ai.FlattenStep; import com.datastax.oss.streaming.ai.MergeKeyValueStep; import com.datastax.oss.streaming.ai.QueryStep; +import com.datastax.oss.streaming.ai.StepPredicatePair; import com.datastax.oss.streaming.ai.TextCompletionsStep; -import com.datastax.oss.streaming.ai.TransformContext; import com.datastax.oss.streaming.ai.TransformStep; import com.datastax.oss.streaming.ai.UnwrapKeyValueStep; import com.datastax.oss.streaming.ai.completions.CompletionsService; import com.datastax.oss.streaming.ai.datasource.CassandraDataSource; import com.datastax.oss.streaming.ai.datasource.QueryStepDataSource; import com.datastax.oss.streaming.ai.embeddings.EmbeddingsService; -import com.datastax.oss.streaming.ai.jstl.predicate.JstlPredicate; -import com.datastax.oss.streaming.ai.jstl.predicate.StepPredicatePair; import com.datastax.oss.streaming.ai.model.ComputeField; import com.datastax.oss.streaming.ai.model.ComputeFieldType; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; import com.datastax.oss.streaming.ai.model.config.CastConfig; import com.datastax.oss.streaming.ai.model.config.ChatCompletionsConfig; import com.datastax.oss.streaming.ai.model.config.ComputeAIEmbeddingsConfig; @@ -64,7 +64,6 @@ import com.datastax.oss.streaming.ai.services.ServiceProvider; import com.datastax.oss.streaming.ai.streaming.StreamingAnswersConsumerFactory; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.nio.ByteBuffer; @@ -75,7 +74,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -87,8 +85,6 @@ import javax.net.ssl.X509TrustManager; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.apache.avro.generic.GenericData; -import org.apache.avro.generic.GenericRecord; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -424,40 +420,6 @@ public static byte[] getBytes(ByteBuffer byteBuffer) { return array; } - public static Object safeClone(Object object) { - if (object == null) { - return null; - } - if (object.getClass().isPrimitive() - || object instanceof String - || object instanceof Number - || object instanceof Boolean) { - return object; - } - if (object instanceof Map map) { - HashMap res = new HashMap<>(); - map.forEach((k, v) -> res.put(safeClone(k), safeClone(v))); - return res; - } - if (object instanceof List list) { - List res = new ArrayList<>(); - list.forEach(v -> res.add(safeClone(v))); - return res; - } - if (object instanceof Set set) { - Set res = new HashSet<>(); - set.forEach(v -> res.add(safeClone(v))); - return res; - } - if (object instanceof GenericRecord genericRecord) { - return GenericData.get().deepCopy(genericRecord.getSchema(), genericRecord); - } - if (object instanceof JsonNode jsonNode) { - return jsonNode.deepCopy(); - } - throw new UnsupportedOperationException("Cannot copy a value of " + object.getClass()); - } - private static class MockHttpClient implements HttpClient { private final java.net.http.HttpClient httpClient; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunction.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunction.java index 67469cb61..30fccf983 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunction.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunction.java @@ -17,13 +17,13 @@ import static com.datastax.oss.streaming.ai.util.TransformFunctionUtil.buildStep; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.TransformSchemaType; import ai.langstream.ai.agents.services.impl.HuggingFaceProvider; import com.datastax.oss.streaming.ai.JsonNodeSchema; -import com.datastax.oss.streaming.ai.TransformContext; +import com.datastax.oss.streaming.ai.StepPredicatePair; import com.datastax.oss.streaming.ai.TransformStep; import com.datastax.oss.streaming.ai.datasource.QueryStepDataSource; -import com.datastax.oss.streaming.ai.jstl.predicate.StepPredicatePair; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; import com.datastax.oss.streaming.ai.model.config.StepConfig; import com.datastax.oss.streaming.ai.model.config.TransformStepConfig; import com.datastax.oss.streaming.ai.services.OpenAIServiceProvider; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunctionTest.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunctionTest.java index f696f1aa6..bdeac3827 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunctionTest.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunctionTest.java @@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import com.datastax.oss.streaming.ai.TransformContext; +import ai.langstream.ai.agents.commons.TransformContext; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.util.List; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/CastStepTest.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/CastStepTest.java index fa3203f43..525d2fdc1 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/CastStepTest.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/CastStepTest.java @@ -19,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; +import ai.langstream.ai.agents.commons.TransformSchemaType; import java.nio.charset.StandardCharsets; import java.sql.Time; import java.sql.Timestamp; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/Utils.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/Utils.java index a9d8135d6..c263c1257 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/Utils.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/Utils.java @@ -21,7 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import com.datastax.oss.streaming.ai.model.TransformSchemaType; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.TransformSchemaType; import com.datastax.oss.streaming.ai.util.TransformFunctionUtil; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlEvaluatorTest.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlEvaluatorTest.java index 2c556b0f0..51b6877d1 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlEvaluatorTest.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlEvaluatorTest.java @@ -18,7 +18,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import com.datastax.oss.streaming.ai.TransformContext; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.jstl.JstlEvaluator; +import ai.langstream.ai.agents.commons.jstl.JstlFunctions; import com.datastax.oss.streaming.ai.Utils; import jakarta.el.MethodNotFoundException; import java.nio.charset.StandardCharsets; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlFunctionsTest.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlFunctionsTest.java index b50411668..dcebe11cc 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlFunctionsTest.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlFunctionsTest.java @@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import ai.langstream.ai.agents.commons.jstl.JstlFunctions; import java.math.BigDecimal; import java.math.BigInteger; import java.nio.charset.StandardCharsets; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlTransformContextAdapterTest.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlTransformContextAdapterTest.java index cf099b8a3..f58be475d 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlTransformContextAdapterTest.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlTransformContextAdapterTest.java @@ -20,7 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import com.datastax.oss.streaming.ai.TransformContext; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.jstl.JstlTransformContextAdapter; import com.datastax.oss.streaming.ai.Utils; import java.time.LocalDate; import java.util.HashMap; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlTypeConverterTest.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlTypeConverterTest.java index ab0bfa94e..1981ec9be 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlTypeConverterTest.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/JstlTypeConverterTest.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import ai.langstream.ai.agents.commons.jstl.JstlTypeConverter; import java.math.BigDecimal; import java.math.BigInteger; import java.nio.charset.StandardCharsets; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/predicate/JstlPredicateTest.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/predicate/JstlPredicateTest.java index b4d820101..cf97dc269 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/predicate/JstlPredicateTest.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/jstl/predicate/JstlPredicateTest.java @@ -19,7 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import com.datastax.oss.streaming.ai.TransformContext; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.jstl.predicate.JstlPredicate; import com.datastax.oss.streaming.ai.Utils; import java.util.HashMap; import org.apache.pulsar.client.api.Schema; diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/util/AvroUtilTest.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/util/AvroUtilTest.java index eed287e21..ab07796a6 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/util/AvroUtilTest.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/streaming/ai/util/AvroUtilTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import ai.langstream.ai.agents.commons.AvroUtil; import org.apache.avro.LogicalType; import org.apache.avro.Schema; import org.apache.avro.SchemaBuilder; diff --git a/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/QueryVectorDBAgent.java b/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/QueryVectorDBAgent.java index 2d6444ff0..b156af21f 100644 --- a/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/QueryVectorDBAgent.java +++ b/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/QueryVectorDBAgent.java @@ -16,13 +16,13 @@ package ai.langstream.agents.vector; import ai.langstream.ai.agents.GenAIToolKitAgent; +import ai.langstream.ai.agents.commons.TransformContext; import ai.langstream.ai.agents.datasource.DataSourceProviderRegistry; import ai.langstream.api.runner.code.Record; import ai.langstream.api.runner.code.SingleRecordAgentProcessor; import com.datastax.oss.streaming.ai.QueryStep; -import com.datastax.oss.streaming.ai.TransformContext; +import com.datastax.oss.streaming.ai.StepPredicatePair; import com.datastax.oss.streaming.ai.datasource.QueryStepDataSource; -import com.datastax.oss.streaming.ai.jstl.predicate.StepPredicatePair; import com.datastax.oss.streaming.ai.model.config.QueryConfig; import com.datastax.oss.streaming.ai.util.TransformFunctionUtil; import com.fasterxml.jackson.databind.DeserializationFeature; diff --git a/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/jdbc/JdbcWriter.java b/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/jdbc/JdbcWriter.java index 493c69cba..51813659e 100644 --- a/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/jdbc/JdbcWriter.java +++ b/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/jdbc/JdbcWriter.java @@ -16,13 +16,13 @@ package ai.langstream.agents.vector.jdbc; import ai.langstream.ai.agents.GenAIToolKitAgent; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.jstl.JstlEvaluator; import ai.langstream.ai.agents.datasource.impl.JdbcDataSourceProvider; import ai.langstream.api.database.VectorDatabaseWriter; import ai.langstream.api.database.VectorDatabaseWriterProvider; import ai.langstream.api.runner.code.Record; import ai.langstream.api.util.ConfigurationUtils; -import com.datastax.oss.streaming.ai.TransformContext; -import com.datastax.oss.streaming.ai.jstl.JstlEvaluator; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import java.sql.Connection; diff --git a/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/milvus/MilvusWriter.java b/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/milvus/MilvusWriter.java index 2a79f145a..9c64521f1 100644 --- a/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/milvus/MilvusWriter.java +++ b/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/milvus/MilvusWriter.java @@ -16,13 +16,13 @@ package ai.langstream.agents.vector.milvus; import ai.langstream.ai.agents.GenAIToolKitAgent; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.jstl.JstlEvaluator; import ai.langstream.api.database.VectorDatabaseWriter; import ai.langstream.api.database.VectorDatabaseWriterProvider; import ai.langstream.api.runner.code.Record; import ai.langstream.api.util.ConfigurationUtils; import com.alibaba.fastjson.JSONObject; -import com.datastax.oss.streaming.ai.TransformContext; -import com.datastax.oss.streaming.ai.jstl.JstlEvaluator; import io.milvus.client.MilvusServiceClient; import io.milvus.grpc.CollectionSchema; import io.milvus.grpc.DescribeCollectionResponse; diff --git a/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/pinecone/PineconeWriter.java b/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/pinecone/PineconeWriter.java index addb26480..8b07ac749 100644 --- a/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/pinecone/PineconeWriter.java +++ b/langstream-agents/langstream-vector-agents/src/main/java/ai/langstream/agents/vector/pinecone/PineconeWriter.java @@ -16,11 +16,11 @@ package ai.langstream.agents.vector.pinecone; import ai.langstream.ai.agents.GenAIToolKitAgent; +import ai.langstream.ai.agents.commons.TransformContext; +import ai.langstream.ai.agents.commons.jstl.JstlEvaluator; import ai.langstream.api.database.VectorDatabaseWriter; import ai.langstream.api.database.VectorDatabaseWriterProvider; import ai.langstream.api.runner.code.Record; -import com.datastax.oss.streaming.ai.TransformContext; -import com.datastax.oss.streaming.ai.jstl.JstlEvaluator; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.protobuf.Struct; diff --git a/langstream-agents/pom.xml b/langstream-agents/pom.xml index a35b0dfff..fbae82927 100644 --- a/langstream-agents/pom.xml +++ b/langstream-agents/pom.xml @@ -32,6 +32,7 @@ 17 + langstream-agents-commons langstream-agent-grpc langstream-agent-s3 langstream-agent-webcrawler