Download web/src/chat/useAsk.ts from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/chat/useAsk.ts
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/src/chat/useAsk.ts
-
curl -L -o useAsk.ts https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/chat/useAsk.ts
1.22 kB
| import { useCallback } from 'react'; | |
| import { useLocation, useNavigate } from 'react-router-dom'; | |
| /** What the Ask page reads from the navigation that brought the person there. */ | |
| export interface AskArrival { ask?: string | null; at: number } | |
| /** | |
| * Ask is a page (/assistant), not a panel that follows the person around. `ask()` goes there, carrying what the person | |
| * was looking at as context (the test run, or a business area), and optionally a question to send straight away. | |
| */ | |
| export function useAsk() { | |
| const nav = useNavigate(); | |
| const loc = useLocation(); | |
| const ask = useCallback((q?: string) => { | |
| const run = /^\/runs\/([^/]+)/.exec(loc.pathname)?.[1]; | |
| const here = /^\/assistant(\/|$)/.test(loc.pathname); | |
| const module = new URLSearchParams(loc.search).get('module'); | |
| const to = here ? `${loc.pathname}${loc.search}` | |
| : run && run !== 'new' ? `/assistant/${run}` | |
| : module ? `/assistant?module=${encodeURIComponent(module)}` : '/assistant'; | |
| const state: AskArrival = { ask: q ?? null, at: Date.now() }; | |
| nav(to, { state }); | |
| }, [nav, loc.pathname, loc.search]); | |
| return { ask }; | |
| } | |
| export type AskState = ReturnType<typeof useAsk>; | |