import type { SuggestionContext } from './suggestionContexts';
import type { PluginExtensionAddedFunctionConfig } from '@grafana/data';
import type { ComponentType, ReactNode } from 'react';
/**
* Extension point id consumed by the Grafana Assistant.
*
* A contributing app plugin registers a manifest function against this target via
* `AppPlugin.addFunction()` (declared under `extensions.addedFunctions` in its `plugin.json`).
* The Assistant discovers registrations with `usePluginFunctions()` and invokes each function to
* obtain the plugin's {@link AssistantExtensionManifest}.
*
* @experimental This API is under active development and may change in future releases.
*/
export declare const ASSISTANT_EXTENSION_POINT = "grafana-assistant-app/extension/v1";
/**
* Props passed to a `tool-details` chit component registered via {@link ChitContribution}.
*
* These are the normalized props every tool row in the Assistant chat track receives; a
* registered component renders inside the expanded details area of the standard tool card,
* in place of the generic expanded content.
*
* @experimental This API is under active development and may change in future releases.
*/
export interface ToolChitProps {
/** The fully namespaced tool name that produced this card. */
toolName: string;
/** The tool call input, as sent to the tool. */
input: unknown;
/** The tool result, once available. `undefined` while the tool is still running. */
result: unknown;
/** Execution state of the tool call. */
status: 'running' | 'success' | 'error';
}
/** Read-only inputs from tool calls in the message containing an inline component. */
export interface InlineChitToolCall {
readonly toolCallId?: string;
readonly name: string;
/** Model-authored input; validate its shape before using it. */
readonly input: unknown;
}
export interface InlineChitTurn {
/** False also covers stopped turns and history; it does not imply success. */
readonly isStreaming: boolean;
readonly tools: readonly InlineChitToolCall[];
}
export interface InlineChitProps {
children?: ReactNode;
/** Host-supplied context, never taken from model-authored attributes. Absent on older hosts. */
turn?: InlineChitTurn;
/** Sanitized `name` attribute, useful for a plugin-defined filter or identifier. */
name?: string;
}
export declare const InlineChitDisplay: {
readonly Inline: 'inline';
readonly Block: 'block';
};
export type InlineChitDisplay = (typeof InlineChitDisplay)[keyof typeof InlineChitDisplay];
/**
* A contribution to the Assistant chat track ("chits"): either an expanded-details renderer
* keyed by tool name, or a component rendered in place of a tag inside assistant text.
*
* - `tool-details`: renders inside the expanded details area of the standard tool card for the
* listed tool names, replacing the generic expanded content (Query/Result). The compact tool
* row, its status, and the Allow/Deny confirmation flow are always built in — a plugin never
* replaces the tool row and never renders while a confirmation is pending. A plugin may only
* register details for tools it owns (tool names are namespaced by the tool pipeline and
* checked against the contributing plugin id).
* - `inline`: registers a component rendered in place of a custom tag inside assistant message
* text. The full tag name is the plugin id with non-alphanumerics collapsed to underscores,
* followed by an underscore and `name` — for example plugin `grafana-k6-app` with
* `name: 'result'` renders `…`. Tag children
* and allow-listed attributes are passed through as props, alongside host-owned turn context.
* Optional `prompt` guidance teaches the model when to emit the tag through chat context.
*
* Component and function references are the only non-JSON-serializable parts of a manifest —
* refer to {@link AssistantExtensionManifest} for the serializability contract.
*
* @experimental This API is under active development and may change in future releases.
*/
export type ChitContribution = {
kind: 'tool-details';
/** Fully namespaced tool names this details renderer applies to. Must be owned by the contributing plugin. */
toolNames: string[];
/** The details component, rendered inside a per-chit error boundary. */
component: ComponentType;
} | {
kind: 'inline';
/** Plugin-local tag suffix: lowercase, `[a-z][a-z0-9]*`. Namespaced by the plugin id into the full tag name. */
name: string;
/** Optional component usage guidance (up to 4096 UTF-8 bytes), sent as attributed chat context, not a system prompt or mode. */
prompt?: string;
/** A childless marker. Recover saved bare/backticked opening tags and suppress identical duplicates outside code. */
selfClosing?: boolean;
/** Defaults to inline. Block requires selfClosing: true and renders below the message text, outside Markdown paragraphs. */
display?: InlineChitDisplay;
/** Rendered in place of the tag, inside a per-chit error boundary. Receives tag children and allow-listed attributes as props. */
component: ComponentType;
};
/**
* The artifact file node handed to plugin artifact renderers and toolbars.
*
* Intentionally minimal and forward-compatible: renderers must treat this as the complete
* artifact surface and must not fetch artifact content from anywhere else.
*
* @experimental This API is under active development and may change in future releases.
*/
export interface AssistantArtifactNode {
/** Opaque host identity. Stable across chat draft edits/renames, scoped to the chat.
* Mounted resources use namespace/path identity. Absent on hosts without identity context.
* Never use this as authorization or parse its internal format.
*/
id?: string;
/** Current, authorized live-resource metadata. Absent for chat-owned drafts. */
resource?: {
namespace: string;
revision?: string;
url?: string;
};
/** File path of the artifact in the conversation's artifact filesystem. */
path: string;
/** The artifact kind extension, e.g. `.grafana-k6-app.test`. */
ext: string;
/** The artifact content. Shape is owned by the contributing plugin's `validate` contract. */
data: unknown;
/**
* Monotonically increasing per-artifact write counter. Increments on every write to this
* artifact. Suitable for memoization keys, cache-busting, and change detection. NOT a
* timestamp — carries no wall-clock meaning.
*/
revision: number;
/** Opaque backend revision for mounted files; use for cache keys when present. */
resourceRevision?: string;
}
/**
* Read-only access to every artifact in the conversation, including built-in and other
* plugins' files. Use this handle and the supplied node for artifact content. Writes and
* edits go through the Assistant's validated `artifact_files` tool.
*
* @experimental This API is under active development and may change in future releases.
*/
export interface AssistantArtifactFs {
/** All artifacts in the conversation, in stable path order. */
list(): AssistantArtifactNode[];
/** Read one artifact by exact normalized path. */
read(path: string): AssistantArtifactNode | undefined;
/** Whether an artifact exists at the path. */
has(path: string): boolean;
}
/**
* Props passed to a plugin artifact renderer.
*
* @experimental This API is under active development and may change in future releases.
*/
/** Prefills the owning conversation. The user reviews and sends the turn. */
export type ArtifactRequestEdit = (input: {
message: string;
}) => void;
export interface ArtifactRendererProps {
/** The artifact node to render. */
node: AssistantArtifactNode;
/** Read-only handle over the conversation's artifact filesystem. */
fs: AssistantArtifactFs;
/** Available in a conversation. Appends text and this artifact's path to the composer,
* preserves existing input, and focuses it. Never sends or writes automatically.
* Call only from an explicit user action. Hide edit actions when absent.
*/
requestEdit?: ArtifactRequestEdit;
/** Normalized validation for this revision. Recheck readiness before saving or running. */
validation?: {
valid: boolean;
ready?: boolean;
issues: ArtifactValidationIssue[];
};
}
/**
* Props passed to an optional plugin artifact toolbar.
*
* @experimental This API is under active development and may change in future releases.
*/
export interface ArtifactToolbarProps {
/** The artifact node the toolbar acts on. */
node: AssistantArtifactNode;
/** Read-only handle over the conversation's artifact filesystem. */
fs: AssistantArtifactFs;
/** Available in a conversation. Appends text and this artifact's path to the composer,
* preserves existing input, and focuses it. Never sends or writes automatically.
* Call only from an explicit user action. Hide edit actions when absent.
*/
requestEdit?: ArtifactRequestEdit;
/** Normalized validation for this revision. Recheck readiness before saving or running. */
validation?: {
valid: boolean;
ready?: boolean;
issues: ArtifactValidationIssue[];
};
}
/**
* A plugin-contributed artifact kind for the Assistant canvas.
*
* The `ext` is double-dot namespaced as `.{pluginId}.{kind}`, where `pluginId` is your full,
* exact plugin id — for example `.grafana-k6-app.test`, not a shortened slug. This keeps plugin
* kinds out of the built-in single-dot space and keeps orphaned artifacts attributable to their
* owning plugin without a live registry, since the plugin id is readable from the artifact path.
*
* Everything except `validate`, `renderer`, and `toolbar` is JSON-serializable — refer to
* {@link AssistantExtensionManifest} for the serializability contract.
*
* @experimental This API is under active development and may change in future releases.
*/
export interface ArtifactValidationIssue {
/** Field path owned by the plugin, for example steps[2].inputs.channel. */
path: string;
/** Actionable feedback. Never include credentials or other sensitive values. */
message: string;
}
/** valid controls draft writes/rendering. ready is advisory and never authorizes a save or run. */
export type ArtifactValidationResult = boolean | {
valid: boolean;
ready?: boolean;
issues: ArtifactValidationIssue[];
};
export interface ArtifactKindContribution {
/** Artifact extension in the form `.{pluginId}.{kind}` (exact plugin id), double-dot namespaced. */
ext: `.${string}.${string}`;
/** Human-readable label shown on artifact tabs and cards. */
label: string;
/** Icon name. The current host displays a generic plugin icon instead. */
icon: string;
/**
* Sort order among plugin kinds, ascending. The host clamps negative values to zero
* and places plugin kinds after built-ins. Ties use the most recently updated artifact.
*/
tabPriority: number;
/** Content validator. Accept with true or { valid: true, issues: [...] }. */
validate(data: unknown): ArtifactValidationResult;
/** Relative paths in this plugin's filesystem, discovered before authoring. */
instructionsPath?: string;
schemaPath?: string;
/** Renders the artifact in the canvas. Receives the artifact node and a read-only conversation filesystem handle. */
renderer: ComponentType;
/** Optional toolbar rendered above the artifact. */
toolbar?: ComponentType;
/** Reserved hint. Accepted by the host but not currently sent to the model. */
promptHint?: string;
}
/** JSON or text stored by a plugin filesystem. Binary files are not supported. */
export type AssistantFileContent = null | boolean | number | string | AssistantFileContent[] | {
[key: string]: AssistantFileContent;
};
/** Paths are relative to the plugin mount, without a leading slash or traversal segments. */
export interface AssistantFilesystemFile {
path: string;
content: AssistantFileContent;
/** Opaque backend revision, used for conditional writes. */
revision: string;
title?: string;
/** Optional Grafana-local native page under /a//. */
url?: string;
}
export interface AssistantFilesystemListInput {
/** Relative directory; empty string lists the mount root. */
path: string;
filter?: {
type?: string;
title?: string;
};
limit: number;
offset: number;
}
export interface AssistantFilesystemListResult {
/** Authorized files only, filtered then sorted by relative path before pagination. */
items: Array<{
path: string;
title?: string;
}>;
hasMore: boolean;
}
/**
* A live filesystem mounted at /plugins// by the host.
* All callbacks run in the browser under the current caller. The owning backend must
* enforce authorization for every operation; chat access grants no resource permission.
* Paths and namespace are routing context, never authorization assertions.
* Missing/denied reads reject. No callback may return content from a different namespace.
* Keep callbacks stable and independent of `this`, like other manifest callbacks.
*
* Ordinary text/JSON files are tool-accessible. Files with the plugin's registered artifact
* extensions can also attach to the canvas. No content is reconstructed from chat inputs.
* @experimental
*/
export interface AssistantFilesystemContribution {
/** Optional Markdown instructions exposed read-only at the mount's AGENT.md (max 32 KiB). */
agentGuide?: string;
read(namespace: string, path: string): Promise;
list(namespace: string, input: AssistantFilesystemListInput): Promise;
/** Metadata only; undefined means missing or inaccessible. Other failures reject. */
metadata(namespace: string, path: string): Promise<{
title?: string;
} | undefined>;
/** Atomic create: assign and return a relative path; rejection means nothing was created. */
create?(namespace: string, content: AssistantFileContent): Promise;
/** Update an existing file only, enforcing the supplied revision atomically in storage. */
write?(namespace: string, path: string, content: AssistantFileContent, revision: string): Promise;
}
/**
* Reserved availability conditions for plugin modes.
* The current plugin-mode adapter does not apply these conditions.
*
* @experimental This API is under active development and may change in future releases.
*/
export type PromptContributionAvailability = 'not-oss' | 'not-trial';
/**
* A plugin-contributed Assistant mode (system prompt variant).
*
* The contribution is exposed in the mode picker as `${pluginId}:${modeId}` and its prompt text
* is always rendered inside an attributed `` wrapper, subject to a
* 16 KiB UTF-8 body limit and an assistant-side allowlist.
*
* The current host applies modeId, label, description, compose, and prompt only. Other
* fields are accepted but not applied; don't use them to enforce tool or access restrictions.
*
* All fields are JSON-serializable — refer to {@link AssistantExtensionManifest} for the
* serializability contract.
*
* @experimental This API is under active development and may change in future releases.
*/
export interface PromptContribution {
/** Plugin-local mode id. Exposed to users as `${pluginId}:${modeId}`. */
modeId: string;
/** Human-readable mode label shown in the mode picker. */
label: string;
/** Short description of the mode shown in the mode picker. */
description: string;
/** Intended suggestion guidance. Required by the schema, but not currently applied by the host. */
whenToUse: string;
/**
* How `prompt` composes with the base system prompt.
*
* - `prepend` / `append`: `prompt` is added before / after the base guidance, which is
* otherwise kept intact.
* - `replace`: the rest of the base guidance is dropped, but the Assistant's identity section
* is ALWAYS retained — the composed prompt is the identity block, then the current-mode
* block, then the attributed plugin body. A plugin never controls or replaces the
* Assistant's identity.
*
* Prefer `prepend` or `append` unless the mode is a genuinely self-contained specialist that
* needs none of the base guidance.
*/
compose: 'prepend' | 'append' | 'replace';
/**
* The prompt snippet (`prepend`/`append`) or specialist body (`replace`). With `replace`, this
* body is composed after the Assistant's always-retained identity section — refer to
* {@link PromptContribution.compose}.
*/
prompt: string;
/** Reserved first-message text. The current host does not send it. */
initialMessage?: string;
/** Reserved switching preference. The current host does not apply it. */
switchable?: boolean;
/** Reserved availability conditions. The current host does not evaluate them for plugin modes. */
availability?: PromptContributionAvailability[];
/** Reserved tool scoping. The current host does not restrict tools using this field. */
modeToolNames?: string[];
/** Reserved icon name. The current host displays a generic plugin icon. */
icon?: string;
/** Reserved badge. The current host does not apply it. */
featureState?: 'preview' | 'experimental';
}
/**
* A proposed first message on empty Assistant chats, attributed to your plugin.
* Selecting it sends `message` as a visible user message. Requires the extensions master
* flag and an enabled plugin; no prompt flag or allowlist is needed.
*
* The host keeps the first 3 valid entries. Over-length entries are dropped, not truncated.
* Use `contexts` to participate in route-relevant selection, or `provideQuestions`
* for suggestions tied to a page where your plugin runs.
*
* @experimental This API is under active development and may change in future releases.
*/
export interface AssistantStarter {
/** Optional short label shown on the starter; defaults to the message itself. Max 80 characters. */
label?: string;
/** The user message sent, visibly and as-is, when the starter is selected. Max 500 characters. */
message: string;
/** Eligible on any listed route context. Omitted: only this plugin's /a/ routes.
* An empty list disables the starter. Eligible starters compete with built-in suggestions.
*/
contexts?: readonly SuggestionContext[];
}
/**
* A plugin workflow with a read-only listing on the Assistant's Skills settings page.
* The catalog and loader that deliver content to the model are not implemented yet.
* Proposed activation requires trusted server integration and a supported runtime surface.
* Automatic discovery would also require a short author hint (`whenToUse`), not yet in this
* interface. Existing manifests remain valid and would be manual-only without a hint once
* manual activation ships; enabling the builtin runtime does not activate plugin registrations.
*
* The host assigns the handle `plugin:{pluginId}:{id}` using the registered plugin ID.
* Plugin skills are not saved as tenant skills or indexed for search. Removing a
* registration removes its skills. The prompt flag and allowlist don't gate registration.
*
* The host keeps the first 5 valid, unique IDs and drops entries that exceed field limits.
*
* @experimental This API is under active development and may change in future releases.
*/
export interface SkillContribution {
/** Plugin-local skill id: `[a-z][a-z0-9-]*`, max 64 characters. Namespaced by the plugin id into the catalog handle. */
id: string;
/** Nonblank title shown in settings. Max 80 characters. */
title: string;
/** One or two sentences describing what the skill does and when to use it. Max 500 characters. */
description: string;
/** Nonblank Markdown body. Model loading is not implemented yet. Max 32768 UTF-8 bytes. */
content: string;
}
/**
* Contributions from one Grafana app plugin to the Assistant sidebar and workspace.
* Register with {@link getAssistantExtensionConfig} and declare the matching target in
* `plugin.json`. Keep the manifest stable after registration.
*
* Fields must be JSON-serializable except components and callbacks (`component`,
* `validate`, `renderer`, `toolbar`, and filesystem callbacks). Unknown fields are ignored. Unknown contribution
* kinds and malformed entries are dropped; an unknown schemaVersion rejects the manifest.
*
* @experimental This API is under active development and may change in future releases.
*/
export interface AssistantExtensionManifest {
/** Manifest schema version. Always 1 for this SDK version. */
schemaVersion: 1;
/** Chat-track contributions: tool-details renderers and inline components. */
chits?: ChitContribution[];
/** Proposed first messages on empty chats, attributed to the plugin. Max 3 valid entries. */
starters?: AssistantStarter[];
/** Plugin workflows listed in settings. Model loading is not implemented yet. Max 5 valid entries. */
skills?: SkillContribution[];
/** Canvas artifact kinds. */
artifactKinds?: ArtifactKindContribution[];
/** Optional persistent filesystem, mounted under the registering plugin ID. */
filesystem?: AssistantFilesystemContribution;
/** Assistant mode / system prompt contributions. */
promptContributions?: PromptContribution[];
}
/**
* Builds the function registration for {@link ASSISTANT_EXTENSION_POINT}.
* Also declare the target in `plugin.json` under `extensions.addedFunctions`. Use
* `preload: true` for Grafana 12.1 compatibility with function-only contributions.
*
* The returned function reuses `manifest`. Don't mutate it after registration; define
* components and callbacks outside React renders so their references stay stable.
*
* @example
* ```typescript
* import { AppPlugin } from '@grafana/data';
* import { getAssistantExtensionConfig } from '@grafana/assistant';
*
* export const plugin = new AppPlugin().addFunction(
* getAssistantExtensionConfig({
* schemaVersion: 1,
* starters: [{ message: 'Help me review recent service errors in this stack.' }],
* })
* );
* ```
*
* @experimental This API is under active development and may change in future releases.
*/
export declare function getAssistantExtensionConfig(manifest: AssistantExtensionManifest): PluginExtensionAddedFunctionConfig<() => AssistantExtensionManifest>;
//# sourceMappingURL=extension.d.ts.map