Skip to content

Latest commit

 

History

History
100 lines (74 loc) · 3.64 KB

File metadata and controls

100 lines (74 loc) · 3.64 KB

DepthOS Bridge v5.2.3 - API Endpoint Fix

Issue Summary

The extension was experiencing a "Self-Reading" loop where raw HTML from the extension's own index.html file was being displayed in the chat window instead of AI responses from OpenRouter.

Root Cause

A trailing space in the Authorization header (Bearer ${apiKey} instead of Bearer ${apiKey}) was causing API authentication to fail silently, potentially leading to fallback behavior that loaded local files.

Fixes Applied

1. Authorization Header Fix (Critical)

File: src/extension.ts (Line 366)

Before:

"Authorization": `Bearer ${apiKey} `,

After:

"Authorization": `Bearer ${apiKey}`,

Impact: Ensures proper API authentication with OpenRouter without trailing whitespace.

2. Documentation Enhancement

File: src/extension.ts (Lines 425-427)

Added clear documentation to the callModelAPI function:

// CRITICAL FIX v5.2.3: FORCE NETWORK CALL - DO NOT LOAD LOCAL FILES
// This prevents the "Self-Reading" loop where the extension would fetch its own index.html
private async callModelAPI(apiKey: string, model: string, prompt: string, roleInfo: string): Promise<any> {

Impact: Makes the intent explicit for future maintainers.

Verification Checklist

API Endpoint Verification

  • The callModelAPI function uses hardcoded URL: https://openrouter.ai/api/v1/chat/completions
  • No file path resolution or local resource loading
  • Returns structured object: { text: data.choices[0].message.content }

Safe Text Rendering

  • Webview uses textContent instead of innerHTML (Line 107 in src/webview/script.js)
  • HTML tags are stripped as fallback in orchestration logic (Line 285 in src/extension.ts)

Error Transparency

  • Clear error messages for API failures: OpenRouter Error (${response.status}): ${errorBody}
  • Network errors are caught and reported to the user

Testing Steps

  1. Test API Connectivity

    • Open the DepthOS Bridge panel
    • Navigate to SETTINGS tab
    • Click "🔍 Test Connectivity" button
    • Verify you see: "✅ DepthOS: OpenRouter connection successful!"
  2. Test Chat Functionality

    • Switch to CHAT tab
    • Click "Initialize Orchestration"
    • Send a test query (e.g., "Hello, can you hear me?")
    • Verify you receive a proper AI response, not HTML code
  3. Verify Logs

    • Open Output panel (View → Output)
    • Select "DepthOS Bridge" from dropdown
    • Look for successful API calls and responses

What Changed in the Build

  • Extension rebuilt: dist/extension.js (784.4kb)
  • Server rebuilt: dist/server.js (969.1kb)
  • Package created: depthos-bridge-5.0.0.vsix
  • Installation: Successfully installed in Antigravity

Next Steps

If you still see HTML in the chat after these fixes:

  1. Reload the VS Code window: Cmd+Shift+P → "Developer: Reload Window"
  2. Check API Key: Ensure your OpenRouter API key is valid and has credits
  3. Review Output Logs: Check for specific error messages in the DepthOS Bridge output channel
  4. Test with Simple Query: Try a basic prompt like "What is 2+2?" to isolate the issue

Technical Notes

Why the Trailing Space Mattered

HTTP Authorization headers are sensitive to exact formatting. The trailing space could cause:

  • API key validation failures
  • Silent fallbacks to error handling paths
  • Potential confusion in request routing

The Network-First Approach

By hardcoding the OpenRouter URL and explicitly structuring the response, we ensure:

  • No ambiguity in endpoint resolution
  • No chance of local file path confusion
  • Consistent error handling and reporting