Skip to content

Add SDK canvas runtime support#1401

Open
jmoseley wants to merge 22 commits into
mainfrom
jmoseley/sdk-canvas-runtime-support
Open

Add SDK canvas runtime support#1401
jmoseley wants to merge 22 commits into
mainfrom
jmoseley/sdk-canvas-runtime-support

Conversation

@jmoseley
Copy link
Copy Markdown
Contributor

Canvas providers need stable runtime contracts across SDKs so native hosts and extensions can declare canvases, handle provider callbacks, and drive canvas chrome without adopting the broader Rust handler refactor from the prototype branch.

What changed

  • Adds the Node extension canvas surface (createCanvas, canvas declarations, handler contexts, errors, and exports) and wires session create/resume to send canvases, requestCanvasRenderer, requestExtensions, and stable extensionInfo.
  • Adds focused Rust canvas support with Canvas, CanvasHandler, direct canvas.open|focus|reload|close|action.invoke provider callback routing, and host APIs under session.canvas() for discover, list_open, open, focus, reload, close, and invoke_action.
  • Aligns the SDK contracts with the runtime branch: displayName is required for canvas declarations, session.canvas.listOpen is a real RPC, resume consumes openCanvases, and capabilities.ui.canvases is boolean.
  • Adds ExtensionInfo { source, name } / extensionInfo so consumers can opt into stable agent-facing extension IDs like github-app:<provider-name> instead of reconnect-specific fallback IDs.

Notes for reviewers

The Rust implementation is additive and keeps the existing separate permission/user-input/tool handler model. Canvas provider callbacks are routed through a focused per-session canvas registry rather than a unified session handler refactor.

Validation

  • cd nodejs && npm run typecheck
  • cd nodejs && npm run lint (existing warnings only)
  • cd nodejs && npx vitest run test/client.test.ts test/extension.test.ts
  • cd rust && cargo +nightly-2026-04-14 fmt --check
  • cd rust && cargo clippy --all-features --all-targets -- -D warnings
  • cd rust && cargo test --all-features
jmoseley and others added 3 commits May 22, 2026 14:15
Add Node extension canvas APIs and direct canvas provider callback routing. Add Rust canvas declarations, provider handlers, create/resume wiring, and host session.canvas APIs aligned with the runtime schema.

Validation: nodejs typecheck/lint/tests; rust fmt/check/clippy; cargo test --all-features.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Expose stable extension identity metadata on Node and Rust session create/resume options and forward extensionInfo on the wire for canvas providers.

Validation: nodejs typecheck/lint/vitest; rust fmt/clippy/test --all-features.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jmoseley jmoseley requested a review from a team as a code owner May 23, 2026 04:50
Copilot AI review requested due to automatic review settings May 23, 2026 04:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds cross-SDK “canvas runtime” support, enabling SDK consumers to declare canvases, receive direct provider callbacks (canvas.*), and use host-side session.canvas.* RPCs with stable extension identity (extensionInfo)—without requiring the larger handler refactor from the prototype branch.

Changes:

  • Rust: Introduces a new canvas module (declarations, handler traits, dispatch, host RPC types) and wires SessionConfig / ResumeSessionConfig to serialize canvas-related fields on session.create / session.resume.
  • Rust: Adds Session::canvas() host API and updates the session event loop/router to handle direct provider callback requests (canvas.open|focus|reload|close|action.invoke).
  • Node.js: Adds a canvas surface (createCanvas, types, dispatch), forwards canvas declarations + request flags + extensionInfo on session create/resume, and routes direct canvas.* JSON-RPC requests to registered canvases with tests.
Show a summary per file
File Description
rust/tests/session_test.rs Adds coverage for Rust canvas wire fields, provider dispatch routing, and SessionCanvas host API behavior.
rust/tests/e2e/elicitation.rs Updates capability struct test to include the new ui.canvases field.
rust/src/wire.rs Extends session create/resume wire payloads with canvases, request flags, and extension_info.
rust/src/types.rs Adds ExtensionInfo, canvas config fields on session configs, resume result open-canvas capture, and UiCapabilities.canvases.
rust/src/session.rs Adds SessionCanvas host API + open-canvas tracking and routes canvas.* provider callbacks through a per-session registry.
rust/src/router.rs Adds debug logging when routing requests to a registered session.
rust/src/lib.rs Exposes the new canvas module publicly.
rust/src/jsonrpc.rs Adds debug logging for incoming JSON-RPC requests from the runtime.
rust/src/canvas.rs New Rust canvas module: declarations, handler traits, registry + dispatch, request/response types, and unit tests.
nodejs/test/extension.test.ts Verifies createCanvas is exported from the extension surface.
nodejs/test/client.test.ts Adds tests for forwarding canvas fields on create/resume and for direct provider dispatch behavior.
nodejs/src/types.ts Adds SessionCapabilities.ui.canvases, introduces ExtensionInfo, and extends session configs with canvas fields.
nodejs/src/session.ts Adds per-session canvas registration and lookup to support direct dispatch routing.
nodejs/src/index.ts Exports canvas APIs/types and ExtensionInfo from the main entrypoint.
nodejs/src/extension.ts Exports canvas APIs/types and ExtensionInfo from the extension surface.
nodejs/src/client.ts Forwards canvas fields on create/resume and registers handlers for direct canvas.* provider callbacks.
nodejs/src/canvas.ts New Node canvas module: canvas declaration/types, createCanvas, and provider request dispatch helper.

Copilot's findings

  • Files reviewed: 17/17 changed files
  • Comments generated: 5
Comment thread rust/src/session.rs Outdated
Comment thread rust/src/canvas.rs Outdated
Comment thread rust/src/canvas.rs Outdated
Comment thread nodejs/src/client.ts Outdated
Comment thread nodejs/src/client.ts Outdated
@github-actions

This comment has been minimized.

Add CanvasInstanceAvailability, OpenCanvasInstance availability, and resume openCanvases seeding support to the Rust SDK.

Validation: cargo +nightly-2026-04-14 fmt --check; cargo clippy --all-features --all-targets -- -D warnings; cargo test --all-features.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Validate canvas provider request payloads before routing, surface Rust canvas serialization and builder errors, and clarify list_open RPC behavior.

Validation: nodejs typecheck/lint/vitest; rust fmt/clippy/test --all-features.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Remove stale focus/close/reload canvas agent-tool references and cover custom-tool permission payload passthrough for open_canvas.

Validation: nodejs typecheck; cargo test --all-features permission_request_data_extracts_typed_kind.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Align canvas contribution and discovered canvas descriptions with the runtime schema, update canvas tool-surface docs, and cover open_canvas custom-tool permission payloads.

Validation: nodejs typecheck/lint/vitest client+extension; rust fmt/clippy; cargo check --all-features --all-targets; targeted canvas and permission tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Align OpenCanvasInstance with the runtime schema by making availability required and updating canvas host/resume tests.

Validation: cargo check --all-features --all-targets; cargo test --all-features canvas; targeted session canvas tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Rename the Node canvas provider option from onOpen to open and remove lifecycle handler options from the extension canvas API.

Validation: nodejs typecheck; vitest client and extension tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Aligns the SDK canvas contract with copilot-agent-runtime
jmoseley/adr-implementation-plan commits 85b23bc264 and acdefc1bc1:

- Rename agentActions to actions on CanvasDeclaration and
  DiscoveredCanvas (Rust + Node).
- Drop toolbar from CanvasContribution and CanvasOpenResponse, and
  remove CanvasToolbarItemDeclaration / CanvasToolbarItem entirely.
- Drop SessionCanvas::focus and SessionCanvas::reload host APIs;
  re-opening with the same instanceId now drives focus via
  session.canvas.opened { reopen: true }, and reload is renderer-only.
- Drop canvas.focus / canvas.reload provider JSON-RPC routes and the
  matching CanvasHandler::on_focus / on_reload hooks; canvas.close keeps
  its dedicated dispatch path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Lets extension authors observe canvas instance close events without
adding back the dropped onFocus/onReload hooks. Fire-and-forget: the
handler's return value is ignored and the provider response is still
undefined.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Each entry in createCanvas({ actions }) may now carry its own optional
handler, co-located with the action's metadata. The top-level onAction
remains as a fallback for actions that don't define their own handler.

Dispatch order:
  1. Per-action handler when set.
  2. Top-level onAction otherwise.
  3. canvas_action_no_handler if neither is wired.

The handler closure is stripped from the wire CanvasDeclaration sent on
session.create / session.resume; only the action's name, description,
and inputSchema reach the runtime. A new CanvasAction authoring type
sits on top of the existing CanvasAgentActionDeclaration wire type.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Per-action handlers are now the only dispatch path. Declared actions
without a handler fall through to canvas_action_no_handler. Keeps the
action's metadata and behavior co-located and removes a second
indirection that always boiled down to a switch on actionName.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

jmoseley and others added 2 commits May 23, 2026 19:49
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

jmoseley and others added 3 commits May 23, 2026 20:00
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Drop CanvasToolDefinition, CanvasToolDefinitionDefer, and the
CanvasOpenResponse.tools / OpenCanvasInstance.tools fields from both
the Node and Rust SDKs. The CLI side is being removed in lockstep, so
the wire contract no longer carries this field.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review

This PR adds canvas runtime support to the Node.js and Rust SDKs. The following new public APIs are being added to Node.js:

New public types/classes

  • Canvas, CanvasError, createCanvas()
  • CanvasAction, CanvasActionContext, CanvasDeclaration, CanvasHostContext, CanvasJsonSchema, CanvasLifecycleContext, CanvasOpenContext, CanvasOpenResponse, CanvasOptions
  • ExtensionInfo

New SessionConfigBase options

  • canvases?: Canvas[]
  • requestCanvasRenderer?: boolean
  • requestExtensions?: boolean
  • extensionInfo?: ExtensionInfo

None of these exist in Python, Go, .NET, or Java SDKs.

Assessment

The canvas provider feature is a significant new surface area that has been deliberately added to Node.js (extension host) and Rust (native host) — both of which are the primary runtimes for this feature. The PR description scopes the work explicitly to these two SDKs.

However, the three session config options that affect session behaviour (requestCanvasRenderer, requestExtensions, extensionInfo) are more broadly applicable — they are opt-ins that any SDK consumer might want to use regardless of whether they are implementing a canvas provider. For example:

  • A Python-based app using requestCanvasRenderer: true would want the model to have access to canvas tools.
  • An app with a stable extension identity would want to provide extensionInfo.

Recommendation: Consider whether requestCanvasRenderer, requestExtensions, and extensionInfo should be added to the session config in the other SDKs (Python, Go, .NET, Java) as follow-up work, even if the full canvas provider handler surface (createCanvas, callbacks, etc.) is deferred. These are wire-protocol fields that are useful independently of canvas provider implementation.

If the intent is to intentionally keep canvas support Node.js/Rust only for this release, a brief note in the PR or a tracking issue for the other SDKs would be helpful for future contributors.

Generated by SDK Consistency Review Agent for issue #1401 · ● 5.6M ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants