Discord: preserve accountId in message actions (refs #1489)
This commit is contained in:
@@ -5,6 +5,7 @@ import { truncateUtf16Safe } from "../../utils.js";
|
||||
import { optionalStringEnum, stringEnum } from "../schema/typebox.js";
|
||||
import { type AnyAgentTool, jsonResult, readStringParam } from "./common.js";
|
||||
import { callGatewayTool, type GatewayCallOptions } from "./gateway.js";
|
||||
import { resolveSessionAgentId } from "../agent-scope.js";
|
||||
import { resolveInternalSessionKey, resolveMainSessionAlias } from "./sessions-helpers.js";
|
||||
|
||||
// NOTE: We use Type.Object({}, { additionalProperties: true }) for job/patch
|
||||
@@ -158,6 +159,15 @@ export function createCronTool(opts?: CronToolOptions): AnyAgentTool {
|
||||
throw new Error("job required");
|
||||
}
|
||||
const job = normalizeCronJobCreate(params.job) ?? params.job;
|
||||
if (job && typeof job === "object") {
|
||||
const cfg = loadConfig();
|
||||
const agentId = opts?.agentSessionKey
|
||||
? resolveSessionAgentId({ sessionKey: opts.agentSessionKey, config: cfg })
|
||||
: undefined;
|
||||
if (agentId && !(job as { agentId?: unknown }).agentId) {
|
||||
(job as { agentId?: string }).agentId = agentId;
|
||||
}
|
||||
}
|
||||
const contextMessages =
|
||||
typeof params.contextMessages === "number" && Number.isFinite(params.contextMessages)
|
||||
? params.contextMessages
|
||||
|
||||
@@ -114,7 +114,8 @@ export async function handleDiscordMessagingAction(
|
||||
required: true,
|
||||
label: "stickerIds",
|
||||
});
|
||||
await sendStickerDiscord(to, stickerIds, { content });
|
||||
const accountId = readStringParam(params, "accountId");
|
||||
await sendStickerDiscord(to, stickerIds, { content, accountId: accountId ?? undefined });
|
||||
return jsonResult({ ok: true });
|
||||
}
|
||||
case "poll": {
|
||||
@@ -137,10 +138,11 @@ export async function handleDiscordMessagingAction(
|
||||
const durationHours =
|
||||
typeof durationRaw === "number" && Number.isFinite(durationRaw) ? durationRaw : undefined;
|
||||
const maxSelections = allowMultiselect ? Math.max(2, answers.length) : 1;
|
||||
const accountId = readStringParam(params, "accountId");
|
||||
await sendPollDiscord(
|
||||
to,
|
||||
{ question, options: answers, maxSelections, durationHours },
|
||||
{ content },
|
||||
{ content, accountId: accountId ?? undefined },
|
||||
);
|
||||
return jsonResult({ ok: true });
|
||||
}
|
||||
@@ -211,7 +213,10 @@ export async function handleDiscordMessagingAction(
|
||||
const replyTo = readStringParam(params, "replyTo");
|
||||
const embeds =
|
||||
Array.isArray(params.embeds) && params.embeds.length > 0 ? params.embeds : undefined;
|
||||
const accountId = readStringParam(params, "accountId");
|
||||
|
||||
const result = await sendMessageDiscord(to, content, {
|
||||
accountId: accountId ?? undefined,
|
||||
mediaUrl,
|
||||
replyTo,
|
||||
embeds,
|
||||
@@ -298,7 +303,9 @@ export async function handleDiscordMessagingAction(
|
||||
});
|
||||
const mediaUrl = readStringParam(params, "mediaUrl");
|
||||
const replyTo = readStringParam(params, "replyTo");
|
||||
const accountId = readStringParam(params, "accountId");
|
||||
const result = await sendMessageDiscord(`channel:${channelId}`, content, {
|
||||
accountId: accountId ?? undefined,
|
||||
mediaUrl,
|
||||
replyTo,
|
||||
});
|
||||
|
||||
@@ -342,6 +342,9 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
|
||||
}) as ChannelMessageActionName;
|
||||
|
||||
const accountId = readStringParam(params, "accountId") ?? agentAccountId;
|
||||
if (accountId) {
|
||||
params.accountId = accountId;
|
||||
}
|
||||
|
||||
const gateway = {
|
||||
url: readStringParam(params, "gatewayUrl", { trim: false }),
|
||||
|
||||
Reference in New Issue
Block a user