feat: add agent API and operational analytics

This commit is contained in:
jjbrunton committed 2026-08-08 22:08:14 +01:00
1 parent 720ea0652a
commit e8b730b592
65 files changed
+2650 -1214

No files matched your search

+21
View File
@@ -29,6 +29,7 @@ import type { MediaSyncService } from './media-sync.js';
import type { MonitorService } from './monitor.js';
import type { ProcessorService } from './processor.js';
import type { ResponseCheckerService } from './response-checker.js';
import type { RedditPost } from '../reddit/api.js';
/** Credentials passed to a factory. They must never be exposed by list/snapshot APIs. */
export interface VerifiedAccountSession {
@@ -80,6 +81,8 @@ export interface RedditAccountRuntimeLifecycle {
start(): void | Promise<void>;
/** Stop and await this account's schedules/loop, then close its browser. */
stop(): void | Promise<void>;
/** Process a post assigned by the shared discovery scheduler. */
dispatchPost?(post: RedditPost, signal?: AbortSignal): Promise<void>;
}
export type RedditAccountRuntimeState =
@@ -172,6 +175,24 @@ export class RedditAccountRuntime {
};
}
async canAcceptPost(): Promise<boolean> {
if (this.state !== 'running') return false;
if (!this.resources.accountAuth.isFullyAuthenticated()
&& !(await this.resources.accountAuth.ensureFullyAuthenticated())) return false;
if (this.resources.chatService.getInvitationCooldown()) return false;
return this.resources.rateLimiter.getTimers().nextMessageAvailableAt === null;
}
dispatchPost(post: RedditPost, signal?: AbortSignal): Promise<void> {
if (this.state !== 'running') {
throw new Error(`Cannot assign a post to ${this.session.redditUsername}: runtime is not running`);
}
if (!this.lifecycle.dispatchPost) {
throw new Error(`Runtime ${this.session.redditUsername} does not support shared post dispatch`);
}
return this.lifecycle.dispatchPost(post, signal);
}
private enqueue(operation: () => Promise<void>): Promise<void> {
const result = this.transition.then(operation, operation);
this.transition = result.catch(() => undefined);