@friendlyrobot/discord-pi-agent 0.7.0 → 0.7.1
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 +18 -71
- 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,
|
|
@@ -1042,17 +1016,8 @@ async function startGatewayClient(config, agentService, sessionRegistry, authCon
|
|
|
1042
1016
|
messageId: message.id,
|
|
1043
1017
|
authorId: message.author.id,
|
|
1044
1018
|
channelType: message.channel.type,
|
|
1045
|
-
|
|
1019
|
+
content: message.content
|
|
1046
1020
|
}, "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
1021
|
try {
|
|
1057
1022
|
await onMessage(message, config, agentService, sessionRegistry, authConfig);
|
|
1058
1023
|
} catch (error) {
|
|
@@ -1163,15 +1128,6 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1163
1128
|
scope
|
|
1164
1129
|
}, "processing message");
|
|
1165
1130
|
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
1131
|
const transformedPrompt = await config.promptTransform(promptContent);
|
|
1176
1132
|
return collectReply(session, transformedPrompt, {
|
|
1177
1133
|
logPrefix: `[agent:${session.sessionId}]`
|
|
@@ -1183,17 +1139,8 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1183
1139
|
scope,
|
|
1184
1140
|
messageId: message.id,
|
|
1185
1141
|
responseLength: response.length,
|
|
1186
|
-
|
|
1142
|
+
response
|
|
1187
1143
|
}, "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
1144
|
await sendReply(message, response);
|
|
1198
1145
|
}
|
|
1199
1146
|
|
|
@@ -1271,7 +1218,7 @@ class SessionRegistry {
|
|
|
1271
1218
|
createdAt: new Date
|
|
1272
1219
|
};
|
|
1273
1220
|
this.scopes.set(scope, entry);
|
|
1274
|
-
logger6.
|
|
1221
|
+
logger6.debug({
|
|
1275
1222
|
scope,
|
|
1276
1223
|
sessionDir,
|
|
1277
1224
|
sessionId: session.sessionId
|
|
@@ -1283,7 +1230,7 @@ class SessionRegistry {
|
|
|
1283
1230
|
if (!entry) {
|
|
1284
1231
|
return;
|
|
1285
1232
|
}
|
|
1286
|
-
logger6.
|
|
1233
|
+
logger6.debug({ scope }, "removing scope");
|
|
1287
1234
|
await entry.session.abort();
|
|
1288
1235
|
entry.session.dispose();
|
|
1289
1236
|
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 {};
|