Repository navigation
Expand file tree
/
Copy pathstep.html
More file actions
1084 lines (1012 loc) · 47.3 KB
/
Copy pathstep.html
File metadata and controls
1084 lines (1012 loc) · 47.3 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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!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&family=Nanum+Gothic:wght@400;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="../site-chrome.css">
<link rel="stylesheet" href="../light-theme.css">
<link rel="stylesheet" href="../korean-typography.css">
<link rel="stylesheet" href="../japanese-typography.css">
<script src="../theme-toggle.js?v=3"></script>
<script src="../language-registry.js"></script>
<script src="../locale-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" id="skipLink">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">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"/></svg>
</button>
<a href="../index.html" class="header-brand" id="homeLink" aria-label="Copilot SDK Workshop home">
<svg class="header-icon" viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 1C5.9 1 1 5.9 1 12c0 4.9 3.2 9 7.5 10.5.6.1.8-.2.8-.5v-2.1c-3.1.7-3.7-1.3-3.7-1.3-.5-1.3-1.2-1.6-1.2-1.6-1-.7.1-.7.1-.7 1.1.1 1.7 1.1 1.7 1.1 1 1.7 2.6 1.2 3.2.9.1-.7.4-1.2.7-1.5-2.5-.3-5.1-1.2-5.1-5.4 0-1.2.4-2.2 1.1-2.9-.1-.3-.5-1.4.1-2.9 0 0 .9-.3 3 1.1.9-.2 1.8-.4 2.7-.4.9 0 1.9.1 2.7.4 2.1-1.4 3-1.1 3-1.1.6 1.5.2 2.6.1 2.9.7.8 1.1 1.7 1.1 2.9 0 4.2-2.6 5.1-5.1 5.4.4.3.8 1 .8 2V22c0 .4.2.6.8.5A11 11 0 0 0 23 12c0-6.1-4.9-11-11-11Z"/>
</svg>
<span class="header-title">Copilot SDK Workshop</span>
<span class="visually-hidden" id="headerLessonTitle">Loading lesson</span>
</a>
<nav class="header-nav" id="headerNav" aria-label="Lesson actions">
<a class="nav-btn" id="previousHeaderLink" href="#" hidden>← Prev</a>
<a class="nav-btn" id="nextHeaderLink" href="#" hidden>Next →</a>
</nav>
<div class="settings" id="settings">
<button class="settings-toggle" id="settingsButton" type="button" aria-expanded="false" aria-controls="settingsPanel" aria-label="Settings">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M10.13 5.25L10.47 2.88L13.53 2.88L13.87 5.25L15.45 5.91L17.37 4.47L19.53 6.63L18.09 8.55L18.75 10.13L21.12 10.47L21.12 13.53L18.75 13.87L18.09 15.45L19.53 17.37L17.37 19.53L15.45 18.09L13.87 18.75L13.53 21.12L10.47 21.12L10.13 18.75L8.55 18.09L6.63 19.53L4.47 17.37L5.91 15.45L5.25 13.87L2.88 13.53L2.88 10.47L5.25 10.13L5.91 8.55L4.47 6.63L6.63 4.47L8.55 5.91Z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
<div class="settings-panel" id="settingsPanel" role="group" aria-label="Settings" hidden>
<div class="settings-row">
<label class="settings-label" id="localeSelectorLabel" for="localeSelector">Language</label>
<select class="settings-select" id="localeSelector"></select>
</div>
<div class="settings-row">
<label class="settings-label" id="languageSelectorLabel" for="languageSelector">Programming language</label>
<select class="settings-select" id="languageSelector">
<option value="" id="chooseLanguageOption">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>
</div>
<fieldset class="settings-row">
<legend class="settings-label" id="themeLabel">Theme</legend>
<div class="theme-options">
<label class="theme-option">
<input class="visually-hidden" type="radio" name="theme" value="light">
<span>
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="12" cy="12" r="4"/>
<path d="M12 2.5v2M12 19.5v2M2.5 12h2M19.5 12h2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/>
</svg>
<span id="themeLightLabel">Light</span>
</span>
</label>
<label class="theme-option">
<input class="visually-hidden" type="radio" name="theme" value="dark">
<span>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M20 14.5A8.5 8.5 0 1 1 9.5 4a6.75 6.75 0 0 0 10.5 10.5Z"/>
</svg>
<span id="themeDarkLabel">Dark</span>
</span>
</label>
</div>
</fieldset>
</div>
</div>
</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">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>
</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" id="loadingMessage">Loading lesson...</p>
</div>
<nav class="nav-footer" id="lessonFooter" aria-label="Lesson pagination"></nav>
<footer class="site-footer">
<nav class="site-footer-nav" id="resourcesNav" aria-label="Workshop resources">
<a id="sdkDocsLink" target="_blank" rel="noopener" hidden>
<span id="sdkDocsLabel">SDK docs</span>
<svg class="external-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 5h5v5M19 5l-8 8M17 13.5V18a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V8a1 1 0 0 1 1-1h4.5"/></svg>
<span class="visually-hidden" id="newTabNote">(opens in a new tab)</span>
</a>
</nav>
</footer>
</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 localeSelector = document.getElementById('localeSelector');
const storageKey = 'copilot-sdk-workshop.language';
const localeStorageKey = 'copilot-sdk-workshop.locale';
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 getLocalizedMarkdownUrl(file, locale) {
return getMarkdownUrl(WorkshopLocales.contentUrlPath(file, locale.id));
}
// Falls back to the canonical English source whenever a locale has no translation yet.
async function fetchLocalizedMarkdown(file, locale) {
const response = await fetch(getLocalizedMarkdownUrl(file, locale));
if (response.ok || locale.id === WorkshopLocales.defaultLocale.id) {
return { response, locale };
}
const fallbackLocale = WorkshopLocales.defaultLocale;
return {
response: await fetch(getLocalizedMarkdownUrl(file, fallbackLocale)),
locale: fallbackLocale
};
}
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 getStoredLocaleId() {
try {
return window.localStorage.getItem(localeStorageKey);
} catch (error) {
return null;
}
}
function storeLocaleId(localeId) {
try {
window.localStorage.setItem(localeStorageKey, localeId);
} catch (error) {
// The workshop remains usable when local storage is unavailable.
}
}
function getSelectedLocale() {
return WorkshopLanguageNavigation.resolveLocale(
window.location.search,
getStoredLocaleId(),
WorkshopLocales.getLocale
) ?? WorkshopLocales.defaultLocale;
}
function selectedLocaleQueryId() {
return WorkshopLocales.queryId(getSelectedLocale().id);
}
function getLessonUi() {
return getSelectedLocale().ui.lesson;
}
function getStepNavTitle(step) {
return getLessonUi().stepLabels[step.id] ?? step.navTitle;
}
function getStepTitle(step) {
return getLessonUi().stepTitles[step.id] ?? step.title;
}
function getWorkshopTitle() {
return getLessonUi().workshopTitles[activeWorkshop.title] ?? activeWorkshop.title;
}
// Step durations are authored in English so the registry only localizes the shape.
function getStepTime(step) {
const times = getLessonUi().times;
if (step.time === 'Untimed') {
return times.untimed;
}
if (step.time === 'Resources') {
return times.resources;
}
const minutes = /^(\d+) min$/.exec(step.time);
return minutes ? times.minutes.replace('{count}', minutes[1]) : step.time;
}
function applyLessonChrome() {
const ui = getSelectedLocale().ui;
const lessonUi = ui.lesson;
document.getElementById('skipLink').textContent = lessonUi.skipLink;
document.getElementById('homeLink').setAttribute('aria-label', lessonUi.homeAriaLabel);
document.getElementById('headerNav').setAttribute('aria-label', lessonUi.lessonActions);
document.getElementById('settingsButton').setAttribute('aria-label', ui.settings.label);
document.getElementById('settingsPanel').setAttribute('aria-label', ui.settings.label);
document.getElementById('localeSelectorLabel').textContent = ui.settings.locale;
document.getElementById('languageSelectorLabel').textContent = ui.programmingLanguage;
document.getElementById('chooseLanguageOption').textContent =
lessonUi.chooseLanguageOption;
document.getElementById('themeLabel').textContent = ui.settings.theme;
document.getElementById('themeLightLabel').textContent = ui.settings.light;
document.getElementById('themeDarkLabel').textContent = ui.settings.dark;
document.getElementById('resourcesNav').setAttribute('aria-label', ui.resourcesLabel);
document.getElementById('newTabNote').textContent = ui.newTab;
document.getElementById('progressTrack').setAttribute(
'aria-label', lessonUi.progressAriaLabel);
document.getElementById('closeNavigationButton').setAttribute(
'aria-label', lessonUi.closeSections);
document.getElementById('workshopNavigation').setAttribute(
'aria-label', lessonUi.navigationAriaLabel);
document.getElementById('lessonFooter').setAttribute(
'aria-label', lessonUi.paginationAriaLabel);
const loadingMessage = document.getElementById('loadingMessage');
if (loadingMessage) {
loadingMessage.textContent = lessonUi.loadingLessonProgress;
}
}
function homeUrl(language) {
return WorkshopLanguageNavigation.homeUrl(
language?.id, activeWorkshopId, selectedLocaleQueryId());
}
function updateLanguageControls(language) {
languageSelector.value = language?.id ?? '';
const docsLink = document.getElementById('sdkDocsLink');
docsLink.hidden = language === null;
if (language) {
docsLink.href = language.docsUrl;
document.getElementById('sdkDocsLabel').textContent =
getSelectedLocale().ui.sdkDocsNamed.replace('{language}', language.displayName);
} else {
docsLink.removeAttribute('href');
}
document.getElementById('homeLink').href = homeUrl(language);
}
function populateLocaleControls() {
WorkshopLocales.locales.forEach(locale => {
const option = document.createElement('option');
option.value = locale.id;
option.textContent = locale.displayName;
localeSelector.append(option);
});
}
function updateLocaleControls(locale) {
localeSelector.value = locale.id;
document.documentElement.lang = locale.htmlLang;
}
function stepUrl(step) {
const language = getSelectedLanguage();
return WorkshopLanguageNavigation.lessonUrl(
step.id, language?.id, selectedLocaleQueryId());
}
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 ? getLessonUi().closeSections : getLessonUi().openSections);
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 lessonUi = getLessonUi();
const groups = [
{ label: lessonUi.beforeYouBegin, steps: steps.filter(step => step.kind === 'preflight') },
{ label: lessonUi.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>${getStepNavTitle(step)}</strong>
<small>${getStepTime(step)}</small>
</span>
</a>`;
}).join('')}
</section>
`).join('');
}
function updatePagination() {
const previous = steps[currentIndex - 1];
const next = steps[currentIndex + 1];
const lessonUi = getLessonUi();
const previousHeaderLink = document.getElementById('previousHeaderLink');
const nextHeaderLink = document.getElementById('nextHeaderLink');
previousHeaderLink.hidden = !previous;
nextHeaderLink.hidden = !next;
if (previous) {
previousHeaderLink.href = stepUrl(previous);
previousHeaderLink.textContent = `← ${lessonUi.previousShort}`;
previousHeaderLink.setAttribute(
'aria-label', lessonUi.previousAria.replace('{title}', getStepNavTitle(previous)));
}
if (next) {
nextHeaderLink.href = stepUrl(next);
nextHeaderLink.textContent = `${lessonUi.nextShort} →`;
nextHeaderLink.setAttribute(
'aria-label', lessonUi.nextAria.replace('{title}', getStepNavTitle(next)));
}
const footer = document.getElementById('lessonFooter');
footer.innerHTML = `
${previous
? `<a href="${stepUrl(previous)}" class="nav-footer-btn">← ${getStepNavTitle(previous)}</a>`
: `<span class="nav-footer-btn disabled" aria-disabled="true">← ${lessonUi.previous}</span>`}
${next
? `<a href="${stepUrl(next)}" class="nav-footer-btn">${getStepNavTitle(next)} →</a>`
: `<a href="${homeUrl(getSelectedLanguage())}" class="nav-footer-btn">${lessonUi.backToHub} →</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;
const lessonUi = getLessonUi();
let progressValue = 0;
if (step.kind !== 'preflight') {
position.textContent = lessonUi.stepPosition
.replace('{number}', step.number)
.replace('{count}', stepCount);
progressValue = step.number;
} else {
position.textContent = lessonUi.preflight;
}
estimate.textContent = getStepTime(step);
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 = getLessonUi().copied;
button.classList.add('copied');
} catch (error) {
button.textContent = getLessonUi().copyFailed;
button.classList.add('copy-error');
console.error('Unable to copy code:', error);
}
window.setTimeout(() => {
button.textContent = getLessonUi().copy;
button.classList.remove('copied', 'copy-error');
}, 1800);
}
function addCopyButtons() {
const lessonUi = getLessonUi();
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 = lessonUi.copy;
button.setAttribute('aria-label', lessonUi.copyAriaLabel);
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 lessonUi = getLessonUi();
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 = lessonUi.loadErrorHeading;
const details = document.createElement('p');
details.textContent = error.message;
const guidance = document.createElement('p');
guidance.textContent = window.location.protocol === 'file:'
? lessonUi.loadErrorFileGuidance
: lessonUi.loadErrorGuidance;
message.append(heading, details, guidance);
container.replaceChildren(message);
container.setAttribute('aria-busy', 'false');
status.textContent = lessonUi.loadErrorStatus;
}
async function loadStep() {
const requestId = ++loadSequence;
celebration.clear();
const language = getSelectedLanguage();
const locale = getSelectedLocale();
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);
updateLocaleControls(locale);
applyLessonChrome();
const lessonUi = getLessonUi();
const workshopTitle = getWorkshopTitle();
document.querySelector('.header-title').textContent = workshopTitle;
document.getElementById('navigationTitle').textContent =
lessonUi.navigationTitle.replace('{workshop}', workshopTitle);
if (!language) {
document.title = lessonUi.chooseLanguageDocumentTitle;
document.getElementById('headerLessonTitle').textContent =
lessonUi.chooseLanguageShort;
buildNavigation();
updatePagination();
const message = document.createElement('section');
message.className = 'load-error language-choice';
const heading = document.createElement('h1');
heading.textContent = lessonUi.chooseLanguageHeading;
const details = document.createElement('p');
details.textContent = lessonUi.chooseLanguageDetails;
message.append(heading, details);
container.replaceChildren(message);
container.setAttribute('aria-busy', 'false');
status.textContent = lessonUi.chooseLanguageStatus;
return;
}
const stepTitle = getStepTitle(step);
document.title = lessonUi.documentTitle
.replace('{step}', stepTitle)
.replace('{language}', language.displayName);
document.getElementById('headerLessonTitle').textContent = stepTitle;
updateProgress(step);
buildNavigation();
updatePagination();
container.setAttribute('aria-busy', 'true');
status.textContent = lessonUi.loadingNamed.replace('{title}', stepTitle);
try {
const demoFile = `start-intro/${language.id}/LIVE_DEMO.md`;
const [lesson, demo] = await Promise.all([
fetchLocalizedMarkdown(step.file, locale),
step.demoAct ? fetchLocalizedMarkdown(demoFile, locale) : Promise.resolve(null)
]);
if (requestId !== loadSequence) {
return;
}