@tpsdev-ai/openclaw-flair 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.ts +15 -10
  2. package/key-resolver.ts +10 -24
  3. package/package.json +1 -1
package/index.ts CHANGED
@@ -124,8 +124,8 @@ export default {
124
124
  const fallbackAgentId = resolveAgentId();
125
125
 
126
126
  function getClient(agentId?: string): FlairClient {
127
- const id = agentId || cfg.agentId || fallbackAgentId;
128
- if (!id || id === "auto") throw new Error("no agentId available — set agentId in plugin config, FLAIR_AGENT_ID env var, or ensure OpenClaw provides it via session context");
127
+ const id = agentId || (cfg.agentId && cfg.agentId !== "auto" ? cfg.agentId : null) || currentAgentId || fallbackAgentId;
128
+ if (!id || id === "auto") throw new Error("no agentId available — set agentId in plugin config, FLAIR_AGENT_ID env var, or ensure OpenClaw provides it via session context (before_agent_start)");
129
129
  let client = clientPool.get(id);
130
130
  if (!client) {
131
131
  client = new FlairClient({
@@ -153,17 +153,22 @@ export default {
153
153
  const autoCapture = cfg.autoCapture ?? false; // opt-in — trust the LLM to use memory_store
154
154
  const autoRecall = cfg.autoRecall ?? true;
155
155
 
156
- // Per-session agentId — set from config, env, or session context.
157
- // IMPORTANT: Only update from before_agent_start if it matches our configured agent,
158
- // NOT from other agents' cron jobs sharing the same gateway.
159
- let currentAgentId: string | undefined = isAutoMode ? fallbackAgentId ?? undefined : cfg.agentId;
160
- const configuredAgentId = cfg.agentId && cfg.agentId !== "auto" ? cfg.agentId : fallbackAgentId;
156
+ // Per-session agentId — resolved from session context at runtime.
157
+ // In auto mode, each session gets its own agentId from before_agent_start.
158
+ // With explicit config, all sessions use the configured agentId.
159
+ let currentAgentId: string | undefined = isAutoMode ? (fallbackAgentId ?? undefined) : cfg.agentId;
160
+ const configuredAgentId = cfg.agentId && cfg.agentId !== "auto" ? cfg.agentId : null;
161
161
 
162
162
  api.on("before_agent_start", async (event: any, ctx: any) => {
163
163
  const eventAgentId = ctx?.agentId || (event as any).agentId;
164
- // Only adopt the session agentId if we don't already have one configured,
165
- // or if it matches our configured agent. Don't let kern's cron overwrite flint's agentId.
166
- if (eventAgentId && (!configuredAgentId || eventAgentId === configuredAgentId)) {
164
+ if (!eventAgentId) return;
165
+
166
+ if (isAutoMode) {
167
+ // Auto mode: always adopt the session's agentId — each session is its own agent
168
+ currentAgentId = eventAgentId;
169
+ api.logger.info(`openclaw-flair: session agentId="${eventAgentId}"`);
170
+ } else if (eventAgentId === configuredAgentId) {
171
+ // Explicit mode: only accept matching agentId
167
172
  currentAgentId = eventAgentId;
168
173
  }
169
174
 
package/key-resolver.ts CHANGED
@@ -2,36 +2,22 @@
2
2
  * OpenClaw-specific identity resolution.
3
3
  *
4
4
  * Key path and private key loading are now handled by @tpsdev-ai/flair-client.
5
- * This file only contains resolveAgentId() which reads OpenClaw config something
6
- * the generic flair-client shouldn't know about.
5
+ * This file only contains resolveAgentId() which reads environment variables
6
+ * something the generic flair-client shouldn't know about.
7
7
  */
8
8
 
9
- import { existsSync, readFileSync } from "node:fs";
10
- import { homedir } from "node:os";
11
- import { resolve } from "node:path";
12
-
13
9
  /**
14
- * Resolve agent ID when not explicitly configured.
15
- * Priority: FLAIR_AGENT_ID env > OpenClaw config file > null
10
+ * Resolve agent ID from environment when not explicitly configured.
11
+ *
12
+ * IMPORTANT: Does NOT read from openclaw.json agents list. On a multi-agent
13
+ * gateway, the first agent in the list is NOT necessarily the current session's
14
+ * agent. The plugin must get the real agentId from the session context via
15
+ * before_agent_start, not from config guessing.
16
+ *
17
+ * Priority: FLAIR_AGENT_ID env > null (let session context provide it)
16
18
  */
17
19
  export function resolveAgentId(): string | null {
18
- // 1. Explicit env var
19
20
  const envId = process.env.FLAIR_AGENT_ID;
20
21
  if (envId) return envId;
21
-
22
- // 2. Read from OpenClaw config — first agent name
23
- try {
24
- const configPath = resolve(homedir(), ".openclaw", "openclaw.json");
25
- if (!existsSync(configPath)) return null;
26
- const config = JSON.parse(readFileSync(configPath, "utf-8"));
27
- const agents = config?.agents?.list;
28
- if (Array.isArray(agents) && agents.length > 0) {
29
- const name = agents[0]?.name;
30
- if (typeof name === "string" && name) return name.toLowerCase();
31
- }
32
- } catch {
33
- // Config unreadable — fall through
34
- }
35
-
36
22
  return null;
37
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpsdev-ai/openclaw-flair",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "OpenClaw memory plugin for Flair \u2014 agent identity and semantic memory",
5
5
  "type": "module",
6
6
  "main": "index.ts",