Skip to content

Commit

Permalink
refactor(eclipse): update tabby-chat-panel api to 0.4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes committed Dec 18, 2024
1 parent d4002be commit 368125a
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 234 deletions.
1 change: 1 addition & 0 deletions clients/eclipse/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
node_modules
plugin/tabby-agent
plugin/chat-panel/create-thread-from-iframe.js
4 changes: 2 additions & 2 deletions clients/eclipse/feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="com.tabbyml.features.tabby4eclipse"
label="Tabby"
version="0.0.2.29"
version="0.0.2.30"
provider-name="com.tabbyml">

<description url="http://www.example.com/description">
Expand All @@ -19,6 +19,6 @@

<plugin
id="com.tabbyml.tabby4eclipse"
version="0.0.2.29"/>
version="0.0.2.30"/>

</feature>
3 changes: 2 additions & 1 deletion clients/eclipse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "tabby4eclipse",
"private": true,
"scripts": {
"build": "node scripts/copy-tabby-agent.js"
"build": "node scripts/copy-dependencies.js"
},
"devDependencies": {
"tabby-agent": "workspace:*",
"tabby-threads": "workspace:*",
"fs-extra": "^11.1.1"
}
}
2 changes: 1 addition & 1 deletion clients/eclipse/plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tabby Plugin for Eclipse
Bundle-SymbolicName: com.tabbyml.tabby4eclipse;singleton:=true
Bundle-Version: 0.0.2.29
Bundle-Version: 0.0.2.30
Bundle-Activator: com.tabbyml.tabby4eclipse.Activator
Bundle-Vendor: com.tabbyml
Require-Bundle: org.eclipse.ui,
Expand Down
44 changes: 1 addition & 43 deletions clients/eclipse/plugin/chat-panel/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ <h4>Welcome to Tabby Chat</h4>
</div>
</div>
<iframe id="chat" style="display: none;"></iframe>
<script src="create-thread-from-iframe.js"></script>
<script>
function getChatPanel() {
return document.getElementById("chat");
Expand Down Expand Up @@ -91,26 +92,6 @@ <h4>Welcome to Tabby Chat</h4>
document.documentElement.style.cssText = css;
}

function sendRequestToChatPanel(request) {
const chat = getChatPanel();
// client to server requests
const { method, params } = JSON.parse(request);
if (method) {
// adapter for @quilted/threads requests
const data = [
0, // kind: Request
[uuid(), method, params],
]
chat.contentWindow.postMessage(data, new URL(chat.src).origin);
}
}

function uuid() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
}

window.addEventListener("focus", (event) => {
const chat = getChatPanel();
if (chat.style.cssText == "display: block;") {
Expand All @@ -119,29 +100,6 @@ <h4>Welcome to Tabby Chat</h4>
}, 1);
}
});

window.addEventListener("message", (event) => {
const chat = getChatPanel();

// server to client requests
if (event.source === chat.contentWindow) {
// adapter for @quilted/threads requests
if (Array.isArray(event.data) && event.data.length >= 2) {
const [kind, data] = event.data;
if (kind === 0) {
// 0: Request
if (Array.isArray(data) && event.data.length >= 2) {
const [_requestId, method, params] = data;
// handleChatPanelRequest is a function injected by the client
handleChatPanelRequest(JSON.stringify({ method, params }));
}
} else {
// 1: Response
// ignored as current methods return void
}
}
}
});
</script>
</body>

Expand Down
Loading

0 comments on commit 368125a

Please sign in to comment.