@shashimadushan/docx-editor-react-native-agent
v0.1.0
Published
AI agent plugin for @shashimadushan/docx-editor-react-native — adds the "@" mention / "Edit with AI" agent to the mobile DOCX editor. Install it only if you want an agent; don't, and none of its code is in your app bundle.
Maintainers
Readme
@shashimadushan/docx-editor-react-native-agent
The AI agent for @shashimadushan/docx-editor-react-native —
the in-document "@" mention and "Edit with AI" flow, the 67-tool agent loop, and
the host-executed tool bridge — packaged as a plugin.
Install it only if you want an agent. Don't, and none of this code is in your
app bundle: this is the mobile equivalent of not installing
@shashimadushan/docx-editor-agent on the web.
pnpm add @shashimadushan/docx-editor-react-native-agentUsage
import { DocxEditorView } from '@shashimadushan/docx-editor-react-native';
import { agentPlugin } from '@shashimadushan/docx-editor-react-native-agent';
<DocxEditorView
plugins={[agentPlugin({ baseUrl: 'https://your-app.com/api/agent' })]}
/>;baseUrl points at your own backend — never a provider URL or key. The
plugin builds a BackendAdapter inside the WebView; your server holds the
provider key. See @shashimadushan/docx-editor-agent's handleAgentChat
server helper, and examples/demo/app/api/agent/chat/route.ts for a working
route.
Two things to get right on a device:
- Use your machine's LAN IP, not
localhost. The simulator/device is a separate network peer. - Send
Access-Control-Allow-Origin: *. The WebView loads the editor from a local file, so its origin is an opaquefile://one your server can't allowlist by name. This is safe here — the adapter always usescredentials: 'omit', so no cookies are ever sent; put your auth token inheadersinstead.
Options
| Option | What it does |
|---|---|
| baseUrl | Your agent backend's URL. Required. |
| headers | Extra headers on every agent request (e.g. { Authorization: … }). |
| tools | Schema-only specs for host-executed tools. The LLM sees them like built-ins; when it calls one, the WebView round-trips to DocxEditorView's onAgentToolCall prop — so the tool runs in your native code, with your SDKs and session. Ship the same specs to your backend so its registry matches. |
| presentation | 'host' suppresses the in-document mention bubble; run activity goes to DocxEditorView's onAgentActivity and prompts come in via handle.sendAgentMessage(), so you can render the conversation in your own native sheet (AgentSheet in the core package's native/ entry is a ready-made one). Default 'webview'. |
All four are live-patchable: they travel over the editor's config channel, so changing them after mount reaches the running agent with no WebView reload. The plugin's script is fixed at mount — adding or removing a plugin needs a remount.
Migrating from agentBaseUrl
-<DocxEditorView
- agentBaseUrl={AGENT_URL}
- agentHeaders={{ Authorization: token }}
- agentTools={[myTool]}
- agentPresentation="host"
- onAgentToolCall={run}
- onAgentActivity={log}
-/>
+<DocxEditorView
+ plugins={[agentPlugin({
+ baseUrl: AGENT_URL,
+ headers: { Authorization: token },
+ tools: [myTool],
+ presentation: 'host',
+ })]}
+ onAgentToolCall={run}
+ onAgentActivity={log}
+/>onAgentToolCall and onAgentActivity stay on DocxEditorView: they're the
host half of the contract, running your native code. The deprecated props
still populate the plugin's config as a fallback, so an app that installs this
package without rewriting its JSX keeps working — but they warn, and on their
own (without this package installed) they no longer do anything, because the
agent isn't in the core bundle to switch on anymore.
How it works
See ARCHITECTURE_PLAN.md §5B in the
core package. In short: web/ builds an IIFE chunk with React and the editor
package left external, mapped to globals the core bundle exposes; src/index.ts
embeds that chunk as a string and wraps it in a DocxEditorHost.register(...)
call; DocxEditorView injects it ahead of the core bundle, which drains the
queue once it has a runtime to hand over. One React, one TipTap, one
ProseMirror in the page — which is why the chunk is ~174 kB rather than
megabytes.
requiresHost is checked at load time against the core's
HOST_RUNTIME_VERSION; a mismatch reports one clear error through
DocxEditorView's onError and the editor mounts without the agent.
License
MIT
