mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:31:22 +00:00
refactor(auto-reply): reuse embedded run context helpers
This commit is contained in:
@@ -134,3 +134,57 @@ export const appendUsageLine = (payloads: ReplyPayload[], line: string): ReplyPa
|
||||
|
||||
export const resolveEnforceFinalTag = (run: FollowupRun["run"], provider: string) =>
|
||||
Boolean(run.enforceFinalTag || isReasoningTagProvider(provider));
|
||||
|
||||
export function buildEmbeddedContextFromTemplate(params: {
|
||||
run: FollowupRun["run"];
|
||||
sessionCtx: TemplateContext;
|
||||
hasRepliedRef: { value: boolean } | undefined;
|
||||
}) {
|
||||
return {
|
||||
sessionId: params.run.sessionId,
|
||||
sessionKey: params.run.sessionKey,
|
||||
agentId: params.run.agentId,
|
||||
messageProvider: params.sessionCtx.Provider?.trim().toLowerCase() || undefined,
|
||||
agentAccountId: params.sessionCtx.AccountId,
|
||||
messageTo: params.sessionCtx.OriginatingTo ?? params.sessionCtx.To,
|
||||
messageThreadId: params.sessionCtx.MessageThreadId ?? undefined,
|
||||
// Provider threading context for tool auto-injection
|
||||
...buildThreadingToolContext({
|
||||
sessionCtx: params.sessionCtx,
|
||||
config: params.run.config,
|
||||
hasRepliedRef: params.hasRepliedRef,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildTemplateSenderContext(sessionCtx: TemplateContext) {
|
||||
return {
|
||||
senderId: sessionCtx.SenderId?.trim() || undefined,
|
||||
senderName: sessionCtx.SenderName?.trim() || undefined,
|
||||
senderUsername: sessionCtx.SenderUsername?.trim() || undefined,
|
||||
senderE164: sessionCtx.SenderE164?.trim() || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveRunAuthProfile(run: FollowupRun["run"], provider: string) {
|
||||
return resolveProviderScopedAuthProfile({
|
||||
provider,
|
||||
primaryProvider: run.provider,
|
||||
authProfileId: run.authProfileId,
|
||||
authProfileIdSource: run.authProfileIdSource,
|
||||
});
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user