refactor: reuse dispatcher helper for native commands
This commit is contained in:
@@ -4,7 +4,9 @@ import type { GetReplyOptions } from "../types.js";
|
||||
import type { DispatchFromConfigResult } from "./dispatch-from-config.js";
|
||||
import { dispatchReplyFromConfig } from "./dispatch-from-config.js";
|
||||
import {
|
||||
createReplyDispatcher,
|
||||
createReplyDispatcherWithTyping,
|
||||
type ReplyDispatcherOptions,
|
||||
type ReplyDispatcherWithTypingOptions,
|
||||
} from "./reply-dispatcher.js";
|
||||
|
||||
@@ -32,3 +34,24 @@ export async function dispatchReplyWithBufferedBlockDispatcher(params: {
|
||||
markDispatchIdle();
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function dispatchReplyWithDispatcher(params: {
|
||||
ctx: MsgContext;
|
||||
cfg: ClawdbotConfig;
|
||||
dispatcherOptions: ReplyDispatcherOptions;
|
||||
replyOptions?: Omit<GetReplyOptions, "onToolResult" | "onBlockReply">;
|
||||
replyResolver?: typeof import("../reply.js").getReplyFromConfig;
|
||||
}): Promise<DispatchFromConfigResult> {
|
||||
const dispatcher = createReplyDispatcher(params.dispatcherOptions);
|
||||
|
||||
const result = await dispatchReplyFromConfig({
|
||||
ctx: params.ctx,
|
||||
cfg: params.cfg,
|
||||
dispatcher,
|
||||
replyResolver: params.replyResolver,
|
||||
replyOptions: params.replyOptions,
|
||||
});
|
||||
|
||||
await dispatcher.waitForIdle();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -46,10 +46,8 @@ import {
|
||||
buildMentionRegexes,
|
||||
matchesMentionPatterns,
|
||||
} from "../auto-reply/reply/mentions.js";
|
||||
import {
|
||||
createReplyDispatcher,
|
||||
createReplyDispatcherWithTyping,
|
||||
} from "../auto-reply/reply/reply-dispatcher.js";
|
||||
import { dispatchReplyWithDispatcher } from "../auto-reply/reply/provider-dispatcher.js";
|
||||
import { createReplyDispatcherWithTyping } from "../auto-reply/reply/reply-dispatcher.js";
|
||||
import { createReplyReferencePlanner } from "../auto-reply/reply/reply-reference.js";
|
||||
import type { ReplyPayload } from "../auto-reply/types.js";
|
||||
import {
|
||||
@@ -1832,31 +1830,29 @@ export function createDiscordNativeCommand(params: {
|
||||
};
|
||||
|
||||
let didReply = false;
|
||||
const dispatcher = createReplyDispatcher({
|
||||
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||
.responsePrefix,
|
||||
humanDelay: resolveHumanDelayConfig(cfg, route.agentId),
|
||||
deliver: async (payload) => {
|
||||
await deliverDiscordInteractionReply({
|
||||
interaction,
|
||||
payload,
|
||||
textLimit: resolveTextChunkLimit(cfg, "discord", accountId, {
|
||||
fallbackLimit: 2000,
|
||||
}),
|
||||
maxLinesPerMessage: discordConfig?.maxLinesPerMessage,
|
||||
preferFollowUp: didReply,
|
||||
});
|
||||
didReply = true;
|
||||
},
|
||||
onError: (err, info) => {
|
||||
console.error(`discord slash ${info.kind} reply failed`, err);
|
||||
},
|
||||
});
|
||||
|
||||
await dispatchReplyFromConfig({
|
||||
await dispatchReplyWithDispatcher({
|
||||
ctx: ctxPayload,
|
||||
cfg,
|
||||
dispatcher,
|
||||
dispatcherOptions: {
|
||||
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||
.responsePrefix,
|
||||
humanDelay: resolveHumanDelayConfig(cfg, route.agentId),
|
||||
deliver: async (payload) => {
|
||||
await deliverDiscordInteractionReply({
|
||||
interaction,
|
||||
payload,
|
||||
textLimit: resolveTextChunkLimit(cfg, "discord", accountId, {
|
||||
fallbackLimit: 2000,
|
||||
}),
|
||||
maxLinesPerMessage: discordConfig?.maxLinesPerMessage,
|
||||
preferFollowUp: didReply,
|
||||
});
|
||||
didReply = true;
|
||||
},
|
||||
onError: (err, info) => {
|
||||
console.error(`discord slash ${info.kind} reply failed`, err);
|
||||
},
|
||||
},
|
||||
replyOptions: {
|
||||
skillFilter: channelConfig?.skills,
|
||||
disableBlockStreaming:
|
||||
@@ -1865,7 +1861,6 @@ export function createDiscordNativeCommand(params: {
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
await dispatcher.waitForIdle();
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -34,10 +34,8 @@ import {
|
||||
buildMentionRegexes,
|
||||
matchesMentionPatterns,
|
||||
} from "../auto-reply/reply/mentions.js";
|
||||
import {
|
||||
createReplyDispatcher,
|
||||
createReplyDispatcherWithTyping,
|
||||
} from "../auto-reply/reply/reply-dispatcher.js";
|
||||
import { dispatchReplyWithDispatcher } from "../auto-reply/reply/provider-dispatcher.js";
|
||||
import { createReplyDispatcherWithTyping } from "../auto-reply/reply/reply-dispatcher.js";
|
||||
import { createReplyReferencePlanner } from "../auto-reply/reply/reply-reference.js";
|
||||
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../auto-reply/tokens.js";
|
||||
import type { ReplyPayload } from "../auto-reply/types.js";
|
||||
@@ -1923,31 +1921,28 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
|
||||
OriginatingTo: `user:${command.user_id}`,
|
||||
};
|
||||
|
||||
const dispatcher = createReplyDispatcher({
|
||||
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||
.responsePrefix,
|
||||
deliver: async (payload) => {
|
||||
await deliverSlackSlashReplies({
|
||||
replies: [payload],
|
||||
respond,
|
||||
ephemeral: slashCommand.ephemeral,
|
||||
textLimit,
|
||||
});
|
||||
},
|
||||
onError: (err, info) => {
|
||||
runtime.error?.(
|
||||
danger(`slack slash ${info.kind} reply failed: ${String(err)}`),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const { counts } = await dispatchReplyFromConfig({
|
||||
const { counts } = await dispatchReplyWithDispatcher({
|
||||
ctx: ctxPayload,
|
||||
cfg,
|
||||
dispatcher,
|
||||
dispatcherOptions: {
|
||||
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||
.responsePrefix,
|
||||
deliver: async (payload) => {
|
||||
await deliverSlackSlashReplies({
|
||||
replies: [payload],
|
||||
respond,
|
||||
ephemeral: slashCommand.ephemeral,
|
||||
textLimit,
|
||||
});
|
||||
},
|
||||
onError: (err, info) => {
|
||||
runtime.error?.(
|
||||
danger(`slack slash ${info.kind} reply failed: ${String(err)}`),
|
||||
);
|
||||
},
|
||||
},
|
||||
replyOptions: { skillFilter: channelConfig?.skills },
|
||||
});
|
||||
await dispatcher.waitForIdle();
|
||||
if (counts.final + counts.tool + counts.block === 0) {
|
||||
await deliverSlackSlashReplies({
|
||||
replies: [],
|
||||
|
||||
Reference in New Issue
Block a user