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