mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
feat(gemini-web): Enable config hot-reload and fix Gem selection
This commit is contained in:
@@ -380,6 +380,15 @@ func (c *GeminiClient) generateOnce(prompt string, files []string, model Model,
|
|||||||
}
|
}
|
||||||
|
|
||||||
inner := []any{item0, nil, item2}
|
inner := []any{item0, nil, item2}
|
||||||
|
// Attach Gem first to keep index alignment with reference implementation
|
||||||
|
// so the Gemini Web UI can recognize the selected Gem.
|
||||||
|
if gem != nil {
|
||||||
|
// pad with 16 nils then gem ID
|
||||||
|
for i := 0; i < 16; i++ {
|
||||||
|
inner = append(inner, nil)
|
||||||
|
}
|
||||||
|
inner = append(inner, gem.ID)
|
||||||
|
}
|
||||||
requestedModel := strings.ToLower(model.Name)
|
requestedModel := strings.ToLower(model.Name)
|
||||||
if chat != nil && chat.RequestedModel() != "" {
|
if chat != nil && chat.RequestedModel() != "" {
|
||||||
requestedModel = chat.RequestedModel()
|
requestedModel = chat.RequestedModel()
|
||||||
@@ -388,13 +397,6 @@ func (c *GeminiClient) generateOnce(prompt string, files []string, model Model,
|
|||||||
inner = ensureAnyLen(inner, 49)
|
inner = ensureAnyLen(inner, 49)
|
||||||
inner[49] = 14
|
inner[49] = 14
|
||||||
}
|
}
|
||||||
if gem != nil {
|
|
||||||
// pad with 16 nils then gem ID
|
|
||||||
for i := 0; i < 16; i++ {
|
|
||||||
inner = append(inner, nil)
|
|
||||||
}
|
|
||||||
inner = append(inner, gem.ID)
|
|
||||||
}
|
|
||||||
innerJSON, _ := json.Marshal(inner)
|
innerJSON, _ := json.Marshal(inner)
|
||||||
outer := []any{nil, string(innerJSON)}
|
outer := []any{nil, string(innerJSON)}
|
||||||
outerJSON, _ := json.Marshal(outer)
|
outerJSON, _ := json.Marshal(outer)
|
||||||
|
|||||||
@@ -1030,3 +1030,10 @@ func FindReusableSessionIn(items map[string]ConversationRecord, index map[string
|
|||||||
}
|
}
|
||||||
return ConversationRecord{}, nil, 0, false
|
return ConversationRecord{}, nil, 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetConfig updates the configuration reference used by the state.
|
||||||
|
// This allows hot-reload of configuration to take effect for existing
|
||||||
|
// runtime states that were cached on auth during previous requests.
|
||||||
|
func (s *GeminiWebState) SetConfig(cfg *config.Config) {
|
||||||
|
s.cfg = cfg
|
||||||
|
}
|
||||||
|
|||||||
@@ -168,6 +168,8 @@ func (e *GeminiWebExecutor) stateFor(auth *cliproxyauth.Auth) (*geminiwebapi.Gem
|
|||||||
return nil, fmt.Errorf("gemini-web executor: auth is nil")
|
return nil, fmt.Errorf("gemini-web executor: auth is nil")
|
||||||
}
|
}
|
||||||
if runtime, ok := auth.Runtime.(*geminiWebRuntime); ok && runtime != nil && runtime.state != nil {
|
if runtime, ok := auth.Runtime.(*geminiWebRuntime); ok && runtime != nil && runtime.state != nil {
|
||||||
|
// Hot-reload: ensure cached state sees the latest config
|
||||||
|
runtime.state.SetConfig(e.cfg)
|
||||||
return runtime.state, nil
|
return runtime.state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +177,8 @@ func (e *GeminiWebExecutor) stateFor(auth *cliproxyauth.Auth) (*geminiwebapi.Gem
|
|||||||
defer e.mu.Unlock()
|
defer e.mu.Unlock()
|
||||||
|
|
||||||
if runtime, ok := auth.Runtime.(*geminiWebRuntime); ok && runtime != nil && runtime.state != nil {
|
if runtime, ok := auth.Runtime.(*geminiWebRuntime); ok && runtime != nil && runtime.state != nil {
|
||||||
|
// Hot-reload: ensure cached state sees the latest config
|
||||||
|
runtime.state.SetConfig(e.cfg)
|
||||||
return runtime.state, nil
|
return runtime.state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user