@friendlyrobot/discord-pi-agent 0.9.4 → 0.9.6
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.
- package/dist/debug-print.d.ts +8 -0
- package/dist/index.js +23 -54
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Print a text body to stdout with ASCII fences.
|
|
3
|
+
* Useful for ad-hoc debug output that stands out in logs.
|
|
4
|
+
*
|
|
5
|
+
* @param body The text content to print.
|
|
6
|
+
* @param title Optional label for the opening fence (defaults to "DEBUG").
|
|
7
|
+
*/
|
|
8
|
+
export declare function debugPrint(body: string, title?: string): void;
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,19 @@ function createModuleLogger(moduleName) {
|
|
|
39
39
|
return logger.child({ module: moduleName });
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// src/debug-print.ts
|
|
43
|
+
function debugPrint(body, title) {
|
|
44
|
+
const label = title ?? "DEBUG";
|
|
45
|
+
const fence = "=".repeat(label.length + 12);
|
|
46
|
+
console.info(`${fence}
|
|
47
|
+
===== ${label} =====
|
|
48
|
+
${fence}`);
|
|
49
|
+
console.info(body);
|
|
50
|
+
console.info(`${fence}
|
|
51
|
+
===== END =====
|
|
52
|
+
${fence}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
// src/markdown-table-transformer.ts
|
|
43
56
|
import { Lexer } from "marked";
|
|
44
57
|
var logger2 = createModuleLogger("markdown-table-transformer");
|
|
@@ -101,6 +114,7 @@ async function collectReply(session, prompt, options = {}) {
|
|
|
101
114
|
let toolCount = 0;
|
|
102
115
|
let sawAgentEnd = false;
|
|
103
116
|
const model = session.model ? `${session.model.provider}/${session.model.id}` : "none";
|
|
117
|
+
debugPrint(prompt, "Full Prompt");
|
|
104
118
|
logger3.debug({
|
|
105
119
|
logPrefix,
|
|
106
120
|
promptLength: prompt.length,
|
|
@@ -148,34 +162,13 @@ async function collectReply(session, prompt, options = {}) {
|
|
|
148
162
|
const errorMessage = session.agent.state.errorMessage?.trim();
|
|
149
163
|
const fallbackText = getLatestAssistantText(session.messages);
|
|
150
164
|
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
165
|
if (errorMessage) {
|
|
162
166
|
return errorMessage;
|
|
163
167
|
}
|
|
164
168
|
if (finalText) {
|
|
165
169
|
const transformed = await transformMarkdownTablesToCodeBlocks(finalText);
|
|
166
|
-
|
|
167
|
-
|
|
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");
|
|
170
|
+
debugPrint(finalText, "BEFORE");
|
|
171
|
+
debugPrint(transformed, "TRANSFORMED");
|
|
179
172
|
return transformed;
|
|
180
173
|
}
|
|
181
174
|
return "No response generated.";
|
|
@@ -981,7 +974,7 @@ async function sendTypingSafe(channel, channelKey) {
|
|
|
981
974
|
headers: { Authorization: `Bot ${token}` }
|
|
982
975
|
});
|
|
983
976
|
if (res.ok) {
|
|
984
|
-
logger5.
|
|
977
|
+
logger5.debug({ channelKey }, "[TYPING] OK");
|
|
985
978
|
return;
|
|
986
979
|
}
|
|
987
980
|
if (res.status === 429) {
|
|
@@ -1011,10 +1004,10 @@ function startTypingForChannel(channel, channelKey) {
|
|
|
1011
1004
|
const existing = typingIntervals.get(channelKey);
|
|
1012
1005
|
if (existing) {
|
|
1013
1006
|
existing.refs += 1;
|
|
1014
|
-
logger5.
|
|
1007
|
+
logger5.debug({ channelKey, refs: existing.refs }, "[TYPING] ref++ (reusing existing interval)");
|
|
1015
1008
|
return;
|
|
1016
1009
|
}
|
|
1017
|
-
logger5.
|
|
1010
|
+
logger5.debug({ channelKey }, "[TYPING] started new interval");
|
|
1018
1011
|
sendTypingSafe(channel, channelKey);
|
|
1019
1012
|
const interval = setInterval(() => {
|
|
1020
1013
|
sendTypingSafe(channel, channelKey);
|
|
@@ -1024,16 +1017,16 @@ function startTypingForChannel(channel, channelKey) {
|
|
|
1024
1017
|
function stopTypingForChannel(channelKey) {
|
|
1025
1018
|
const entry = typingIntervals.get(channelKey);
|
|
1026
1019
|
if (!entry) {
|
|
1027
|
-
logger5.
|
|
1020
|
+
logger5.debug({ channelKey }, "[TYPING] stop called but no entry found");
|
|
1028
1021
|
return;
|
|
1029
1022
|
}
|
|
1030
1023
|
entry.refs -= 1;
|
|
1031
1024
|
if (entry.refs <= 0) {
|
|
1032
1025
|
clearInterval(entry.interval);
|
|
1033
1026
|
typingIntervals.delete(channelKey);
|
|
1034
|
-
logger5.
|
|
1027
|
+
logger5.debug({ channelKey }, "[TYPING] interval cleared (refs hit 0)");
|
|
1035
1028
|
} else {
|
|
1036
|
-
logger5.
|
|
1029
|
+
logger5.debug({ channelKey, refs: entry.refs }, "[TYPING] ref-- (interval still active)");
|
|
1037
1030
|
}
|
|
1038
1031
|
}
|
|
1039
1032
|
async function sendReply(message, text) {
|
|
@@ -1044,13 +1037,8 @@ async function sendReply(message, text) {
|
|
|
1044
1037
|
}, "reply skipped, channel not sendable");
|
|
1045
1038
|
return;
|
|
1046
1039
|
}
|
|
1040
|
+
debugPrint(text, "Full Reply");
|
|
1047
1041
|
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");
|
|
1054
1042
|
const [firstChunk, ...remainingChunks] = chunks;
|
|
1055
1043
|
if (!firstChunk) {
|
|
1056
1044
|
return;
|
|
@@ -1200,41 +1188,22 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1200
1188
|
}
|
|
1201
1189
|
await addWorkingReaction(message);
|
|
1202
1190
|
const queuePosition = promptQueue.getSnapshot().pending;
|
|
1203
|
-
logger5.debug({
|
|
1204
|
-
scope,
|
|
1205
|
-
messageId: message.id,
|
|
1206
|
-
queuePosition
|
|
1207
|
-
}, "enqueue request");
|
|
1208
1191
|
if (queuePosition > 0) {
|
|
1209
1192
|
await sendReply(message, `Queued. ${queuePosition} request(s) ahead of this one.`);
|
|
1210
1193
|
}
|
|
1211
1194
|
let response;
|
|
1212
1195
|
try {
|
|
1213
1196
|
response = await promptQueue.enqueue(async () => {
|
|
1214
|
-
logger5.debug({
|
|
1215
|
-
messageId: message.id,
|
|
1216
|
-
scope
|
|
1217
|
-
}, "processing message");
|
|
1218
|
-
logger5.info({ messageId: message.id, scope, channelKey }, "[TYPING] prompt enqueued, starting processing");
|
|
1219
1197
|
const promptContent = buildDiscordPromptContent(message, scope, content, config);
|
|
1220
1198
|
const transformedPrompt = await config.promptTransform(promptContent);
|
|
1221
|
-
logger5.info({ messageId: message.id, scope, channelKey }, "[TYPING] about to call collectReply/session.prompt");
|
|
1222
1199
|
return collectReply(session, transformedPrompt, {
|
|
1223
1200
|
logPrefix: `[agent:${session.sessionId}]`
|
|
1224
1201
|
});
|
|
1225
1202
|
});
|
|
1226
1203
|
} finally {
|
|
1227
1204
|
stopTypingForChannel(channelKey);
|
|
1228
|
-
logger5.info({ channelKey, scope }, "[TYPING] interval released");
|
|
1229
1205
|
await removeWorkingReaction(message);
|
|
1230
1206
|
}
|
|
1231
|
-
logger5.info({
|
|
1232
|
-
direction: "OUT",
|
|
1233
|
-
scope,
|
|
1234
|
-
messageId: message.id,
|
|
1235
|
-
responseLength: response.length,
|
|
1236
|
-
response
|
|
1237
|
-
}, "response ready");
|
|
1238
1207
|
await sendReply(message, response);
|
|
1239
1208
|
}
|
|
1240
1209
|
|