Repository navigation
canvas: add chat-scoped discovery and URI-addressed lifecycle - #528
Joaquín Ruales (jruales) wants to merge 16 commits into
Conversation
9a3f79a to
37f5151
Compare
4493b21 to
d21b6fa
Compare
d21b6fa to
c7ecbd7
Compare
Add capability-gated exact-chat listCanvasTypes and openCanvas commands, including owning extension metadata, and regenerate all protocol clients and schemas. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0a6aa762-4b80-4e33-be5d-68d9f3398af2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0a6aa762-4b80-4e33-be5d-68d9f3398af2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0a6aa762-4b80-4e33-be5d-68d9f3398af2
Replace snapshot-only Canvas listing with an authoritative exact-chat registry, explicit cold materialization action, and URI-addressed Canvas opening. Normalize provider metadata and update every generated client, reducer, fixture, and specification. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0a6aa762-4b80-4e33-be5d-68d9f3398af2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
c7ecbd7 to
a9c3184
Compare
Addressed
| /** Stable identifier of the extension that declares the canvas. */ | ||
| extensionId: string; | ||
| /** Provider-local canvas type identifier. */ | ||
| canvasId: string; |
There was a problem hiding this comment.
canvasId was initially proposed in a PR before, but we removed it since the canvas channel: URI is already unique, so there was no need for another unique canvasId. Can we retain that?
There was a problem hiding this comment.
Here canvasId selects the registered Canvas type to open (CanvasType.id), not the instance. It has the same meaning as the existing CanvasState.canvasId; multiple canvas instances can share it while having different channel URIs. The new, client-chosen URI alone doesn’t tell the host which type to create.
We could keep canvasId consistently and clarify the docs, or rename both fields to canvasTypeId to make that distinction explicit—though renaming CanvasState.canvasId would change an existing wire-format field.
🤖 Written by GitHub Copilot on behalf of Joaquín Ruales (@jruales).
Auto-replied by the GitHub Copilot app
There was a problem hiding this comment.
So this is canvasTypeId; not canvasId -- that should be renamed
| * URI. They MUST NOT treat this provider identifier as a second resource | ||
| * identity. | ||
| */ | ||
| instanceId: string; |
There was a problem hiding this comment.
on the ID/URI note -- I don't see this used/passed around anywhere else in the protocol. How does a client use it / can it be removed?
There was a problem hiding this comment.
instanceId predates this PR and supports sidebar-pin restoration and matching agent open requests to canvases. URI-only identity is a possibility, but replacing those uses requires a broader migration. I propose retaining it here and exploring that in a follow-up. I’ve clarified the docstring locally to distinguish correlation from protocol addressing.
There was a problem hiding this comment.
I would favor getting rid of it. It's never used outside of this one field, there's no reason to have it in the protocol when we already have a unique identifier (the URI)
| /** Human-readable canvas type title. */ | ||
| title: string; | ||
| /** Description of what the canvas type does. */ | ||
| description: string; |
There was a problem hiding this comment.
Should this be StringOrMarkdown?
There was a problem hiding this comment.
I checked the current runtime and Copilot app implementations. The runtime declares this as a plain String and defines it as a short, single-sentence catalog description. The app preserves and validates it as a string, uses it as plain search/accessibility text, and renders it directly in Canvas pickers and Customize. Keeping string here matches both source and consumer behavior; StringOrMarkdown would introduce rendering and sanitization semantics that neither currently supports.
🤖 Written by GitHub Copilot on behalf of Joaquín Ruales (@jruales).
There was a problem hiding this comment.
I am not necessarily asking what the runtime does, I'm asking what should it do. If we make this a string and only a string, changing it in the future is a breaking change.
| * Declaring namespaces. `extensionId` MUST be unique within this | ||
| * array. An empty array is an authoritative loaded registry with no types. | ||
| */ | ||
| extensions: CanvasExtensionDeclaration[]; |
There was a problem hiding this comment.
Should this be among the SessionState.customizations?: Customization[] instead of on its own over here?
There was a problem hiding this comment.
Kept this in the new Canvas collection rather than SessionState.customizations: it describes types currently available in one exact chat, whereas customizations describe session-scoped sources and enablement. Runtime registrations can also exist without a corresponding source customization. A provenance link could connect the two later without making customizations a second registry.
🤖 Written by GitHub Copilot on behalf of Joaquín Ruales (@jruales).
Auto-replied by the GitHub Copilot app
| * @stability 1.0 | ||
| * @clientDispatchable | ||
| */ | ||
| export interface ChatCanvasRegistryRequestedAction { |
There was a problem hiding this comment.
An alternative design:
- Remove
canvasRegistryandcanvasesfrom the ChatState - Intead advertise a
canvasesUri?: URIin the ChatState that would be a new CanvasesState - Have that state expose the
registryandcanvasesstate. Subscribing to that would trigger enumeration of canvas registries as this action does today.
I like this because:
- It segments off canvas capability so that hosts/clients/implementors who don't support them don't have the code or mental overhead of dealing with canvas concepts mixed into general Chat state which everyone cares about
- It composes well as we start thinking about cross-session/app-level canvases -- the canvases URIs would just be given out additionally by the root state or whatever we want to do there, but after that point operate the exact same way.
There was a problem hiding this comment.
Implemented in 2309426, with the VS Code consumer in microsoft/vscode#345703. ChatState.canvasesUri now points to a CanvasesState containing the registry and live references; openCanvas stays instance-addressed and names the collection as its owner.
Two deliberate differences: collection subscriptions enumerate already-live runtimes, but cold resume/extension startup still requires canvases/registryRequested, so passive membership and pin observers don't start runtimes. Also, the shipped ChatState.canvases field/action remain deprecated projections of the same membership for compatibility. Registry loading/errors and explicit retry are represented in state. Ownership remains chat-scoped in this PR.
🤖 Written by GitHub Copilot on behalf of Joaquín Ruales (@jruales).
Auto-replied by the GitHub Copilot app
There was a problem hiding this comment.
Did you intend to remove ChatState.canvases and chat/canvasesChanged outright, or deprecate them? They predate this PR, are present in the AHP 1.0.0 release, and have a consumer in released VS Code 1.141.0, although the Canvas feature is experimental/default-off.
The pushed change moves discovery and live membership into CanvasesState, advertised through ChatState.canvasesUri. For now, I've deprecated the old field/action and kept them as a compatibility projection of the collection's authoritative membership—not a separate inventory. Are you okay with removing that projection outright instead?
🤖 Written by GitHub Copilot on behalf of Joaquín Ruales (@jruales).
Auto-replied by the GitHub Copilot app
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Separate passive collection observation from explicit runtime activation, preserve legacy chat membership, and carry full input schemas through generated clients. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve Canvas collection registry and membership alongside upstream snapshot decoding, action origin generation, and rejected-envelope handling. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
| * back to those references when this pointer is absent. Advertising the URI | ||
| * does not require materializing backing or starting extensions. |
There was a problem hiding this comment.
| * back to those references when this pointer is absent. Advertising the URI | |
| * does not require materializing backing or starting extensions. | |
| * back to those references when this pointer is absent. |
| */ | ||
| backgroundWork?: BackgroundWork[]; | ||
| /** | ||
| * Advertised `ahp-canvases:` collection owned by this exact chat. |
There was a problem hiding this comment.
| * Advertised `ahp-canvases:` collection owned by this exact chat. | |
| * Advertised `ahp-canvases:` collection owned by this chat. |
| * @category Canvases State | ||
| * @nonexhaustive | ||
| */ | ||
| export enum CanvasRegistryStatus { |
There was a problem hiding this comment.
| export enum CanvasRegistryStatus { | |
| export const enum CanvasRegistryStatus { |
| * Advertising and subscribing are observation only: hosts MUST NOT create | ||
| * backing, resume a cold runtime, or start extensions to serve a subscription. | ||
| * Hosts MAY enumerate or refresh an already-live runtime. Collection ownership | ||
| * is established by the host, not inferred from URI grammar. Other ownership | ||
| * scopes are not currently defined. | ||
| * |
There was a problem hiding this comment.
This is up to the implementation, doesn't matter for the protocol.
| * Advertising and subscribing are observation only: hosts MUST NOT create | |
| * backing, resume a cold runtime, or start extensions to serve a subscription. | |
| * Hosts MAY enumerate or refresh an already-live runtime. Collection ownership | |
| * is established by the host, not inferred from URI grammar. Other ownership | |
| * scopes are not currently defined. | |
| * |
| /** Stable identifier of the extension that declares the canvas. */ | ||
| extensionId: string; | ||
| /** Provider-local canvas type identifier. */ | ||
| canvasId: string; |
There was a problem hiding this comment.
So this is canvasTypeId; not canvasId -- that should be renamed
| * within this array. An empty array is an authoritative loaded registry with | ||
| * no types. |
There was a problem hiding this comment.
| * within this array. An empty array is an authoritative loaded registry with | |
| * no types. | |
| * within this array. |
| export interface CanvasReference { | ||
| /** Canvas channel URI. Subscribe to this resource for the full state. */ | ||
| /** | ||
| * Canvas channel URI. Subscribe to this resource for the full state. |
There was a problem hiding this comment.
should note the scheme
| * URI. They MUST NOT treat this provider identifier as a second resource | ||
| * identity. | ||
| */ | ||
| instanceId: string; |
There was a problem hiding this comment.
I would favor getting rid of it. It's never used outside of this one field, there's no reason to have it in the protocol when we already have a unique identifier (the URI)
| /** Owning declaration namespace. */ | ||
| extensionId: string; | ||
| /** Owning extension display name, when available. */ | ||
| /** Owning namespace title, when available. */ |
There was a problem hiding this comment.
What does a namespace mean here? This is a new concept.
| * @stability 1.0 | ||
| * @clientDispatchable | ||
| */ | ||
| export interface CanvasesRegistryRequestedAction { |
There was a problem hiding this comment.
Is there any case I would subscribe to ahp-canvases but not want to dispatch this action to materialize?
Summary
AHP already projects live Canvas instances through
ChatState.canvasesand experimentalahp-canvas:channels, but clients also need an authoritative way to discover the Canvas types available to one exact chat and manage a selected Canvas resource.This PR models discovery as chat state and uses the Canvas channel URI as the resource identity:
ChatState.canvasRegistryis the authoritative exact-chat Canvas type registry.chat/canvasRegistryChangedreplaces or clears that registry when live provider registration changes.chat/canvasRegistryRequestedexplicitly requests potentially effectful materialization for a persisted cold chat.openCanvasuses a client-chosenahp-canvas:URI and separately identifies the owning chat and declaration.disposeCanvascloses that URI-addressed Canvas resource.CanvasExtensionDeclaration; nestedCanvasTypeDeclarationentries usetitleand contain only type-local metadata.AgentCapabilities.canvases.Protocol behavior
Live registry state
For a live chat, the host keeps
canvasRegistrysynchronized with provider registration and emitschat/canvasRegistryChangedonly when the authoritative registry changes. Clients do not poll and do not treat changes to the open-instance list as registry invalidation.The registry distinguishes three states:
{ extensions: [] }: materialized, with no available Canvas types;(extensionId, canvasId).requiresInputremains so clients can exclude declarations whose input flow they do not support. Speculative action metadata is not part of the registry.Cold materialization
When a persisted chat is cold, a client may dispatch
chat/canvasRegistryRequested. The reducer intentionally leaves optimistic state unchanged while the host may resume the backing runtime, discover extensions, and execute extension startup code. The host then publishes the complete result throughchat/canvasRegistryChanged.Materialization must not create a backing for a brand-new chat, send a user message, or invoke a model.
URI-addressed lifecycle
openCanvas.channelis the client-chosenahp-canvas:resource URI. Reusing that URI for the same chat and declaration focuses or refreshes the logical instance; reusing it for a different chat, extension, or Canvas type must fail withConflict.disposeCanvas.channelidentifies the same resource for disposal.CanvasState.instanceIdremains provider-facing correlation metadata; the Canvas URI is the AHP resource identity.sequenceDiagram participant C as Client participant H as Agent Host C->>H: subscribe(chat) H-->>C: ChatState snapshot opt Registry absent and chat persisted C->>H: dispatchAction(chat, canvasRegistryRequested) H->>H: Resume runtime and discover providers H-->>C: action(chat, canvasRegistryChanged) end C->>H: openCanvas(canvas, chat, extensionId, canvasId) H-->>C: action(chat, canvasesChanged) C->>H: subscribe(canvas) H-->>C: CanvasState snapshot C->>H: disposeCanvas(canvas) H-->>C: action(chat, canvasesChanged)Compatibility and generated surfaces
AgentCapabilities.canvasesremain unsupported without probing.1.1.0; this PR does not bump the protocol version.openCanvas/disposeCanvascommand helpers, and Swift dispatchability matches the client-dispatchable registry request.Validation
npm testnpm run docs:buildnpm run typecheck && npm test && npm run buildcargo fmt --all -- --check,cargo clippy --workspace -- -D warnings,cargo test --workspacego build ./...,gofmt -l,go vet ./...,go test ./...swift build && swift test./gradlew build --stacktraceon JDK 17🤖 Written by GitHub Copilot on behalf of Joaquín Ruales (@jruales).