-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose route/location info to the assistant
- Loading branch information
Showing
6 changed files
with
252 additions
and
135 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
49 changes: 49 additions & 0 deletions
49
catalog/app/components/Assistant/Model/GlobalContext/index.ts
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,49 @@ | ||
import * as React from 'react' | ||
|
||
import { useCurrentRoute } from '../navigation' | ||
|
||
function useRouteContext() { | ||
const { match, loc } = useCurrentRoute() | ||
|
||
const description = React.useMemo(() => { | ||
if (!match) return '' | ||
const params = match.decoded?.params | ||
? ` | ||
<parameters> | ||
${JSON.stringify(match.decoded.params, null, 2)} | ||
</parameters> | ||
` | ||
: '' | ||
return ` | ||
<route-info> | ||
Name: "${match.descriptor.name}" | ||
<description> | ||
${match.descriptor.description} | ||
</description> | ||
${params} | ||
</route-info> | ||
` | ||
}, [match]) | ||
|
||
const msg = React.useMemo( | ||
() => | ||
` | ||
<viewport> | ||
<current-location> | ||
${JSON.stringify(loc, null, 2)} | ||
</current-location> | ||
${description} | ||
Refer to "navigate" tool schema for navigable routes and their parameters. | ||
</viewport> | ||
`, | ||
[description, loc], | ||
) | ||
|
||
return msg | ||
} | ||
|
||
export function useGlobalContext() { | ||
return [useRouteContext()] | ||
} | ||
|
||
export { useGlobalContext as use } | ||
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
Oops, something went wrong.