Skip to content

Commit

Permalink
- feature: 52 shinkai roadmap internal (#94)
Browse files Browse the repository at this point in the history
* - feature: replace pdf with html in send page to agent feature

* - fix: removed unused file
  • Loading branch information
agallardol authored Nov 28, 2023
1 parent a72c74b commit 36173a5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 52 deletions.
11 changes: 0 additions & 11 deletions apps/shinkai-visor/src/components/popup/popup-embeder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { generatePdfFromCurrentPage } from '../../helpers/pdf-generator';
import { srcUrlResolver } from '../../helpers/src-url-resolver';
import { sendContentScriptMessage } from '../../service-worker/communication/internal';
import {
Expand Down Expand Up @@ -66,16 +65,6 @@ chrome.runtime.onMessage.addListener(async (message: ServiceWorkerInternalMessag
baseContainer.style.pointerEvents = isVisible ? 'auto' : 'none';
}
break;
case ServiceWorkerInternalMessageType.SendPageToAgent: {
const pageAsPdf = await generatePdfFromCurrentPage(message.data.filename, document.body);
if (pageAsPdf) {
message.data = {
...message.data,
pdf: pageAsPdf,
}
}
break;
}
default:
break;
}
Expand Down
34 changes: 0 additions & 34 deletions apps/shinkai-visor/src/helpers/pdf-generator.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export const useGlobalPopupChromeMessage = () => {
sendContentScriptMessage({ type: ContentScriptBridgeMessageType.TogglePopupVisibility, data: true });
break;
}
case ServiceWorkerInternalMessageType.SendPageToAgent:
history.push({ pathname: '/inboxes/create-job', state: { files: [message.data.pdf] } });
case ServiceWorkerInternalMessageType.SendPageToAgent: {
const file = dataUrlToFile(message.data.fileDataUrl, message.data.filename);
history.push({ pathname: '/inboxes/create-job', state: { files: [file] } });
sendContentScriptMessage({ type: ContentScriptBridgeMessageType.TogglePopupVisibility, data: true });
break;
}
case ServiceWorkerInternalMessageType.SendCaptureToAgent: {
const imageFile = dataUrlToFile(message.data.image, message.data.filename);
const imageFile = dataUrlToFile(message.data.imageDataUrl, message.data.filename);
history.push({ pathname: '/inboxes/create-job', state: { files: [imageFile] } });
sendContentScriptMessage({ type: ContentScriptBridgeMessageType.TogglePopupVisibility, data: true });
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export type ServiceWorkerInternalMessage =
| {
type: ServiceWorkerInternalMessageType.SendPageToAgent;
data: {
pdf?: File;
filename: string;
fileDataUrl: string;
fileType: string;
}
}
| { type: ServiceWorkerInternalMessageType.RehydrateStore, data?: never }
| { type: ServiceWorkerInternalMessageType.CopyToClipboard, data: { content: string } }
| { type: ServiceWorkerInternalMessageType.CaptureImage, data: { image: string } }
| { type: ServiceWorkerInternalMessageType.SendCaptureToAgent, data: { image: string, filename: string } };
| { type: ServiceWorkerInternalMessageType.SendCaptureToAgent, data: { imageDataUrl: string, filename: string } };
;
16 changes: 14 additions & 2 deletions apps/shinkai-visor/src/service-worker/context-menu.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Buffer } from 'buffer';

import { ServiceWorkerInternalMessage, ServiceWorkerInternalMessageType } from "./communication/internal/types";

enum ContextMenu {
Expand All @@ -11,10 +13,20 @@ const sendPageToAgent = async (info: chrome.contextMenus.OnClickData, tab: chrom
if (!tab?.id) {
return;
}
const [htmlContent] = await chrome.scripting.executeScript({
target: { tabId: tab?.id },
func: () => {
return document.documentElement.outerHTML;
},
args: [],
});
const fileType = 'text/html';
const message: ServiceWorkerInternalMessage = {
type: ServiceWorkerInternalMessageType.SendPageToAgent,
data: {
filename: `${encodeURIComponent(tab.url || Date.now())}.pdf`
filename: `${encodeURIComponent(tab.url || Date.now())}.html`,
fileType: fileType,
fileDataUrl: `data:${fileType};base64,${Buffer.from(htmlContent.result).toString('base64')}`,
},
};
chrome.tabs.sendMessage<ServiceWorkerInternalMessage>(tab.id, message);
Expand Down Expand Up @@ -53,7 +65,7 @@ const sendCaptureToAgent = async (info: chrome.contextMenus.OnClickData, tab: ch
console.log('cropped image', croppedImage);
message = {
type: ServiceWorkerInternalMessageType.SendCaptureToAgent,
data: { image: croppedImage, filename: `${encodeURIComponent(tab.url || 'capture')}.jpeg` },
data: { imageDataUrl: croppedImage, filename: `${encodeURIComponent(tab.url || 'capture')}.jpeg` },
};
chrome.tabs.sendMessage<ServiceWorkerInternalMessage>(tab.id, message);
}
Expand Down

0 comments on commit 36173a5

Please sign in to comment.