shraga 0.1.143 → 0.1.145
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/dist/client/assets/index-CXLXqguJ.js +2112 -0
- package/dist/client/assets/{index-BLAQpfJ9.css → index-DzxOqQtK.css} +2 -2
- package/dist/client/index.html +2 -2
- package/package.json +5 -1
- package/src/client/bare-v3.d.ts +15 -0
- package/src/client/components/AssistantMarkdown.css +18 -0
- package/src/client/components/AssistantMarkdown.tsx +94 -0
- package/src/client/components/AuthedImage.tsx +10 -5
- package/src/client/components/ChatView.tsx +8 -76
- package/dist/client/assets/index-CQi1LGRZ.js +0 -2009
|
@@ -5,7 +5,15 @@ import { useWorkspace } from '@/lib/workspaceContext';
|
|
|
5
5
|
// `/uploads/*` is gated by requireAuth on the server, so a plain <img src>/<a href> GET 401s
|
|
6
6
|
// (no Authorization header). Fetch with a fresh bearer token and render/open a blob URL instead.
|
|
7
7
|
// Other srcs (data:, http(s):, blob:) need no auth.
|
|
8
|
-
const NEEDS_AUTH = /^\/uploads\//;
|
|
8
|
+
export const NEEDS_AUTH = /^\/uploads\//;
|
|
9
|
+
|
|
10
|
+
/** Fetch an auth-gated src with a bearer token → a blob URL the caller must revoke. */
|
|
11
|
+
export async function authedBlobUrl(src: string, getToken: () => Promise<string | null | undefined>): Promise<string> {
|
|
12
|
+
const token = await getToken();
|
|
13
|
+
const res = await fetch(src, { headers: token ? { Authorization: `Bearer ${token}` } : {} });
|
|
14
|
+
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
15
|
+
return URL.createObjectURL(await res.blob());
|
|
16
|
+
}
|
|
9
17
|
|
|
10
18
|
interface ImageProps {
|
|
11
19
|
src: string;
|
|
@@ -29,10 +37,7 @@ export function AuthedImage({ src, alt, className, onClick }: ImageProps) {
|
|
|
29
37
|
setResolved(null);
|
|
30
38
|
(async () => {
|
|
31
39
|
try {
|
|
32
|
-
|
|
33
|
-
const res = await fetch(src, { headers: token ? { Authorization: `Bearer ${token}` } : {} });
|
|
34
|
-
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
35
|
-
objectUrl = URL.createObjectURL(await res.blob());
|
|
40
|
+
objectUrl = await authedBlobUrl(src, getToken);
|
|
36
41
|
if (cancelled) URL.revokeObjectURL(objectUrl);
|
|
37
42
|
else setResolved(objectUrl);
|
|
38
43
|
} catch (err) {
|
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import remarkGfm from 'remark-gfm';
|
|
4
|
-
import rehypeHighlight from 'rehype-highlight';
|
|
5
|
-
import type { Root, Element } from 'hast';
|
|
6
|
-
import type { Plugin } from 'unified';
|
|
7
|
-
|
|
8
|
-
const RTL_BLOCK_TAGS = new Set(['p', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'td', 'th']);
|
|
9
|
-
const rehypeBidi: Plugin<[], Root> = () => (tree) => {
|
|
10
|
-
const visit = (node: Root | Element) => {
|
|
11
|
-
for (const child of (node.children ?? [])) {
|
|
12
|
-
if (child.type === 'element') {
|
|
13
|
-
if (RTL_BLOCK_TAGS.has(child.tagName)) {
|
|
14
|
-
child.properties ??= {};
|
|
15
|
-
child.properties.dir = 'auto';
|
|
16
|
-
}
|
|
17
|
-
visit(child);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
visit(tree);
|
|
22
|
-
};
|
|
23
|
-
import 'highlight.js/styles/github.css';
|
|
24
|
-
import { ChevronRight, Wrench, User, Bot, Copy, Check, RotateCcw, Pencil, X, SendHorizontal, ShieldQuestion, CheckCircle2, XCircle, Eye, EyeOff, Info, Loader2, BrainCircuit, GitFork, Minimize2 } from 'lucide-react';
|
|
2
|
+
import { ChevronRight, Wrench, User, Bot, Check, RotateCcw, Pencil, X, SendHorizontal, ShieldQuestion, CheckCircle2, XCircle, Eye, EyeOff, Info, Loader2, BrainCircuit, GitFork, Minimize2 } from 'lucide-react';
|
|
25
3
|
import { cn } from '@/lib/utils';
|
|
26
4
|
import { toolPreview } from '@/lib/tool-preview';
|
|
27
5
|
import { annotateLimitReset } from '@/lib/limit-reset';
|
|
@@ -32,33 +10,15 @@ import { AuthedImage, AuthedFileLink } from './AuthedImage';
|
|
|
32
10
|
import { useSlots } from '@/lib/slots';
|
|
33
11
|
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
|
34
12
|
import { ZoomableImage } from './ZoomableImage';
|
|
13
|
+
import { AssistantMarkdown } from './AssistantMarkdown';
|
|
35
14
|
|
|
36
15
|
// The appwrap iOS WKWebView wedges its GPU compositor when rendering react-markdown's DOM for a chat with
|
|
37
16
|
// history — JS keeps running but paint + hit-testing freeze for ~1-2min (screen stuck/touch-dead) before
|
|
38
17
|
// WebKit lazily restores. The SAME content in mobile Safari and on desktop is fine, so this is specific to
|
|
39
|
-
// the native WKWebView shell, not the web app. Until the native shell issue is fixed, render assistant
|
|
18
|
+
// the native WKWebView shell, not the web app. (Observed with react-markdown; MarkdownStream is unverified there.) Until the native shell issue is fixed, render assistant
|
|
40
19
|
// messages as PLAIN TEXT inside the native app only; full markdown stays on Safari/desktop/web.
|
|
41
20
|
const IS_APPWRAP_NATIVE = typeof window !== 'undefined' && !!(window as { webkit?: { messageHandlers?: { appwrap?: unknown } } }).webkit?.messageHandlers?.appwrap;
|
|
42
21
|
|
|
43
|
-
function AssistantMarkdown({ text, onImageClick }: { text: string; onImageClick?: (src: string) => void }) {
|
|
44
|
-
const clean = text.replace(/\[Image #\d+\]\s*/g, '').trim();
|
|
45
|
-
if (IS_APPWRAP_NATIVE) {
|
|
46
|
-
return <div className="prose prose-sm max-w-none dark:prose-invert break-words min-w-0 whitespace-pre-wrap">{clean}</div>;
|
|
47
|
-
}
|
|
48
|
-
return (
|
|
49
|
-
<ReactMarkdown
|
|
50
|
-
remarkPlugins={[remarkGfm]}
|
|
51
|
-
rehypePlugins={[rehypeHighlight, rehypeBidi]}
|
|
52
|
-
className="prose prose-sm max-w-none dark:prose-invert prose-pre:bg-muted prose-pre:border prose-code:before:content-none prose-code:after:content-none break-words min-w-0"
|
|
53
|
-
components={{
|
|
54
|
-
pre: ({ children, ...props }) => <CodeBlock {...props}>{children}</CodeBlock>,
|
|
55
|
-
a: ({ href, children }) => <a href={href} target="_blank" rel="noopener noreferrer">{children}</a>,
|
|
56
|
-
img: ({ src, alt }) => <AuthedImage src={src ?? ''} alt={alt ?? ''} className="max-h-[80vh] max-w-full rounded-xl border object-contain cursor-pointer hover:opacity-80 transition-opacity" onClick={(s) => onImageClick?.(s)} />,
|
|
57
|
-
}}
|
|
58
|
-
>{clean}</ReactMarkdown>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
22
|
function formatTs(ts: number): string {
|
|
63
23
|
const d = new Date(ts);
|
|
64
24
|
const now = new Date();
|
|
@@ -397,7 +357,7 @@ const MessageRow = memo(function MessageRow({
|
|
|
397
357
|
const result = block.type === 'tool_use'
|
|
398
358
|
? message.blocks.find((b): b is MessageBlock & { type: 'tool_result' } => b.type === 'tool_result' && b.toolUseId === block.toolUseId)
|
|
399
359
|
: undefined;
|
|
400
|
-
return <BlockRenderer key={i} block={block} isUser={isUser} ts={message.ts} onPermissionRespond={onPermissionRespond} onQuestionRespond={onQuestionRespond} pairedResult={result} onImageClick={onImageClick} busy={busy} screenMap={screenMap} />;
|
|
360
|
+
return <BlockRenderer key={i} block={block} isUser={isUser} ts={message.ts} onPermissionRespond={onPermissionRespond} onQuestionRespond={onQuestionRespond} pairedResult={result} onImageClick={onImageClick} busy={busy} live={!!busy && block === message.blocks[message.blocks.length - 1]} screenMap={screenMap} />;
|
|
401
361
|
})}
|
|
402
362
|
{isUser && userText && (
|
|
403
363
|
<div className={cn('flex gap-1 items-center justify-end transition-opacity', actionsVisible ? 'opacity-100' : 'opacity-0 group-hover/row:opacity-100')}>
|
|
@@ -462,7 +422,7 @@ function CompactMarkerDivider({ summary, compactedCount }: { summary: string; co
|
|
|
462
422
|
);
|
|
463
423
|
}
|
|
464
424
|
|
|
465
|
-
function BlockRenderer({ block, isUser, ts, onPermissionRespond, onQuestionRespond, pairedResult, onImageClick, busy, screenMap }: { block: MessageBlock; isUser: boolean; ts?: number; onPermissionRespond?: (id: string, allow: boolean, allowAll?: boolean) => void; onQuestionRespond?: (id: string, answers: QuestionAnswers) => void; pairedResult?: MessageBlock & { type: 'tool_result' }; onImageClick?: (src: string) => void; busy?: boolean; screenMap?: Map<string, string[]> }) {
|
|
425
|
+
function BlockRenderer({ block, isUser, ts, onPermissionRespond, onQuestionRespond, pairedResult, onImageClick, busy, live, screenMap }: { block: MessageBlock; isUser: boolean; ts?: number; onPermissionRespond?: (id: string, allow: boolean, allowAll?: boolean) => void; onQuestionRespond?: (id: string, answers: QuestionAnswers) => void; pairedResult?: MessageBlock & { type: 'tool_result' }; onImageClick?: (src: string) => void; busy?: boolean; /** This text block is the one currently streaming. */ live?: boolean; screenMap?: Map<string, string[]> }) {
|
|
466
426
|
const slots = useSlots();
|
|
467
427
|
if (block.type === 'image') {
|
|
468
428
|
return (
|
|
@@ -500,7 +460,9 @@ function BlockRenderer({ block, isUser, ts, onPermissionRespond, onQuestionRespo
|
|
|
500
460
|
}
|
|
501
461
|
return (
|
|
502
462
|
<div className="text-sm" dir="auto">
|
|
503
|
-
|
|
463
|
+
{IS_APPWRAP_NATIVE
|
|
464
|
+
? <div className="prose prose-sm max-w-none dark:prose-invert break-words min-w-0 whitespace-pre-wrap">{block.text.replace(/\[Image #\d+\]\s*/g, '').trim()}</div>
|
|
465
|
+
: <AssistantMarkdown text={block.text} streaming={live} onImageClick={onImageClick} />}
|
|
504
466
|
</div>
|
|
505
467
|
);
|
|
506
468
|
}
|
|
@@ -938,33 +900,3 @@ function QuestionRequestBlock({
|
|
|
938
900
|
</div>
|
|
939
901
|
);
|
|
940
902
|
}
|
|
941
|
-
|
|
942
|
-
function CodeBlock({ children, ...props }: any) {
|
|
943
|
-
const ref = useRef<HTMLPreElement>(null);
|
|
944
|
-
return (
|
|
945
|
-
<div className="relative group">
|
|
946
|
-
<pre ref={ref} {...props} className="rounded-lg border bg-muted p-4 overflow-x-auto text-xs text-foreground">
|
|
947
|
-
{children}
|
|
948
|
-
</pre>
|
|
949
|
-
<CopyButton getText={() => ref.current?.textContent || ''} />
|
|
950
|
-
</div>
|
|
951
|
-
);
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
function CopyButton({ getText }: { getText: () => string }) {
|
|
955
|
-
const [copied, setCopied] = useState(false);
|
|
956
|
-
|
|
957
|
-
return (
|
|
958
|
-
<button
|
|
959
|
-
onClick={() => {
|
|
960
|
-
navigator.clipboard.writeText(getText());
|
|
961
|
-
setCopied(true);
|
|
962
|
-
setTimeout(() => setCopied(false), 2000);
|
|
963
|
-
}}
|
|
964
|
-
className="absolute top-2 right-2 p-1.5 rounded-md bg-background/80 border opacity-0 group-hover:opacity-100 transition-opacity"
|
|
965
|
-
title="Copy"
|
|
966
|
-
>
|
|
967
|
-
{copied ? <Check className="w-3 h-3" /> : <Copy className="w-3 h-3" />}
|
|
968
|
-
</button>
|
|
969
|
-
);
|
|
970
|
-
}
|