agentcord 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -761,7 +761,8 @@ import {
|
|
|
761
761
|
EmbedBuilder,
|
|
762
762
|
ActionRowBuilder,
|
|
763
763
|
ButtonBuilder,
|
|
764
|
-
ButtonStyle
|
|
764
|
+
ButtonStyle,
|
|
765
|
+
StringSelectMenuBuilder
|
|
765
766
|
} from "discord.js";
|
|
766
767
|
var expandableStore = /* @__PURE__ */ new Map();
|
|
767
768
|
var expandCounter = 0;
|
|
@@ -951,6 +952,45 @@ var STATUS_EMOJI = {
|
|
|
951
952
|
deleted: "\u{1F5D1}\uFE0F"
|
|
952
953
|
// wastebasket
|
|
953
954
|
};
|
|
955
|
+
function renderAskUserQuestion(toolInput, sessionId) {
|
|
956
|
+
try {
|
|
957
|
+
const data = JSON.parse(toolInput);
|
|
958
|
+
const questions = data.questions;
|
|
959
|
+
if (!questions?.length) return null;
|
|
960
|
+
const embeds = [];
|
|
961
|
+
const components = [];
|
|
962
|
+
for (const q of questions) {
|
|
963
|
+
const embed = new EmbedBuilder().setColor(15965202).setTitle(q.header || "Question").setDescription(q.question);
|
|
964
|
+
if (q.options?.length) {
|
|
965
|
+
if (q.options.length <= 4) {
|
|
966
|
+
const row = new ActionRowBuilder();
|
|
967
|
+
for (let i = 0; i < q.options.length; i++) {
|
|
968
|
+
row.addComponents(
|
|
969
|
+
new ButtonBuilder().setCustomId(`answer:${sessionId}:${q.options[i].label}`).setLabel(q.options[i].label.slice(0, 80)).setStyle(i === 0 ? ButtonStyle.Primary : ButtonStyle.Secondary)
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
components.push(row);
|
|
973
|
+
} else {
|
|
974
|
+
const menu = new StringSelectMenuBuilder().setCustomId(`answer-select:${sessionId}`).setPlaceholder("Select an option...");
|
|
975
|
+
for (const opt of q.options) {
|
|
976
|
+
menu.addOptions({
|
|
977
|
+
label: opt.label.slice(0, 100),
|
|
978
|
+
description: opt.description?.slice(0, 100),
|
|
979
|
+
value: opt.label
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
components.push(new ActionRowBuilder().addComponents(menu));
|
|
983
|
+
}
|
|
984
|
+
const optionLines = q.options.map((o) => o.description ? `**${o.label}** \u2014 ${o.description}` : `**${o.label}**`).join("\n");
|
|
985
|
+
embed.addFields({ name: "Options", value: truncate(optionLines, 1e3) });
|
|
986
|
+
}
|
|
987
|
+
embeds.push(embed);
|
|
988
|
+
}
|
|
989
|
+
return { embeds, components };
|
|
990
|
+
} catch {
|
|
991
|
+
return null;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
954
994
|
function renderTaskToolEmbed(toolName, toolInput) {
|
|
955
995
|
try {
|
|
956
996
|
const data = JSON.parse(toolInput);
|
|
@@ -1023,6 +1063,12 @@ async function handleOutputStream(stream, channel, sessionId, verbose = false) {
|
|
|
1023
1063
|
embeds: [taskEmbed],
|
|
1024
1064
|
components: [makeStopButton(sessionId)]
|
|
1025
1065
|
});
|
|
1066
|
+
} else if (currentToolName === "AskUserQuestion") {
|
|
1067
|
+
const rendered = renderAskUserQuestion(currentToolInput, sessionId);
|
|
1068
|
+
if (rendered) {
|
|
1069
|
+
rendered.components.push(makeStopButton(sessionId));
|
|
1070
|
+
await channel.send({ embeds: rendered.embeds, components: rendered.components });
|
|
1071
|
+
}
|
|
1026
1072
|
} else if (!isTaskTool) {
|
|
1027
1073
|
const toolInput = currentToolInput;
|
|
1028
1074
|
const displayInput = toolInput.length > 1e3 ? truncate(toolInput, 1e3) : toolInput;
|
|
@@ -1999,6 +2045,26 @@ ${display}
|
|
|
1999
2045
|
}
|
|
2000
2046
|
return;
|
|
2001
2047
|
}
|
|
2048
|
+
if (customId.startsWith("answer:")) {
|
|
2049
|
+
const parts = customId.split(":");
|
|
2050
|
+
const sessionId = parts[1];
|
|
2051
|
+
const answer = parts.slice(2).join(":");
|
|
2052
|
+
const session = getSession(sessionId);
|
|
2053
|
+
if (!session) {
|
|
2054
|
+
await interaction.reply({ content: "Session not found.", ephemeral: true });
|
|
2055
|
+
return;
|
|
2056
|
+
}
|
|
2057
|
+
await interaction.deferReply();
|
|
2058
|
+
try {
|
|
2059
|
+
const channel = interaction.channel;
|
|
2060
|
+
const stream = sendPrompt(sessionId, answer);
|
|
2061
|
+
await interaction.editReply(`Answered: **${truncate(answer, 100)}**`);
|
|
2062
|
+
await handleOutputStream(stream, channel, sessionId, session.verbose);
|
|
2063
|
+
} catch (err) {
|
|
2064
|
+
await interaction.editReply(`Error: ${err.message}`);
|
|
2065
|
+
}
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2002
2068
|
if (customId.startsWith("confirm:")) {
|
|
2003
2069
|
const parts = customId.split(":");
|
|
2004
2070
|
const sessionId = parts[1];
|
|
@@ -2027,6 +2093,25 @@ async function handleSelectMenu(interaction) {
|
|
|
2027
2093
|
return;
|
|
2028
2094
|
}
|
|
2029
2095
|
const customId = interaction.customId;
|
|
2096
|
+
if (customId.startsWith("answer-select:")) {
|
|
2097
|
+
const sessionId = customId.slice(14);
|
|
2098
|
+
const selected = interaction.values[0];
|
|
2099
|
+
const session = getSession(sessionId);
|
|
2100
|
+
if (!session) {
|
|
2101
|
+
await interaction.reply({ content: "Session not found.", ephemeral: true });
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
await interaction.deferReply();
|
|
2105
|
+
try {
|
|
2106
|
+
const channel = interaction.channel;
|
|
2107
|
+
const stream = sendPrompt(sessionId, selected);
|
|
2108
|
+
await interaction.editReply(`Answered: **${truncate(selected, 100)}**`);
|
|
2109
|
+
await handleOutputStream(stream, channel, sessionId, session.verbose);
|
|
2110
|
+
} catch (err) {
|
|
2111
|
+
await interaction.editReply(`Error: ${err.message}`);
|
|
2112
|
+
}
|
|
2113
|
+
return;
|
|
2114
|
+
}
|
|
2030
2115
|
if (customId.startsWith("select:")) {
|
|
2031
2116
|
const sessionId = customId.slice(7);
|
|
2032
2117
|
const selected = interaction.values[0];
|
package/dist/cli.js
CHANGED
|
@@ -18,7 +18,7 @@ switch (command) {
|
|
|
18
18
|
console.log("Run \x1B[36magentcord setup\x1B[0m to configure.\n");
|
|
19
19
|
process.exit(1);
|
|
20
20
|
}
|
|
21
|
-
const { startBot } = await import("./bot-
|
|
21
|
+
const { startBot } = await import("./bot-RT4CJNKG.js");
|
|
22
22
|
console.log("agentcord starting...");
|
|
23
23
|
await startBot();
|
|
24
24
|
break;
|