Commit Graph

56 Commits

Author SHA1 Message Date
王性驊 f9a92b0bfa add refactor doc 2026-04-06 22:21:32 +08:00
王性驊 3dc49bfc7d fix: remove duplicate Verbose field and use raw JSON parsing for handlers
- Remove Verbose from Config struct (inherited from RestConf)
- Remove Verbose from yaml config to fix conflict
- Use raw JSON parsing in handlers for interface{} Content field
- Fix config tests
2026-04-04 12:49:32 +08:00
王性驊 9e2a10b614 feat: complete implementation of all endpoints and config
- Update etc/chat-api.yaml with all configuration options (no env vars)
- Add ToBridgeConfig method to Config for YAML-based config
- Implement complete AnthropicMessages streaming with SSE
- Add Tools field to AnthropicRequest
- Update ServiceContext with model tracking
- Add all CRUD handlers for health, models, chat, anthropic

Features restored:
- Health check endpoint
- Models list with caching
- ChatCompletions streaming (OpenAI format)
- AnthropicMessages streaming (Anthropic format)
- Tool calls support for both formats
- Thinking/reasoning content support
- Rate limit detection and handling
- Account pool integration
- Request/response logging
- Model resolution with strict mode
- Workspace and prompt truncation handling
2026-04-03 23:17:04 +08:00
王性驊 3387887fb9 feat(logic): implement complete ChatCompletions streaming with SSE
- Full SSE streaming support with proper event format
- Tool calls handling with marker detection
- Rate limit detection and reporting
- Account pool integration (round-robin, stats tracking)
- Request/response logging and traffic tracking
- Thinking/reasoning content support
- Model resolution with strict mode
- Workspace and prompt truncation handling
- Added X-Accel-Buffering header for proper SSE
- Pass method/path for logging context
2026-04-03 23:04:28 +08:00
王性驊 f90d72b279 feat(logic): implement logic layer for health, models, and chat completions
- HealthLogic: simple health check response
- ModelsLogic: list Cursor CLI models with caching and Anthropic aliases
- ChatCompletionsLogic: scaffold for OpenAI-format completions (streaming placeholder)
- AnthropicMessagesLogic: scaffold for Anthropic format (TODO)
- Update handler for SSE streaming support
- Add models.go with ListCursorCliModels and model mappings
2026-04-03 23:00:18 +08:00
王性驊 081f404f77 Task 9: Cleanup - remove old internal files, update import paths, add go-zero entry point
- Removed old files from internal/* (migrated to pkg/*)
- Removed old CLI files from cmd/ (now in cmd/cli/)
- Updated import paths (internal/* -> pkg/*)
- Rewrote main.go to support CLI commands + go-zero HTTP server
- Fixed AccountStat type references (use entity.AccountStat)
- Fixed cmd/cli/* to use usecase package instead of agent
- Fixed logger to use entity.AccountStat
- Fixed geminiweb fmt.Println redundant newlines
- Fixed scripts/detect-gemini-dom.go pointer format issues
2026-04-03 22:54:18 +08:00
王性驊 7e0b7a970c refactor(task-7): integrate all layers and fix type mismatches
- Merge all branches (domain, infrastructure, repository, provider, adapter, usecase, cli)
- Update ServiceContext to inject dependencies
- Fix Message.Content type mismatch (string vs interface{})
- Update AccountStat to use entity.AccountStat
- Add helper functions for content conversion
2026-04-03 17:49:11 +08:00
王性驊 8f1b7159ed merge: refactor/cli 2026-04-03 17:46:37 +08:00
王性驊 e379c79bd1 merge: refactor/usecase 2026-04-03 17:46:37 +08:00
王性驊 ef4b6519f5 merge: refactor/adapter 2026-04-03 17:46:36 +08:00
王性驊 7b82986dca merge: refactor/provider 2026-04-03 17:46:33 +08:00
王性驊 e5f19c243b merge: refactor/repository 2026-04-03 17:46:32 +08:00
王性驊 83418d5e76 merge: refactor/infrastructure 2026-04-03 17:46:32 +08:00
王性驊 5866a5b9c9 refactor(task-5): add usecase layer
- Migrate agent runner from internal/agent
- Migrate sanitizer from internal/sanitize
- Migrate toolcall from internal/toolcall
- Update import paths to use pkg/usecase
2026-04-03 17:38:16 +08:00
王性驊 270accfd75 refactor(task-4): migrate providers to pkg/provider
- Migrate cursor provider
- Migrate geminiweb provider (playwright-based)
- Update import paths to use pkg/domain/entity
2026-04-03 17:35:23 +08:00
王性驊 f9f3c5fb42 refactor(task-6): migrate adapters to pkg/adapter
- Migrate OpenAI adapter
- Migrate Anthropic adapter
- Update import paths
2026-04-03 17:33:53 +08:00
王性驊 d4fcb8d3b8 refactor(task-3): add repository layer implementation
- Migrate AccountPool from internal/pool
- Update import paths to use pkg/repository
2026-04-03 17:33:51 +08:00
王性驊 3a005ea02e refactor(task-8): migrate CLI tools to cmd/cli
- Migrate args.go, login.go, accounts.go
- Migrate resethwid.go, usage.go, sqlite.go
2026-04-03 17:22:52 +08:00
王性驊 80d7a4bb29 refactor(task-2): migrate infrastructure layer
- Migrate process (runner, kill_unix, kill_windows)
- Migrate parser (stream)
- Migrate httputil (httputil)
- Migrate logger (logger)
- Migrate env (env)
- Migrate workspace (workspace)
- Migrate winlimit (winlimit)
2026-04-03 17:22:51 +08:00
王性驊 294bd74a43 refactor(task-1): add domain layer with entities and interfaces
- Add entity types: Message, Tool, ToolCall, Chunk, Account
- Add repository interfaces: AccountPool, Provider
- Add usecase interfaces: ChatUsecase, AgentRunner
- Add model constants and error definitions
2026-04-03 17:22:48 +08:00
王性驊 8b6abbbba7 refactor(task-0): initialize go-zero project structure
- Add go-zero dependency to go.mod
- Create api/chat.api with OpenAI-compatible types
- Create etc/chat.yaml configuration
- Update Makefile with goctl commands
- Generate go-zero scaffold (types, handlers, logic, svc)
- Move chat.go to cmd/chat/chat.go
- Add Config struct for go-zero (keep BridgeConfig for backward compatibility)
2026-04-03 17:15:35 +08:00
王性驊 b18e3d82f0 add refactor doc 2026-04-03 10:17:17 +08:00
王性驊 85f695250e Merge pull request 'feature/gemini-web-provider' (#1) from feature/gemini-web-provider into master
Reviewed-on: #1
2026-04-02 18:36:48 +00:00
王性驊 4b87efd02b rm bin 2026-04-03 02:36:21 +08:00
王性驊 4517b07f33 feat: Implement Gemini Web provider with model selection
- Fix handler to use PlaywrightProvider instead of old Provider
- Add model selection for Gemini Web (fast/thinking/pro)
- Improve response extraction to remove 'Gemini said' prefix
- Add progress logging for headless mode
- Fix navigation to use Domcontentloaded instead of Networkidle
- Add proper input field selectors (.ql-editor)
- Improve response completion detection with stability check
2026-04-03 02:28:47 +08:00
王性驊 3fec6e55eb fix: Always save diagnostics on any error
- Add saveDiagnostics method
- Use defer in Generate to catch all errors
- Simplify typeInput error handling
- Automatic screenshot and HTML dump on failure
2026-04-03 01:40:33 +08:00
王性驊 e245558f3d fix: Remove duplicate code and fix Evaluate error 2026-04-03 01:36:22 +08:00
王性驊 bef521504e feat: Add debug mode with screenshot and page analysis
Features:
- Wait for user ENTER in visible mode (GEMINI_BROWSER_VISIBLE=true)
- Save screenshot to /tmp/gemini-debug.png
- Save HTML to /tmp/gemini-debug.html
- JavaScript-based element detection
- Multi-strategy wait (A: selectors, B: time, C: JS, D: debug)
- Detailed logging of each strategy attempt
- Page structure dump in debug mode

This helps identify why input field is not found
2026-04-03 01:31:37 +08:00
王性驊 104e55d613 fix: Add proper page ready check before finding input
Key improvements:
- Wait for page to fully load (SPA needs time)
- Wait for input field to be visible before typing
- Check login status only after page is ready
- Add fallback wait (3 seconds) if first attempt fails
- Properly handle error messages

Based on project-golem's PageInteractor.waitForReady()
2026-04-03 01:26:43 +08:00
王性驊 3d5f2d91c0 feat: Switch to playwright-go for better DOM automation
Major refactor using Playwright (pure Go):
- Add playwright-go dependency (v0.5700.1)
- Create PlaywrightProvider with auto-wait for elements
- Use LaunchPersistentContext for session persistence
- Implement Locator-based element finding (auto-wait)
- Fill input using Playwright's built-in methods
- Add fallback selectors for input fields
- Better error messages with page URL and title

Key improvements over Rod:
- Auto-wait for elements (solves 'input field not found')
- More mature browser automation library
- Better documentation and examples
- Based on project-golem's proven strategies

Installation:
- Playwright driver and Chromium downloaded to ~/Library/Caches/ms-playwright/
- ~160MB download (one-time setup)
2026-04-03 01:20:42 +08:00
王性驊 17b001d8c2 fix: Add debug output and fallback selectors for input field detection 2026-04-03 01:11:02 +08:00
王性驊 32673c028e refactor: Complete rewrite of GeminiWeb provider
Based on project-golem implementation:

Phase 1: Browser Persistence
- Add BrowserManager singleton to manage browser lifecycle
- Use launchPersistentContext with UserDataDir
- Auto-save cookies and session state
- Clean Chrome lock files on startup
- Single browser instance reused across requests

Phase 2: Improved DOM Interaction
- Use correct input selectors (ProseMirror first)
- Implement 'Physical Enter' send method
- Trigger input/change/keyup events properly
- Check for 'Stop' button to detect busy state

Phase 3: Session Management
- No manual cookie saving/loading needed
- Session pool just manages userDataDir paths
- Default session directory structure

Breaking changes:
- Remove manual cookie management
- Browser stays open between requests
- Simpler session management
2026-04-03 01:05:54 +08:00
王性驊 24459ffcfe fix: Don't wait for user input during login flow
- Remove blocking 'Press Enter' prompt
- Continue without waiting when no session exists
- Save cookies asynchronously if user logs in during session
- Add debug output for finding input field and send button
- Try Enter key as fallback for sending message
2026-04-03 00:51:55 +08:00
王性驊 9f41d3b5b5 feat: Allow using Gemini Web without login
- Remove requirement to login before using Gemini Web
- If logged in (cookies exist), use the account
- If not logged in, continue without login (browser opens)
- When browser is visible, prompt user they can login or continue without
- Save cookies only if user actually logs in
2026-04-03 00:45:59 +08:00
王性驊 69df57555d fix: Improve Gemini Web DOM selectors and add debug output
- Make model selector optional (skip if not found, use current model)
- Add multiple fallback selectors for input field and send button
- Add debug logging to trace execution flow
- Improve error messages to suggest running gemini-login
2026-04-03 00:40:57 +08:00
王性驊 19985dd476 feat: Route chat completions to Gemini Web provider when configured
- Add HandleGeminiChatCompletions for Gemini Web provider requests
- Update router to route requests based on cfg.Provider
- Support both streaming and non-streaming modes for Gemini
- Map stream chunks to OpenAI-compatible SSE format
2026-04-03 00:36:48 +08:00
王性驊 f33353897c feat: Add provider display in startup logs and OpenCode gemini-web config
- Add provider name display in LogServerStart (cursor/gemini-web)
- Show gemini-dir and max-sess when using gemini-web provider
- Update Makefile to include gemini-web provider in opencode.json
- Update opencode-models to sync models for both cursor and gemini-web
- Add Gemini Web Provider examples in help text
2026-04-03 00:29:22 +08:00
王性驊 df22640d6a feat: Add Gemini provider env vars to Makefile and CLI options
- Add PROVIDER, GEMINI_ACCOUNT_DIR, GEMINI_BROWSER_VISIBLE, GEMINI_MAX_SESSIONS to Makefile
- Update gemini-login command to support --visible flag
- Add help text showing env vars and usage examples
- Display session save location and browser visibility on startup
2026-04-02 22:53:41 +08:00
王性驊 33a0e53709 feat: Add GeminiWeb provider foundation
- Add Provider interface and factory pattern
- Create apitypes package for shared types
- Implement GeminiWeb provider with:
  - Browser automation using Rod
  - Session pool management
  - Cookie persistence
  - DOM interaction for Gemini web interface
- Add gemini-login command for session setup
- Add CURSOR_BRIDGE_PROVIDER env variable

Remaining: Integration with chat.go handlers
2026-04-02 22:45:41 +08:00
王性驊 670c1b37c1 fix output 2026-04-02 21:54:28 +08:00
daniel a5d057f220 fix readme 2026-04-01 22:18:24 +08:00
daniel 18e1fc1dfc add ignore 2026-04-01 22:17:15 +08:00
daniel 38f74b1784 add ignore 2026-04-01 22:15:55 +08:00
daniel 42f85e4538 add ignore 2026-04-01 22:12:21 +08:00
daniel 018765f97d add ignore 2026-04-01 22:11:58 +08:00
王性驊 40970d32f5 Merge remote-tracking branch 'refs/remotes/origin/master' 2026-04-01 13:57:42 +00:00
王性驊 ebc1249e09 fix 2026-04-01 13:57:03 +00:00
daniel c7e71cb8c8 add docker build 2026-04-01 21:48:17 +08:00
王性驊 0844302460 add proxy 2026-04-01 13:47:16 +00:00
王性驊 10ac210f10 first commit 2026-04-01 21:36:55 +08:00