@openlegion/platform 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +1189 -2
- package/dist/body.d.ts +9 -0
- package/dist/body.js +28 -0
- package/dist/chat-history.d.ts +53 -0
- package/dist/chat-history.js +11 -0
- package/dist/client.d.ts +217 -0
- package/dist/client.js +367 -0
- package/dist/core.d.ts +47 -0
- package/dist/core.js +1 -0
- package/dist/crypto.d.ts +25 -0
- package/dist/crypto.js +81 -0
- package/dist/errors.d.ts +111 -0
- package/dist/errors.js +134 -0
- package/dist/events.d.ts +131 -0
- package/dist/events.js +5 -0
- package/dist/generated/api.d.ts +5505 -0
- package/dist/generated/api.js +446 -0
- package/dist/handler.d.ts +201 -0
- package/dist/handler.js +682 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +12 -0
- package/dist/kit-agents.d.ts +95 -0
- package/dist/kit-agents.js +280 -0
- package/dist/kit-codes.d.ts +279 -0
- package/dist/kit-codes.js +44 -0
- package/dist/kit-connections.d.ts +21 -0
- package/dist/kit-connections.js +189 -0
- package/dist/kit-files.d.ts +8 -0
- package/dist/kit-files.js +117 -0
- package/dist/kit-model-keys.d.ts +8 -0
- package/dist/kit-model-keys.js +86 -0
- package/dist/kit-threads.d.ts +3 -0
- package/dist/kit-threads.js +92 -0
- package/dist/kit-tools.d.ts +21 -0
- package/dist/kit-tools.js +47 -0
- package/dist/kit.d.ts +130 -0
- package/dist/kit.js +155 -0
- package/dist/mcp-server.d.ts +27 -0
- package/dist/mcp-server.js +166 -0
- package/dist/next.d.ts +24 -0
- package/dist/next.js +6 -0
- package/dist/ol-signed.d.ts +82 -0
- package/dist/ol-signed.js +115 -0
- package/dist/react/add-server.d.ts +90 -0
- package/dist/react/add-server.js +183 -0
- package/dist/react/agent-chat.d.ts +925 -0
- package/dist/react/agent-chat.js +1917 -0
- package/dist/react/agent-editor.d.ts +133 -0
- package/dist/react/agent-editor.js +222 -0
- package/dist/react/agent-kit.d.ts +160 -0
- package/dist/react/agent-kit.js +279 -0
- package/dist/react/agent-list.d.ts +247 -0
- package/dist/react/agent-list.js +248 -0
- package/dist/react/approval-card.d.ts +272 -0
- package/dist/react/approval-card.js +372 -0
- package/dist/react/artifact-card.d.ts +38 -0
- package/dist/react/artifact-card.js +39 -0
- package/dist/react/avatar.d.ts +21 -0
- package/dist/react/avatar.js +33 -0
- package/dist/react/card-ledger.d.ts +30 -0
- package/dist/react/card-ledger.js +49 -0
- package/dist/react/chat-timing.d.ts +121 -0
- package/dist/react/chat-timing.js +229 -0
- package/dist/react/computer-view.d.ts +309 -0
- package/dist/react/computer-view.js +543 -0
- package/dist/react/computer-viewer.d.ts +175 -0
- package/dist/react/computer-viewer.js +555 -0
- package/dist/react/computer-wire.d.ts +178 -0
- package/dist/react/computer-wire.js +244 -0
- package/dist/react/connect-button.d.ts +145 -0
- package/dist/react/connect-button.js +212 -0
- package/dist/react/connection-request.d.ts +16 -0
- package/dist/react/connection-request.js +18 -0
- package/dist/react/connections-list.d.ts +90 -0
- package/dist/react/connections-list.js +76 -0
- package/dist/react/errors.d.ts +250 -0
- package/dist/react/errors.js +146 -0
- package/dist/react/files.d.ts +41 -0
- package/dist/react/files.js +78 -0
- package/dist/react/index.d.ts +35 -0
- package/dist/react/index.js +26 -0
- package/dist/react/limit-words.d.ts +80 -0
- package/dist/react/limit-words.js +53 -0
- package/dist/react/markdown.d.ts +42 -0
- package/dist/react/markdown.js +56 -0
- package/dist/react/md-parse.d.ts +106 -0
- package/dist/react/md-parse.js +638 -0
- package/dist/react/model-keys-card.d.ts +94 -0
- package/dist/react/model-keys-card.js +123 -0
- package/dist/react/reload.d.ts +211 -0
- package/dist/react/reload.js +339 -0
- package/dist/react/reveal.d.ts +17 -0
- package/dist/react/reveal.js +22 -0
- package/dist/react/schedule-editor.d.ts +107 -0
- package/dist/react/schedule-editor.js +172 -0
- package/dist/react/schedule-time.d.ts +66 -0
- package/dist/react/schedule-time.js +90 -0
- package/dist/react/styles.css +1274 -0
- package/dist/react/transport.d.ts +49 -0
- package/dist/react/transport.js +380 -0
- package/dist/react/use-connections.d.ts +155 -0
- package/dist/react/use-connections.js +231 -0
- package/dist/react/use-model-keys.d.ts +47 -0
- package/dist/react/use-model-keys.js +57 -0
- package/dist/react/use-threads.d.ts +63 -0
- package/dist/react/use-threads.js +73 -0
- package/dist/react/vault-form.d.ts +92 -0
- package/dist/react/vault-form.js +151 -0
- package/dist/schema.d.ts +47 -0
- package/dist/schema.js +16 -0
- package/dist/secrets.d.ts +15 -0
- package/dist/secrets.js +18 -0
- package/dist/stream.d.ts +129 -0
- package/dist/stream.js +192 -0
- package/dist/testing.d.ts +33 -0
- package/dist/testing.js +40 -0
- package/dist/webhooks.d.ts +31 -0
- package/dist/webhooks.js +72 -0
- package/package.json +85 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A SPENDING LIMIT THAT REFUSED A PERSON'S MESSAGE, IN THEIR OWN TIME (RUN16 (A), the kit's half).
|
|
3
|
+
*
|
|
4
|
+
* The platform names the limit on a `cap_reached` refusal: `limit {cap, why, resets_at}` on the 402's
|
|
5
|
+
* `error.limit`, on the `data-refusal` part's `data.limit` and on the run's `error.limit`. Its own `message` says the
|
|
6
|
+
* time in the workspace's zone, named ("at 7:00 PM EST"), because a server can't know the reader's. `<AgentChat>`
|
|
7
|
+
* says it in the browser's zone, with the platform's signed-off words:
|
|
8
|
+
*
|
|
9
|
+
* - used up: "You've used today's limit. It resets at 7:00 PM."
|
|
10
|
+
* - too small: "What's left of today's limit isn't enough for this request. It resets at 7:00 PM."
|
|
11
|
+
* - read after the reset (a reload later): "Today's limit has reset. Send it again."
|
|
12
|
+
*
|
|
13
|
+
* The same for your monthly limit (`period`) and this assistant's daily limit (`agent_daily`, a trailing 24 hours).
|
|
14
|
+
* White-label: no credits, runs or numbers. Every word is a label; the partner's `labels.refusals.cap_reached`, when
|
|
15
|
+
* given, replaces the whole sentence.
|
|
16
|
+
*/
|
|
17
|
+
export type KitLimitCap = "daily" | "period" | "agent_daily";
|
|
18
|
+
/** A `cap_reached` refusal's limit, as the kit reads it from the wire. */
|
|
19
|
+
export interface KitLimit {
|
|
20
|
+
cap: KitLimitCap;
|
|
21
|
+
/** `used_up`: nothing usable is left. `too_small`: something is, but less than this request needs. */
|
|
22
|
+
why: "used_up" | "too_small";
|
|
23
|
+
/** When it resets (RFC 3339), or null when the platform doesn't know. */
|
|
24
|
+
resetsAt: string | null;
|
|
25
|
+
}
|
|
26
|
+
/** Every word of the limit's sentence. `{limit}`, `{Limit}` (its first letter upper-case), `{when}`, `{time}` and `{date}` are replaced. */
|
|
27
|
+
export interface LimitLabels {
|
|
28
|
+
/** Each limit's name, as it reads inside a sentence. */
|
|
29
|
+
names: Record<KitLimitCap, string>;
|
|
30
|
+
usedUp: string;
|
|
31
|
+
tooSmall: string;
|
|
32
|
+
/** After either, when the reset time is known. */
|
|
33
|
+
resets: string;
|
|
34
|
+
/** In place of both, once the reset time has passed. */
|
|
35
|
+
hasReset: string;
|
|
36
|
+
/** `{when}` for a time later today, the midnight that ends today, tomorrow, and a later date. */
|
|
37
|
+
today: string;
|
|
38
|
+
midnight: string;
|
|
39
|
+
tomorrow: string;
|
|
40
|
+
later: string;
|
|
41
|
+
/**
|
|
42
|
+
* Your line under the sentence, as a link: "You can raise your limit in Settings." Only you know whether the
|
|
43
|
+
* person may raise anything (a person's own key can't set limits), so there is none unless you give it.
|
|
44
|
+
*/
|
|
45
|
+
raise?: {
|
|
46
|
+
text: string;
|
|
47
|
+
href: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
}
|
|
50
|
+
export declare const DEFAULT_LIMIT_LABELS: Omit<LimitLabels, "raise">;
|
|
51
|
+
/** Your words for the limit, any of them: the rest stay ours. */
|
|
52
|
+
export type LimitLabelsInput = Partial<Omit<LimitLabels, "names">> & {
|
|
53
|
+
names?: Partial<Record<KitLimitCap, string>> | undefined;
|
|
54
|
+
};
|
|
55
|
+
/** The wire's `limit` (`{cap, why, resets_at}`), read whole or not at all. */
|
|
56
|
+
export declare function limitOf(raw: unknown): KitLimit | null;
|
|
57
|
+
/**
|
|
58
|
+
* The person's sentence for a limit that refused their message, as of `now`, in the browser's zone and locale
|
|
59
|
+
* (`opts` for your tests, or to pin them).
|
|
60
|
+
*/
|
|
61
|
+
export declare function limitWords(limit: KitLimit, labels?: LimitLabelsInput, now?: Date, opts?: {
|
|
62
|
+
locale?: string | undefined;
|
|
63
|
+
timeZone?: string | undefined;
|
|
64
|
+
}): string;
|
|
65
|
+
/**
|
|
66
|
+
* A refusal's sentence: the partner's for its code first (`labels.refusals`); else, for a cap with its limit, the
|
|
67
|
+
* kit's words in the browser's zone, but only once the page is live (`live`): drawn on a server, the time would be
|
|
68
|
+
* the server's zone, unnamed, so it is the platform's sentence, which names its zone. Else the platform's.
|
|
69
|
+
*/
|
|
70
|
+
export declare function refusalWords(r: {
|
|
71
|
+
code: string | null;
|
|
72
|
+
message: string | null;
|
|
73
|
+
limit?: KitLimit | null | undefined;
|
|
74
|
+
}, labels: {
|
|
75
|
+
refusals?: Partial<Record<string, string>> | undefined;
|
|
76
|
+
limits?: LimitLabelsInput | undefined;
|
|
77
|
+
}, live: boolean, now?: Date, opts?: {
|
|
78
|
+
locale?: string | undefined;
|
|
79
|
+
timeZone?: string | undefined;
|
|
80
|
+
}): string | null;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { errorLimitOf } from "../errors.js";
|
|
2
|
+
import { timeOfDay } from "./schedule-time.js";
|
|
3
|
+
export const DEFAULT_LIMIT_LABELS = {
|
|
4
|
+
names: { daily: "today's limit", period: "your monthly limit", agent_daily: "this assistant's daily limit" },
|
|
5
|
+
usedUp: "You've used {limit}.",
|
|
6
|
+
tooSmall: "What's left of {limit} isn't enough for this request.",
|
|
7
|
+
resets: "It resets {when}.",
|
|
8
|
+
hasReset: "{Limit} has reset. Send it again.",
|
|
9
|
+
today: "at {time}",
|
|
10
|
+
midnight: "at midnight",
|
|
11
|
+
tomorrow: "tomorrow at {time}",
|
|
12
|
+
later: "on {date} at {time}",
|
|
13
|
+
};
|
|
14
|
+
export function limitOf(raw) {
|
|
15
|
+
const l = errorLimitOf(raw);
|
|
16
|
+
return l ? { cap: l.cap, why: l.why, resetsAt: l.resets_at } : null;
|
|
17
|
+
}
|
|
18
|
+
function dayOf(at, timeZone) {
|
|
19
|
+
const ymd = new Intl.DateTimeFormat("en-CA", { timeZone, year: "numeric", month: "2-digit", day: "2-digit" }).format(at);
|
|
20
|
+
return Math.round(Date.parse(`${ymd}T00:00:00Z`) / 86_400_000);
|
|
21
|
+
}
|
|
22
|
+
function whenWords(at, now, l, o) {
|
|
23
|
+
const days = dayOf(at, o.timeZone) - dayOf(now, o.timeZone);
|
|
24
|
+
const clock = new Intl.DateTimeFormat("en-US", { timeZone: o.timeZone, hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).format(at);
|
|
25
|
+
if (days === 1 && clock === "00:00")
|
|
26
|
+
return l.midnight;
|
|
27
|
+
const time = timeOfDay(at, o);
|
|
28
|
+
if (days <= 0)
|
|
29
|
+
return l.today.replaceAll("{time}", time);
|
|
30
|
+
if (days === 1)
|
|
31
|
+
return l.tomorrow.replaceAll("{time}", time);
|
|
32
|
+
const date = new Intl.DateTimeFormat(o.locale, { timeZone: o.timeZone, month: "long", day: "numeric" }).format(at);
|
|
33
|
+
return l.later.replaceAll("{date}", date).replaceAll("{time}", time);
|
|
34
|
+
}
|
|
35
|
+
export function limitWords(limit, labels = {}, now = new Date(), opts = {}) {
|
|
36
|
+
const l = { ...DEFAULT_LIMIT_LABELS, ...labels, names: { ...DEFAULT_LIMIT_LABELS.names, ...labels.names } };
|
|
37
|
+
const name = l.names[limit.cap];
|
|
38
|
+
const Name = name.charAt(0).toLocaleUpperCase(opts.locale) + name.slice(1);
|
|
39
|
+
const fill = (s) => s.replaceAll("{limit}", name).replaceAll("{Limit}", Name);
|
|
40
|
+
const at = limit.resetsAt === null ? null : new Date(limit.resetsAt);
|
|
41
|
+
if (at !== null && at.getTime() <= now.getTime())
|
|
42
|
+
return fill(l.hasReset);
|
|
43
|
+
const head = fill(limit.why === "used_up" ? l.usedUp : l.tooSmall);
|
|
44
|
+
return at === null ? head : `${head} ${l.resets.replaceAll("{when}", whenWords(at, now, l, opts))}`;
|
|
45
|
+
}
|
|
46
|
+
export function refusalWords(r, labels, live, now = new Date(), opts = {}) {
|
|
47
|
+
const yours = r.code !== null ? labels.refusals?.[r.code] : undefined;
|
|
48
|
+
if (yours !== undefined)
|
|
49
|
+
return yours;
|
|
50
|
+
if (live && r.code === "cap_reached" && r.limit)
|
|
51
|
+
return limitWords(r.limit, labels.limits, now, opts);
|
|
52
|
+
return r.message;
|
|
53
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<MarkdownText>`: an agent's Markdown, drawn (`md-parse.ts` reads it). What `<AgentChat>` draws an assistant's
|
|
3
|
+
* words with, unless you pass your own `renderText`; a person's own words stay plain text.
|
|
4
|
+
*
|
|
5
|
+
* React elements only: no HTML string is ever made, and the kit never sets `dangerouslySetInnerHTML` (a test
|
|
6
|
+
* reads every file for it). A link opens in a new tab with `rel="noopener noreferrer"`, and its address is its
|
|
7
|
+
* title; when its words do not name its host, the host follows them in quiet text (`data-ol-md-host`), so
|
|
8
|
+
* "sign in here" cannot hide where it goes. An image is a link, never loaded.
|
|
9
|
+
*
|
|
10
|
+
* UNSTYLED, like the rest of the kit: `data-ol-md-*` hooks on each element, and the optional stylesheet's
|
|
11
|
+
* defaults (`@openlegion/platform/react/styles.css`): a heading is a modest bold line, a table scrolls sideways
|
|
12
|
+
* inside the reply on a narrow screen, code is in the page's monospace.
|
|
13
|
+
*/
|
|
14
|
+
import { type ReactNode } from "react";
|
|
15
|
+
/** How the words' links are drawn. */
|
|
16
|
+
export interface MarkdownLinkOptions {
|
|
17
|
+
/** Untrusted content reached the run that wrote these words (`RenderTextInfo.tainted`). */
|
|
18
|
+
tainted?: boolean | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* A tainted text's links: "draw" (default), each a link with its host shown, as in every reply (a research
|
|
21
|
+
* answer's sources are its point); or "text", each its words and host with nothing to click.
|
|
22
|
+
*/
|
|
23
|
+
taintedLinks?: "draw" | "text" | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Markdown text as React elements: the blocks, with no wrapper. Pure; for a `renderText` of yours that adds to it.
|
|
27
|
+
* `ended`: the text will not grow (a reply no longer streaming), so its end draws no marker that never closed.
|
|
28
|
+
* `tainted` and `taintedLinks`: see `MarkdownLinkOptions`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function renderMarkdown(text: string, opts?: {
|
|
31
|
+
ended?: boolean | undefined;
|
|
32
|
+
} & MarkdownLinkOptions): ReactNode;
|
|
33
|
+
/**
|
|
34
|
+
* Markdown text, drawn: `<div data-ol-md>` around its blocks (`data-ol-md-tainted` when `tainted`). Read again only
|
|
35
|
+
* when the text changes. `ended`: see `renderMarkdown` (the chat passes it for every reply's words but the ones
|
|
36
|
+
* streaming). `tainted` and `taintedLinks`: see `MarkdownLinkOptions` (the chat passes each reply's `tainted`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function MarkdownText({ text, className, ended, tainted, taintedLinks }: {
|
|
39
|
+
text: string;
|
|
40
|
+
className?: string | undefined;
|
|
41
|
+
ended?: boolean | undefined;
|
|
42
|
+
} & MarkdownLinkOptions): import("react").JSX.Element;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useMemo } from "react";
|
|
3
|
+
import { linkHostShown, parseMarkdown } from "./md-parse.js";
|
|
4
|
+
function plainText(nodes) {
|
|
5
|
+
return nodes.map((n) => (n.type === "text" || n.type === "code" ? n.text : n.type === "br" ? " " : plainText(n.children))).join("");
|
|
6
|
+
}
|
|
7
|
+
function inlines(nodes, asText = false) {
|
|
8
|
+
return nodes.map((n, i) => {
|
|
9
|
+
switch (n.type) {
|
|
10
|
+
case "text":
|
|
11
|
+
return _jsx(Fragment, { children: n.text }, i);
|
|
12
|
+
case "code":
|
|
13
|
+
return (_jsx("code", { "data-ol-md-code": true, children: n.text }, i));
|
|
14
|
+
case "strong":
|
|
15
|
+
return (_jsx("strong", { "data-ol-md-strong": true, children: inlines(n.children, asText) }, i));
|
|
16
|
+
case "em":
|
|
17
|
+
return (_jsx("em", { "data-ol-md-em": true, children: inlines(n.children, asText) }, i));
|
|
18
|
+
case "link": {
|
|
19
|
+
const host = linkHostShown(n.href, plainText(n.children));
|
|
20
|
+
return (_jsxs(Fragment, { children: [asText ? (_jsx("span", { "data-ol-md-link-text": true, children: inlines(n.children, true) })) : (_jsx("a", { "data-ol-md-link": true, href: n.href, title: n.href, target: "_blank", rel: "noopener noreferrer", children: inlines(n.children) })), host !== null ? (_jsxs(_Fragment, { children: [" ", _jsxs("span", { "data-ol-md-host": true, children: ["(", host, ")"] })] })) : null] }, i));
|
|
21
|
+
}
|
|
22
|
+
case "br":
|
|
23
|
+
return _jsx("br", {}, i);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function block(b, key, asText) {
|
|
28
|
+
switch (b.type) {
|
|
29
|
+
case "paragraph":
|
|
30
|
+
return (_jsx("p", { "data-ol-md-p": true, children: inlines(b.children, asText) }, key));
|
|
31
|
+
case "heading":
|
|
32
|
+
return (_jsx("p", { "data-ol-md-heading": String(b.level), children: _jsx("strong", { children: inlines(b.children, asText) }) }, key));
|
|
33
|
+
case "code":
|
|
34
|
+
return (_jsx("pre", { "data-ol-md-pre": true, ...(b.lang ? { "data-ol-md-lang": b.lang } : {}), children: _jsx("code", { children: b.text }) }, key));
|
|
35
|
+
case "quote":
|
|
36
|
+
return (_jsx("blockquote", { "data-ol-md-quote": true, children: blocks(b.children, asText) }, key));
|
|
37
|
+
case "list": {
|
|
38
|
+
const items = b.items.map((item, i) => (_jsx("li", { "data-ol-md-li": true, children: item.length === 1 && item[0].type === "paragraph" ? inlines(item[0].children, asText) : blocks(item, asText) }, i)));
|
|
39
|
+
return b.ordered ? (_jsx("ol", { "data-ol-md-ol": true, ...(b.start !== 1 ? { start: b.start } : {}), children: items }, key)) : (_jsx("ul", { "data-ol-md-ul": true, children: items }, key));
|
|
40
|
+
}
|
|
41
|
+
case "rule":
|
|
42
|
+
return _jsx("hr", { "data-ol-md-rule": true }, key);
|
|
43
|
+
case "table":
|
|
44
|
+
return (_jsx("div", { "data-ol-md-table": true, children: _jsxs("table", { children: [_jsx("thead", { children: _jsx("tr", { children: b.head.map((cell, i) => (_jsx("th", { scope: "col", ...(b.align[i] ? { "data-ol-md-align": b.align[i] } : {}), children: inlines(cell, asText) }, i))) }) }), b.rows.length > 0 ? (_jsx("tbody", { children: b.rows.map((row, r) => (_jsx("tr", { children: row.map((cell, i) => (_jsx("td", { ...(b.align[i] ? { "data-ol-md-align": b.align[i] } : {}), children: inlines(cell, asText) }, i))) }, r))) })) : null] }) }, key));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function blocks(list, asText) {
|
|
48
|
+
return list.map((b, i) => block(b, i, asText));
|
|
49
|
+
}
|
|
50
|
+
export function renderMarkdown(text, opts) {
|
|
51
|
+
return _jsx(_Fragment, { children: blocks(parseMarkdown(text, opts), opts?.tainted === true && opts.taintedLinks === "text") });
|
|
52
|
+
}
|
|
53
|
+
export function MarkdownText({ text, className, ended, tainted, taintedLinks }) {
|
|
54
|
+
const tree = useMemo(() => renderMarkdown(text, { ended, tainted, taintedLinks }), [text, ended, tainted, taintedLinks]);
|
|
55
|
+
return (_jsx("div", { "data-ol-md": true, className: className, ...(tainted ? { "data-ol-md-tainted": true } : {}), children: tree }));
|
|
56
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE MARKDOWN AN AGENT WRITES, read into a small tree (`<MarkdownText>` draws it). A real model answers in
|
|
3
|
+
* Markdown; drawn as plain text, a person reads `**Asana.**` and `[a link](https://…)`.
|
|
4
|
+
*
|
|
5
|
+
* A SUBSET, ON PURPOSE: paragraphs, bold, italics, inline code, fenced code, links, ordered and unordered lists
|
|
6
|
+
* (nested), headings, block quotes, rules and tables. Everything else is the text it is: HTML is never HTML (a
|
|
7
|
+
* `<b>` is the four characters), a reference link stays `[text][ref]`, an indented block is a paragraph.
|
|
8
|
+
*
|
|
9
|
+
* SAFE BY CONSTRUCTION. The tree holds strings and nodes, never markup; the renderer makes React elements, so
|
|
10
|
+
* nothing here can become HTML. A link is kept only when its address is `http:`, `https:` or `mailto:` as the
|
|
11
|
+
* URL parser reads it (`safeHref`); any other link is drawn as the text it was written as. An image is never
|
|
12
|
+
* loaded: `` is a link to the url, its alt text as the words (a model talked into writing an image
|
|
13
|
+
* of `https://evil.example/?q=<secret>` would have the browser fetch it unasked).
|
|
14
|
+
*
|
|
15
|
+
* STREAMING DOES NOT JUMP. The tree of a half-arrived reply is the tree of that text: an unclosed `**`, `` ` ``
|
|
16
|
+
* or `[text](` stays literal until it closes, and a link is never made before its `)`. A fence that has not
|
|
17
|
+
* closed is code to the end, as it will be once it closes, so the box does not come and go.
|
|
18
|
+
*
|
|
19
|
+
* A TEXT THAT HAS ENDED HAS NO DANGLING MARKER (`{ ended: true }`, a reply no longer streaming): in its last
|
|
20
|
+
* block, where the text ran out before the marker closed, an opening `**` or `*` that never closed (a run that can
|
|
21
|
+
* only open), a `` ` `` with no closer and a `[` with no `]` are not drawn, nor the `](…` of a link whose address
|
|
22
|
+
* never closed; the words after them are. Earlier blocks are as written: a lone `*` there is the model's own text.
|
|
23
|
+
*
|
|
24
|
+
* BOUNDED: containers nest at most `MAX_DEPTH` deep (deeper, the rest is paragraph text); emphasis is matched
|
|
25
|
+
* only in a paragraph with at most `MAX_DELIMITERS` runs of `*` and `_`; a link's text is looked for at most
|
|
26
|
+
* `MAX_LINK_TEXT` characters ahead. Every pass is linear in the text, so a 1 MB reply or 10 000 nested `>` is
|
|
27
|
+
* read in one go.
|
|
28
|
+
*/
|
|
29
|
+
export type MdInline = {
|
|
30
|
+
type: "text";
|
|
31
|
+
text: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: "code";
|
|
34
|
+
text: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "strong";
|
|
37
|
+
children: MdInline[];
|
|
38
|
+
} | {
|
|
39
|
+
type: "em";
|
|
40
|
+
children: MdInline[];
|
|
41
|
+
} | {
|
|
42
|
+
type: "link";
|
|
43
|
+
href: string;
|
|
44
|
+
children: MdInline[];
|
|
45
|
+
} | {
|
|
46
|
+
type: "br";
|
|
47
|
+
};
|
|
48
|
+
export type MdAlign = "left" | "center" | "right" | null;
|
|
49
|
+
export type MdBlock = {
|
|
50
|
+
type: "paragraph";
|
|
51
|
+
children: MdInline[];
|
|
52
|
+
} | {
|
|
53
|
+
type: "heading";
|
|
54
|
+
level: number;
|
|
55
|
+
children: MdInline[];
|
|
56
|
+
} | {
|
|
57
|
+
type: "code";
|
|
58
|
+
lang: string;
|
|
59
|
+
text: string;
|
|
60
|
+
} | {
|
|
61
|
+
type: "quote";
|
|
62
|
+
children: MdBlock[];
|
|
63
|
+
} | {
|
|
64
|
+
type: "list";
|
|
65
|
+
ordered: boolean;
|
|
66
|
+
start: number;
|
|
67
|
+
items: MdBlock[][];
|
|
68
|
+
} | {
|
|
69
|
+
type: "rule";
|
|
70
|
+
} | {
|
|
71
|
+
type: "table";
|
|
72
|
+
align: MdAlign[];
|
|
73
|
+
head: MdInline[][];
|
|
74
|
+
rows: MdInline[][][];
|
|
75
|
+
};
|
|
76
|
+
/** Lists and quotes nest at most this deep; deeper, their lines are paragraph text. */
|
|
77
|
+
export declare const MAX_DEPTH = 8;
|
|
78
|
+
/** A paragraph with more runs of `*` and `_` than this keeps them all as text. */
|
|
79
|
+
export declare const MAX_DELIMITERS = 1000;
|
|
80
|
+
/** How far a `[` looks for its `]`. */
|
|
81
|
+
export declare const MAX_LINK_TEXT = 1000;
|
|
82
|
+
/** A table has at most this many columns; one with more is paragraph text. */
|
|
83
|
+
export declare const MAX_COLUMNS = 64;
|
|
84
|
+
export declare function safeHref(raw: string): string | null;
|
|
85
|
+
/**
|
|
86
|
+
* The host to show after a link, or null. A link's words can say anything ("sign in here", or another site's
|
|
87
|
+
* name): when they do not name the address's own host, the host is shown beside them, as the URL parser spells it
|
|
88
|
+
* (an international name in its `xn--` form, so a look-alike letter cannot pass). Words that are the address, or
|
|
89
|
+
* that name its host (with or without `www.`), are left as they are. For `mailto:`, the host is the mail domain; an
|
|
90
|
+
* address that will not decode (`mailto:%`) shows no host, rather than throwing while the reply is drawn.
|
|
91
|
+
*/
|
|
92
|
+
export declare function linkHostShown(href: string, words: string): string | null;
|
|
93
|
+
/** A table row's cells: split on `|` that is not escaped and not inside a code span; the outer pipes dropped. */
|
|
94
|
+
export declare function splitRow(line: string): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Markdown text as blocks. Line endings are `\n`; a tab counts as four spaces. Never throws. `ended`: the text will
|
|
97
|
+
* not grow (a reply no longer streaming): its last block draws no marker that never closed.
|
|
98
|
+
*/
|
|
99
|
+
export declare function parseMarkdown(text: string, opts?: {
|
|
100
|
+
ended?: boolean | undefined;
|
|
101
|
+
}): MdBlock[];
|
|
102
|
+
/**
|
|
103
|
+
* A paragraph's text as inline nodes. `inLink`: inside a link's text, where no other link is made. `ended`: the text
|
|
104
|
+
* ran out here, so a marker that never closed is not drawn (see `parseMarkdown`).
|
|
105
|
+
*/
|
|
106
|
+
export declare function inline(src: string, inLink?: boolean, ended?: boolean): MdInline[];
|