feat(dispatcher): object name mapping for human-readable summaries

Config adds names: { '3': '小墨 🖊️', '5': '小橘 🍊' }
Summary now shows '由 小墨 🖊️ 创建' instead of 'agent:3'
Added task_assigned and task_commented to summary format
This commit is contained in:
小墨 2026-04-13 08:07:58 +00:00
parent 9088487673
commit 752f765132
2 changed files with 18 additions and 2 deletions

View File

@ -11,6 +11,7 @@ function ts(): string {
export class OcScheduler {
private running = false;
private timer: ReturnType<typeof setTimeout> | null = null;
private readonly names: Record<string, string>;
constructor(
private readonly config: DispatcherConfig,
@ -18,7 +19,9 @@ export class OcScheduler {
private readonly pending: Map<string, PendingEntry>,
/** Agent clients for pushing events */
private readonly agentClients: AgentClient[],
) {}
) {
this.names = config.names ?? {};
}
start(): void {
if (this.running) return;
@ -151,6 +154,12 @@ export class OcScheduler {
}
}
/** Resolve object id to human-readable name */
private resolveName(id: unknown): string {
const key = String(id);
return this.names[key] ?? `#${key}`;
}
private buildEventSummary(entries: PendingEntry[], events: OGraphEvent[]): string {
const lines: string[] = ['📋 OGraph Event Stream Updates'];
@ -160,10 +169,16 @@ export class OcScheduler {
// Format based on event type
if (event.type_name === 'task_created') {
const payload = event.payload as any;
lines.push(`📋 新任务: #${payload.subject} ${payload.title || '(无标题)'} (${payload.priority || 'normal'}) — 由 agent:${payload.creator || '?'} 创建`);
lines.push(`📋 新任务: #${payload.subject} ${payload.title || '(无标题)'} (${payload.priority || 'normal'}) — 由 ${this.resolveName(payload.creator)} 创建`);
} else if (event.type_name === 'task_assigned') {
const payload = event.payload as any;
lines.push(`📋 任务 #${payload.subject} 分配给 ${this.resolveName(payload.assignee)}`);
} else if (event.type_name === 'task_status_changed') {
const payload = event.payload as any;
lines.push(`📋 #${payload.subject} 状态更新: → ${payload.status}`);
} else if (event.type_name === 'task_commented') {
const payload = event.payload as any;
lines.push(`💬 ${this.resolveName(payload.author)} 评论了任务 #${payload.subject}: 「${payload.content}`);
} else {
lines.push(`${event.type_name} #${event.id} (${age}s ago)`);
}

View File

@ -29,6 +29,7 @@ export interface DispatcherConfig {
minAvailable: number; // 最少空闲槽位(默认 2)
};
agents?: AgentConfig[]; // 新的 AgentClient 配置
names?: Record<string, string>; // object id → 可读名字(如 "3": "小墨 🖊️")
intervals: {
watcherIdle: number; // 无变化时 poll 间隔 ms(默认 30000)
watcherActive: number; // 有变化时 poll 间隔 ms(默认 5000)