npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nutrient-sdk/document-authoring-ai

v1.0.2

Published

AI tool definitions and editor execution helpers for Nutrient Document Authoring.

Downloads

1,092

Readme

Nutrient Document Authoring AI

Document Authoring AI is the AI toolkit for Nutrient Document Authoring. It gives a Large Language Model (LLM) a list of document tools, validates the tool calls the model sends back, and applies accepted edits through a live Document Authoring editor.

The package is split by where the code runs. The root entrypoint is safe to use on a server because it only exports prompts, schemas, tool metadata, and validation helpers. The /editor entrypoint is for browser code that owns a DocAuthEditor. The /vercel and /langchain entrypoints adapt the same tool definitions for those AI frameworks.

Install

Install the AI package first. This is enough to call getAiPromptGuide(), inspect tool definitions, validate tool calls, define workflows, use adapters, and export tool metadata as JSON.

npm install @nutrient-sdk/document-authoring-ai

If you execute tools against a Document Authoring editor, install Document Authoring SDK 1.15.0 or newer:

npm install @nutrient-sdk/document-authoring@^1.15.0

You do not need @nutrient-sdk/document-authoring when you stay on the root, /vercel, or /langchain entrypoints. You need it when you import @nutrient-sdk/document-authoring-ai/editor, because that entrypoint talks to a live DocAuthEditor.

If you use the Vercel AI SDK adapter, install the Vercel AI SDK too. The adapter supports ai versions 6 and 7:

npm install ai

The LangChain adapter uses this package's built-in Zod dependency and does not need another peer dependency from this package.

Entrypoints

import { getAiPromptGuide, getAiToolDefinitions, getBuiltInWorkflow, parseAiToolCall } from '@nutrient-sdk/document-authoring-ai';

import { getAiToolkit } from '@nutrient-sdk/document-authoring-ai/editor';
import { toVercelAiTools } from '@nutrient-sdk/document-authoring-ai/vercel';
import { toLangChainTools } from '@nutrient-sdk/document-authoring-ai/langchain';

Use the root entrypoint for model-facing setup:

  • getAiPromptGuide() returns instructions you can add to your model's system prompt.
  • getAiToolDefinitions() returns built-in tool names, descriptions, input schemas, output schemas, and read/write metadata.
  • parseAiToolCall(...) validates untrusted tool calls from a model.
  • getBuiltInWorkflow(...) returns the built-in proofreading and translation workflows.
  • createWorkflow(...) defines a custom workflow that uses the same structured replacement-fragment output.

A typical integration has two halves. Your model runtime gets prompts, tool definitions, and schemas from the root entrypoint or an adapter entrypoint. Your browser app receives tool calls and executes them through the /editor entrypoint, where the live document exists.

Tool Definitions

Send tool definitions to the model. A tool definition names one document action and includes the JSON schema for its arguments. When the model returns a tool call, parse it before it reaches the editor.

import { getAiPromptGuide, getAiToolDefinitions, parseAiToolCall, type UnvalidatedAiToolCall } from '@nutrient-sdk/document-authoring-ai';

const definitions = getAiToolDefinitions({
	tools: ['read_document', 'search_elements', 'read_element', 'replace_text'],
});

const systemPrompt = `${getAiPromptGuide()}\n\nUse only these document tools.`;

function parseModelToolCall(call: UnvalidatedAiToolCall) {
	return parseAiToolCall(call, definitions);
}

The read tools inspect the current document:

  • read_document
  • search_elements
  • read_element

The write tools edit document content:

  • add_paragraphs
  • add_section_break
  • replace_paragraph
  • replace_text
  • add_table
  • replace_table
  • delete_block
  • format_text
  • format_list

By default, write tools apply changes directly. At execution time you can switch to tracked changes. You can also expose a reviewComment argument so the model can leave a review comment with an edit.

const definitions = getAiToolDefinitions({
	reviewComments: 'create',
});

Editor Execution

Use getAiToolkit(editor) in browser code that already has a DocAuthEditor. That is where validated tool calls turn into real document reads and writes. This entrypoint requires @nutrient-sdk/document-authoring 1.15.0 or newer.

import { parseAiToolCall } from '@nutrient-sdk/document-authoring-ai';
import { getAiToolkit } from '@nutrient-sdk/document-authoring-ai/editor';
import type { DocAuthEditor } from '@nutrient-sdk/document-authoring';
import type { UnvalidatedAiToolCall } from '@nutrient-sdk/document-authoring-ai';

export async function executeDocumentTool(editor: DocAuthEditor, rawCall: UnvalidatedAiToolCall) {
	const toolkit = getAiToolkit(editor);

	try {
		const call = parseAiToolCall(rawCall);
		return await toolkit.executeTool(call, {
			writeMode: 'track_changes',
			reviewComments: 'create',
		});
	} finally {
		toolkit.dispose();
	}
}

executeTool(...) returns the validated call, the tool result, and an execution state. Read results have execution.kind === 'read'. Write results say whether the edit was applied directly or with tracked changes.

Vercel AI SDK

@nutrient-sdk/document-authoring-ai/vercel converts built-in tool definitions to Vercel AI SDK tool metadata. It needs the ai package.

import { getAiToolDefinitions, getBuiltInWorkflow } from '@nutrient-sdk/document-authoring-ai';
import { toVercelAiTools, toVercelAiWorkflowOutputSchema } from '@nutrient-sdk/document-authoring-ai/vercel';

const tools = toVercelAiTools(getAiToolDefinitions());

const workflow = getBuiltInWorkflow('translation', {
	targetLanguage: 'german',
});
const outputSchema = toVercelAiWorkflowOutputSchema(workflow).schema;

The adapter returns metadata and schemas. It does not execute document writes on the model server. Pass accepted tool calls to getAiToolkit(editor) in the browser.

LangChain

@nutrient-sdk/document-authoring-ai/langchain converts built-in tool definitions to LangChain-style metadata with Zod schemas.

import { getAiToolDefinitions, getBuiltInWorkflow } from '@nutrient-sdk/document-authoring-ai';
import { toLangChainTools, toLangChainWorkflowOutputSchema } from '@nutrient-sdk/document-authoring-ai/langchain';

const tools = toLangChainTools(
	getAiToolDefinitions({
		tools: ['search_elements', 'read_element', 'replace_text'],
	}),
);

const workflow = getBuiltInWorkflow('proofreading');
const outputSchema = toLangChainWorkflowOutputSchema(workflow);

These tool definitions do not include execution functions. Keep execution in your application, then pass validated tool calls to the editor toolkit.

Workflows

Workflows are useful when the model should rewrite a whole selection or document fragment, for example during proofreading or translation. The toolkit reads the current scope as plain text plus a DocJSON fragment, which is the structured Document Authoring content that can be replaced. Your model returns a replacement fragment. The toolkit validates that output before applying it.

import { getBuiltInWorkflow } from '@nutrient-sdk/document-authoring-ai';
import { getAiToolkit } from '@nutrient-sdk/document-authoring-ai/editor';
import type { DocAuthEditor } from '@nutrient-sdk/document-authoring';

export async function runTranslationWorkflow(editor: DocAuthEditor, modelOutput: unknown) {
	const toolkit = getAiToolkit(editor);
	const workflow = getBuiltInWorkflow('translation', {
		targetLanguage: 'spanish',
	});

	try {
		const input = await toolkit.readWorkflowInput(workflow, {
			scope: 'selection',
		});

		const result = await toolkit.applyWorkflowOutput(workflow, modelOutput, {
			scope: input.scope,
			writeMode: 'track_changes',
		});

		return { input, result };
	} finally {
		toolkit.dispose();
	}
}

Send input.inputText, input.inputFragment, workflow.systemPrompt, and workflow.defaultTask to your model. Pass the model's structured output to applyWorkflowOutput(...).

Built-in workflows:

  • proofreading
  • translation, with english, german, french, and spanish targets

Use createWorkflow(...) for custom prompts that still return a structured replacement fragment.

Exporting Tool Definitions

Backends that do not run TypeScript can use the built-in tool metadata as JSON.

npx document-authoring-ai-export > document-authoring-ai-tools.json
npx document-authoring-ai-export --tools search_elements,read_element,replace_text

The command prints a versioned JSON payload with tool names, descriptions, schemas, and read/write metadata.

License

This package uses the same license as @nutrient-sdk/document-authoring: see the Nutrient SDK User Evaluation Subscription Agreement.