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;
await patchSessionEntry({
sessionKey: input.openclawSessionKey,
fallbackEntry: {
sessionId: input.openclawSessionKey,
updatedAt: Date.now(),
},
preserveActivity: true,
update: (entry) => {
const existing = readMappingFromEntry(entry);

View File

@ -25,12 +25,17 @@ function createApiFixture(tasks: Record<string, unknown> = {}) {
})),
patchSessionEntry: async ({
sessionKey,
fallbackEntry,
update,
}: {
sessionKey: string;
fallbackEntry?: any;
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);
if (patch) {
sessions.set(sessionKey, { ...current, ...patch });

View File

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