feat(background-agent): add per-key queue structure
This commit is contained in:
parent
426fb36040
commit
b053df42fb
@ -49,6 +49,11 @@ interface Todo {
|
|||||||
id: string
|
id: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface QueueItem {
|
||||||
|
task: BackgroundTask
|
||||||
|
input: LaunchInput
|
||||||
|
}
|
||||||
|
|
||||||
export class BackgroundManager {
|
export class BackgroundManager {
|
||||||
private static cleanupManagers = new Set<BackgroundManager>()
|
private static cleanupManagers = new Set<BackgroundManager>()
|
||||||
private static cleanupRegistered = false
|
private static cleanupRegistered = false
|
||||||
@ -65,6 +70,9 @@ export class BackgroundManager {
|
|||||||
private config?: BackgroundTaskConfig
|
private config?: BackgroundTaskConfig
|
||||||
|
|
||||||
|
|
||||||
|
private queuesByKey: Map<string, QueueItem[]> = new Map()
|
||||||
|
private processingKeys: Set<string> = new Set()
|
||||||
|
|
||||||
constructor(ctx: PluginInput, config?: BackgroundTaskConfig) {
|
constructor(ctx: PluginInput, config?: BackgroundTaskConfig) {
|
||||||
this.tasks = new Map()
|
this.tasks = new Map()
|
||||||
this.notifications = new Map()
|
this.notifications = new Map()
|
||||||
@ -252,6 +260,13 @@ export class BackgroundManager {
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getConcurrencyKeyFromInput(input: LaunchInput): string {
|
||||||
|
if (input.model) {
|
||||||
|
return `${input.model.providerID}/${input.model.modelID}`
|
||||||
|
}
|
||||||
|
return input.agent
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Track a task created elsewhere (e.g., from delegate_task) for notification tracking.
|
* Track a task created elsewhere (e.g., from delegate_task) for notification tracking.
|
||||||
* This allows tasks created by other tools to receive the same toast/prompt notifications.
|
* This allows tasks created by other tools to receive the same toast/prompt notifications.
|
||||||
@ -1129,6 +1144,8 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea
|
|||||||
this.tasks.clear()
|
this.tasks.clear()
|
||||||
this.notifications.clear()
|
this.notifications.clear()
|
||||||
this.pendingByParent.clear()
|
this.pendingByParent.clear()
|
||||||
|
this.queuesByKey.clear()
|
||||||
|
this.processingKeys.clear()
|
||||||
this.unregisterProcessCleanup()
|
this.unregisterProcessCleanup()
|
||||||
log("[background-agent] Shutdown complete")
|
log("[background-agent] Shutdown complete")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user