feat(sdk): browser SDK + AI tool quality improvements#2511
Draft
feat(sdk): browser SDK + AI tool quality improvements#2511
Conversation
The create response now includes a ref handle that can be passed directly to superdoc_format or superdoc_edit without a search step. Before: create → search → format (3 calls) After: create → format using ref from response (2 calls) The ref is minted from the created block's nodeId + text range + document revision. It's a V4 block-scoped ref that resolves to the full text range of the created content.
- Removed "optional styleId" reference (styleId was removed) - Changed "search after create" to "use ref from response" - Separated heading vs paragraph formatting rules - Added create ref to targeting section - Removed contradictory "search before editing" for create flow
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
… for insert and replace operations
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
This PR improves AI tool call quality and efficiency by fixing tool definitions, adding ref handles to API responses, and introducing the browser SDK for in-browser AI agent workflows.
Problem
AI agents (LLMs) using SuperDoc tools were inefficient and error-prone:
{kind:"text"}instead of{kind:"selection"}due to incorrect fallback descriptionsblockId,start,endin edit tools confused models into trying flat params instead of refsChanges
Block refs in
blocks.list— Each non-empty block now returns arefhandle covering its full text. Agents can pass this directly tosuperdoc_edit replaceorsuperdoc_formatwithout searching first. This is the key enabler for efficient "rewrite this paragraph" flows.Ref from
superdoc_create— Create responses include a ref for the new block, enabling immediate formatting without a search step.Auto-formatting on create —
createParagraphWrapperandcreateHeadingWrapperautomatically inheritfontFamily+color(andfontSizefor paragraphs) from nearby blocks. New content matches the document's visual style with zero extra LLM calls.Fixed target descriptions — Corrected the fallback
targetdescription from{kind:'text', blockId, range:{start,end}}(wrong) to{kind:'selection', start:{kind:'text', blockId, offset}, end:{kind:'text', blockId, offset}}(correct). This was the root cause of models trying wrong target formats.Tool description improvements —
superdoc_edit: guides towardrefusage, warns that search refs are partial, block refs are fullsuperdoc_create: removed manual format instructions (auto-formatting handles it), added ordering guidancesuperdoc_get_content: mentions that blocks returns ref handlessuperdoc_list: system prompt includespreset: "disc"example to prevent missing-kind errorsHidden confusing params —
blockId,start,end,offsetflat params removed from agent tool schemas (kept for CLI). Pushes models towardrefwhich is simpler and more reliable.Browser SDK — New
@superdoc-dev/sdk-browserpackage with:dispatchSuperDocTool()for in-browser AI agent integrationchangeMode,dryRun,force→ options, not input)Schema validator fix — Added
description,minimum,maximumto supported keywords so contract conformance tests pass with described schema properties.Mark-copying helpers —
findNearbyMarks()shared helper with heading/body preference, parasitic mark filtering, and defensive guard for mock docs.Efficiency gains
Files changed
operation-definitions.ts,schemas.tsblocks.types.ts,create.types.tsreffield onBlockListEntryand create resultsgenerate-intent-tools.mjsoperation-params.tslangs/browser/src/*system-prompt.mdinsertHeadingAt.js,insertParagraphAt.jsfindNearbyMarks.jsblocks-wrappers.ts,create-wrappers.tsschema-validator.tsdescription/minimum/maximumkeywordsTest plan
pnpm --filter super-editor test— 9527 passed, 0 failed