The files and custom instructions an assistant reads in every chat of a project, with Add and a drop zone.
Project knowledge
- Customer feedback transcript.pdf402 KB · Added this minute
- Survey results.docx86 KB · Added 18 hours ago
2 files · 488 KB
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { ProjectKnowledge } from "./ui/uicontext/components/chat/ProjectKnowledge.ts"import { KnowledgeFile } from "./ui/uicontext/components/domain/Chat.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const now = "2026-12-01T10:00:00Z"const Message = UiSchema.TaggedEnum({ AddedFiles: { files: Schema.Array(Schema.Struct({ name: Schema.String, size: Schema.Number, type: Schema.String })) }, RemovedFile: { id: Schema.String }, SavedInstructions: { instructions: Schema.String },})const styles = stylex.create({ frame: { width: "min(100%, 22rem)" } })export const ProjectKnowledgeDemo = Html.component({ name: "ProjectKnowledgeDemo", model: Schema.Struct({ files: Schema.Array(KnowledgeFile), instructions: Schema.String, added: Schema.Number }), message: Message,}).make({ init: () => ({ files: [ { id: "a", name: "Customer feedback transcript.pdf", size: 412_000, type: "application/pdf", addedAt: "2026-12-01T09:59:30Z" }, { id: "b", name: "Survey results.docx", size: 88_000, addedAt: "2026-11-30T16:00:00Z" }, ], instructions: "", added: 0, }), update: { AddedFiles: ($, { files }) => $.evolve({ added: (n) => n + files.length, files: (all) => [...files.map((f, i) => ({ id: `new-${$.model.added + i}`, name: f.name, size: f.size, type: f.type, addedAt: now })), ...all], }), RemovedFile: ($, { id }) => $.evolve({ files: (all) => all.filter((f) => f.id !== id) }), SavedInstructions: ($, { instructions }) => $.evolve({ instructions }), }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( ProjectKnowledge(h, { props: { files: model.files, instructions: model.instructions, now }, onEmit: { RequestedAdd: ({ files }) => Message.AddedFiles({ files: files.map((f) => ({ name: f.name, size: f.size, type: f.type })) }), RequestedRemove: ({ id }) => Message.RemovedFile({ id }), RequestedInstructions: ({ instructions }) => Message.SavedInstructions({ instructions }), }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/project-knowledgeUsage
import { ProjectKnowledge } from "./ui/uicontext/components/chat/ProjectKnowledge.ts"import type { KnowledgeFile } from "./ui/uicontext/components/domain/Chat.ts"const Message = UiSchema.TaggedEnum({ AddedKnowledge: { files: Schema.Array(Schema.instanceOf(File)) }, RemovedKnowledge: { id: Schema.String }, SavedInstructions: { instructions: Schema.String },})// the project owns its files and instructions: upload what's added, store what's savedexport const Knowledge = (h: Html.H<typeof Message.Type>, files: ReadonlyArray<KnowledgeFile>, instructions: string, now: string) => ProjectKnowledge(h, { props: { files, instructions, now }, onEmit: { RequestedAdd: ({ files: added }) => Message.AddedKnowledge({ files: added }), RequestedRemove: ({ id }) => Message.RemovedKnowledge({ id }), RequestedInstructions: ({ instructions: text }) => Message.SavedInstructions({ instructions: text }), }, })API reference
Props
| Name | Type | Description |
|---|---|---|
filesrequired | KnowledgeFile[] | — |
instructionsrequired | string | The project's custom instructions; empty for none |
nowrequired | string | The present, ISO, for "Added 2 hours ago" |
label | string | The card's heading: "Project knowledge" by default |
agentId | string | The id agents see this card by |
adding | number | Files on their way in, shown as a status line |
Events
| Event | Payload | Description |
|---|---|---|
RequestedAdd | { files: Files } | Files picked or dropped, to add to the project |
RequestedRemove | { id: string } | — |
RequestedInstructions | { instructions: string } | Store these as the project's instructions; empty clears them |
Agent actions
| Action | Description |
|---|---|
SubmittedInstructions | Set the project's custom instructions: how the assistant should behave and answer in this project. Empty clears them. |
ClickedRemoveFile | Remove a file from the project, by id |
Accessibility
- Add is a real file input behind a label, so it works from the keyboard and with a screen reader. Dropping files on the card does the same.
- Long file names are cut in the middle so the extension stays; the full name is the row's tooltip.
- Instructions count their characters as you type and refuse to save past the limit; Escape cancels.