History

feat(gemini-web): Enable config hot-reload and fix Gem selection

hkfires committed 1 year ago

Commit 9bb7df71 parent 43665cb3 files · +20 −7Browse files

Unified · Split

3 files
  1. internal/provider/gemini-web/client.go +9 −7
  2. internal/provider/gemini-web/state.go +7 −0
  3. internal/runtime/executor/gemini_web_executor.go +4 −0
internal/provider/gemini-web/client.go+9−7
@@ -380,6 +380,15 @@ func (c *GeminiClient) generateOnce(prompt string, files []string, model Model, · 379 unmodified lines
380380 }
381381
382382 inner := []any{item0, nil, item2}
383+ // Attach Gem first to keep index alignment with reference implementation
384+ // so the Gemini Web UI can recognize the selected Gem.
385+ if gem != nil {
386+ // pad with 16 nils then gem ID
387+ for i := 0; i < 16; i++ {
388+ inner = append(inner, nil)
389+ }
390+ inner = append(inner, gem.ID)
391+ }
383392 requestedModel := strings.ToLower(model.Name)
384393 if chat != nil && chat.RequestedModel() != "" {
385394 requestedModel = chat.RequestedModel()
@@ -388,13 +397,6 @@ func (c *GeminiClient) generateOnce(prompt string, files []string, model Model, · 2 unmodified lines
388397 inner = ensureAnyLen(inner, 49)
389398 inner[49] = 14
390399 }
391− if gem != nil {
392− // pad with 16 nils then gem ID
393− for i := 0; i < 16; i++ {
394− inner = append(inner, nil)
395− }
396− inner = append(inner, gem.ID)
397− }
398400 innerJSON, _ := json.Marshal(inner)
399401 outer := []any{nil, string(innerJSON)}
400402 outerJSON, _ := json.Marshal(outer)
internal/provider/gemini-web/state.go+7−0
@@ -1030,3 +1030,10 @@ func FindReusableSessionIn(items map[string]ConversationRecord, index map[string · 1029 unmodified lines
10301030 }
10311031 return ConversationRecord{}, nil, 0, false
10321032 }
1033+
1034+// SetConfig updates the configuration reference used by the state.
1035+// This allows hot-reload of configuration to take effect for existing
1036+// runtime states that were cached on auth during previous requests.
1037+func (s *GeminiWebState) SetConfig(cfg *config.Config) {
1038+ s.cfg = cfg
1039+}
internal/runtime/executor/gemini_web_executor.go+4−0
@@ -168,6 +168,8 @@ func (e *GeminiWebExecutor) stateFor(auth *cliproxyauth.Auth) (*geminiwebapi.Gem · 167 unmodified lines
168168 return nil, fmt.Errorf("gemini-web executor: auth is nil")
169169 }
170170 if runtime, ok := auth.Runtime.(*geminiWebRuntime); ok && runtime != nil && runtime.state != nil {
171+ // Hot-reload: ensure cached state sees the latest config
172+ runtime.state.SetConfig(e.cfg)
171173 return runtime.state, nil
172174 }
173175
@@ -175,6 +177,8 @@ func (e *GeminiWebExecutor) stateFor(auth *cliproxyauth.Auth) (*geminiwebapi.Gem · 1 unmodified line
175177 defer e.mu.Unlock()
176178
177179 if runtime, ok := auth.Runtime.(*geminiWebRuntime); ok && runtime != nil && runtime.state != nil {
180+ // Hot-reload: ensure cached state sees the latest config
181+ runtime.state.SetConfig(e.cfg)
178182 return runtime.state, nil
179183 }
180184

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t