Create session mapping entries during prepare
This commit is contained in:
parent
529965aa3b
commit
4cf4ae49af
4
dist/src/taskState.js
vendored
4
dist/src/taskState.js
vendored
@ -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);
|
||||||
|
|||||||
@ -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 });
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user