feat: add agent API and operational analytics
This commit is contained in:
1 parent
720ea0652a
commit
e8b730b592
65 files changed
+2650
-1214
No files matched your search
@@ -2,7 +2,7 @@ import type { Page } from 'playwright';
|
||||
import type { Logger } from '../utils/logger.js';
|
||||
import type { MessagesRepository, SuccessfulMessagesRepository, SentMessageRecord, ConversationOutcomesRepository } from '../database/repositories.js';
|
||||
import type { PostsRepository } from '../database/repositories.js';
|
||||
import { classifyConversationOutcome } from './conversation-outcome.js';
|
||||
import { recordConversationReply } from './conversation-outcome-recorder.js';
|
||||
import { denyAccountAuth, type AccountAuthGate } from './account-auth-context.js';
|
||||
|
||||
export interface ResponseCheckResult {
|
||||
@@ -68,25 +68,28 @@ export class ResponseCheckerService {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.messagesRepo.markGotResponse(message.id);
|
||||
|
||||
// Get the original post info
|
||||
const post = message.postId ? this.postsRepo.getById(message.postId) : undefined;
|
||||
|
||||
const outcome = classifyConversationOutcome(result.responseSnippet ?? '');
|
||||
this.outcomesRepo?.record(message.id, outcome, result.responseSnippet ?? null);
|
||||
if (outcome === 'engaged') {
|
||||
this.successfulMessagesRepo.insert({
|
||||
sentMessageId: message.id,
|
||||
originalMessage: message.message,
|
||||
imageAnalysis: post?.imageAnalysis || null,
|
||||
postTitle: post?.title || null,
|
||||
responseSnippet: result.responseSnippet || null,
|
||||
subreddit: post?.subreddit || null,
|
||||
});
|
||||
this.logger.info(`Engaged response from u/${message.recipient}; stored for learning.`);
|
||||
const attributedMessage = {
|
||||
...message,
|
||||
subreddit: message.subreddit ?? post?.subreddit,
|
||||
postTitle: message.postTitle ?? post?.title,
|
||||
postImageAnalysis: message.postImageAnalysis ?? post?.imageAnalysis ?? undefined,
|
||||
};
|
||||
if (this.outcomesRepo) {
|
||||
recordConversationReply(
|
||||
attributedMessage,
|
||||
result.responseSnippet ?? '',
|
||||
{ messageCount: 2, reciprocal: false },
|
||||
{
|
||||
messages: this.messagesRepo,
|
||||
successful: this.successfulMessagesRepo,
|
||||
outcomes: this.outcomesRepo,
|
||||
logger: this.logger,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
this.logger.info(`Response from u/${message.recipient} classified as ${outcome}; excluded from learning examples.`);
|
||||
this.messagesRepo.markGotResponse(message.id);
|
||||
this.logger.warn('Outcome repository unavailable; response recorded but excluded from learning.');
|
||||
}
|
||||
} else {
|
||||
// Just mark as checked
|
||||
|
||||
Reference in new issue
Block a user