Spaces:
Paused
Paused
Download src/lib/utils/artifactsContext.ts from Mike0021/chat-ui-agent-demo: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/utils/artifactsContext.ts
- Command line
-
hf download hf://spaces/Mike0021/chat-ui-agent-demo/src/lib/utils/artifactsContext.ts
-
curl -L -o artifactsContext.ts https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/utils/artifactsContext.ts
1.23 kB
| import { getContext, setContext } from "svelte"; | |
| import type { ArtifactRegistry } from "./artifacts"; | |
| import type { artifactPanel } from "$lib/stores/artifactPanel.svelte"; | |
| /** | |
| * Context bridging ChatWindow (which derives the artifact registry from the | |
| * visible message path) and the inline ArtifactCard components rendered deep | |
| * inside ChatMessage. | |
| */ | |
| export interface ArtifactsContext { | |
| readonly registry: ArtifactRegistry; | |
| panel: typeof artifactPanel; | |
| /** | |
| * Sends a preview-error fix request straight to the chat as a user message, | |
| * returning whether it was dispatched. Undefined while the conversation | |
| * can't accept a message (read-only, errored generation, streaming), so | |
| * consumers hide their ask-to-fix control instead of rendering a dead one. | |
| */ | |
| readonly requestFix?: (text: string) => boolean; | |
| } | |
| /** Exported for test harnesses that seed this context without mounting ChatWindow. */ | |
| export const ARTIFACTS_CONTEXT_KEY = Symbol("artifacts"); | |
| export function setArtifactsContext(ctx: ArtifactsContext): void { | |
| setContext(ARTIFACTS_CONTEXT_KEY, ctx); | |
| } | |
| export function getArtifactsContext(): ArtifactsContext | undefined { | |
| return getContext<ArtifactsContext | undefined>(ARTIFACTS_CONTEXT_KEY); | |
| } | |