Skip to content

Add SDK canvas runtime support#1401

Merged
jmoseley merged 29 commits into
mainfrom
jmoseley/sdk-canvas-runtime-support
May 24, 2026
Merged

Add SDK canvas runtime support#1401
jmoseley merged 29 commits into
mainfrom
jmoseley/sdk-canvas-runtime-support

Conversation

@jmoseley
Copy link
Copy Markdown
Contributor

@jmoseley jmoseley commented May 23, 2026

What changed

Adds canvas runtime support across the Rust, Node, Python, Go, and .NET SDKs so consumers can declare canvases on session.create / session.resume, install a single CanvasHandler, and receive routed canvas.open / canvas.close / canvas.action.invoke JSON-RPC requests from the runtime. Resume surfaces openCanvases for rehydration, and host code can call session.canvas.* for native UI / chrome actions.

Per-language surface

  • Rust (rust/src/canvas.rs): CanvasDeclaration, CanvasHandler trait, CanvasHostContext/CanvasOpenContext/CanvasActionContext/CanvasLifecycleContext, CanvasError, CanvasOpenResponse, ExtensionInfo. Wire types (OpenCanvasInstance, CanvasAction, CanvasInstanceAvailability, CanvasInvokeActionRequest/Result, etc.) consumed directly from generated::api_types — no duplication. Session::open_canvases() accessor; host APIs via session.rpc().canvas().
  • Node (nodejs/src/canvas.ts): createCanvas, canvas declarations, handler contexts, errors, exports. Session create/resume thread canvases, requestCanvasRenderer, requestExtensions, extensionInfo.
  • Python (python/copilot/canvas.py): CanvasHandler ABC with default on_close / on_action (raises canvas_action_no_handler). _jsonrpc loosened to allow arbitrary JSON return values for action results.
  • Go (go/canvas.go): CanvasHandler interface + CanvasHandlerDefaults embeddable for partial impls. Inbound RPC registered via jsonrpc2.RequestHandlerFor with {code,message} error envelope.
  • .NET (dotnet/src/Canvas.cs): idiomatic ICanvasHandler with async methods; same dispatch shape.

Java is intentionally not included in this PR and will follow separately.

Shared design

  • App-side dispatch: SDK exposes a single CanvasHandler per session. Consumers switch on canvas_id themselves — no per-canvas registry inside the SDK.
  • Generated wire types are imported directly from each language's codegen module; the hand-written canvas API is purely additive.
  • Inbound RPC without a handler installed returns {"code":"canvas_handler_unset","message":"..."}.
  • ExtensionInfo { source, name } lets consumers opt into stable agent-facing extension IDs (github-app:<provider-name>).

Notes for reviewers

Additive on top of the existing permission / user-input / tool handler models — no broad handler refactor. Canvas declarations require displayName. capabilities.ui.canvases is boolean. session.canvas.listOpen is a real RPC.

Validation

Per language:

  • Rust: cargo +nightly-2026-04-14 fmt --check, cargo clippy --all-features --all-targets -- -D warnings, cargo test --all-features, cargo doc --no-deps --all-features
  • Node: npm run typecheck, npm run lint, npx vitest run
  • Python: uv run ruff format/check, uv run ty check copilot, uv run pytest
  • Go: gofmt, go build/vet/test ./...
  • .NET: dotnet format --verify-no-changes, dotnet build, dotnet test

@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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@jmoseley jmoseley force-pushed the jmoseley/sdk-canvas-runtime-support branch from 1202bc1 to c50b728 Compare May 24, 2026 07:24
@jmoseley jmoseley changed the base branch from main to update-copilot-1.0.53-2 May 24, 2026 07:25
@github-actions

This comment has been minimized.

Base automatically changed from update-copilot-1.0.53-2 to main May 24, 2026 07:48
@jmoseley jmoseley enabled auto-merge May 24, 2026 07:54
jmoseley and others added 3 commits May 24, 2026 07:54
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 and others added 3 commits May 24, 2026 07:54
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
Move per-canvas registry, Canvas builder, dispatch helpers, and the
SessionCanvas host helper out of the SDK. The Rust canvas surface now
matches the other typed extension points (PermissionHandler /
UserInputHandler / HookHandler):

  SessionConfig
    .with_canvases([CanvasDeclaration, ...])
    .with_canvas_handler(Arc::new(MyHandler))

Removed:
  - canvas::Canvas, CanvasBuilder (declaration+handler bundle)
  - canvas::CanvasRegistry, build_registry, dispatch_canvas_*
  - session::SessionCanvas + Session::canvas() accessor
    (callers move to session.rpc().canvas().*)

Kept (the wire boundary + typed extension point):
  - All wire types (CanvasDeclaration, OpenCanvasInstance, ...)
  - CanvasHandler trait + on_open/on_action/on_close
  - SessionConfig/ResumeSessionConfig.canvases (now Vec<CanvasDeclaration>)
  - SessionConfig/ResumeSessionConfig.canvas_handler

handle_request dispatches canvas.open/close/action.invoke directly to
the handler; the per-canvas registry now lives in the app layer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jmoseley jmoseley force-pushed the jmoseley/sdk-canvas-runtime-support branch from 3a8b85f to 3c0850d Compare May 24, 2026 14:55
@github-actions

This comment has been minimized.

Removed CanvasInstanceAvailability, OpenCanvasInstance,
CanvasAgentActionDeclaration (-> CanvasAction), CanvasDiscoverResult,
DiscoveredCanvas, CanvasListOpenResult, CanvasOpenRequest,
CanvasCloseRequest, CanvasInvokeActionRequest, and
CanvasInvokeActionResult from canvas.rs; consumers import these from
crate::generated::api_types directly. The remaining hand-written types
(CanvasDeclaration, CanvasOpenResponse, handler trait, contexts,
CanvasError) are genuinely additive provider-authoring contracts.

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

This comment has been minimized.

The canvas wire types were deduplicated against generated/api_types.rs,
renaming CanvasAgentActionDeclaration to CanvasAction. A doc comment
in canvas.rs still referenced the old name, which broke cargo doc on CI
(broken_intra_doc_links is denied).

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

This comment has been minimized.

jmoseley and others added 2 commits May 24, 2026 09:14
Mirrors the Rust SDK canvas surface in rust/src/canvas.rs:

- CanvasDeclaration, CanvasOpenResponse, CanvasHostContext,
  CanvasOpenContext / CanvasActionContext / CanvasLifecycleContext,
  CanvasError, CanvasHandler interface + CanvasHandlerDefaults, and
  ExtensionInfo.
- SessionConfig / ResumeSessionConfig: Canvases, RequestCanvasRenderer,
  RequestExtensions, CanvasHandler, ExtensionInfo.
- Inbound JSON-RPC dispatch for canvas.open, canvas.close, and
  canvas.action.invoke, with a canvas_handler_unset error envelope when
  no handler is installed and a canvas_handler_error envelope when a
  handler returns a non-CanvasError error.
- Session.OpenCanvases() surfaces the openCanvases snapshot from the
  session.resume response.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mirrors the Rust SDK design: callers declare canvases on session.create
/ session.resume, install a single CanvasHandler, and the SDK dispatches
inbound canvas.open / canvas.close / canvas.action.invoke JSON-RPC
requests to that handler. Resume populates session.open_canvases from
the response. JSON-RPC dispatch was loosened to allow handlers to return
any JSON value (canvas.action.invoke result is arbitrary JSON).

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

This comment has been minimized.

Ports the canvas runtime surface from the Rust SDK to the .NET SDK so
.NET hosts can declare canvases on session create/resume, advertise an
extension identity, and handle inbound canvas.open / canvas.close /
canvas.action.invoke RPC calls.

* New public Canvas.cs surface (CanvasDeclaration, ExtensionInfo,
  CanvasOpenResponse, CanvasHostContext, lifecycle/action/open contexts,
  CanvasError, ICanvasHandler, CanvasHandlerBase). All marked
  [Experimental(GHCP001)].
* SessionConfigBase gains Canvases, RequestCanvasRenderer,
  RequestExtensions, ExtensionInfo, CanvasHandler.
* CreateSession/ResumeSession requests forward the new fields and
  surface OpenCanvases on the response. CopilotSession exposes the
  returned canvases via OpenCanvases.
* CopilotClient registers canvas.open / canvas.close /
  canvas.action.invoke handlers and dispatches them to the session,
  which invokes the user's ICanvasHandler and returns structured
  CanvasError data via a new JsonRpc LocalRpcInvocationException path.

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

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@ghost ghost left a comment

Choose a reason for hiding this comment

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

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

Comment thread nodejs/src/session.ts
Comment thread nodejs/src/canvas.ts
Comment thread python/copilot/client.py
- Node: add openCanvases accessor on CopilotSession and OpenCanvases
  field on ResumeSessionConfig so callers can both rehydrate from
  the resume response and pre-populate canvas state on resume.
- Node: document why createCanvas/Canvas intentionally diverges from
  the per-session CanvasHandler pattern used by Rust/Python/Go/.NET.
- Go: add ResumeSessionConfig.OpenCanvases, thread through to the
  resume request wire payload, and add a serialization test.
- .NET: add ResumeSessionConfig.OpenCanvases, thread through to the
  internal ResumeSessionRequest record, and add a serialization test.

Mirrors what Rust and Python already do, fixing wire-protocol parity
across SDKs.

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

ghost commented May 24, 2026

Cross-SDK Consistency Review 🔍

Overall, this is an impressively well-aligned multi-language implementation. The five SDKs (Rust, Node.js, Python, Go, .NET) are highly consistent on wire format, lifecycle callbacks (on_open/on_close/on_action), context types, ExtensionInfo, CanvasDeclaration, CanvasOpenResponse, and the session.canvas.* host-side RPC surface.

✅ Intentional Divergence (well-documented)

Node.js per-canvas factory vs single handler: The createCanvas() factory pattern in Node.js vs the single CanvasHandler per session in Rust/Python/Go/.NET is intentional and documented in nodejs/src/canvas.ts. Both target the same wire protocol. ✅


🔎 Minor Inconsistency Found

CanvasHostCapabilities is not a named type in Node.js

In all other SDKs, CanvasHostCapabilities is a named, exported type:

  • Python: CanvasHostCapabilities dataclass exported in __all__
  • Go: CanvasHostCapabilities struct exported from the package
  • .NET: CanvasHostCapabilities sealed class (public)
  • Rust: CanvasHostCapabilities struct (pub)

In Node.js however, the capabilities are typed inline:

// nodejs/src/canvas.ts line 67
export interface CanvasHostContext {
    capabilities?: {       // ← anonymous inline type
        canvases?: boolean;
    };
}

CanvasHostCapabilities is not exported from nodejs/src/index.ts.

This means Node.js consumers can't reference the capabilities type by name (e.g., to annotate a variable or destructure typed), while consumers in every other SDK can. A small addition to maintain parity:

/** Host capability details passed to canvas provider callbacks. */
export interface CanvasHostCapabilities {
    canvases?: boolean;
}

export interface CanvasHostContext {
    capabilities?: CanvasHostCapabilities;
}

...and export CanvasHostCapabilities from index.ts.


i️ Note on CanvasError.handler_unset()

Python exposes CanvasError.handler_unset() as a public class method, while other SDKs treat the unset-handler error as internal (e.g., .NET's CanvasErrorHelpers.HandlerUnset() is internal; Go and Rust construct it inline). This is a very minor surface inconsistency—consumers shouldn't normally need to construct this error—but worth noting for future cleanup.


✅ Everything Else

  • All five SDKs expose open_canvases/OpenCanvases on the session ✅
  • requestCanvasRenderer, requestExtensions, extensionInfo present in all five SessionConfig/create+resume params ✅
  • CanvasDeclaration, CanvasOpenResponse, context types all structurally equivalent ✅
  • canvas_handler_unset error code string matches across all SDKs ✅
  • Java exclusion is documented and expected to follow separately ✅

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

Copy link
Copy Markdown
Contributor

@ghost ghost left a comment

Choose a reason for hiding this comment

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

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

Comment thread nodejs/src/canvas.ts
@jmoseley jmoseley added this pull request to the merge queue May 24, 2026
Merged via the queue into main with commit 51043b1 May 24, 2026
45 checks passed
@jmoseley jmoseley deleted the jmoseley/sdk-canvas-runtime-support branch May 24, 2026 19:12
Comment thread dotnet/src/Canvas.cs
{
/// <summary>Whether the host supports canvas rendering.</summary>
[JsonPropertyName("canvases")]
public bool Canvases { get; set; }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This name confuses me a bit. Should this be specific to rendering, as elaborated on in the comment? It's not clear to me from "Canvases" that it's specific to rendering, and presumably there are other capabilities a canvas host will be capable of related to canvases.

Comment thread dotnet/src/Canvas.cs
Comment thread dotnet/src/Canvas.cs
Comment thread dotnet/src/Canvas.cs
Comment thread dotnet/src/Canvas.cs
/// default no-op / no-handler implementations of the optional callbacks.
/// </summary>
[Experimental(Diagnostics.Experimental)]
public abstract class CanvasHandlerBase : ICanvasHandler
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this necessary? Doesn't seem like it provides much in the way of convenience.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CanvasHandlerBase is there for netstandard2.0 consumers — that target can't use default interface methods on ICanvasHandler, so without the base class every netstandard2.0 user has to write the OnCloseAsync no-op + OnActionAsync throw boilerplate themselves. Happy to drop it (and just put the boilerplate in the README) if you'd rather, but leaving as-is in #1420 — let me know if you want it removed in a follow-up.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, I think we should drop it. Implementing this will be rare, and the cited boilerplate is a trivial one-liner. Better to not add additional surface area to the namespace.

Comment thread dotnet/src/JsonRpc.cs
Comment thread dotnet/src/Session.cs
Comment thread rust/src/canvas.rs
Comment thread rust/src/canvas.rs
Assert.Equal(1, openCanvases.GetArrayLength());
Assert.Equal("canvas-id", openCanvases[0].GetProperty("canvasId").GetString());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there a way we can add some good E2E tests in the SDK for this canvas support, in each language? We have a fairly extensive set of hundreds of E2E tests in each of the languages, and while we have some gaps we're working to fill, we're trying to make it so that we have great E2E coverage for every API exposed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I added a tiny bit of E2E coverage in #1413 but @jmoseley will know better what other coverage would be valuable to add.

Comment thread nodejs/src/canvas.ts
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.

5 participants