fix(copilot-sdk-nodejs): correct assistant message delta event name (#1712)

The accessibility-report recipe and its companion doc used "assistant.message.delta" (dotted), which never matches the SDK event. The canonical name is "assistant.message_delta" (underscore), as documented in instructions/copilot-sdk-nodejs.instructions.md and used by the Python cookbook. Without this fix the streaming branch was dead and no incremental output was printed.


(cherry picked from commit e050d7bfc96c55924b0bf534c8b3e57359463ba9)

Signed-off-by: syalioune <sy_alioune@yahoo.fr>
This commit is contained in:
syalioune
2026-05-15 03:17:38 +02:00
committed by GitHub
parent ede8b1f59e
commit ee3e386c9c
2 changed files with 10 additions and 10 deletions
@@ -90,7 +90,7 @@ async function main() {
let idleResolve: (() => void) | null = null;
session.on((event) => {
if (event.type === "assistant.message.delta") {
if (event.type === "assistant.message_delta") {
process.stdout.write(event.data.deltaContent ?? "");
} else if (event.type === "session.idle") {
idleResolve?.();
@@ -179,7 +179,7 @@ main().catch(console.error);
## How it works
1. **Playwright MCP server**: Configures a local MCP server running `@playwright/mcp` to provide browser automation tools
2. **Streaming output**: Uses `streaming: true` and `assistant.message.delta` events for real-time token-by-token output
2. **Streaming output**: Uses `streaming: true` and `assistant.message_delta` events for real-time token-by-token output
3. **Accessibility snapshot**: Playwright's `browser_snapshot` tool captures the full accessibility tree of the page
4. **Structured report**: The prompt engineers a consistent WCAG-aligned report format with emoji severity indicators
5. **Test generation**: Optionally detects the project language and generates Playwright accessibility tests
@@ -212,7 +212,7 @@ Unlike `sendAndWait`, this recipe uses streaming for real-time output:
```typescript
session.on((event) => {
if (event.type === "assistant.message.delta") {
if (event.type === "assistant.message_delta") {
process.stdout.write(event.data.deltaContent ?? "");
} else if (event.type === "session.idle") {
idleResolve?.();
@@ -55,7 +55,7 @@ async function main() {
let idleResolve: (() => void) | null = null;
session.on((event) => {
if (event.type === "assistant.message.delta") {
if (event.type === "assistant.message_delta") {
process.stdout.write(event.data.deltaContent ?? "");
} else if (event.type === "session.idle") {
idleResolve?.();
@@ -72,12 +72,12 @@ async function main() {
const prompt = `
Use the Playwright MCP server to analyze the accessibility of this webpage: ${url}
Please:
1. Navigate to the URL using playwright-browser_navigate
2. Take an accessibility snapshot using playwright-browser_snapshot
3. Analyze the snapshot and provide a detailed accessibility report
Format the report EXACTLY like this structure with emoji indicators:
📊 Accessibility Report: [Page Title] (domain.com)
@@ -133,8 +133,8 @@ async function main() {
const detectLanguagePrompt = `
Analyze the current working directory to detect the primary programming language used in this project.
Look for project files like package.json, *.csproj, pom.xml, requirements.txt, go.mod, etc.
Respond with ONLY the detected language name (e.g., "TypeScript", "JavaScript", "C#", "Python", "Java")
Respond with ONLY the detected language name (e.g., "TypeScript", "JavaScript", "C#", "Python", "Java")
and a brief explanation of why you detected it.
If no project is detected, suggest "TypeScript" as the default for Playwright tests.
`;
@@ -151,7 +151,7 @@ async function main() {
const testGenerationPrompt = `
Based on the accessibility report you just generated for ${url}, create Playwright accessibility tests in ${language}.
The tests should:
1. Verify all the accessibility checks from the report
2. Test for the issues that were found (to ensure they get fixed)
@@ -167,7 +167,7 @@ async function main() {
- Touch targets meet minimum size requirements
4. Use Playwright's accessibility testing features
5. Include helpful comments explaining each test
Output the complete test file that can be saved and run.
Use the Playwright MCP server tools if you need to verify any page details.
`;