|
@@ -12,6 +12,7 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
type Kimi struct {
|
|
type Kimi struct {
|
|
|
|
+ userContext *llm.UserContext
|
|
browser *rod.Browser
|
|
browser *rod.Browser
|
|
launcher *launcher.Launcher
|
|
launcher *launcher.Launcher
|
|
loginEvent func(ctx context.Context, bytes []byte) error
|
|
loginEvent func(ctx context.Context, bytes []byte) error
|
|
@@ -28,6 +29,11 @@ func (k *Kimi) WithLoginCallback(f func(ctx context.Context, user *llm.UserConte
|
|
return k
|
|
return k
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (k *Kimi) WithUserContext(user *llm.UserContext) llm.UserBrowserAgent {
|
|
|
|
+ k.userContext = user
|
|
|
|
+ return k
|
|
|
|
+}
|
|
|
|
+
|
|
func (k *Kimi) IsLogin(ctx context.Context, page *rod.Page) (bool, error) {
|
|
func (k *Kimi) IsLogin(ctx context.Context, page *rod.Page) (bool, error) {
|
|
_, err := page.Timeout(3 * time.Second).Element("div[data-testid='msh-header-user-avatar']")
|
|
_, err := page.Timeout(3 * time.Second).Element("div[data-testid='msh-header-user-avatar']")
|
|
if err != nil && !errors.Is(err, context.DeadlineExceeded) {
|
|
if err != nil && !errors.Is(err, context.DeadlineExceeded) {
|
|
@@ -87,7 +93,7 @@ func (k *Kimi) GetName() string {
|
|
return "kimi"
|
|
return "kimi"
|
|
}
|
|
}
|
|
|
|
|
|
-func (k *Kimi) NewChat(ctx context.Context, user *llm.UserContext) (llm.Chat, error) {
|
|
|
|
|
|
+func (k *Kimi) NewChat(ctx context.Context) (llm.Chat, error) {
|
|
c := &Chat{
|
|
c := &Chat{
|
|
ai: k,
|
|
ai: k,
|
|
Page: k.browser.Context(ctx).MustIncognito().MustPage(),
|
|
Page: k.browser.Context(ctx).MustIncognito().MustPage(),
|
|
@@ -114,7 +120,7 @@ func (k *Kimi) NewChat(ctx context.Context, user *llm.UserContext) (llm.Chat, er
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
- localStorage, ok := user.LocalStorage[k.GetName()]
|
|
|
|
|
|
+ localStorage, ok := k.userContext.LocalStorage[k.GetName()]
|
|
if ok {
|
|
if ok {
|
|
for key, val := range localStorage {
|
|
for key, val := range localStorage {
|
|
c.Page.MustEval(fmt.Sprintf("() => {window.localStorage.setItem('%s','%s')}", key, val))
|
|
c.Page.MustEval(fmt.Sprintf("() => {window.localStorage.setItem('%s','%s')}", key, val))
|