feat: live agent chat with client-side document tools#201
Open
feat: live agent chat with client-side document tools#201
Conversation
Add EditorBridge that connects AI agent tools to a live DocxEditor instance. The agent can read the document, add comments, suggest tracked changes, and scroll — all executing on the client without reloading the document. Key changes: - DocxEditorRef: 6 new methods (addComment, replyToComment, resolveComment, proposeReplacement, scrollToIndex, getComments) - EditorBridge (packages/agent-use/bridge.ts): wraps DocxEditorRef for agent use - Tool definitions (packages/agent-use/tools/): 6 tools with OpenAI-compatible schemas (read_document, read_comments, read_changes, add_comment, suggest_replacement, scroll_to) - useAgentChat hook: wires tools to editor ref - agent-chat-demo: Next.js example with chat panel beside the editor Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Replace getOpenAITools/getAnthropicTools with single getToolSchemas()
(OpenAI format is the de facto standard)
- Simplify useAgentChat hook: returns { executeToolCall, toolSchemas }
(removed stale bridge, getSystemContext, provider-specific helpers)
- Demo uses useAgentChat hook instead of manual bridge creation
- Fix multi-turn history: persistent openaiHistoryRef preserves tool
call context across turns
- Fix bridge.getComments(): reads from live editor state, not stale
Document model
- Fix replyToComment: validates parent comment exists
- Add 29 tests for tools + bridge (bun:test)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Extract getCommentText() helper, replacing inline type-cast chain - Fix O(n^2) reply matching: pre-group with Map (same pattern as discovery.ts) - Guard redundant editorRef.getComments() call when doc comments exist - Memoize toolSchemas as module-level constant (static, never changes) - Cache bridge creation via useMemo in useAgentChat hook - Move msgId counter from module-level to useRef (scoped to component) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
yash-giantanalytics
added a commit
to giantanalyticsai/docx-editor
that referenced
this pull request
Mar 26, 2026
This was referenced Mar 27, 2026
Contributor
|
Hey @jedrazb, quick question about this PR. Is it a high priority for you? I'm asking because I started working on something similar in my app, and there’s definitely some overlap with this PR. Do you plan to merge it soon, or is it more of an experiment? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
packages/agent-use/bridge.ts): connects AI agent tools to a live DocxEditor — agent reads content, adds comments, suggests tracked changes, scrolls, all on the client without reloading the documentaddComment,replyToComment,resolveComment,proposeReplacement,scrollToIndex,getCommentspackages/agent-use/tools/): 6 tools with OpenAI-compatible schemas +executeToolCall()dispatcher +getToolSchemas()helperuseAgentChathook: wires tools to editor ref — returns{ executeToolCall, toolSchemas }Test plan
bun run typecheck)cd examples/agent-chat-demo && next build)🤖 Generated with Claude Code