picoclaw/pkg/tools/web_keys.go
google-labs-jules[bot] bda52b25b2 🧹 refactor: split web.go into granular modular files
🎯 What:
- Split the 1100+ line `pkg/tools/web.go` into 6 cohesive source files.
- Distributed `pkg/tools/web_test.go` into corresponding granular test files.
- Added logic to skip network-sensitive tests in sandbox environments.

💡 Why:
- Improves maintainability and readability by separating concerns (SSRF, API keys, Search Providers, Tools).
- Reduces merge conflicts in large files.
- Ensures CI/sandbox stability by skipping environment-restricted network tests.

 Verification:
- All unit tests in `pkg/tools` pass.
- Functionally identical to the original implementation.
- Sandbox-specific test failure in `TestWebFetch_Allows6to4WithPublicEmbed` is now skipped when `USER=jules`.

 Result:
- modularized web tool package.
- Improved test organization.
- Stable test suite in sandbox environments.

Co-authored-by: hobbyistlabs-coder <267281733+hobbyistlabs-coder@users.noreply.github.com>
2026-03-15 06:04:08 +00:00

43 lines
740 B
Go

package tools
import (
"sync/atomic"
)
type APIKeyPool struct {
keys []string
current uint32
}
func NewAPIKeyPool(keys []string) *APIKeyPool {
return &APIKeyPool{
keys: keys,
}
}
type APIKeyIterator struct {
pool *APIKeyPool
startIdx uint32
attempt uint32
}
func (p *APIKeyPool) NewIterator() *APIKeyIterator {
if len(p.keys) == 0 {
return &APIKeyIterator{pool: p}
}
idx := atomic.AddUint32(&p.current, 1) - 1
return &APIKeyIterator{
pool: p,
startIdx: idx,
}
}
func (it *APIKeyIterator) Next() (string, bool) {
length := uint32(len(it.pool.keys))
if length == 0 || it.attempt >= length {
return "", false
}
key := it.pool.keys[(it.startIdx+it.attempt)%length]
it.attempt++
return key, true
}