-
Notifications
You must be signed in to change notification settings - Fork 541
feat: add Deno-powered extensions runtime (Phase 1) #1938
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
14f5636
feat: add Deno-powered extensions runtime (Phase 1)
devin-ai-integration[bot] e1f7e4b
fix: use correct z.record() signature with key and value schemas
devin-ai-integration[bot] ebe1f07
feat: add React component support for extensions with @hypr/ui
devin-ai-integration[bot] 0f523d0
fix: address code review feedback for extensions runtime
devin-ai-integration[bot] 4106859
fix: remove cdylib from crate-type to fix Linux V8 TLS linker error
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
apps/desktop/src/components/main/body/extensions/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { PuzzleIcon, XIcon } from "lucide-react"; | ||
| import { Reorder, useDragControls } from "motion/react"; | ||
| import type { PointerEvent } from "react"; | ||
|
|
||
| import { Button } from "@hypr/ui/components/ui/button"; | ||
| import { | ||
| ContextMenu, | ||
| ContextMenuContent, | ||
| ContextMenuItem, | ||
| ContextMenuSeparator, | ||
| ContextMenuTrigger, | ||
| } from "@hypr/ui/components/ui/context-menu"; | ||
| import { cn } from "@hypr/utils"; | ||
|
|
||
| import type { Tab } from "../../../../store/zustand/tabs"; | ||
| import { StandardTabWrapper } from "../index"; | ||
| import { getExtensionComponent } from "./registry"; | ||
|
|
||
| type ExtensionTab = Extract<Tab, { type: "extension" }>; | ||
|
|
||
| export function TabItemExtension({ | ||
| tab, | ||
| tabIndex, | ||
| handleCloseThis, | ||
| handleSelectThis, | ||
| handleCloseOthers, | ||
| handleCloseAll, | ||
| }: { | ||
| tab: ExtensionTab; | ||
| tabIndex?: number; | ||
| handleCloseThis: (tab: Tab) => void; | ||
| handleSelectThis: (tab: Tab) => void; | ||
| handleCloseOthers: () => void; | ||
| handleCloseAll: () => void; | ||
| }) { | ||
| const controls = useDragControls(); | ||
|
|
||
| return ( | ||
| <ContextMenu> | ||
| <ContextMenuTrigger asChild> | ||
| <Reorder.Item | ||
| value={tab} | ||
| dragListener={false} | ||
| dragControls={controls} | ||
| as="div" | ||
| className={cn([ | ||
| "h-full flex items-center gap-1 px-2 rounded-lg cursor-pointer select-none", | ||
| "hover:bg-neutral-100", | ||
| tab.active && "bg-neutral-100", | ||
| ])} | ||
| onClick={() => handleSelectThis(tab)} | ||
| onPointerDown={(e: PointerEvent) => controls.start(e)} | ||
| > | ||
| <PuzzleIcon size={14} className="text-neutral-500 shrink-0" /> | ||
| <span className="text-sm truncate max-w-[120px]"> | ||
| {tab.extensionId} | ||
| </span> | ||
| {tabIndex && ( | ||
| <span className="text-xs text-neutral-400 shrink-0"> | ||
| {tabIndex} | ||
| </span> | ||
| )} | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| className="size-5 shrink-0" | ||
| onClick={(e) => { | ||
| e.stopPropagation(); | ||
| handleCloseThis(tab); | ||
| }} | ||
| > | ||
| <XIcon size={12} /> | ||
| </Button> | ||
| </Reorder.Item> | ||
| </ContextMenuTrigger> | ||
| <ContextMenuContent> | ||
| <ContextMenuItem onClick={() => handleCloseThis(tab)}> | ||
| Close | ||
| </ContextMenuItem> | ||
| <ContextMenuItem onClick={handleCloseOthers}> | ||
| Close Others | ||
| </ContextMenuItem> | ||
| <ContextMenuSeparator /> | ||
| <ContextMenuItem onClick={handleCloseAll}>Close All</ContextMenuItem> | ||
| </ContextMenuContent> | ||
| </ContextMenu> | ||
| ); | ||
| } | ||
|
|
||
| export function TabContentExtension({ tab }: { tab: ExtensionTab }) { | ||
| const Component = getExtensionComponent(tab.extensionId); | ||
|
|
||
| if (!Component) { | ||
| return ( | ||
| <StandardTabWrapper> | ||
| <div className="flex items-center justify-center h-full"> | ||
| <div className="text-center"> | ||
| <PuzzleIcon size={48} className="mx-auto text-neutral-300 mb-4" /> | ||
| <p className="text-neutral-500"> | ||
| Extension not found: {tab.extensionId} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </StandardTabWrapper> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <StandardTabWrapper> | ||
| <Component extensionId={tab.extensionId} state={tab.state} /> | ||
| </StandardTabWrapper> | ||
| ); | ||
| } |
29 changes: 29 additions & 0 deletions
29
apps/desktop/src/components/main/body/extensions/registry.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { ComponentType } from "react"; | ||
|
|
||
| import type { ExtensionViewProps } from "../../../../types/extensions"; | ||
|
|
||
| const extensionModules = import.meta.glob<{ | ||
| default: ComponentType<ExtensionViewProps>; | ||
| }>("@extensions/*/ui.tsx", { eager: true }); | ||
|
|
||
| export const extensionComponents: Record< | ||
| string, | ||
| ComponentType<ExtensionViewProps> | ||
| > = {}; | ||
|
|
||
| for (const path in extensionModules) { | ||
| const mod = extensionModules[path]; | ||
| const parts = path.split("/"); | ||
| const extensionId = parts[parts.length - 2]; | ||
| extensionComponents[extensionId] = mod.default; | ||
| } | ||
|
|
||
| export function getExtensionComponent( | ||
| extensionId: string, | ||
| ): ComponentType<ExtensionViewProps> | undefined { | ||
| return extensionComponents[extensionId]; | ||
| } | ||
|
|
||
| export function getAvailableExtensions(): string[] { | ||
| return Object.keys(extensionComponents); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import type { ComponentType } from "react"; | ||
|
|
||
| export interface ExtensionViewProps { | ||
| extensionId: string; | ||
| state?: Record<string, unknown>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [package] | ||
| name = "extensions-runtime" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| deno_core = "0.338" | ||
|
|
||
| serde = { workspace = true, features = ["derive"] } | ||
| serde_json = { workspace = true } | ||
| thiserror = { workspace = true } | ||
| tokio = { workspace = true, features = ["rt-multi-thread", "sync"] } | ||
| tracing = { workspace = true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum Error { | ||
| #[error("Extension not found: {0}")] | ||
| ExtensionNotFound(String), | ||
|
|
||
| #[error("Invalid manifest: {0}")] | ||
| InvalidManifest(String), | ||
|
|
||
| #[error("Runtime error: {0}")] | ||
| RuntimeError(String), | ||
|
|
||
| #[error("IO error: {0}")] | ||
| Io(#[from] std::io::Error), | ||
|
|
||
| #[error("JSON error: {0}")] | ||
| Json(#[from] serde_json::Error), | ||
|
|
||
| #[error("Channel send error")] | ||
| ChannelSend, | ||
|
|
||
| #[error("Channel receive error")] | ||
| ChannelRecv, | ||
| } | ||
|
|
||
| pub type Result<T> = std::result::Result<T, Error>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| mod error; | ||
| mod manifest; | ||
| mod ops; | ||
| mod runtime; | ||
|
|
||
| pub use error::*; | ||
| pub use manifest::*; | ||
| pub use runtime::*; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.