mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
Merge pull request #2143 from shoaib050326/codex/issue-2131-openclaw-session-key
fix(openclaw-gateway): prefix session keys with configured agent id
This commit is contained in:
commit
391afa627f
2 changed files with 67 additions and 4 deletions
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { resolveSessionKey } from "./execute.js";
|
||||||
|
|
||||||
|
describe("resolveSessionKey", () => {
|
||||||
|
it("prefixes run-scoped session keys with the configured agent", () => {
|
||||||
|
expect(
|
||||||
|
resolveSessionKey({
|
||||||
|
strategy: "run",
|
||||||
|
configuredSessionKey: null,
|
||||||
|
agentId: "meridian",
|
||||||
|
runId: "run-123",
|
||||||
|
issueId: null,
|
||||||
|
}),
|
||||||
|
).toBe("agent:meridian:paperclip:run:run-123");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefixes issue-scoped session keys with the configured agent", () => {
|
||||||
|
expect(
|
||||||
|
resolveSessionKey({
|
||||||
|
strategy: "issue",
|
||||||
|
configuredSessionKey: null,
|
||||||
|
agentId: "meridian",
|
||||||
|
runId: "run-123",
|
||||||
|
issueId: "issue-456",
|
||||||
|
}),
|
||||||
|
).toBe("agent:meridian:paperclip:issue:issue-456");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefixes fixed session keys with the configured agent", () => {
|
||||||
|
expect(
|
||||||
|
resolveSessionKey({
|
||||||
|
strategy: "fixed",
|
||||||
|
configuredSessionKey: "paperclip",
|
||||||
|
agentId: "meridian",
|
||||||
|
runId: "run-123",
|
||||||
|
issueId: null,
|
||||||
|
}),
|
||||||
|
).toBe("agent:meridian:paperclip");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not double-prefix an already-routed session key", () => {
|
||||||
|
expect(
|
||||||
|
resolveSessionKey({
|
||||||
|
strategy: "fixed",
|
||||||
|
configuredSessionKey: "agent:meridian:paperclip",
|
||||||
|
agentId: "meridian",
|
||||||
|
runId: "run-123",
|
||||||
|
issueId: null,
|
||||||
|
}),
|
||||||
|
).toBe("agent:meridian:paperclip");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -133,16 +133,26 @@ function normalizeSessionKeyStrategy(value: unknown): SessionKeyStrategy {
|
||||||
return "issue";
|
return "issue";
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveSessionKey(input: {
|
function prefixSessionKeyForAgent(sessionKey: string, agentId: string | null): string {
|
||||||
|
if (!agentId || sessionKey.startsWith("agent:")) return sessionKey;
|
||||||
|
return `agent:${agentId}:${sessionKey}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveSessionKey(input: {
|
||||||
strategy: SessionKeyStrategy;
|
strategy: SessionKeyStrategy;
|
||||||
configuredSessionKey: string | null;
|
configuredSessionKey: string | null;
|
||||||
|
agentId: string | null;
|
||||||
runId: string;
|
runId: string;
|
||||||
issueId: string | null;
|
issueId: string | null;
|
||||||
}): string {
|
}): string {
|
||||||
const fallback = input.configuredSessionKey ?? "paperclip";
|
const fallback = input.configuredSessionKey ?? "paperclip";
|
||||||
if (input.strategy === "run") return `paperclip:run:${input.runId}`;
|
if (input.strategy === "run") {
|
||||||
if (input.strategy === "issue" && input.issueId) return `paperclip:issue:${input.issueId}`;
|
return prefixSessionKeyForAgent(`paperclip:run:${input.runId}`, input.agentId);
|
||||||
return fallback;
|
}
|
||||||
|
if (input.strategy === "issue" && input.issueId) {
|
||||||
|
return prefixSessionKeyForAgent(`paperclip:issue:${input.issueId}`, input.agentId);
|
||||||
|
}
|
||||||
|
return prefixSessionKeyForAgent(fallback, input.agentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLoopbackHost(hostname: string): boolean {
|
function isLoopbackHost(hostname: string): boolean {
|
||||||
|
|
@ -1106,6 +1116,7 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
||||||
const sessionKey = resolveSessionKey({
|
const sessionKey = resolveSessionKey({
|
||||||
strategy: sessionKeyStrategy,
|
strategy: sessionKeyStrategy,
|
||||||
configuredSessionKey,
|
configuredSessionKey,
|
||||||
|
agentId: nonEmpty(ctx.config.agentId),
|
||||||
runId: ctx.runId,
|
runId: ctx.runId,
|
||||||
issueId: wakePayload.issueId,
|
issueId: wakePayload.issueId,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue