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:
parent
9088487673
commit
752f765132
@ -11,6 +11,7 @@ function ts(): string {
|
|||||||
export class OcScheduler {
|
export class OcScheduler {
|
||||||
private running = false;
|
private running = false;
|
||||||
private timer: ReturnType<typeof setTimeout> | null = null;
|
private timer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
private readonly names: Record<string, string>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly config: DispatcherConfig,
|
private readonly config: DispatcherConfig,
|
||||||
@ -18,7 +19,9 @@ export class OcScheduler {
|
|||||||
private readonly pending: Map<string, PendingEntry>,
|
private readonly pending: Map<string, PendingEntry>,
|
||||||
/** Agent clients for pushing events */
|
/** Agent clients for pushing events */
|
||||||
private readonly agentClients: AgentClient[],
|
private readonly agentClients: AgentClient[],
|
||||||
) {}
|
) {
|
||||||
|
this.names = config.names ?? {};
|
||||||
|
}
|
||||||
|
|
||||||
start(): void {
|
start(): void {
|
||||||
if (this.running) return;
|
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 {
|
private buildEventSummary(entries: PendingEntry[], events: OGraphEvent[]): string {
|
||||||
const lines: string[] = ['📋 OGraph Event Stream Updates'];
|
const lines: string[] = ['📋 OGraph Event Stream Updates'];
|
||||||
|
|
||||||
@ -160,10 +169,16 @@ export class OcScheduler {
|
|||||||
// Format based on event type
|
// Format based on event type
|
||||||
if (event.type_name === 'task_created') {
|
if (event.type_name === 'task_created') {
|
||||||
const payload = event.payload as any;
|
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') {
|
} else if (event.type_name === 'task_status_changed') {
|
||||||
const payload = event.payload as any;
|
const payload = event.payload as any;
|
||||||
lines.push(`📋 #${payload.subject} 状态更新: → ${payload.status}`);
|
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 {
|
} else {
|
||||||
lines.push(`• ${event.type_name} #${event.id} (${age}s ago)`);
|
lines.push(`• ${event.type_name} #${event.id} (${age}s ago)`);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ export interface DispatcherConfig {
|
|||||||
minAvailable: number; // 最少空闲槽位(默认 2)
|
minAvailable: number; // 最少空闲槽位(默认 2)
|
||||||
};
|
};
|
||||||
agents?: AgentConfig[]; // 新的 AgentClient 配置
|
agents?: AgentConfig[]; // 新的 AgentClient 配置
|
||||||
|
names?: Record<string, string>; // object id → 可读名字(如 "3": "小墨 🖊️")
|
||||||
intervals: {
|
intervals: {
|
||||||
watcherIdle: number; // 无变化时 poll 间隔 ms(默认 30000)
|
watcherIdle: number; // 无变化时 poll 间隔 ms(默认 30000)
|
||||||
watcherActive: number; // 有变化时 poll 间隔 ms(默认 5000)
|
watcherActive: number; // 有变化时 poll 间隔 ms(默认 5000)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user