Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- feature: 52 shinkai roadmap internal #94

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading