
Company News
Socket Joins the OpenJS Foundation
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.
@sanity/agent-directives
Advanced tools
Shared directive system for Sanity Agent.
pnpm add @sanity/agent-directives
// directives/kit.ts
import { createDirectiveKit } from "@sanity/agent-directives/react";
import { useThreadApplication } from "../hooks/useThreadResource";
export const { defineDirective } = createDirectiveKit({
useApplication: useThreadApplication,
});
// directives/Document.tsx
import { defineDirective } from "./kit";
export const Document = defineDirective("document", ({ id, application }) => {
const doc = useDocument(id);
return <DocumentCard document={doc} />;
});
That's it. Schema validation and application injection happen automatically.
// directives/kit.ts
import { createDirectiveKit } from "@sanity/agent-directives/string";
interface SlackContext {
accessToken: string;
applications: Application[];
}
interface SlackOutput {
text?: string;
blocks?: SlackBlock[];
}
export const { defineDirective, renderDirective } = createDirectiveKit<
SlackContext,
SlackOutput
>();
// directives/document.ts
import { defineDirective } from "./kit";
export const Document = defineDirective(
"document",
async ({ id, _context }) => {
const doc = await fetchDocument(id, _context.accessToken);
return { blocks: [linkButton(doc.title, url)] };
},
);
// Render directives from remark AST
import { renderDirective } from "./kit";
const output = await renderDirective(node, context);
import {
createDocumentDirective,
createChangesDirective,
} from "@sanity/agent-directives/formatters";
createDocumentDirective({ id: "doc-123", type: "article" });
// => '::document{id="doc-123" type="article"}'
createChangesDirective({ createdCount: 3, updatedCount: 5 });
// => '::changes{createdCount="3" updatedCount="5"}'
| Name | Props |
|---|---|
document | id, type?, source? |
release | id, source? |
resource | source |
set | id |
changes | createdCount, updatedCount |
| Path | Description |
|---|---|
@sanity/agent-directives | Schemas and formatters |
@sanity/agent-directives/react | createDirectiveKit for React |
@sanity/agent-directives/string | createDirectiveKit for server-side |
@sanity/agent-directives/formatters | Directive string formatters |
FAQs
Shared directive system for Sanity Agent
The npm package @sanity/agent-directives receives a total of 2,063 weekly downloads. As such, @sanity/agent-directives popularity was classified as popular.
We found that @sanity/agent-directives demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 113 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.

Security News
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.