Skip to content

Commit 88aff48

Browse files
committed
fix: support explicit active-memory chat types
Signed-off-by: Lidang-Jiang <[email protected]>
1 parent ddb7a8d commit 88aff48

4 files changed

Lines changed: 65 additions & 6 deletions

File tree

‎extensions/active-memory/config.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,32 @@ describe("active-memory manifest config schema", () => {
2121

2222
expect(result.ok).toBe(true);
2323
});
24+
25+
it("accepts explicit in allowedChatTypes", () => {
26+
const result = validateJsonSchemaValue({
27+
schema: manifest.configSchema,
28+
cacheKey: "active-memory.manifest.allowed-chat-types.explicit",
29+
value: {
30+
enabled: true,
31+
agents: ["main"],
32+
allowedChatTypes: ["direct", "explicit"],
33+
},
34+
});
35+
36+
expect(result.ok).toBe(true);
37+
});
38+
39+
it("rejects unknown allowedChatTypes values", () => {
40+
const result = validateJsonSchemaValue({
41+
schema: manifest.configSchema,
42+
cacheKey: "active-memory.manifest.allowed-chat-types.invalid",
43+
value: {
44+
enabled: true,
45+
agents: ["main"],
46+
allowedChatTypes: ["direct", "portal"],
47+
},
48+
});
49+
50+
expect(result.ok).toBe(false);
51+
});
2452
});

‎extensions/active-memory/index.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,31 @@ describe("active-memory plugin", () => {
443443
});
444444
});
445445

446+
it("runs for explicit sessions when explicit chat types are explicitly allowed", async () => {
447+
api.pluginConfig = {
448+
agents: ["main"],
449+
allowedChatTypes: ["explicit"],
450+
};
451+
await plugin.register(api as unknown as OpenClawPluginApi);
452+
453+
const result = await hooks.before_prompt_build(
454+
{ prompt: "what should i work on next?", messages: [] },
455+
{
456+
agentId: "main",
457+
trigger: "user",
458+
sessionKey: "agent:main:explicit:portal-123",
459+
messageProvider: "webchat",
460+
channelId: "webchat",
461+
},
462+
);
463+
464+
expect(runEmbeddedPiAgent).toHaveBeenCalledTimes(1);
465+
expect(result).toEqual({
466+
prependSystemContext: expect.stringContaining("plugin-provided supplemental context"),
467+
appendSystemContext: expect.stringContaining("<active_memory_plugin>"),
468+
});
469+
});
470+
446471
it("injects system context on a successful recall hit", async () => {
447472
const result = await hooks.before_prompt_build(
448473
{

‎extensions/active-memory/index.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type ActiveRecallPluginConfig = {
6060
model?: string;
6161
modelFallback?: string;
6262
modelFallbackPolicy?: "default-remote" | "resolved-only";
63-
allowedChatTypes?: Array<"direct" | "group" | "channel">;
63+
allowedChatTypes?: Array<"direct" | "group" | "channel" | "explicit">;
6464
thinking?: ActiveMemoryThinkingLevel;
6565
promptStyle?:
6666
| "balanced"
@@ -95,7 +95,7 @@ type ResolvedActiveRecallPluginConfig = {
9595
model?: string;
9696
modelFallback?: string;
9797
modelFallbackPolicy: "default-remote" | "resolved-only";
98-
allowedChatTypes: Array<"direct" | "group" | "channel">;
98+
allowedChatTypes: Array<"direct" | "group" | "channel" | "explicit">;
9999
thinking: ActiveMemoryThinkingLevel;
100100
promptStyle:
101101
| "balanced"
@@ -164,7 +164,7 @@ type CachedActiveRecallResult = {
164164
result: ActiveRecallResult;
165165
};
166166

167-
type ActiveMemoryChatType = "direct" | "group" | "channel";
167+
type ActiveMemoryChatType = "direct" | "group" | "channel" | "explicit";
168168

169169
type ActiveMemoryToggleStore = {
170170
sessions?: Record<string, { disabled?: boolean; updatedAt?: number }>;
@@ -610,7 +610,10 @@ function normalizePluginConfig(pluginConfig: unknown): ResolvedActiveRecallPlugi
610610
const allowedChatTypes = Array.isArray(raw.allowedChatTypes)
611611
? raw.allowedChatTypes.filter(
612612
(value): value is ActiveMemoryChatType =>
613-
value === "direct" || value === "group" || value === "channel",
613+
value === "direct" ||
614+
value === "group" ||
615+
value === "channel" ||
616+
value === "explicit",
614617
)
615618
: [];
616619
return {
@@ -882,6 +885,9 @@ function resolveChatType(ctx: {
882885
if (sessionKey.includes(":channel:")) {
883886
return "channel";
884887
}
888+
if (sessionKey.includes(":explicit:")) {
889+
return "explicit";
890+
}
885891
if (sessionKey.includes(":direct:") || sessionKey.includes(":dm:")) {
886892
return "direct";
887893
}

‎extensions/active-memory/openclaw.plugin.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"type": "array",
2222
"items": {
2323
"type": "string",
24-
"enum": ["direct", "group", "channel"]
24+
"enum": ["direct", "group", "channel", "explicit"]
2525
}
2626
},
2727
"thinking": {
@@ -90,7 +90,7 @@
9090
},
9191
"allowedChatTypes": {
9292
"label": "Allowed Chat Types",
93-
"help": "Choose which session types may run Active Memory. Defaults to direct-message style sessions only."
93+
"help": "Choose which session types may run Active Memory. Defaults to direct-message style sessions only, but explicit portal/webchat sessions can also be enabled."
9494
},
9595
"timeoutMs": {
9696
"label": "Timeout (ms)"

0 commit comments

Comments
 (0)