The old IPC Task system passed `any` through TaskHandler and
PerformAsync. Now that named Actions exist with typed signatures
(ActionHandler func(context.Context, Options) Result), the untyped
layer is dead weight.
Changes:
- type Task any removed (was in contract.go)
- type Task struct is now the composed sequence (action.go)
- PerformAsync takes (action string, opts Options) not (t Task)
- TaskHandler type removed — use c.Action("name", handler)
- RegisterTask removed — use c.Action("name", handler)
- PERFORM sugar removed — use c.Action("name").Run()
- ActionTaskStarted/Progress/Completed carry typed fields
(Action string, Options, Result) not any
ActionDef → Action rename also in this commit (same principle:
DTOs don't have Run() methods).
Co-Authored-By: Virgil <virgil@lethean.io>
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
// Background action dispatch for the Core framework.
|
|
// PerformAsync runs a named Action in a background goroutine with
|
|
// panic recovery and progress broadcasting.
|
|
|
|
package core
|
|
|
|
import "context"
|
|
|
|
// PerformAsync dispatches a named action in a background goroutine.
|
|
// Broadcasts ActionTaskStarted, ActionTaskProgress, and ActionTaskCompleted
|
|
// as IPC messages so other services can track progress.
|
|
//
|
|
// r := c.PerformAsync("agentic.dispatch", opts)
|
|
// taskID := r.Value.(string)
|
|
func (c *Core) PerformAsync(action string, opts Options) Result {
|
|
if c.shutdown.Load() {
|
|
return Result{}
|
|
}
|
|
taskID := ID()
|
|
|
|
c.ACTION(ActionTaskStarted{TaskIdentifier: taskID, Action: action, Options: opts})
|
|
|
|
c.waitGroup.Go(func() {
|
|
defer func() {
|
|
if rec := recover(); rec != nil {
|
|
c.ACTION(ActionTaskCompleted{
|
|
TaskIdentifier: taskID,
|
|
Action: action,
|
|
Result: Result{E("core.PerformAsync", Sprint("panic: ", rec), nil), false},
|
|
})
|
|
}
|
|
}()
|
|
|
|
r := c.Action(action).Run(context.Background(), opts)
|
|
|
|
c.ACTION(ActionTaskCompleted{
|
|
TaskIdentifier: taskID,
|
|
Action: action,
|
|
Result: r,
|
|
})
|
|
})
|
|
|
|
return Result{taskID, true}
|
|
}
|
|
|
|
// Progress broadcasts a progress update for a background task.
|
|
//
|
|
// c.Progress(taskID, 0.5, "halfway done", "agentic.dispatch")
|
|
func (c *Core) Progress(taskID string, progress float64, message string, action string) {
|
|
c.ACTION(ActionTaskProgress{
|
|
TaskIdentifier: taskID,
|
|
Action: action,
|
|
Progress: progress,
|
|
Message: message,
|
|
})
|
|
}
|
|
|
|
// Registration methods (RegisterAction, RegisterActions)
|
|
// are in ipc.go — registration is IPC's responsibility.
|