@instructure/platform-study-assist
v2.8.1
Published
Study Assist UI: a context provider plus `AssistContent` component for rendering prompt chips, flashcards, and quizzes returned by an assistant backend.
Keywords
Readme
@instructure/platform-study-assist
Study Assist UI: a context provider plus AssistContent component for rendering prompt chips, flashcards, and quizzes returned by an assistant backend.
Installation
# in canvas-lms
yarn add -W @instructure/platform-study-assist-W adds to the root workspace.
Usage
<AssistProvider fetchAssistResponse={fetchAssistResponse} courseId={courseId}>
<AssistContent allowedPrompts={[{ kind: 'summarize' }, { kind: 'flashcards' }]} />
</AssistProvider>Tool-aware heading (currentTool)
The host owns the tray header. To make the heading reflect the active study tool
instead of a static "Study tools" label, read currentTool from the context —
the same way showBackButton is consumed for the back arrow:
const { currentTool } = useAssistContext()
const headingByTool: Record<NonNullable<typeof currentTool>, string> = {
summarize: I18n.t('Summarize'),
quiz: I18n.t('Quiz Me'),
flashcards: I18n.t('Flashcards'),
}
const heading = currentTool ? headingByTool[currentTool] : I18n.t('Study tools')currentTool is 'summarize' | 'quiz' | 'flashcards' | null, derived from the
active view. It is null on the prompt-selection view, where the host should
fall back to its default heading. Keeping the title mapping host-side preserves
locale ownership (the package never ships display strings).
allowedPrompts contract
AssistContent accepts an optional allowedPrompts prop to filter the chips returned by the server. Two shapes are accepted:
| Form | Type | Behavior |
|---|---|---|
| Stable-kind (preferred) | { kind: string }[] | Filters by each chip's kind field. Locale-independent — translating a chip's shortMessage has no effect on which chips render. |
| Legacy (deprecated) | string[] | Filters by each chip's localized shortMessage. Emits a one-time console.warn and will be removed in the next major version. |
An empty array ([]) in either form filters out all chips. Omitting the prop (or passing undefined) shows every chip.
For kind filtering to work, the backend must emit a kind field on each chip in the assist response. Chips without a kind are excluded from the result when using the stable-kind form.
Migration
Replace localized-string allowlists with stable kinds:
- <AssistContent allowedPrompts={[I18n.t('Summarize'), I18n.t('Quiz me')]} />
+ <AssistContent allowedPrompts={[{ kind: 'summarize' }, { kind: 'quiz' }]} />Development
pnpm build # vite build
pnpm dev # vite build --watch
pnpm test # vitest run
pnpm lint # biome + ast-grep
pnpm type-check # tsc
pnpm pack:tarball # build + pnpm pack (for local consumption from canvas-lms)See the monorepo root PACK_WORKFLOW.md for the canvas-lms integration loop.
