Skip to content

Commit 098b6c9

Browse files
jmoseleyCopilot
andcommitted
Add required instance_id to CanvasOpenContext (Rust + Node)
Mirrors runtime PR #8441 making agent-supplied instance_id required on canvas.open. Handlers now receive ctx.instance_id directly instead of generating their own. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 77ffb49 commit 098b6c9

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

nodejs/src/canvas.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ export interface CanvasOpenContext {
103103
sessionId: string;
104104
/** Canvas id (matches the declaring `CanvasDeclaration.id`). */
105105
canvasId: string;
106+
/**
107+
* Agent-supplied stable instance id. Required by the runtime on every
108+
* `canvas.open` invocation; handlers should key their per-instance state
109+
* off this value.
110+
*/
111+
instanceId: string;
106112
/** Validated `input` payload, shaped by `CanvasDeclaration.inputSchema`. */
107113
input: unknown;
108114
/** Toolbar items declared on the canvas, passed through for convenience. */
@@ -309,9 +315,16 @@ export async function dispatchCanvasAction(
309315
): Promise<unknown> {
310316
switch (params.actionName) {
311317
case RESERVED_CANVAS_ACTIONS.open: {
318+
if (!params.instanceId) {
319+
throw new CanvasError(
320+
"canvas_missing_instance_id",
321+
"canvas.open requires an instanceId"
322+
);
323+
}
312324
const result = await canvas.onOpen({
313325
sessionId,
314326
canvasId: params.canvasId,
327+
instanceId: params.instanceId,
315328
input: params.input,
316329
toolbar: params.toolbar,
317330
});

rust/src/canvas.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ pub struct CanvasOpenContext {
118118
pub session_id: SessionId,
119119
/// Canvas id (matches the declaring [`CanvasDeclaration::id`]).
120120
pub canvas_id: String,
121+
/// Agent-supplied stable instance id. Required by the runtime on every
122+
/// `canvas.open` invocation; handlers should key their per-instance state
123+
/// off this value.
124+
pub instance_id: String,
121125
/// Validated `input` payload, shaped by [`CanvasDeclaration::input_schema`].
122126
pub input: Value,
123127
/// Toolbar items declared on the canvas, passed through for handler
@@ -376,9 +380,16 @@ pub async fn dispatch_canvas_invoke(
376380

377381
match params.action_name.as_str() {
378382
"canvas.open" => {
383+
let instance_id = params.instance_id.ok_or_else(|| {
384+
CanvasError::new(
385+
"canvas_missing_instance_id",
386+
"canvas.open requires an instanceId",
387+
)
388+
})?;
379389
let ctx = CanvasOpenContext {
380390
session_id,
381391
canvas_id: params.canvas_id,
392+
instance_id,
382393
input: params.input,
383394
toolbar: params.toolbar,
384395
};
@@ -564,7 +575,7 @@ mod tests {
564575

565576
let params = CanvasInvokeParams {
566577
canvas_id: "echo".into(),
567-
instance_id: None,
578+
instance_id: Some("echo-1".into()),
568579
action_name: "canvas.open".into(),
569580
input: json!({ "x": 1 }),
570581
toolbar: None,

0 commit comments

Comments
 (0)