+
{children}>;
+ }
+ if (sandboxLink.kind === 'artifact') {
+ return renderArtifactChip(sandboxLink.artifact, children);
+ }
+ if (href?.startsWith('#cite-')) {
+ const num = href.replace('#cite-', '');
+ const sourceIdx = parseInt(num, 10) - 1;
+ return (
+
- );
- }
- return (
-
- {children}
-
- );
- },
- img({ src, alt }) {
- // `` is how a model
- // announces a plot it produced. react-markdown runs
- // urlTransform over `src` too, so without this the invented
- // scheme survives and renders a broken-image box beside the
- // chip that opens the very same file.
- const source = typeof src === 'string' ? src : undefined;
- const sandboxLink = resolveSandboxLink(
- source,
- artifacts,
- turnArtifacts,
- );
- if (sandboxLink.kind === 'artifact') {
- const { artifact } = sandboxLink;
- return renderArtifactChip(
- artifact,
- alt || artifact.label || 'Open file',
- );
- }
- if (sandboxLink.kind === 'plain') {
- return <>{alt ?? ''}>;
- }
- return
;
- },
- code(props) {
- const { children, className, node, ref, ...rest } = props;
- const match = /language-(\w+)/.exec(className || '');
- const language = match ? match[1] : '';
-
- return match ? (
-
-
-
- {language}
-
-
-
-
- {String(children).replace(/\n$/, '')}
-
-
- ) : (
-
- {children}
-
- );
- },
- ul({ children }) {
- return (
-
- );
- },
- ol({ children }) {
- return (
-
- {children}
-
- );
- },
- table({ children }) {
- return (
-
-
+ if (el) {
+ el.scrollIntoView({
+ behavior: 'smooth',
+ block: 'center',
+ });
+ el.classList.add('ring-2', 'ring-purple-500');
+ setTimeout(
+ () =>
+ el.classList.remove(
+ 'ring-2',
+ 'ring-purple-500',
+ ),
+ 2000,
+ );
+ }
+ }}
+ className="mx-0.5 h-5 min-w-5 rounded-full bg-purple-100 px-1.5 text-xs font-semibold text-purple-700 hover:bg-purple-200 dark:bg-purple-900/40 dark:text-purple-300 dark:hover:bg-purple-900/60"
+ title={`Jump to source ${num}`}
+ >
+ {num}
+
+ );
+ }
+ return (
+
{children}
-
-
- );
- },
- thead({ children }) {
- return (
-
- {children}
-
- );
- },
- tr({ children }) {
- return (
-
- {children}
-
- );
- },
- th({ children }) {
- return {children} | ;
- },
- td({ children }) {
- return {children} | ;
- },
- }}
- >
- {segment.content}
-
+
+ );
+ },
+ img({ src, alt }) {
+ // `` is how a model
+ // announces a plot it produced. react-markdown runs
+ // urlTransform over `src` too, so without this the invented
+ // scheme survives and renders a broken-image box beside the
+ // chip that opens the very same file.
+ const source = typeof src === 'string' ? src : undefined;
+ const sandboxLink = resolveSandboxLink(
+ source,
+ artifacts,
+ turnArtifacts,
+ );
+ if (sandboxLink.kind === 'artifact') {
+ const { artifact } = sandboxLink;
+ return renderArtifactChip(
+ artifact,
+ alt || artifact.label || 'Open file',
+ );
+ }
+ if (sandboxLink.kind === 'plain') {
+ return <>{alt ?? ''}>;
+ }
+ return (
+

+ );
+ },
+ code(props) {
+ const { children, className, node, ref, ...rest } = props;
+ const match = /language-(\w+)/.exec(className || '');
+ const language = match ? match[1] : '';
+
+ return match ? (
+
+
+
+ {language}
+
+
+
+
+ {String(children).replace(/\n$/, '')}
+
+
+ ) : (
+
+ {children}
+
+ );
+ },
+ ul({ children }) {
+ return (
+
+ );
+ },
+ ol({ children }) {
+ return (
+
+ {children}
+
+ );
+ },
+ table({ children }) {
+ return (
+
+ );
+ },
+ thead({ children }) {
+ return (
+
+ {children}
+
+ );
+ },
+ tr({ children }) {
+ return (
+
+ {children}
+
+ );
+ },
+ th({ children }) {
+ return
{children} | ;
+ },
+ td({ children }) {
+ return
{children} | ;
+ },
+ }}
+ >
+ {segment.content}
+
+
) : (