"use client" // Upload and index: the browser sends the file to the files module (the kit's `uploadFile`), then // asks this module to index it (`knowledge.document.index`). The indexing itself is a worker job; // this form only ever waits on the request, which resolves once the live stream has seen the document's // row, so the collection's live list already shows it queued. import type { ProjectSlugs } from "@conusai-kit/ui" import { useUpload, useWrite } from "@conusai-kit/ui/data" import { FormLayout, PageSection, TextField } from "@conusai-kit/ui/patterns" import { type ReactElement, useState } from "react" import { INDEXABLE_CONTENT_TYPES, MAX_INDEX_BYTES } from "../contract/index.js" export interface IndexFormLabels { readonly heading: string readonly label: string readonly hint: string readonly submit: string readonly busy: string readonly done: string } export function IndexForm({ slugs, collectionName, labels, }: { slugs: ProjectSlugs collectionName: string labels: IndexFormLabels }): ReactElement { const upload = useUpload() const indexDocument = useWrite( "knowledge.document.index", { org: slugs.org }, ) const [done, setDone] = useState(false) const index = async (_: unknown, data: FormData): Promise => { const file = data.get("file") if (!(file instanceof File) || file.size === 0) return setDone(false) const stored = await upload(slugs, file) await indexDocument.mutate({ ...slugs, collectionName, fileId: stored.fileId }) setDone(true) } return ( {done ?

{labels.done}

: null}
) }