@friendlyrobot/discord-pi-agent 0.7.0 → 0.7.2
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/index.js +25 -77
- package/dist/logger.d.ts +0 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38,17 +38,6 @@ var logger = usePrettyTransport ? pino({
|
|
|
38
38
|
function createModuleLogger(moduleName) {
|
|
39
39
|
return logger.child({ module: moduleName });
|
|
40
40
|
}
|
|
41
|
-
function logPayload(targetLogger, options) {
|
|
42
|
-
targetLogger.debug({
|
|
43
|
-
...options.context,
|
|
44
|
-
direction: options.direction,
|
|
45
|
-
payloadLength: options.content.length
|
|
46
|
-
}, formatPayloadBlock(options.label, options.content));
|
|
47
|
-
}
|
|
48
|
-
function formatPayloadBlock(label, content) {
|
|
49
|
-
return [label, "----- BEGIN -----", content, "----- END -----"].join(`
|
|
50
|
-
`);
|
|
51
|
-
}
|
|
52
41
|
|
|
53
42
|
// src/markdown-table-transformer.ts
|
|
54
43
|
import { Lexer } from "marked";
|
|
@@ -111,15 +100,10 @@ async function collectReply(session, prompt, options = {}) {
|
|
|
111
100
|
let eventCount = 0;
|
|
112
101
|
let toolCount = 0;
|
|
113
102
|
let sawAgentEnd = false;
|
|
114
|
-
logger3.debug({
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
content: prompt,
|
|
119
|
-
context: {
|
|
120
|
-
logPrefix
|
|
121
|
-
}
|
|
122
|
-
});
|
|
103
|
+
logger3.debug({
|
|
104
|
+
logPrefix,
|
|
105
|
+
promptLength: prompt.length
|
|
106
|
+
}, "prompt start");
|
|
123
107
|
const unsubscribe = session.subscribe((event) => {
|
|
124
108
|
eventCount += 1;
|
|
125
109
|
if (event.type === "message_update") {
|
|
@@ -174,22 +158,12 @@ async function collectReply(session, prompt, options = {}) {
|
|
|
174
158
|
}
|
|
175
159
|
if (finalText) {
|
|
176
160
|
const transformed = await transformMarkdownTablesToCodeBlocks(finalText);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
logPayload(logger3, {
|
|
186
|
-
direction: "OUT",
|
|
187
|
-
label: `${logPrefix} assistant transformed text`,
|
|
188
|
-
content: transformed,
|
|
189
|
-
context: {
|
|
190
|
-
logPrefix
|
|
191
|
-
}
|
|
192
|
-
});
|
|
161
|
+
logger3.debug({
|
|
162
|
+
logPrefix,
|
|
163
|
+
finalTextLength: finalText.length,
|
|
164
|
+
transformedTextLength: transformed.length,
|
|
165
|
+
transformed: transformed !== finalText
|
|
166
|
+
}, "assistant text ready");
|
|
193
167
|
return transformed;
|
|
194
168
|
}
|
|
195
169
|
return "No response generated.";
|
|
@@ -283,7 +257,7 @@ class AgentService {
|
|
|
283
257
|
sessionManager: SessionManager.continueRecent(this.config.cwd, sessionDir),
|
|
284
258
|
thinkingLevel: this.config.thinkingLevel
|
|
285
259
|
});
|
|
286
|
-
logger4.
|
|
260
|
+
logger4.debug({
|
|
287
261
|
sessionDir,
|
|
288
262
|
sessionId: session.sessionId,
|
|
289
263
|
sessionFile: session.sessionFile
|
|
@@ -389,7 +363,7 @@ class AgentService {
|
|
|
389
363
|
throw new Error(`Configured model not found: ${this.config.modelProvider}/${this.config.modelId}. Check your pi agent config and installed extensions.`);
|
|
390
364
|
}
|
|
391
365
|
if (isSameModel(session.model, desiredModel)) {
|
|
392
|
-
logger4.
|
|
366
|
+
logger4.debug({
|
|
393
367
|
model: `${desiredModel.provider}/${desiredModel.id}`
|
|
394
368
|
}, "model already selected");
|
|
395
369
|
return;
|
|
@@ -415,7 +389,7 @@ class AgentService {
|
|
|
415
389
|
const available = session.getAvailableThinkingLevels();
|
|
416
390
|
if (available.includes(this.config.thinkingLevel)) {
|
|
417
391
|
session.setThinkingLevel(this.config.thinkingLevel);
|
|
418
|
-
logger4.
|
|
392
|
+
logger4.debug({
|
|
419
393
|
level: this.config.thinkingLevel
|
|
420
394
|
}, "thinking level applied");
|
|
421
395
|
} else {
|
|
@@ -988,7 +962,7 @@ async function sendReply(message, text) {
|
|
|
988
962
|
return;
|
|
989
963
|
}
|
|
990
964
|
const chunks = chunkMessage(text);
|
|
991
|
-
logger5.
|
|
965
|
+
logger5.debug({
|
|
992
966
|
direction: "OUT",
|
|
993
967
|
messageId: message.id,
|
|
994
968
|
chunkCount: chunks.length,
|
|
@@ -1037,22 +1011,6 @@ async function startGatewayClient(config, agentService, sessionRegistry, authCon
|
|
|
1037
1011
|
}
|
|
1038
1012
|
});
|
|
1039
1013
|
client.on(Events.MessageCreate, async (message) => {
|
|
1040
|
-
logger5.info({
|
|
1041
|
-
direction: "IN",
|
|
1042
|
-
messageId: message.id,
|
|
1043
|
-
authorId: message.author.id,
|
|
1044
|
-
channelType: message.channel.type,
|
|
1045
|
-
preview: message.content.slice(0, 200)
|
|
1046
|
-
}, "message received");
|
|
1047
|
-
logPayload(logger5, {
|
|
1048
|
-
direction: "IN",
|
|
1049
|
-
label: "gateway message content",
|
|
1050
|
-
content: message.content,
|
|
1051
|
-
context: {
|
|
1052
|
-
messageId: message.id,
|
|
1053
|
-
authorId: message.author.id
|
|
1054
|
-
}
|
|
1055
|
-
});
|
|
1056
1014
|
try {
|
|
1057
1015
|
await onMessage(message, config, agentService, sessionRegistry, authConfig);
|
|
1058
1016
|
} catch (error) {
|
|
@@ -1098,6 +1056,14 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1098
1056
|
logger5.debug({ messageId: message.id }, "ignored empty message");
|
|
1099
1057
|
return;
|
|
1100
1058
|
}
|
|
1059
|
+
logger5.info({
|
|
1060
|
+
direction: "IN",
|
|
1061
|
+
scope,
|
|
1062
|
+
messageId: message.id,
|
|
1063
|
+
authorId: message.author.id,
|
|
1064
|
+
channelType: message.channel.type,
|
|
1065
|
+
content
|
|
1066
|
+
}, "message received");
|
|
1101
1067
|
const { entry, created } = await sessionRegistry.getOrCreate(scope);
|
|
1102
1068
|
const { session, promptQueue } = entry;
|
|
1103
1069
|
if (created && scope.startsWith("thread:") && message.channel.isThread()) {
|
|
@@ -1163,15 +1129,6 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1163
1129
|
scope
|
|
1164
1130
|
}, "processing message");
|
|
1165
1131
|
const promptContent = buildDiscordPromptContent(message, scope, content, config);
|
|
1166
|
-
logPayload(logger5, {
|
|
1167
|
-
direction: "IN",
|
|
1168
|
-
label: "gateway prompt content",
|
|
1169
|
-
content: promptContent,
|
|
1170
|
-
context: {
|
|
1171
|
-
scope,
|
|
1172
|
-
messageId: message.id
|
|
1173
|
-
}
|
|
1174
|
-
});
|
|
1175
1132
|
const transformedPrompt = await config.promptTransform(promptContent);
|
|
1176
1133
|
return collectReply(session, transformedPrompt, {
|
|
1177
1134
|
logPrefix: `[agent:${session.sessionId}]`
|
|
@@ -1183,17 +1140,8 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1183
1140
|
scope,
|
|
1184
1141
|
messageId: message.id,
|
|
1185
1142
|
responseLength: response.length,
|
|
1186
|
-
|
|
1143
|
+
response
|
|
1187
1144
|
}, "response ready");
|
|
1188
|
-
logPayload(logger5, {
|
|
1189
|
-
direction: "OUT",
|
|
1190
|
-
label: "gateway response content",
|
|
1191
|
-
content: response,
|
|
1192
|
-
context: {
|
|
1193
|
-
scope,
|
|
1194
|
-
messageId: message.id
|
|
1195
|
-
}
|
|
1196
|
-
});
|
|
1197
1145
|
await sendReply(message, response);
|
|
1198
1146
|
}
|
|
1199
1147
|
|
|
@@ -1271,7 +1219,7 @@ class SessionRegistry {
|
|
|
1271
1219
|
createdAt: new Date
|
|
1272
1220
|
};
|
|
1273
1221
|
this.scopes.set(scope, entry);
|
|
1274
|
-
logger6.
|
|
1222
|
+
logger6.debug({
|
|
1275
1223
|
scope,
|
|
1276
1224
|
sessionDir,
|
|
1277
1225
|
sessionId: session.sessionId
|
|
@@ -1283,7 +1231,7 @@ class SessionRegistry {
|
|
|
1283
1231
|
if (!entry) {
|
|
1284
1232
|
return;
|
|
1285
1233
|
}
|
|
1286
|
-
logger6.
|
|
1234
|
+
logger6.debug({ scope }, "removing scope");
|
|
1287
1235
|
await entry.session.abort();
|
|
1288
1236
|
entry.session.dispose();
|
|
1289
1237
|
this.scopes.delete(scope);
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
import { type Logger } from "pino";
|
|
2
2
|
export declare const logger: Logger<never, boolean>;
|
|
3
3
|
export declare function createModuleLogger(moduleName: string): Logger;
|
|
4
|
-
type PayloadLogOptions = {
|
|
5
|
-
direction: "IN" | "OUT";
|
|
6
|
-
label: string;
|
|
7
|
-
content: string;
|
|
8
|
-
context?: Record<string, unknown>;
|
|
9
|
-
};
|
|
10
|
-
export declare function logPayload(targetLogger: Logger, options: PayloadLogOptions): void;
|
|
11
|
-
export {};
|