-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension] Add route to auto start conversation (#8649)
- Loading branch information
Showing
8 changed files
with
203 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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 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 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,19 @@ | ||
import { createContext, useEffect, useState } from "react"; | ||
|
||
export const PortContext = createContext<chrome.runtime.Port | null>(null); | ||
|
||
export const PortProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [port, setPort] = useState<chrome.runtime.Port | null>(null); | ||
|
||
useEffect(() => { | ||
const port = chrome.runtime.connect({ name: "sidepanel-connection" }); | ||
|
||
setPort(port); | ||
|
||
return () => { | ||
port.disconnect(); | ||
}; | ||
}, []); | ||
|
||
return <PortContext.Provider value={port}>{children}</PortContext.Provider>; | ||
}; |
This file contains 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 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 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 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,60 @@ | ||
import type { LightWorkspaceType } from "@dust-tt/client"; | ||
import { Spinner } from "@dust-tt/sparkle"; | ||
import { useFileUploaderService } from "@extension/hooks/useFileUploaderService"; | ||
import { postConversation } from "@extension/lib/conversation"; | ||
import { useDustAPI } from "@extension/lib/dust_api"; | ||
import { useEffect } from "react"; | ||
import { useLocation, useNavigate } from "react-router"; | ||
|
||
export const RunPage = ({ workspace }: { workspace: LightWorkspaceType }) => { | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
const dustAPI = useDustAPI(); | ||
|
||
const fileUploaderService = useFileUploaderService({ | ||
owner: workspace, | ||
}); | ||
|
||
useEffect(() => { | ||
const run = async () => { | ||
const params = JSON.parse(decodeURI(location.search.substr(1))); | ||
|
||
const files = await fileUploaderService.uploadContentTab({ | ||
includeContent: params.includeContent, | ||
includeScreenshot: params.includeScreenshot, | ||
includeSelectionOnly: params.includeSelectionOnly, | ||
updateBlobs: false, | ||
}); | ||
|
||
const conversationRes = await postConversation({ | ||
dustAPI, | ||
messageData: { | ||
input: params.text, | ||
mentions: [{ configurationId: params.configurationId }], | ||
}, | ||
contentFragments: files | ||
? files.map((cf) => ({ | ||
title: cf.filename, | ||
fileId: cf.fileId || "", | ||
url: cf.publicUrl, | ||
})) | ||
: [], | ||
}); | ||
|
||
fileUploaderService.resetUpload(); | ||
|
||
if (conversationRes.isOk()) { | ||
navigate(`/conversations/${conversationRes.value.sId}`); | ||
} else { | ||
navigate("/"); | ||
} | ||
}; | ||
|
||
void run(); | ||
}, []); | ||
return ( | ||
<div className="w-full h-full flex items-center justify-center"> | ||
<Spinner size="xl" /> | ||
</div> | ||
); | ||
}; |
This file contains 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