feat: factories return instances — WithService handles registration
Register factories no longer call c.RegisterService() explicitly.
WithService auto-discovers name from package path and registers.
Eliminates double-registration error.
Uses WithOption("name", "core-agent") for Options struct.
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
adafee0f18
commit
919dcf963f
5 changed files with 7 additions and 13 deletions
|
|
@ -19,7 +19,7 @@ import (
|
|||
|
||||
func main() {
|
||||
r := core.New(
|
||||
core.WithOptions(core.Options{{Key: "name", Value: "core-agent"}}),
|
||||
core.WithOption("name", "core-agent"),
|
||||
core.WithService(agentic.Register),
|
||||
core.WithService(monitor.Register),
|
||||
core.WithService(brain.Register),
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ func TestSetCore_Good(t *testing.T) {
|
|||
s := &PrepSubsystem{}
|
||||
assert.Nil(t, s.core)
|
||||
|
||||
c := core.New(core.WithOptions(core.Options{{Key: "name", Value: "test"}})).Value.(*core.Core)
|
||||
c := core.New(core.WithOption("name", "test")).Value.(*core.Core)
|
||||
s.SetCore(c)
|
||||
assert.NotNil(t, s.core)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ import (
|
|||
)
|
||||
|
||||
// Register is the service factory for core.WithService.
|
||||
// Creates the PrepSubsystem, registers it via RegisterService (auto-discovers
|
||||
// Startable/Stoppable), loads config, and wires IPC handlers.
|
||||
// Returns the PrepSubsystem instance — WithService auto-discovers the name
|
||||
// from the package path and registers it. Startable/Stoppable/HandleIPCEvents
|
||||
// are auto-discovered by RegisterService.
|
||||
//
|
||||
// core.New(
|
||||
// core.WithService(agentic.Register),
|
||||
|
|
@ -23,9 +24,6 @@ func Register(c *core.Core) core.Result {
|
|||
c.Config().Set("agents.rates", cfg.Rates)
|
||||
c.Config().Set("agents.dispatch", cfg.Dispatch)
|
||||
|
||||
// Register instance — lifecycle hooks wired via Startable/Stoppable if implemented
|
||||
c.RegisterService("agentic", prep)
|
||||
|
||||
RegisterHandlers(c, prep)
|
||||
|
||||
return core.Result{Value: prep, OK: true}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,12 @@ import (
|
|||
)
|
||||
|
||||
// Register is the service factory for core.WithService.
|
||||
// Brain is a stateless API proxy — no lifecycle hooks.
|
||||
// Returns the DirectSubsystem — WithService auto-registers it.
|
||||
//
|
||||
// core.New(
|
||||
// core.WithService(brain.Register),
|
||||
// )
|
||||
func Register(c *core.Core) core.Result {
|
||||
brn := NewDirect()
|
||||
c.RegisterService("brain", brn)
|
||||
return core.Result{Value: brn, OK: true}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ import (
|
|||
)
|
||||
|
||||
// Register is the service factory for core.WithService.
|
||||
// Creates the monitor subsystem, registers via RegisterService,
|
||||
// and wires IPC handlers for agent lifecycle events.
|
||||
// Returns the monitor Subsystem — WithService auto-registers it.
|
||||
//
|
||||
// core.New(
|
||||
// core.WithService(monitor.Register),
|
||||
|
|
@ -18,8 +17,6 @@ func Register(c *core.Core) core.Result {
|
|||
mon := New()
|
||||
mon.core = c
|
||||
|
||||
c.RegisterService("monitor", mon)
|
||||
|
||||
// Register IPC handler for agent lifecycle events
|
||||
c.RegisterAction(func(c *core.Core, msg core.Message) core.Result {
|
||||
switch ev := msg.(type) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue