@superjackfruitlabs/vibekit-docs 0.0.0-bootstrap.0 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/LICENSE +26 -0
- package/README.md +109 -1
- package/index.ts +180 -0
- package/package.json +52 -5
- package/src/client/steps.ts +80 -0
- package/src/components/BentoHome.astro +226 -0
- package/src/components/Callout.astro +47 -0
- package/src/components/CaptainJack.astro +180 -0
- package/src/components/CopyMarkdown.astro +50 -0
- package/src/components/CopyPrompt.astro +68 -0
- package/src/components/DecisionReplay.astro +182 -0
- package/src/components/FlowSteps.astro +99 -0
- package/src/components/Footer.astro +56 -0
- package/src/components/Header.astro +16 -0
- package/src/components/HeadsUp.astro +6 -0
- package/src/components/JackAside.astro +6 -0
- package/src/components/OpenMarkdown.astro +17 -0
- package/src/components/PageTitle.astro +38 -0
- package/src/components/SiteTitle.astro +43 -0
- package/src/components/StatusBadge.astro +14 -0
- package/src/components/Street.astro +60 -0
- package/src/components/Switcher.astro +63 -0
- package/src/components/Tip.astro +6 -0
- package/src/components/WetPaint.astro +6 -0
- package/src/markdown.ts +13 -0
- package/src/pages/404.astro +72 -0
- package/src/pages/markdown.ts +17 -0
- package/src/schema.d.mts +8 -0
- package/src/schema.mjs +19 -0
- package/src/sidebar.mjs +19 -0
- package/src/site.ts +52 -0
- package/src/steps.ts +8 -0
- package/src/styles/fonts.css +13 -0
- package/src/styles/theme.css +212 -0
- package/src/tokens.mjs +113 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
---
|
|
2
|
+
// A docs home as a bento grid: the claim in a hero lit by the product's colour, Ask Captain Jack,
|
|
3
|
+
// Work with an agent (a prompt to copy), Find your way (a map of the docs), a Quick start, and a
|
|
4
|
+
// "how it works" tile (whatever the page puts inside, usually FlowSteps). Used from index.mdx
|
|
5
|
+
// with `template: splash` and no `hero`:
|
|
6
|
+
//
|
|
7
|
+
// <BentoHome claim="…" sub="…" actions={[…]} quickstart={{ command: '…' }} flowTitle="…">
|
|
8
|
+
// <FlowSteps steps={[…]} />
|
|
9
|
+
// </BentoHome>
|
|
10
|
+
//
|
|
11
|
+
// The Quick start is a command to copy, or, when the page fills the `quickstart` slot, anything
|
|
12
|
+
// the reader can try with nothing installed (a DecisionReplay, say):
|
|
13
|
+
//
|
|
14
|
+
// <BentoHome claim="…" sub="…" quickstart={{ label: 'Quick start: replay a decision' }}>
|
|
15
|
+
// <div slot="quickstart"><DecisionReplay decision={record} /></div>
|
|
16
|
+
// </BentoHome>
|
|
17
|
+
import StatusBadge from './StatusBadge.astro';
|
|
18
|
+
import CaptainJack from './CaptainJack.astro';
|
|
19
|
+
import CopyMarkdown from './CopyMarkdown.astro';
|
|
20
|
+
import CopyPrompt from './CopyPrompt.astro';
|
|
21
|
+
import OpenMarkdown from './OpenMarkdown.astro';
|
|
22
|
+
import { GROUPS } from '../sidebar.mjs';
|
|
23
|
+
import { hostOf, productOf, routeOf, siteStatus } from '../site.ts';
|
|
24
|
+
|
|
25
|
+
interface Action { text: string; link: string; variant?: 'primary' | 'secondary' }
|
|
26
|
+
interface MapEntry { label: string; href: string; note?: string }
|
|
27
|
+
interface Props {
|
|
28
|
+
product?: string;
|
|
29
|
+
claim: string;
|
|
30
|
+
sub: string;
|
|
31
|
+
actions?: Action[];
|
|
32
|
+
/** The Quick start: a command to copy, or only a label and note when the `quickstart` slot holds it. */
|
|
33
|
+
quickstart: { command?: string; label?: string; note?: string };
|
|
34
|
+
status?: string | null;
|
|
35
|
+
/** Ask Captain Jack: on, with these example questions (false hides the tile). */
|
|
36
|
+
ask?: false | { examples?: string[] };
|
|
37
|
+
/** Work with an agent: a prompt to copy that points an agent at llms.txt (false hides the tile). */
|
|
38
|
+
agent?: false | { task?: string; prompt?: string };
|
|
39
|
+
flowTitle?: string;
|
|
40
|
+
/** The page map; by default the sidebar's groups, each linking to its first page. */
|
|
41
|
+
map?: MapEntry[];
|
|
42
|
+
}
|
|
43
|
+
const p = Astro.props;
|
|
44
|
+
const me = productOf(p.product);
|
|
45
|
+
const route = routeOf(Astro.locals);
|
|
46
|
+
const status = p.status === undefined ? ((route?.entry?.data as { status?: string } | undefined)?.status ?? siteStatus()) : p.status;
|
|
47
|
+
const actions: Action[] = p.actions ?? [];
|
|
48
|
+
|
|
49
|
+
type Entry = { type: string; label: string; href?: string; entries?: Entry[] };
|
|
50
|
+
const firstLink = (e: Entry): Entry | undefined => (e.type === 'link' ? e : e.entries?.map(firstLink).find(Boolean));
|
|
51
|
+
const fromSidebar = ((route?.sidebar ?? []) as Entry[])
|
|
52
|
+
.filter((g) => g.type === 'group')
|
|
53
|
+
.map((g) => ({ label: g.label, href: firstLink(g)?.href ?? '#', note: (g.entries ?? []).filter((x) => x.type === 'link').slice(0, 2).map((x) => x.label).join(' · ') }));
|
|
54
|
+
const map: MapEntry[] = p.map ?? fromSidebar.sort((a, b) => GROUPS.indexOf(a.label as never) - GROUPS.indexOf(b.label as never));
|
|
55
|
+
const hasFlow = Astro.slots.has('default');
|
|
56
|
+
const qsSlot = Astro.slots.has('quickstart');
|
|
57
|
+
if (!qsSlot && !p.quickstart?.command) throw new Error('docs-theme: BentoHome needs quickstart.command or a quickstart slot');
|
|
58
|
+
---
|
|
59
|
+
<div class="sjl-bento not-content" data-flow={hasFlow ? '' : undefined} data-ask={p.ask === false ? undefined : ''} data-agent={p.agent === false ? undefined : ''}>
|
|
60
|
+
<section class="tile hero" aria-labelledby="sjl-claim">
|
|
61
|
+
<div class="mesh" aria-hidden="true"></div>
|
|
62
|
+
<div class="eyebrow">
|
|
63
|
+
<span>{me.name} docs</span>
|
|
64
|
+
{status && <StatusBadge status={status} />}
|
|
65
|
+
</div>
|
|
66
|
+
<h2 id="sjl-claim" class="claim">{p.claim}</h2>
|
|
67
|
+
<p class="sub">{p.sub}</p>
|
|
68
|
+
<div class="row">
|
|
69
|
+
{actions.map((a, i) => (
|
|
70
|
+
<a class:list={['sjl-btn', { primary: (a.variant ?? (i === 0 ? 'primary' : 'secondary')) === 'primary' }]} href={a.link}>{a.text}{i === 0 && <span aria-hidden="true"> →</span>}</a>
|
|
71
|
+
))}
|
|
72
|
+
<a class="sjl-btn" href={me.landing}>{hostOf(me.landing)} <span aria-hidden="true">↗</span></a>
|
|
73
|
+
</div>
|
|
74
|
+
</section>
|
|
75
|
+
|
|
76
|
+
{p.ask !== false && (
|
|
77
|
+
<section class="tile t-jack" aria-labelledby="sjl-ask">
|
|
78
|
+
<h3 id="sjl-ask">Ask Captain Jack</h3>
|
|
79
|
+
<CaptainJack product={me.slug} examples={p.ask?.examples} />
|
|
80
|
+
</section>
|
|
81
|
+
)}
|
|
82
|
+
|
|
83
|
+
{p.agent !== false && (
|
|
84
|
+
<section class="tile t-agent" aria-labelledby="sjl-agent">
|
|
85
|
+
<h3 id="sjl-agent">Work with an agent</h3>
|
|
86
|
+
<CopyPrompt product={me.slug} task={p.agent?.task} prompt={p.agent?.prompt} />
|
|
87
|
+
</section>
|
|
88
|
+
)}
|
|
89
|
+
|
|
90
|
+
<section class="tile t-term" aria-labelledby="sjl-qs">
|
|
91
|
+
<h3 id="sjl-qs">{p.quickstart?.label ?? 'Quick start'}</h3>
|
|
92
|
+
{qsSlot ? <slot name="quickstart" /> : (
|
|
93
|
+
<sjl-term class="term">
|
|
94
|
+
<pre><code><span class="pr" aria-hidden="true">$ </span>{p.quickstart?.command}</code></pre>
|
|
95
|
+
<button type="button" class="copy" data-copy={p.quickstart?.command} hidden>Copy</button>
|
|
96
|
+
<span class="sjl-sr-only" aria-live="polite"></span>
|
|
97
|
+
</sjl-term>
|
|
98
|
+
)}
|
|
99
|
+
{p.quickstart?.note && <p class="note">{p.quickstart.note}</p>}
|
|
100
|
+
</section>
|
|
101
|
+
|
|
102
|
+
{hasFlow && (
|
|
103
|
+
<section class="tile t-flow" aria-labelledby="sjl-flow">
|
|
104
|
+
<h3 id="sjl-flow">{p.flowTitle ?? 'How it works'}</h3>
|
|
105
|
+
<slot />
|
|
106
|
+
</section>
|
|
107
|
+
)}
|
|
108
|
+
|
|
109
|
+
<nav class="tile t-map" aria-labelledby="sjl-map">
|
|
110
|
+
<h3 id="sjl-map">Find your way</h3>
|
|
111
|
+
<ul>
|
|
112
|
+
{map.map((m) => <li><a href={m.href}><span>{m.label}</span>{m.note && <small>{m.note}</small>}</a></li>)}
|
|
113
|
+
</ul>
|
|
114
|
+
<div class="copy-page">
|
|
115
|
+
<CopyMarkdown title={route?.entry?.data?.title ?? me.name} body={route?.entry?.body} />
|
|
116
|
+
{route?.entry && <OpenMarkdown id={route.entry.id} />}
|
|
117
|
+
</div>
|
|
118
|
+
</nav>
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<script>
|
|
122
|
+
class SjlTerm extends HTMLElement {
|
|
123
|
+
connectedCallback() {
|
|
124
|
+
const b = this.querySelector<HTMLButtonElement>('.copy');
|
|
125
|
+
const live = this.querySelector('[aria-live]');
|
|
126
|
+
if (!b || !navigator.clipboard) return;
|
|
127
|
+
b.hidden = false;
|
|
128
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
129
|
+
b.addEventListener('click', async () => {
|
|
130
|
+
clearTimeout(timer);
|
|
131
|
+
try {
|
|
132
|
+
await navigator.clipboard.writeText(b.dataset.copy ?? '');
|
|
133
|
+
b.textContent = 'Copied';
|
|
134
|
+
} catch {
|
|
135
|
+
// Select the command, so the reader can copy it by hand; focus stays on the button.
|
|
136
|
+
const sel = getSelection();
|
|
137
|
+
sel?.selectAllChildren(this.querySelector('code')!);
|
|
138
|
+
b.textContent = 'Selected';
|
|
139
|
+
}
|
|
140
|
+
if (live) live.textContent = b.textContent === 'Copied' ? 'Copied' : 'Copy blocked. The command is selected.';
|
|
141
|
+
timer = setTimeout(() => { b.textContent = 'Copy'; if (live) live.textContent = ''; }, 2000);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (!customElements.get('sjl-term')) customElements.define('sjl-term', SjlTerm);
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<style>
|
|
149
|
+
.sjl-bento {
|
|
150
|
+
display: grid;
|
|
151
|
+
gap: 0.85rem;
|
|
152
|
+
grid-template-columns: repeat(6, minmax(0, 1fr));
|
|
153
|
+
grid-auto-flow: row dense;
|
|
154
|
+
margin-block: 1rem 2rem;
|
|
155
|
+
}
|
|
156
|
+
.tile {
|
|
157
|
+
position: relative;
|
|
158
|
+
min-width: 0;
|
|
159
|
+
display: grid;
|
|
160
|
+
gap: 0.8rem;
|
|
161
|
+
align-content: start;
|
|
162
|
+
padding: 1.2rem;
|
|
163
|
+
background: var(--sl-color-gray-7);
|
|
164
|
+
border: 1px solid var(--sl-color-gray-5);
|
|
165
|
+
border-radius: var(--sjl-radius);
|
|
166
|
+
}
|
|
167
|
+
.tile h3 { margin: 0; font: 700 1.02rem/1.2 var(--sjl-font-display); letter-spacing: -0.01em; color: var(--sl-color-white); }
|
|
168
|
+
|
|
169
|
+
/* The hero: the claim, lit from the corner by the product's colour. */
|
|
170
|
+
.hero {
|
|
171
|
+
grid-column: span 4;
|
|
172
|
+
min-height: 17rem;
|
|
173
|
+
align-content: end;
|
|
174
|
+
overflow: hidden;
|
|
175
|
+
isolation: isolate;
|
|
176
|
+
}
|
|
177
|
+
.mesh {
|
|
178
|
+
position: absolute;
|
|
179
|
+
inset: 0;
|
|
180
|
+
z-index: -1;
|
|
181
|
+
background:
|
|
182
|
+
radial-gradient(60% 80% at 88% 8%, var(--sjl-glow), transparent 70%),
|
|
183
|
+
radial-gradient(45% 65% at 8% 112%, color-mix(in oklab, var(--sjl-brand) 26%, transparent), transparent 70%),
|
|
184
|
+
radial-gradient(30% 40% at 55% 40%, color-mix(in oklab, var(--sjl-brand) 10%, transparent), transparent 70%);
|
|
185
|
+
}
|
|
186
|
+
.eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; font: 600 0.72rem/1 var(--sl-font); letter-spacing: 0.12em; text-transform: uppercase; color: var(--sl-color-gray-2); }
|
|
187
|
+
.claim { margin: 0; font: 800 clamp(1.9rem, 4.2vw, 3.1rem)/1.04 var(--sjl-font-display); letter-spacing: -0.035em; color: var(--sl-color-white); text-wrap: balance; }
|
|
188
|
+
.sub { margin: 0; max-width: 48ch; color: var(--sl-color-gray-2); font-size: 1.02rem; line-height: 1.55; }
|
|
189
|
+
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
|
|
190
|
+
|
|
191
|
+
/* Row one: the hero and Ask (two rows tall). Row two: Work with an agent and the map. Then the
|
|
192
|
+
Quick start and the flow, each the full width, so a replay or the lanes have room. Without
|
|
193
|
+
Ask, the hero takes the full width and the agent tile and map share the next row. */
|
|
194
|
+
.t-jack { grid-column: span 2; grid-row: span 2; }
|
|
195
|
+
.t-agent { grid-column: span 2; }
|
|
196
|
+
.t-map { grid-column: span 2; }
|
|
197
|
+
.t-term { grid-column: 1 / -1; }
|
|
198
|
+
.t-flow { grid-column: 1 / -1; }
|
|
199
|
+
.sjl-bento:not([data-agent]) .t-map { grid-column: span 4; }
|
|
200
|
+
.sjl-bento:not([data-ask]) .hero { grid-column: span 6; }
|
|
201
|
+
.sjl-bento:not([data-ask]) .t-agent, .sjl-bento:not([data-ask]) .t-map { grid-column: span 3; }
|
|
202
|
+
.sjl-bento:not([data-ask]):not([data-agent]) .t-map { grid-column: 1 / -1; }
|
|
203
|
+
|
|
204
|
+
.term { position: relative; display: block; border-radius: 14px; background: #0e0f14; color: #e8e6ef; overflow: hidden; }
|
|
205
|
+
.term pre { margin: 0; padding: 0.9rem 4.2rem 0.9rem 1rem; overflow-x: auto; font: 500 0.84rem/1.55 var(--sl-font-mono); white-space: pre-wrap; overflow-wrap: anywhere; background: transparent; border: 0; }
|
|
206
|
+
.term .pr { color: color-mix(in oklab, var(--sjl-brand) 70%, #fff); }
|
|
207
|
+
.copy { position: absolute; top: 0.4rem; inset-inline-end: 0.4rem; min-height: 2.25rem; min-width: 3.5rem; border: 1px solid #2c2d36; background: #191a22; color: #e2dff0; border-radius: 8px; padding: 0.3rem 0.6rem; font: 600 0.75rem/1 var(--sl-font); cursor: pointer; }
|
|
208
|
+
.copy[hidden] { display: none; }
|
|
209
|
+
@media (pointer: coarse) { .copy { min-height: 44px; } }
|
|
210
|
+
.copy:hover { border-color: var(--sjl-brand); }
|
|
211
|
+
.copy:focus-visible { outline: 2px solid var(--sjl-brand); outline-offset: 2px; }
|
|
212
|
+
.note { margin: 0; font-size: 0.8rem; color: var(--sl-color-gray-3); }
|
|
213
|
+
|
|
214
|
+
.t-map ul { margin: 0; padding: 0; list-style: none; }
|
|
215
|
+
.t-map li a { display: grid; gap: 0.1rem; padding: 0.55rem 0; border-bottom: 1px solid var(--sl-color-gray-5); color: var(--sl-color-white); text-decoration: none; font-weight: 600; }
|
|
216
|
+
.t-map li:last-child a { border-bottom: 0; }
|
|
217
|
+
.t-map li a small { font-weight: 400; font-size: 0.78rem; color: var(--sl-color-gray-3); }
|
|
218
|
+
.t-map li a:hover span { color: var(--sl-color-text-accent); }
|
|
219
|
+
.t-map li a:focus-visible { outline: 2px solid var(--sl-color-text-accent); outline-offset: 2px; border-radius: 6px; }
|
|
220
|
+
.copy-page { margin-top: 0.25rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
|
|
221
|
+
|
|
222
|
+
@media (max-width: 56rem) {
|
|
223
|
+
.sjl-bento > * { grid-column: 1 / -1 !important; grid-row: auto !important; }
|
|
224
|
+
.hero { min-height: 0; }
|
|
225
|
+
}
|
|
226
|
+
</style>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The suite's callouts: Tip, Heads up, Wet paint, and Captain Jack's aside. Import the named
|
|
3
|
+
// ones (Tip.astro, HeadsUp.astro, WetPaint.astro, JackAside.astro); this is what they share.
|
|
4
|
+
// Tip wears the product accent; Heads up and Wet paint wear vibekit's status fills (never the
|
|
5
|
+
// accent, which would read as "this product" rather than "careful"); Jack's aside is his voice.
|
|
6
|
+
import { jack } from '@superjackfruitlabs/vibekit-frame/components/shadow.ts';
|
|
7
|
+
|
|
8
|
+
interface Props { kind: 'tip' | 'heads-up' | 'wet-paint' | 'jack'; title?: string }
|
|
9
|
+
const TITLES = { tip: 'Tip', 'heads-up': 'Heads up', 'wet-paint': 'Wet paint', jack: 'Captain Jack says' } as const;
|
|
10
|
+
const { kind } = Astro.props;
|
|
11
|
+
const title = Astro.props.title ?? TITLES[kind];
|
|
12
|
+
---
|
|
13
|
+
<aside class:list={['sjl-callout', `sjl-callout--${kind}`]} aria-label={title}>
|
|
14
|
+
{kind === 'jack' ? <span class="ava" set:html={jack()} /> : <span class="icon" aria-hidden="true">{kind === 'tip' ? '✦' : kind === 'heads-up' ? '!' : '🖌'}</span>}
|
|
15
|
+
<div class="body">
|
|
16
|
+
<p class="title">{title}</p>
|
|
17
|
+
<div class="content"><slot /></div>
|
|
18
|
+
</div>
|
|
19
|
+
</aside>
|
|
20
|
+
|
|
21
|
+
<style>
|
|
22
|
+
.sjl-callout {
|
|
23
|
+
--_edge: var(--sl-color-accent);
|
|
24
|
+
--_bg: var(--sl-color-accent-low);
|
|
25
|
+
display: grid;
|
|
26
|
+
grid-template-columns: auto 1fr;
|
|
27
|
+
gap: 0.75rem;
|
|
28
|
+
margin-block: 1.25rem;
|
|
29
|
+
padding: 0.9rem 1rem;
|
|
30
|
+
border-radius: 14px;
|
|
31
|
+
border: 1px solid color-mix(in oklab, var(--_edge) 45%, transparent);
|
|
32
|
+
border-inline-start: 4px solid var(--_edge);
|
|
33
|
+
background: var(--_bg);
|
|
34
|
+
color: var(--sl-color-white);
|
|
35
|
+
}
|
|
36
|
+
.sjl-callout--heads-up { --_edge: color-mix(in oklab, var(--sjl-status-half-lit) 55%, var(--sjl-status-ink)); --_bg: color-mix(in oklab, var(--sjl-status-half-lit) 22%, var(--sl-color-black)); }
|
|
37
|
+
.sjl-callout--wet-paint { --_edge: color-mix(in oklab, var(--sjl-status-wet-paint) 55%, var(--sjl-status-ink)); --_bg: color-mix(in oklab, var(--sjl-status-wet-paint) 22%, var(--sl-color-black)); }
|
|
38
|
+
.sjl-callout--jack { --_edge: var(--sl-color-gray-4); --_bg: var(--sl-color-gray-6); border-radius: 4px 18px 18px 18px; }
|
|
39
|
+
.icon { width: 1.6rem; height: 1.6rem; border-radius: 50%; display: grid; place-items: center; font: 700 0.85rem/1 var(--sl-font); background: color-mix(in oklab, var(--_edge) 25%, transparent); color: var(--sl-color-white); }
|
|
40
|
+
.ava { width: 2.4rem; height: 2.4rem; border-radius: 50%; overflow: hidden; display: grid; place-items: center; background: var(--sjl-soft); }
|
|
41
|
+
.ava :global(svg) { width: 118%; height: 118%; margin-top: 12%; }
|
|
42
|
+
.body { min-width: 0; }
|
|
43
|
+
.title { margin: 0 0 0.25rem; font: 700 0.95rem/1.3 var(--sjl-font-display); }
|
|
44
|
+
.content :global(> :first-child) { margin-top: 0; }
|
|
45
|
+
.content :global(> :last-child) { margin-bottom: 0; }
|
|
46
|
+
.sjl-callout--jack .content { font-style: italic; }
|
|
47
|
+
</style>
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
---
|
|
2
|
+
// Ask Captain Jack, on a docs page. He answers from this product's docs (the suite worker reads
|
|
3
|
+
// the site's /llms-full.txt) and the lab's checked claims, and cites what he used: each docs
|
|
4
|
+
// passage he cites becomes a link to its page here. When the docs do not cover a question he
|
|
5
|
+
// says he does not know, rather than guess. The worker is routed at /captain/* on every docs
|
|
6
|
+
// domain, so the question goes to this site's own origin.
|
|
7
|
+
//
|
|
8
|
+
// Without JavaScript the box is a link to search; with it, the answer streams in.
|
|
9
|
+
import { getCollection } from 'astro:content';
|
|
10
|
+
import { jack } from '@superjackfruitlabs/vibekit-frame/components/shadow.ts';
|
|
11
|
+
import { productOf } from '../site.ts';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
product?: string;
|
|
15
|
+
/** Questions offered as chips; the last is a deliberate miss, to show he says when he does not know. */
|
|
16
|
+
examples?: string[];
|
|
17
|
+
/** Where the worker is; same-origin by default. */
|
|
18
|
+
endpoint?: string;
|
|
19
|
+
/** The page titles, for linking his sources (read from the docs collection when left out). */
|
|
20
|
+
pages?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
const me = productOf(Astro.props.product);
|
|
23
|
+
const examples = Astro.props.examples ?? [];
|
|
24
|
+
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
25
|
+
let pages = Astro.props.pages;
|
|
26
|
+
if (!pages) {
|
|
27
|
+
try {
|
|
28
|
+
const docs = await getCollection('docs');
|
|
29
|
+
pages = Object.fromEntries(docs.map((d) => [d.data.title, `${base}/${d.id === 'index' ? '' : `${d.id}/`}`]));
|
|
30
|
+
} catch { pages = {}; }
|
|
31
|
+
}
|
|
32
|
+
const config = JSON.stringify({ product: me.slug, name: me.name, endpoint: Astro.props.endpoint ?? '/captain/', pages }).replace(/</g, '\\u003c');
|
|
33
|
+
---
|
|
34
|
+
<sjl-captain-jack class="sjl-jack">
|
|
35
|
+
<div class="ans">
|
|
36
|
+
<span class="ava" set:html={jack()} />
|
|
37
|
+
<div class="said">
|
|
38
|
+
<p class="bubble" aria-live="polite">Ahoy. Ask me anything about {me.name}. I answer only from these docs, and I'll tell you when they don't cover it.</p>
|
|
39
|
+
<ol class="sources" hidden></ol>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
<form class="q" action={`${base}/`} method="get">
|
|
43
|
+
<label class="sjl-sr-only" for={`ask-${me.slug}`}>Ask Captain Jack about {me.name}</label>
|
|
44
|
+
<input id={`ask-${me.slug}`} name="ask" maxlength="500" autocomplete="off" placeholder="Ask Captain Jack…" required />
|
|
45
|
+
<button class="sjl-btn primary" type="submit">Ask</button>
|
|
46
|
+
</form>
|
|
47
|
+
{examples.length > 0 && (
|
|
48
|
+
<div class="chips">{examples.map((q) => <button type="button" class="chip sjl-focus" data-q={q}>{q}</button>)}</div>
|
|
49
|
+
)}
|
|
50
|
+
<p class="fine">An AI writes his answers from the docs; check anything you copy.</p>
|
|
51
|
+
<script type="application/json" set:html={config} />
|
|
52
|
+
</sjl-captain-jack>
|
|
53
|
+
|
|
54
|
+
<script>
|
|
55
|
+
type Fact = { id: string; title: string; product: string; status: string; caveat: string | null; href?: string };
|
|
56
|
+
const DONT_KNOW = /I don't know that one/;
|
|
57
|
+
const slug = (s: string) => s.toLowerCase().trim().replace(/[^\w\s-]/g, '').replace(/\s+/g, '-');
|
|
58
|
+
const esc = (s: string) => s.replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]!);
|
|
59
|
+
const visitor = (): string => {
|
|
60
|
+
try {
|
|
61
|
+
const id = localStorage.getItem('sjl-visitor');
|
|
62
|
+
if (id) return id;
|
|
63
|
+
const fresh = crypto.randomUUID();
|
|
64
|
+
localStorage.setItem('sjl-visitor', fresh);
|
|
65
|
+
return fresh;
|
|
66
|
+
} catch { return crypto.randomUUID(); }
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
class SjlCaptainJack extends HTMLElement {
|
|
70
|
+
connectedCallback() {
|
|
71
|
+
const cfg = JSON.parse(this.querySelector('script[type="application/json"]')!.textContent || '{}');
|
|
72
|
+
const form = this.querySelector('form')!;
|
|
73
|
+
const input = form.querySelector('input')!;
|
|
74
|
+
const bubble = this.querySelector('.bubble')!;
|
|
75
|
+
const sources = this.querySelector<HTMLOListElement>('.sources')!;
|
|
76
|
+
const button = form.querySelector('button')!;
|
|
77
|
+
const agent = new URL(`agents/captain-jack/${visitor()}`, new URL(cfg.endpoint, location.href));
|
|
78
|
+
const pageHref = (title: string) => {
|
|
79
|
+
const [page = '', heading = ''] = title.split(' › ');
|
|
80
|
+
const href = cfg.pages?.[page];
|
|
81
|
+
return href ? (heading && heading !== page ? `${href}#${slug(heading)}` : href) : null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// While he reads, Ask is aria-disabled rather than disabled, so a focused button keeps focus.
|
|
85
|
+
let busy = false;
|
|
86
|
+
const ask = async (question: string) => {
|
|
87
|
+
question = question.trim().slice(0, 500);
|
|
88
|
+
if (!question || busy) return;
|
|
89
|
+
busy = true;
|
|
90
|
+
button.setAttribute('aria-disabled', 'true');
|
|
91
|
+
bubble.textContent = 'Reading the docs…';
|
|
92
|
+
sources.hidden = true;
|
|
93
|
+
sources.innerHTML = '';
|
|
94
|
+
let facts: Fact[] = [];
|
|
95
|
+
let text = '';
|
|
96
|
+
try {
|
|
97
|
+
const r = await fetch(agent, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ message: question, product: cfg.product }) });
|
|
98
|
+
if (!r.ok || !r.body) throw new Error(String(r.status));
|
|
99
|
+
const reader = r.body.getReader();
|
|
100
|
+
const dec = new TextDecoder();
|
|
101
|
+
let buf = '';
|
|
102
|
+
for (;;) {
|
|
103
|
+
const { done, value } = await reader.read();
|
|
104
|
+
if (done) break;
|
|
105
|
+
buf += dec.decode(value, { stream: true });
|
|
106
|
+
let i;
|
|
107
|
+
while ((i = buf.indexOf('\n\n')) >= 0) {
|
|
108
|
+
const chunk = buf.slice(0, i);
|
|
109
|
+
buf = buf.slice(i + 2);
|
|
110
|
+
const event = chunk.match(/^event: (.+)$/m)?.[1];
|
|
111
|
+
const data = chunk.match(/^data: (.*)$/m)?.[1] ?? '';
|
|
112
|
+
if (event === 'facts') facts = JSON.parse(data);
|
|
113
|
+
else if (!event) { text += JSON.parse(data); render(text, facts, false); }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
render(text, facts, true);
|
|
117
|
+
} catch {
|
|
118
|
+
bubble.textContent = `I can't reach my notes just now. Search is at the top of the page, and every ${cfg.name} page is in the menu.`;
|
|
119
|
+
} finally {
|
|
120
|
+
busy = false;
|
|
121
|
+
button.removeAttribute('aria-disabled');
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// The answer as text, its [D1] / [SA-01] marks as numbered links to the sources it used.
|
|
126
|
+
const render = (t: string, facts: Fact[], done: boolean) => {
|
|
127
|
+
const order: string[] = [];
|
|
128
|
+
const html = esc(t)
|
|
129
|
+
.replace(/\s*\[([A-Z]+-\d+|D\d+)\]/g, (_, id: string) => {
|
|
130
|
+
if (!order.includes(id)) order.push(id);
|
|
131
|
+
return `<sup>${order.indexOf(id) + 1}</sup>`;
|
|
132
|
+
})
|
|
133
|
+
.replace(/`([^`\n]+)`/g, '<code>$1</code>');
|
|
134
|
+
bubble.innerHTML = html || '…';
|
|
135
|
+
if (!done) return;
|
|
136
|
+
const used = order.map((id) => facts.find((f) => f.id === id)).filter((f): f is Fact => !!f);
|
|
137
|
+
if (DONT_KNOW.test(t) || !used.length) {
|
|
138
|
+
sources.hidden = false;
|
|
139
|
+
sources.innerHTML = `<li class="none">No source: these docs don't cover that.</li>`;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
sources.innerHTML = used.map((f) => {
|
|
143
|
+
const href = f.status === 'docs' ? pageHref(f.title) : null;
|
|
144
|
+
const label = esc(f.status === 'docs' ? f.title : `${f.title} (the lab's checked claims)`);
|
|
145
|
+
return `<li>${href ? `<a href="${esc(href)}">${label}</a>` : label}${f.caveat ? ` <em>${esc(f.caveat)}</em>` : ''}</li>`;
|
|
146
|
+
}).join('');
|
|
147
|
+
sources.hidden = false;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
form.addEventListener('submit', (e) => { e.preventDefault(); ask(input.value); });
|
|
151
|
+
this.querySelectorAll<HTMLButtonElement>('[data-q]').forEach((b) => b.addEventListener('click', () => { input.value = b.dataset.q!; ask(b.dataset.q!); }));
|
|
152
|
+
// A search-engine style link (?ask=…) asks straight away.
|
|
153
|
+
const pre = new URLSearchParams(location.search).get('ask');
|
|
154
|
+
if (pre) { input.value = pre; ask(pre); }
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!customElements.get('sjl-captain-jack')) customElements.define('sjl-captain-jack', SjlCaptainJack);
|
|
158
|
+
</script>
|
|
159
|
+
|
|
160
|
+
<style>
|
|
161
|
+
.sjl-jack { display: grid; gap: 0.75rem; }
|
|
162
|
+
.ans { display: grid; grid-template-columns: 2.6rem 1fr; gap: 0.7rem; align-items: start; }
|
|
163
|
+
.ava { width: 2.6rem; height: 2.6rem; border-radius: 50%; overflow: hidden; background: var(--sjl-soft); display: grid; place-items: center; }
|
|
164
|
+
.ava :global(svg) { width: 118%; height: 118%; margin-top: 12%; }
|
|
165
|
+
.said { min-width: 0; }
|
|
166
|
+
.bubble { margin: 0; background: var(--sl-color-gray-6); border-radius: 4px 14px 14px 14px; padding: 0.65rem 0.8rem; font-size: 0.92rem; line-height: 1.5; color: var(--sl-color-white); }
|
|
167
|
+
.bubble :global(sup) { color: var(--sl-color-gray-2); font-weight: 700; }
|
|
168
|
+
.sources { margin: 0.4rem 0 0; padding-inline-start: 1.2rem; font-size: 0.78rem; color: var(--sl-color-gray-3); }
|
|
169
|
+
.sources :global(a) { color: var(--sl-color-text-accent); }
|
|
170
|
+
.sources :global(.none) { list-style: none; margin-inline-start: -1.2rem; }
|
|
171
|
+
.q { display: flex; gap: 0.5rem; }
|
|
172
|
+
.q input { flex: 1; min-width: 0; border: 1px solid var(--sl-color-gray-5); border-radius: 12px; padding: 0.6rem 0.75rem; background: var(--sl-color-gray-7); color: var(--sl-color-white); font: inherit; font-size: 0.95rem; }
|
|
173
|
+
.q input:focus-visible { outline: 2px solid var(--sl-color-text-accent); outline-offset: 1px; }
|
|
174
|
+
.q button[aria-disabled='true'] { opacity: 0.6; cursor: progress; }
|
|
175
|
+
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
|
|
176
|
+
.chip { border: 1px solid var(--sl-color-gray-5); background: var(--sl-color-gray-7); color: var(--sl-color-gray-2); border-radius: 999px; padding: 0.35rem 0.7rem; font: 500 0.78rem/1.2 var(--sl-font); cursor: pointer; text-align: start; }
|
|
177
|
+
.chip:hover { border-color: var(--sjl-brand); color: var(--sl-color-white); }
|
|
178
|
+
@media (pointer: coarse) { .chip { min-height: 44px; } }
|
|
179
|
+
.fine { margin: 0; font-size: 0.72rem; color: var(--sl-color-gray-3); }
|
|
180
|
+
</style>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
// Copy Markdown: the page as its author wrote it (title and body, MDX imports dropped), for
|
|
3
|
+
// pasting into an agent or an issue (the page's `.md` address serves the same text). The text ships in the page as JSON; the button needs
|
|
4
|
+
// JavaScript and stays hidden without it.
|
|
5
|
+
import { pageMarkdown } from '../markdown.ts';
|
|
6
|
+
|
|
7
|
+
interface Props { title: string; body?: string }
|
|
8
|
+
const md = pageMarkdown(Astro.props.title, Astro.props.body);
|
|
9
|
+
const json = JSON.stringify(md).replace(/</g, '\\u003c');
|
|
10
|
+
---
|
|
11
|
+
<sjl-copy-md class="sjl-copy-md">
|
|
12
|
+
<button type="button" class="sjl-btn sjl-copy" hidden>
|
|
13
|
+
<svg aria-hidden="true" viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
|
|
14
|
+
<span class="label">Copy Markdown</span>
|
|
15
|
+
</button>
|
|
16
|
+
<span class="sjl-sr-only" aria-live="polite"></span>
|
|
17
|
+
<script type="application/json" set:html={json} />
|
|
18
|
+
</sjl-copy-md>
|
|
19
|
+
|
|
20
|
+
<script>
|
|
21
|
+
class SjlCopyMd extends HTMLElement {
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
const button = this.querySelector('button')!;
|
|
24
|
+
const label = button.querySelector('.label')!;
|
|
25
|
+
const live = this.querySelector('[aria-live]')!;
|
|
26
|
+
const text = JSON.parse(this.querySelector('script[type="application/json"]')!.textContent || '""');
|
|
27
|
+
if (!navigator.clipboard) return;
|
|
28
|
+
button.hidden = false;
|
|
29
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
30
|
+
button.addEventListener('click', async () => {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
try {
|
|
33
|
+
await navigator.clipboard.writeText(text);
|
|
34
|
+
label.textContent = 'Copied';
|
|
35
|
+
live.textContent = 'Copied';
|
|
36
|
+
} catch {
|
|
37
|
+
label.textContent = 'Copy blocked';
|
|
38
|
+
live.textContent = 'Copy blocked. Open as Markdown has the same text.';
|
|
39
|
+
}
|
|
40
|
+
timer = setTimeout(() => { label.textContent = 'Copy Markdown'; live.textContent = ''; }, 2000);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!customElements.get('sjl-copy-md')) customElements.define('sjl-copy-md', SjlCopyMd);
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<style>
|
|
48
|
+
.sjl-copy { padding: 0.35rem 0.7rem; font-size: 0.8rem; border-radius: 9px; min-height: 2.25rem; }
|
|
49
|
+
@media (pointer: coarse) { .sjl-copy { min-height: 44px; } }
|
|
50
|
+
</style>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
// A prompt to paste into a coding agent: which of this product's docs to read (its llms.txt and
|
|
3
|
+
// llms-full.txt) and what to do with them. The idea is UI SDK's "Build with an Agent" page
|
|
4
|
+
// (ui-sdk.dev/docs/agents/build-with-an-agent): give the agent the docs first, then the task.
|
|
5
|
+
// The text is on the page, so it can be selected by hand; Copy needs JavaScript and a clipboard,
|
|
6
|
+
// says "Copied" when it worked, and announces it to a screen reader.
|
|
7
|
+
import { productOf } from '../site.ts';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
product?: string;
|
|
11
|
+
/** What the agent should do once it has read the docs. */
|
|
12
|
+
task?: string;
|
|
13
|
+
/** The whole prompt, in place of the one built from the product and `task`. */
|
|
14
|
+
prompt?: string;
|
|
15
|
+
/** The docs site's address, for the llms.txt links (default: the product's docs). */
|
|
16
|
+
docs?: string;
|
|
17
|
+
}
|
|
18
|
+
const me = productOf(Astro.props.product);
|
|
19
|
+
const docs = (Astro.props.docs ?? me.docs).replace(/\/$/, '');
|
|
20
|
+
const task = Astro.props.task ?? `Then answer my questions about ${me.name} from those docs.`;
|
|
21
|
+
const prompt = (Astro.props.prompt ?? [
|
|
22
|
+
`I'm working with ${me.name}. Read ${docs}/llms.txt to see what its docs cover, and ${docs}/llms-full.txt for every page in one file.`,
|
|
23
|
+
'',
|
|
24
|
+
task,
|
|
25
|
+
'',
|
|
26
|
+
'Name the docs page each answer comes from, and tell me when the docs do not cover something.',
|
|
27
|
+
].join('\n')).trim();
|
|
28
|
+
---
|
|
29
|
+
<sjl-copy-prompt class="sjl-copy-prompt not-content">
|
|
30
|
+
<pre class="text"><code>{prompt}</code></pre>
|
|
31
|
+
<button type="button" class="sjl-btn copy" hidden><span class="label">Copy prompt</span></button>
|
|
32
|
+
<span class="sjl-sr-only" aria-live="polite"></span>
|
|
33
|
+
</sjl-copy-prompt>
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
class SjlCopyPrompt extends HTMLElement {
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
const button = this.querySelector<HTMLButtonElement>('button.copy')!;
|
|
39
|
+
const label = button.querySelector('.label')!;
|
|
40
|
+
const live = this.querySelector('[aria-live]')!;
|
|
41
|
+
const text = this.querySelector('pre')!.textContent ?? '';
|
|
42
|
+
if (!navigator.clipboard) return;
|
|
43
|
+
button.hidden = false;
|
|
44
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
45
|
+
button.addEventListener('click', async () => {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
try {
|
|
48
|
+
await navigator.clipboard.writeText(text);
|
|
49
|
+
label.textContent = 'Copied';
|
|
50
|
+
live.textContent = 'Copied';
|
|
51
|
+
} catch {
|
|
52
|
+
label.textContent = 'Copy blocked';
|
|
53
|
+
live.textContent = 'Copy blocked. Select the prompt and copy it by hand.';
|
|
54
|
+
}
|
|
55
|
+
timer = setTimeout(() => { label.textContent = 'Copy prompt'; live.textContent = ''; }, 2000);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!customElements.get('sjl-copy-prompt')) customElements.define('sjl-copy-prompt', SjlCopyPrompt);
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<style>
|
|
63
|
+
/* minmax(0, 1fr) and min-width: 0: a long address wraps inside the tile instead of widening it. */
|
|
64
|
+
.sjl-copy-prompt { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5rem; min-width: 0; }
|
|
65
|
+
.text { margin: 0; padding: 0.8rem 0.9rem; border-radius: 12px; background: var(--sl-color-gray-6); border: 1px solid var(--sl-color-gray-5); white-space: pre-wrap; overflow-wrap: anywhere; font: 500 0.8rem/1.5 var(--sl-font-mono); color: var(--sl-color-gray-2); }
|
|
66
|
+
.copy { justify-self: start; min-height: 44px; }
|
|
67
|
+
.copy[hidden] { display: none; }
|
|
68
|
+
</style>
|