Commit graph

520 commits

Author SHA1 Message Date
539bd21fce Ignore research/tmp*.yaml generated files 2026-03-16 09:52:30 -04:00
d7fcfc8935 Clean up debug code, keep Send button
Root cause found: uncloseai extension was clobbering window.sendMessage.
Fixed in uncloseai.com repo by namespacing under window.uncloseai.
2026-02-23 19:55:55 -05:00
c06b3706f2 Debug send failure - self-contained handler with visible error output 2026-02-23 19:39:04 -05:00
844ed05cf0 Add Send button and inline keydown handler for chat
Belt-and-suspenders: inline onkeydown on textarea ensures Enter
works regardless of JS event listener registration order, plus
a visible Send button as clickable fallback.
2026-02-23 19:30:00 -05:00
c0ec5ded04 Fix socket.io connection for reverse proxy deployments
Replace deprecated document.domain + port construction with io()
which auto-connects to the serving host regardless of proxy setup.
2026-02-23 19:19:42 -05:00
timehexon
f963cd9443 Replace "AI" with "machine learning" in CLAUDE.md
Machine learning is what we grow. "AI" is forbidden in all
permacomputer discourse, marketing, & documentation.
2026-02-02 19:56:03 +00:00
47bf62ef66 Add streaming TTS using MediaSource API for instant playback
- Audio starts playing as soon as ~1KB arrives instead of waiting for full download
- Browser-aware format detection (webm+opus for Firefox, mp3 for Chrome)
- Falls back to buffered download if MediaSource not supported
- Updated speakText() and speakTextQueued() to use streaming
- Cache blobs instead of Audio objects for cleaner replay
2026-01-28 07:53:11 -05:00
c6e6e81c3c Fix artifact API - use correct parameter and field names
Correct the artifact implementation to match Unsandbox API:
- Request parameter: return_artifact (boolean, singular)
- Response field: artifacts (array, plural)
- Data field: content_base64 (not data/content)

Changes:
- Backend: Changed artifacts to return_artifact in request body
- Frontend: Use return_artifact in execute request
- Frontend: Look for artifacts array in response (not artifact singleton)
- Frontend: Decode content_base64 field (not data/content)
- Frontend: Use filename field (primary) over name
- Remove debug console.log statements
- Update CLAUDE.md with correct API contract

The API parameter is singular but response is plural - this is intentional
design by Unsandbox API. Request enables artifact collection, response
returns array of generated artifacts.
2026-01-20 09:07:25 -05:00
b53ee2168b modified: app.py 2026-01-20 08:58:19 -05:00
acee097d3b Add debug logging for artifact structure
Add console.log statements to see actual artifact object structure:
- Log artifacts array when received
- Log each artifact object and its keys
- Log download attempt with artifact keys and data presence

This will help diagnose why artifacts show metadata but fail on download/view.
2026-01-20 08:50:29 -05:00
7a54952191 Fix artifact handling - use base64 from response payload
Artifacts are returned as base64-encoded data directly in the job response
payload, not as URLs. Previous implementation incorrectly tried to fetch
artifacts from URLs via a proxy endpoint.

Changes:
- Remove /api/code/artifacts proxy endpoint (not needed)
- Update downloadArtifact() to decode base64 and trigger download
- Update viewArtifact() to decode base64 and display inline:
  * Images: rendered as data URLs (data:image/png;base64,...)
  * Videos: decoded to blob URLs with controls
  * Text: decoded and displayed in <pre> blocks
- Update CLAUDE.md with correct artifact format and implementation details
- Add artifact response format example showing base64 data structure

Artifact format in response:
{
  "artifacts": [{
    "name": "output.png",
    "type": "image/png",
    "data": "base64string...",
    "size": 12345
  }]
}
2026-01-20 08:38:37 -05:00
5576179ffa Add comprehensive artifact support for code execution
Implement full artifact support for Unsandbox code execution, enabling
download and inline viewing of generated files (binaries, images, videos).

Backend changes (app.py):
- Update /api/code/execute to accept artifacts parameter
- Add /api/code/artifacts/<path> proxy endpoint for authenticated downloads
- Use SDK's _make_request for full parameter support
- Support artifacts in execution request body

Frontend changes (templates/chat.html):
- Pass artifacts=true in all code execution requests
- Display artifacts section with file info (name, type, size)
- Add download button for all artifact types
- Add view button with inline display for images/videos (disabled for binaries)
- Implement formatFileSize, downloadArtifact, viewArtifact helper functions
- Images and videos render directly in chat
- Text files display in formatted <pre> blocks

Documentation (CLAUDE.md):
- Document artifact support section
- List supported artifact types
- Describe frontend and backend features
- Update frontend integration notes

Artifact types supported:
- Compiled binaries (executables from C, C++, Rust, Go, etc.)
- Images (PNG, JPG, GIF, SVG)
- Videos (MP4, WebM)
- Text/data files (JSON, CSV, TXT)
2026-01-20 08:34:35 -05:00
27a0df3d12 Migrate to official Unsandbox Python SDK
Replace manual HMAC authentication with official Unsandbox Python SDK (un.py).
Simplifies code execution proxy endpoints by using SDK methods: execute_async,
get_job, and cancel_job. Removes ~40 lines of manual HTTP/auth code.

Changes:
- Add official Unsandbox Python SDK (un.py)
- Refactor app.py proxy endpoints to use SDK methods
- Update CLAUDE.md documentation with SDK setup and usage
- Remove manual HMAC signing code
- Maintain backward compatibility with existing API endpoints
2026-01-20 08:21:58 -05:00
a825633be5 Add MODEL_ENDPOINT_0 to functional tests in GitHub Actions 2026-01-11 11:56:08 -05:00
ae875a7269 Exclude venv from flake8 and black in GitHub Actions 2026-01-11 11:55:41 -05:00
237888a6ab Exclude venv from flake8 and black in CI 2026-01-11 11:52:40 -05:00
532523e1b3 Remove GIT_CLEAN_FLAGS 2026-01-11 09:39:14 -05:00
8a77b395a9 Add GIT_CLEAN_FLAGS to clean venvs between CI runs 2026-01-11 09:38:26 -05:00
69703b1e82 Fix test_initialize_model_map_with_env_vars: clear CI env vars 2026-01-11 09:18:55 -05:00
cf63e5c6cd Fix tiktoken mock: use class not instance, remove TESTING check 2026-01-11 09:17:49 -05:00
9fb7047866 Fix tiktoken SSL/gevent conflict in tests: use fallback token counting 2026-01-11 08:42:51 -05:00
4cc7e61c8b Fix GitLab CI for shell executor: use python3 and venv 2026-01-11 08:32:35 -05:00
6a4d9d560b Add GitLab CI pipeline for unit, integration, and functional tests 2026-01-11 07:53:58 -05:00
f5afedc5f7 Fix unturf capitalization to lowercase 2026-01-11 07:14:43 -05:00
ddf071161e Document git remote configuration with dual push targets 2026-01-11 07:14:12 -05:00
0d5d2c27be Switch Unsandbox API auth to HMAC-SHA256 with public/secret keys
Replace simple Bearer token auth with HMAC-SHA256 signature scheme:
- UNSANDBOX_PUBLIC_KEY for account identification (Bearer token)
- UNSANDBOX_SECRET_KEY for request signing (never transmitted)
- X-Timestamp header for replay attack prevention
- X-Signature header with HMAC-SHA256(secret, ts:method:path:body)
2025-12-28 13:44:38 -05:00
331c11e8f7 Only truncate large code blocks on page refresh, not during streaming 2025-12-15 11:31:43 -05:00
5329bccdec Add Open Graph and Twitter Card meta tags for social sharing
- Add helper functions to extract first image and generate description from chat messages
- Update base.html and index.html with og:image, og:description, twitter:card meta tags
- Chat rooms now use first image from messages for unfurling instead of site logo
- Description shows first 500 chars of room content for link previews
- Add default OG image (black with OC) as fallback when no image found
2025-12-15 08:17:01 -05:00
50404f62d9 Fix F824 lint error and add lint instructions to CLAUDE.md 2025-12-07 15:34:35 -05:00
6e279c0ed5 Use backend proxy for Unsandbox API calls to keep API key secure 2025-12-07 14:54:35 -05:00
8c128878c4 Fix is_base64_image() to detect all image formats, add debug logging
- is_base64_image() now detects any base64 image (jpeg, png, gif, webp, etc.)
  not just the hardcoded jpeg/png patterns
- Added [Vision] debug logging to trace image fetch/save flow
2025-12-07 13:58:47 -05:00
56800afae5 Fix SQL LIKE query for URLs with special characters (%, _)
URLs like eBay images contain % and _ which have special meaning in SQL
LIKE patterns. Added escape_like_pattern() helper to escape these chars.
This fixes saved base64 images not being found on refresh.
2025-12-07 13:51:40 -05:00
de5bdaaa68 Vision: send only most recent image, keep all text history
- Find the most recent image message
- Include full text conversation history for context
- Only send base64 for the most recent image
- Skip older images entirely (no useful text in them)
2025-12-07 11:44:56 -05:00
305375d9e6 Limit vision model to 2 most recent images to prevent slow/hanging requests
Multiple large base64 images can overwhelm the vision model. Now we:
1. First pass: identify the 2 most recent image messages
2. Second pass: build chat history, skipping older images
2025-12-07 11:42:53 -05:00
ff9d8011a6 Fix model/voice localStorage persistence on page refresh
Remove race condition where syncDropdownsAndQueryString() was called before
dropdowns were populated, causing empty values to overwrite localStorage.
Model and voice restoration now happens only in populateModelDropdown() and
populateVoiceDropdown() after async fetch completes.
2025-12-07 11:29:06 -05:00
38da58c33e Cache fetched external images to avoid re-fetching
- Add find_saved_base64_for_url() to lookup existing saved base64 in DB
- Check for existing saved version before fetching external images
- Prevent duplicate saves in save_fetched_image_as_message()
- Use in-memory cache for faster repeated lookups within same session
2025-12-07 11:18:01 -05:00
116fac4c90 Fix DetachedInstanceError: use room_name parameter instead of room.name
Replace room.name with room_name in chat_gpt, chat_claude, and chat_llama
functions to avoid accessing SQLAlchemy objects outside session context.
2025-12-07 10:59:13 -05:00
4714c2730a Fix streaming protocol tests for Message.query mocking and gevent conflicts
- Fix Message.query.filter_by() chain mocking in test_bedrock_streaming_protocol
  and test_streaming_protocol_backwards_compatibility
- Add is_gevent_patched() helper to detect monkey patching
- Skip bedrock test at runtime when gevent has already patched (avoids RecursionError)
2025-12-07 10:53:51 -05:00
da9ed50d38 Fix DetachedInstanceError: save room_id early, use room_name parameter 2025-12-07 10:22:57 -05:00
0d19e0b9ce Fix model selection persistence: populate both dropdowns, validate stored value 2025-12-07 10:17:43 -05:00
5928ad3d9d Save fetched external images as new messages in database
- save_fetched_image_as_message() creates a new message with base64 content
- build_message_content() now accepts room_id to persist fetched images
- Fetched images saved with username "system" (added to SYSTEM_USERS)
- Prevents re-fetching: once fetched, base64 version is in chat history
2025-12-07 09:01:01 -05:00
51de5991c4 Add server-side fetching of external images for vision model chat context
- extract_external_image_url() to find http/https URLs in img tags
- fetch_external_image_as_base64() fetches via CORS proxy, converts to base64
- build_message_content() now handles both base64 and external image URLs
- Caches fetched images to avoid re-fetching
- Uses cors-proxy.uncloseai.com for robots.txt compliance
2025-12-07 08:58:18 -05:00
589406d11d Fix CORS proxy URL to cors-proxy.uncloseai.com 2025-12-07 08:49:28 -05:00
19b8ce4037 Add external image URL support via CORS proxy
- Fetch external images through proxy.unturf.com (respects robots.txt)
- Convert fetched images to base64 for vision API
- Cache both fetched images and descriptions
- Shows "Fetching image..." for external URLs, "Generating description..." for base64
- Handles 403 responses when blocked by robots.txt
2025-12-07 08:47:36 -05:00
d9976ffe31 Fix image hover: use mouseover instead of mouseenter for event delegation 2025-12-07 08:39:58 -05:00
bd2dbf7ed5 Add vision model support with auto alt-text on image hover
Backend:
- Track VISION_MODELS list at startup from available endpoints
- Add is_vision_model() to detect vision-capable models (*-vl*, *vision*, gpt-4o)
- Add extract_base64_from_img_tag() and build_message_content() helpers
- Modify chat_gpt() to include base64 images for vision models
- Add GET /vision endpoint for vision availability status
- Add POST /vision/describe endpoint for image alt-text generation

Frontend:
- Check vision availability on page load via /vision
- Add hover event delegation on chat images
- On hover: call vision model, cache result, set img.title and img.alt
- Shows cursor:wait while loading description
2025-12-07 08:36:47 -05:00
030b1cc447 Use only stderr for code auto-fix error detection
Update code execution error detection to use stderr exclusively
instead of checking both stdout and stderr. This aligns with the
Unsandbox API's proper stream separation where:
- stdout is for program output
- stderr is for errors/warnings

Changes:
- Remove stdout from error detection logic
- Only trigger auto-fix when exit_code != 0 AND stderr is non-empty
- Send only stderr to /api/fix-code endpoint

This prevents false positives where stdout contains normal output
that was previously being treated as error content.
2025-12-01 11:49:33 -05:00
22ed72da7e Store auto-exec attempt on code block to avoid empty DOM elements
- Use codeBlock.dataset.autoExecAttempt to pass attempt number
- executeCodeBlock transfers attempt to results container
- No longer pre-creates empty results container
- Clean up data attribute after use
2025-11-30 15:17:27 -05:00
5c25229429 Fix classList check for non-element nodes
- Add null check for classList before calling contains()
- Handles case where nextSibling might be a text node
- Prevents 'classList is undefined' error
2025-11-30 14:56:04 -05:00
36e713147a Fix DOM insertion error in auto-exec results container
- Correctly insert results container after button container
- Use buttonContainer.parentNode.insertBefore() instead of preElement
- Add proper styling when creating results container
- Fixes 'Child to insert before is not a child of this node' error
2025-11-30 14:47:17 -05:00