Skip to content

Commit 615ff92

Browse files
Use SimplePlugin builder for VectorStore and EmbeddingModel plugins
Replace VectorStorePlugin and EmbeddingModelPlugin subclasses with SimplePlugin.newBuilder().registerActivitiesImplementations() in the auto-config classes. These plugins are trivial activity registrations that don't need custom subclasses when the builder already supports this. SpringAiPlugin stays as a subclass (has getter API for chat models). McpPlugin stays as a subclass (needs SmartInitializingSingleton for deferred registration). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 969aabd commit 615ff92

6 files changed

Lines changed: 31 additions & 86 deletions

File tree

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.temporal.springai.autoconfigure;
22

3-
import io.temporal.springai.plugin.EmbeddingModelPlugin;
3+
import io.temporal.common.SimplePlugin;
4+
import io.temporal.springai.activity.EmbeddingModelActivityImpl;
45
import org.springframework.ai.embedding.EmbeddingModel;
56
import org.springframework.boot.autoconfigure.AutoConfiguration;
67
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -10,7 +11,8 @@
1011
/**
1112
* Auto-configuration for EmbeddingModel integration with Temporal.
1213
*
13-
* <p>Conditionally creates an {@link EmbeddingModelPlugin} when {@code spring-ai-rag} is on the
14+
* <p>Conditionally creates a plugin that registers {@link
15+
* io.temporal.springai.activity.EmbeddingModelActivity} when {@code spring-ai-rag} is on the
1416
* classpath and an {@link EmbeddingModel} bean is available.
1517
*/
1618
@AutoConfiguration(after = SpringAiTemporalAutoConfiguration.class)
@@ -19,7 +21,9 @@
1921
public class SpringAiEmbeddingAutoConfiguration {
2022

2123
@Bean
22-
public EmbeddingModelPlugin embeddingModelPlugin(EmbeddingModel embeddingModel) {
23-
return new EmbeddingModelPlugin(embeddingModel);
24+
public SimplePlugin embeddingModelPlugin(EmbeddingModel embeddingModel) {
25+
return SimplePlugin.newBuilder("io.temporal.spring-ai-embedding")
26+
.registerActivitiesImplementations(new EmbeddingModelActivityImpl(embeddingModel))
27+
.build();
2428
}
2529
}
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.temporal.springai.autoconfigure;
22

3-
import io.temporal.springai.plugin.VectorStorePlugin;
3+
import io.temporal.common.SimplePlugin;
4+
import io.temporal.springai.activity.VectorStoreActivityImpl;
45
import org.springframework.ai.vectorstore.VectorStore;
56
import org.springframework.boot.autoconfigure.AutoConfiguration;
67
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -10,16 +11,19 @@
1011
/**
1112
* Auto-configuration for VectorStore integration with Temporal.
1213
*
13-
* <p>Conditionally creates a {@link VectorStorePlugin} when {@code spring-ai-rag} is on the
14-
* classpath and a {@link VectorStore} bean is available.
14+
* <p>Conditionally creates a plugin that registers {@link
15+
* io.temporal.springai.activity.VectorStoreActivity} when {@code spring-ai-rag} is on the classpath
16+
* and a {@link VectorStore} bean is available.
1517
*/
1618
@AutoConfiguration(after = SpringAiTemporalAutoConfiguration.class)
1719
@ConditionalOnClass(name = "org.springframework.ai.vectorstore.VectorStore")
1820
@ConditionalOnBean(VectorStore.class)
1921
public class SpringAiVectorStoreAutoConfiguration {
2022

2123
@Bean
22-
public VectorStorePlugin vectorStorePlugin(VectorStore vectorStore) {
23-
return new VectorStorePlugin(vectorStore);
24+
public SimplePlugin vectorStorePlugin(VectorStore vectorStore) {
25+
return SimplePlugin.newBuilder("io.temporal.spring-ai-vectorstore")
26+
.registerActivitiesImplementations(new VectorStoreActivityImpl(vectorStore))
27+
.build();
2428
}
2529
}

temporal-spring-ai/src/main/java/io/temporal/springai/plugin/EmbeddingModelPlugin.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

temporal-spring-ai/src/main/java/io/temporal/springai/plugin/SpringAiPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* auto-configuration:
2323
*
2424
* <ul>
25-
* <li>{@link VectorStorePlugin} - when {@code spring-ai-rag} is on the classpath
26-
* <li>{@link EmbeddingModelPlugin} - when {@code spring-ai-rag} is on the classpath
25+
* <li>VectorStore plugin - when {@code spring-ai-rag} is on the classpath
26+
* <li>EmbeddingModel plugin - when {@code spring-ai-rag} is on the classpath
2727
* <li>{@link McpPlugin} - when {@code spring-ai-mcp} is on the classpath
2828
* </ul>
2929
*

temporal-spring-ai/src/main/java/io/temporal/springai/plugin/VectorStorePlugin.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

temporal-spring-ai/src/test/java/io/temporal/springai/plugin/SpringAiPluginTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.*;
44
import static org.mockito.Mockito.*;
55

6+
import io.temporal.common.SimplePlugin;
67
import io.temporal.springai.activity.ChatModelActivityImpl;
78
import io.temporal.springai.activity.EmbeddingModelActivityImpl;
89
import io.temporal.springai.activity.VectorStoreActivityImpl;
@@ -109,28 +110,32 @@ void emptyChatModelsMap_throwsIllegalArgument() {
109110
IllegalArgumentException.class, () -> new SpringAiPlugin(new LinkedHashMap<>(), null));
110111
}
111112

112-
// --- VectorStorePlugin tests ---
113+
// --- Builder-based plugin tests ---
113114

114115
@Test
115-
void vectorStorePlugin_registersActivity() {
116+
void vectorStorePlugin_viaBuilder_registersActivity() {
116117
VectorStore vectorStore = mock(VectorStore.class);
117118
Worker worker = mock(Worker.class);
118119

119-
VectorStorePlugin plugin = new VectorStorePlugin(vectorStore);
120+
SimplePlugin plugin =
121+
SimplePlugin.newBuilder("io.temporal.spring-ai-vectorstore")
122+
.registerActivitiesImplementations(new VectorStoreActivityImpl(vectorStore))
123+
.build();
120124
plugin.initializeWorker("test-queue", worker);
121125

122126
Set<Class<?>> types = activityTypes(captureRegisteredActivities(worker));
123127
assertTrue(types.contains(VectorStoreActivityImpl.class));
124128
}
125129

126-
// --- EmbeddingModelPlugin tests ---
127-
128130
@Test
129-
void embeddingModelPlugin_registersActivity() {
131+
void embeddingModelPlugin_viaBuilder_registersActivity() {
130132
EmbeddingModel embeddingModel = mock(EmbeddingModel.class);
131133
Worker worker = mock(Worker.class);
132134

133-
EmbeddingModelPlugin plugin = new EmbeddingModelPlugin(embeddingModel);
135+
SimplePlugin plugin =
136+
SimplePlugin.newBuilder("io.temporal.spring-ai-embedding")
137+
.registerActivitiesImplementations(new EmbeddingModelActivityImpl(embeddingModel))
138+
.build();
134139
plugin.initializeWorker("test-queue", worker);
135140

136141
Set<Class<?>> types = activityTypes(captureRegisteredActivities(worker));

0 commit comments

Comments
 (0)