feat: AI save and save_and_publish tools#166
Merged
Merged
Conversation
Adds optional `save?` and `publish?` methods to UaiEntityAdapterApi alongside a new UaiPersistResult shape (mirroring UaiValueChangeResult). The entity adapter context exposes delegating `saveSelectedEntity()` / `publishSelectedEntity()` methods that return structured "not supported" errors when an entity type doesn't implement either operation — most commonly when the user has a block workspace selected, since block changes save through the parent document. Document adapter implements both: save calls the workspace's `requestSubmit()`; publish resolves the document publishing workspace context as a sibling (both register against the same host) and calls `saveAndPublish()`. Media adapter implements save only — media has no publish concept. Block adapter intentionally omits both so the missing-method path surfaces a clear redirect to the parent document. Two new built-in scopes back the new tools: EntitySaveScope (entity-save) and EntityPublishScope (entity-publish). Both are destructive. Splitting them from EntityWriteScope means an agent can be granted permission to stage value changes without also being allowed to commit them or push them live. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two new LLM-visible tools in the entity-tool surface: - `save` (scope entity-save) — calls UaiEntityAdapterContext.saveSelectedEntity(); the equivalent of the user clicking the workspace Save button. Works on documents and media. - `save_and_publish` (scope entity-publish) — calls publishSelectedEntity(); document-only. Both tools take no parameters since save/publish operate at the workspace level. Tool descriptions explicitly direct the LLM toward the right tool for the entity type (no publish on media, blocks save with their parent document) so failure modes surface a useful error path rather than a generic rejection. Agents currently using AllowedToolScopeIds=["entity-write"] won't pick these up; the new scopes must be granted explicitly. Agents using AllowedToolIds need the tool IDs Uai.AgentFrontendTool.Save and Uai.AgentFrontendTool.SaveAndPublish added. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The scope picker resolves per-scope labels and descriptions via
`uaiToolScope_${camelCase(scope.id)}Label` / `Description` keys, falling back to the raw
scope id when no key is registered. Adds entries for the new entity-save and entity-publish
scopes so they render as "Save Entity" / "Publish Entity" rather than the raw ids.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adapt the save and save_and_publish tools to the new manifest layout where HITL approval lives on the frontend tool, not the renderer. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
a7f5807 to
6cf34e0
Compare
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
Stacked on #160 (which itself stacks on #153). Adds two new LLM-visible tools for persisting AI-driven workspace changes:
save— calls the workspace'srequestSubmit(); equivalent to clicking Save. Works on documents and media.save_and_publish— calls the document publishing context'ssaveAndPublish(). Documents only.The property-value-handler tools introduced in #160 stage changes on the workspace; until now the only way to persist them was a human clicking Save. These tools close that gap so the LLM can complete the staging → persistence flow on the user's behalf.
Design
Both tools route through the entity adapter contract, mirroring the existing
applyValueChangeshape:UaiEntityAdapterApigains optionalsave?(ctx)andpublish?(ctx)methods returning a newUaiPersistResult { success, error? }.UaiEntityAdapterContextgainssaveSelectedEntity()/publishSelectedEntity()that delegate to the adapter and produce structured "not supported" errors when an adapter omits a method.Per-adapter behavior:
requestSubmit()UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXTas a sibling and callssaveAndPublish()requestSubmit()(always live, so save IS publish)Two new tool scopes back the tools:
entity-saveandentity-publish. Both destructive. Split from the existingentity-writeso an agent can be granted permission to mutate staged values without also being allowed to commit them, or to save drafts without publishing live.Permissions migration
Agents currently using
AllowedToolScopeIds: ["entity-write"]will not automatically pick these tools up. To enable them, grant the new scopes:entity-savefor saveentity-publishfor publish (implies save semantics — publishing always saves first)Agents using explicit
AllowedToolIdsneed:Uai.AgentFrontendTool.SaveUai.AgentFrontendTool.SaveAndPublishTest plan
savefrom a document workspace persists staged AI-driven changessavefrom a media workspace persists staged changessavefrom a block workspace returns the structured "save the parent document" errorsave_and_publishfrom a document workspace publishes the documentsave_and_publishfrom a media workspace returns "use save instead"save_and_publishon a multi-variant document surfaces the variant-picker modal (intentional — same UX as clicking the button)entity-savescope cannot invokesaveentity-publishscope cannot invokesave_and_publish🤖 Generated with Claude Code