refactor(commands): add runtime interfaces for agent-backed handlers
This commit is contained in:
parent
bb61147f7e
commit
1dd5ffcdab
2 changed files with 74 additions and 0 deletions
21
pkg/commands/runtime.go
Normal file
21
pkg/commands/runtime.go
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/sipeed/picoclaw/pkg/config"
|
||||||
|
"github.com/sipeed/picoclaw/pkg/session"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SessionOps interface {
|
||||||
|
ResolveActive(scopeKey string) (string, error)
|
||||||
|
StartNew(scopeKey string) (string, error)
|
||||||
|
List(scopeKey string) ([]session.SessionMeta, error)
|
||||||
|
Resume(scopeKey string, index int) (string, error)
|
||||||
|
Prune(scopeKey string, limit int) ([]string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Runtime interface {
|
||||||
|
Channel() string
|
||||||
|
ScopeKey() string
|
||||||
|
SessionOps() SessionOps
|
||||||
|
Config() *config.Config
|
||||||
|
}
|
||||||
53
pkg/commands/runtime_test.go
Normal file
53
pkg/commands/runtime_test.go
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/pkg/config"
|
||||||
|
"github.com/sipeed/picoclaw/pkg/session"
|
||||||
|
)
|
||||||
|
|
||||||
|
type fakeSessionOps struct{}
|
||||||
|
|
||||||
|
func (f *fakeSessionOps) ResolveActive(scopeKey string) (string, error) {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeSessionOps) StartNew(scopeKey string) (string, error) {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeSessionOps) List(scopeKey string) ([]session.SessionMeta, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeSessionOps) Resume(scopeKey string, index int) (string, error) {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeSessionOps) Prune(scopeKey string, limit int) ([]string, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type fakeRuntime struct{}
|
||||||
|
|
||||||
|
func (f *fakeRuntime) Channel() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeRuntime) ScopeKey() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeRuntime) SessionOps() SessionOps {
|
||||||
|
return &fakeSessionOps{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeRuntime) Config() *config.Config {
|
||||||
|
return &config.Config{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRuntimeContracts_MinimalSessionOps(t *testing.T) {
|
||||||
|
var _ SessionOps = (*fakeSessionOps)(nil)
|
||||||
|
var _ Runtime = (*fakeRuntime)(nil)
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue