-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.go
More file actions
44 lines (35 loc) · 1.21 KB
/
interfaces.go
File metadata and controls
44 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package copilotai
import (
"context"
copilot "github.com/github/copilot-sdk/go"
)
// SessionWrapper wraps the methods we use from copilot.Session so they can be mocked.
type SessionWrapper interface {
SendAndWait(ctx context.Context, opts copilot.MessageOptions) (*copilot.SessionEvent, error)
Destroy() error
}
// ClientWrapper wraps the methods we use from copilot.Client so they can be mocked.
type ClientWrapper interface {
CreateSession(ctx context.Context, cfg *copilot.SessionConfig) (SessionWrapper, error)
}
// realClientWrapper delegates to a real copilot.Client.
type realClientWrapper struct {
cli *copilot.Client
}
func (w *realClientWrapper) CreateSession(ctx context.Context, cfg *copilot.SessionConfig) (SessionWrapper, error) {
sess, err := w.cli.CreateSession(ctx, cfg)
if err != nil {
return nil, err
}
return &realSessionWrapper{sess: sess}, nil
}
// realSessionWrapper delegates to a real copilot.Session.
type realSessionWrapper struct {
sess *copilot.Session
}
func (w *realSessionWrapper) SendAndWait(ctx context.Context, opts copilot.MessageOptions) (*copilot.SessionEvent, error) {
return w.sess.SendAndWait(ctx, opts)
}
func (w *realSessionWrapper) Destroy() error {
return w.sess.Destroy()
}