|
7 | 7 | import type { OpenClawConfig } from "openclaw/plugin-sdk/core"; |
8 | 8 | import { parseStrictInteger } from "openclaw/plugin-sdk/number-runtime"; |
9 | 9 | import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared"; |
10 | | -import { parseThreadSessionSuffix } from "openclaw/plugin-sdk/routing"; |
11 | 10 | import { getSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime"; |
12 | 11 | import { |
13 | 12 | normalizeOptionalString, |
@@ -40,8 +39,6 @@ type MattermostModelPickerRenderedView = { |
40 | 39 | buttons: MattermostInteractiveButtonInput[][]; |
41 | 40 | }; |
42 | 41 |
|
43 | | -type MattermostModelPickerSessionEntry = ReturnType<typeof getSessionEntry>; |
44 | | - |
45 | 42 | function splitModelRef(modelRef?: string | null): { provider: string; model: string } | null { |
46 | 43 | const trimmed = normalizeOptionalString(modelRef); |
47 | 44 | const match = trimmed?.match(/^([^/]+)\/(.+)$/u); |
@@ -80,24 +77,6 @@ function normalizePage(value: number | undefined): number { |
80 | 77 | return Math.max(1, Math.floor(value as number)); |
81 | 78 | } |
82 | 79 |
|
83 | | -function resolveMattermostModelPickerParentSessionKey(params: { |
84 | | - sessionEntry: MattermostModelPickerSessionEntry; |
85 | | - sessionKey: string; |
86 | | -}): string | undefined { |
87 | | - // Preserve inherited model overrides without exposing whole-store reads to the UI path. |
88 | | - const persistedParent = |
89 | | - typeof params.sessionEntry?.parentSessionKey === "string" |
90 | | - ? params.sessionEntry.parentSessionKey.trim() |
91 | | - : ""; |
92 | | - if (persistedParent && persistedParent !== params.sessionKey) { |
93 | | - return persistedParent; |
94 | | - } |
95 | | - const parsed = parseThreadSessionSuffix(params.sessionKey); |
96 | | - return parsed.threadId && parsed.baseSessionKey && parsed.baseSessionKey !== params.sessionKey |
97 | | - ? parsed.baseSessionKey |
98 | | - : undefined; |
99 | | -} |
100 | | - |
101 | 80 | function paginateItems<T>(items: T[], page?: number, pageSize = MODELS_PAGE_SIZE) { |
102 | 81 | const totalPages = Math.max(1, Math.ceil(items.length / pageSize)); |
103 | 82 | const safePage = Math.max(1, Math.min(normalizePage(page), totalPages)); |
@@ -258,38 +237,28 @@ export function resolveMattermostModelPickerCurrentModel(params: { |
258 | 237 | cfg: OpenClawConfig; |
259 | 238 | route: { agentId: string; sessionKey: string }; |
260 | 239 | data: ModelsProviderData; |
261 | | - skipCache?: boolean; |
| 240 | + readConsistency?: "latest"; |
262 | 241 | }): string { |
263 | 242 | const fallback = `${params.data.resolvedDefault.provider}/${params.data.resolvedDefault.model}`; |
264 | 243 | try { |
265 | 244 | const storePath = resolveStorePath(params.cfg.session?.store, { |
266 | 245 | agentId: params.route.agentId, |
267 | 246 | }); |
268 | | - const readOptions = { |
269 | | - storePath, |
270 | | - ...(params.skipCache ? { readConsistency: "latest" as const } : {}), |
271 | | - }; |
272 | 247 | const sessionEntry = getSessionEntry({ |
273 | | - ...readOptions, |
274 | | - sessionKey: params.route.sessionKey, |
275 | | - }); |
276 | | - const parentSessionKey = resolveMattermostModelPickerParentSessionKey({ |
277 | | - sessionEntry, |
| 248 | + storePath, |
278 | 249 | sessionKey: params.route.sessionKey, |
| 250 | + ...(params.readConsistency === "latest" ? { readConsistency: "latest" as const } : {}), |
279 | 251 | }); |
280 | | - const parentEntry = parentSessionKey |
281 | | - ? getSessionEntry({ |
282 | | - ...readOptions, |
283 | | - sessionKey: parentSessionKey, |
284 | | - }) |
285 | | - : undefined; |
286 | 252 | const override = resolveStoredModelOverride({ |
287 | 253 | sessionEntry, |
288 | | - ...(parentEntry && parentSessionKey |
289 | | - ? { sessionStore: { [parentSessionKey]: parentEntry } } |
290 | | - : {}), |
| 254 | + loadSessionEntry: (sessionKey) => |
| 255 | + getSessionEntry({ |
| 256 | + storePath, |
| 257 | + sessionKey, |
| 258 | + ...(params.readConsistency === "latest" ? { readConsistency: "latest" as const } : {}), |
| 259 | + }), |
291 | 260 | sessionKey: params.route.sessionKey, |
292 | | - parentSessionKey, |
| 261 | + parentSessionKey: sessionEntry?.parentSessionKey, |
293 | 262 | defaultProvider: params.data.resolvedDefault.provider, |
294 | 263 | }); |
295 | 264 | if (!override?.model) { |
|
0 commit comments