chore(memory): backport bundled Mem0 docs source and align plugin code style with repo conventions

This commit is contained in:
mateaix 2026-07-26 10:56:27 +08:00
parent 396cdb175b
commit f9fcf35dc7
5 changed files with 17 additions and 9 deletions

View File

@ -4,6 +4,8 @@ import org.slf4j.Logger;
import vip.mate.plugin.api.MateClawPlugin;
import vip.mate.plugin.api.PluginContext;
import java.net.URI;
/**
* MateClaw plugin entrypoint that registers {@link Mem0Provider} with the
* platform's memory subsystem.
@ -94,7 +96,7 @@ public class Mem0Plugin implements MateClawPlugin {
private static String maskUrl(String url) {
if (url == null || url.isBlank()) return "(unset)";
try {
java.net.URI u = java.net.URI.create(url);
URI u = URI.create(url);
String host = u.getHost();
int port = u.getPort();
return u.getScheme() + "://" + host + (port > 0 ? ":" + port : "");

View File

@ -30,7 +30,7 @@ import java.util.concurrent.Executors;
* When {@code ownerKey} is null/blank, both recall and sync are skipped Mem0
* requires {@code user_id}.
*
* <p>Asynchronous sync: a single-thread virtual-thread-per-task executor is used
* <p>Asynchronous sync: a single-thread daemon executor is used
* so that bursts of turns don't pile up on the platform's request thread.
*
* @author MateClaw Team

View File

@ -3,13 +3,18 @@ package vip.mate.plugin.mem0;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallback;
import vip.mate.plugin.api.PluginContext;
import vip.mate.plugin.api.PluginException;
import vip.mate.plugin.api.channel.PluginChannelAdapter;
import vip.mate.plugin.api.memory.PluginMemoryProvider;
import vip.mate.plugin.api.search.PluginSearchProvider;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@ -132,10 +137,10 @@ class Mem0PluginTest {
// The remaining methods are not used by Mem0Plugin; stub them out.
@Override public void registerTool(org.springframework.ai.tool.ToolCallback tool) { throw new UnsupportedOperationException(); }
@Override public void registerTool(org.springframework.ai.tool.ToolCallback tool, java.util.function.Supplier<Boolean> availabilityCheck) { throw new UnsupportedOperationException(); }
@Override public void registerProvider(String providerId, org.springframework.ai.chat.model.ChatModel chatModel) { throw new UnsupportedOperationException(); }
@Override public void registerChannel(vip.mate.plugin.api.channel.PluginChannelAdapter channel) { throw new UnsupportedOperationException(); }
@Override public void registerSearchProvider(vip.mate.plugin.api.search.PluginSearchProvider provider) { throw new UnsupportedOperationException(); }
@Override public void registerTool(ToolCallback tool) { throw new UnsupportedOperationException(); }
@Override public void registerTool(ToolCallback tool, Supplier<Boolean> availabilityCheck) { throw new UnsupportedOperationException(); }
@Override public void registerProvider(String providerId, ChatModel chatModel) { throw new UnsupportedOperationException(); }
@Override public void registerChannel(PluginChannelAdapter channel) { throw new UnsupportedOperationException(); }
@Override public void registerSearchProvider(PluginSearchProvider provider) { throw new UnsupportedOperationException(); }
}
}

View File

@ -140,7 +140,7 @@ class Mem0ProviderTest {
void syncTurn_pushesAsynchronouslyWithoutBlocking() throws Exception {
provider.syncTurn(1L, "conv-1", "hello", "world");
// Wait briefly for the virtual thread to fire the POST.
// Wait briefly for the async executor to fire the POST.
long deadline = System.currentTimeMillis() + 2000;
while (addCount.get() == 0 && System.currentTimeMillis() < deadline) {
Thread.sleep(20);

View File

@ -47,7 +47,8 @@ public class PluginMemoryBridge implements MemoryProvider {
@Override
public String prefetch(Long agentId, String userQuery, String ownerKey) {
// 透传 ownerKey 到插件 provider插件若未 override 三参版会走 default 退化到两参
// Forward ownerKey to the plugin provider; plugins that don't override the
// three-arg variant fall back to the two-arg default (ownerKey dropped).
return delegate.prefetch(agentId, userQuery, ownerKey);
}