@friendlyrobot/discord-pi-agent 0.9.4 → 0.9.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.
Files changed (2) hide show
  1. package/dist/index.js +17 -50
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -101,6 +101,7 @@ async function collectReply(session, prompt, options = {}) {
101
101
  let toolCount = 0;
102
102
  let sawAgentEnd = false;
103
103
  const model = session.model ? `${session.model.provider}/${session.model.id}` : "none";
104
+ console.info(prompt);
104
105
  logger3.debug({
105
106
  logPrefix,
106
107
  promptLength: prompt.length,
@@ -148,34 +149,16 @@ async function collectReply(session, prompt, options = {}) {
148
149
  const errorMessage = session.agent.state.errorMessage?.trim();
149
150
  const fallbackText = getLatestAssistantText(session.messages);
150
151
  const finalText = streamedText.trim() || fallbackText.trim();
151
- logger3.debug({
152
- eventCount,
153
- toolCount,
154
- sawAgentEnd,
155
- streamedTextLength: streamedText.trim().length,
156
- fallbackTextLength: fallbackText.trim().length,
157
- errorMessage,
158
- model,
159
- logPrefix
160
- }, "prompt done");
161
152
  if (errorMessage) {
162
153
  return errorMessage;
163
154
  }
164
155
  if (finalText) {
165
156
  const transformed = await transformMarkdownTablesToCodeBlocks(finalText);
166
- console.info(`========== reply-buffer BEFORE (${finalText.length} chars) ==========
167
- ${finalText}
168
- ========== reply-buffer BEFORE END ==========`);
169
- console.info(`========== reply-buffer AFTER (${transformed.length} chars) ==========
170
- ${transformed}
171
- ========== reply-buffer AFTER END ==========`);
172
- logger3.debug({
173
- logPrefix,
174
- model,
175
- finalTextLength: finalText.length,
176
- transformedTextLength: transformed.length,
177
- transformed: transformed !== finalText
178
- }, "assistant text ready");
157
+ console.info(`========== BEFORE ==========`);
158
+ console.info(finalText);
159
+ console.info(`========== TRANSFORMED ==========`);
160
+ console.info(transformed);
161
+ console.info(`========== END ==========`);
179
162
  return transformed;
180
163
  }
181
164
  return "No response generated.";
@@ -981,7 +964,7 @@ async function sendTypingSafe(channel, channelKey) {
981
964
  headers: { Authorization: `Bot ${token}` }
982
965
  });
983
966
  if (res.ok) {
984
- logger5.info({ channelKey }, "[TYPING] OK");
967
+ logger5.debug({ channelKey }, "[TYPING] OK");
985
968
  return;
986
969
  }
987
970
  if (res.status === 429) {
@@ -1011,10 +994,10 @@ function startTypingForChannel(channel, channelKey) {
1011
994
  const existing = typingIntervals.get(channelKey);
1012
995
  if (existing) {
1013
996
  existing.refs += 1;
1014
- logger5.info({ channelKey, refs: existing.refs }, "[TYPING] ref++ (reusing existing interval)");
997
+ logger5.debug({ channelKey, refs: existing.refs }, "[TYPING] ref++ (reusing existing interval)");
1015
998
  return;
1016
999
  }
1017
- logger5.info({ channelKey }, "[TYPING] started new interval");
1000
+ logger5.debug({ channelKey }, "[TYPING] started new interval");
1018
1001
  sendTypingSafe(channel, channelKey);
1019
1002
  const interval = setInterval(() => {
1020
1003
  sendTypingSafe(channel, channelKey);
@@ -1024,16 +1007,16 @@ function startTypingForChannel(channel, channelKey) {
1024
1007
  function stopTypingForChannel(channelKey) {
1025
1008
  const entry = typingIntervals.get(channelKey);
1026
1009
  if (!entry) {
1027
- logger5.info({ channelKey }, "[TYPING] stop called but no entry found");
1010
+ logger5.debug({ channelKey }, "[TYPING] stop called but no entry found");
1028
1011
  return;
1029
1012
  }
1030
1013
  entry.refs -= 1;
1031
1014
  if (entry.refs <= 0) {
1032
1015
  clearInterval(entry.interval);
1033
1016
  typingIntervals.delete(channelKey);
1034
- logger5.info({ channelKey }, "[TYPING] interval cleared (refs hit 0)");
1017
+ logger5.debug({ channelKey }, "[TYPING] interval cleared (refs hit 0)");
1035
1018
  } else {
1036
- logger5.info({ channelKey, refs: entry.refs }, "[TYPING] ref-- (interval still active)");
1019
+ logger5.debug({ channelKey, refs: entry.refs }, "[TYPING] ref-- (interval still active)");
1037
1020
  }
1038
1021
  }
1039
1022
  async function sendReply(message, text) {
@@ -1045,21 +1028,20 @@ async function sendReply(message, text) {
1045
1028
  return;
1046
1029
  }
1047
1030
  const chunks = chunkMessage(text);
1048
- logger5.debug({
1049
- direction: "OUT",
1050
- messageId: message.id,
1051
- chunkCount: chunks.length,
1052
- textLength: text.length
1053
- }, "sending reply");
1031
+ logger5.debug("sending reply");
1054
1032
  const [firstChunk, ...remainingChunks] = chunks;
1055
1033
  if (!firstChunk) {
1056
1034
  return;
1057
1035
  }
1058
1036
  try {
1037
+ console.info("=== Reply Start ===");
1059
1038
  await message.reply(firstChunk);
1039
+ console.info(firstChunk);
1060
1040
  for (const chunk of remainingChunks) {
1041
+ console.info(chunk);
1061
1042
  await channel.send(chunk);
1062
1043
  }
1044
+ console.info("=== Reply End ===");
1063
1045
  } catch (error) {
1064
1046
  logger5.error({
1065
1047
  messageId: message.id,
@@ -1200,11 +1182,6 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
1200
1182
  }
1201
1183
  await addWorkingReaction(message);
1202
1184
  const queuePosition = promptQueue.getSnapshot().pending;
1203
- logger5.debug({
1204
- scope,
1205
- messageId: message.id,
1206
- queuePosition
1207
- }, "enqueue request");
1208
1185
  if (queuePosition > 0) {
1209
1186
  await sendReply(message, `Queued. ${queuePosition} request(s) ahead of this one.`);
1210
1187
  }
@@ -1215,26 +1192,16 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
1215
1192
  messageId: message.id,
1216
1193
  scope
1217
1194
  }, "processing message");
1218
- logger5.info({ messageId: message.id, scope, channelKey }, "[TYPING] prompt enqueued, starting processing");
1219
1195
  const promptContent = buildDiscordPromptContent(message, scope, content, config);
1220
1196
  const transformedPrompt = await config.promptTransform(promptContent);
1221
- logger5.info({ messageId: message.id, scope, channelKey }, "[TYPING] about to call collectReply/session.prompt");
1222
1197
  return collectReply(session, transformedPrompt, {
1223
1198
  logPrefix: `[agent:${session.sessionId}]`
1224
1199
  });
1225
1200
  });
1226
1201
  } finally {
1227
1202
  stopTypingForChannel(channelKey);
1228
- logger5.info({ channelKey, scope }, "[TYPING] interval released");
1229
1203
  await removeWorkingReaction(message);
1230
1204
  }
1231
- logger5.info({
1232
- direction: "OUT",
1233
- scope,
1234
- messageId: message.id,
1235
- responseLength: response.length,
1236
- response
1237
- }, "response ready");
1238
1205
  await sendReply(message, response);
1239
1206
  }
1240
1207
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friendlyrobot/discord-pi-agent",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "Reusable Discord gateway bridge for persistent pi agent sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",