From f712bbcb3ffe1cc7126fc06b3bbd3e2baf74402a Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 29 May 2026 14:07:59 +0200 Subject: [PATCH] refactor: share host hook projection collection --- src/plugins/host-hook-state.ts | 50 ++++++---------------------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/src/plugins/host-hook-state.ts b/src/plugins/host-hook-state.ts index c3ff95e8ba8..79cfbe0ea5f 100644 --- a/src/plugins/host-hook-state.ts +++ b/src/plugins/host-hook-state.ts @@ -583,6 +583,13 @@ export async function projectPluginSessionExtensions(params: { sessionKey: string; entry: SessionEntry; }): Promise { + return collectPluginSessionExtensionProjections(params); +} + +function collectPluginSessionExtensionProjections(params: { + sessionKey: string; + entry: SessionEntry; +}): PluginSessionExtensionProjection[] { const registry = getActivePluginRegistry(); const extensions = registry?.sessionExtensions ?? []; if (extensions.length === 0) { @@ -666,46 +673,5 @@ export function projectPluginSessionExtensionsSync(params: { sessionKey: string; entry: SessionEntry; }): PluginSessionExtensionProjection[] { - const registry = getActivePluginRegistry(); - const extensions = registry?.sessionExtensions ?? []; - if (extensions.length === 0) { - return []; - } - const projections: PluginSessionExtensionProjection[] = []; - for (const registration of extensions) { - const state = params.entry.pluginExtensions?.[registration.pluginId]?.[ - registration.extension.namespace - ] as PluginJsonValue | undefined; - if (state === undefined) { - continue; - } - const projected = projectSessionExtensionValue({ - pluginId: registration.pluginId, - namespace: registration.extension.namespace, - project: registration.extension.project, - sessionKey: params.sessionKey, - sessionId: params.entry.sessionId, - state, - }); - if (projected === PROJECTION_FAILED) { - continue; - } - if (isPromiseLike(projected)) { - discardUnexpectedPromiseProjection(projected); - continue; - } - if (projected === undefined || !isPluginJsonValue(projected)) { - // Validate the projection regardless of whether the extension has a - // `project` function: with a projector the value can be arbitrary; - // without one the persisted state could be hand-edited or malformed. - // Either way the size + shape check should run before projection. - continue; - } - projections.push({ - pluginId: registration.pluginId, - namespace: registration.extension.namespace, - value: copyJsonValue(projected), - }); - } - return projections; + return collectPluginSessionExtensionProjections(params); }