feat(cli): pass detected agent_caller to backend on Agent Mode bootstrap
The CLI's detect_agent_caller() already canonicalizes the caller (env-var sniff returning "claude-code", "cursor", etc.) and reports it to PostHog — but the value never reached the backend, so APIKey.agent_caller stayed NULL. Join: send it in the bootstrap request body so the platform can persist it (see mem0ai/platform#2784). Wire-up: - bootstrap_via_backend / bootstrapViaBackend gain an agent_caller kwarg, pass it as request body field "agent_caller" - init_cmd / init.ts call detect_agent_caller() once and forward - platform.agent_caller persisted to ~/.mem0/config.json so the local view matches what the backend stored No change to created_via — that stays the channel enum ("agent_mode" / "email" / "api_key"). agent_caller is the orthogonal "who started this".
This commit is contained in:
@@ -26,7 +26,10 @@ export interface BootstrapEnvelope {
|
||||
|
||||
export async function bootstrapViaBackend(
|
||||
config: Mem0Config,
|
||||
{ source }: { source?: string | null } = {},
|
||||
{
|
||||
source,
|
||||
agentCaller,
|
||||
}: { source?: string | null; agentCaller?: string | null } = {},
|
||||
): Promise<void> {
|
||||
const baseUrl = (config.platform.baseUrl || "https://api.mem0.ai").replace(
|
||||
/\/+$/,
|
||||
@@ -34,6 +37,7 @@ export async function bootstrapViaBackend(
|
||||
);
|
||||
const body: Record<string, unknown> = {};
|
||||
if (source) body.source = source;
|
||||
if (agentCaller) body.agent_caller = agentCaller;
|
||||
|
||||
let resp: Response;
|
||||
try {
|
||||
@@ -89,6 +93,7 @@ export async function bootstrapViaBackend(
|
||||
config.platform.baseUrl = baseUrl;
|
||||
config.platform.agentMode = true;
|
||||
config.platform.createdVia = "agent_mode";
|
||||
config.platform.agentCaller = agentCaller ?? "";
|
||||
config.platform.claimedAt = "";
|
||||
config.platform.defaultUserId = envelope.default_user_id;
|
||||
// Adopt the slug-derived user_id as the default scope for memory ops.
|
||||
|
||||
@@ -367,7 +367,10 @@ export async function runInit(
|
||||
return;
|
||||
}
|
||||
// Rule 3: mint a fresh shadow (no valid key to reuse).
|
||||
await bootstrapViaBackend(config, { source: opts.source ?? null });
|
||||
await bootstrapViaBackend(config, {
|
||||
source: opts.source ?? null,
|
||||
agentCaller: detectAgentCaller(),
|
||||
});
|
||||
fireInit("agent");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ export interface PlatformConfig {
|
||||
// Agent Mode (unclaimed-shadow signup)
|
||||
agentMode: boolean; // true while the key is an unclaimed agent-mode key
|
||||
createdVia: string; // "agent_mode" | "email" | "api_key" | "existing_key"
|
||||
agentCaller: string; // canonical agent name when createdVia === "agent_mode" (e.g. "claude-code")
|
||||
claimedAt: string; // ISO timestamp once the agent has been claimed
|
||||
defaultUserId: string; // `user_<slug>` returned by bootstrap; auto-default scope
|
||||
}
|
||||
@@ -61,6 +62,7 @@ export function createDefaultConfig(): Mem0Config {
|
||||
userEmail: "",
|
||||
agentMode: false,
|
||||
createdVia: "",
|
||||
agentCaller: "",
|
||||
claimedAt: "",
|
||||
defaultUserId: "",
|
||||
},
|
||||
@@ -90,6 +92,7 @@ export function loadConfig(): Mem0Config {
|
||||
config.platform.userEmail = plat.user_email ?? "";
|
||||
config.platform.agentMode = Boolean(plat.agent_mode ?? false);
|
||||
config.platform.createdVia = plat.created_via ?? "";
|
||||
config.platform.agentCaller = plat.agent_caller ?? "";
|
||||
config.platform.claimedAt = plat.claimed_at ?? "";
|
||||
config.platform.defaultUserId = plat.default_user_id ?? "";
|
||||
|
||||
@@ -133,6 +136,7 @@ export function saveConfig(config: Mem0Config): void {
|
||||
user_email: config.platform.userEmail,
|
||||
agent_mode: config.platform.agentMode,
|
||||
created_via: config.platform.createdVia,
|
||||
agent_caller: config.platform.agentCaller,
|
||||
claimed_at: config.platform.claimedAt,
|
||||
default_user_id: config.platform.defaultUserId,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user