refactor: centralize inbound session updates
This commit is contained in:
@@ -11,7 +11,6 @@ import { dispatchInboundMessage } from "../../../auto-reply/dispatch.js";
|
||||
import { clearHistoryEntriesIfEnabled } from "../../../auto-reply/reply/history.js";
|
||||
import { removeAckReactionAfterReply } from "../../../channels/ack-reactions.js";
|
||||
import { createReplyDispatcherWithTyping } from "../../../auto-reply/reply/reply-dispatcher.js";
|
||||
import { resolveStorePath, updateLastRoute } from "../../../config/sessions.js";
|
||||
import { danger, logVerbose, shouldLogVerbose } from "../../../globals.js";
|
||||
import { removeSlackReaction } from "../../actions.js";
|
||||
import { resolveSlackThreadTargets } from "../../threading.js";
|
||||
@@ -25,23 +24,6 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
|
||||
const cfg = ctx.cfg;
|
||||
const runtime = ctx.runtime;
|
||||
|
||||
if (prepared.isDirectMessage) {
|
||||
const sessionCfg = cfg.session;
|
||||
const storePath = resolveStorePath(sessionCfg?.store, {
|
||||
agentId: route.agentId,
|
||||
});
|
||||
await updateLastRoute({
|
||||
storePath,
|
||||
sessionKey: route.mainSessionKey,
|
||||
deliveryContext: {
|
||||
channel: "slack",
|
||||
to: `user:${message.user}`,
|
||||
accountId: route.accountId,
|
||||
},
|
||||
ctx: prepared.ctxPayload,
|
||||
});
|
||||
}
|
||||
|
||||
const { statusThreadTs } = resolveSlackThreadTargets({
|
||||
message,
|
||||
replyToMode: ctx.replyToMode,
|
||||
|
||||
@@ -27,11 +27,8 @@ import { resolveMentionGatingWithBypass } from "../../../channels/mention-gating
|
||||
import { resolveConversationLabel } from "../../../channels/conversation-label.js";
|
||||
import { resolveControlCommandGate } from "../../../channels/command-gating.js";
|
||||
import { formatAllowlistMatchMeta } from "../../../channels/allowlist-match.js";
|
||||
import {
|
||||
readSessionUpdatedAt,
|
||||
recordSessionMetaFromInbound,
|
||||
resolveStorePath,
|
||||
} from "../../../config/sessions.js";
|
||||
import { recordInboundSession } from "../../../channels/session.js";
|
||||
import { readSessionUpdatedAt, resolveStorePath } from "../../../config/sessions.js";
|
||||
|
||||
import type { ResolvedSlackAccount } from "../../accounts.js";
|
||||
import { reactSlackMessage } from "../../actions.js";
|
||||
@@ -511,19 +508,28 @@ export async function prepareSlackMessage(params: {
|
||||
OriginatingTo: slackTo,
|
||||
}) satisfies FinalizedMsgContext;
|
||||
|
||||
void recordSessionMetaFromInbound({
|
||||
await recordInboundSession({
|
||||
storePath,
|
||||
sessionKey: sessionKey,
|
||||
sessionKey,
|
||||
ctx: ctxPayload,
|
||||
}).catch((err) => {
|
||||
ctx.logger.warn(
|
||||
{
|
||||
error: String(err),
|
||||
storePath,
|
||||
sessionKey,
|
||||
},
|
||||
"failed updating session meta",
|
||||
);
|
||||
updateLastRoute: isDirectMessage
|
||||
? {
|
||||
sessionKey: route.mainSessionKey,
|
||||
channel: "slack",
|
||||
to: `user:${message.user}`,
|
||||
accountId: route.accountId,
|
||||
}
|
||||
: undefined,
|
||||
onRecordError: (err) => {
|
||||
ctx.logger.warn(
|
||||
{
|
||||
error: String(err),
|
||||
storePath,
|
||||
sessionKey,
|
||||
},
|
||||
"failed updating session meta",
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const replyTarget = ctxPayload.To ?? undefined;
|
||||
|
||||
Reference in New Issue
Block a user