- Add unbounded CLI sessions agent-task with plan and code review logs - Add edge console with tests - Add node run manager for session lifecycle management - Add router and store tests - Update transport session handling - Add runtime proto definitions - Update configurations and packages
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package router
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"iop/apps/node/internal/adapters"
|
|
"iop/apps/node/internal/runtime"
|
|
)
|
|
|
|
type defaultRouter struct {
|
|
registry *adapters.Registry
|
|
logger *zap.Logger
|
|
}
|
|
|
|
// New returns a Router that resolves requests to registered adapters.
|
|
func New(reg *adapters.Registry, logger *zap.Logger) runtime.Router {
|
|
return &defaultRouter{registry: reg, logger: logger}
|
|
}
|
|
|
|
func (r *defaultRouter) Resolve(_ context.Context, req runtime.RunRequest) (runtime.ExecutionSpec, error) {
|
|
adapterName := req.Adapter
|
|
if adapterName == "" {
|
|
adapterName = r.registry.Default()
|
|
}
|
|
if adapterName == "" {
|
|
return runtime.ExecutionSpec{}, fmt.Errorf("router: no adapters registered")
|
|
}
|
|
|
|
if _, ok := r.registry.Get(adapterName); !ok {
|
|
return runtime.ExecutionSpec{}, fmt.Errorf("router: adapter %q not found", adapterName)
|
|
}
|
|
|
|
spec := runtime.ExecutionSpec{
|
|
RunID: req.RunID,
|
|
Adapter: adapterName,
|
|
Model: req.Model,
|
|
SessionID: req.SessionID,
|
|
SessionMode: req.SessionMode,
|
|
Background: req.Background,
|
|
Workspace: req.Workspace,
|
|
Policy: req.Policy,
|
|
Input: req.Input,
|
|
TimeoutSec: req.TimeoutSec,
|
|
Metadata: req.Metadata,
|
|
}
|
|
|
|
r.logger.Debug("resolved execution spec",
|
|
zap.String("run_id", req.RunID),
|
|
zap.String("adapter", spec.Adapter),
|
|
zap.String("model", spec.Model),
|
|
)
|
|
return spec, nil
|
|
}
|