@robosystems/core 0.19.0 → 0.20.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 -0
- package/docs/DocsMarkdown.d.ts +5 -0
- package/docs/DocsMarkdown.js +56 -0
- package/docs/catalog.d.ts +86 -0
- package/docs/catalog.js +141 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ Shared React core for the RoboSystems ecosystem apps — authentication, platfor
|
|
|
11
11
|
- **Contexts** — graph, entity, organization, service-offerings, and sidebar state
|
|
12
12
|
- **Task monitoring** — SSE-based operation monitoring with a polling fallback for long-running jobs
|
|
13
13
|
- **UI components** — layout, chat, forms, settings, API keys, and the shared Tailwind theme and the owned UI primitives (`@robosystems/core/ui`)
|
|
14
|
+
- **Docs rendering** — the docs catalog loader (`@robosystems/core/docs/catalog`) and the markdown renderer (`@robosystems/core/docs/DocsMarkdown`), server-side, for each app's `/docs`
|
|
14
15
|
- **Hooks & utilities** — user, limits, toast, and media-query hooks plus cookie persistence helpers
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
@@ -30,6 +31,7 @@ import { AuthProvider, useGraphContext } from '@robosystems/core'
|
|
|
30
31
|
import { Button, Modal } from '@robosystems/core/ui'
|
|
31
32
|
import { PageHeader, Spinner } from '@robosystems/core/ui-components'
|
|
32
33
|
import { useToast } from '@robosystems/core/hooks/use-toast'
|
|
34
|
+
import { getDocsCatalog } from '@robosystems/core/docs/catalog'
|
|
33
35
|
```
|
|
34
36
|
|
|
35
37
|
## Resources
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import Link from 'next/link';
|
|
14
|
+
import ReactMarkdown from 'react-markdown';
|
|
15
|
+
import rehypeSlug from 'rehype-slug';
|
|
16
|
+
import remarkGfm from 'remark-gfm';
|
|
17
|
+
// GitHub-flavored markdown, rendered on the server. The bodies are never compiled as
|
|
18
|
+
// MDX and raw HTML is not interpreted, so the literal `{` and `<` throughout the technical
|
|
19
|
+
// docs' prose stay text. rehype-slug gives headings GitHub's ids, which the docs' anchor
|
|
20
|
+
// links and tableOfContents() both rely on.
|
|
21
|
+
function DocsLink(_a) {
|
|
22
|
+
var { href = '', children } = _a, rest = __rest(_a, ["href", "children"]);
|
|
23
|
+
if (href.startsWith('/')) {
|
|
24
|
+
return _jsx(Link, { href: href, children: children });
|
|
25
|
+
}
|
|
26
|
+
if (href.startsWith('#')) {
|
|
27
|
+
return (_jsx("a", Object.assign({ href: href }, rest, { children: children })));
|
|
28
|
+
}
|
|
29
|
+
return (_jsx("a", Object.assign({ href: href, target: "_blank", rel: "noopener noreferrer" }, rest, { children: children })));
|
|
30
|
+
}
|
|
31
|
+
function DocsTable(props) {
|
|
32
|
+
return (_jsx("div", { className: "overflow-x-auto", children: _jsx("table", Object.assign({}, props)) }));
|
|
33
|
+
}
|
|
34
|
+
// Markdown image syntax is the one way a page shows media, so the file decides what
|
|
35
|
+
// it renders as: a clip plays, a YouTube link embeds, anything else is a picture.
|
|
36
|
+
// Screenshots of the app are dark on a dark page, so each one gets a frame, and it
|
|
37
|
+
// opens full size because the column shows it at about half. Everything here is
|
|
38
|
+
// phrasing content, because markdown puts an image inside a paragraph.
|
|
39
|
+
const VIDEO_FILE = /\.(mp4|webm)(?:[?#]|$)/i;
|
|
40
|
+
const YOUTUBE = /^https:\/\/(?:www\.youtube\.com\/watch\?(?:.*&)?v=|youtu\.be\/)([\w-]{11})/;
|
|
41
|
+
const FRAME = 'my-8 block w-full rounded-lg border border-gray-700';
|
|
42
|
+
export function DocsImage({ src, alt = '', title }) {
|
|
43
|
+
if (typeof src !== 'string' || !src)
|
|
44
|
+
return null;
|
|
45
|
+
const youtube = YOUTUBE.exec(src);
|
|
46
|
+
if (youtube) {
|
|
47
|
+
return (_jsx("iframe", { src: `https://www.youtube.com/embed/${youtube[1]}`, title: alt || title || 'Video', allow: "encrypted-media; picture-in-picture; fullscreen", loading: "lazy", className: `${FRAME} aspect-video` }));
|
|
48
|
+
}
|
|
49
|
+
if (VIDEO_FILE.test(src)) {
|
|
50
|
+
return (_jsx("video", { src: src, title: title, "aria-label": alt, controls: true, muted: true, playsInline: true, preload: "metadata", className: FRAME, children: _jsx("a", { href: src, children: alt || 'Download the video' }) }));
|
|
51
|
+
}
|
|
52
|
+
return (_jsx("a", { href: src, target: "_blank", rel: "noopener noreferrer", title: "Open full size", className: "not-prose block cursor-zoom-in", children: _jsx("img", { src: src, alt: alt, title: title, loading: "lazy", decoding: "async", className: `${FRAME} h-auto` }) }));
|
|
53
|
+
}
|
|
54
|
+
export function DocsMarkdown({ children }) {
|
|
55
|
+
return (_jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], rehypePlugins: [rehypeSlug], components: { a: DocsLink, img: DocsImage, table: DocsTable }, children: children }));
|
|
56
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export declare const DOCS_CATALOG_URL: string;
|
|
2
|
+
export declare const DOCS_REVALIDATE_SECONDS = 300;
|
|
3
|
+
export type DocsLayer = 'technical' | 'product';
|
|
4
|
+
export interface DocsPage {
|
|
5
|
+
site: string;
|
|
6
|
+
layer: DocsLayer;
|
|
7
|
+
slug: string;
|
|
8
|
+
path: string;
|
|
9
|
+
title: string;
|
|
10
|
+
description: string;
|
|
11
|
+
section: string | null;
|
|
12
|
+
order: number;
|
|
13
|
+
updated: string | null;
|
|
14
|
+
body: string;
|
|
15
|
+
source_url: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DocsSection {
|
|
18
|
+
title: string | null;
|
|
19
|
+
slugs: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface DocsCollection {
|
|
22
|
+
site: string;
|
|
23
|
+
layer: DocsLayer;
|
|
24
|
+
base_path: string;
|
|
25
|
+
sections: DocsSection[];
|
|
26
|
+
}
|
|
27
|
+
export interface DocsCatalog {
|
|
28
|
+
schema_version: number;
|
|
29
|
+
digest: string;
|
|
30
|
+
collections: DocsCollection[];
|
|
31
|
+
pages: DocsPage[];
|
|
32
|
+
}
|
|
33
|
+
/** A collection's pages grouped the way its sidebar shows them, index page first. */
|
|
34
|
+
export interface DocsNav {
|
|
35
|
+
collection: DocsCollection;
|
|
36
|
+
index: DocsPage | undefined;
|
|
37
|
+
sections: {
|
|
38
|
+
title: string | null;
|
|
39
|
+
pages: DocsPage[];
|
|
40
|
+
}[];
|
|
41
|
+
ordered: DocsPage[];
|
|
42
|
+
}
|
|
43
|
+
export interface TocHeading {
|
|
44
|
+
depth: number;
|
|
45
|
+
text: string;
|
|
46
|
+
id: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The docs catalog. Throws when it cannot be read: a page regenerating during a CDN blip
|
|
50
|
+
* then keeps its last good render instead of caching a 404. Callers that can do without
|
|
51
|
+
* it (the sitemap, build-time params) catch.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getDocsCatalog(): Promise<DocsCatalog>;
|
|
54
|
+
export declare function getDocsNav(catalog: DocsCatalog, site: string, layer: DocsLayer): DocsNav | null;
|
|
55
|
+
export declare function findDocsPage(nav: DocsNav, slug: string): DocsPage | undefined;
|
|
56
|
+
/** The pages before and after one, in sidebar order. */
|
|
57
|
+
export declare function docsNeighbors(nav: DocsNav, slug: string): {
|
|
58
|
+
previous?: DocsPage;
|
|
59
|
+
next?: DocsPage;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A page's markdown body. Body keys are relative to the catalog's own URL. Throws when the
|
|
63
|
+
* body cannot be read, for the same reason as `getDocsCatalog`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function getDocsBody(page: DocsPage): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* For a read a page cannot do without at build. A catalog read throws when the CDN fails,
|
|
68
|
+
* which keeps the last good render at runtime; at build there is none to keep, and a throw
|
|
69
|
+
* would fail the whole build (a fork or offline build has no CDN at all), so the build falls
|
|
70
|
+
* back to an empty page that the first regeneration replaces.
|
|
71
|
+
*/
|
|
72
|
+
export declare function orBuildFallback<T>(read: Promise<T>, fallback: T): Promise<T>;
|
|
73
|
+
/** The newest `updated` date across pages, or none. */
|
|
74
|
+
export declare function latestUpdate(pages: DocsPage[]): Date | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Whether a description only restates the body's opening. The publisher derives a
|
|
77
|
+
* description from the first paragraph when a page has none, so showing it above the
|
|
78
|
+
* body would print the same sentence twice.
|
|
79
|
+
*/
|
|
80
|
+
export declare function descriptionRepeatsBody(description: string, body: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The page's H2 and H3 headings with the ids rehype-slug gives them. Every heading is
|
|
83
|
+
* slugged in document order, so repeated titles get the same `-1` suffixes the rendered
|
|
84
|
+
* page does; fenced code is skipped.
|
|
85
|
+
*/
|
|
86
|
+
export declare function tableOfContents(markdown: string): TocHeading[];
|
package/docs/catalog.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Docs catalog access. The catalog is built by the robosystems repo's Publish Docs workflow
|
|
2
|
+
// (robosystems/scripts/publish_docs.py) from two folders, docs/technical/ (technical docs)
|
|
3
|
+
// and docs/product/{site}/ (product pages), and served from the content CDN as one
|
|
4
|
+
// index.json plus a markdown body per page. Fetched server-side with ISR, so every docs
|
|
5
|
+
// page is real HTML for crawlers.
|
|
6
|
+
//
|
|
7
|
+
// All three apps read the one catalog: each page carries a `site` and a `layer`, and each
|
|
8
|
+
// app renders its own by passing its site to getDocsNav.
|
|
9
|
+
import GithubSlugger from 'github-slugger';
|
|
10
|
+
export const DOCS_CATALOG_URL = process.env.NEXT_PUBLIC_DOCS_CATALOG_URL ||
|
|
11
|
+
'https://assets.robosystems.ai/docs/index.json';
|
|
12
|
+
export const DOCS_REVALIDATE_SECONDS = 300;
|
|
13
|
+
/**
|
|
14
|
+
* The docs catalog. Throws when it cannot be read: a page regenerating during a CDN blip
|
|
15
|
+
* then keeps its last good render instead of caching a 404. Callers that can do without
|
|
16
|
+
* it (the sitemap, build-time params) catch.
|
|
17
|
+
*/
|
|
18
|
+
export async function getDocsCatalog() {
|
|
19
|
+
const res = await fetch(DOCS_CATALOG_URL, {
|
|
20
|
+
next: { revalidate: DOCS_REVALIDATE_SECONDS },
|
|
21
|
+
});
|
|
22
|
+
if (!res.ok)
|
|
23
|
+
throw new Error(`Docs catalog fetch failed: ${res.status}`);
|
|
24
|
+
return (await res.json());
|
|
25
|
+
}
|
|
26
|
+
export function getDocsNav(catalog, site, layer) {
|
|
27
|
+
const collection = catalog.collections.find((c) => c.site === site && c.layer === layer);
|
|
28
|
+
if (!collection)
|
|
29
|
+
return null;
|
|
30
|
+
const pages = new Map(catalog.pages
|
|
31
|
+
.filter((p) => p.site === site && p.layer === layer)
|
|
32
|
+
.map((p) => [p.slug, p]));
|
|
33
|
+
const sections = collection.sections
|
|
34
|
+
.map((s) => ({
|
|
35
|
+
title: s.title,
|
|
36
|
+
pages: s.slugs
|
|
37
|
+
.filter((slug) => slug !== 'index')
|
|
38
|
+
.map((slug) => pages.get(slug))
|
|
39
|
+
.filter((p) => !!p),
|
|
40
|
+
}))
|
|
41
|
+
.filter((s) => s.pages.length > 0);
|
|
42
|
+
const index = pages.get('index');
|
|
43
|
+
const ordered = [
|
|
44
|
+
...(index ? [index] : []),
|
|
45
|
+
...sections.flatMap((s) => s.pages),
|
|
46
|
+
];
|
|
47
|
+
return { collection, index, sections, ordered };
|
|
48
|
+
}
|
|
49
|
+
export function findDocsPage(nav, slug) {
|
|
50
|
+
return nav.ordered.find((p) => p.slug === slug);
|
|
51
|
+
}
|
|
52
|
+
/** The pages before and after one, in sidebar order. */
|
|
53
|
+
export function docsNeighbors(nav, slug) {
|
|
54
|
+
const i = nav.ordered.findIndex((p) => p.slug === slug);
|
|
55
|
+
if (i === -1)
|
|
56
|
+
return {};
|
|
57
|
+
return { previous: nav.ordered[i - 1], next: nav.ordered[i + 1] };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A page's markdown body. Body keys are relative to the catalog's own URL. Throws when the
|
|
61
|
+
* body cannot be read, for the same reason as `getDocsCatalog`.
|
|
62
|
+
*/
|
|
63
|
+
export async function getDocsBody(page) {
|
|
64
|
+
const res = await fetch(new URL(page.body, DOCS_CATALOG_URL), {
|
|
65
|
+
next: { revalidate: DOCS_REVALIDATE_SECONDS },
|
|
66
|
+
});
|
|
67
|
+
if (!res.ok) {
|
|
68
|
+
throw new Error(`Docs body fetch failed for ${page.path}: ${res.status}`);
|
|
69
|
+
}
|
|
70
|
+
return await res.text();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* For a read a page cannot do without at build. A catalog read throws when the CDN fails,
|
|
74
|
+
* which keeps the last good render at runtime; at build there is none to keep, and a throw
|
|
75
|
+
* would fail the whole build (a fork or offline build has no CDN at all), so the build falls
|
|
76
|
+
* back to an empty page that the first regeneration replaces.
|
|
77
|
+
*/
|
|
78
|
+
export async function orBuildFallback(read, fallback) {
|
|
79
|
+
if (process.env.NEXT_PHASE !== 'phase-production-build')
|
|
80
|
+
return read;
|
|
81
|
+
return read.catch((error) => {
|
|
82
|
+
console.warn('Content catalog unreachable during build:', error);
|
|
83
|
+
return fallback;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** The newest `updated` date across pages, or none. */
|
|
87
|
+
export function latestUpdate(pages) {
|
|
88
|
+
const times = pages
|
|
89
|
+
.map((p) => (p.updated ? new Date(p.updated).getTime() : NaN))
|
|
90
|
+
.filter((t) => !Number.isNaN(t));
|
|
91
|
+
return times.length ? new Date(Math.max(...times)) : undefined;
|
|
92
|
+
}
|
|
93
|
+
/** Heading text as a reader sees it: inline code, emphasis and link syntax removed. */
|
|
94
|
+
function headingText(markdown) {
|
|
95
|
+
return markdown
|
|
96
|
+
.replace(/!\[[^\]]*\]\([^)]*\)/g, '')
|
|
97
|
+
.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
98
|
+
.replace(/`([^`]*)`/g, '$1')
|
|
99
|
+
.replace(/(\*\*|__)(.+?)\1/g, '$2')
|
|
100
|
+
.replace(/(^|\W)[*_](\S.*?\S|\S)[*_](?=\W|$)/g, '$1$2')
|
|
101
|
+
.trim();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Whether a description only restates the body's opening. The publisher derives a
|
|
105
|
+
* description from the first paragraph when a page has none, so showing it above the
|
|
106
|
+
* body would print the same sentence twice.
|
|
107
|
+
*/
|
|
108
|
+
export function descriptionRepeatsBody(description, body) {
|
|
109
|
+
const plain = (text) => headingText(text.replace(/…$/, '')).replace(/\s+/g, ' ').trim();
|
|
110
|
+
const opening = plain(description).slice(0, 60);
|
|
111
|
+
return opening.length > 0 && plain(body.trimStart()).startsWith(opening);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The page's H2 and H3 headings with the ids rehype-slug gives them. Every heading is
|
|
115
|
+
* slugged in document order, so repeated titles get the same `-1` suffixes the rendered
|
|
116
|
+
* page does; fenced code is skipped.
|
|
117
|
+
*/
|
|
118
|
+
export function tableOfContents(markdown) {
|
|
119
|
+
var _a;
|
|
120
|
+
const slugger = new GithubSlugger();
|
|
121
|
+
const headings = [];
|
|
122
|
+
let fence = null;
|
|
123
|
+
for (const line of markdown.split('\n')) {
|
|
124
|
+
const marker = (_a = /^\s*(```|~~~)/.exec(line)) === null || _a === void 0 ? void 0 : _a[1];
|
|
125
|
+
if (marker) {
|
|
126
|
+
fence = fence === null ? marker : fence === marker ? null : fence;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (fence)
|
|
130
|
+
continue;
|
|
131
|
+
const match = /^(#{1,6})\s+(.+?)\s*#*\s*$/.exec(line);
|
|
132
|
+
if (!match)
|
|
133
|
+
continue;
|
|
134
|
+
const text = headingText(match[2]);
|
|
135
|
+
const id = slugger.slug(text);
|
|
136
|
+
const depth = match[1].length;
|
|
137
|
+
if (depth === 2 || depth === 3)
|
|
138
|
+
headings.push({ depth, text, id });
|
|
139
|
+
}
|
|
140
|
+
return headings;
|
|
141
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robosystems/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Shared RoboSystems frontend core library (auth, contexts, task monitoring, UI components) for the RoboSystems Next.js apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@floating-ui/react": "^0.27.20",
|
|
26
|
+
"github-slugger": "^2.0.0",
|
|
26
27
|
"react-markdown": "^10",
|
|
28
|
+
"rehype-slug": "^6.0.0",
|
|
27
29
|
"remark-gfm": "^4.0.1",
|
|
28
30
|
"tailwind-merge": "^3"
|
|
29
31
|
},
|