liveog 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +137 -2
- package/dist/browser.d.ts +6 -0
- package/dist/browser.js +27 -0
- package/dist/check.d.ts +20 -0
- package/dist/check.js +106 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +53 -0
- package/dist/cover.d.ts +38 -0
- package/dist/cover.js +66 -0
- package/dist/draw.d.ts +12 -0
- package/dist/draw.js +43 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/install.d.ts +26 -0
- package/dist/install.js +85 -0
- package/dist/links.d.ts +32 -0
- package/dist/links.js +32 -0
- package/dist/mcp.d.ts +18 -0
- package/dist/mcp.js +213 -0
- package/dist/og.d.ts +24 -0
- package/dist/og.js +44 -0
- package/dist/study.d.ts +31 -0
- package/dist/study.js +161 -0
- package/dist/template.d.ts +21 -0
- package/dist/template.js +35 -0
- package/package.json +57 -4
package/dist/install.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// `liveog mcp add`: the MCP server added to every agent app on this machine (Hermes Agent, Claude
|
|
2
|
+
// Code, Codex, Cursor, VS Code, Amp, Windsurf, Kiro, LM Studio, OpenCode, Claude Desktop). Apps with their own
|
|
3
|
+
// command are asked through it; apps that keep a JSON file get one key added, nothing else changed.
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { homedir } from 'node:os';
|
|
7
|
+
import { dirname, join } from 'node:path';
|
|
8
|
+
export const SERVER = { command: 'npx', args: ['-y', 'liveog', 'mcp'] };
|
|
9
|
+
/** Add liveog under `key` (mcpServers for most apps) in an app's JSON file; the rest of the file is kept as it was. */
|
|
10
|
+
export function addToJson(file, key = 'mcpServers', entry = SERVER) {
|
|
11
|
+
let cfg = {};
|
|
12
|
+
if (existsSync(file)) {
|
|
13
|
+
try {
|
|
14
|
+
cfg = JSON.parse(readFileSync(file, 'utf8') || '{}');
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return 'failed';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const servers = (cfg[key] && typeof cfg[key] === 'object' ? cfg[key] : {});
|
|
21
|
+
if (servers.liveog)
|
|
22
|
+
return 'already';
|
|
23
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
24
|
+
writeFileSync(file, `${JSON.stringify({ ...cfg, [key]: { ...servers, liveog: entry } }, null, 2)}\n`);
|
|
25
|
+
return 'added';
|
|
26
|
+
}
|
|
27
|
+
export const realEnv = () => ({
|
|
28
|
+
home: homedir(),
|
|
29
|
+
platform: process.platform,
|
|
30
|
+
has: (bin) => { try {
|
|
31
|
+
execFileSync(process.platform === 'win32' ? 'where' : 'which', [bin], { stdio: 'ignore' });
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
} },
|
|
37
|
+
run: (bin, args) => execFileSync(bin, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 30_000 }),
|
|
38
|
+
});
|
|
39
|
+
const viaCommand = (env, bin, args) => {
|
|
40
|
+
try {
|
|
41
|
+
env.run(bin, args);
|
|
42
|
+
return 'added';
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
const msg = String(e.stderr ?? e.message);
|
|
46
|
+
return /already exists|already configured/i.test(msg) ? 'already' : 'failed';
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/** Each app found, and what happened. */
|
|
50
|
+
export function addEverywhere(env = realEnv()) {
|
|
51
|
+
const out = [];
|
|
52
|
+
const tail = ['--', SERVER.command, ...SERVER.args];
|
|
53
|
+
if (env.has('hermes'))
|
|
54
|
+
out.push({ app: 'Hermes Agent', result: viaCommand(env, 'hermes', ['mcp', 'add', 'liveog', '--command', SERVER.command, '--args', ...SERVER.args]) });
|
|
55
|
+
if (env.has('claude'))
|
|
56
|
+
out.push({ app: 'Claude Code', result: viaCommand(env, 'claude', ['mcp', 'add', '--scope', 'user', 'liveog', ...tail]) });
|
|
57
|
+
if (env.has('codex'))
|
|
58
|
+
out.push({ app: 'Codex', result: viaCommand(env, 'codex', ['mcp', 'add', 'liveog', ...tail]) });
|
|
59
|
+
if (env.has('amp'))
|
|
60
|
+
out.push({ app: 'Amp', result: viaCommand(env, 'amp', ['mcp', 'add', 'liveog', ...tail]) });
|
|
61
|
+
if (env.has('code'))
|
|
62
|
+
out.push({ app: 'VS Code', result: viaCommand(env, 'code', ['--add-mcp', JSON.stringify({ name: 'liveog', ...SERVER })]) });
|
|
63
|
+
// apps that keep a JSON file: [name, file, key, entry]; found when the file's folder is there
|
|
64
|
+
const files = [
|
|
65
|
+
['Cursor', join(env.home, '.cursor', 'mcp.json')],
|
|
66
|
+
['Windsurf', join(env.home, '.codeium', 'windsurf', 'mcp_config.json')],
|
|
67
|
+
['Kiro', join(env.home, '.kiro', 'settings', 'mcp.json')],
|
|
68
|
+
['LM Studio', join(env.home, '.lmstudio', 'mcp.json')],
|
|
69
|
+
['OpenCode', join(env.home, '.config', 'opencode', 'opencode.json'), 'mcp', { type: 'local', command: [SERVER.command, ...SERVER.args], enabled: true }],
|
|
70
|
+
];
|
|
71
|
+
if (env.platform === 'darwin')
|
|
72
|
+
files.push(['Claude Desktop', join(env.home, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json')]);
|
|
73
|
+
for (const [app, file, key, entry] of files)
|
|
74
|
+
if (existsSync(dirname(file)))
|
|
75
|
+
out.push({ app, result: addToJson(file, key, entry) });
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/** What to tell the person. */
|
|
79
|
+
export function report(found) {
|
|
80
|
+
const manual = `Any other MCP client: run "${[SERVER.command, ...SERVER.args].join(' ')}" over stdio, e.g.\n${JSON.stringify({ mcpServers: { liveog: SERVER } }, null, 2)}`;
|
|
81
|
+
if (!found.length)
|
|
82
|
+
return `No agent app found here.\n${manual}`;
|
|
83
|
+
const word = { added: 'added', already: 'already there', failed: 'could not add, see below' };
|
|
84
|
+
return [...found.map((f) => `${f.app.padEnd(16)}${word[f.result]}`), '', found.some((f) => f.result === 'failed') ? manual : 'Restart the app, then ask: "Set up link previews for this project."'].join('\n');
|
|
85
|
+
}
|
package/dist/links.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Card } from './og.js';
|
|
2
|
+
export interface Kind {
|
|
3
|
+
name: string;
|
|
4
|
+
/** Is this path this kind? */
|
|
5
|
+
match: (path: string) => boolean;
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
alt?: string;
|
|
9
|
+
/** The generic cover's path on your site, e.g. /og/join.png. */
|
|
10
|
+
cover?: string;
|
|
11
|
+
/** A link that holds a secret (an invite code, a share token). */
|
|
12
|
+
private?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** A link's own cover, when one has been drawn for it: its path and, maybe, its own title. */
|
|
15
|
+
export interface Own {
|
|
16
|
+
image: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Headers for every answer at a private link, found or not. */
|
|
20
|
+
export declare const PRIVATE_HEADERS: Readonly<Record<string, string>>;
|
|
21
|
+
export interface Links {
|
|
22
|
+
/** The kind a path is; the fallback for any path no kind matches. */
|
|
23
|
+
of(path: string): Kind;
|
|
24
|
+
/** The card for a path: its own cover and title when given, else the kind's. */
|
|
25
|
+
card(path: string, origin: string | null, own?: Own | null): Card;
|
|
26
|
+
/** The headers this path's answers should carry. */
|
|
27
|
+
headers(path: string): Record<string, string>;
|
|
28
|
+
/** The page with the path's tags in its head. */
|
|
29
|
+
page(html: string, path: string, origin: string | null, own?: Own | null): string;
|
|
30
|
+
}
|
|
31
|
+
/** Your site's links: its name, its kinds (first match wins), and the kind for everything else. */
|
|
32
|
+
export declare function links(site: string, kinds: readonly Kind[], fallback: Omit<Kind, 'match'>): Links;
|
package/dist/links.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Link kinds: which paths are which kind, the words and generic cover each shows, and which are
|
|
2
|
+
// private. A private link's preview never holds its path (the code or token in it), and its answers
|
|
3
|
+
// keep it out of search, Referers and caches.
|
|
4
|
+
import { inject, tags } from './og.js';
|
|
5
|
+
/** Headers for every answer at a private link, found or not. */
|
|
6
|
+
export const PRIVATE_HEADERS = Object.freeze({
|
|
7
|
+
'referrer-policy': 'no-referrer',
|
|
8
|
+
'x-robots-tag': 'noindex, nofollow',
|
|
9
|
+
'cache-control': 'no-store',
|
|
10
|
+
});
|
|
11
|
+
/** Your site's links: its name, its kinds (first match wins), and the kind for everything else. */
|
|
12
|
+
export function links(site, kinds, fallback) {
|
|
13
|
+
const rest = { ...fallback, match: () => true };
|
|
14
|
+
const of = (path) => kinds.find((k) => k.match(path)) ?? rest;
|
|
15
|
+
function card(path, origin, own) {
|
|
16
|
+
const k = of(path);
|
|
17
|
+
const title = own?.title || k.title;
|
|
18
|
+
const image = own?.image || k.cover;
|
|
19
|
+
const c = { site, title, description: k.description };
|
|
20
|
+
if (origin && image) {
|
|
21
|
+
c.image = origin + image;
|
|
22
|
+
c.alt = own?.title ? `${site}: ${own.title}` : (k.alt ?? title);
|
|
23
|
+
}
|
|
24
|
+
return c;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
of,
|
|
28
|
+
card,
|
|
29
|
+
headers: (path) => (of(path).private ? { ...PRIVATE_HEADERS } : {}),
|
|
30
|
+
page: (html, path, origin, own) => inject(html, tags(card(path, origin, own))),
|
|
31
|
+
};
|
|
32
|
+
}
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const INSTRUCTIONS = "liveog gives a project link previews that stay current: the tags, a 1200 x 630 cover per kind of link, and privacy for links that hold a secret.\n\nHow to work, with the person:\n1. study_project, then say in a few lines which of its links people share (home, an article, a profile, an invite, a listing, a share) and what each preview should show. Ask which matter; do not decide alone.\n If no logo file turns up (it may live in a component, an image host or a design tool), ask the person for one: an SVG, a PNG, or a screenshot to trace.\n2. For the ones they pick, draw two or three ideas with draw_cover in the project's own colours, fonts and mark. Look at each, fix what is off, then show them. Let the person choose.\n3. setup_project for the code, then wire it in. Save the chosen covers with out.\n4. check_link on a deployed link to confirm.\n\nA good cover:\n- Even sides: the same margin left and right, nothing closer to an edge. The default cover (draw_cover with a title) already has this; start there.\n- One font, two weights, three sizes. The title under 30 characters, two lines at most.\n- The line under the title says what is true now: who is in, the bid, how close to the goal.\n- At most one picture, bottom right, its foot on the text's last line. The mark top left; a word or two top right for state.\n- The project's own colours, high contrast. No gradients or shadows the brand does not have.\n- It must read at 360px wide, as chats show it.\n- Never a private link's code or token, or a name it should not show.";
|
|
2
|
+
export declare const SETUP = "Add liveog to this project (npm i liveog; Node 22+, Deno, Bun, Workers; ESM).\n\n1. Name the kinds of link, first match wins:\n import { links, originOf } from 'liveog';\n const site = links('yoursite', [\n { name: 'invite', match: (p) => p.startsWith('/join/'), title: 'Join the team', description: '...', cover: '/og/invite.png', private: true },\n ], { name: 'home', title: 'yoursite', description: '...', cover: '/og/home.png' });\n\n2. Where the server sends an HTML page:\n const origin = originOf(req.headers.host, process.env.SITE); // SITE: the public host\n for (const [k, v] of Object.entries(site.headers(path))) res.setHeader(k, v);\n res.end(site.page(html, path, origin, own)); // own: { image, title? } for a link's own cover, else null\n A static site: write tags(card) into each page at build time instead.\n\n3. Draw each kind's cover once and commit the PNGs: draw_cover with out, or\n npx liveog cover \"Title\" public/og/home.png, or npx liveog draw cover.html public/og/home.png.\n\n4. Only for a link whose picture changes (an invite filling up, a bid, a goal): the page that has\n it open draws it (import { drawCover, sendCover } from 'liveog/browser') and posts it. The server\n keeps it if isCover(bytes), sets cover = nextCover(cover) and the link's own image is\n coverPath(cover). At GET /c/<id>/<v>.png answer with answer(parseCoverPath(path), cover):\n 200, 302 to the newest, or 404. nextCover(cover, true) when a private link is stopped or replaced.\n\n5. npx liveog check https://yoursite/some/link";
|
|
3
|
+
type Msg = {
|
|
4
|
+
jsonrpc: '2.0';
|
|
5
|
+
id?: number | string;
|
|
6
|
+
method?: string;
|
|
7
|
+
params?: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
/** Pages drawn for an agent may not reach the network or this machine's files: inline styles and
|
|
10
|
+
* scripts, data: pictures and Google Fonts only. */
|
|
11
|
+
export declare const CSP = "default-src 'none'; style-src 'unsafe-inline' https://fonts.googleapis.com; font-src data: https://fonts.gstatic.com; img-src data: blob:; script-src 'unsafe-inline'";
|
|
12
|
+
export declare function lockDown(html: string): string;
|
|
13
|
+
/** Where to save a cover: inside the project folder, never outside it. */
|
|
14
|
+
export declare function savePath(out: string, root?: string): string | null;
|
|
15
|
+
/** One message in, its answer out (null for a notification). */
|
|
16
|
+
export declare function reply(m: Msg, version: string): Promise<object | null>;
|
|
17
|
+
export declare function serve(version: string, input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream): void;
|
|
18
|
+
export {};
|
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// The MCP server: JSON-RPC over stdio, one message per line. Four small tools; how to use them and
|
|
2
|
+
// what a good cover looks like is said once, in INSTRUCTIONS, which a client reads at the start.
|
|
3
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
6
|
+
import { createInterface } from 'node:readline';
|
|
7
|
+
import { check, describe } from './check.js';
|
|
8
|
+
import { draw } from './draw.js';
|
|
9
|
+
import { study } from './study.js';
|
|
10
|
+
import { coverHtml } from './template.js';
|
|
11
|
+
export const INSTRUCTIONS = `liveog gives a project link previews that stay current: the tags, a 1200 x 630 cover per kind of link, and privacy for links that hold a secret.
|
|
12
|
+
|
|
13
|
+
How to work, with the person:
|
|
14
|
+
1. study_project, then say in a few lines which of its links people share (home, an article, a profile, an invite, a listing, a share) and what each preview should show. Ask which matter; do not decide alone.
|
|
15
|
+
If no logo file turns up (it may live in a component, an image host or a design tool), ask the person for one: an SVG, a PNG, or a screenshot to trace.
|
|
16
|
+
2. For the ones they pick, draw two or three ideas with draw_cover in the project's own colours, fonts and mark. Look at each, fix what is off, then show them. Let the person choose.
|
|
17
|
+
3. setup_project for the code, then wire it in. Save the chosen covers with out.
|
|
18
|
+
4. check_link on a deployed link to confirm.
|
|
19
|
+
|
|
20
|
+
A good cover:
|
|
21
|
+
- Even sides: the same margin left and right, nothing closer to an edge. The default cover (draw_cover with a title) already has this; start there.
|
|
22
|
+
- One font, two weights, three sizes. The title under 30 characters, two lines at most.
|
|
23
|
+
- The line under the title says what is true now: who is in, the bid, how close to the goal.
|
|
24
|
+
- At most one picture, bottom right, its foot on the text's last line. The mark top left; a word or two top right for state.
|
|
25
|
+
- The project's own colours, high contrast. No gradients or shadows the brand does not have.
|
|
26
|
+
- It must read at 360px wide, as chats show it.
|
|
27
|
+
- Never a private link's code or token, or a name it should not show.`;
|
|
28
|
+
export const SETUP = `Add liveog to this project (npm i liveog; Node 22+, Deno, Bun, Workers; ESM).
|
|
29
|
+
|
|
30
|
+
1. Name the kinds of link, first match wins:
|
|
31
|
+
import { links, originOf } from 'liveog';
|
|
32
|
+
const site = links('yoursite', [
|
|
33
|
+
{ name: 'invite', match: (p) => p.startsWith('/join/'), title: 'Join the team', description: '...', cover: '/og/invite.png', private: true },
|
|
34
|
+
], { name: 'home', title: 'yoursite', description: '...', cover: '/og/home.png' });
|
|
35
|
+
|
|
36
|
+
2. Where the server sends an HTML page:
|
|
37
|
+
const origin = originOf(req.headers.host, process.env.SITE); // SITE: the public host
|
|
38
|
+
for (const [k, v] of Object.entries(site.headers(path))) res.setHeader(k, v);
|
|
39
|
+
res.end(site.page(html, path, origin, own)); // own: { image, title? } for a link's own cover, else null
|
|
40
|
+
A static site: write tags(card) into each page at build time instead.
|
|
41
|
+
|
|
42
|
+
3. Draw each kind's cover once and commit the PNGs: draw_cover with out, or
|
|
43
|
+
npx liveog cover "Title" public/og/home.png, or npx liveog draw cover.html public/og/home.png.
|
|
44
|
+
|
|
45
|
+
4. Only for a link whose picture changes (an invite filling up, a bid, a goal): the page that has
|
|
46
|
+
it open draws it (import { drawCover, sendCover } from 'liveog/browser') and posts it. The server
|
|
47
|
+
keeps it if isCover(bytes), sets cover = nextCover(cover) and the link's own image is
|
|
48
|
+
coverPath(cover). At GET /c/<id>/<v>.png answer with answer(parseCoverPath(path), cover):
|
|
49
|
+
200, 302 to the newest, or 404. nextCover(cover, true) when a private link is stopped or replaced.
|
|
50
|
+
|
|
51
|
+
5. npx liveog check https://yoursite/some/link`;
|
|
52
|
+
const TOOLS = [
|
|
53
|
+
{
|
|
54
|
+
name: 'study_project',
|
|
55
|
+
title: 'Study a project',
|
|
56
|
+
description: 'Start here. Reads a project folder (no network) and returns, as JSON: its name, colours with their CSS variable names, fonts, logo files, existing preview images and tags, files that set previews, and its routes.',
|
|
57
|
+
inputSchema: { type: 'object', properties: { dir: { type: 'string', description: 'The project folder. Default: the current one.' } } },
|
|
58
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'draw_cover',
|
|
62
|
+
title: 'Draw a cover',
|
|
63
|
+
description: 'Draws a 1200 x 630 cover with this machine\'s Chrome and returns the picture to look at. Give a title (and site, line, tag, art, look) for the default cover, which has good spacing and type; or a whole html page. Saves a PNG only when out is given.',
|
|
64
|
+
inputSchema: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
title: { type: 'string', description: 'Under 30 characters.' },
|
|
68
|
+
site: { type: 'string', description: 'The site\'s name, top left.' },
|
|
69
|
+
line: { type: 'string', description: 'Under the title: what is true now.' },
|
|
70
|
+
tag: { type: 'string', description: 'A word or two, top right: Live, Sold, Friday 8pm.' },
|
|
71
|
+
art: { type: 'string', description: 'One picture, bottom right: inline SVG drawn in currentColor.' },
|
|
72
|
+
look: {
|
|
73
|
+
type: 'object',
|
|
74
|
+
description: 'The project\'s own: bg, fg, muted (hex, rgb(), hsl(), oklch()), font (a CSS font-family list), mark (its logo as inline SVG).',
|
|
75
|
+
properties: { bg: { type: 'string' }, fg: { type: 'string' }, muted: { type: 'string' }, font: { type: 'string' }, mark: { type: 'string' } },
|
|
76
|
+
},
|
|
77
|
+
html: { type: 'string', description: 'Instead of the default: a whole page laid out at 1200 x 630.' },
|
|
78
|
+
out: { type: 'string', description: 'Where to save the PNG, relative to the project, e.g. public/og/home.png.' },
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'setup_project',
|
|
85
|
+
title: 'How to wire it in',
|
|
86
|
+
description: 'The code to add liveog to the project: link kinds, tags, covers, covers that stay current. Use once the person has chosen what each link shows.',
|
|
87
|
+
inputSchema: { type: 'object', properties: {} },
|
|
88
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'check_link',
|
|
92
|
+
title: 'Check a link',
|
|
93
|
+
description: 'Fetches a public link as a chat app would and says what its preview shows (title, description, image size and weight) and what is wrong.',
|
|
94
|
+
inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'An http or https address.' } }, required: ['url'] },
|
|
95
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
const VERSIONS = ['2025-06-18', '2025-03-26', '2024-11-05'];
|
|
99
|
+
const text = (t, isError = false) => ({ content: [{ type: 'text', text: t }], ...(isError ? { isError } : {}) });
|
|
100
|
+
const str = (x) => (typeof x === 'string' && x ? x : undefined);
|
|
101
|
+
/** Pages drawn for an agent may not reach the network or this machine's files: inline styles and
|
|
102
|
+
* scripts, data: pictures and Google Fonts only. */
|
|
103
|
+
export const CSP = "default-src 'none'; style-src 'unsafe-inline' https://fonts.googleapis.com; font-src data: https://fonts.gstatic.com; img-src data: blob:; script-src 'unsafe-inline'";
|
|
104
|
+
export function lockDown(html) {
|
|
105
|
+
const meta = `<meta http-equiv="Content-Security-Policy" content="${CSP}">`;
|
|
106
|
+
if (/<head[^>]*>/i.test(html))
|
|
107
|
+
return html.replace(/<head[^>]*>/i, (h) => h + meta);
|
|
108
|
+
if (/^\s*<!doctype[^>]*>/i.test(html))
|
|
109
|
+
return html.replace(/^\s*<!doctype[^>]*>/i, (d) => d + meta);
|
|
110
|
+
return meta + html;
|
|
111
|
+
}
|
|
112
|
+
/** Where to save a cover: inside the project folder, never outside it. */
|
|
113
|
+
export function savePath(out, root = process.cwd()) {
|
|
114
|
+
const file = resolve(root, out);
|
|
115
|
+
const rel = relative(resolve(root), file);
|
|
116
|
+
return rel && !rel.startsWith('..') && !isAbsolute(rel) ? file : null;
|
|
117
|
+
}
|
|
118
|
+
function drawCover(args) {
|
|
119
|
+
const title = str(args.title);
|
|
120
|
+
const html = str(args.html);
|
|
121
|
+
if (!html && !title)
|
|
122
|
+
return text('Give a title for the default cover, or a whole html page.', true);
|
|
123
|
+
const out = str(args.out);
|
|
124
|
+
if (out && !/\.png$/i.test(out))
|
|
125
|
+
return text('out must end in .png.', true);
|
|
126
|
+
const saveAt = out ? savePath(out) : null;
|
|
127
|
+
if (out && !saveAt)
|
|
128
|
+
return text('out must be a path inside the project, e.g. public/og/home.png.', true);
|
|
129
|
+
const words = { title: title ?? '' };
|
|
130
|
+
for (const k of ['site', 'line', 'tag', 'art']) {
|
|
131
|
+
const v = str(args[k]);
|
|
132
|
+
if (v)
|
|
133
|
+
words[k] = v;
|
|
134
|
+
}
|
|
135
|
+
const look = (args.look && typeof args.look === 'object' ? args.look : {});
|
|
136
|
+
const tmp = mkdtempSync(join(tmpdir(), 'liveog-mcp-'));
|
|
137
|
+
try {
|
|
138
|
+
const src = join(tmp, 'cover.html');
|
|
139
|
+
writeFileSync(src, lockDown(html ?? coverHtml(words, look)));
|
|
140
|
+
const file = saveAt ?? join(tmp, 'cover.png');
|
|
141
|
+
const s = draw(src, file);
|
|
142
|
+
return {
|
|
143
|
+
content: [
|
|
144
|
+
{ type: 'image', data: readFileSync(file).toString('base64'), mimeType: 'image/png' },
|
|
145
|
+
{ type: 'text', text: `${s.width} x ${s.height}${out ? `, saved at ${file}` : ', not saved (give out to keep it)'}` },
|
|
146
|
+
],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
return text(e.message, true);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async function call(name, args) {
|
|
157
|
+
switch (name) {
|
|
158
|
+
case 'study_project': return text(JSON.stringify(study(resolve(str(args.dir) ?? process.cwd())), null, 2));
|
|
159
|
+
case 'draw_cover': return drawCover(args);
|
|
160
|
+
case 'setup_project': return text(SETUP);
|
|
161
|
+
case 'check_link': {
|
|
162
|
+
const url = str(args.url) ?? '';
|
|
163
|
+
if (!/^https?:\/\//i.test(url))
|
|
164
|
+
return text('Give an http or https address.', true);
|
|
165
|
+
try {
|
|
166
|
+
return text(describe(await check(url)));
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
return text(`Could not check ${url}: ${e.message}`, true);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
default: return text(`No tool ${String(name)}.`, true);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** One message in, its answer out (null for a notification). */
|
|
176
|
+
export async function reply(m, version) {
|
|
177
|
+
if (m.id === undefined)
|
|
178
|
+
return null;
|
|
179
|
+
const ok = (result) => ({ jsonrpc: '2.0', id: m.id, result });
|
|
180
|
+
switch (m.method) {
|
|
181
|
+
case 'initialize': {
|
|
182
|
+
const asked = String(m.params?.protocolVersion ?? '');
|
|
183
|
+
return ok({ protocolVersion: VERSIONS.includes(asked) ? asked : VERSIONS[0], capabilities: { tools: {} }, serverInfo: { name: 'liveog', version }, instructions: INSTRUCTIONS });
|
|
184
|
+
}
|
|
185
|
+
case 'ping': return ok({});
|
|
186
|
+
case 'tools/list': return ok({ tools: TOOLS });
|
|
187
|
+
case 'tools/call':
|
|
188
|
+
try {
|
|
189
|
+
return ok(await call(m.params?.name, (m.params?.arguments ?? {})));
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
return ok(text(e.message, true));
|
|
193
|
+
}
|
|
194
|
+
default: return { jsonrpc: '2.0', id: m.id, error: { code: -32601, message: `No method ${m.method}` } };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
export function serve(version, input = process.stdin, output = process.stdout) {
|
|
198
|
+
createInterface({ input }).on('line', async (line) => {
|
|
199
|
+
if (!line.trim())
|
|
200
|
+
return;
|
|
201
|
+
let m;
|
|
202
|
+
try {
|
|
203
|
+
m = JSON.parse(line);
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
output.write(`${JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } })}\n`);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const out = await reply(m, version);
|
|
210
|
+
if (out)
|
|
211
|
+
output.write(`${JSON.stringify(out)}\n`);
|
|
212
|
+
});
|
|
213
|
+
}
|
package/dist/og.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** What a link's preview shows. `image` is an absolute address, or left out for none. */
|
|
2
|
+
export interface Card {
|
|
3
|
+
site: string;
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
image?: string;
|
|
7
|
+
/** The image's words for a screen reader; the title when left out. */
|
|
8
|
+
alt?: string;
|
|
9
|
+
}
|
|
10
|
+
/** The size the large cards are drawn at, width by height. */
|
|
11
|
+
export declare const COVER_SIZE: readonly [1200, 630];
|
|
12
|
+
/** Text made safe for HTML content or a quoted attribute. */
|
|
13
|
+
export declare const esc: (s: unknown) => string;
|
|
14
|
+
/** The meta tags for a card, one per line. */
|
|
15
|
+
export declare function tags(card: Card): string;
|
|
16
|
+
/** The page with the tags put in just before its </head>; the page as it was when it has none. */
|
|
17
|
+
export declare function inject(html: string, t: string): string;
|
|
18
|
+
/** A plain host (letters, digits, dots, hyphens, a port), lowercased, or null for anything else. */
|
|
19
|
+
export declare function cleanHost(x: unknown): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* The origin an image address is made absolute with: the public site when it is set and plain,
|
|
22
|
+
* else the Host a request came to when that is plain, else null. http for localhost only.
|
|
23
|
+
*/
|
|
24
|
+
export declare function originOf(host: unknown, site?: unknown): string | null;
|
package/dist/og.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The tags a chat app or a social site reads to show a link: Open Graph, and Twitter's large card.
|
|
2
|
+
/** The size the large cards are drawn at, width by height. */
|
|
3
|
+
export const COVER_SIZE = [1200, 630];
|
|
4
|
+
const ENTITY = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
5
|
+
/** Text made safe for HTML content or a quoted attribute. */
|
|
6
|
+
export const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ENTITY[c] ?? c);
|
|
7
|
+
/** The meta tags for a card, one per line. */
|
|
8
|
+
export function tags(card) {
|
|
9
|
+
const meta = (k, v, by = 'property') => `<meta ${by}="${k}" content="${esc(v)}">`;
|
|
10
|
+
const out = [
|
|
11
|
+
meta('og:type', 'website'),
|
|
12
|
+
meta('og:site_name', card.site),
|
|
13
|
+
meta('og:title', card.title),
|
|
14
|
+
meta('og:description', card.description),
|
|
15
|
+
meta('twitter:card', card.image ? 'summary_large_image' : 'summary', 'name'),
|
|
16
|
+
meta('twitter:title', card.title, 'name'),
|
|
17
|
+
meta('twitter:description', card.description, 'name'),
|
|
18
|
+
];
|
|
19
|
+
if (card.image) {
|
|
20
|
+
const alt = card.alt ?? card.title;
|
|
21
|
+
out.push(meta('og:image', card.image), meta('og:image:width', String(COVER_SIZE[0])), meta('og:image:height', String(COVER_SIZE[1])), meta('og:image:alt', alt), meta('twitter:image', card.image, 'name'), meta('twitter:image:alt', alt, 'name'));
|
|
22
|
+
}
|
|
23
|
+
return out.join('\n');
|
|
24
|
+
}
|
|
25
|
+
/** The page with the tags put in just before its </head>; the page as it was when it has none. */
|
|
26
|
+
export function inject(html, t) {
|
|
27
|
+
const at = html.search(/<\/head>/i);
|
|
28
|
+
return at < 0 ? html : `${html.slice(0, at)}${t}\n${html.slice(at)}`;
|
|
29
|
+
}
|
|
30
|
+
const HOST = /^[A-Za-z0-9.-]{1,253}(:[0-9]{1,5})?$/;
|
|
31
|
+
const LOCAL = /^(localhost|127\.0\.0\.1)(:|$)/i;
|
|
32
|
+
/** A plain host (letters, digits, dots, hyphens, a port), lowercased, or null for anything else. */
|
|
33
|
+
export function cleanHost(x) {
|
|
34
|
+
const h = String(x ?? '').trim().replace(/^https?:\/\//i, '').replace(/\/+$/, '');
|
|
35
|
+
return HOST.test(h) && !h.startsWith('.') && !h.startsWith('-') ? h.toLowerCase() : null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The origin an image address is made absolute with: the public site when it is set and plain,
|
|
39
|
+
* else the Host a request came to when that is plain, else null. http for localhost only.
|
|
40
|
+
*/
|
|
41
|
+
export function originOf(host, site) {
|
|
42
|
+
const h = cleanHost(site) ?? cleanHost(host);
|
|
43
|
+
return h ? `${LOCAL.test(h) ? 'http' : 'https'}://${h}` : null;
|
|
44
|
+
}
|
package/dist/study.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface Brief {
|
|
2
|
+
dir: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
homepage?: string;
|
|
6
|
+
/** Colours by how often they are used, with the custom property that names one when there is one. */
|
|
7
|
+
colors: {
|
|
8
|
+
value: string;
|
|
9
|
+
uses: number;
|
|
10
|
+
names: string[];
|
|
11
|
+
}[];
|
|
12
|
+
fonts: {
|
|
13
|
+
family: string;
|
|
14
|
+
uses: number;
|
|
15
|
+
}[];
|
|
16
|
+
/** Logo, mark and icon files. */
|
|
17
|
+
marks: string[];
|
|
18
|
+
/** Pages that already write og: or twitter: tags, and what they say. */
|
|
19
|
+
tagged: {
|
|
20
|
+
file: string;
|
|
21
|
+
tags: Record<string, string>;
|
|
22
|
+
}[];
|
|
23
|
+
/** Files that set previews in code (Next metadata, opengraph-image), to change rather than add to. */
|
|
24
|
+
previewFiles: string[];
|
|
25
|
+
/** Preview images already there. */
|
|
26
|
+
covers: string[];
|
|
27
|
+
/** Paths the project serves, as found in its routes. */
|
|
28
|
+
routes: string[];
|
|
29
|
+
}
|
|
30
|
+
/** Read a project and say what its covers could be made of. */
|
|
31
|
+
export declare function study(dir: string): Brief;
|
package/dist/study.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Reading a project for what its covers should look like and which links it has: its name, its
|
|
2
|
+
// colours, fonts and marks, the tags it already writes, and its routes. Plain file reads, bounded.
|
|
3
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
4
|
+
import { join, relative, sep } from 'node:path';
|
|
5
|
+
import { readTags } from './check.js';
|
|
6
|
+
const SKIP = new Set(['node_modules', '.git', 'dist', 'build', 'out', '.next', '.nuxt', '.svelte-kit', '.output', 'coverage', 'vendor', '.turbo', '.vercel', '.cache']);
|
|
7
|
+
const TEXT = /\.(css|scss|sass|less|html?|[cm]?[jt]sx?|svelte|vue|astro|svg)$/i;
|
|
8
|
+
const MAX_FILES = 3000;
|
|
9
|
+
const MAX_BYTES = 512 * 1024;
|
|
10
|
+
function walk(dir, depth = 0, out = []) {
|
|
11
|
+
if (depth > 8 || out.length >= MAX_FILES)
|
|
12
|
+
return out;
|
|
13
|
+
let names;
|
|
14
|
+
try {
|
|
15
|
+
names = readdirSync(dir).sort();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
for (const n of names) {
|
|
21
|
+
if (out.length >= MAX_FILES)
|
|
22
|
+
break;
|
|
23
|
+
if (SKIP.has(n) || (n.startsWith('.') && n !== '.github'))
|
|
24
|
+
continue;
|
|
25
|
+
const p = join(dir, n);
|
|
26
|
+
let s;
|
|
27
|
+
try {
|
|
28
|
+
s = statSync(p);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (s.isDirectory())
|
|
34
|
+
walk(p, depth + 1, out);
|
|
35
|
+
else
|
|
36
|
+
out.push(p);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
const bump = (m, k) => m.set(k, (m.get(k) ?? 0) + 1);
|
|
41
|
+
const norm = (c) => c.toLowerCase().replace(/\s+/g, ' ');
|
|
42
|
+
// a file's place as a route, for the frameworks that route by file (Next, SvelteKit, Astro, Nuxt), or null
|
|
43
|
+
function fileRoute(rel) {
|
|
44
|
+
const p = rel.split(sep).join('/');
|
|
45
|
+
const m = /(?:^|\/)(app|pages|routes|src\/pages)\/(.*)$/.exec(p);
|
|
46
|
+
if (!m?.[2])
|
|
47
|
+
return null;
|
|
48
|
+
let r = m[2];
|
|
49
|
+
if (m[1] === 'app' && !/(^|\/)page\.(tsx|jsx|ts|js|mdx)$/.test(r))
|
|
50
|
+
return null;
|
|
51
|
+
if (m[1] === 'routes' && !/(^|\/)\+page\.svelte$/.test(r))
|
|
52
|
+
return null;
|
|
53
|
+
if (/(^|\/)(_app|_document|_error|api\/|layout\.|\+layout)/.test(r))
|
|
54
|
+
return null;
|
|
55
|
+
r = r.replace(/(^|\/)(page|\+page|index)\.[a-z]+$/, '').replace(/\.(tsx|jsx|ts|js|mdx|astro|vue|svelte)$/, '');
|
|
56
|
+
r = r.replace(/\([^/)]*\)\/?/g, '').replace(/\/$/, '');
|
|
57
|
+
return `/${r}`;
|
|
58
|
+
}
|
|
59
|
+
/** Read a project and say what its covers could be made of. */
|
|
60
|
+
export function study(dir) {
|
|
61
|
+
const b = { dir, colors: [], fonts: [], marks: [], tagged: [], previewFiles: [], covers: [], routes: [] };
|
|
62
|
+
try {
|
|
63
|
+
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
64
|
+
for (const k of ['name', 'description', 'homepage'])
|
|
65
|
+
if (typeof pkg[k] === 'string')
|
|
66
|
+
b[k] = pkg[k];
|
|
67
|
+
}
|
|
68
|
+
catch { /* not a package */ }
|
|
69
|
+
const colors = new Map();
|
|
70
|
+
const names = new Map();
|
|
71
|
+
const fonts = new Map();
|
|
72
|
+
const routes = new Set();
|
|
73
|
+
for (const file of walk(dir)) {
|
|
74
|
+
const rel = relative(dir, file);
|
|
75
|
+
const r = fileRoute(rel);
|
|
76
|
+
if (r !== null)
|
|
77
|
+
routes.add(r);
|
|
78
|
+
if (/\.svg$/i.test(file)) {
|
|
79
|
+
if (/logo|mark|brand|icon|favicon/i.test(rel))
|
|
80
|
+
b.marks.push(rel);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (/\.(ico|png|jpe?g|webp)$/i.test(rel)) {
|
|
84
|
+
if (/(^|[/\\])(og|opengraph|twitter|social)[^/\\]*\.\w+$/i.test(rel))
|
|
85
|
+
b.covers.push(rel);
|
|
86
|
+
else if (/favicon|logo|icon|brand/i.test(rel))
|
|
87
|
+
b.marks.push(rel);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (/(^|[/\\])(opengraph|twitter)-image\.\w+$/.test(rel)) {
|
|
91
|
+
b.previewFiles.push(rel);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (!TEXT.test(file))
|
|
95
|
+
continue;
|
|
96
|
+
let t;
|
|
97
|
+
try {
|
|
98
|
+
if (statSync(file).size > MAX_BYTES)
|
|
99
|
+
continue;
|
|
100
|
+
t = readFileSync(file, 'utf8');
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (/export\s+(const\s+metadata\b|(async\s+)?function\s+generateMetadata)|\bopenGraph\s*:/.test(t))
|
|
106
|
+
b.previewFiles.push(rel);
|
|
107
|
+
// shadcn's bare HSL: --primary: 222.2 47.4% 11.2%;
|
|
108
|
+
for (const m of t.matchAll(/--([\w-]+)\s*:\s*([0-9.]{1,6}\s+[0-9.]{1,6}%\s+[0-9.]{1,6}%)\s*;/g)) {
|
|
109
|
+
if (!m[1] || !m[2])
|
|
110
|
+
continue;
|
|
111
|
+
const v = `hsl(${norm(m[2])})`;
|
|
112
|
+
bump(colors, v);
|
|
113
|
+
(names.get(v) ?? names.set(v, new Set()).get(v))?.add(`--${m[1]}`);
|
|
114
|
+
}
|
|
115
|
+
for (const m of t.matchAll(/import\s*\{([^}]{1,300})\}\s*from\s*['"]next\/font\/google['"]/g))
|
|
116
|
+
for (const f of (m[1] ?? '').split(',')) {
|
|
117
|
+
const n = f.trim().split(/\s+as\s+/)[0]?.trim();
|
|
118
|
+
if (n)
|
|
119
|
+
bump(fonts, n.replace(/_/g, ' '));
|
|
120
|
+
}
|
|
121
|
+
if (/next\/font\/local|@font-face/.test(t))
|
|
122
|
+
for (const m of t.matchAll(/['"(]([^'"()]*?([^/'"()]+)\.(?:woff2?|ttf|otf))['")]/g))
|
|
123
|
+
if (m[2])
|
|
124
|
+
bump(fonts, `${m[2]} (file)`);
|
|
125
|
+
for (const m of t.matchAll(/--([\w-]+)\s*:\s*(#[0-9a-fA-F]{3,8}\b|(?:rgba?|hsla?|oklch|oklab)\([^)]{1,60}\))/g)) {
|
|
126
|
+
if (!m[1] || !m[2])
|
|
127
|
+
continue;
|
|
128
|
+
const v = norm(m[2]);
|
|
129
|
+
if (!v.startsWith('#') || !/\.(css|scss|sass|less|html?|svelte|vue|astro)$/i.test(file))
|
|
130
|
+
bump(colors, v); // a hex there is counted below
|
|
131
|
+
(names.get(v) ?? names.set(v, new Set()).get(v))?.add(`--${m[1]}`);
|
|
132
|
+
}
|
|
133
|
+
if (/\.(css|scss|sass|less|html?|svelte|vue|astro)$/i.test(file) || /tailwind\.config/.test(file))
|
|
134
|
+
for (const m of t.matchAll(/#[0-9a-fA-F]{6}\b|#[0-9a-fA-F]{3}\b/g))
|
|
135
|
+
bump(colors, norm(m[0]));
|
|
136
|
+
for (const m of t.matchAll(/font-family\s*:\s*([^;}{]{1,200})/g))
|
|
137
|
+
if (m[1])
|
|
138
|
+
bump(fonts, m[1].trim().replace(/\s*!important$/, ''));
|
|
139
|
+
for (const m of t.matchAll(/fonts\.googleapis\.com\/css2?\?family=([^"'&:]+)/g))
|
|
140
|
+
if (m[1])
|
|
141
|
+
bump(fonts, decodeURIComponent(m[1].replace(/\+/g, ' ')));
|
|
142
|
+
for (const m of t.matchAll(/\b(?:app|router|server)\.(?:get|all|route)\(\s*['"`](\/[^'"`]{0,100})/g))
|
|
143
|
+
if (m[1])
|
|
144
|
+
routes.add(m[1]);
|
|
145
|
+
if (/\.html?$/i.test(file) || /(^|\/)(layout|_document|_app|head)\.[jt]sx?$/.test(rel)) {
|
|
146
|
+
const tags = readTags(t);
|
|
147
|
+
if (Object.keys(tags).length)
|
|
148
|
+
b.tagged.push({ file: rel, tags });
|
|
149
|
+
}
|
|
150
|
+
if (/\.html?$/i.test(file) && r === null)
|
|
151
|
+
routes.add(`/${rel.split(sep).join('/').replace(/(^|\/)index\.html?$/, '').replace(/\.html?$/, '')}`);
|
|
152
|
+
}
|
|
153
|
+
b.colors = [...colors].sort((x, y) => y[1] - x[1]).slice(0, 16).map(([value, uses]) => ({ value, uses, names: [...(names.get(value) ?? [])].slice(0, 4) }));
|
|
154
|
+
b.fonts = [...fonts].sort((x, y) => y[1] - x[1]).slice(0, 6).map(([family, uses]) => ({ family, uses }));
|
|
155
|
+
b.marks = b.marks.slice(0, 12);
|
|
156
|
+
b.tagged = b.tagged.slice(0, 8);
|
|
157
|
+
b.previewFiles = b.previewFiles.slice(0, 20);
|
|
158
|
+
b.covers = b.covers.slice(0, 12);
|
|
159
|
+
b.routes = [...routes].sort().slice(0, 60);
|
|
160
|
+
return b;
|
|
161
|
+
}
|