@arbidocs/react 0.5.81 → 0.5.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifacts/index.cjs +4 -11
- package/dist/artifacts/index.cjs.map +1 -1
- package/dist/artifacts/index.d.cts +1 -3
- package/dist/artifacts/index.d.ts +1 -3
- package/dist/artifacts/index.js +3 -10
- package/dist/artifacts/index.js.map +1 -1
- package/dist/calls/livekit/index.cjs +41 -41
- package/dist/calls/livekit/index.js +2 -2
- package/dist/{chunk-L2P2X6LH.cjs → chunk-5N3UFEXE.cjs} +6 -3
- package/dist/chunk-5N3UFEXE.cjs.map +1 -0
- package/dist/{chunk-IZ3B62EN.cjs → chunk-A5BJZ4ZN.cjs} +5 -5
- package/dist/{chunk-IZ3B62EN.cjs.map → chunk-A5BJZ4ZN.cjs.map} +1 -1
- package/dist/{chunk-DLBGBIAM.js → chunk-CQYJQWJY.js} +6 -4
- package/dist/chunk-CQYJQWJY.js.map +1 -0
- package/dist/{chunk-4QON6LSH.js → chunk-RXPBHHX2.js} +3 -3
- package/dist/{chunk-4QON6LSH.js.map → chunk-RXPBHHX2.js.map} +1 -1
- package/dist/{chunk-IHKQPOPK.cjs → chunk-XQUC25ME.cjs} +3 -4
- package/dist/chunk-XQUC25ME.cjs.map +1 -0
- package/dist/{chunk-LBAGMNGG.js → chunk-ZDTOJVPP.js} +3 -4
- package/dist/chunk-ZDTOJVPP.js.map +1 -0
- package/dist/index.cjs +698 -678
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -23
- package/dist/index.d.ts +41 -23
- package/dist/index.js +48 -33
- package/dist/index.js.map +1 -1
- package/dist/ui/index.cjs +148 -148
- package/dist/ui/index.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-DLBGBIAM.js.map +0 -1
- package/dist/chunk-IHKQPOPK.cjs.map +0 -1
- package/dist/chunk-L2P2X6LH.cjs.map +0 -1
- package/dist/chunk-LBAGMNGG.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/artifacts/redline-engine.ts","../../src/artifacts/useRedline.ts","../../src/artifacts/useArtifactEditSession.ts","../../src/artifacts/useArtifactText.ts","../../src/artifacts/useArtifactSession.ts","../../src/artifacts/useArtifactSource.ts","../../src/artifacts/renderArtifactMarkdown.tsx","../../src/artifacts/useStreamedArtifact.ts","../../src/artifacts/artifact-kind.ts"],"names":["savedFromId","useState","useCallback","useRef","useEffect","content","useMemo","useQuery"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsBO,IAAM,uBAAA,GAAyC;AAAA,EACpD,YAAA,EAAc,0BAAA;AAAA,EACd,uBAAA,EAAyB,6BAAA;AAAA,EACzB,YAAA,EAAc;AAChB;ACUO,SAAS,UAAA,CAAW;AAAA,EACzB,QAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA,GAAY,KAAA;AAAA,EACZ,WAAA,GAAc,KAAA;AAAA,EACd,MAAA,GAAS;AACX,CAAA,EAAwC;AACtC,EAAA,MAAM,CAAC,OAAO,QAAQ,CAAA,GAAI,SAAuB,EAAE,IAAA,EAAM,QAAQ,CAAA;AACjE,EAAA,MAAM,YAAA,GAAe,OAAO,CAAC,CAAA;AAE7B,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,QAAA,KAAa,MAAA,IAAa,WAAA,KAAgB,MAAA,EAAW;AACvD,MAAA,QAAA,CAAS,EAAE,IAAA,EAAM,MAAA,EAAQ,CAAA;AACzB,MAAA;AAAA,IACF;AACA,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,QAAA,CAAS,EAAE,IAAA,EAAM,WAAA,EAAa,CAAA;AAC9B,MAAA;AAAA,IACF;AACA,IAAA,IAAI,QAAA,KAAa,IAAA,IAAQ,WAAA,KAAgB,IAAA,EAAM;AAC7C,MAAA,QAAA,CAAS,EAAE,IAAA,EAAM,aAAA,EAAe,CAAA;AAChC,MAAA;AAAA,IACF;AACA,IAAA,IACE,aAAa,W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AAA,KAAW,OAAA,IAAW,IAAA,CAAK,MAAM,KAAA,GAAQ,OAAA;AAAA,OAAA,IAC9C,KAAK,MAAA,KAAW,OAAA,IAAW,IAAA,CAAK,MAAA,KAAW,SAAS,KAAA,GAAQ,OAAA;AAAA,OAChE,KAAA,GAAQ,SAAA;AAEb,EAAA,MAAM,KAAA,GACJ,UAAU,OAAA,GACN,IAAA,GACC,aAAa,IAAA,CAAK,KAAA,IAAS,IAAI,KAAA,CAAM,kCAAkC,CAAA;AAC9E,EAAA,OAAO,EAAE,KAAA,EAAO,QAAA,EAAU,KAAA,EAAO,KAAA,EAAO,SAAS,KAAA,EAAM;AACzD;;;AC7IO,SAAS,yBAAyB,QAAA,EAAsD;AAC7F,EAAA,MAAM,GAAA,GAAA,CAAO,YAAY,EAAA,EAAI,WAAA,GAAc,KAAA,CAAM,cAAc,IAAI,CAAC,CAAA;AACpE,EAAA,IAAI,GAAA,KAAQ,OAAA,IAAW,GAAA,KAAQ,MAAA,EAAQ,OAAO,MAAA;AAC9C,EAAA,IAAI,GAAA,KAAQ,QAAQ,OAAO,OAAA;AAC3B,EAAA,OAAO,IAAA;AACT;AAEO,SAAS,qBAAqB,IAAA,EAAkD;AACrF,EAAA,OAAO,IAAA,KAAS,MAAA,IAAU,IAAA,KAAS,OAAA,GAAU,IAAA,GAAO,IAAA;AACtD;AAMO,SAAS,yBAAyB,IAAA,EAAkD;AACzF,EAAA,IAAI,IAAA,KAAS,SAAS,OAAO,KAAA;AAC7B,EAAA,OAAO,oBAAA,CAAqB,IAAI,CAAA,GAAI,SAAA,GAAY,MAAA;AAClD","file":"index.js","sourcesContent":["import {\n buildHybridRedlineMarkdown,\n buildHybridRedlineWithRegions,\n revertRedlineRegion,\n type RedlineWithRegions,\n} from './redline-diff'\n\n/**\n * Where a redline is computed. The default runs on the calling thread; a host with large\n * documents passes an engine backed by a Web Worker (for example a Comlink proxy exposing the same\n * three functions) so typing never waits on a diff.\n */\nexport interface RedlineEngine {\n buildRedline(baseText: string, compareText: string): string | Promise<string>\n buildRedlineWithRegions(\n baseText: string,\n compareText: string\n ): RedlineWithRegions | Promise<RedlineWithRegions>\n revertRegion(baseText: string, compareText: string, regionId: string): string | Promise<string>\n}\n\n/** Main-thread engine: the pure functions of `redline-diff`. */\nexport const mainThreadRedlineEngine: RedlineEngine = {\n buildRedline: buildHybridRedlineMarkdown,\n buildRedlineWithRegions: buildHybridRedlineWithRegions,\n revertRegion: revertRedlineRegion,\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport type { RedlineRegion } from './redline-diff'\nimport { normalizeMarkdown } from './normalize-markdown'\nimport { mainThreadRedlineEngine, type RedlineEngine } from './redline-engine'\n\n/** What a redline view can show. Mirrors the status parts of `@arbidocs/blocks/artifacts`. */\nexport type RedlineState =\n | { kind: 'idle' }\n | { kind: 'computing' }\n | { kind: 'ready'; markdown: string; regions: RedlineRegion[] }\n | { kind: 'identical' }\n | { kind: 'unavailable' }\n\nexport interface UseRedlineOptions {\n /** The older side. `null` means the text could not be loaded; `undefined` means not chosen. */\n baseText: string | null | undefined\n /** The newer side (a loaded version, or the live edit buffer). */\n compareText: string | null | undefined\n /** Either text is still being fetched. */\n isLoading?: boolean\n /** Tag every change with a stable id so a view can offer per-change undo. */\n withRegions?: boolean\n /** Defaults to the main thread; pass a worker-backed engine for big documents. */\n engine?: RedlineEngine\n}\n\nexport interface UseRedlineResult {\n state: RedlineState\n /** Undo one change: resolves with the compare text rebuilt without it (null if nothing changed). */\n revertRegion: (regionId: string) => Promise<string | null>\n}\n\n/**\n * Track-changes between two texts. Stale results are dropped when the inputs change mid-compute,\n * and a failed diff reports `unavailable` instead of throwing into the render.\n */\nexport function useRedline({\n baseText,\n compareText,\n isLoading = false,\n withRegions = false,\n engine = mainThreadRedlineEngine,\n}: UseRedlineOptions): UseRedlineResult {\n const [state, setState] = useState<RedlineState>({ kind: 'idle' })\n const requestIdRef = useRef(0)\n\n useEffect(() => {\n if (baseText === undefined || compareText === undefined) {\n setState({ kind: 'idle' })\n return\n }\n if (isLoading) {\n setState({ kind: 'computing' })\n return\n }\n if (baseText === null || compareText === null) {\n setState({ kind: 'unavailable' })\n return\n }\n if (\n baseText === compareText ||\n normalizeMarkdown(baseText) === normalizeMarkdown(compareText)\n ) {\n setState({ kind: 'identical' })\n return\n }\n\n const id = ++requestIdRef.current\n let cancelled = false\n setState({ kind: 'computing' })\n Promise.resolve(\n withRegions\n ? engine.buildRedlineWithRegions(baseText, compareText)\n : Promise.resolve(engine.buildRedline(baseText, compareText)).then((markdown) => ({\n markdown,\n regions: [] as RedlineRegion[],\n }))\n )\n .then((result) => {\n if (cancelled || id !== requestIdRef.current) return\n setState({ kind: 'ready', markdown: result.markdown, regions: result.regions })\n })\n .catch(() => {\n if (cancelled || id !== requestIdRef.current) return\n setState({ kind: 'unavailable' })\n })\n return () => {\n cancelled = true\n }\n }, [baseText, compareText, isLoading, withRegions, engine])\n\n // The latest texts, so `revertRegion` stays referentially stable while the user types.\n const latest = useRef({ baseText, compareText })\n useEffect(() => {\n latest.current = { baseText, compareText }\n }, [baseText, compareText])\n\n const revertRegion = useCallback(\n async (regionId: string): Promise<string | null> => {\n const { baseText: base, compareText: compare } = latest.current\n if (!base || !compare) return null\n try {\n const next = await engine.revertRegion(base, compare, regionId)\n return next !== normalizeMarkdown(compare) ? next : null\n } catch {\n return null\n }\n },\n [engine]\n )\n\n return useMemo(() => ({ state, revertRegion }), [state, revertRegion])\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { normalizeMarkdown } from './normalize-markdown'\nimport { useRedline, type UseRedlineResult } from './useRedline'\nimport type { RedlineEngine } from './redline-engine'\n\n/** What a save reports back. `docId` is the new version when the backend already knows it. */\nexport interface ArtifactSaveResult {\n docId?: string\n /** 1-based number of the version that was just saved (1 for the first save of a draft). */\n version?: number\n}\n\nexport interface ArtifactEditSessionOptions {\n /** The artifact being edited. Changing it discards the buffer and any comparison. */\n docId: string | null | undefined\n /**\n * The saved text of the open version. `undefined` while it loads; whenever it changes the\n * baseline follows it (a version arriving from the realtime channel, a finished stream).\n */\n baseline: string | undefined\n /**\n * A new document the user types from scratch: open straight in the editor, seeded with\n * `initialContent`, instead of showing a read-only view. Read when `docId` changes.\n */\n startEditing?: boolean\n initialContent?: string\n /** The version this one was saved from. Offering \"compare with previous\" needs it. */\n savedFromId?: string | null\n /** Controlled comparison target. Omit for an uncontrolled one the session owns. */\n compareId?: string | null\n onCompareChange?: (id: string | null) => void\n /** The saved text of the compare target (the older side of the diff). */\n compareText?: string | null\n compareLoading?: boolean\n /** Starting a comparison opens the editor with track changes on (default true). */\n compareOpensEditor?: boolean\n /** Persist the buffer as a NEW version. Rejecting keeps the buffer so nothing is lost. */\n save: (content: string) => Promise<ArtifactSaveResult | void>\n onSaved?: (result: ArtifactSaveResult, content: string) => void\n onSaveError?: (error: unknown) => void\n /** Every buffer change (a host keeps a draft store in sync with it). */\n onContentChange?: (content: string) => void\n /** The unsaved-changes flag, for a host that warns before a panel is closed. */\n onDirtyChange?: (dirty: boolean) => void\n /** Where the diff runs. Defaults to the main thread. */\n redlineEngine?: RedlineEngine\n /** Typing is never debounced; the diff trails the buffer by this long. Default 300ms. */\n diffDelayMs?: number\n}\n\nexport interface ArtifactEditSession {\n isEditing: boolean\n /** The saved text of the open version. */\n baseline: string\n /** The text in the editor (the baseline until the first edit). */\n content: string\n hasChanges: boolean\n isSaving: boolean\n canCompare: boolean\n compareId: string | null\n showTrackChanges: boolean\n /** Track changes between the compare target and the (debounced) buffer. */\n redline: UseRedlineResult\n startEdit: () => void\n /** Discard the buffer and any comparison; back to the rendered view. */\n cancel: () => void\n /** Save the buffer as a new version. Resolves false when it failed (the buffer is kept). */\n save: () => Promise<boolean>\n /** The editor's `onChange`; also replaces the buffer (for example after an undo-this-change). */\n change: (markdown: string) => void\n /** The editor's `onNormalized`: adopt its canonical form as the baseline so Save does not fire. */\n normalized: (markdown: string) => void\n /** Compare with the previous version (when no id is given). */\n compare: (id?: string) => void\n stopCompare: () => void\n setShowTrackChanges: (show: boolean) => void\n /** Undo one tracked change in the buffer. */\n revertRegion: (regionId: string) => Promise<void>\n}\n\n/**\n * The state machine of an artifact edit session, with no SDK and no network: the edit buffer and\n * its baseline, the dirty flag, immutable-version saves and a track-changes comparison. A host\n * supplies the saved text and a `save` function (see `useArtifactSession` for the SDK binding).\n */\nexport function useArtifactEditSession(options: ArtifactEditSessionOptions): ArtifactEditSession {\n const {\n docId,\n baseline: loadedBaseline,\n startEditing = false,\n initialContent,\n savedFromId,\n compareId: controlledCompareId,\n onCompareChange,\n compareText,\n compareLoading = false,\n compareOpensEditor = true,\n save: persist,\n onSaved,\n onSaveError,\n onContentChange,\n onDirtyChange,\n redlineEngine,\n diffDelayMs = 300,\n } = options\n\n const [isEditing, setIsEditing] = useState(false)\n const [baseline, setBaseline] = useState('')\n const [buffer, setBuffer] = useState('')\n const [isSaving, setIsSaving] = useState(false)\n const [showTrackChanges, setShowTrackChanges] = useState(false)\n const [ownCompareId, setOwnCompareId] = useState<string | null>(null)\n const controlled = controlledCompareId !== undefined\n const compareId = controlled ? controlledCompareId : ownCompareId\n\n const setCompareId = useCallback(\n (id: string | null) => {\n if (!controlled) setOwnCompareId(id)\n onCompareChange?.(id)\n },\n [controlled, onCompareChange]\n )\n\n // The latest values for callbacks that must not change identity while the user types.\n const latest = useRef({ buffer, baseline, isEditing, initialContent })\n latest.current = { buffer, baseline, isEditing, initialContent }\n\n // The baseline follows the loaded text. A draft has none and seeds itself below.\n useEffect(() => {\n if (loadedBaseline !== undefined) setBaseline(loadedBaseline)\n }, [loadedBaseline])\n\n // Another artifact: drop stale edits and comparison. A new typed document starts in the editor.\n useEffect(() => {\n if (startEditing) {\n const seed = latest.current.initialContent ?? ''\n setIsEditing(true)\n setBaseline(seed)\n setBuffer(seed)\n } else {\n setIsEditing(false)\n setBuffer('')\n }\n setCompareId(null)\n setShowTrackChanges(false)\n // Only the identity of the artifact resets the session.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [docId])\n\n const startEdit = useCallback(() => {\n setBuffer(latest.current.baseline)\n setIsEditing(true)\n }, [])\n\n const stopCompare = useCallback(() => {\n setCompareId(null)\n setShowTrackChanges(false)\n }, [setCompareId])\n\n const cancel = useCallback(() => {\n setIsEditing(false)\n setBuffer('')\n stopCompare()\n }, [stopCompare])\n\n const compare = useCallback(\n (id?: string) => {\n const target = id ?? savedFromId\n if (target) setCompareId(target)\n },\n [savedFromId, setCompareId]\n )\n\n // Comparing and editing are one surface: a comparison opens the editor with the diff showing,\n // like Word's Compare yields tracked changes you can keep typing through.\n const hasBaseline = baseline !== ''\n useEffect(() => {\n if (!compareId || !compareOpensEditor || !hasBaseline) return\n if (!latest.current.isEditing) startEdit()\n setShowTrackChanges(true)\n }, [compareId, compareOpensEditor, hasBaseline, startEdit])\n\n const save = useCallback(async (): Promise<boolean> => {\n // Persist the canonical spelling so the editor's gratuitous escapes never reach a version.\n const raw = latest.current.buffer\n const normalised = normalizeMarkdown(raw)\n const content = raw.endsWith('\\n') ? normalised : normalised.replace(/\\n$/, '')\n setIsSaving(true)\n try {\n const result = (await persist(content)) ?? {}\n setBaseline(content)\n setIsEditing(false)\n stopCompare()\n onSaved?.(result, content)\n return true\n } catch (error) {\n onSaveError?.(error)\n return false\n } finally {\n setIsSaving(false)\n }\n }, [persist, stopCompare, onSaved, onSaveError])\n\n const content = buffer || baseline\n const hasChanges = isEditing && !!buffer && buffer !== baseline\n useEffect(() => {\n onDirtyChange?.(hasChanges)\n return () => onDirtyChange?.(false)\n }, [hasChanges, onDirtyChange])\n\n const setContent = useCallback(\n (markdown: string) => {\n setBuffer(markdown)\n onContentChange?.(markdown)\n },\n [onContentChange]\n )\n const normalized = useCallback((markdown: string) => {\n setBaseline(markdown)\n setBuffer(markdown)\n }, [])\n\n // The diff trails the buffer so it runs on a settled text.\n const [diffContent, setDiffContent] = useState(content)\n useEffect(() => {\n const id = setTimeout(() => setDiffContent(content), diffDelayMs)\n return () => clearTimeout(id)\n }, [content, diffDelayMs])\n\n const redline = useRedline({\n baseText: compareId ? compareText : undefined,\n compareText: compareId ? diffContent || baseline : undefined,\n isLoading: compareLoading,\n withRegions: true,\n engine: redlineEngine,\n })\n const { revertRegion: revertInRedline } = redline\n const revertRegion = useCallback(\n async (regionId: string): Promise<void> => {\n const next = await revertInRedline(regionId)\n if (next !== null) setContent(next)\n },\n [revertInRedline, setContent]\n )\n\n return useMemo(\n () => ({\n isEditing,\n baseline,\n content,\n hasChanges,\n isSaving,\n canCompare: !!savedFromId && !compareId,\n compareId,\n showTrackChanges,\n redline,\n startEdit,\n cancel,\n save,\n change: setContent,\n normalized,\n compare,\n stopCompare,\n setShowTrackChanges,\n revertRegion,\n }),\n [\n isEditing,\n baseline,\n content,\n hasChanges,\n isSaving,\n savedFromId,\n compareId,\n showTrackChanges,\n redline,\n startEdit,\n cancel,\n save,\n setContent,\n normalized,\n compare,\n stopCompare,\n revertRegion,\n ]\n )\n}\n","import { useCallback, useMemo } from 'react'\nimport { useQuery } from '@tanstack/react-query'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../hooks'\nimport { flattenChunks, isDocumentId, parseVersionRef } from './versions'\n\n/**\n * Where the text of a stored artifact is:\n * - `loading`: the first request is in flight (or there is no document yet);\n * - `parsing`: the backend has not finished parsing the upload (the endpoint answers 404, 422 or\n * 500, or an empty parse, for a few seconds after an upload) and the hook is retrying;\n * - `ready`: the text is here (an empty document is `ready` with `text: null`);\n * - `error`: the retries ran out, or the request was refused (401/403).\n */\nexport type ArtifactTextStatus = 'loading' | 'parsing' | 'ready' | 'error'\n\n/** How long `useArtifactText` keeps asking while a document is still being parsed. */\nexport interface ArtifactTextRetry {\n /** Retries after the first request. Default 12. */\n attempts?: number\n /** Delay before the first retry; it grows by 1.6x each time. Default 1000 ms. */\n baseDelayMs?: number\n /** Cap for one delay. Default 5000 ms (12 retries are about 50 s in all). */\n maxDelayMs?: number\n}\n\nexport const DEFAULT_ARTIFACT_TEXT_RETRY: Required<ArtifactTextRetry> = {\n attempts: 12,\n baseDelayMs: 1000,\n maxDelayMs: 5000,\n}\n\n/** Thrown inside the query when the parse has no text yet, so that it is retried like a 500. */\nclass NotParsedYetError extends Error {\n constructor() {\n super('The document has no parsed text yet')\n }\n}\n\nconst isRefusal = (error: unknown): boolean => {\n const status = error as { status?: number; response?: { status?: number } } | null\n const code = status?.status ?? status?.response?.status\n return code === 401 || code === 403\n}\n\nexport interface ArtifactText {\n /**\n * The markdown, clean: `undefined` while `loading` or `parsing`, `null` when there is none (an\n * empty document, or `error`).\n */\n text: string | null | undefined\n /** `status` is `loading` or `parsing`. */\n isLoading: boolean\n status: ArtifactTextStatus\n /** The last request error while `parsing` or after `error`. */\n error: Error | null\n /** Ask again now (after an `error`). */\n retry: () => void\n}\n\n/**\n * The saved markdown of an artifact version (its parsed chunks, joined and unescaped).\n *\n * A freshly uploaded document is parsed asynchronously, and for roughly 3 to 20 seconds the parsed\n * content endpoint answers 404, 422 or 500 (or an empty parse). The hook therefore retries with a\n * growing delay (see `ArtifactTextRetry`) and reports `status: 'parsing'` meanwhile, so a host can\n * show \"Preparing editor...\" instead of opening an editor on an empty baseline. After the last\n * retry the status is `error`; `retry()` starts a new round.\n *\n * The text is run through `unescapeMarkdown`: an artifact is always stored from markdown, and the\n * backend's parse of a `.md` escapes its punctuation.\n */\nexport function useArtifactText(\n docId: string | null | undefined,\n options?: { enabled?: boolean; retry?: ArtifactTextRetry }\n): ArtifactText {\n const arbi = useArbi()\n const { attempts, baseDelayMs, maxDelayMs } = {\n ...DEFAULT_ARTIFACT_TEXT_RETRY,\n ...options?.retry,\n }\n // A local draft (placeholder id) has no backend document: asking for its text would be a 422.\n const enabled = (options?.enabled ?? true) && isDocumentId(docId) && arbi.hasWorkspace\n const query = useQuery({\n // Under the shared `parsedDoc` key, so a document's invalidation reaches it too.\n queryKey: [...arbiQueryKeys.parsedDoc(docId ?? '', 'marker'), 'artifact-text'] as const,\n queryFn: async () => {\n // A version reference (`doc-…@v2`) reads that version; a plain id the current one.\n const { docId: plainId, version } = parseVersionRef(docId)\n const parsed = (await arbi.documents.getParsedContent(\n plainId,\n 'marker',\n version ?? undefined\n )) as {\n chunks?: { content?: string | null }[]\n }\n if (!parsed.chunks?.some((c) => c.content?.trim())) throw new NotParsedYetError()\n return flattenChunks(parsed.chunks, { unescape: true })\n },\n enabled,\n retry: (failureCount, error) => !isRefusal(error) && failureCount < attempts,\n retryDelay: (failureCount) => Math.min(baseDelayMs * 1.6 ** failureCount, maxDelayMs),\n })\n\n const { refetch } = query\n const retry = useCallback(() => void refetch(), [refetch])\n\n return useMemo<ArtifactText>(() => {\n const error = query.error\n const neverParsed = error instanceof NotParsedYetError\n let status: ArtifactTextStatus = 'loading'\n if (!enabled) status = 'loading'\n else if (query.isSuccess || (query.isError && neverParsed)) status = 'ready'\n else if (query.isError) status = 'error'\n else if (query.failureCount > 0) status = 'parsing'\n const text = !enabled\n ? undefined\n : query.isSuccess\n ? query.data\n : status === 'ready' || status === 'error'\n ? null\n : undefined\n return {\n text,\n isLoading: enabled && (status === 'loading' || status === 'parsing'),\n status,\n error: status === 'ready' ? null : (error ?? query.failureReason ?? null),\n retry,\n }\n }, [\n enabled,\n query.isSuccess,\n query.isError,\n query.data,\n query.error,\n query.failureCount,\n query.failureReason,\n retry,\n ])\n}\n","import { useCallback, useMemo, useState } from 'react'\nimport { useMutation, useQueryClient } from '@tanstack/react-query'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys, useDocumentVersionList } from '../hooks'\nimport { refreshDocuments, useDocuments } from '../documents/documents-data'\nimport { useArtifactText, type ArtifactTextStatus } from './useArtifactText'\nimport {\n documentVersions,\n findVersion,\n isDocumentId,\n parseVersionRef,\n toArtifactVersions,\n versionLabel,\n type ArtifactVersion,\n} from './versions'\nimport {\n useArtifactEditSession,\n type ArtifactEditSession,\n type ArtifactEditSessionOptions,\n type ArtifactSaveResult,\n} from './useArtifactEditSession'\n\n/**\n * The versions of an artifact, oldest first. `docId` is a document id or a version reference\n * (`doc-…@v2`). Every listed document carries its versions; a document that is not in the\n * workspace list asks for its version list.\n */\nexport function useArtifactVersions(\n workspaceId: string | undefined,\n docId: string | null | undefined\n): ArtifactVersion[] {\n const plainId = docId ? parseVersionRef(docId).docId : null\n const { data: documents } = useDocuments(workspaceId)\n const listed = useMemo(\n () => (documents ?? []).find((d) => d.external_id === plainId),\n [documents, plainId]\n )\n // Asked only once the list has loaded and the document is not in it.\n const { data: history } = useDocumentVersionList(plainId, {\n enabled: !!plainId && documents !== undefined && !listed,\n })\n return useMemo(\n () => (listed ? documentVersions(listed) : toArtifactVersions(plainId, history)),\n [listed, history, plainId]\n )\n}\n\nexport interface SaveArtifactVersionInput {\n /** File name of the new version (`.md` is added when missing). */\n title: string\n content: string\n /** Save as the next version of this document (it keeps its id); omit for a new document. */\n versionOf?: string | null\n /** The processing config (auto-title, parsing) to run the upload with. */\n configId?: string | null\n /** `artifact` (default) for AI-style drafts; `source` for a document the user typed. */\n wpType?: 'artifact' | 'source'\n}\n\n/**\n * Save markdown as a NEW immutable version (the next version of `versionOf`'s document, which keeps\n * its id) and refresh the workspace document list, version lists and the document's text.\n */\nexport function useSaveArtifactVersion() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation<ArtifactSaveResult, Error, SaveArtifactVersionInput>({\n mutationFn: async ({ title, content, versionOf, configId, wpType }) => {\n // The backend classifies uploads by extension: a title without one is silently dropped.\n const fileName = /\\.md$/i.test(title) ? title : `${title}.md`\n const result = await arbi.documents.uploadFile(\n new Blob([content], { type: 'text/markdown' }),\n fileName,\n {\n wpType: wpType ?? 'artifact',\n versionOf: versionOf ? parseVersionRef(versionOf).docId : undefined,\n configExtId: configId ?? undefined,\n }\n )\n const docId = result.doc_ext_ids?.[0]\n // The document's row moves to the new version (its version lists re-read with it).\n if (docId) await refreshDocuments(queryClient, arbi, [docId])\n await queryClient.invalidateQueries({ queryKey: arbiQueryKeys.allDocumentVersions() })\n // The document's current text is the new version's now.\n if (docId)\n await queryClient.invalidateQueries({ queryKey: arbiQueryKeys.parsedDocument(docId) })\n return { docId, version: result.version ?? undefined }\n },\n })\n}\n\nexport interface ArtifactSessionOptions extends Pick<\n ArtifactEditSessionOptions,\n | 'onSaved'\n | 'onSaveError'\n | 'onCompareChange'\n | 'compareId'\n | 'compareOpensEditor'\n | 'redlineEngine'\n | 'onDirtyChange'\n> {\n workspaceId: string | undefined\n /**\n * The open document (its current version), a version reference `doc-…@v{n}`, or the placeholder\n * id of an unsaved local draft (anything that is not a backend document id, i.e. does not start\n * with `doc`).\n */\n docId: string | null | undefined\n /**\n * The text of a local draft (nothing is fetched for it). The FIRST save uploads it as a real\n * document with no parent and the session switches to the new id; later saves chain from it.\n */\n draftContent?: string\n /** Name for saved versions. Defaults to the open version's file name, else \"Untitled\". */\n title?: string\n /** Processing config for saved versions. */\n configId?: string | null\n}\n\n/** Everything `ArtifactEditor` (`@arbidocs/blocks/artifacts`) takes from a session, flat. */\nexport interface ArtifactSessionView {\n content: string\n isEditing: boolean\n hasChanges: boolean\n isSaving: boolean\n canCompare: boolean\n comparing: boolean\n compareId: string | null\n showTrackChanges: boolean\n versions: ArtifactVersion[]\n currentVersionId: string\n onStartEdit: () => void\n onCancel: () => void\n onSave: () => void\n onCompare: () => void\n onStopCompare: () => void\n onToggleTrackChanges: () => void\n /**\n * Whether the text is ready. `ArtifactEditor` renders \"Preparing editor...\" while it is\n * `loading` or `parsing` (a fresh upload is parsed for a few seconds) and an error with Retry.\n */\n status: ArtifactTextStatus\n /** Ask for the text again after an `error`. */\n onRetry: () => void\n}\n\nexport interface ArtifactSession extends ArtifactEditSession {\n /** The open document: the new real id once a local draft has been saved. */\n docId: string | null | undefined\n /** The open version is an unsaved local draft (no backend document yet). */\n isLocal: boolean\n isLoading: boolean\n /** See `ArtifactTextStatus`. */\n status: ArtifactTextStatus\n versions: ArtifactVersion[]\n /** \"v2\" for any version (reference) of the document. */\n labelOf: (id: string | null | undefined) => string | null\n /** Props for `<ArtifactEditor>`. */\n view: ArtifactSessionView\n /** Props for `<ArtifactMarkdownEditor>` (`@arbidocs/blocks/artifacts/editor`). */\n editorProps: {\n markdown: string\n onChange: (markdown: string) => void\n onNormalized: (markdown: string) => void\n }\n /** Props for `<ArtifactRedlineView>`. */\n redlineProps: {\n state: ArtifactEditSession['redline']['state']\n onRevert: (regionId: string) => void\n }\n}\n\n/**\n * Edit an artifact through the SDK: load it, edit it, save it as a new version, list its versions\n * and compare any two with track changes. Needs an `<ArbiHost>` with an `arbi` and a selected workspace.\n *\n * ```tsx\n * const session = useArtifactSession({ workspaceId, docId, onSaved: ({ docId }) => docId && open(docId) })\n * <ArtifactEditor {...session.view} onOpenVersion={open}\n * editor={<ArtifactMarkdownEditor {...session.editorProps} />}\n * redline={<ArtifactRedlineView {...session.redlineProps} />} />\n * ```\n */\nexport function useArtifactSession(options: ArtifactSessionOptions): ArtifactSession {\n const {\n workspaceId,\n docId: hostDocId,\n draftContent,\n title,\n configId,\n compareId,\n onCompareChange,\n onSaved,\n ...passthrough\n } = options\n // A saved local draft becomes this real document; another host docId resets it.\n const [saved, setSaved] = useState<{\n forId: string | null | undefined\n id: string\n text: string\n } | null>(null)\n const adopted = saved && saved.forId === hostDocId ? saved : null\n const docId = adopted?.id ?? hostDocId\n const isLocal = !isDocumentId(docId)\n\n // Owned here (not in the edit session) because the compare target's text must be loaded first.\n const [ownCompareId, setOwnCompareId] = useState<string | null>(null)\n const activeCompareId = compareId === undefined ? ownCompareId : compareId\n const changeCompare = useCallback(\n (id: string | null) => {\n setOwnCompareId(id)\n onCompareChange?.(id)\n },\n [onCompareChange]\n )\n\n const { text, isLoading, status, retry } = useArtifactText(docId)\n const versions = useArtifactVersions(workspaceId, isLocal ? null : docId)\n const { text: compareText, isLoading: compareLoading } = useArtifactText(activeCompareId, {\n enabled: !!activeCompareId,\n })\n const saveVersion = useSaveArtifactVersion()\n const current = findVersion(versions, docId)\n\n const save = useCallback(\n async (content: string) => {\n const result = await saveVersion.mutateAsync({\n title: title ?? current?.name ?? 'Untitled',\n content,\n versionOf: isLocal ? null : docId,\n configId,\n })\n const latest = versions.reduce((n, v) => Math.max(n, v.number), 0)\n return { ...result, version: result.version ?? (isLocal ? 1 : latest + 1) }\n },\n [saveVersion, title, current?.name, isLocal, docId, configId, versions]\n )\n\n const handleSaved = useCallback(\n (result: ArtifactSaveResult, content: string) => {\n // A host that keeps passing the local draft's placeholder id: follow every save to the real\n // document it created (the first save creates version 1, later ones chain from it).\n if (!isDocumentId(hostDocId) && result.docId)\n setSaved({ forId: hostDocId, id: result.docId, text: content })\n onSaved?.(result, content)\n },\n [hostDocId, onSaved]\n )\n\n const session = useArtifactEditSession({\n ...passthrough,\n docId,\n // A local draft has only its own text; a just-saved one shows what was saved until the parsed\n // text of the new document arrives.\n baseline: text ?? (isLocal ? draftContent : adopted?.text),\n savedFromId: current?.savedFromId,\n compareId: activeCompareId,\n onCompareChange: changeCompare,\n compareText,\n compareLoading,\n save,\n onSaved: handleSaved,\n })\n\n const { redline } = session\n return useMemo<ArtifactSession>(\n () => ({\n ...session,\n docId,\n isLocal,\n isLoading,\n status,\n versions,\n labelOf: (id) => versionLabel(versions, id),\n view: {\n content: session.baseline,\n isEditing: session.isEditing,\n hasChanges: session.hasChanges,\n isSaving: session.isSaving,\n canCompare: session.canCompare,\n comparing: !!session.compareId,\n compareId: session.compareId,\n showTrackChanges: session.showTrackChanges,\n versions,\n currentVersionId: current?.id ?? docId ?? '',\n onStartEdit: session.startEdit,\n onCancel: session.cancel,\n onSave: () => void session.save(),\n onCompare: () => session.compare(),\n onStopCompare: session.stopCompare,\n onToggleTrackChanges: () => session.setShowTrackChanges(!session.showTrackChanges),\n // A local draft has its text already: it is ready.\n status: isLocal ? 'ready' : status,\n onRetry: retry,\n },\n editorProps: {\n markdown: session.content,\n onChange: session.change,\n onNormalized: session.normalized,\n },\n redlineProps: {\n state: redline.state,\n onRevert: (regionId) => void session.revertRegion(regionId),\n },\n }),\n [session, redline, isLoading, status, retry, isLocal, versions, docId]\n )\n}\n","import { useQuery } from '@tanstack/react-query'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../query-keys'\n\n/**\n * The stored source of a live artifact (the `.html` / `.jsx` file itself; the parsed text strips\n * it). `undefined` until it has loaded.\n */\nexport function useArtifactSource(documentId: string | null | undefined, enabled = true) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.artifactSource(documentId ?? ''),\n queryFn: async () => (await arbi.documents.download(documentId as string)).text(),\n enabled: enabled && !!documentId && arbi.isLoggedIn,\n staleTime: 5 * 60 * 1000,\n })\n}\n","import type { ComponentPropsWithoutRef, FC, ReactNode } from 'react'\nimport { MarkdownRenderer } from '../ai/MarkdownRenderer'\n\n/** The `<del>` / `<ins>` renderers `ArtifactRedlineView` hands to a markdown renderer. */\nexport interface ArtifactRedlineComponents {\n del: FC<ComponentPropsWithoutRef<'del'> & { 'data-cid'?: string }>\n ins: FC<ComponentPropsWithoutRef<'ins'> & { 'data-cid'?: string }>\n}\n\n/**\n * The kit's markdown renderer as the `renderMarkdown` slot of `ArtifactEditor` and\n * `ArtifactRedlineView`: full markdown (tables, lists, code) plus the raw `<del>` / `<ins>` tags\n * of a redline.\n */\nexport function renderArtifactMarkdown(\n markdown: string,\n components?: ArtifactRedlineComponents\n): ReactNode {\n return <MarkdownRenderer components={components}>{markdown}</MarkdownRenderer>\n}\n","import { useCallback, useEffect, useRef, useState } from 'react'\nimport type { ArtifactEvent } from '../ai/engine'\nimport { cleanDraftWithReport, type DraftCleanReport } from '../ai/stored-markdown'\nimport { useSaveArtifactVersion } from './useArtifactSession'\nimport { isDocumentId } from './versions'\nimport { useArtifactText, type ArtifactTextRetry } from './useArtifactText'\n\n/**\n * Where a drafted artifact is in its STREAM -> PERSIST -> EDIT life:\n * - `streaming`: the agent is still working (or has produced nothing final): show the live canvas;\n * - `persisting`: the finished draft is being stored as version 1 of the artifact;\n * - `parsing`: stored; the backend is still parsing it, so there is no editable text yet;\n * - `ready`: the text is readable: mount the editor on `docId`;\n * - `error`: storing failed or the parse never produced text (`retry()` starts over).\n */\nexport type StreamedArtifactPhase = 'streaming' | 'persisting' | 'parsing' | 'ready' | 'error'\n\nexport interface UseStreamedArtifactOptions {\n /** The artifacts of the agent run (`useConnectedAiTask().artifacts`). */\n artifacts: ArtifactEvent[]\n workspaceId: string | undefined\n /**\n * The run has stopped: not busy and not failed. Nothing is stored before this, so a draft that\n * is still streaming is never persisted half-written.\n */\n settled: boolean\n /**\n * Make the stored markdown from the streamed content. Default `cleanDraftWithReport`, which is\n * guarded: it stores the raw streamed text (or links-only text) rather than a cleanup that would\n * lose content (see `DraftCleanReport`).\n */\n clean?: (streamed: string) => string\n /** Called once per stored draft with what the cleanup did (`stage` is not `cleaned` if guarded). */\n onCleaned?: (report: DraftCleanReport) => void\n /** Processing config for the stored version. */\n configId?: string | null\n /** How long to wait for the parse (see `useArtifactText`). */\n parseRetry?: ArtifactTextRetry\n}\n\nexport interface StreamedArtifact {\n phase: StreamedArtifactPhase\n /** The finished streamed artifact (its `title` names the stored versions). */\n artifact: ArtifactEvent | undefined\n /** The backend document to edit, once there is one (while `parsing` and `ready`). */\n docId: string | undefined\n error: Error | null\n /** What the cleanup did to the stored draft (`null` until it was stored, or with a custom `clean`). */\n cleaned: DraftCleanReport | null\n /** After an `error`: store again or ask for the parse again. */\n retry: () => void\n}\n\n/**\n * The lifecycle of an agent-drafted artifact, so a host passes the stream and renders the phase.\n *\n * While the agent streams, the draft lives only on the canvas. Once the run is `settled` and the\n * draft is complete, a draft that is not yet a backend document is cleaned (`cleanDraftMarkdown`)\n * and stored ONCE as the artifact's first version (`wpType: 'artifact'`); a draft that already is a\n * backend document passes through. The hook then waits for the parse (`useArtifactText`, which\n * retries) and reports `ready` with the `docId` to open in an editor.\n *\n * Needs an `<ArbiHost>` with an `arbi` and a workspace. `@arbidocs/blocks/connect` has the whole thing as a\n * component (`StreamedArtifact`).\n */\nexport function useStreamedArtifact({\n artifacts,\n workspaceId,\n settled,\n clean,\n onCleaned,\n configId,\n parseRetry,\n}: UseStreamedArtifactOptions): StreamedArtifact {\n const artifact = artifacts.find((a) => a.is_complete)\n const { mutateAsync } = useSaveArtifactVersion()\n const [saved, setSaved] = useState<{ content: string; docId: string } | null>(null)\n const [saveError, setSaveError] = useState<Error | null>(null)\n const [attempt, setAttempt] = useState(0)\n const [cleaned, setCleaned] = useState<DraftCleanReport | null>(null)\n const started = useRef<string | null>(null)\n\n const content = artifact?.content ?? ''\n const title = artifact?.title ?? 'Draft'\n const passThrough = !!artifact && isDocumentId(artifact.doc_ext_id)\n const needsSave = settled && !!artifact && !passThrough && !!content.trim() && !!workspaceId\n\n useEffect(() => {\n const key = `${attempt}:${content}`\n if (!needsSave || started.current === key) return\n started.current = key\n setSaveError(null)\n let stored: string\n if (clean) stored = clean(content)\n else {\n const report = cleanDraftWithReport(content)\n stored = report.text\n setCleaned(report)\n onCleaned?.(report)\n if (report.guarded) {\n console.warn(\n `[useStreamedArtifact] the draft cleanup would have lost content; stored the ${report.stage} text instead (kept ${Math.round(report.ratio * 100)}%, changed by: ${report.changedBy.join(', ') || 'nothing'})`\n )\n }\n }\n mutateAsync({\n title,\n content: stored,\n configId,\n wpType: 'artifact',\n })\n .then((r) => {\n if (r.docId) setSaved({ content, docId: r.docId })\n else setSaveError(new Error('The draft was stored but the server returned no document id'))\n })\n .catch((e: unknown) => setSaveError(e instanceof Error ? e : new Error(String(e))))\n // `clean` and `onCleaned` are deliberately not dependencies: a new function identity must not\n // store twice.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [needsSave, content, title, workspaceId, configId, attempt, mutateAsync])\n\n const docId = !artifact\n ? undefined\n : passThrough\n ? artifact.doc_ext_id\n : saved?.content === content\n ? saved.docId\n : undefined\n\n const text = useArtifactText(docId, { enabled: settled, retry: parseRetry })\n const { retry: retryText } = text\n\n const retry = useCallback(() => {\n if (saveError) setAttempt((n) => n + 1)\n else retryText()\n }, [saveError, retryText])\n\n let phase: StreamedArtifactPhase\n if (!settled || !artifact) phase = 'streaming'\n else if (saveError) phase = 'error'\n else if (!docId) phase = needsSave ? 'persisting' : 'streaming'\n else if (text.status === 'ready' && text.text) phase = 'ready'\n else if (text.status === 'error' || text.status === 'ready') phase = 'error'\n else phase = 'parsing'\n\n const error =\n phase !== 'error'\n ? null\n : (saveError ?? text.error ?? new Error('The document has no text to edit'))\n return { phase, artifact, docId, error, cleaned, retry }\n}\n","/**\n * Which live renderer, if any, an artifact maps to. Kept free of heavy imports (no compiler) so the\n * document viewer can use it without pulling the preview code into its bundle.\n *\n * The backend persists an artifact's render mode in the saved file's extension: .html / .jsx are live\n * artifacts; document drafts are stored as .docx and open in the Word editor.\n */\nexport type ArtifactPreviewKind = 'html' | 'react'\n\nexport function artifactKindFromFileName(fileName?: string | null): ArtifactPreviewKind | null {\n const ext = (fileName ?? '').toLowerCase().match(/\\.[a-z0-9]+$/)?.[0]\n if (ext === '.html' || ext === '.htm') return 'html'\n if (ext === '.jsx') return 'react'\n return null\n}\n\nexport function artifactKindFromMode(mode?: string | null): ArtifactPreviewKind | null {\n return mode === 'html' || mode === 'react' ? mode : null\n}\n\n/**\n * The viewer tab an artifact opens on: a generated image on its media view ('pdf'), an html/react\n * artifact on its rendered Preview, and a document draft (stored as .docx) in the Word editor.\n */\nexport function viewerTabForArtifactMode(mode?: string | null): 'pdf' | 'preview' | 'edit' {\n if (mode === 'image') return 'pdf'\n return artifactKindFromMode(mode) ? 'preview' : 'edit'\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/artifacts/redline-engine.ts","../../src/artifacts/useRedline.ts","../../src/artifacts/useArtifactEditSession.ts","../../src/artifacts/useArtifactText.ts","../../src/artifacts/useArtifactSession.ts","../../src/artifacts/useArtifactSource.ts","../../src/artifacts/renderArtifactMarkdown.tsx","../../src/artifacts/useStreamedArtifact.ts","../../src/artifacts/artifact-kind.ts"],"names":["savedFromId","useState","useCallback","useRef","useEffect","content","useMemo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AA,IAAI,GAAA,KAAQ,OAAA,IAAW,GAAA,KAAQ,MAAA,EAAQ,OAAO,MAAA;AAC9C,EAAA,IAAI,GAAA,KAAQ,QAAQ,OAAO,OAAA;AAC3B,EAAA,OAAO,IAAA;AACT;AAEO,SAAS,qBAAqB,IAAA,EAAkD;AACrF,EAAA,OAAO,IAAA,KAAS,MAAA,IAAU,IAAA,KAAS,OAAA,GAAU,IAAA,GAAO,IAAA;AACtD;AAMO,SAAS,yBAAyB,IAAA,EAAkD;AACzF,EAAA,IAAI,IAAA,KAAS,SAAS,OAAO,KAAA;AAC7B,EAAA,OAAO,oBAAA,CAAqB,IAAI,CAAA,GAAI,SAAA,GAAY,MAAA;AAClD","file":"index.js","sourcesContent":["import {\n buildHybridRedlineMarkdown,\n buildHybridRedlineWithRegions,\n revertRedlineRegion,\n type RedlineWithRegions,\n} from './redline-diff'\n\n/**\n * Where a redline is computed. The default runs on the calling thread; a host with large\n * documents passes an engine backed by a Web Worker (for example a Comlink proxy exposing the same\n * three functions) so typing never waits on a diff.\n */\nexport interface RedlineEngine {\n buildRedline(baseText: string, compareText: string): string | Promise<string>\n buildRedlineWithRegions(\n baseText: string,\n compareText: string\n ): RedlineWithRegions | Promise<RedlineWithRegions>\n revertRegion(baseText: string, compareText: string, regionId: string): string | Promise<string>\n}\n\n/** Main-thread engine: the pure functions of `redline-diff`. */\nexport const mainThreadRedlineEngine: RedlineEngine = {\n buildRedline: buildHybridRedlineMarkdown,\n buildRedlineWithRegions: buildHybridRedlineWithRegions,\n revertRegion: revertRedlineRegion,\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport type { RedlineRegion } from './redline-diff'\nimport { normalizeMarkdown } from './normalize-markdown'\nimport { mainThreadRedlineEngine, type RedlineEngine } from './redline-engine'\n\n/** What a redline view can show. Mirrors the status parts of `@arbidocs/blocks/artifacts`. */\nexport type RedlineState =\n | { kind: 'idle' }\n | { kind: 'computing' }\n | { kind: 'ready'; markdown: string; regions: RedlineRegion[] }\n | { kind: 'identical' }\n | { kind: 'unavailable' }\n\nexport interface UseRedlineOptions {\n /** The older side. `null` means the text could not be loaded; `undefined` means not chosen. */\n baseText: string | null | undefined\n /** The newer side (a loaded version, or the live edit buffer). */\n compareText: string | null | undefined\n /** Either text is still being fetched. */\n isLoading?: boolean\n /** Defaults to the main thread; pass a worker-backed engine for big documents. */\n engine?: RedlineEngine\n}\n\nexport interface UseRedlineResult {\n state: RedlineState\n /** Undo one change: resolves with the compare text rebuilt without it (null if nothing changed). */\n revertRegion: (regionId: string) => Promise<string | null>\n}\n\n/**\n * Track-changes between two texts. Stale results are dropped when the inputs change mid-compute,\n * and a failed diff reports `unavailable` instead of throwing into the render.\n */\nexport function useRedline({\n baseText,\n compareText,\n isLoading = false,\n engine = mainThreadRedlineEngine,\n}: UseRedlineOptions): UseRedlineResult {\n const [state, setState] = useState<RedlineState>({ kind: 'idle' })\n const requestIdRef = useRef(0)\n\n useEffect(() => {\n if (baseText === undefined || compareText === undefined) {\n setState({ kind: 'idle' })\n return\n }\n if (isLoading) {\n setState({ kind: 'computing' })\n return\n }\n if (baseText === null || compareText === null) {\n setState({ kind: 'unavailable' })\n return\n }\n if (\n baseText === compareText ||\n normalizeMarkdown(baseText) === normalizeMarkdown(compareText)\n ) {\n setState({ kind: 'identical' })\n return\n }\n\n const id = ++requestIdRef.current\n let cancelled = false\n setState({ kind: 'computing' })\n // Every change carries a stable id, so a view can offer per-change undo.\n Promise.resolve(engine.buildRedlineWithRegions(baseText, compareText))\n .then((result) => {\n if (cancelled || id !== requestIdRef.current) return\n setState({ kind: 'ready', markdown: result.markdown, regions: result.regions })\n })\n .catch(() => {\n if (cancelled || id !== requestIdRef.current) return\n setState({ kind: 'unavailable' })\n })\n return () => {\n cancelled = true\n }\n }, [baseText, compareText, isLoading, engine])\n\n // The latest texts, so `revertRegion` stays referentially stable while the user types.\n const latest = useRef({ baseText, compareText })\n useEffect(() => {\n latest.current = { baseText, compareText }\n }, [baseText, compareText])\n\n const revertRegion = useCallback(\n async (regionId: string): Promise<string | null> => {\n const { baseText: base, compareText: compare } = latest.current\n if (!base || !compare) return null\n try {\n const next = await engine.revertRegion(base, compare, regionId)\n return next !== normalizeMarkdown(compare) ? next : null\n } catch {\n return null\n }\n },\n [engine]\n )\n\n return useMemo(() => ({ state, revertRegion }), [state, revertRegion])\n}\n","import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { normalizeMarkdown } from './normalize-markdown'\nimport { useRedline, type UseRedlineResult } from './useRedline'\nimport type { RedlineEngine } from './redline-engine'\n\n/** What a save reports back. `docId` is the new version when the backend already knows it. */\nexport interface ArtifactSaveResult {\n docId?: string\n /** 1-based number of the version that was just saved (1 for the first save of a draft). */\n version?: number\n}\n\nexport interface ArtifactEditSessionOptions {\n /** The artifact being edited. Changing it discards the buffer and any comparison. */\n docId: string | null | undefined\n /**\n * The saved text of the open version. `undefined` while it loads; whenever it changes the\n * baseline follows it (a version arriving from the realtime channel, a finished stream).\n */\n baseline: string | undefined\n /**\n * A new document the user types from scratch: open straight in the editor, seeded with\n * `initialContent`, instead of showing a read-only view. Read when `docId` changes.\n */\n startEditing?: boolean\n initialContent?: string\n /** The version this one was saved from. Offering \"compare with previous\" needs it. */\n savedFromId?: string | null\n /** Controlled comparison target. Omit for an uncontrolled one the session owns. */\n compareId?: string | null\n onCompareChange?: (id: string | null) => void\n /** The saved text of the compare target (the older side of the diff). */\n compareText?: string | null\n compareLoading?: boolean\n /** Starting a comparison opens the editor with track changes on (default true). */\n compareOpensEditor?: boolean\n /** Persist the buffer as a NEW version. Rejecting keeps the buffer so nothing is lost. */\n save: (content: string) => Promise<ArtifactSaveResult | void>\n onSaved?: (result: ArtifactSaveResult, content: string) => void\n onSaveError?: (error: unknown) => void\n /** Every buffer change (a host keeps a draft store in sync with it). */\n onContentChange?: (content: string) => void\n /** The unsaved-changes flag, for a host that warns before a panel is closed. */\n onDirtyChange?: (dirty: boolean) => void\n /** Where the diff runs. Defaults to the main thread. */\n redlineEngine?: RedlineEngine\n /** Typing is never debounced; the diff trails the buffer by this long. Default 300ms. */\n diffDelayMs?: number\n}\n\nexport interface ArtifactEditSession {\n isEditing: boolean\n /** The saved text of the open version. */\n baseline: string\n /** The text in the editor (the baseline until the first edit). */\n content: string\n hasChanges: boolean\n isSaving: boolean\n canCompare: boolean\n compareId: string | null\n showTrackChanges: boolean\n /** Track changes between the compare target and the (debounced) buffer. */\n redline: UseRedlineResult\n startEdit: () => void\n /** Discard the buffer and any comparison; back to the rendered view. */\n cancel: () => void\n /** Save the buffer as a new version. Resolves false when it failed (the buffer is kept). */\n save: () => Promise<boolean>\n /** The editor's `onChange`; also replaces the buffer (for example after an undo-this-change). */\n change: (markdown: string) => void\n /** The editor's `onNormalized`: adopt its canonical form as the baseline so Save does not fire. */\n normalized: (markdown: string) => void\n /** Compare with the previous version (when no id is given). */\n compare: (id?: string) => void\n stopCompare: () => void\n setShowTrackChanges: (show: boolean) => void\n /** Undo one tracked change in the buffer. */\n revertRegion: (regionId: string) => Promise<void>\n}\n\n/**\n * The state machine of an artifact edit session, with no SDK and no network: the edit buffer and\n * its baseline, the dirty flag, immutable-version saves and a track-changes comparison. A host\n * supplies the saved text and a `save` function (see `useArtifactSession` for the SDK binding).\n */\nexport function useArtifactEditSession(options: ArtifactEditSessionOptions): ArtifactEditSession {\n const {\n docId,\n baseline: loadedBaseline,\n startEditing = false,\n initialContent,\n savedFromId,\n compareId: controlledCompareId,\n onCompareChange,\n compareText,\n compareLoading = false,\n compareOpensEditor = true,\n save: persist,\n onSaved,\n onSaveError,\n onContentChange,\n onDirtyChange,\n redlineEngine,\n diffDelayMs = 300,\n } = options\n\n const [isEditing, setIsEditing] = useState(false)\n const [baseline, setBaseline] = useState('')\n const [buffer, setBuffer] = useState('')\n const [isSaving, setIsSaving] = useState(false)\n const [showTrackChanges, setShowTrackChanges] = useState(false)\n const [ownCompareId, setOwnCompareId] = useState<string | null>(null)\n const controlled = controlledCompareId !== undefined\n const compareId = controlled ? controlledCompareId : ownCompareId\n\n const setCompareId = useCallback(\n (id: string | null) => {\n if (!controlled) setOwnCompareId(id)\n onCompareChange?.(id)\n },\n [controlled, onCompareChange]\n )\n\n // The latest values for callbacks that must not change identity while the user types.\n const latest = useRef({ buffer, baseline, isEditing, initialContent })\n latest.current = { buffer, baseline, isEditing, initialContent }\n\n // The baseline follows the loaded text. A draft has none and seeds itself below.\n useEffect(() => {\n if (loadedBaseline !== undefined) setBaseline(loadedBaseline)\n }, [loadedBaseline])\n\n // Another artifact: drop stale edits and comparison. A new typed document starts in the editor.\n useEffect(() => {\n if (startEditing) {\n const seed = latest.current.initialContent ?? ''\n setIsEditing(true)\n setBaseline(seed)\n setBuffer(seed)\n } else {\n setIsEditing(false)\n setBuffer('')\n }\n setCompareId(null)\n setShowTrackChanges(false)\n // Only the identity of the artifact resets the session.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [docId])\n\n const startEdit = useCallback(() => {\n setBuffer(latest.current.baseline)\n setIsEditing(true)\n }, [])\n\n const stopCompare = useCallback(() => {\n setCompareId(null)\n setShowTrackChanges(false)\n }, [setCompareId])\n\n const cancel = useCallback(() => {\n setIsEditing(false)\n setBuffer('')\n stopCompare()\n }, [stopCompare])\n\n const compare = useCallback(\n (id?: string) => {\n const target = id ?? savedFromId\n if (target) setCompareId(target)\n },\n [savedFromId, setCompareId]\n )\n\n // Comparing and editing are one surface: a comparison opens the editor with the diff showing,\n // like Word's Compare yields tracked changes you can keep typing through.\n const hasBaseline = baseline !== ''\n useEffect(() => {\n if (!compareId || !compareOpensEditor || !hasBaseline) return\n if (!latest.current.isEditing) startEdit()\n setShowTrackChanges(true)\n }, [compareId, compareOpensEditor, hasBaseline, startEdit])\n\n const save = useCallback(async (): Promise<boolean> => {\n // Persist the canonical spelling so the editor's gratuitous escapes never reach a version.\n const raw = latest.current.buffer\n const normalised = normalizeMarkdown(raw)\n const content = raw.endsWith('\\n') ? normalised : normalised.replace(/\\n$/, '')\n setIsSaving(true)\n try {\n const result = (await persist(content)) ?? {}\n setBaseline(content)\n setIsEditing(false)\n stopCompare()\n onSaved?.(result, content)\n return true\n } catch (error) {\n onSaveError?.(error)\n return false\n } finally {\n setIsSaving(false)\n }\n }, [persist, stopCompare, onSaved, onSaveError])\n\n const content = buffer || baseline\n const hasChanges = isEditing && !!buffer && buffer !== baseline\n useEffect(() => {\n onDirtyChange?.(hasChanges)\n return () => onDirtyChange?.(false)\n }, [hasChanges, onDirtyChange])\n\n const setContent = useCallback(\n (markdown: string) => {\n setBuffer(markdown)\n onContentChange?.(markdown)\n },\n [onContentChange]\n )\n const normalized = useCallback((markdown: string) => {\n setBaseline(markdown)\n setBuffer(markdown)\n }, [])\n\n // The diff trails the buffer so it runs on a settled text.\n const [diffContent, setDiffContent] = useState(content)\n useEffect(() => {\n const id = setTimeout(() => setDiffContent(content), diffDelayMs)\n return () => clearTimeout(id)\n }, [content, diffDelayMs])\n\n const redline = useRedline({\n baseText: compareId ? compareText : undefined,\n compareText: compareId ? diffContent || baseline : undefined,\n isLoading: compareLoading,\n engine: redlineEngine,\n })\n const { revertRegion: revertInRedline } = redline\n const revertRegion = useCallback(\n async (regionId: string): Promise<void> => {\n const next = await revertInRedline(regionId)\n if (next !== null) setContent(next)\n },\n [revertInRedline, setContent]\n )\n\n return useMemo(\n () => ({\n isEditing,\n baseline,\n content,\n hasChanges,\n isSaving,\n canCompare: !!savedFromId && !compareId,\n compareId,\n showTrackChanges,\n redline,\n startEdit,\n cancel,\n save,\n change: setContent,\n normalized,\n compare,\n stopCompare,\n setShowTrackChanges,\n revertRegion,\n }),\n [\n isEditing,\n baseline,\n content,\n hasChanges,\n isSaving,\n savedFromId,\n compareId,\n showTrackChanges,\n redline,\n startEdit,\n cancel,\n save,\n setContent,\n normalized,\n compare,\n stopCompare,\n revertRegion,\n ]\n )\n}\n","import { useCallback, useMemo } from 'react'\nimport { useQuery } from '@tanstack/react-query'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../hooks'\nimport { flattenChunks, isDocumentId, parseVersionRef } from './versions'\n\n/**\n * Where the text of a stored artifact is:\n * - `loading`: the first request is in flight (or there is no document yet);\n * - `parsing`: the backend has not finished parsing the upload (the endpoint answers 404, 422 or\n * 500, or an empty parse, for a few seconds after an upload) and the hook is retrying;\n * - `ready`: the text is here (an empty document is `ready` with `text: null`);\n * - `error`: the retries ran out, or the request was refused (401/403).\n */\nexport type ArtifactTextStatus = 'loading' | 'parsing' | 'ready' | 'error'\n\n/** How long `useArtifactText` keeps asking while a document is still being parsed. */\nexport interface ArtifactTextRetry {\n /** Retries after the first request. Default 12. */\n attempts?: number\n /** Delay before the first retry; it grows by 1.6x each time. Default 1000 ms. */\n baseDelayMs?: number\n /** Cap for one delay. Default 5000 ms (12 retries are about 50 s in all). */\n maxDelayMs?: number\n}\n\nexport const DEFAULT_ARTIFACT_TEXT_RETRY: Required<ArtifactTextRetry> = {\n attempts: 12,\n baseDelayMs: 1000,\n maxDelayMs: 5000,\n}\n\n/** Thrown inside the query when the parse has no text yet, so that it is retried like a 500. */\nclass NotParsedYetError extends Error {\n constructor() {\n super('The document has no parsed text yet')\n }\n}\n\nconst isRefusal = (error: unknown): boolean => {\n const status = error as { status?: number; response?: { status?: number } } | null\n const code = status?.status ?? status?.response?.status\n return code === 401 || code === 403\n}\n\nexport interface ArtifactText {\n /**\n * The markdown, clean: `undefined` while `loading` or `parsing`, `null` when there is none (an\n * empty document, or `error`).\n */\n text: string | null | undefined\n /** `status` is `loading` or `parsing`. */\n isLoading: boolean\n status: ArtifactTextStatus\n /** The last request error while `parsing` or after `error`. */\n error: Error | null\n /** Ask again now (after an `error`). */\n retry: () => void\n}\n\n/**\n * The saved markdown of an artifact version (its parsed chunks, joined and unescaped).\n *\n * A freshly uploaded document is parsed asynchronously, and for roughly 3 to 20 seconds the parsed\n * content endpoint answers 404, 422 or 500 (or an empty parse). The hook therefore retries with a\n * growing delay (see `ArtifactTextRetry`) and reports `status: 'parsing'` meanwhile, so a host can\n * show \"Preparing editor...\" instead of opening an editor on an empty baseline. After the last\n * retry the status is `error`; `retry()` starts a new round.\n *\n * The text is run through `unescapeMarkdown`: an artifact is always stored from markdown, and the\n * backend's parse of a `.md` escapes its punctuation.\n */\nexport function useArtifactText(\n docId: string | null | undefined,\n options?: { enabled?: boolean; retry?: ArtifactTextRetry }\n): ArtifactText {\n const arbi = useArbi()\n const { attempts, baseDelayMs, maxDelayMs } = {\n ...DEFAULT_ARTIFACT_TEXT_RETRY,\n ...options?.retry,\n }\n // A local draft (placeholder id) has no backend document: asking for its text would be a 422.\n const enabled = (options?.enabled ?? true) && isDocumentId(docId) && arbi.hasWorkspace\n const query = useQuery({\n // Under the shared `parsedDoc` key, so a document's invalidation reaches it too.\n queryKey: [...arbiQueryKeys.parsedDoc(docId ?? '', 'marker'), 'artifact-text'] as const,\n queryFn: async () => {\n // A version reference (`doc-…@v2`) reads that version; a plain id the current one.\n const { docId: plainId, version } = parseVersionRef(docId)\n const parsed = (await arbi.documents.getParsedContent(\n plainId,\n 'marker',\n version ?? undefined\n )) as {\n chunks?: { content?: string | null }[]\n }\n if (!parsed.chunks?.some((c) => c.content?.trim())) throw new NotParsedYetError()\n return flattenChunks(parsed.chunks, { unescape: true })\n },\n enabled,\n retry: (failureCount, error) => !isRefusal(error) && failureCount < attempts,\n retryDelay: (failureCount) => Math.min(baseDelayMs * 1.6 ** failureCount, maxDelayMs),\n })\n\n const { refetch } = query\n const retry = useCallback(() => void refetch(), [refetch])\n\n return useMemo<ArtifactText>(() => {\n const error = query.error\n const neverParsed = error instanceof NotParsedYetError\n let status: ArtifactTextStatus = 'loading'\n if (!enabled) status = 'loading'\n else if (query.isSuccess || (query.isError && neverParsed)) status = 'ready'\n else if (query.isError) status = 'error'\n else if (query.failureCount > 0) status = 'parsing'\n const text = !enabled\n ? undefined\n : query.isSuccess\n ? query.data\n : status === 'ready' || status === 'error'\n ? null\n : undefined\n return {\n text,\n isLoading: enabled && (status === 'loading' || status === 'parsing'),\n status,\n error: status === 'ready' ? null : (error ?? query.failureReason ?? null),\n retry,\n }\n }, [\n enabled,\n query.isSuccess,\n query.isError,\n query.data,\n query.error,\n query.failureCount,\n query.failureReason,\n retry,\n ])\n}\n","import { useCallback, useMemo, useState } from 'react'\nimport { useMutation, useQueryClient } from '@tanstack/react-query'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys, useDocumentVersionList } from '../hooks'\nimport { refreshDocuments, useDocuments } from '../documents/documents-data'\nimport { useArtifactText, type ArtifactTextStatus } from './useArtifactText'\nimport {\n documentVersions,\n findVersion,\n isDocumentId,\n parseVersionRef,\n toArtifactVersions,\n versionLabel,\n type ArtifactVersion,\n} from './versions'\nimport {\n useArtifactEditSession,\n type ArtifactEditSession,\n type ArtifactEditSessionOptions,\n type ArtifactSaveResult,\n} from './useArtifactEditSession'\n\n/**\n * The versions of an artifact, oldest first. `docId` is a document id or a version reference\n * (`doc-…@v2`). Every listed document carries its versions; a document that is not in the\n * workspace list asks for its version list.\n */\nexport function useArtifactVersions(\n workspaceId: string | undefined,\n docId: string | null | undefined\n): ArtifactVersion[] {\n const plainId = docId ? parseVersionRef(docId).docId : null\n const { data: documents } = useDocuments(workspaceId)\n const listed = useMemo(\n () => (documents ?? []).find((d) => d.external_id === plainId),\n [documents, plainId]\n )\n // Asked only once the list has loaded and the document is not in it.\n const { data: history } = useDocumentVersionList(plainId, {\n enabled: !!plainId && documents !== undefined && !listed,\n })\n return useMemo(\n () => (listed ? documentVersions(listed) : toArtifactVersions(plainId, history)),\n [listed, history, plainId]\n )\n}\n\nexport interface SaveArtifactVersionInput {\n /** File name of the new version (`.md` is added when missing). */\n title: string\n content: string\n /** Save as the next version of this document (it keeps its id); omit for a new document. */\n versionOf?: string | null\n /** The processing config (auto-title, parsing) to run the upload with. */\n configId?: string | null\n /** `artifact` (default) for AI-style drafts; `source` for a document the user typed. */\n wpType?: 'artifact' | 'source'\n}\n\n/**\n * Save markdown as a NEW immutable version (the next version of `versionOf`'s document, which keeps\n * its id) and refresh the workspace document list, version lists and the document's text.\n */\nexport function useSaveArtifactVersion() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation<ArtifactSaveResult, Error, SaveArtifactVersionInput>({\n mutationFn: async ({ title, content, versionOf, configId, wpType }) => {\n // The backend classifies uploads by extension: a title without one is silently dropped.\n const fileName = /\\.md$/i.test(title) ? title : `${title}.md`\n const result = await arbi.documents.uploadFile(\n new Blob([content], { type: 'text/markdown' }),\n fileName,\n {\n wpType: wpType ?? 'artifact',\n versionOf: versionOf ? parseVersionRef(versionOf).docId : undefined,\n configExtId: configId ?? undefined,\n }\n )\n const docId = result.doc_ext_ids?.[0]\n // The document's row moves to the new version (its version lists re-read with it).\n if (docId) await refreshDocuments(queryClient, arbi, [docId])\n await queryClient.invalidateQueries({ queryKey: arbiQueryKeys.allDocumentVersions() })\n // The document's current text is the new version's now.\n if (docId)\n await queryClient.invalidateQueries({ queryKey: arbiQueryKeys.parsedDocument(docId) })\n return { docId, version: result.version ?? undefined }\n },\n })\n}\n\nexport interface ArtifactSessionOptions extends Pick<\n ArtifactEditSessionOptions,\n | 'onSaved'\n | 'onSaveError'\n | 'onCompareChange'\n | 'compareId'\n | 'compareOpensEditor'\n | 'redlineEngine'\n | 'onDirtyChange'\n> {\n workspaceId: string | undefined\n /**\n * The open document (its current version), a version reference `doc-…@v{n}`, or the placeholder\n * id of an unsaved local draft (anything that is not a backend document id, i.e. does not start\n * with `doc`).\n */\n docId: string | null | undefined\n /**\n * The text of a local draft (nothing is fetched for it). The FIRST save uploads it as a real\n * document with no parent and the session switches to the new id; later saves chain from it.\n */\n draftContent?: string\n /** Name for saved versions. Defaults to the open version's file name, else \"Untitled\". */\n title?: string\n /** Processing config for saved versions. */\n configId?: string | null\n}\n\n/** Everything `ArtifactEditor` (`@arbidocs/blocks/artifacts`) takes from a session, flat. */\nexport interface ArtifactSessionView {\n content: string\n isEditing: boolean\n hasChanges: boolean\n isSaving: boolean\n canCompare: boolean\n comparing: boolean\n compareId: string | null\n showTrackChanges: boolean\n versions: ArtifactVersion[]\n currentVersionId: string\n onStartEdit: () => void\n onCancel: () => void\n onSave: () => void\n onCompare: () => void\n onStopCompare: () => void\n onToggleTrackChanges: () => void\n /**\n * Whether the text is ready. `ArtifactEditor` renders \"Preparing editor...\" while it is\n * `loading` or `parsing` (a fresh upload is parsed for a few seconds) and an error with Retry.\n */\n status: ArtifactTextStatus\n /** Ask for the text again after an `error`. */\n onRetry: () => void\n}\n\nexport interface ArtifactSession extends ArtifactEditSession {\n /** The open document: the new real id once a local draft has been saved. */\n docId: string | null | undefined\n /** The open version is an unsaved local draft (no backend document yet). */\n isLocal: boolean\n isLoading: boolean\n /** See `ArtifactTextStatus`. */\n status: ArtifactTextStatus\n versions: ArtifactVersion[]\n /** \"v2\" for any version (reference) of the document. */\n labelOf: (id: string | null | undefined) => string | null\n /** Props for `<ArtifactEditor>`. */\n view: ArtifactSessionView\n /** Props for `<ArtifactMarkdownEditor>` (`@arbidocs/blocks/artifacts/editor`). */\n editorProps: {\n markdown: string\n onChange: (markdown: string) => void\n onNormalized: (markdown: string) => void\n }\n /** Props for `<ArtifactRedlineView>`. */\n redlineProps: {\n state: ArtifactEditSession['redline']['state']\n onRevert: (regionId: string) => void\n }\n}\n\n/**\n * Edit an artifact through the SDK: load it, edit it, save it as a new version, list its versions\n * and compare any two with track changes. Needs an `<ArbiHost>` with an `arbi` and a selected workspace.\n *\n * ```tsx\n * const session = useArtifactSession({ workspaceId, docId, onSaved: ({ docId }) => docId && open(docId) })\n * <ArtifactEditor {...session.view} onOpenVersion={open}\n * editor={<ArtifactMarkdownEditor {...session.editorProps} />}\n * redline={<ArtifactRedlineView {...session.redlineProps} />} />\n * ```\n */\nexport function useArtifactSession(options: ArtifactSessionOptions): ArtifactSession {\n const {\n workspaceId,\n docId: hostDocId,\n draftContent,\n title,\n configId,\n compareId,\n onCompareChange,\n onSaved,\n ...passthrough\n } = options\n // A saved local draft becomes this real document; another host docId resets it.\n const [saved, setSaved] = useState<{\n forId: string | null | undefined\n id: string\n text: string\n } | null>(null)\n const adopted = saved && saved.forId === hostDocId ? saved : null\n const docId = adopted?.id ?? hostDocId\n const isLocal = !isDocumentId(docId)\n\n // Owned here (not in the edit session) because the compare target's text must be loaded first.\n const [ownCompareId, setOwnCompareId] = useState<string | null>(null)\n const activeCompareId = compareId === undefined ? ownCompareId : compareId\n const changeCompare = useCallback(\n (id: string | null) => {\n setOwnCompareId(id)\n onCompareChange?.(id)\n },\n [onCompareChange]\n )\n\n const { text, isLoading, status, retry } = useArtifactText(docId)\n const versions = useArtifactVersions(workspaceId, isLocal ? null : docId)\n const { text: compareText, isLoading: compareLoading } = useArtifactText(activeCompareId, {\n enabled: !!activeCompareId,\n })\n const saveVersion = useSaveArtifactVersion()\n const current = findVersion(versions, docId)\n\n const save = useCallback(\n async (content: string) => {\n const result = await saveVersion.mutateAsync({\n title: title ?? current?.name ?? 'Untitled',\n content,\n versionOf: isLocal ? null : docId,\n configId,\n })\n const latest = versions.reduce((n, v) => Math.max(n, v.number), 0)\n return { ...result, version: result.version ?? (isLocal ? 1 : latest + 1) }\n },\n [saveVersion, title, current?.name, isLocal, docId, configId, versions]\n )\n\n const handleSaved = useCallback(\n (result: ArtifactSaveResult, content: string) => {\n // A host that keeps passing the local draft's placeholder id: follow every save to the real\n // document it created (the first save creates version 1, later ones chain from it).\n if (!isDocumentId(hostDocId) && result.docId)\n setSaved({ forId: hostDocId, id: result.docId, text: content })\n onSaved?.(result, content)\n },\n [hostDocId, onSaved]\n )\n\n const session = useArtifactEditSession({\n ...passthrough,\n docId,\n // A local draft has only its own text; a just-saved one shows what was saved until the parsed\n // text of the new document arrives.\n baseline: text ?? (isLocal ? draftContent : adopted?.text),\n savedFromId: current?.savedFromId,\n compareId: activeCompareId,\n onCompareChange: changeCompare,\n compareText,\n compareLoading,\n save,\n onSaved: handleSaved,\n })\n\n const { redline } = session\n return useMemo<ArtifactSession>(\n () => ({\n ...session,\n docId,\n isLocal,\n isLoading,\n status,\n versions,\n labelOf: (id) => versionLabel(versions, id),\n view: {\n content: session.baseline,\n isEditing: session.isEditing,\n hasChanges: session.hasChanges,\n isSaving: session.isSaving,\n canCompare: session.canCompare,\n comparing: !!session.compareId,\n compareId: session.compareId,\n showTrackChanges: session.showTrackChanges,\n versions,\n currentVersionId: current?.id ?? docId ?? '',\n onStartEdit: session.startEdit,\n onCancel: session.cancel,\n onSave: () => void session.save(),\n onCompare: () => session.compare(),\n onStopCompare: session.stopCompare,\n onToggleTrackChanges: () => session.setShowTrackChanges(!session.showTrackChanges),\n // A local draft has its text already: it is ready.\n status: isLocal ? 'ready' : status,\n onRetry: retry,\n },\n editorProps: {\n markdown: session.content,\n onChange: session.change,\n onNormalized: session.normalized,\n },\n redlineProps: {\n state: redline.state,\n onRevert: (regionId) => void session.revertRegion(regionId),\n },\n }),\n [session, redline, isLoading, status, retry, isLocal, versions, docId]\n )\n}\n","import { useQuery } from '@tanstack/react-query'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../query-keys'\n\n/**\n * The stored source of a live artifact (the `.html` / `.jsx` file itself; the parsed text strips\n * it). `undefined` until it has loaded.\n */\nexport function useArtifactSource(documentId: string | null | undefined, enabled = true) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.artifactSource(documentId ?? ''),\n queryFn: async () => (await arbi.documents.download(documentId as string)).text(),\n enabled: enabled && !!documentId && arbi.isLoggedIn,\n staleTime: 5 * 60 * 1000,\n })\n}\n","import type { ComponentPropsWithoutRef, FC, ReactNode } from 'react'\nimport { MarkdownRenderer } from '../ai/MarkdownRenderer'\n\n/** The `<del>` / `<ins>` renderers `ArtifactRedlineView` hands to a markdown renderer. */\nexport interface ArtifactRedlineComponents {\n del: FC<ComponentPropsWithoutRef<'del'> & { 'data-cid'?: string }>\n ins: FC<ComponentPropsWithoutRef<'ins'> & { 'data-cid'?: string }>\n}\n\n/**\n * The kit's markdown renderer as the `renderMarkdown` slot of `ArtifactEditor` and\n * `ArtifactRedlineView`: full markdown (tables, lists, code) plus the raw `<del>` / `<ins>` tags\n * of a redline.\n */\nexport function renderArtifactMarkdown(\n markdown: string,\n components?: ArtifactRedlineComponents\n): ReactNode {\n return <MarkdownRenderer components={components}>{markdown}</MarkdownRenderer>\n}\n","import { useCallback, useEffect, useRef, useState } from 'react'\nimport type { ArtifactEvent } from '../ai/engine'\nimport { cleanDraftWithReport, type DraftCleanReport } from '../ai/stored-markdown'\nimport { useSaveArtifactVersion } from './useArtifactSession'\nimport { isDocumentId } from './versions'\nimport { useArtifactText, type ArtifactTextRetry } from './useArtifactText'\n\n/**\n * Where a drafted artifact is in its STREAM -> PERSIST -> EDIT life:\n * - `streaming`: the agent is still working (or has produced nothing final): show the live canvas;\n * - `persisting`: the finished draft is being stored as version 1 of the artifact;\n * - `parsing`: stored; the backend is still parsing it, so there is no editable text yet;\n * - `ready`: the text is readable: mount the editor on `docId`;\n * - `error`: storing failed or the parse never produced text (`retry()` starts over).\n */\nexport type StreamedArtifactPhase = 'streaming' | 'persisting' | 'parsing' | 'ready' | 'error'\n\nexport interface UseStreamedArtifactOptions {\n /** The artifacts of the agent run (`useConnectedAiTask().artifacts`). */\n artifacts: ArtifactEvent[]\n workspaceId: string | undefined\n /**\n * The run has stopped: not busy and not failed. Nothing is stored before this, so a draft that\n * is still streaming is never persisted half-written.\n */\n settled: boolean\n /**\n * Make the stored markdown from the streamed content. Default `cleanDraftWithReport`, which is\n * guarded: it stores the raw streamed text (or links-only text) rather than a cleanup that would\n * lose content (see `DraftCleanReport`).\n */\n clean?: (streamed: string) => string\n /** Called once per stored draft with what the cleanup did (`stage` is not `cleaned` if guarded). */\n onCleaned?: (report: DraftCleanReport) => void\n /** Processing config for the stored version. */\n configId?: string | null\n /** How long to wait for the parse (see `useArtifactText`). */\n parseRetry?: ArtifactTextRetry\n}\n\nexport interface StreamedArtifact {\n phase: StreamedArtifactPhase\n /** The finished streamed artifact (its `title` names the stored versions). */\n artifact: ArtifactEvent | undefined\n /** The backend document to edit, once there is one (while `parsing` and `ready`). */\n docId: string | undefined\n error: Error | null\n /** What the cleanup did to the stored draft (`null` until it was stored, or with a custom `clean`). */\n cleaned: DraftCleanReport | null\n /** After an `error`: store again or ask for the parse again. */\n retry: () => void\n}\n\n/**\n * The lifecycle of an agent-drafted artifact, so a host passes the stream and renders the phase.\n *\n * While the agent streams, the draft lives only on the canvas. Once the run is `settled` and the\n * draft is complete, a draft that is not yet a backend document is cleaned (`cleanDraftMarkdown`)\n * and stored ONCE as the artifact's first version (`wpType: 'artifact'`); a draft that already is a\n * backend document passes through. The hook then waits for the parse (`useArtifactText`, which\n * retries) and reports `ready` with the `docId` to open in an editor.\n *\n * Needs an `<ArbiHost>` with an `arbi` and a workspace. `@arbidocs/blocks/connect` has the whole thing as a\n * component (`StreamedArtifact`).\n */\nexport function useStreamedArtifact({\n artifacts,\n workspaceId,\n settled,\n clean,\n onCleaned,\n configId,\n parseRetry,\n}: UseStreamedArtifactOptions): StreamedArtifact {\n const artifact = artifacts.find((a) => a.is_complete)\n const { mutateAsync } = useSaveArtifactVersion()\n const [saved, setSaved] = useState<{ content: string; docId: string } | null>(null)\n const [saveError, setSaveError] = useState<Error | null>(null)\n const [attempt, setAttempt] = useState(0)\n const [cleaned, setCleaned] = useState<DraftCleanReport | null>(null)\n const started = useRef<string | null>(null)\n\n const content = artifact?.content ?? ''\n const title = artifact?.title ?? 'Draft'\n const passThrough = !!artifact && isDocumentId(artifact.doc_ext_id)\n const needsSave = settled && !!artifact && !passThrough && !!content.trim() && !!workspaceId\n\n useEffect(() => {\n const key = `${attempt}:${content}`\n if (!needsSave || started.current === key) return\n started.current = key\n setSaveError(null)\n let stored: string\n if (clean) stored = clean(content)\n else {\n const report = cleanDraftWithReport(content)\n stored = report.text\n setCleaned(report)\n onCleaned?.(report)\n if (report.guarded) {\n console.warn(\n `[useStreamedArtifact] the draft cleanup would have lost content; stored the ${report.stage} text instead (kept ${Math.round(report.ratio * 100)}%, changed by: ${report.changedBy.join(', ') || 'nothing'})`\n )\n }\n }\n mutateAsync({\n title,\n content: stored,\n configId,\n wpType: 'artifact',\n })\n .then((r) => {\n if (r.docId) setSaved({ content, docId: r.docId })\n else setSaveError(new Error('The draft was stored but the server returned no document id'))\n })\n .catch((e: unknown) => setSaveError(e instanceof Error ? e : new Error(String(e))))\n // `clean` and `onCleaned` are deliberately not dependencies: a new function identity must not\n // store twice.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [needsSave, content, title, workspaceId, configId, attempt, mutateAsync])\n\n const docId = !artifact\n ? undefined\n : passThrough\n ? artifact.doc_ext_id\n : saved?.content === content\n ? saved.docId\n : undefined\n\n const text = useArtifactText(docId, { enabled: settled, retry: parseRetry })\n const { retry: retryText } = text\n\n const retry = useCallback(() => {\n if (saveError) setAttempt((n) => n + 1)\n else retryText()\n }, [saveError, retryText])\n\n let phase: StreamedArtifactPhase\n if (!settled || !artifact) phase = 'streaming'\n else if (saveError) phase = 'error'\n else if (!docId) phase = needsSave ? 'persisting' : 'streaming'\n else if (text.status === 'ready' && text.text) phase = 'ready'\n else if (text.status === 'error' || text.status === 'ready') phase = 'error'\n else phase = 'parsing'\n\n const error =\n phase !== 'error'\n ? null\n : (saveError ?? text.error ?? new Error('The document has no text to edit'))\n return { phase, artifact, docId, error, cleaned, retry }\n}\n","/**\n * Which live renderer, if any, an artifact maps to. Kept free of heavy imports (no compiler) so the\n * document viewer can use it without pulling the preview code into its bundle.\n *\n * The backend persists an artifact's render mode in the saved file's extension: .html / .jsx are live\n * artifacts; document drafts are stored as .docx and open in the Word editor.\n */\nexport type ArtifactPreviewKind = 'html' | 'react'\n\nexport function artifactKindFromFileName(fileName?: string | null): ArtifactPreviewKind | null {\n const ext = (fileName ?? '').toLowerCase().match(/\\.[a-z0-9]+$/)?.[0]\n if (ext === '.html' || ext === '.htm') return 'html'\n if (ext === '.jsx') return 'react'\n return null\n}\n\nexport function artifactKindFromMode(mode?: string | null): ArtifactPreviewKind | null {\n return mode === 'html' || mode === 'react' ? mode : null\n}\n\n/**\n * The viewer tab an artifact opens on: a generated image on its media view ('pdf'), an html/react\n * artifact on its rendered Preview, and a document draft (stored as .docx) in the Word editor.\n */\nexport function viewerTabForArtifactMode(mode?: string | null): 'pdf' | 'preview' | 'edit' {\n if (mode === 'image') return 'pdf'\n return artifactKindFromMode(mode) ? 'preview' : 'edit'\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
3
|
+
var chunkA5BJZ4ZN_cjs = require('../../chunk-A5BJZ4ZN.cjs');
|
|
4
|
+
require('../../chunk-5N3UFEXE.cjs');
|
|
5
5
|
require('../../chunk-U4PWVSCT.cjs');
|
|
6
6
|
var chunk5YGUBXXH_cjs = require('../../chunk-5YGUBXXH.cjs');
|
|
7
7
|
var chunkDZUBZ45Y_cjs = require('../../chunk-DZUBZ45Y.cjs');
|
|
@@ -125,8 +125,8 @@ function useCallTranscriber({
|
|
|
125
125
|
const arbi = chunk5YGUBXXH_cjs.useArbi();
|
|
126
126
|
const queryClient = reactQuery.useQueryClient();
|
|
127
127
|
const profile = arbi.isLoggedIn ? arbi.user.profile() : null;
|
|
128
|
-
const myProfileName = profile &&
|
|
129
|
-
const deploymentAvailable =
|
|
128
|
+
const myProfileName = profile && chunkA5BJZ4ZN_cjs.toProfileView(profile).fullName || null;
|
|
129
|
+
const deploymentAvailable = chunkA5BJZ4ZN_cjs.useCallTranscriptionAvailable();
|
|
130
130
|
const available = deploymentAvailable && !!callKey;
|
|
131
131
|
const [state, setState] = react.useState(null);
|
|
132
132
|
const [creatorExtId, setCreatorExtId] = react.useState(null);
|
|
@@ -169,7 +169,7 @@ function useCallTranscriber({
|
|
|
169
169
|
};
|
|
170
170
|
}, [available, callExtId]);
|
|
171
171
|
react.useEffect(
|
|
172
|
-
() =>
|
|
172
|
+
() => chunkA5BJZ4ZN_cjs.onCallEvent("call.transcription", (message) => {
|
|
173
173
|
if (message.call_ext_id === callExtId) applyState(message);
|
|
174
174
|
}),
|
|
175
175
|
[callExtId, applyState]
|
|
@@ -185,7 +185,7 @@ function useCallTranscriber({
|
|
|
185
185
|
const persist = react.useCallback(
|
|
186
186
|
(segment, speakerNeedsProxy) => {
|
|
187
187
|
if (!callKey || persisted.current.has(segment.segmentId)) return;
|
|
188
|
-
const role =
|
|
188
|
+
const role = chunkA5BJZ4ZN_cjs.transcriptPersistRole({
|
|
189
189
|
myIdentity,
|
|
190
190
|
canPost: canPost && (segment.speakerIdentity !== myIdentity || selfPosts.current),
|
|
191
191
|
hasCallKey: true,
|
|
@@ -194,7 +194,7 @@ function useCallTranscriber({
|
|
|
194
194
|
});
|
|
195
195
|
if (!role) return;
|
|
196
196
|
persisted.current.add(segment.segmentId);
|
|
197
|
-
|
|
197
|
+
chunkA5BJZ4ZN_cjs.persistTranscriptSegment(arbi, queryClient, callExtId, callKey, segment).catch(
|
|
198
198
|
(err) => {
|
|
199
199
|
persisted.current.delete(segment.segmentId);
|
|
200
200
|
if (role === "own" && err?.status === 403) {
|
|
@@ -214,7 +214,7 @@ function useCallTranscriber({
|
|
|
214
214
|
);
|
|
215
215
|
react.useEffect(() => {
|
|
216
216
|
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
217
|
-
if (topic ===
|
|
217
|
+
if (topic === chunkA5BJZ4ZN_cjs.CALL_TRANSCRIPTION_TOPIC) {
|
|
218
218
|
if (participant || participantIdentity) return;
|
|
219
219
|
try {
|
|
220
220
|
const next = browser.calls.transcriptionStateFrom(JSON.parse(new TextDecoder().decode(payload)));
|
|
@@ -223,10 +223,10 @@ function useCallTranscriber({
|
|
|
223
223
|
}
|
|
224
224
|
return;
|
|
225
225
|
}
|
|
226
|
-
if (topic !==
|
|
226
|
+
if (topic !== chunkA5BJZ4ZN_cjs.CALL_CAPTION_TOPIC || !callKey) return;
|
|
227
227
|
const identity = participant?.identity ?? participantIdentity;
|
|
228
228
|
if (!identity || identity === myIdentity) return;
|
|
229
|
-
void
|
|
229
|
+
void chunkA5BJZ4ZN_cjs.decodeCaptionPacket(payload, callKey).then((packet) => {
|
|
230
230
|
if (!packet || packet.identity !== identity) return;
|
|
231
231
|
const name = participant?.name || packet.name || identity;
|
|
232
232
|
const t = Math.min(packet.t, Date.now());
|
|
@@ -266,7 +266,7 @@ function useCallTranscriber({
|
|
|
266
266
|
})) {
|
|
267
267
|
return;
|
|
268
268
|
}
|
|
269
|
-
const segmentId =
|
|
269
|
+
const segmentId = chunkA5BJZ4ZN_cjs.newSegmentId();
|
|
270
270
|
const startedAt = new Date(segment.startedAt).toISOString();
|
|
271
271
|
let text;
|
|
272
272
|
try {
|
|
@@ -300,7 +300,7 @@ function useCallTranscriber({
|
|
|
300
300
|
});
|
|
301
301
|
try {
|
|
302
302
|
await localParticipant.publishData(
|
|
303
|
-
await
|
|
303
|
+
await chunkA5BJZ4ZN_cjs.encodeCaptionPacket(
|
|
304
304
|
{
|
|
305
305
|
v: 1,
|
|
306
306
|
segment_id: segmentId,
|
|
@@ -312,7 +312,7 @@ function useCallTranscriber({
|
|
|
312
312
|
},
|
|
313
313
|
callKey
|
|
314
314
|
),
|
|
315
|
-
{ reliable: true, topic:
|
|
315
|
+
{ reliable: true, topic: chunkA5BJZ4ZN_cjs.CALL_CAPTION_TOPIC }
|
|
316
316
|
);
|
|
317
317
|
} catch (err) {
|
|
318
318
|
console.warn("[calls] could not broadcast a caption", err);
|
|
@@ -427,14 +427,14 @@ function useCallRecorder({
|
|
|
427
427
|
};
|
|
428
428
|
}, [callExtId]);
|
|
429
429
|
react.useEffect(
|
|
430
|
-
() =>
|
|
430
|
+
() => chunkA5BJZ4ZN_cjs.onCallEvent("call.recording", (message) => {
|
|
431
431
|
if (message.call_ext_id === callExtId) applyState(message);
|
|
432
432
|
}),
|
|
433
433
|
[callExtId, applyState]
|
|
434
434
|
);
|
|
435
435
|
react.useEffect(() => {
|
|
436
436
|
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
437
|
-
if (topic !==
|
|
437
|
+
if (topic !== chunkA5BJZ4ZN_cjs.CALL_RECORDING_TOPIC) return;
|
|
438
438
|
if (participant || participantIdentity) return;
|
|
439
439
|
try {
|
|
440
440
|
const next = browser.calls.recordingStateFrom(JSON.parse(new TextDecoder().decode(payload)));
|
|
@@ -455,7 +455,7 @@ function useCallRecorder({
|
|
|
455
455
|
try {
|
|
456
456
|
const row = call ?? await arbi.calls.get(callExtId);
|
|
457
457
|
if (!row.workspace_locked && !row.chat_ext_id && callKey) {
|
|
458
|
-
const ref = await
|
|
458
|
+
const ref = await chunkA5BJZ4ZN_cjs.ensureMeetingChat(arbi, queryClient, callExtId, callKey);
|
|
459
459
|
if (ref.kind === "chat") setCall({ ...row, chat_ext_id: ref.chatExtId });
|
|
460
460
|
}
|
|
461
461
|
const answer = await arbi.calls.recording.start(callExtId, mode);
|
|
@@ -557,7 +557,7 @@ function useTrackUploader(recording, callKey, kind, mimeType) {
|
|
|
557
557
|
const queryClient = reactQuery.useQueryClient();
|
|
558
558
|
return react.useMemo(() => {
|
|
559
559
|
if (!shouldCapture || !recordingExtId || !call) return null;
|
|
560
|
-
return
|
|
560
|
+
return chunkA5BJZ4ZN_cjs.trackUploaderFor({
|
|
561
561
|
arbi,
|
|
562
562
|
callExtId: call.external_id,
|
|
563
563
|
recordingExtId,
|
|
@@ -565,7 +565,7 @@ function useTrackUploader(recording, callKey, kind, mimeType) {
|
|
|
565
565
|
mimeType,
|
|
566
566
|
recordingStartedAt: startedAt,
|
|
567
567
|
linkVersion,
|
|
568
|
-
conversationKey: () =>
|
|
568
|
+
conversationKey: () => chunkA5BJZ4ZN_cjs.conversationKeyForCall(arbi, queryClient, call, { callKey }),
|
|
569
569
|
// The server stopped the recording at the quota (its state event says so too).
|
|
570
570
|
onStopped: () => markStopped()
|
|
571
571
|
});
|
|
@@ -614,10 +614,10 @@ function useInCallChat({
|
|
|
614
614
|
react.useEffect(() => {
|
|
615
615
|
if (!callKey) return;
|
|
616
616
|
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
617
|
-
if (topic !==
|
|
617
|
+
if (topic !== chunkA5BJZ4ZN_cjs.CALL_CHAT_TOPIC) return;
|
|
618
618
|
const identity = participant?.identity ?? participantIdentity;
|
|
619
619
|
if (!identity || identity === myIdentity) return;
|
|
620
|
-
void
|
|
620
|
+
void chunkA5BJZ4ZN_cjs.decodeCallChatPacket(payload, callKey).then((packet) => {
|
|
621
621
|
if (!packet) return;
|
|
622
622
|
const key = `${identity}:${packet.id}`;
|
|
623
623
|
if (seen.current.has(key)) return;
|
|
@@ -647,7 +647,7 @@ function useInCallChat({
|
|
|
647
647
|
if (!open || !canRead || historyRequested.current) return;
|
|
648
648
|
historyRequested.current = true;
|
|
649
649
|
setHistoryLoading(true);
|
|
650
|
-
|
|
650
|
+
chunkA5BJZ4ZN_cjs.loadMeetingHistory(arbi, queryClient, callExtId).then((result) => {
|
|
651
651
|
if (!result) return;
|
|
652
652
|
setMeetingChat(result.ref);
|
|
653
653
|
setHistory(result.messages);
|
|
@@ -658,13 +658,13 @@ function useInCallChat({
|
|
|
658
658
|
}, [open, canRead, callExtId]);
|
|
659
659
|
const send = react.useCallback(
|
|
660
660
|
async (raw) => {
|
|
661
|
-
const text = raw.trim().slice(0,
|
|
661
|
+
const text = raw.trim().slice(0, chunkA5BJZ4ZN_cjs.CALL_CHAT_MAX_CHARS);
|
|
662
662
|
if (!text || !callKey || readOnly) return;
|
|
663
|
-
const id =
|
|
663
|
+
const id = chunkA5BJZ4ZN_cjs.newPacketId();
|
|
664
664
|
const at = Date.now();
|
|
665
665
|
await localParticipant.publishData(
|
|
666
|
-
await
|
|
667
|
-
{ reliable: true, topic:
|
|
666
|
+
await chunkA5BJZ4ZN_cjs.encodeCallChatPacket({ v: 1, id, text, at }, callKey),
|
|
667
|
+
{ reliable: true, topic: chunkA5BJZ4ZN_cjs.CALL_CHAT_TOPIC }
|
|
668
668
|
);
|
|
669
669
|
setLive((prev) => [
|
|
670
670
|
...prev,
|
|
@@ -683,7 +683,7 @@ function useInCallChat({
|
|
|
683
683
|
(prev) => prev.map((l) => l.id === id && l.senderIdentity === myIdentity ? { ...l, status } : l)
|
|
684
684
|
);
|
|
685
685
|
try {
|
|
686
|
-
setMeetingChat(await
|
|
686
|
+
setMeetingChat(await chunkA5BJZ4ZN_cjs.persistMeetingMessage(arbi, queryClient, callExtId, callKey, text));
|
|
687
687
|
mark("saved");
|
|
688
688
|
} catch (err) {
|
|
689
689
|
console.warn("[calls] could not keep the message in the meeting chat", err);
|
|
@@ -695,7 +695,7 @@ function useInCallChat({
|
|
|
695
695
|
const openMeeting = react.useCallback(async () => {
|
|
696
696
|
if (!callKey) return;
|
|
697
697
|
try {
|
|
698
|
-
const ref = meetingChat ?? await
|
|
698
|
+
const ref = meetingChat ?? await chunkA5BJZ4ZN_cjs.ensureMeetingChat(arbi, queryClient, callExtId, callKey);
|
|
699
699
|
setMeetingChat(ref);
|
|
700
700
|
openMeetingChat?.(ref);
|
|
701
701
|
} catch (err) {
|
|
@@ -703,7 +703,7 @@ function useInCallChat({
|
|
|
703
703
|
}
|
|
704
704
|
}, [callExtId, callKey, meetingChat]);
|
|
705
705
|
const lines = react.useMemo(
|
|
706
|
-
() =>
|
|
706
|
+
() => chunkA5BJZ4ZN_cjs.mergeChatLines(history, live, {
|
|
707
707
|
myIdentity,
|
|
708
708
|
nameOf: (identity) => identity === myIdentity ? localParticipant.name || "You" : room.remoteParticipants.get(identity)?.name || null
|
|
709
709
|
}),
|
|
@@ -762,7 +762,7 @@ function useWebinar({
|
|
|
762
762
|
const n = ++questionsRead.current;
|
|
763
763
|
try {
|
|
764
764
|
const rows = await webinarApi().questions.list(callExtId, linkVersion);
|
|
765
|
-
const opened = await Promise.all(rows.map((q) =>
|
|
765
|
+
const opened = await Promise.all(rows.map((q) => chunkA5BJZ4ZN_cjs.openQuestion(q, callKey)));
|
|
766
766
|
if (n === questionsRead.current) setQuestions(opened);
|
|
767
767
|
} catch (err) {
|
|
768
768
|
console.warn("[calls] could not load the questions", err);
|
|
@@ -774,7 +774,7 @@ function useWebinar({
|
|
|
774
774
|
}, [refresh, refreshQuestions]);
|
|
775
775
|
react.useEffect(() => {
|
|
776
776
|
if (!enabled) return;
|
|
777
|
-
return
|
|
777
|
+
return chunkA5BJZ4ZN_cjs.onCallEvent("call.webinar", (m) => {
|
|
778
778
|
if (m.call_ext_id !== callExtId) return;
|
|
779
779
|
setState((s) => s ? { ...s, live: m.live, chat: m.chat } : s);
|
|
780
780
|
});
|
|
@@ -783,8 +783,8 @@ function useWebinar({
|
|
|
783
783
|
react.useEffect(() => {
|
|
784
784
|
if (!enabled) return;
|
|
785
785
|
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
786
|
-
if (topic !==
|
|
787
|
-
const packet =
|
|
786
|
+
if (topic !== chunkA5BJZ4ZN_cjs.CALL_WEBINAR_TOPIC) return;
|
|
787
|
+
const packet = chunkA5BJZ4ZN_cjs.parseWebinarPacket(payload, !!(participant || participantIdentity));
|
|
788
788
|
if (!packet) return;
|
|
789
789
|
switch (packet.type) {
|
|
790
790
|
case "state":
|
|
@@ -805,7 +805,7 @@ function useWebinar({
|
|
|
805
805
|
return;
|
|
806
806
|
case "demoted":
|
|
807
807
|
setStageCheck(false);
|
|
808
|
-
|
|
808
|
+
chunkA5BJZ4ZN_cjs.markRejoining(callExtId);
|
|
809
809
|
if (fallback.current) clearTimeout(fallback.current);
|
|
810
810
|
fallback.current = setTimeout(() => void room.disconnect(), DEMOTE_REJOIN_FALLBACK_MS);
|
|
811
811
|
return;
|
|
@@ -832,12 +832,12 @@ function useWebinar({
|
|
|
832
832
|
[callExtId, linkVersion]
|
|
833
833
|
);
|
|
834
834
|
const stepDown = react.useCallback(async () => {
|
|
835
|
-
|
|
835
|
+
chunkA5BJZ4ZN_cjs.markRejoining(callExtId);
|
|
836
836
|
setStageCheck(false);
|
|
837
837
|
try {
|
|
838
838
|
await webinarApi().demote(callExtId, myIdentity, linkVersion);
|
|
839
839
|
} catch (err) {
|
|
840
|
-
|
|
840
|
+
chunkA5BJZ4ZN_cjs.markRejoining(callExtId, false);
|
|
841
841
|
failed("leave the stage")(err);
|
|
842
842
|
}
|
|
843
843
|
}, [callExtId, myIdentity, linkVersion]);
|
|
@@ -897,7 +897,7 @@ function useWebinar({
|
|
|
897
897
|
if (!callKey) throw new Error("This call has no key.");
|
|
898
898
|
await webinarApi().questions.ask(
|
|
899
899
|
callExtId,
|
|
900
|
-
await
|
|
900
|
+
await chunkA5BJZ4ZN_cjs.sealQuestionText(text, callKey),
|
|
901
901
|
linkVersion
|
|
902
902
|
);
|
|
903
903
|
}, "ask the question"),
|
|
@@ -911,7 +911,7 @@ function useWebinar({
|
|
|
911
911
|
await webinarApi().questions.update(
|
|
912
912
|
callExtId,
|
|
913
913
|
id,
|
|
914
|
-
{ answer: await
|
|
914
|
+
{ answer: await chunkA5BJZ4ZN_cjs.sealQuestionText(text, callKey) },
|
|
915
915
|
linkVersion
|
|
916
916
|
);
|
|
917
917
|
}, "answer the question"),
|
|
@@ -941,15 +941,15 @@ function useWebinar({
|
|
|
941
941
|
function useHostMuteNotice(callExtId) {
|
|
942
942
|
const room = componentsReact.useRoomContext();
|
|
943
943
|
react.useEffect(() => {
|
|
944
|
-
const notifyMuted =
|
|
944
|
+
const notifyMuted = chunkA5BJZ4ZN_cjs.createMutedNotifier((text) => chunkDZUBZ45Y_cjs.notify.info(text));
|
|
945
945
|
const onData = (payload, participant, _kind, topic, _encryption, participantIdentity) => {
|
|
946
|
-
if (topic !==
|
|
946
|
+
if (topic !== chunkA5BJZ4ZN_cjs.CALL_MODERATION_TOPIC) return;
|
|
947
947
|
if (participant || participantIdentity) return;
|
|
948
|
-
const notice =
|
|
948
|
+
const notice = chunkA5BJZ4ZN_cjs.mutedNoticeFromPacket(payload);
|
|
949
949
|
if (notice) notifyMuted(notice);
|
|
950
950
|
};
|
|
951
951
|
room.on(livekitClient.RoomEvent.DataReceived, onData);
|
|
952
|
-
const offWs =
|
|
952
|
+
const offWs = chunkA5BJZ4ZN_cjs.onCallEvent("call.muted", (message) => {
|
|
953
953
|
if (message.callExtId === callExtId) notifyMuted(message);
|
|
954
954
|
});
|
|
955
955
|
return () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { toProfileView, useCallTranscriptionAvailable, onCallEvent, transcriptPersistRole, persistTranscriptSegment, newSegmentId, encodeCaptionPacket, CALL_CAPTION_TOPIC, ensureMeetingChat, trackUploaderFor, conversationKeyForCall, loadMeetingHistory, CALL_CHAT_MAX_CHARS, newPacketId, encodeCallChatPacket, CALL_CHAT_TOPIC, persistMeetingMessage, mergeChatLines, openQuestion, markRejoining, sealQuestionText, createMutedNotifier, CALL_RECORDING_TOPIC, CALL_TRANSCRIPTION_TOPIC, decodeCaptionPacket, CALL_MODERATION_TOPIC, mutedNoticeFromPacket, decodeCallChatPacket, CALL_WEBINAR_TOPIC, parseWebinarPacket } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
1
|
+
import { toProfileView, useCallTranscriptionAvailable, onCallEvent, transcriptPersistRole, persistTranscriptSegment, newSegmentId, encodeCaptionPacket, CALL_CAPTION_TOPIC, ensureMeetingChat, trackUploaderFor, conversationKeyForCall, loadMeetingHistory, CALL_CHAT_MAX_CHARS, newPacketId, encodeCallChatPacket, CALL_CHAT_TOPIC, persistMeetingMessage, mergeChatLines, openQuestion, markRejoining, sealQuestionText, createMutedNotifier, CALL_RECORDING_TOPIC, CALL_TRANSCRIPTION_TOPIC, decodeCaptionPacket, CALL_MODERATION_TOPIC, mutedNoticeFromPacket, decodeCallChatPacket, CALL_WEBINAR_TOPIC, parseWebinarPacket } from '../../chunk-RXPBHHX2.js';
|
|
2
|
+
import '../../chunk-CQYJQWJY.js';
|
|
3
3
|
import '../../chunk-TK7ERJPE.js';
|
|
4
4
|
import { useArbi, useArbiHost } from '../../chunk-2Y6LJNWA.js';
|
|
5
5
|
import { notify } from '../../chunk-G4Z3IP4J.js';
|