Skip to content

Dato Agent: return full website URLs from Web Previews - #167

Open
rodrigobarona wants to merge 1 commit into
datocms:masterfrom
rodrigobarona:feat/dato-agent-preview-links
Open

rodrigobarona wants to merge 1 commit into
datocms:masterfrom
rodrigobarona:feat/dato-agent-preview-links

Conversation

@rodrigobarona

Copy link
Copy Markdown
Contributor

Closes #164

When an editor asks for a page link, the agent calls get_record_preview_links. That tool reads the Web Previews frontends and POSTs the same payload that plugin sends. Each endpoint has its own timeout, and a failure on one frontend does not drop the links from the others.

Editors who cannot read plugin settings use a copy imported from the config screen. If no preview endpoint returns a URL, the agent builds one from the configured website address and the record slug, and says so. If neither is configured, it returns the slug and says the full URL is unavailable.

Test plan

  • npm test in dato-agent
  • Import Web Previews from the plugin settings and save
  • Ask the agent for a page URL and confirm it returns the full website address

Made with Cursor

When an editor asks for a page link, call the Web Previews endpoints and return the full URL. Keep a saved copy of those endpoints for editors who cannot read plugin settings, and fall back to a configured website address plus the record slug.

Co-authored-by: Cursor <cursoragent@cursor.com>
@roger-datocms

roger-datocms commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

(Claude here [Opus 5.5])

Triage

Status: open, still relevant. Master (6f57d960) has no website-URL tool, so #164 still reproduces. The PR branches from current master and merges cleanly.

Checks I ran on the PR head (15f6ecde):

  • npm test in dato-agent: 962/962 pass.
  • tsc -b: clean. biome check ./src: clean.
  • The PR has no CI checks configured, so these local runs are the only signal.

Overlap with other open Dato Agent PRs: I trial-merged #157, #160 and #161 on top of this branch. All three merge without conflicts. tsc -b and the full suite (965 tests) still pass. #160 also edits agentRuntime.ts, but in separate hunks.

Review

The approach is sound. The POST payload matches what Web Previews sends (web-previews/src/utils/common.ts:99). Per-frontend timeouts and isolated failures work as the tests show. The tool stays read-only, and it never returns custom headers to the model.

Issues to fix before merge:

  1. Inspector sends the UI language as the content locale. dato-agent/src/entrypoints/AgentInspector.tsx:294 passes ctx.ui.locale. That is the editor's interface language, not a project locale. A project with en-US/it locales gets locale: "en" when the model passes null. Use the project's main locale (ctx.site.attributes.locales[0]) instead.
  2. Slug fallback silently picks another locale. localizedText (dato-agent/src/lib/previewLinks.ts:347) returns the first non-empty slug from any locale. The agent then presents a URL for the wrong language as correct. Return null when the requested locale has no slug.
  3. Fallback only knows a field with API key slug (previewLinks.ts:69). It also ignores locale prefixes and tree-parent paths. That is acceptable for a labelled fallback. Detect the field by type (slug field type) from the item type, not by API key.
  4. The saved frontend copy can drift. resolveFrontends (previewLinks.ts:383) prefers live settings. Editors who cannot list plugins always use the saved copy. After someone rotates a Web Previews header, those editors get failed requests with no hint to re-import. Show the import date on the config screen, and add a way to clear the saved copy. Today the only action is "Import from Web Previews" (ConfigScreen.tsx:894).
  5. Secret headers get copied into Dato Agent's parameters. Every Dato Agent user's browser then receives them in ctx.plugin.attributes.parameters. Web Previews already exposes them the same way, so the risk barely changes. Still, add one line to the config screen saying this.
  6. Stray assertion. agentRuntime.test.ts:1090 asserts the absence of open_record_in_full_editor. No such tool exists on master or in this PR. Remove it.

Minor: the endpoints now receive requests from the Dato Agent iframe origin. An endpoint that allows only the Web Previews origin through CORS will fail. The error reaches the model, so the failure stays visible.

Recommended next step

  1. Fix items 1, 2 and 6. They are small, local changes.
  2. Decide on items 3–5, or track them as follow-ups.
  3. Complete the two unchecked manual steps in the test plan on a project that has Web Previews configured.
  4. Then merge. Order relative to Fix Dato Agent sign-in: use oauth.datocms.com OAuth endpoints #157, Dato Agent: avoid Anthropic output-limit failures on large writes #160 and Dato Agent: redact credentials from copied failure diagnostics #161 does not matter.

roger-datocms pushed a commit that referenced this pull request Oct 20, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
roger-datocms pushed a commit that referenced this pull request Oct 20, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dato Agent: answers with a slug instead of the full website URL

2 participants