@gridsay/mui-x-data-grid is the Gridsay helper for MUI X Data Grid Premium. It is ESM only, MIT licensed, and depends on @gridsay/core. Its peer dependency is @mui/x-data-grid-premium ^9.18.0.
npm install @gridsay/mui-x-data-gridHow to use it: Using the helper.
| Export | Kind | What it is |
|---|---|---|
createPromptResolver | Function | Takes PromptResolverOptions; returns a PromptResolver to pass as the grid's onPrompt |
PromptResolverOptions | Type | The options below |
PromptResolver | Type | NonNullable<DataGridPremiumProps['onPrompt']>: takes the question, MUI's column context and the conversation id; resolves with the answer for the grid |
GridsayError | Class | What the resolver rejects with. See Errors |
UNAUTHENTICATED_USER_CODE and UNAUTHENTICATED_USER | Constants | 'unauthenticated_user', "Sign in to use the assistant." |
CONNECTION_FAILED_CODE and CONNECTION_FAILED | Constants | 'connection_failed', "The connection was interrupted. Try again." |
NOT_JSON_CODE and NOT_JSON | Constants | 'not_json', "The assistant couldn't respond. Try again." |
INVALID_ANSWER_CODE and INVALID_ANSWER | Constants | 'invalid_answer', "The assistant couldn't complete your request. Try again." |
UNEXPECTED_ERROR_CODE | Constant | 'unexpected_error'; its sentence is INVALID_ANSWER |
There is no other entry point. The types of the request and the answer are exported by @gridsay/core.
type PromptResolverOptions = { url: string; apiRef?: { readonly current: GridApi | null }; headers?: RequestHeaders | (() => RequestHeaders | Promise<RequestHeaders>); publishableKey?: string; getToken?: () => string | null | undefined | Promise<string | null | undefined>; additionalContext?: string; privateMode?: boolean; referenceId?: string;}; type PromptResolver = NonNullable<DataGridPremiumProps['onPrompt']>;declare function createPromptResolver(options: PromptResolverOptions): PromptResolver;| Option | Type | Default | Meaning |
|---|---|---|---|
url | string | Required | Where each question is posted: your own route, or the gateway's full prompt URL, https://api.gridsay.com/api/v1/datagrid/prompt. Nothing is appended |
apiRef | { readonly current: GridApi | null } | None | The grid's apiRef, from useGridApiRef(). With it, each question carries the grid's switches, column limits and current view, and answers are adapted to the grid |
headers | RequestHeaders or a function returning them, sync or async | None | Added to every request. A function is called for each question |
publishableKey | string | None | Sent as x-api-key. Only for calling the gateway from the browser |
getToken | () => string | null | undefined, or a promise of one | None | Called for each question; the token is sent as Authorization: Bearer …. Nothing returned, or a throw, stops the question with unauthenticated_user |
additionalContext | string | None | Notes about your data, sent as options.additionalContext. Up to 20,000 characters |
privateMode | boolean | None; the gateway treats it as false | Sent as options.privateMode. See private mode |
referenceId | string | None | Your id for the user, sent as options.metadata.referenceId. Up to 127 characters. It labels usage; it does not sign anyone in |
RequestHeaders is Record<string, string>, from @gridsay/core. GridApi is the part of MUI's API the helper reads; pass the grid's own apiRef.
additionalContext, privateMode and referenceId are read once, when the resolver is created: create a new resolver to change them. headers and getToken run for every question.
Each request carries content-type: application/json, then your headers, then x-api-key and authorization when you set publishableKey and getToken. A later one replaces an earlier one spelled the same way.
A POST with the JSON body MUI's stock resolver sends (query, context, conversationId, options) and, with apiRef, a grid field:
Field of grid | What it holds |
|---|---|
disabled | Features switched off: filtering, sorting, grouping, aggregation, pivoting, selection, and charts when no chart is open |
columns | By field, only for columns with a limit: filterable, sortable, groupable, pivotable or aggregable set to false, aggregationFunctions, and a singleSelect's options with their values and labels (up to 500) |
state | The filters, filter join, sorting, grouping, totals and pivot the grid shows now. Always sent, even when empty |
invalid_answer and the grid stays as it was.dataSource, from the loaded page once it arrives.The resolver rejects with a GridsayError. The grid shows its message in the assistant panel.
| Property | Type | Meaning |
|---|---|---|
message | string | A sentence for your user |
code | string, optional | The gateway's code, or one of the helper's below |
status | number, optional | The HTTP status, when a response arrived |
retryAfter | number, optional | Seconds to wait, for a limit |
detail | string, optional | The gateway's explanation for you. Never show it to your user |
cause | unknown, optional | What was thrown, when the failure started with a throw: your headers or getToken, fetch, or reading the response |
The helper's own codes:
code | Sentence | When |
|---|---|---|
unauthenticated_user | UNAUTHENTICATED_USER, or your route's own sentence | getToken threw or returned nothing, and nothing was sent; or a 401 whose body names no other code |
unexpected_error | INVALID_ANSWER | Your headers function threw; nothing was sent |
connection_failed | CONNECTION_FAILED | No response arrived, or reading it was cut off |
not_json | NOT_JSON | The response was not JSON. status 404 usually means url is wrong |
invalid_answer | INVALID_ANSWER | The response was not an answer the helper can read, or an error with no sentence of its own |
Any other code comes from the gateway, with its own status, sentence, retryAfter and detail: every one is in Refusals and errors. Compare codes, never messages: the sentences may change. The helper does not retry.
credentials, a custom fetch, a timeout, retries or cancelling a question.