From d1404014d97fdaec9f023f7480afcbeba04bf374 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 22 Mar 2026 18:28:55 -0700 Subject: [PATCH] perf(reply): split runner auth profile seam --- .../reply/agent-runner-auth-profile.ts | 24 ++++++++++++++++ src/auto-reply/reply/agent-runner-utils.ts | 28 ++++--------------- src/auto-reply/reply/followup-runner.ts | 2 +- 3 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 src/auto-reply/reply/agent-runner-auth-profile.ts diff --git a/src/auto-reply/reply/agent-runner-auth-profile.ts b/src/auto-reply/reply/agent-runner-auth-profile.ts new file mode 100644 index 00000000000..87bb9cc2c9c --- /dev/null +++ b/src/auto-reply/reply/agent-runner-auth-profile.ts @@ -0,0 +1,24 @@ +import type { FollowupRun } from "./queue.js"; + +export function resolveProviderScopedAuthProfile(params: { + provider: string; + primaryProvider: string; + authProfileId?: string; + authProfileIdSource?: "auto" | "user"; +}): { authProfileId?: string; authProfileIdSource?: "auto" | "user" } { + const authProfileId = + params.provider === params.primaryProvider ? params.authProfileId : undefined; + return { + authProfileId, + authProfileIdSource: authProfileId ? params.authProfileIdSource : undefined, + }; +} + +export function resolveRunAuthProfile(run: FollowupRun["run"], provider: string) { + return resolveProviderScopedAuthProfile({ + provider, + primaryProvider: run.provider, + authProfileId: run.authProfileId, + authProfileIdSource: run.authProfileIdSource, + }); +} diff --git a/src/auto-reply/reply/agent-runner-utils.ts b/src/auto-reply/reply/agent-runner-utils.ts index abf6322a287..91583a49124 100644 --- a/src/auto-reply/reply/agent-runner-utils.ts +++ b/src/auto-reply/reply/agent-runner-utils.ts @@ -8,6 +8,11 @@ import { isReasoningTagProvider } from "../../utils/provider-utils.js"; import { estimateUsageCost, formatTokenCount, formatUsd } from "../../utils/usage-format.js"; import type { TemplateContext } from "../templating.js"; import type { ReplyPayload } from "../types.js"; +import { + resolveProviderScopedAuthProfile, + resolveRunAuthProfile, +} from "./agent-runner-auth-profile.js"; +export { resolveProviderScopedAuthProfile, resolveRunAuthProfile }; import { resolveOriginMessageProvider, resolveOriginMessageTo } from "./origin-routing.js"; import type { FollowupRun } from "./queue.js"; @@ -237,15 +242,6 @@ export function buildTemplateSenderContext(sessionCtx: TemplateContext) { }; } -export function resolveRunAuthProfile(run: FollowupRun["run"], provider: string) { - return resolveProviderScopedAuthProfile({ - provider, - primaryProvider: run.provider, - authProfileId: run.authProfileId, - authProfileIdSource: run.authProfileIdSource, - }); -} - export function buildEmbeddedRunContexts(params: { run: FollowupRun["run"]; sessionCtx: TemplateContext; @@ -287,17 +283,3 @@ export function buildEmbeddedRunExecutionParams(params: { runBaseParams, }; } - -export function resolveProviderScopedAuthProfile(params: { - provider: string; - primaryProvider: string; - authProfileId?: string; - authProfileIdSource?: "auto" | "user"; -}): { authProfileId?: string; authProfileIdSource?: "auto" | "user" } { - const authProfileId = - params.provider === params.primaryProvider ? params.authProfileId : undefined; - return { - authProfileId, - authProfileIdSource: authProfileId ? params.authProfileIdSource : undefined, - }; -} diff --git a/src/auto-reply/reply/followup-runner.ts b/src/auto-reply/reply/followup-runner.ts index a8e9072ff92..d7d0cb22345 100644 --- a/src/auto-reply/reply/followup-runner.ts +++ b/src/auto-reply/reply/followup-runner.ts @@ -19,7 +19,7 @@ import { stripHeartbeatToken } from "../heartbeat.js"; import type { OriginatingChannelType } from "../templating.js"; import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../tokens.js"; import type { GetReplyOptions, ReplyPayload } from "../types.js"; -import { resolveRunAuthProfile } from "./agent-runner-utils.js"; +import { resolveRunAuthProfile } from "./agent-runner-auth-profile.js"; import { resolveOriginAccountId, resolveOriginMessageProvider,