Commit Graph

78 Commits

Author SHA1 Message Date
southseact-3d
237f10d6ef fix: remove Model ID field from public models in admin
Public models are now display-only and don't require a Model ID:
- Removed Model ID input field from admin.html public models section
- Updated admin.js to not require or send Model ID for public models
- Updated server API to accept public models without Model ID
  - Uses display label as the identifier for public models
  - Only requires Model ID for OpenCode models (which need it for execution)

Public models are purely for user-facing display in the builder dropdown,
while OpenCode models form the actual execution fallback chain.
2026-02-19 14:56:02 +00:00
southseact-3d
5627f7d758 fix: opencode model fallback chain improvements
- Never use public model ID in opencode fallback chain
  The opencode model selection is now independent of public models,
  always using the opencodeModels array in order for fallback chain.

- Add zero output detection to trigger fallback
  When a model returns empty output, it now triggers fallback to the
  next model in the chain instead of returning empty results.

Fixes issues where:
1. Generic 'opencode' model ID from public models caused failures
2. Empty responses didn't trigger fallback to backup models
2026-02-19 14:13:02 +00:00
southseact-3d
f5fee2ac4d Remove freePlanModel and opencodeBackupModel settings
Users now use OpenCode Models (Fallback Chain) for model selection.
- Removed Auto Model for Hobby/Free Plan section from admin panel
- Removed OpenCode Ultimate Backup Model section from admin panel
- Updated server to use opencodeModels for free plan users
- Removed backup model fallback logic (opencodeModels chain handles this)
2026-02-19 13:25:54 +00:00
southseact-3d
d3205dafe5 Separate OpenCode and Public model management in admin panel
- Add OpenCode Models section with dropdown selection from available models
- Add Public Models section with manual model ID input
- Both sections have up/down ordering buttons for fallback chain priority
- OpenCode models used for execution fallback when rate limits/errors occur
- Public models displayed in builder dropdown for user selection
- Remove unified provider chain in favor of two separate lists
- Keep all existing functionality: Auto Model, Provider Limits, Icon Library, etc.
2026-02-18 19:49:46 +00:00
southseact-3d
81ff352966 feat: Add Kilo Gateway as AI provider
Add full support for Kilo Gateway AI provider across the codebase:

- Add custom loader for 'kilo' provider in provider.ts with API key detection
- Add auth CLI hint for Kilo Gateway in auth.ts
- Add Kilo to DEFAULT_PROVIDER_SEEDS in chat server.js
- Add Kilo to PLANNING_PROVIDERS for planning chain support
- Add Kilo provider configuration with baseURL and API key support
- Update admin env config to show Kilo API key status

Kilo Gateway provides access to 500+ AI models through a single
OpenAI-compatible endpoint at https://api.kilo.ai/api/gateway
2026-02-18 16:22:34 +00:00
southseact-3d
828a9dad41 Remove separate chain concept - fallback is now determined by OpenCode models order
- Removed opencodeChain variable entirely
- Removed chain form/list from admin UI
- Fallback now uses the order of models in the OpenCode models list
- Updated buildOpencodeAttemptChain to iterate through opencodeModels
- Removed chain-related API endpoints
- Simplified to just two lists: opencodeModels and publicModels
2026-02-18 16:18:31 +00:00
southseact-3d
b961c6e302 Fix remaining providerChain references to opencodeChain 2026-02-18 15:23:36 +00:00
southseact-3d
3ba9fab6ab Clean up model structure: OpenCode Models, Chain, and Public Models
- Simplified to 3 clear sections:
  1. OpenCode Models: OpenCode dropdown + display name + order buttons
  2. OpenCode Chain: Fallback chain with add form + order buttons
  3. Public Models: Manual entry + order buttons (completely separate)
- New state variables: opencodeModels, opencodeChain, publicModels
- Clean API endpoints for chain operations
- Removed all confusing legacy code and naming
2026-02-18 15:11:12 +00:00
southseact-3d
cc17079988 Fix model sections: separate Provider Models and Public-Facing Models
- Provider Models section: restored OpenCode integration with dropdown
- Public-Facing Models section: completely separate manual entry
- Provider Chain section: fallback chain with up/down buttons (unchanged)
- Added separate arrays: providerModels and publicModels
- Added reorder support for both provider and public models
- Updated server to handle providerModel type and reorder by type
2026-02-18 14:38:19 +00:00
southseact-3d
7e5dc8b62d Add up/down reorder buttons and order numbers to public models
- Add order number badge (#1, #2, #3) to each public model
- Add up/down arrow buttons to reorder models in the list
- Add persistPublicModelsOrder function to save reordered list
- Add server-side /api/admin/models/reorder endpoint
- Remove automatic alphabetical sorting to preserve custom order
- First model (#1) gets green background highlighting
2026-02-18 14:08:21 +00:00
southseact-3d
0ce352ad8d feat(admin): Add token usage and remaining balance management options
Implements both Option A and B for admin token management:
- Option A (mode='remaining'): Set tokens remaining to use (calculates usage from limit)
- Option B (mode='usage'): Directly set tokens consumed
- Original mode='limit': Still sets token limit override

The admin UI now presents 3 modes via prompt dialog, and the API endpoint
handles each mode appropriately by updating the token usage bucket.
2026-02-18 10:40:10 +00:00
southseact-3d
44deabc2cf Add unified model chain system with public models and provider chain
- Add publicModels and providerChain data structures for unified fallback
- Add two separate model adding sections in admin panel (public-facing and provider models)
- Add up/down buttons to reorder provider chain order
- Update server to use unified chain for all model fallbacks
- Auto-migrate legacy data on first load
- Update admin.js to handle new model structure and forms
2026-02-18 10:37:01 +00:00
southseact-3d
d46515d49a fix: ignore body opencodeSessionId when session was reset
When session.opencodeSessionId is null (indicating the session was reset
due to corruption or undo failure), ignore any opencodeSessionId sent
in the request body. This prevents the client from reusing a corrupted
session that was previously reset on the server.
2026-02-17 19:43:42 +00:00
southseact-3d
227794d463 fix: handle undo failures gracefully by resetting session
When opencode undo command fails:
1. Reset the opencode session (both IDs set to null)
2. Still remove the message from history
3. Return success instead of error

This prevents corrupted sessions from blocking subsequent operations.
2026-02-17 19:24:12 +00:00
southseact-3d
86bd6ff332 fix: reset opencode session when undoing failed messages
When a message fails with zero output and error status, undoing it now
resets the opencode session to ensure the next message starts fresh.
This prevents corrupted session reuse that was causing subsequent failures.
2026-02-17 19:14:05 +00:00
southseact-3d
d4232d487d fix: skip opencode undo when message has zero output
Prevents error when undoing messages that produced no output.
Checks for reply, partialOutput, or done status before sending
/undo command to opencode.
2026-02-17 19:03:27 +00:00
southseact-3d
0e6d3eddb6 Fix: add missing getOpencodeSessionTokenUsage function to resolve redo button error 2026-02-17 18:44:30 +00:00
southseact-3d
0c954449d3 Fix Android app connectivity issues and add detailed logging
- Add CORS headers to backend server to allow mobile app requests
- Implement request timeout (10s) in capacitor-bridge.js to prevent hanging
- Add comprehensive logging throughout authentication flow
- Add detailed error reporting in initApp for better debugging
- Log all API requests with request IDs for traceability

This fixes the 'Loading Plugin Compass...' infinite loop issue caused by
missing CORS headers and unhandled network timeouts.
2026-02-17 10:20:11 +00:00
southseact-3d
49983fbc3c Build OpenCode from source in Docker and remove broken session token queries
- Dockerfile: Build OpenCode CLI from source during Docker build instead of downloading from GitHub releases
- Disabled GitHub Actions workflow that was failing to create releases
- Removed getOpencodeSessionTokenUsage function that tried non-existent CLI commands (session info/usage/show)
- Token tracking now relies on 3 layers: result extraction, streaming capture, and estimation
2026-02-16 16:38:22 +00:00
Developer
14f59c2f56 Fix builder plan message display and error handling
- Strip double stars (**) and double hashtags (##) from plan message displayContent in both client and server
- Fix server restart error replacing plan message by skipping error state for plan messages
- Fix rate limiting regex pattern to use proper global flag
2026-02-16 08:40:58 +00:00
southseact-3d
dafd3c796d Add admin token override feature for user accounts
- Add tokenOverride field to token usage bucket
- Create POST /api/admin/accounts/tokens endpoint for setting manual token limits
- Update admin accounts page to display token usage and override status
- Add 'Set Tokens' button to manually override user token limits for the month
- Override takes precedence over plan-based limits when set
2026-02-15 16:19:06 +00:00
Developer
cea30dc84c Fix admin test checkout email validation - ensure valid email format is sent to Dodo Payments 2026-02-14 21:36:55 +00:00
Developer
a6a5d8f7a0 Fix ReferenceError: handleAdminTopupOptions is not defined
- Added missing closing brace for handleTopupConfirm function
- Removed extra closing brace after handleAdminMe function
- Admin functions (handleAdminTopupOptions, handleAdminTopupCheckout, handleAdminTopupConfirm) were incorrectly nested inside handleTopupConfirm scope, making them inaccessible to the router
2026-02-14 20:38:22 +00:00
Developer
4fa0a1b737 Fix ReferenceError: handleAdminTopupOptions is not defined by removing unnecessary await 2026-02-13 19:43:11 +00:00
Developer
180990bea5 fix: standardize contact email to info@plugincompass.com and add await to topup handlers 2026-02-13 15:02:31 +00:00
southseact-3d
af30843f05 fix: add missing Map declarations (loginAttempts, adminLoginAttempts, apiRateLimit, csrfTokens)
Fixed ReferenceError: apiRateLimit is not defined that was causing
internal server errors on all pages. Added 4 missing Map variable
declarations that are used throughout the codebase for rate limiting
and CSRF protection.
2026-02-13 11:13:07 +00:00
southseact-3d
098e971151 Fix syntax error: remove orphan object definition after sendEmail function 2026-02-13 09:18:11 +00:00
southseact-3d
df3a8cdf43 mailpilot sending 2026-02-12 19:35:55 +00:00
southseact-3d
49747d08db fix: prevent duplicate Dodo customers and handle multiple subscriptions per email
Comprehensive fixes to prevent customer ID mismatches:

1. **Checkout creation now passes customer_id** (lines 13669, 13064, 13503):
   - All checkouts (subscription, topup, PAYG) now call ensureDodoCustomer() first
   - Pass existing customer_id to checkout body to prevent Dodo from creating duplicates
   - Added customerId to metadata for tracking

2. **Subscription confirmation validates customer consistency** (line 13843):
   - Logs warning when checkout returns different customer_id than stored
   - Tracks which customer_id was used in checkout metadata
   - Prevents silent customer ID overwrites

3. **ensureDodoCustomer handles multiple customers per email** (line 6774):
   - Logs warning when multiple customers found for same email
   - Checks ALL customers for active subscriptions
   - Selects customer with active subscriptions if multiple exist
   - Returns first customer only if no active subscriptions found

4. **Added missing return statements** (lines 12417, 12448):
   - Prevents double response errors after successful plan changes

This ensures that:
- New subscriptions use existing customers instead of creating duplicates
- Plan changes work correctly even with multiple subscriptions
- Customer ID mismatches are detected and logged
- The correct customer (one with active subscriptions) is always used
2026-02-12 12:06:49 +00:00
southseact-3d
d61fa3d621 fix: add return statements after successful plan changes to prevent double response
- Added return statement after successful paid-to-free cancellation (line 12417)
- Added return statement after successful paid-to-paid plan change (line 12448)
- Prevents 'Cannot write headers after they are sent' error
- Each plan change now returns immediately with the updated account data
2026-02-12 11:58:35 +00:00
southseact-3d
1e30e07ed5 fix: remove hardcoded subscription ID and rely on API queries
- Removed hardcoded subscription ID from code
- Rely on API queries to find subscriptions by customer or through fallback search
- Added proper logging to diagnose customer/subscription mismatches
2026-02-12 11:51:51 +00:00
southseact-3d
8e937a6ff4 debug: try fetching subscription directly by ID to check customer mismatch
- Add direct API call to fetch subscription sub_0NYKZRvba3g5KJfp8R5jp
- Log customer ID comparison to detect mismatches
- Update user record if subscription belongs to different customer
- This will help identify if duplicate customers exist in Dodo
2026-02-12 11:50:14 +00:00
southseact-3d
2268a0e649 debug: log full API response to diagnose empty subscription results 2026-02-12 11:48:58 +00:00
southseact-3d
001993d0bc fix: query all subscriptions without status filter for customers with multiple subs
- Query ALL subscriptions for customer without status filter first
- This handles customers with multiple subscriptions across different statuses
- Returns first active subscription found, or most recent if none active
- Added detailed logging to show all subscription IDs and statuses found
- Fallback to check individual statuses including cancelled/expired
2026-02-12 11:45:53 +00:00
southseact-3d
2a603549f4 debug: add detailed logging for customer and subscription lookup
Add comprehensive DEBUG logs to trace through:
- Customer lookup by email (request and response details)
- Subscription lookup by customer ID (for each status)
- Entry point when plan change is initiated

This will help identify exactly where the lookup is failing.
2026-02-12 11:36:52 +00:00
southseact-3d
d82dcfd5e4 fix: improve customer lookup to prevent duplicate customers in Dodo
- Modified ensureDodoCustomer() to query existing customers by email before creating new ones
- This prevents duplicate customer records when dodoCustomerId is missing from database
- Added logging for both found existing customers and new customer creation
- Updated subscription lookup to check multiple statuses (active, pending, on_hold)
- Should resolve paid-to-paid and paid-to-free plan change issues for users missing subscription IDs
2026-02-12 11:30:52 +00:00
southseact-3d
ae871df0a0 fix: resolve subscription ID lookup and checkout URL issues
- Fix getBaseUrl() ReferenceError by changing to resolveBaseUrl(req) for free-to-paid upgrades
- Add subscription lookup by customer email when dodoSubscriptionId is missing
- Log critical issues when paid users have no subscription ID in database or Dodo
- Return clear error message to contact support when subscription cannot be found
- Prevent silent failures in plan changes from settings page
2026-02-12 11:09:45 +00:00
southseact-3d
e2abb2ee98 fix 2 2026-02-11 20:16:01 +00:00
southseact-3d
0513000a9e Fix builder page layout: make new chat and history buttons sticky at top on desktop
- Moved sticky positioning from mobile-only to global CSS for .top-left-actions

- Buttons now stay fixed at top above content on all screen sizes

- Includes various other app updates (version management, server improvements)
2026-02-11 19:23:23 +00:00
southseact-3d
5d91c86f90 Add Cohere as a provider for build messages in admin panel
- Add 'cohere' to DEFAULT_PROVIDERS and PLANNING_PROVIDERS arrays in admin.js
- Add Cohere option to provider limits dropdown in admin.html
- Add 'cohere' to DEFAULT_PROVIDER_SEEDS, PLANNING_PROVIDERS, and KNOWN_USAGE_PROVIDERS in server.js

Cohere was already integrated in the opencode backend (SDK installed, provider registered, icons defined). These changes make it available in the admin panel for build message configuration.
2026-02-11 13:25:16 +00:00
southseact-3d
71c1677932 chore: remove excessive debug logging from ensureOpencodeConfig 2026-02-11 12:03:16 +00:00
southseact-3d
d2640eee5d fix: extract provider from model name (e.g., chutes/model-name)
- Parse model names like 'chutes/deepseek-ai/DeepSeek-V3.2-TEE'
- Extract provider prefix before '/' to detect chutes, cerebras, etc.
- This fixes provider detection when admin panel sets wrong provider
2026-02-11 11:49:43 +00:00
southseact-3d
f1fb336f4d debug: log all models and filter for chutes models 2026-02-11 11:44:48 +00:00
southseact-3d
b85cc73a4d fix: handle both string and object formats in providers array
- Support providers as array of strings: [opencode, chutes]
- Support providers as array of objects: [{provider: opencode}]
- This fixes provider detection for Chutes and other providers
2026-02-11 11:41:22 +00:00
southseact-3d
bddc710a90 debug: add detailed logging for adminModels and provider detection
- Log adminModels count and sample data
- Log CHUTES_API_KEY status and prefix
- Log detected providers from adminModels
2026-02-11 11:37:06 +00:00
southseact-3d
3ec9177082 fix: load adminModels before sessions in bootstrap sequence
- Move loadAdminModelStore() before loadState() in bootstrap()
- This ensures adminModels is available when ensureOpencodeConfig is called
- Fixes issue where Chutes provider was not being configured
2026-02-11 11:27:43 +00:00
southseact-3d
18d9e18978 debug: add detailed logging for Chutes API calls
- Log API key prefix to verify key is loaded
- Log full error response from Chutes API
- Log success count when models are fetched
2026-02-11 11:20:04 +00:00
southseact-3d
49092c3229 fix: ensure adminModels is loaded before checking providers in ensureOpencodeConfig
- Add check to load adminModels if not already loaded
- Add error handling for models.dev fetch failures
- Log provider source (models.dev vs built-in) for debugging
2026-02-11 11:18:56 +00:00
southseact-3d
17792d39a0 feat: dynamic provider model loading from models.dev
- Add fetchModelsDevProviderModels() function with 1-hour caching
- Update ensureOpencodeConfig() to dynamically load all models for configured providers
- Support Chutes, Cerebras, Groq, Google, and Nvidia providers
- Only fetch models for providers actually used in adminModels
- Cache models.dev data to reduce API calls and improve performance

This allows any model from models.dev to work when added in the admin panel,
instead of requiring hardcoded model definitions.
2026-02-11 10:53:37 +00:00
southseact-3d
d0105ff967 fix: add DeepSeek V3.2 TEE model to Chutes provider config with baseURL 2026-02-11 10:44:48 +00:00