Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/finic-ai/finic
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwcfan committed Oct 15, 2024
2 parents 07cfba0 + a72c3c0 commit fd830bc
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 25 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"react-hook-form": "^7.51.5",
"react-icons": "^4.10.1",
"react-markdown": "^8.0.7",
"react-player": "^2.16.0",
"react-router-dom": "^6.18.0",
"rehype-raw": "^6.1.1",
"remark-breaks": "^3.0.3",
Expand Down
51 changes: 26 additions & 25 deletions frontend/src/components/Modals/SessionRecordingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { Alert } from "@/subframe/components/Alert";
import { Select } from "@/subframe/components/Select";
import useFinicApp from "@/hooks/useFinicApp";
import { Execution } from "@/types";
import ReactPlayer from 'react-player';
import { Loader } from "@/subframe/components/Loader";


interface SessionRecordingModalProps extends React.HTMLAttributes<HTMLDivElement> {
isOpen: boolean;
Expand All @@ -20,16 +23,26 @@ export default function SessionRecordingModal({
sessionId,
setIsOpen,
}: SessionRecordingModalProps) {
const [errorMessage, setErrorMessage] = React.useState<string | null>(null);
const { getSessionRecordingUrl, error, isLoading } = useFinicApp();
const [errorMessage, setErrorMessage] = React.useState<string | undefined>(undefined);
const [args, setArgs] = React.useState<string>("");
const dialogRef = useRef<HTMLDivElement>(null);
const [url, setUrl] = React.useState<string | undefined>(undefined);

React.useEffect(() => {
if (sessionId && isOpen) {
getSessionRecordingUrl(sessionId).then((url) => {
setUrl(url);
});
}
}, [sessionId, isOpen]);

return (
<DialogLayout open={isOpen}>
<div className="flex h-full w-full min-w-[576px] flex-col items-start gap-8 bg-default-background px-8 py-8">
<div className="flex h-full w-full min-w-[800px] flex-col items-start gap-8 bg-default-background px-8 py-8">
<div className="flex w-full items-center justify-between">
<span className="text-heading-3 font-heading-3 text-default-font">
Run Agent
Session Recording
</span>
<IconButton
icon="FeatherX"
Expand All @@ -38,32 +51,20 @@ export default function SessionRecordingModal({
}}
/>
</div>
<div className="flex w-full min-w-[384px] max-w-[576px] grow shrink-0 basis-0 flex-col flex-wrap items-start gap-4">
<TextArea
className="h-auto w-full flex-none outline-none focus:outline-none ring-0 focus:ring-0"
error={false}
variant="outline"
label="Arguments (JSON format)"
helpText="These will be passed to your agent's main function as arguments. If left blank, no arguments will be passed."
>
<TextArea.Input
className="h-auto min-h-[128px] w-full flex-none outline-none focus:outline-none ring-0 focus:ring-0"
placeholder={
'{\n "openai_api_key": "<api-key>",\n "server_url": "https://api.example.com/",\n "product_id": "001777c8-8c9b-4dcb-b062-fe5960d13470"\n}'
}
value={args}
onChange={(event: React.ChangeEvent<HTMLTextAreaElement>) => {
setArgs(event.target.value);
}}
/>
</TextArea>
</div>
{errorMessage == null ? null : (

<ReactPlayer
url={url}
width="100%"
height="100%"
controls={true}
/>

{error && (
<Alert
variant="error"
icon="FeatherAlertCircle"
title="Error"
description={errorMessage}
description={error.message}
/>
)}

Expand Down
33 changes: 33 additions & 0 deletions frontend/src/hooks/useFinicApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface FinicAppContextType {
input: Record<string, any>
) => Promise<Execution | undefined>;
listExecutions: (agentId?: string) => Promise<Execution[] | undefined>;
getSessionRecordingUrl: (sessionId: string) => Promise<string | undefined>;
}

const FinicAppContext = createContext<FinicAppContextType | undefined>(
Expand Down Expand Up @@ -131,6 +132,37 @@ export const FinicAppContextProvider: React.FC<{
[bearer]
);

const getSessionRecordingUrl = useCallback(
async (sessionId: string) => {
try {
setIsLoading(true);
setError(null);
const response = await fetch(`${server_url}/session-recording-download-link/${sessionId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${bearer}`,
},
});
if (!response.ok) {
throw new Error("Failed to fetch session recording URL");
}
const data = await response.json();
if (data.download_url) {
return data.download_url as string;
}
console.log("data", data);
return undefined;
} catch (err: any) {
console.log("error", err);
setError(err);
} finally {
setIsLoading(false);
}
},
[bearer]
);

return (
<FinicAppContext.Provider
value={{
Expand All @@ -140,6 +172,7 @@ export const FinicAppContextProvider: React.FC<{
runAgent,
listExecutions,
getAgent,
getSessionRecordingUrl,
}}
>
{children}
Expand Down
31 changes: 31 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3224,6 +3224,11 @@ deep-is@^0.1.3:
resolved "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz"
integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==

deepmerge@^4.0.0:
version "4.3.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.3.1.tgz#44b5f2147cd3b00d4b56137685966f26fd25dd4a"
integrity sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==

delaunator@4:
version "4.0.1"
resolved "https://registry.npmjs.org/delaunator/-/delaunator-4.0.1.tgz"
Expand Down Expand Up @@ -4107,6 +4112,11 @@ lines-and-columns@^1.1.6:
resolved "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz"
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==

load-script@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/load-script/-/load-script-1.0.0.tgz#0491939e0bee5643ee494a7e3da3d2bac70c6ca4"
integrity sha512-kPEjMFtZvwL9TaZo0uZ2ml+Ye9HUMmPwbYRJ324qF9tqMejwykJ5ggTyvzmrbBeapCAbk98BSbTeovHEEP1uCA==

locate-path@^6.0.0:
version "6.0.0"
resolved "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz"
Expand Down Expand Up @@ -4248,6 +4258,11 @@ mdast-util-to-string@^3.1.0:
dependencies:
"@types/mdast" "^3.0.0"

memoize-one@^5.1.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.2.1.tgz#8337aa3c4335581839ec01c3d594090cebe8f00e"
integrity sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==

memoize-one@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-6.0.0.tgz#b2591b871ed82948aee4727dc6abceeeac8c1045"
Expand Down Expand Up @@ -4900,6 +4915,11 @@ react-dom@^18.2.0:
loose-envify "^1.1.0"
scheduler "^0.23.0"

react-fast-compare@^3.0.1:
version "3.2.2"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49"
integrity sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==

react-ga4@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/react-ga4/-/react-ga4-1.4.1.tgz#6ee2a2db115ed235b2f2092bc746b4eeeca9e206"
Expand Down Expand Up @@ -5016,6 +5036,17 @@ react-overlays@^5.1.2:
uncontrollable "^7.2.1"
warning "^4.0.3"

react-player@^2.16.0:
version "2.16.0"
resolved "https://registry.yarnpkg.com/react-player/-/react-player-2.16.0.tgz#89070700b03f5a5ded9f0b3165d4717390796481"
integrity sha512-mAIPHfioD7yxO0GNYVFD1303QFtI3lyyQZLY229UEAp/a10cSW+hPcakg0Keq8uWJxT2OiT/4Gt+Lc9bD6bJmQ==
dependencies:
deepmerge "^4.0.0"
load-script "^1.0.0"
memoize-one "^5.1.1"
prop-types "^15.7.2"
react-fast-compare "^3.0.1"

react-refresh@^0.14.0:
version "0.14.0"
resolved "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz"
Expand Down
15 changes: 15 additions & 0 deletions server/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ async def run_agent(
print(e)
raise HTTPException(status_code=500, detail=str(e))



@app.post("/agent-upload-link/{agent_id}")
async def get_agent_upload_link(
agent_id: str = Path(...),
Expand Down Expand Up @@ -243,6 +245,19 @@ async def get_session_recording_upload_link(
print(e)
raise HTTPException(status_code=500, detail=str(e))

@app.get("/session-recording-download-link/{session_id}")
async def get_session_recording_download_link(
session_id: str = Path(...),
config: AppConfig = Depends(validate_token),
):
try:
session = db.get_session(session_id, config.app_id)
download_url = db.get_session_recording_download_link(session)
return {"download_url": download_url}
except Exception as e:
print(e)
raise HTTPException(status_code=500, detail=str(e))

@app.get("/agent/{agent_id}")
async def get_agent(
agent_id: str = Path(...),
Expand Down

0 comments on commit fd830bc

Please sign in to comment.