Skip to content

Commit 12292dc

Browse files
authored
Merge pull request #27 from SentienceAPI/fix_release2
Fix release2
2 parents 9fbd092 + 38a3e86 commit 12292dc

File tree

10 files changed

+1178
-7
lines changed

10 files changed

+1178
-7
lines changed

.github/workflows/sync-extension.yml

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,19 @@ jobs:
7575
jq -r '.assets[] | select(.name | endswith(".js") or endswith(".wasm") or endswith(".json") or endswith(".d.ts")) | "\(.browser_download_url)|\(.name)"' | \
7676
while IFS='|' read -r url name; do
7777
if [ -n "$url" ] && [ "$url" != "null" ] && [ -n "$name" ]; then
78-
# Handle asset names that might have paths like "pkg/sentience_core.js"
78+
# Handle asset names that might have paths like "pkg/sentience_core.js" or "extension-package/manifest.json"
7979
# GitHub releases might preserve directory structure in asset names
80-
# If name starts with "pkg/", we want to preserve that structure
81-
# If name is just a filename, put it at root
82-
if [[ "$name" == pkg/* ]]; then
80+
# Strip "extension-package/" prefix if present, as we'll handle it in copy step
81+
if [[ "$name" == extension-package/* ]]; then
82+
# Asset name is "extension-package/manifest.json" - strip prefix
83+
filename="${name#extension-package/}"
84+
dir=$(dirname "$filename")
85+
if [ "$dir" != "." ]; then
86+
mkdir -p "$dir"
87+
fi
88+
echo " Downloading $name -> $filename"
89+
curl -L -H "Authorization: token ${{ secrets.SENTIENCE_CHROME_TOKEN }}" "$url" -o "$filename"
90+
elif [[ "$name" == pkg/* ]]; then
8391
# Asset name is "pkg/sentience_core.js" - create pkg directory
8492
mkdir -p pkg
8593
filename=$(basename "$name")
@@ -103,6 +111,19 @@ jobs:
103111
echo ""
104112
echo "Directory structure:"
105113
ls -laR . | head -50
114+
echo ""
115+
echo "🔍 Verifying critical files:"
116+
if [ -f "manifest.json" ]; then
117+
echo "✅ manifest.json found ($(wc -c < manifest.json) bytes)"
118+
head -5 manifest.json
119+
else
120+
echo "❌ manifest.json NOT FOUND"
121+
fi
122+
if [ -d "pkg" ]; then
123+
echo "✅ pkg directory found with $(ls -1 pkg | wc -l) files"
124+
else
125+
echo "❌ pkg directory NOT FOUND"
126+
fi
106127
107128
- name: Copy extension files
108129
if: steps.release.outputs.skip != 'true'
@@ -113,11 +134,42 @@ jobs:
113134
# Copy extension files (handle both root and extension-package/ subdirectory)
114135
# Check root first, then extension-package/ subdirectory
115136
if [ -f "extension-temp/manifest.json" ]; then
116-
cp extension-temp/manifest.json sentience/extension/
137+
size=$(wc -c < extension-temp/manifest.json)
138+
if [ "$size" -gt 0 ]; then
139+
echo "✅ Copying manifest.json ($size bytes)"
140+
cp extension-temp/manifest.json sentience/extension/
141+
# Verify copy
142+
if [ -f "sentience/extension/manifest.json" ] && [ "$(wc -c < sentience/extension/manifest.json)" -gt 0 ]; then
143+
echo "✅ manifest.json copied successfully"
144+
else
145+
echo "❌ manifest.json copy failed or file is empty"
146+
exit 1
147+
fi
148+
else
149+
echo "❌ manifest.json is empty ($size bytes)"
150+
exit 1
151+
fi
117152
elif [ -f "extension-temp/extension-package/manifest.json" ]; then
118-
cp extension-temp/extension-package/manifest.json sentience/extension/
153+
size=$(wc -c < extension-temp/extension-package/manifest.json)
154+
if [ "$size" -gt 0 ]; then
155+
echo "✅ Copying manifest.json from extension-package/ ($size bytes)"
156+
cp extension-temp/extension-package/manifest.json sentience/extension/
157+
# Verify copy
158+
if [ -f "sentience/extension/manifest.json" ] && [ "$(wc -c < sentience/extension/manifest.json)" -gt 0 ]; then
159+
echo "✅ manifest.json copied successfully"
160+
else
161+
echo "❌ manifest.json copy failed or file is empty"
162+
exit 1
163+
fi
164+
else
165+
echo "❌ manifest.json is empty ($size bytes)"
166+
exit 1
167+
fi
119168
else
120-
echo "⚠️ manifest.json not found"
169+
echo "❌ manifest.json not found in extension-temp/"
170+
echo "Available files:"
171+
find extension-temp -type f | head -20
172+
exit 1
121173
fi
122174
123175
if [ -f "extension-temp/content.js" ]; then

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
pip install -e ".[dev]"
3535
3636
- name: Build extension (if needed)
37+
if: runner.os != 'Windows'
38+
shell: bash
3739
run: |
3840
if [ -d "../sentience-chrome" ]; then
3941
cd ../sentience-chrome && ./build.sh || echo "Extension build skipped (may not be available in CI)"

sentience/extension/background.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// background.js - Service Worker for screenshot capture
2+
// Chrome extensions can only capture screenshots from the background script
3+
// Listen for screenshot requests from content script
4+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
5+
if (request.action === 'captureScreenshot') {
6+
handleScreenshotCapture(sender.tab.id, request.options)
7+
.then(screenshot => {
8+
sendResponse({ success: true, screenshot });
9+
})
10+
.catch(error => {
11+
console.error('[Sentience] Screenshot capture failed:', error);
12+
sendResponse({
13+
success: false,
14+
error: error.message || 'Screenshot capture failed'
15+
});
16+
});
17+
18+
// Return true to indicate we'll send response asynchronously
19+
return true;
20+
}
21+
});
22+
23+
/**
24+
* Capture screenshot of the active tab
25+
* @param {number} tabId - Tab ID to capture
26+
* @param {Object} options - Screenshot options
27+
* @returns {Promise<string>} Base64-encoded PNG data URL
28+
*/
29+
async function handleScreenshotCapture(tabId, options = {}) {
30+
try {
31+
const {
32+
format = 'png', // 'png' or 'jpeg'
33+
quality = 90 // JPEG quality (0-100), ignored for PNG
34+
} = options;
35+
36+
// Capture visible tab as data URL
37+
const dataUrl = await chrome.tabs.captureVisibleTab(null, {
38+
format: format,
39+
quality: quality
40+
});
41+
42+
console.log(`[Sentience] Screenshot captured: ${format}, size: ${dataUrl.length} bytes`);
43+
44+
return dataUrl;
45+
} catch (error) {
46+
console.error('[Sentience] Screenshot error:', error);
47+
throw new Error(`Failed to capture screenshot: ${error.message}`);
48+
}
49+
}
50+
51+
/**
52+
* Optional: Add viewport-specific capture (requires additional setup)
53+
* This would allow capturing specific regions, not just visible area
54+
*/
55+
async function captureRegion(tabId, region) {
56+
// For region capture, you'd need to:
57+
// 1. Capture full visible tab
58+
// 2. Use Canvas API to crop to region
59+
// 3. Return cropped image
60+
61+
// Not implemented in this basic version
62+
throw new Error('Region capture not yet implemented');
63+
}

sentience/extension/content.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// content.js - ISOLATED WORLD
2+
console.log('[Sentience] Bridge loaded.');
3+
4+
// 1. Pass Extension ID to Main World (So WASM knows where to load from)
5+
document.documentElement.dataset.sentienceExtensionId = chrome.runtime.id;
6+
7+
// 2. Proxy for Screenshots (The only thing Isolated World needs to do)
8+
window.addEventListener('message', (event) => {
9+
// Security check: only accept messages from same window
10+
if (event.source !== window || event.data.type !== 'SENTIENCE_SCREENSHOT_REQUEST') return;
11+
12+
chrome.runtime.sendMessage(
13+
{ action: 'captureScreenshot', options: event.data.options },
14+
(response) => {
15+
window.postMessage({
16+
type: 'SENTIENCE_SCREENSHOT_RESULT',
17+
requestId: event.data.requestId,
18+
screenshot: response?.success ? response.screenshot : null
19+
}, '*');
20+
}
21+
);
22+
});

0 commit comments

Comments
 (0)