Repository navigation
Expand file tree
/
Copy pathstep.html
More file actions
865 lines (808 loc) · 36.1 KB
/
Copy pathstep.html
File metadata and controls
865 lines (808 loc) · 36.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Self-guided, multilingual workshops for building agents with the GitHub Copilot SDK.">
<title>Copilot SDK Workshop</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=Instrument+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/marked@15.0.7/marked.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.11.1/styles/github-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
<link rel="stylesheet" href="../step.css">
<link rel="stylesheet" href="../light-theme.css">
<script src="../theme-toggle.js"></script>
<script src="../language-registry.js"></script>
<script src="../language-navigation.js"></script>
<script src="../markdown-language-preprocessor.js"></script>
<script src="../workshop-completion.js"></script>
</head>
<body>
<a class="skip-link" href="#lessonContent">Skip to lesson</a>
<header class="header">
<div class="header-content">
<button
class="nav-btn menu-btn"
id="menuButton"
type="button"
aria-expanded="false"
aria-controls="navigationPanel"
aria-label="Open sections">☰</button>
<a href="../index.html" class="header-brand" id="homeLink" aria-label="Copilot SDK Workshop home">
<span class="header-icon" aria-hidden="true">🤖</span>
<span class="header-title">Copilot SDK Workshop</span>
<span class="visually-hidden" id="headerLessonTitle">Loading lesson</span>
</a>
<nav class="header-nav" aria-label="Lesson actions">
<label class="language-select-label" for="languageSelector">Language</label>
<select class="language-select" id="languageSelector" aria-label="Workshop language">
<option value="">Choose language</option>
<option value="dotnet">.NET</option>
<option value="go">Go</option>
<option value="java">Java</option>
<option value="nodejs">Node.js</option>
<option value="python">Python</option>
<option value="rust">Rust</option>
</select>
<a href="../index.html" class="nav-btn" id="hubLink">🏠 Hub</a>
<a class="nav-btn" id="headerDocsLink" target="_blank" rel="noopener" hidden>📚 Docs ↗</a>
<button class="theme-toggle" type="button" onclick="toggleTheme()">☀️ Light</button>
<a class="nav-btn" id="previousHeaderLink" href="#" hidden>← Prev</a>
<a class="nav-btn" id="nextHeaderLink" href="#" hidden>Next →</a>
</nav>
</div>
</header>
<div class="lesson-progress">
<div class="progress-copy">
<span id="stepPosition">Loading</span>
<span id="stepEstimate"></span>
</div>
<div
class="progress-track"
id="progressTrack"
role="progressbar"
aria-label="Workshop progress"
aria-valuemin="0"
aria-valuemax="10"
aria-valuenow="0">
<span id="progressFill"></span>
</div>
</div>
<div class="flyout-overlay" id="navigationOverlay"></div>
<div class="layout">
<aside
class="flyout-panel"
id="navigationPanel"
aria-labelledby="navigationTitle"
tabindex="-1">
<div class="flyout-header">
<span class="flyout-title" id="navigationTitle">🤖 Workshop Steps</span>
<button
class="flyout-close"
id="closeNavigationButton"
type="button"
aria-label="Close sections">✕</button>
</div>
<nav class="flyout-nav" id="workshopNavigation" aria-label="Workshop steps"></nav>
</aside>
<main class="main lesson-main">
<div class="lesson-shell">
<div class="lesson-content" id="lessonContent">
<p class="visually-hidden" id="lessonStatus" role="status" aria-live="polite">Loading lesson.</p>
<div id="markdownContent" aria-busy="true">
<p class="loading-message">Loading lesson...</p>
</div>
<nav class="nav-footer" id="lessonFooter" aria-label="Lesson pagination"></nav>
</div>
</div>
</main>
</div>
<script>
const introSteps = [
{
id: 'intro-00-preflight',
file: 'workshop/intro-00-preflight.md',
title: 'Prepare for SDK 101',
navTitle: 'Preflight',
kind: 'preflight',
time: 'Untimed'
},
{
id: 'intro-01-sdk-basics',
file: 'workshop/intro-01-sdk-basics.md',
title: 'SDK basics',
navTitle: 'SDK basics',
kind: 'core',
number: 1,
time: '5 min'
},
{
id: 'intro-02-hello-world',
file: 'workshop/intro-02-hello-world.md',
demoAct: 'one',
title: 'Streaming hello world',
navTitle: 'Hello world',
kind: 'core',
number: 2,
time: '10 min'
},
{
id: 'intro-03-podcast-agent',
file: 'workshop/intro-03-podcast-agent.md',
demoAct: 'two',
title: 'Build the podcast agent',
navTitle: 'Podcast agent',
kind: 'core',
number: 3,
time: '12 min'
},
{
id: 'intro-04-wrap-up',
file: 'workshop/intro-04-wrap-up.md',
title: 'Recap and next steps',
navTitle: 'Recap',
kind: 'core',
number: 4,
time: '3 min'
}
];
const sdlcSteps = [
{
id: '00-preflight',
file: 'workshop/00-preflight.md',
title: 'Prepare your machine',
navTitle: 'Preflight',
kind: 'preflight',
time: 'Untimed'
},
{
id: '01-first-session',
file: 'workshop/01-first-session.md',
title: 'Create your first Copilot session',
navTitle: 'First session',
kind: 'core',
number: 1,
time: '10 min'
},
{
id: '02-streaming',
file: 'workshop/02-streaming.md',
title: 'Stream a response',
navTitle: 'Streaming',
kind: 'core',
number: 2,
time: '10 min'
},
{
id: '03-local-tool',
file: 'workshop/03-local-tool.md',
title: 'Add application-owned knowledge',
navTitle: 'Local tool',
kind: 'core',
number: 3,
time: '15 min'
},
{
id: '04-mcp-safety',
file: 'workshop/04-mcp-safety.md',
title: 'Connect an external tool safely',
navTitle: 'MCP and permissions',
kind: 'core',
number: 4,
time: '20 min'
},
{
id: '05-combine-tools',
file: 'workshop/05-combine-tools.md',
title: 'Combine local and MCP tools',
navTitle: 'Combine tools',
kind: 'core',
number: 5,
time: '15 min'
},
{
id: '06-structured-report',
file: 'workshop/06-structured-report.md',
title: 'Produce a structured report',
navTitle: 'Structured report',
kind: 'core',
number: 6,
time: '10 min'
},
{
id: '07-run-explain',
file: 'workshop/07-run-explain.md',
title: 'Run and explain the application',
navTitle: 'Run and explain',
kind: 'core',
number: 7,
time: '10 min'
},
{
id: '08-model-selection',
file: 'workshop/08-model-selection.md',
title: 'Select a model',
navTitle: 'Model selection',
kind: 'core',
number: 8,
time: '10 min'
},
{
id: '09-interactive-html-report',
file: 'workshop/09-interactive-html-report.md',
title: 'Generate an interactive HTML report',
navTitle: 'Interactive report',
kind: 'core',
number: 9,
time: '15 min'
},
{
id: '10-complete',
file: 'workshop/10-complete.md',
title: 'You did it!',
navTitle: 'Celebrate and keep building',
kind: 'completion',
number: 10,
time: 'Resources'
}
];
const museumSteps = [
{
id: 'museum-00-preflight',
file: 'workshop/museum-00-preflight.md',
title: 'Prepare Museum Exhibit Studio',
navTitle: 'Preflight',
kind: 'preflight',
time: 'Untimed'
},
{
id: 'museum-01-first-curator-session',
file: 'workshop/museum-01-first-curator-session.md',
title: 'Your first curator session',
navTitle: 'First session',
kind: 'core',
number: 1,
time: '10 min'
},
{
id: 'museum-02-stream-the-curator',
file: 'workshop/museum-02-stream-the-curator.md',
title: 'Stream the curator',
navTitle: 'Streaming',
kind: 'core',
number: 2,
time: '10 min'
},
{
id: 'museum-03-curator-voice',
file: 'workshop/museum-03-curator-voice.md',
title: 'Give the curator a voice',
navTitle: 'Curator voice',
kind: 'core',
number: 3,
time: '10 min'
},
{
id: 'museum-04-approved-facts',
file: 'workshop/museum-04-approved-facts.md',
title: 'Ground it in approved facts',
navTitle: 'Approved facts',
kind: 'core',
number: 4,
time: '15 min'
},
{
id: 'museum-06-prove-the-structure',
file: 'workshop/museum-06-prove-the-structure.md',
title: 'Prove the structure',
navTitle: 'Structural checks',
kind: 'core',
number: 5,
time: '10 min'
},
{
id: 'museum-07-wikipedia-research',
file: 'workshop/museum-07-wikipedia-research.md',
title: 'Research with Wikipedia MCP',
navTitle: 'Wikipedia research',
kind: 'core',
number: 6,
time: '20 min'
},
{
id: 'museum-08-interactive-exhibit-page',
file: 'workshop/museum-08-interactive-exhibit-page.md',
title: 'Publish an interactive exhibit page',
navTitle: 'Exhibit page',
kind: 'core',
number: 7,
time: '15 min'
},
{
id: 'museum-09-complete',
file: 'workshop/museum-09-complete.md',
title: 'You did it!',
navTitle: 'Celebrate and keep building',
kind: 'completion',
number: 8,
time: 'Resources'
}
];
const workshopTracks = {
intro: { title: 'SDK 101', steps: introSteps },
sdlc: { title: 'Accessibility Reviewer', steps: sdlcSteps },
museum: { title: 'Museum Exhibit Studio', steps: museumSteps }
};
const legacyStepMap = {
'00-overview': '00-preflight',
'01-setup': '00-preflight',
'02-client': '01-first-session',
'03-streaming': '02-streaming',
'04-local-tools': '03-local-tool',
'05-interactive': '03-local-tool',
'06-browser-setup': '00-preflight',
'07-mcp-session': '04-mcp-safety',
'08-url-input': '05-combine-tools',
'09-tool-activity': '05-combine-tools',
'10-report-prompt': '06-structured-report',
'11-generate-tests': '07-run-explain',
'12-run-review': '07-run-explain',
'museum-01-curator-role': 'museum-03-curator-voice',
'museum-02-tool-free-session': 'museum-04-approved-facts',
'museum-03-approved-facts': 'museum-04-approved-facts',
'museum-04-deterministic-validation': 'museum-06-prove-the-structure',
'museum-05-lifecycle-tests': 'museum-04-approved-facts',
'museum-05-guardrails': 'museum-04-approved-facts',
'museum-06-run-review': 'museum-06-prove-the-structure',
'museum-07-wikipedia-grounding': 'museum-07-wikipedia-research'
};
const requestedStepParameter = new URLSearchParams(window.location.search).get('step');
const mappedStepParameter = legacyStepMap[requestedStepParameter] ?? requestedStepParameter;
const activeWorkshopId = mappedStepParameter?.startsWith('intro-')
? 'intro'
: mappedStepParameter?.startsWith('museum-') ? 'museum' : 'sdlc';
const activeWorkshop = workshopTracks[activeWorkshopId];
const steps = activeWorkshop.steps;
const menuButton = document.getElementById('menuButton');
const navigationPanel = document.getElementById('navigationPanel');
const navigationOverlay = document.getElementById('navigationOverlay');
const closeNavigationButton = document.getElementById('closeNavigationButton');
const compactNavigation = window.matchMedia('(max-width: 900px)');
const languageSelector = document.getElementById('languageSelector');
const storageKey = 'copilot-sdk-workshop.language';
let currentIndex = 0;
let focusBeforeNavigation;
let loadSequence = 0;
const celebration = WorkshopCompletion.createCelebration(window, document);
function getPathSegments() {
return window.location.pathname.split('/').filter(Boolean);
}
function isGitHubPages() {
return window.location.hostname.toLowerCase().endsWith('.github.io');
}
function getSiteRootUrl() {
return WorkshopLanguageNavigation.siteRootUrl(window.location.href);
}
function getMarkdownUrl(file) {
const segments = getPathSegments();
if (!isGitHubPages() && segments[0] === 'docs') {
return new URL(`../../${file}`, window.location.href);
}
return new URL(file, getSiteRootUrl());
}
function getRequestedStepId() {
return steps.some(step => step.id === mappedStepParameter)
? mappedStepParameter
: steps[0].id;
}
function getStoredLanguageId() {
try {
return window.localStorage.getItem(storageKey);
} catch (error) {
return null;
}
}
function storeLanguageId(languageId) {
try {
window.localStorage.setItem(storageKey, languageId);
} catch (error) {
// The workshop remains usable when local storage is unavailable.
}
}
function getSelectedLanguage() {
return WorkshopLanguageNavigation.resolveLanguage(
window.location.search,
getStoredLanguageId(),
WorkshopLanguages.getLanguage
);
}
function homeUrl(language) {
return WorkshopLanguageNavigation.homeUrl(language?.id, activeWorkshopId);
}
function updateLanguageControls(language) {
languageSelector.value = language?.id ?? '';
const docsLink = document.getElementById('headerDocsLink');
docsLink.hidden = language === null;
if (language) {
docsLink.href = language.docsUrl;
docsLink.textContent = `📚 ${language.displayName} docs ↗`;
} else {
docsLink.removeAttribute('href');
}
document.getElementById('homeLink').href = homeUrl(language);
document.getElementById('hubLink').href = homeUrl(language);
}
function stepUrl(step) {
const language = getSelectedLanguage();
return WorkshopLanguageNavigation.lessonUrl(step.id, language?.id);
}
function setNavigationOpen(open) {
const shouldOpen = compactNavigation.matches && open;
navigationPanel.classList.toggle('open', shouldOpen);
navigationOverlay.classList.toggle('open', shouldOpen);
menuButton.setAttribute('aria-expanded', String(shouldOpen));
menuButton.setAttribute('aria-label', `${shouldOpen ? 'Close' : 'Open'} sections`);
document.body.classList.toggle('navigation-open', shouldOpen);
const hideNavigation = compactNavigation.matches && !shouldOpen;
navigationPanel.toggleAttribute('inert', hideNavigation);
if (hideNavigation) {
navigationPanel.setAttribute('aria-hidden', 'true');
} else {
navigationPanel.removeAttribute('aria-hidden');
}
if (shouldOpen) {
navigationPanel.setAttribute('role', 'dialog');
navigationPanel.setAttribute('aria-modal', 'true');
} else {
navigationPanel.removeAttribute('role');
navigationPanel.removeAttribute('aria-modal');
}
if (shouldOpen) {
focusBeforeNavigation = document.activeElement;
closeNavigationButton.focus();
} else if (focusBeforeNavigation instanceof HTMLElement) {
focusBeforeNavigation.focus();
focusBeforeNavigation = undefined;
}
}
function trapNavigationFocus(event) {
if (!compactNavigation.matches
|| !navigationPanel.classList.contains('open')
|| event.key !== 'Tab') {
return;
}
const focusable = [...navigationPanel.querySelectorAll(
'a[href], button:not([disabled]), [tabindex]:not([tabindex="-1"])'
)].filter(element => !element.hidden);
if (focusable.length === 0) {
return;
}
const first = focusable[0];
const last = focusable[focusable.length - 1];
if (event.shiftKey && document.activeElement === first) {
event.preventDefault();
last.focus();
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault();
first.focus();
}
}
function buildNavigation() {
const groups = [
{ label: 'Before you begin', steps: steps.filter(step => step.kind === 'preflight') },
{ label: 'Workshop', steps: steps.filter(step => step.kind !== 'preflight') }
];
document.getElementById('workshopNavigation').innerHTML = groups.filter(group => group.steps.length > 0).map(group => `
<section class="navigation-group">
<h3>${group.label}</h3>
${group.steps.map(step => {
const index = steps.findIndex(candidate => candidate.id === step.id);
const active = index === currentIndex;
const marker = step.kind === 'preflight' ? 'P' : step.number;
return `
<a
href="${stepUrl(step)}"
class="flyout-link ${active ? 'active' : ''}"
${active ? 'aria-current="step"' : ''}>
<span class="flyout-number">${marker}</span>
<span>
<strong>${step.navTitle}</strong>
<small>${step.time}</small>
</span>
</a>`;
}).join('')}
</section>
`).join('');
}
function updatePagination() {
const previous = steps[currentIndex - 1];
const next = steps[currentIndex + 1];
const previousHeaderLink = document.getElementById('previousHeaderLink');
const nextHeaderLink = document.getElementById('nextHeaderLink');
previousHeaderLink.hidden = !previous;
nextHeaderLink.hidden = !next;
if (previous) {
previousHeaderLink.href = stepUrl(previous);
previousHeaderLink.textContent = '← Prev';
previousHeaderLink.setAttribute('aria-label', `Previous: ${previous.title}`);
}
if (next) {
nextHeaderLink.href = stepUrl(next);
nextHeaderLink.textContent = 'Next →';
nextHeaderLink.setAttribute('aria-label', `Next: ${next.title}`);
}
const footer = document.getElementById('lessonFooter');
footer.innerHTML = `
${previous
? `<a href="${stepUrl(previous)}" class="nav-footer-btn">← ${previous.navTitle}</a>`
: '<span class="nav-footer-btn disabled" aria-disabled="true">← Previous</span>'}
${next
? `<a href="${stepUrl(next)}" class="nav-footer-btn">${next.navTitle} →</a>`
: `<a href="${homeUrl(getSelectedLanguage())}" class="nav-footer-btn">Back to workshop hub →</a>`}`;
}
function updateProgress(step) {
const position = document.getElementById('stepPosition');
const estimate = document.getElementById('stepEstimate');
const track = document.getElementById('progressTrack');
const fill = document.getElementById('progressFill');
const stepCount = steps.filter(candidate => candidate.kind !== 'preflight').length;
let progressValue = 0;
if (step.kind !== 'preflight') {
position.textContent = `Step ${step.number} of ${stepCount}`;
progressValue = step.number;
} else {
position.textContent = 'Preflight';
}
estimate.textContent = step.time;
track.setAttribute('aria-valuemax', String(stepCount));
track.setAttribute('aria-valuenow', String(progressValue));
fill.style.transform = `scaleX(${progressValue / stepCount})`;
}
function processMarkdown(markdown) {
const targetUrl = new URL('target-app/', getSiteRootUrl()).href;
return WorkshopMarkdown.preprocessLanguageDirectives(
markdown,
getSelectedLanguage()?.id,
WorkshopLanguages.getLanguage
)
.replaceAll('{{TARGET_APP_URL}}', targetUrl)
.replace(/\]\(([a-z0-9-]+)\.md\)/g, (match, stepId) => {
const target = steps.find(step => step.id === stepId);
return target ? `](${stepUrl(target)})` : match;
});
}
async function copyCode(button, codeBlock) {
const text = codeBlock.textContent.replace(/\n$/, '');
try {
if (navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(text);
} else {
const textArea = document.createElement('textarea');
textArea.value = text;
textArea.setAttribute('readonly', '');
textArea.style.position = 'fixed';
textArea.style.opacity = '0';
document.body.append(textArea);
textArea.select();
const copied = document.execCommand('copy');
textArea.remove();
if (!copied) {
throw new Error('The browser did not copy the code.');
}
}
button.textContent = 'Copied';
button.classList.add('copied');
} catch (error) {
button.textContent = 'Copy failed';
button.classList.add('copy-error');
console.error('Unable to copy code:', error);
}
window.setTimeout(() => {
button.textContent = 'Copy';
button.classList.remove('copied', 'copy-error');
}, 1800);
}
function addCopyButtons() {
document.querySelectorAll('#markdownContent pre').forEach(pre => {
const codeBlock = pre.querySelector('code');
if (!codeBlock || pre.querySelector('.copy-code-button')) {
return;
}
const button = document.createElement('button');
button.type = 'button';
button.className = 'copy-code-button';
button.textContent = 'Copy';
button.setAttribute('aria-label', 'Copy code block');
button.addEventListener('click', () => copyCode(button, codeBlock));
pre.append(button);
});
}
function initializeTabs() {
document.querySelectorAll('[data-tabs]').forEach((group, groupIndex) => {
const tabs = [...group.querySelectorAll('[role="tab"]')];
const panels = [...group.querySelectorAll('[role="tabpanel"]')];
function activateTab(tabToActivate, moveFocus) {
tabs.forEach(tab => {
const active = tab === tabToActivate;
tab.setAttribute('aria-selected', String(active));
tab.tabIndex = active ? 0 : -1;
const panel = panels.find(candidate =>
candidate.dataset.panel === tab.dataset.tab);
if (panel) {
panel.hidden = !active;
}
});
if (moveFocus) {
tabToActivate.focus();
}
}
tabs.forEach((tab, tabIndex) => {
const panel = panels.find(candidate =>
candidate.dataset.panel === tab.dataset.tab);
const tabId = `tab-${groupIndex}-${tabIndex}`;
const panelId = `panel-${groupIndex}-${tabIndex}`;
tab.id = tabId;
tab.setAttribute('aria-controls', panelId);
tab.tabIndex = tab.getAttribute('aria-selected') === 'true' ? 0 : -1;
if (panel) {
panel.id = panelId;
panel.setAttribute('aria-labelledby', tabId);
}
tab.addEventListener('click', () => activateTab(tab, false));
tab.addEventListener('keydown', event => {
let targetIndex;
if (event.key === 'ArrowRight') {
targetIndex = (tabIndex + 1) % tabs.length;
} else if (event.key === 'ArrowLeft') {
targetIndex = (tabIndex - 1 + tabs.length) % tabs.length;
} else if (event.key === 'Home') {
targetIndex = 0;
} else if (event.key === 'End') {
targetIndex = tabs.length - 1;
}
if (targetIndex !== undefined) {
event.preventDefault();
activateTab(tabs[targetIndex], true);
}
});
});
});
}
function prepareRenderedLesson() {
document.querySelectorAll('#markdownContent pre code').forEach(codeBlock => {
hljs.highlightElement(codeBlock);
});
addCopyButtons();
initializeTabs();
document.querySelectorAll('#markdownContent a[href^="http"]').forEach(link => {
link.target = '_blank';
link.rel = 'noopener';
});
}
function showLoadError(error) {
const container = document.getElementById('markdownContent');
const status = document.getElementById('lessonStatus');
const message = document.createElement('div');
message.className = 'load-error';
const heading = document.createElement('h1');
heading.textContent = 'Unable to load this lesson';
const details = document.createElement('p');
details.textContent = error.message;
const guidance = document.createElement('p');
guidance.textContent = window.location.protocol === 'file:'
? 'Serve the repository with a local HTTP server; browsers block lesson fetches from file URLs.'
: 'Refresh the page. If the problem continues, verify that the workshop Markdown was deployed.';
message.append(heading, details, guidance);
container.replaceChildren(message);
container.setAttribute('aria-busy', 'false');
status.textContent = 'Unable to load this lesson.';
}
async function loadStep() {
const requestId = ++loadSequence;
celebration.clear();
const language = getSelectedLanguage();
const stepId = getRequestedStepId();
currentIndex = steps.findIndex(step => step.id === stepId);
const step = steps[currentIndex];
const container = document.getElementById('markdownContent');
const status = document.getElementById('lessonStatus');
updateLanguageControls(language);
document.querySelector('.header-title').textContent = activeWorkshop.title;
document.getElementById('navigationTitle').textContent = `${activeWorkshop.title} steps`;
if (!language) {
document.title = 'Choose a language | Copilot SDK Workshop';
document.getElementById('headerLessonTitle').textContent = 'Choose a language';
buildNavigation();
updatePagination();
const message = document.createElement('section');
message.className = 'load-error language-choice';
const heading = document.createElement('h1');
heading.textContent = 'Choose a workshop language';
const details = document.createElement('p');
details.textContent = 'Select one of the six supported languages above before loading a lesson.';
message.append(heading, details);
container.replaceChildren(message);
container.setAttribute('aria-busy', 'false');
status.textContent = 'Choose a workshop language to continue.';
return;
}
document.title = `${step.title} | ${language.displayName} | Copilot SDK Workshop`;
document.getElementById('headerLessonTitle').textContent = step.title;
updateProgress(step);
buildNavigation();
updatePagination();
container.setAttribute('aria-busy', 'true');
status.textContent = `Loading ${step.title}.`;
try {
const demoFile = `start-intro/${language.id}/LIVE_DEMO.md`;
const [response, demoResponse] = await Promise.all([
fetch(getMarkdownUrl(step.file)),
step.demoAct ? fetch(getMarkdownUrl(demoFile)) : Promise.resolve(null)
]);
if (requestId !== loadSequence) {
return;
}
if (!response.ok) {
throw new Error(`Lesson request failed with HTTP ${response.status}.`);
}
if (demoResponse && !demoResponse.ok) {
throw new Error(`${demoFile} request failed with HTTP ${demoResponse.status}.`);
}
const [source, demoSource] = await Promise.all([
response.text(),
demoResponse ? demoResponse.text() : Promise.resolve(null)
]);
if (requestId !== loadSequence) {
return;
}
const combined = step.demoAct
? WorkshopMarkdown.includeLiveDemoAct(source, demoSource, step.demoAct)
: source;
const markdown = processMarkdown(combined);
container.innerHTML =
`<article class="markdown${step.kind === 'completion' ? ' workshop-complete' : ''}">${marked.parse(markdown, { gfm: true })}</article>`;
prepareRenderedLesson();
container.setAttribute('aria-busy', 'false');
status.textContent = step.kind === 'completion'
? `${activeWorkshop.title} complete. You did it! Resources are ready below.`
: `Loaded ${step.title}.`;
celebration.show(step);
} catch (error) {
if (requestId === loadSequence) {
showLoadError(error);
}
}
}
menuButton.addEventListener(
'click',
() => setNavigationOpen(!navigationPanel.classList.contains('open')));
closeNavigationButton.addEventListener('click', () => setNavigationOpen(false));
navigationOverlay.addEventListener('click', () => setNavigationOpen(false));
compactNavigation.addEventListener('change', () => setNavigationOpen(false));
languageSelector.addEventListener('change', () => {
const language = WorkshopLanguages.getLanguage(languageSelector.value);
if (!language) {
return;
}
storeLanguageId(language.id);
const url = new URL(window.location.href);
url.searchParams.set('lang', language.id);
window.history.replaceState({}, '', url);
loadStep();
});
window.addEventListener('popstate', loadStep);
document.addEventListener('keydown', event => {
if (navigationPanel.classList.contains('open') && event.key === 'Escape') {
event.preventDefault();
setNavigationOpen(false);
return;
}
trapNavigationFocus(event);
});
setNavigationOpen(false);
loadStep();
</script>
</body>
</html>