@profullstack/waitlist 0.13.0 → 0.14.0
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/README.md +2 -1
- package/package.json +1 -1
- package/src/advisor-client.js +245 -0
- package/src/advisor.js +181 -0
- package/src/build.js +35 -2
- package/src/community.js +1 -0
- package/src/plugins.js +1 -1
- package/src/waitlist.css +13 -0
package/README.md
CHANGED
|
@@ -120,7 +120,7 @@ The page reports one exposure a day; a signup is the conversion. Both go through
|
|
|
120
120
|
waitlist API, which holds the CrawlProof token. Stop the experiment with a winner in
|
|
121
121
|
CrawlProof and every page switches to it. Turn it off per site with `"ab": false`.
|
|
122
122
|
|
|
123
|
-
## Plugins (0.4; buyaday 0.6; book + promo 0.7; affiliate 0.9; paid referral terms 0.13)
|
|
123
|
+
## Plugins (0.4; buyaday 0.6; book + promo 0.7; affiliate 0.9; paid referral terms 0.13; advisor 0.14)
|
|
124
124
|
|
|
125
125
|
Every page showcases all plugins by default. Pick per site in `sites.json`:
|
|
126
126
|
`"plugins": ["form", "board"]` keeps only those, `"plugins": { "faq": false }` drops some.
|
|
@@ -140,6 +140,7 @@ Every page showcases all plugins by default. Pick per site in `sites.json`:
|
|
|
140
140
|
| `book` | The Profullstack pitch (four solution lines) and `<book-a-call>`, our booking widget: open times from the OutreachGraph public calendar in the reader's own time zone, booked inline as a PairUX call. A plain link to the booking page without script. `"booking": {"handle": "chovy"}` picks the calendar |
|
|
141
141
|
| `promo` | "More from the network": sister properties from the live `@profullstack/cross-promo` catalog, tagged `utm_medium=waitlist`. `"promoAudience": "developers"` (or a list) overrides the audience picked from the hierarchy |
|
|
142
142
|
| `community` | A header bar with Search and a branded **Community** button to the name's own tsbb board (`https://bbs.<name>.pit.world`, sign in with pit.world / CoinPay OAuth 2.1, or `tsbb login <board> --with coinpay`). Linked only once the board answers over HTTPS, so new names gain it as their certificate lands. Writes `brand.json` (look, colours, light/dark, closest tsbb skin) that pit.world's board seed uses to match the site |
|
|
143
|
+
| `advisor` | An **Advisor** page (`advisor/`) that answers questions about the site's own topic from what the build holds: the pitch, the FAQ, the resources and the text search results. The visitor signs in with their own c0mpute account (OAuth 2.1 + PKCE, scope `inference`, through CoinPay or a passkey) and the page calls c0mpute's chat API with that key, billed to them: no server and no key on the site. Also writes `advisor/dataset.jsonl` (the same notes as a `c0mpute train lora` dataset), `context.json` and `prompt.txt`, and prints the CLI commands to ask or train from a terminal. Skipped when the build holds fewer than 3 documents. Settings: `advisor: { clientId, model }` (the page registers its own OAuth client on first sign-in when no `clientId` is given). Asking from the browser needs c0mpute to allow cross-origin calls to `/v1/chat/completions` (profullstack/c0mpute#718) |
|
|
143
144
|
| (search, resources) | Every search item and resource carries pit.world's result tools from `https://pit.world/widgets.js`: vote, Summarize, Listen and Share. They work without an account; on a pit.world host, "Sign in with CoinPay" (OAuth 2.1 + PKCE through pit.world) raises the limits. From a terminal the same account is `pit login` |
|
|
144
145
|
| `affiliate` | Referrals (0.9). Every signup gets a personal link `https://<site>/?ref=<code>`, shown right after joining by `<pf-referral-share>` ("You are #X of Y, N people referred.", copy button, plain X/Bluesky/LinkedIn/email links) and in the confirmation email with a signed status page. A visitor who arrives with `?ref=` keeps a 30-day first-party, first-touch cookie `wl_ref`; their signup credits the referrer once they confirm. Each confirmed referral moves the referrer up `bumpPlaces`. A "Move up the list" section bakes `<pf-referral-leaderboard>` (handles or masked emails only). With `buyaday` on, a door sold to a referred visitor credits the referrer too (holi.days `ref=<code>.<site>`), and since 0.13 the page states the paid terms: the referrer earns `commissionPct` of what that visitor pays and the visitor gets `discountPct` off. See below |
|
|
145
146
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/waitlist",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Email waitlist for any launch page: a <waitlist-form> web component, a live signup chart, and a static-site builder on @profullstack/css + @profullstack/charts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// <site-advisor>: the question box on a site's Advisor page.
|
|
2
|
+
//
|
|
3
|
+
// The page is static, so the visitor brings the account: "Sign in with
|
|
4
|
+
// c0mpute" runs OAuth 2.1 + PKCE against c0mpute.com (scope `inference`),
|
|
5
|
+
// which signs them in through CoinPay or a passkey. The key that comes back
|
|
6
|
+
// stays in this tab's sessionStorage and is sent only to c0mpute.
|
|
7
|
+
//
|
|
8
|
+
// The page registers itself as a public OAuth client the first time someone
|
|
9
|
+
// signs in (c0mpute's open registration endpoint), unless the build baked a
|
|
10
|
+
// client id into the config. Config is the JSON script inside the element
|
|
11
|
+
// (src/advisor.js advisorConfig).
|
|
12
|
+
|
|
13
|
+
const SCOPE = 'inference';
|
|
14
|
+
const b64url = (bytes) => btoa(String.fromCharCode(...new Uint8Array(bytes))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
15
|
+
|
|
16
|
+
export function randomToken(bytes = 32) {
|
|
17
|
+
return b64url(crypto.getRandomValues(new Uint8Array(bytes)));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** PKCE S256: the challenge for a verifier. */
|
|
21
|
+
export async function pkceChallenge(verifier) {
|
|
22
|
+
return b64url(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier)));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The page's own address without query or hash: the redirect URI. */
|
|
26
|
+
export function redirectUri(href) {
|
|
27
|
+
const u = new URL(href);
|
|
28
|
+
return `${u.origin}${u.pathname}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function authorizeUrl({ api, clientId, redirect, challenge, state }) {
|
|
32
|
+
const q = new URLSearchParams({ response_type: 'code', client_id: clientId, redirect_uri: redirect, code_challenge: challenge, code_challenge_method: 'S256', scope: SCOPE, state });
|
|
33
|
+
return `${api}/oauth/authorize?${q}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The chat request: the site's notes as the system message, then the conversation so far. */
|
|
37
|
+
export function chatBody(cfg, history, question) {
|
|
38
|
+
return {
|
|
39
|
+
model: cfg.model || 'auto',
|
|
40
|
+
stream: false,
|
|
41
|
+
messages: [{ role: 'system', content: cfg.system }, ...history.slice(-6), { role: 'user', content: question }],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A message a person can act on, from whatever c0mpute (or the network) said. */
|
|
46
|
+
export function explain(status, body) {
|
|
47
|
+
const msg = body?.error?.message || body?.error_description || (typeof body?.error === 'string' ? body.error : '');
|
|
48
|
+
if (status === 401) return 'Your c0mpute sign-in is no longer valid. Sign in again.';
|
|
49
|
+
if (status === 402) return msg || 'Your c0mpute balance is empty. Top it up at c0mpute.com/checkout.';
|
|
50
|
+
if (status === 429) return msg || 'Too many questions for now. Try again in a few minutes.';
|
|
51
|
+
if (status === 0) return 'c0mpute could not be reached from this page. Try again, or ask from a terminal with the command below.';
|
|
52
|
+
return msg || `c0mpute answered ${status}. Try again in a minute.`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const store = (kind) => {
|
|
56
|
+
try {
|
|
57
|
+
return kind === 'local' ? localStorage : sessionStorage;
|
|
58
|
+
} catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
async function call(url, init) {
|
|
64
|
+
try {
|
|
65
|
+
const res = await fetch(url, init);
|
|
66
|
+
const body = await res.json().catch(() => ({}));
|
|
67
|
+
return { ok: res.ok, status: res.status, body };
|
|
68
|
+
} catch {
|
|
69
|
+
// A network failure and a refused cross-origin call look the same from here.
|
|
70
|
+
return { ok: false, status: 0, body: {} };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const h = (tag, props = {}, ...kids) => {
|
|
75
|
+
const n = document.createElement(tag);
|
|
76
|
+
for (const [k, v] of Object.entries(props)) {
|
|
77
|
+
if (k === 'class') n.className = v;
|
|
78
|
+
else if (k.startsWith('on')) n.addEventListener(k.slice(2), v);
|
|
79
|
+
else if (v !== false && v != null) n.setAttribute(k, v === true ? '' : v);
|
|
80
|
+
}
|
|
81
|
+
for (const k of kids) n.append(k);
|
|
82
|
+
return n;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
if (typeof HTMLElement !== 'undefined') {
|
|
86
|
+
class SiteAdvisor extends HTMLElement {
|
|
87
|
+
#cfg = null;
|
|
88
|
+
#key = null;
|
|
89
|
+
#who = null;
|
|
90
|
+
#history = [];
|
|
91
|
+
#busy = false;
|
|
92
|
+
#error = '';
|
|
93
|
+
#log = [];
|
|
94
|
+
|
|
95
|
+
async connectedCallback() {
|
|
96
|
+
if (this.#cfg) return;
|
|
97
|
+
try {
|
|
98
|
+
this.#cfg = JSON.parse(this.querySelector('script[type="application/json"]')?.textContent || 'null');
|
|
99
|
+
} catch {
|
|
100
|
+
this.#cfg = null;
|
|
101
|
+
}
|
|
102
|
+
if (!this.#cfg?.system) return; // leave the static fallback text in place
|
|
103
|
+
this.#key = store('session')?.getItem(this.#k('key')) ?? null;
|
|
104
|
+
this.#render();
|
|
105
|
+
await this.#finishSignIn();
|
|
106
|
+
if (this.#key) void this.#loadWho();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#k(name) {
|
|
110
|
+
return `site-advisor:${this.#cfg.api}:${name}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async #clientId() {
|
|
114
|
+
if (this.#cfg.clientId) return this.#cfg.clientId;
|
|
115
|
+
const redirect = redirectUri(location.href);
|
|
116
|
+
const cacheKey = this.#k(`client:${redirect}`);
|
|
117
|
+
const cached = store('local')?.getItem(cacheKey);
|
|
118
|
+
if (cached) return cached;
|
|
119
|
+
const r = await call(`${this.#cfg.api}/api/oauth/register`, {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
headers: { 'content-type': 'application/json' },
|
|
122
|
+
body: JSON.stringify({ client_name: `${this.#cfg.site} advisor (${location.host})`, redirect_uris: [redirect], token_endpoint_auth_method: 'none', grant_types: ['authorization_code'], response_types: ['code'] }),
|
|
123
|
+
});
|
|
124
|
+
if (!r.ok || !r.body.client_id) throw new Error(explain(r.status, r.body));
|
|
125
|
+
store('local')?.setItem(cacheKey, r.body.client_id);
|
|
126
|
+
return r.body.client_id;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async #signIn() {
|
|
130
|
+
this.#error = '';
|
|
131
|
+
this.#busy = true;
|
|
132
|
+
this.#render();
|
|
133
|
+
try {
|
|
134
|
+
const clientId = await this.#clientId();
|
|
135
|
+
const verifier = randomToken(48);
|
|
136
|
+
const state = randomToken(16);
|
|
137
|
+
const redirect = redirectUri(location.href);
|
|
138
|
+
store('session')?.setItem(this.#k('pending'), JSON.stringify({ verifier, state, clientId, redirect }));
|
|
139
|
+
location.assign(authorizeUrl({ api: this.#cfg.api, clientId, redirect, challenge: await pkceChallenge(verifier), state }));
|
|
140
|
+
} catch (e) {
|
|
141
|
+
this.#busy = false;
|
|
142
|
+
this.#error = e.message;
|
|
143
|
+
this.#render();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Back from c0mpute with ?code&state: swap the code for a key, then clean the address bar. */
|
|
148
|
+
async #finishSignIn() {
|
|
149
|
+
const q = new URLSearchParams(location.search);
|
|
150
|
+
if (!q.has('code') && !q.has('error')) return;
|
|
151
|
+
const pending = JSON.parse(store('session')?.getItem(this.#k('pending')) || 'null');
|
|
152
|
+
store('session')?.removeItem(this.#k('pending'));
|
|
153
|
+
history.replaceState(null, '', redirectUri(location.href));
|
|
154
|
+
if (q.has('error')) {
|
|
155
|
+
this.#error = q.get('error') === 'access_denied' ? 'Sign-in was cancelled.' : `Sign-in failed: ${q.get('error_description') || q.get('error')}`;
|
|
156
|
+
} else if (!pending || pending.state !== q.get('state')) {
|
|
157
|
+
this.#error = 'Sign-in could not be completed in this tab. Start it again.';
|
|
158
|
+
} else {
|
|
159
|
+
const r = await call(`${this.#cfg.api}/api/oauth/token`, {
|
|
160
|
+
method: 'POST',
|
|
161
|
+
headers: { 'content-type': 'application/json' },
|
|
162
|
+
body: JSON.stringify({ grant_type: 'authorization_code', code: q.get('code'), code_verifier: pending.verifier, client_id: pending.clientId, redirect_uri: pending.redirect }),
|
|
163
|
+
});
|
|
164
|
+
if (r.ok && r.body.access_token) {
|
|
165
|
+
this.#key = r.body.access_token;
|
|
166
|
+
store('session')?.setItem(this.#k('key'), this.#key);
|
|
167
|
+
} else this.#error = explain(r.status, r.body);
|
|
168
|
+
}
|
|
169
|
+
this.#render();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async #loadWho() {
|
|
173
|
+
const r = await call(`${this.#cfg.api}/api/v1/me`, { headers: { authorization: `Bearer ${this.#key}` } });
|
|
174
|
+
if (r.status === 401) return this.#signOut('Your c0mpute sign-in is no longer valid. Sign in again.');
|
|
175
|
+
if (r.ok) {
|
|
176
|
+
this.#who = { name: r.body.name || 'your c0mpute account', balance: r.body.balance?.spendable_usd ?? null };
|
|
177
|
+
this.#render();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#signOut(message = '') {
|
|
182
|
+
const key = this.#key;
|
|
183
|
+
this.#key = null;
|
|
184
|
+
this.#who = null;
|
|
185
|
+
this.#history = [];
|
|
186
|
+
store('session')?.removeItem(this.#k('key'));
|
|
187
|
+
if (key && !message) void call(`${this.#cfg.api}/api/oauth/revoke`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ token: key }) });
|
|
188
|
+
this.#error = message;
|
|
189
|
+
this.#render();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async #ask(question) {
|
|
193
|
+
const q = question.trim();
|
|
194
|
+
if (!q || this.#busy) return;
|
|
195
|
+
this.#busy = true;
|
|
196
|
+
this.#error = '';
|
|
197
|
+
this.#log.push({ role: 'user', text: q });
|
|
198
|
+
this.#render();
|
|
199
|
+
const r = await call(`${this.#cfg.api}/v1/chat/completions`, {
|
|
200
|
+
method: 'POST',
|
|
201
|
+
headers: { authorization: `Bearer ${this.#key}`, 'content-type': 'application/json' },
|
|
202
|
+
body: JSON.stringify(chatBody(this.#cfg, this.#history, q)),
|
|
203
|
+
});
|
|
204
|
+
this.#busy = false;
|
|
205
|
+
const answer = r.body?.choices?.[0]?.message?.content;
|
|
206
|
+
if (r.ok && answer) {
|
|
207
|
+
this.#history.push({ role: 'user', content: q }, { role: 'assistant', content: answer });
|
|
208
|
+
this.#log.push({ role: 'assistant', text: answer, model: r.body.model });
|
|
209
|
+
} else if (r.status === 401) {
|
|
210
|
+
this.#log.pop();
|
|
211
|
+
return this.#signOut('Your c0mpute sign-in is no longer valid. Sign in again.');
|
|
212
|
+
} else {
|
|
213
|
+
this.#log.pop();
|
|
214
|
+
this.#error = r.ok ? 'The model returned no answer. Try rephrasing.' : explain(r.status, r.body);
|
|
215
|
+
}
|
|
216
|
+
this.#render();
|
|
217
|
+
this.querySelector('input[name="q"]')?.focus();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
#render() {
|
|
221
|
+
const cfg = this.#cfg;
|
|
222
|
+
const out = [];
|
|
223
|
+
if (this.#log.length) {
|
|
224
|
+
out.push(h('div', { class: 'advisor-log stack', 'aria-live': 'polite' }, ...this.#log.map((m) => h('div', { class: `advisor-turn advisor-${m.role}` }, h('p', { class: 'advisor-who muted' }, m.role === 'user' ? 'You' : `${cfg.site} advisor${m.model ? ` · ${m.model}` : ''}`), h('div', { class: 'advisor-text' }, m.text)))));
|
|
225
|
+
}
|
|
226
|
+
if (this.#error) out.push(h('p', { class: 'advisor-error', role: 'alert' }, this.#error));
|
|
227
|
+
if (!this.#key) {
|
|
228
|
+
out.push(h('p', {}, h('button', { type: 'button', disabled: this.#busy, onclick: () => void this.#signIn() }, this.#busy ? 'Opening c0mpute…' : 'Sign in with c0mpute to ask')));
|
|
229
|
+
} else {
|
|
230
|
+
const input = h('input', { name: 'q', type: 'text', required: true, maxlength: '1000', autocomplete: 'off', placeholder: cfg.examples?.[0] || `Ask about ${cfg.site}`, 'aria-label': 'Your question', disabled: this.#busy });
|
|
231
|
+
out.push(
|
|
232
|
+
h('form', { class: 'stack', onsubmit: (e) => { e.preventDefault(); void this.#ask(input.value); } }, h('div', { class: 'field-group' }, input, h('button', { type: 'submit', disabled: this.#busy }, this.#busy ? 'Thinking…' : 'Ask'))),
|
|
233
|
+
);
|
|
234
|
+
if (cfg.examples?.length && !this.#log.length) {
|
|
235
|
+
out.push(h('p', { class: 'advisor-examples' }, ...cfg.examples.map((ex) => h('button', { type: 'button', class: 'advisor-example', disabled: this.#busy, onclick: () => void this.#ask(ex) }, ex))));
|
|
236
|
+
}
|
|
237
|
+
out.push(
|
|
238
|
+
h('p', { class: 'muted' }, this.#who ? `Signed in as ${this.#who.name}${this.#who.balance != null ? `, balance $${Number(this.#who.balance).toFixed(2)}` : ''}. ` : 'Signed in. ', h('button', { type: 'button', class: 'advisor-link', onclick: () => this.#signOut() }, 'Sign out')),
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
this.replaceChildren(...out);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (!customElements.get('site-advisor')) customElements.define('site-advisor', SiteAdvisor);
|
|
245
|
+
}
|
package/src/advisor.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// The `advisor` plugin: an Advisor page on every site that answers questions
|
|
2
|
+
// about that site's own topic, from what the build already holds (the pitch,
|
|
3
|
+
// the FAQ, the resources and the baked search results).
|
|
4
|
+
//
|
|
5
|
+
// Nothing here has a server or a key. The visitor signs in with their own
|
|
6
|
+
// c0mpute account (OAuth 2.1 + PKCE, which signs in through CoinPay) and the
|
|
7
|
+
// page calls c0mpute's chat API with the key that grant returns, billed to
|
|
8
|
+
// them. The same corpus is written as a JSONL dataset so anyone can train a
|
|
9
|
+
// LoRA adapter on it with `c0mpute train lora`.
|
|
10
|
+
//
|
|
11
|
+
// Files written under advisor/: index.html, context.json, prompt.txt, dataset.jsonl.
|
|
12
|
+
import { esc, headTags, clip } from './seo.js';
|
|
13
|
+
|
|
14
|
+
export const C0MPUTE = 'https://c0mpute.com';
|
|
15
|
+
/** Small on purpose: workers train LoRA in fp32, on CPU as often as GPU. */
|
|
16
|
+
export const TRAIN_BASE = 'Qwen/Qwen2.5-0.5B-Instruct';
|
|
17
|
+
export const ADVISOR_PATH = 'advisor/';
|
|
18
|
+
|
|
19
|
+
const MAX_CONTEXT_CHARS = 14_000;
|
|
20
|
+
const PER_TAB = 6;
|
|
21
|
+
|
|
22
|
+
const clean = (v) => String(v ?? '').replace(/\s+/g, ' ').trim();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Everything the site knows, as documents: { kind, title, text, url? }.
|
|
26
|
+
* `search` and `resources` are what runPlugins fetched (either may be null).
|
|
27
|
+
*/
|
|
28
|
+
export function advisorCorpus(s, { search = null, resources = null } = {}) {
|
|
29
|
+
const docs = [];
|
|
30
|
+
const about = [s.tagline, s.summary, s.about].map(clean).filter(Boolean).join(' ');
|
|
31
|
+
if (about) docs.push({ kind: 'site', title: s.title, text: about, url: s.url });
|
|
32
|
+
if (s.points?.length) docs.push({ kind: 'site', title: `What is coming on ${s.title}`, text: s.points.map(clean).filter(Boolean).join('; '), url: s.url });
|
|
33
|
+
for (const f of s.faq ?? []) {
|
|
34
|
+
const q = clean(f.q);
|
|
35
|
+
const a = clean(f.a);
|
|
36
|
+
if (q && a) docs.push({ kind: 'faq', title: q, text: a, url: s.url });
|
|
37
|
+
}
|
|
38
|
+
const seen = new Set();
|
|
39
|
+
const add = (kind, r) => {
|
|
40
|
+
const url = clean(r?.url);
|
|
41
|
+
const title = clean(r?.title);
|
|
42
|
+
if (!url || !title || seen.has(url)) return;
|
|
43
|
+
seen.add(url);
|
|
44
|
+
docs.push({ kind, title, text: clean(r.summary) || title, url });
|
|
45
|
+
};
|
|
46
|
+
for (const r of resources?.results ?? []) add('resource', r);
|
|
47
|
+
for (const t of search?.live ?? []) {
|
|
48
|
+
// Image and video tabs are thumbnails with thin titles: no use to a text model.
|
|
49
|
+
if (t.id === 'images' || t.id === 'videos') continue;
|
|
50
|
+
for (const r of (search.tabs?.[t.id]?.results ?? []).slice(0, PER_TAB)) add(t.id, r);
|
|
51
|
+
}
|
|
52
|
+
return docs;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The corpus as numbered text for the prompt, cut at whole documents to fit a small model. */
|
|
56
|
+
export function advisorContext(corpus, maxChars = MAX_CONTEXT_CHARS) {
|
|
57
|
+
const out = [];
|
|
58
|
+
let used = 0;
|
|
59
|
+
for (const [i, d] of corpus.entries()) {
|
|
60
|
+
const line = `[${i + 1}] ${d.title}\n${clip(d.text, 600)}${d.url ? `\nSource: ${d.url}` : ''}`;
|
|
61
|
+
if (used + line.length > maxChars) break;
|
|
62
|
+
out.push(line);
|
|
63
|
+
used += line.length + 2;
|
|
64
|
+
}
|
|
65
|
+
return out.join('\n\n');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function advisorSystem(s) {
|
|
69
|
+
return `You are the ${s.title} advisor, on ${s.host}. ${clean(s.tagline)}
|
|
70
|
+
Answer questions about this site's topic from the numbered notes below, and say which note a fact came from by its number. The notes are the site's own FAQ and a daily snapshot of web results about the topic.
|
|
71
|
+
- Lead with the answer in one or two sentences, then the detail.
|
|
72
|
+
- If the notes do not cover the question, say so plainly and answer from general knowledge, marked as such. Never invent a source.
|
|
73
|
+
- ${s.title} itself has not opened yet: for anything about the product, the notes are all that is known.
|
|
74
|
+
- Keep it under about 200 words unless asked for more.`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The corpus as a `c0mpute train lora` dataset: one {"title","text"} per line.
|
|
79
|
+
* FAQ entries keep their question and answer together so the adapter learns the pair.
|
|
80
|
+
*/
|
|
81
|
+
export function advisorDataset(s, corpus) {
|
|
82
|
+
return corpus
|
|
83
|
+
.map((d) => {
|
|
84
|
+
const text = d.kind === 'faq' ? `Question: ${d.title}\nAnswer: ${d.text}` : `${d.text}${d.url && d.kind !== 'site' ? `\nSource: ${d.url}` : ''}`;
|
|
85
|
+
return JSON.stringify({ title: d.kind === 'faq' ? `${s.title} FAQ` : d.title, text });
|
|
86
|
+
})
|
|
87
|
+
.join('\n') + (corpus.length ? '\n' : '');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** What the <site-advisor> element needs, baked into the page. */
|
|
91
|
+
export function advisorConfig(s, corpus) {
|
|
92
|
+
return {
|
|
93
|
+
site: s.title,
|
|
94
|
+
host: s.host,
|
|
95
|
+
api: C0MPUTE,
|
|
96
|
+
clientId: s.advisor?.clientId || null,
|
|
97
|
+
model: s.advisor?.model || 'auto',
|
|
98
|
+
system: `${advisorSystem(s)}\n\nNotes:\n\n${advisorContext(corpus)}`,
|
|
99
|
+
examples: (s.faq ?? []).map((f) => clean(f.q)).filter(Boolean).slice(0, 3),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const slug = (name) => clean(name).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'site';
|
|
104
|
+
|
|
105
|
+
/** The shell commands shown on the page: train an adapter, and ask from the CLI. */
|
|
106
|
+
export function advisorCommands(s) {
|
|
107
|
+
const base = `${s.url}${ADVISOR_PATH}`;
|
|
108
|
+
return {
|
|
109
|
+
train: [
|
|
110
|
+
'c0mpute login',
|
|
111
|
+
`curl -sO ${base}dataset.jsonl`,
|
|
112
|
+
`c0mpute train lora --base ${TRAIN_BASE} --dataset dataset.jsonl --name ${slug(s.name)}-advisor`,
|
|
113
|
+
],
|
|
114
|
+
ask: [`c0mpute chat --system "$(curl -s ${base}prompt.txt)" "What is ${s.title}?"`],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function advisorMeta(s, corpus) {
|
|
119
|
+
const url = `${s.url}${ADVISOR_PATH}`;
|
|
120
|
+
return {
|
|
121
|
+
url,
|
|
122
|
+
seoTitle: clip(`Ask the ${s.title} advisor`, 60),
|
|
123
|
+
description: clip(`Ask anything about ${s.title} and its topic. Answers come from this site's FAQ and ${corpus.length} notes it keeps, on open models on the c0mpute network.`, 158),
|
|
124
|
+
h1: `Ask the ${s.title} advisor`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The home page card that links to the Advisor page. */
|
|
129
|
+
export function advisorCardHtml(s, corpus) {
|
|
130
|
+
return `<section class="card stack" aria-labelledby="advisor-card"><h2 id="advisor-card">Ask the advisor</h2>
|
|
131
|
+
<p>Questions about ${esc(s.title)} and its topic, answered from the ${corpus.length} notes this site keeps.</p>
|
|
132
|
+
<p><a class="button" href="${ADVISOR_PATH}">Ask a question</a></p></section>`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The Advisor page. `chrome({ head, body, spec })` renders the shared shell.
|
|
137
|
+
* Everything useful is in the HTML (what it knows, how to ask from a CLI, how
|
|
138
|
+
* to train): the element only adds sign-in and the question box.
|
|
139
|
+
*/
|
|
140
|
+
export function advisorPageHtml(s, corpus, { chrome, rebase }) {
|
|
141
|
+
const m = advisorMeta(s, corpus);
|
|
142
|
+
const ps = { ...s, url: m.url, seoTitle: m.seoTitle, description: m.description };
|
|
143
|
+
const cfg = JSON.stringify(advisorConfig(s, corpus)).replace(/</g, '\\u003c');
|
|
144
|
+
const cmd = advisorCommands(s);
|
|
145
|
+
const base = esc(m.url);
|
|
146
|
+
const known = corpus
|
|
147
|
+
.filter((d) => d.kind !== 'site')
|
|
148
|
+
.slice(0, 24)
|
|
149
|
+
.map((d) => `<li>${d.url && d.kind !== 'faq' ? `<a href="${esc(d.url)}" rel="noopener nofollow">${esc(d.title)}</a>` : esc(d.title)} <small class="muted">${esc(d.kind)}</small></li>`)
|
|
150
|
+
.join('');
|
|
151
|
+
const body = `<header class="waitlist-hero stack" data-space="md">
|
|
152
|
+
<p class="waitlist-kicker"><a href="../">← ${esc(s.title)}</a> <span class="badge">Advisor</span></p>
|
|
153
|
+
<h1>${esc(m.h1)}</h1>
|
|
154
|
+
<p class="waitlist-answer">Ask about ${esc(s.title)} and its topic. Answers come from this site's FAQ and a daily snapshot of ${corpus.length} notes, on open models on the <a href="${C0MPUTE}">c0mpute</a> network.</p>
|
|
155
|
+
</header>
|
|
156
|
+
<section class="card stack" aria-labelledby="advisor-ask"><h2 id="advisor-ask">Ask a question</h2>
|
|
157
|
+
<site-advisor><script type="application/json">${cfg}</script>
|
|
158
|
+
<p class="muted">Asking needs JavaScript and a c0mpute account. Without them, the commands below do the same from a terminal.</p>
|
|
159
|
+
</site-advisor>
|
|
160
|
+
<p class="muted">You sign in with your own c0mpute account (through CoinPay or a passkey). Each answer is charged to your compute balance, or runs on the free tier when it is empty. This site has no server and never sees your key.</p>
|
|
161
|
+
</section>
|
|
162
|
+
<section class="stack advisor-section" aria-labelledby="advisor-cli"><h2 id="advisor-cli">From a terminal</h2>
|
|
163
|
+
<p>The same notes, with the <a href="${C0MPUTE}/docs">c0mpute CLI</a>:</p>
|
|
164
|
+
<pre><code>${esc(cmd.ask.join('\n'))}</code></pre>
|
|
165
|
+
</section>
|
|
166
|
+
<section class="stack advisor-section" aria-labelledby="advisor-train"><h2 id="advisor-train">Train your own</h2>
|
|
167
|
+
<p>The notes are also a training set (<a href="${base}dataset.jsonl">dataset.jsonl</a>, ${corpus.length} rows, rebuilt daily). This trains a small LoRA adapter on it with a c0mpute worker and downloads it to you:</p>
|
|
168
|
+
<pre><code>${esc(cmd.train.join('\n'))}</code></pre>
|
|
169
|
+
<p class="muted">The last command only checks the data and shows a preview. Add <code>--yes</code> to send it to a worker; training is paid from your c0mpute balance at the price the worker bids.</p>
|
|
170
|
+
</section>
|
|
171
|
+
${known ? `<section class="stack advisor-section" aria-labelledby="advisor-knows"><h2 id="advisor-knows">What it knows</h2><ul class="waitlist-points">${known}</ul>
|
|
172
|
+
<p class="muted">Machine-readable: <a href="${base}context.json">context.json</a> · <a href="${base}prompt.txt">prompt.txt</a></p></section>` : ''}`;
|
|
173
|
+
const head = headTags(ps);
|
|
174
|
+
return { html: rebase(chrome({ head, body, spec: ps }), '../'), path: 'advisor', meta: m };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** context.json: the prompt and the documents, for agents and the CLI. */
|
|
178
|
+
export function advisorContextJson(s, corpus) {
|
|
179
|
+
const cfg = advisorConfig(s, corpus);
|
|
180
|
+
return JSON.stringify({ site: s.title, host: s.host, updated: s.updated, model: cfg.model, system: cfg.system, documents: corpus, dataset: `${s.url}${ADVISOR_PATH}dataset.jsonl`, train: { base: TRAIN_BASE, commands: advisorCommands(s).train } }, null, 2) + '\n';
|
|
181
|
+
}
|
package/src/build.js
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { mkdir, writeFile, copyFile, readFile, readdir } from 'node:fs/promises';
|
|
6
6
|
import { pluginSet, keywordsFor, runPlugins, baseSlot, affiliateConfig } from './plugins.js';
|
|
7
|
+
import { ADVISOR_PATH, advisorCardHtml, advisorContextJson, advisorCorpus, advisorConfig, advisorDataset, advisorMeta, advisorPageHtml } from './advisor.js';
|
|
7
8
|
import { boardLive, boardUrl, brandJson, navHtml } from './community.js';
|
|
8
9
|
import {
|
|
9
10
|
TABS, SORTS, tabPath, searchPageHtml, searchPageMeta, searchJson, searchLlms, manifestJson,
|
|
10
|
-
openSearchXml, serviceWorker, maskableIconSvg,
|
|
11
|
+
openSearchXml, serviceWorker, maskableIconSvg, rebase,
|
|
11
12
|
} from './search.js';
|
|
12
13
|
import { createRequire } from 'node:module';
|
|
13
14
|
import { createHash } from 'node:crypto';
|
|
@@ -133,6 +134,7 @@ export function normalize(spec) {
|
|
|
133
134
|
audience: spec.audience || '',
|
|
134
135
|
promoAudience: spec.promoAudience || null,
|
|
135
136
|
booking: spec.booking && typeof spec.booking === 'object' ? spec.booking : null,
|
|
137
|
+
advisor: spec.advisor && typeof spec.advisor === 'object' ? spec.advisor : null,
|
|
136
138
|
indexnowKey: spec.indexnowKey || indexNowKey(name),
|
|
137
139
|
updated: spec.updated || new Date().toISOString().slice(0, 10),
|
|
138
140
|
};
|
|
@@ -264,8 +266,15 @@ export async function buildSite(spec, out, { footers = true, images = true, fetc
|
|
|
264
266
|
await writeFile(join(out, 'assets', 'icon-maskable-512.png'), await svgToPng(maskableIconSvg(s), { width: 512 }));
|
|
265
267
|
}
|
|
266
268
|
const foot = footers ? await renderFooters(s, { fetchImpl }) : '';
|
|
267
|
-
const { slot, search } = await runPlugins(s, out, { fetchImpl, cacheDir, maxAgeMs, searchOpts });
|
|
269
|
+
const { slot, search, resources } = await runPlugins(s, out, { fetchImpl, cacheDir, maxAgeMs, searchOpts });
|
|
268
270
|
s.searchLive = Boolean(search?.live?.length);
|
|
271
|
+
// advisor: a page that answers from what this build holds. Too little to go on, no page.
|
|
272
|
+
const corpus = s.plugins.has('advisor') ? advisorCorpus(s, { search, resources }) : [];
|
|
273
|
+
s.advisorLive = corpus.length >= ADVISOR_MIN_DOCS;
|
|
274
|
+
if (s.advisorLive) {
|
|
275
|
+
await copyFile(join(here, 'advisor-client.js'), join(out, 'assets', 'advisor.js'));
|
|
276
|
+
slot.cards.push(advisorCardHtml(s, corpus));
|
|
277
|
+
}
|
|
269
278
|
// community: the name's own board, linked once it answers over HTTPS; brand.json for its look.
|
|
270
279
|
if (s.plugins.has('community')) {
|
|
271
280
|
s.community = (await boardLive(boardUrl(s), { fetchImpl })) ? boardUrl(s) : null;
|
|
@@ -277,6 +286,7 @@ export async function buildSite(spec, out, { footers = true, images = true, fetc
|
|
|
277
286
|
await writeFile(join(out, 'index.html'), withAssetVersion(pageHtml(s, { footers: foot, slot }), ver));
|
|
278
287
|
await writeFile(join(out, '404.html'), withAssetVersion(pageHtml(s, { footers: foot, noindex: true, slot }), ver));
|
|
279
288
|
const pages = s.searchLive ? await writeSearch(s, search, out, { footers: foot, slot, ver, images }) : [];
|
|
289
|
+
if (s.advisorLive) pages.push(await writeAdvisor(s, corpus, out, { footers: foot, slot, ver }));
|
|
280
290
|
s.extraUrls = pages.map((p) => p.url);
|
|
281
291
|
await writeFile(join(out, 'site.webmanifest'), manifestJson(s, s.searchLive ? search : null));
|
|
282
292
|
await writeFile(join(out, 'opensearch.xml'), openSearchXml(s));
|
|
@@ -318,6 +328,29 @@ async function writeSearch(s, search, out, { footers, slot, ver, images }) {
|
|
|
318
328
|
return pages;
|
|
319
329
|
}
|
|
320
330
|
|
|
331
|
+
/** Below this many documents an advisor would only be guessing. */
|
|
332
|
+
export const ADVISOR_MIN_DOCS = 3;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Write the Advisor page and its data: the prompt and documents (context.json,
|
|
336
|
+
* prompt.txt) and the training set (dataset.jsonl). Returns the sitemap entry.
|
|
337
|
+
*/
|
|
338
|
+
async function writeAdvisor(s, corpus, out, { footers, slot, ver }) {
|
|
339
|
+
const dir = join(out, ADVISOR_PATH);
|
|
340
|
+
await mkdir(dir, { recursive: true });
|
|
341
|
+
// The waitlist form rides along; the home page's cards and sections do not.
|
|
342
|
+
const pageSlot = { ...slot, cards: [], sections: [], scripts: [...slot.scripts, '<script type="module" src="assets/advisor.js"></script>'] };
|
|
343
|
+
const { html } = advisorPageHtml(s, corpus, {
|
|
344
|
+
rebase,
|
|
345
|
+
chrome: ({ head, body, spec }) => withAssetVersion(shellHtml(spec, { head, main: `${body}\n<section class="card stack" aria-label="Waitlist"><h2>Get ${esc(s.title)} when it opens</h2>${slot.hero.join('\n')}</section>`, footers, slot: pageSlot }), ver),
|
|
346
|
+
});
|
|
347
|
+
await writeFile(join(dir, 'index.html'), html);
|
|
348
|
+
await writeFile(join(dir, 'context.json'), advisorContextJson(s, corpus));
|
|
349
|
+
await writeFile(join(dir, 'prompt.txt'), advisorConfig(s, corpus).system + '\n');
|
|
350
|
+
await writeFile(join(dir, 'dataset.jsonl'), advisorDataset(s, corpus));
|
|
351
|
+
return { url: advisorMeta(s, corpus).url, lastmod: s.updated, changefreq: 'daily' };
|
|
352
|
+
}
|
|
353
|
+
|
|
321
354
|
/** A short hash of everything in assets/; module imports between assets carry it too. */
|
|
322
355
|
export async function versionAssets(out) {
|
|
323
356
|
const dir = join(out, 'assets');
|
package/src/community.js
CHANGED
|
@@ -78,6 +78,7 @@ export async function boardLive(url, { fetchImpl = globalThis.fetch, timeoutMs =
|
|
|
78
78
|
export function navHtml(s, { community = null, esc }) {
|
|
79
79
|
const links = [
|
|
80
80
|
s.searchLive ? `<a href="search/">Search</a>` : '',
|
|
81
|
+
s.advisorLive ? `<a href="advisor/">Advisor</a>` : '',
|
|
81
82
|
community ? `<a class="waitlist-community" href="${esc(community)}" rel="noopener">Community</a>` : '',
|
|
82
83
|
].filter(Boolean);
|
|
83
84
|
if (!links.length) return '';
|
package/src/plugins.js
CHANGED
|
@@ -25,7 +25,7 @@ import { fetchSearch, searchCardHtml } from './search.js';
|
|
|
25
25
|
|
|
26
26
|
const require = createRequire(import.meta.url);
|
|
27
27
|
|
|
28
|
-
export const PLUGINS = ['form', 'stats', 'ab', 'faq', 'search', 'resources', 'board', 'share', 'feed', 'buyaday', 'book', 'promo', 'affiliate', 'community'];
|
|
28
|
+
export const PLUGINS = ['form', 'stats', 'ab', 'faq', 'search', 'resources', 'board', 'share', 'feed', 'buyaday', 'book', 'promo', 'affiliate', 'community', 'advisor'];
|
|
29
29
|
|
|
30
30
|
/** Resolve a site's `plugins` setting to a Set (default: all of them). */
|
|
31
31
|
export function pluginSet(setting) {
|
package/src/waitlist.css
CHANGED
|
@@ -55,3 +55,16 @@
|
|
|
55
55
|
.waitlist-nav-links a:hover { border-color: currentColor; }
|
|
56
56
|
.waitlist-nav-links a.waitlist-community { background: var(--pf-color-primary, currentColor); color: var(--pf-color-on-primary, #fff); border-color: transparent; font-weight: 700; }
|
|
57
57
|
.waitlist-nav-links a.waitlist-community:hover { filter: brightness(1.1); }
|
|
58
|
+
|
|
59
|
+
/* advisor plugin: the question box on advisor/ (src/advisor-client.js). */
|
|
60
|
+
site-advisor { display: block; }
|
|
61
|
+
.advisor-section { margin-block-start: 2rem; }
|
|
62
|
+
.advisor-section pre { overflow-x: auto; }
|
|
63
|
+
.advisor-turn { padding-block: 0.6rem; border-block-end: 1px solid color-mix(in srgb, currentColor 18%, transparent); }
|
|
64
|
+
.advisor-who { margin: 0 0 0.2rem; font-size: 0.8em; }
|
|
65
|
+
.advisor-text { white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
66
|
+
.advisor-user .advisor-text { font-weight: 600; }
|
|
67
|
+
.advisor-error { padding: 0.6rem 0.8rem; border: 1px solid currentColor; border-radius: 0.4rem; }
|
|
68
|
+
.advisor-examples { display: flex; flex-wrap: wrap; gap: 0.5rem; }
|
|
69
|
+
.advisor-example { font-size: 0.85em; }
|
|
70
|
+
.advisor-link { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
|