Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
import {
openArtifact,
previewRegisterRoot,
previewUnregisterRoot,
} from '@janhq/tauri-plugin-agent-tools-api'
import { getServiceHub } from '@/hooks/useServiceHub'
import { previewUrlFor } from '@/lib/coworkPreview'
/**
* The unsandboxed preview: the page is loaded by URL from the `preview://`
* scheme instead of inlined into a `srcDoc`, so it gets an origin of its own
* (storage works, relative assets resolve) that is still not the app's. The
* scheme serves only roots registered here; see `preview.rs`.
*/
export const registerPreviewRoot = (root: string, allowNetwork: boolean) =>
previewRegisterRoot(root, allowNetwork)
export const unregisterPreviewRoot = (root: string) =>
previewUnregisterRoot(root)
/** The `preview://` URL for an absolute file path, on this platform. */
export function previewUrl(abs: string): string {
return previewUrlFor(abs, getServiceHub().core().convertFileSrc('/', 'preview'))
}
/** What `openOrReveal` opens and reveals with: "Open" goes through the host,
* which checks the file itself rather than its name (`open_artifact`). */
export function artifactOpener() {
return {
openArtifact: async (roots: string[], abs: string) => {
const dataFolder = await getServiceHub().app().getJanDataFolder()
await openArtifact(dataFolder ?? '', roots, abs)
},
revealItemInDir: (abs: string) =>
getServiceHub().opener().revealItemInDir(abs),
}
}