Create session mapping entries during prepare

This commit is contained in:
Haitao Pan 2026-06-06 10:26:55 +08:00
parent 529965aa3b
commit 4cf4ae49af
3 changed files with 15 additions and 1 deletions

View File

@ -77,6 +77,10 @@ export async function upsertXWorkmateSessionMapping(api, input) {
let mapping; let mapping;
await patchSessionEntry({ await patchSessionEntry({
sessionKey: input.openclawSessionKey, sessionKey: input.openclawSessionKey,
fallbackEntry: {
sessionId: input.openclawSessionKey,
updatedAt: Date.now(),
},
preserveActivity: true, preserveActivity: true,
update: (entry) => { update: (entry) => {
const existing = readMappingFromEntry(entry); const existing = readMappingFromEntry(entry);

View File

@ -25,12 +25,17 @@ function createApiFixture(tasks: Record<string, unknown> = {}) {
})), })),
patchSessionEntry: async ({ patchSessionEntry: async ({
sessionKey, sessionKey,
fallbackEntry,
update, update,
}: { }: {
sessionKey: string; sessionKey: string;
fallbackEntry?: any;
update: (entry: any) => Partial<any> | null; update: (entry: any) => Partial<any> | null;
}) => { }) => {
const current = sessions.get(sessionKey) ?? { sessionId: sessionKey, updatedAt: 0 }; const current = sessions.get(sessionKey) ?? fallbackEntry;
if (!current) {
return null;
}
const patch = update(current); const patch = update(current);
if (patch) { if (patch) {
sessions.set(sessionKey, { ...current, ...patch }); sessions.set(sessionKey, { ...current, ...patch });

View File

@ -49,6 +49,7 @@ type SessionEntry = Record<string, unknown> & {
type PatchSessionEntry = (params: { type PatchSessionEntry = (params: {
sessionKey: string; sessionKey: string;
fallbackEntry?: SessionEntry;
preserveActivity?: boolean; preserveActivity?: boolean;
update: (entry: SessionEntry) => Partial<SessionEntry> | null; update: (entry: SessionEntry) => Partial<SessionEntry> | null;
}) => Promise<SessionEntry | null> | SessionEntry | null; }) => Promise<SessionEntry | null> | SessionEntry | null;
@ -159,6 +160,10 @@ export async function upsertXWorkmateSessionMapping(
let mapping: XWorkmateSessionMappingV1 | undefined; let mapping: XWorkmateSessionMappingV1 | undefined;
await patchSessionEntry({ await patchSessionEntry({
sessionKey: input.openclawSessionKey, sessionKey: input.openclawSessionKey,
fallbackEntry: {
sessionId: input.openclawSessionKey,
updatedAt: Date.now(),
},
preserveActivity: true, preserveActivity: true,
update: (entry) => { update: (entry) => {
const existing = readMappingFromEntry(entry); const existing = readMappingFromEntry(entry);