Skip to content

Commit 51d8d95

Browse files
committed
clawdbot-55f: route sdk session patch through seam
1 parent 7fe43fe commit 51d8d95

5 files changed

Lines changed: 97 additions & 4 deletions

File tree

src/plugin-sdk/config-runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { loadSessionStore as loadSessionStoreImpl } from "../config/sessions/sto
88
export {
99
getSessionEntry,
1010
listSessionEntries,
11+
patchSessionEntry,
1112
updateSessionStoreEntry,
1213
upsertSessionEntry,
1314
} from "./session-store-runtime.js";
@@ -147,7 +148,6 @@ export type {
147148
} from "../config/types.js";
148149
export {
149150
clearSessionStoreCacheForTest,
150-
patchSessionEntry,
151151
readSessionUpdatedAt,
152152
recordSessionMetaFromInbound,
153153
saveSessionStore,

src/plugin-sdk/session-store-runtime.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
55
import {
66
getSessionEntry,
77
listSessionEntries,
8+
patchSessionEntry,
89
updateSessionStoreEntry,
910
upsertSessionEntry,
1011
} from "./session-store-runtime.js";
@@ -80,6 +81,19 @@ describe("session-store-runtime compatibility surface", () => {
8081
updatedAt: 10,
8182
},
8283
});
84+
const beforePatch = getSessionEntry({ sessionKey, storePath });
85+
await expect(
86+
patchSessionEntry({
87+
sessionKey,
88+
storePath,
89+
preserveActivity: true,
90+
update: () => ({ providerOverride: "openai", updatedAt: 20 }),
91+
}),
92+
).resolves.toMatchObject({
93+
providerOverride: "openai",
94+
sessionId: "session-1",
95+
updatedAt: beforePatch?.updatedAt,
96+
});
8397
await expect(
8498
updateSessionStoreEntry({
8599
sessionKey,

src/plugin-sdk/session-store-runtime.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import {
44
listSessionEntries as listAccessorSessionEntries,
55
loadSessionEntry,
6+
patchSessionEntry as patchAccessorSessionEntry,
67
replaceSessionEntry,
78
updateSessionEntry,
89
} from "../config/sessions/session-accessor.js";
@@ -28,6 +29,18 @@ type SessionStoreEntryUpdate = (
2829
entry: SessionEntry,
2930
) => Promise<Partial<SessionEntry> | null> | Partial<SessionEntry> | null;
3031

32+
type SessionStoreEntryPatch = (
33+
entry: SessionEntry,
34+
context: { existingEntry?: SessionEntry },
35+
) => Promise<Partial<SessionEntry> | null> | Partial<SessionEntry> | null;
36+
37+
type PatchSessionEntryParams = SessionStoreReadParams & {
38+
fallbackEntry?: SessionEntry;
39+
preserveActivity?: boolean;
40+
replaceEntry?: boolean;
41+
update: SessionStoreEntryPatch;
42+
};
43+
3144
type UpdateSessionStoreEntryParams = {
3245
storePath: string;
3346
sessionKey: string;
@@ -70,6 +83,27 @@ export function listSessionEntries(
7083
});
7184
}
7285

86+
/** Patches one session entry through the accessor seam. */
87+
export async function patchSessionEntry(
88+
params: PatchSessionEntryParams,
89+
): Promise<SessionEntry | null> {
90+
return await patchAccessorSessionEntry(
91+
{
92+
agentId: params.agentId,
93+
env: params.env,
94+
hydrateSkillPromptRefs: params.hydrateSkillPromptRefs,
95+
sessionKey: params.sessionKey,
96+
storePath: params.storePath,
97+
},
98+
params.update,
99+
{
100+
fallbackEntry: params.fallbackEntry,
101+
preserveActivity: params.preserveActivity,
102+
replaceEntry: params.replaceEntry,
103+
},
104+
);
105+
}
106+
73107
/** Updates an existing session entry through the accessor seam. */
74108
export async function updateSessionStoreEntry(
75109
params: UpdateSessionStoreEntryParams,
@@ -114,7 +148,6 @@ export { resolveGroupSessionKey } from "../config/sessions/group.js";
114148
export { canonicalizeMainSessionAlias } from "../config/sessions/main-session.js";
115149
export {
116150
clearSessionStoreCacheForTest,
117-
patchSessionEntry,
118151
readSessionUpdatedAt,
119152
recordSessionMetaFromInbound,
120153
saveSessionStore,

src/plugins/runtime/runtime-agent.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import { resolveSessionFilePath, resolveStorePath } from "../../config/sessions/
1414
import {
1515
listSessionEntries as listAccessorSessionEntries,
1616
loadSessionEntry,
17+
patchSessionEntry as patchAccessorSessionEntry,
1718
replaceSessionEntry,
1819
updateSessionEntry,
1920
} from "../../config/sessions/session-accessor.js";
2021
import {
2122
loadSessionStore,
22-
patchSessionEntry,
2323
saveSessionStore,
2424
updateSessionStore,
2525
} from "../../config/sessions/store.js";
@@ -53,6 +53,16 @@ type RuntimeSessionStoreEntryUpdateParams = {
5353
takeCacheOwnership?: boolean;
5454
};
5555

56+
type RuntimeSessionStoreEntryPatchParams = RuntimeSessionStoreReadParams & {
57+
fallbackEntry?: SessionEntry;
58+
preserveActivity?: boolean;
59+
replaceEntry?: boolean;
60+
update: (
61+
entry: SessionEntry,
62+
context: { existingEntry?: SessionEntry },
63+
) => Promise<Partial<SessionEntry> | null> | Partial<SessionEntry> | null;
64+
};
65+
5666
type RuntimeUpsertSessionEntryParams = RuntimeSessionStoreReadParams & {
5767
entry: SessionEntry;
5868
};
@@ -92,6 +102,26 @@ function listSessionEntries(
92102
});
93103
}
94104

105+
async function patchSessionEntry(
106+
params: RuntimeSessionStoreEntryPatchParams,
107+
): Promise<SessionEntry | null> {
108+
return await patchAccessorSessionEntry(
109+
{
110+
agentId: params.agentId,
111+
env: params.env,
112+
hydrateSkillPromptRefs: params.hydrateSkillPromptRefs,
113+
sessionKey: params.sessionKey,
114+
storePath: params.storePath,
115+
},
116+
params.update,
117+
{
118+
fallbackEntry: params.fallbackEntry,
119+
preserveActivity: params.preserveActivity,
120+
replaceEntry: params.replaceEntry,
121+
},
122+
);
123+
}
124+
95125
async function updateSessionStoreEntry(
96126
params: RuntimeSessionStoreEntryUpdateParams,
97127
): Promise<SessionEntry | null> {

src/plugins/runtime/types-core.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,23 @@ export type PluginRuntimeCore = {
223223
sessionKey: string;
224224
entry: import("../../config/sessions/types.js").SessionEntry;
225225
}>;
226-
patchSessionEntry: typeof import("../../config/sessions/store.js").patchSessionEntry;
226+
patchSessionEntry: (params: {
227+
agentId?: string;
228+
env?: NodeJS.ProcessEnv;
229+
fallbackEntry?: import("../../config/sessions/types.js").SessionEntry;
230+
hydrateSkillPromptRefs?: boolean;
231+
preserveActivity?: boolean;
232+
replaceEntry?: boolean;
233+
sessionKey: string;
234+
storePath?: string;
235+
update: (
236+
entry: import("../../config/sessions/types.js").SessionEntry,
237+
context: { existingEntry?: import("../../config/sessions/types.js").SessionEntry },
238+
) =>
239+
| Promise<Partial<import("../../config/sessions/types.js").SessionEntry> | null>
240+
| Partial<import("../../config/sessions/types.js").SessionEntry>
241+
| null;
242+
}) => Promise<import("../../config/sessions/types.js").SessionEntry | null>;
227243
upsertSessionEntry: (params: {
228244
agentId?: string;
229245
env?: NodeJS.ProcessEnv;

0 commit comments

Comments
 (0)