Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@sanity/agent-directives

Package Overview
Dependencies
Maintainers
114
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/agent-directives

Shared directive system for Sanity Agent

Source
npmnpm
Version
0.0.4
Version published
Weekly downloads
2.1K
131.02%
Maintainers
114
Weekly downloads
 
Created
Source

@sanity/agent-directives

Shared directive system for Sanity Agent.

Installation

pnpm add @sanity/agent-directives

React Usage (Ada)

// 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.

String Usage (Slack)

// 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);

Formatters (Agent Backend)

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"}'

Available Directives

NameProps
documentid, type?, source?
releaseid, source?
resourcesource
setid
changescreatedCount, updatedCount

Exports

PathDescription
@sanity/agent-directivesSchemas and formatters
@sanity/agent-directives/reactcreateDirectiveKit for React
@sanity/agent-directives/stringcreateDirectiveKit for server-side
@sanity/agent-directives/formattersDirective string formatters

Keywords

sanity

FAQs

Package last updated on 29 Jan 2026

Did you know?

Socket

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.

Install

Related posts