@stainless-api/docs-ai-chat 0.1.0-beta.6 → 0.1.0-beta.60
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/CHANGELOG.md +264 -33
- package/ambient.d.ts +6 -0
- package/eslint.config.ts +2 -0
- package/package.json +8 -17
- package/plugin.tsx +2 -2
- package/src/DocsChat.tsx +60 -0
- package/src/api/client-id.ts +11 -0
- package/src/api/index.ts +72 -6
- package/src/api/schemas.ts +15 -0
- package/src/hook.ts +106 -75
- package/tsconfig.json +1 -1
- package/eslint.config.js +0 -2
- package/src/AiChat.module.css +0 -221
- package/src/AiChat.tsx +0 -84
- package/src/Trigger.tsx +0 -135
- package/src/components/ChatLog.tsx +0 -42
- package/src/components/ChatMessage.tsx +0 -43
- package/src/components/CodeBlock.tsx +0 -29
- package/src/components/ToolCall.tsx +0 -36
- package/src/components/hljs-github.css +0 -81
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { ChatMessage } from '../hook';
|
|
2
|
-
import Message from './ChatMessage';
|
|
3
|
-
import ToolCall from './ToolCall';
|
|
4
|
-
|
|
5
|
-
import { motion } from 'motion/react';
|
|
6
|
-
|
|
7
|
-
import styles from '../AiChat.module.css';
|
|
8
|
-
|
|
9
|
-
export default function ChatLog({ messages }: { messages: ChatMessage[] }) {
|
|
10
|
-
return (
|
|
11
|
-
<motion.ul
|
|
12
|
-
layout
|
|
13
|
-
role="log"
|
|
14
|
-
aria-live="polite"
|
|
15
|
-
className={styles['message-log']}
|
|
16
|
-
initial={{ opacity: 0, filter: `blur(4px)` }}
|
|
17
|
-
animate={{ opacity: 1, filter: `blur(0px)` }}
|
|
18
|
-
>
|
|
19
|
-
{messages.map((msg) => {
|
|
20
|
-
if (msg.role === 'user') {
|
|
21
|
-
return (
|
|
22
|
-
<Message key={msg.id} role="user">
|
|
23
|
-
{msg.content}
|
|
24
|
-
</Message>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (msg.role === 'assistant' && msg.messageType === 'text') {
|
|
29
|
-
return (
|
|
30
|
-
<Message key={msg.id} role={msg.role} isMarkdown isStreaming={!msg.isComplete}>
|
|
31
|
-
{msg.content}
|
|
32
|
-
</Message>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (msg.role === 'assistant' && msg.messageType === 'tool_use') {
|
|
37
|
-
return <ToolCall key={msg.id} message={msg} />;
|
|
38
|
-
}
|
|
39
|
-
})}
|
|
40
|
-
</motion.ul>
|
|
41
|
-
);
|
|
42
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import remend from 'remend';
|
|
2
|
-
import Markdown from 'react-markdown';
|
|
3
|
-
import { motion } from 'motion/react';
|
|
4
|
-
|
|
5
|
-
import highlightCodeComponent from './CodeBlock';
|
|
6
|
-
|
|
7
|
-
import clsx from 'clsx';
|
|
8
|
-
import styles from '../AiChat.module.css';
|
|
9
|
-
|
|
10
|
-
export default function ChatMessage({
|
|
11
|
-
children,
|
|
12
|
-
role,
|
|
13
|
-
isStreaming = false,
|
|
14
|
-
isMarkdown = false,
|
|
15
|
-
}: {
|
|
16
|
-
children: string;
|
|
17
|
-
role: 'user' | 'assistant';
|
|
18
|
-
isStreaming?: boolean;
|
|
19
|
-
isMarkdown?: boolean;
|
|
20
|
-
}) {
|
|
21
|
-
return (
|
|
22
|
-
<motion.li
|
|
23
|
-
layout="position"
|
|
24
|
-
data-message-role={role}
|
|
25
|
-
className={clsx(styles['chat-message'], 'stl-ui-prose', 'smaller-headings')}
|
|
26
|
-
style={{ borderRadius: 16 }}
|
|
27
|
-
>
|
|
28
|
-
{/* inner div provides scale correction while outer container transforms */}
|
|
29
|
-
{isMarkdown ? (
|
|
30
|
-
<Markdown
|
|
31
|
-
components={{
|
|
32
|
-
...highlightCodeComponent,
|
|
33
|
-
}}
|
|
34
|
-
>
|
|
35
|
-
{/* repair incomplete markdown syntax during streaming to ensure proper rendering */}
|
|
36
|
-
{isStreaming ? remend(children) : children}
|
|
37
|
-
</Markdown>
|
|
38
|
-
) : (
|
|
39
|
-
<p>{children}</p>
|
|
40
|
-
)}
|
|
41
|
-
</motion.li>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Fragment } from 'react';
|
|
2
|
-
|
|
3
|
-
import { LightAsync as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
4
|
-
|
|
5
|
-
import type { Components } from 'react-markdown';
|
|
6
|
-
import clsx from 'clsx';
|
|
7
|
-
import './hljs-github.css';
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
code(props) {
|
|
11
|
-
const { children, className, ref, style, ...rest } = props;
|
|
12
|
-
const match = /language-(\w+)/.exec(className || '');
|
|
13
|
-
return match ? (
|
|
14
|
-
<SyntaxHighlighter
|
|
15
|
-
{...rest}
|
|
16
|
-
PreTag={Fragment}
|
|
17
|
-
language={match[1]}
|
|
18
|
-
useInlineStyles
|
|
19
|
-
codeTagProps={{ className: clsx(className, 'hljs-github') }}
|
|
20
|
-
>
|
|
21
|
-
{String(children).replace(/\n$/, '')}
|
|
22
|
-
</SyntaxHighlighter>
|
|
23
|
-
) : (
|
|
24
|
-
<code {...rest} className={className}>
|
|
25
|
-
{children}
|
|
26
|
-
</code>
|
|
27
|
-
);
|
|
28
|
-
},
|
|
29
|
-
} satisfies Components;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { motion } from 'motion/react';
|
|
2
|
-
import z from 'zod';
|
|
3
|
-
|
|
4
|
-
import type { ChatMessage } from '../hook';
|
|
5
|
-
|
|
6
|
-
import styles from '../AiChat.module.css';
|
|
7
|
-
import clsx from 'clsx';
|
|
8
|
-
|
|
9
|
-
type ToolUseMessage = Extract<ChatMessage, { role: 'assistant'; messageType: 'tool_use' }>;
|
|
10
|
-
|
|
11
|
-
export default function ToolCall({
|
|
12
|
-
message,
|
|
13
|
-
}: {
|
|
14
|
-
message: Pick<ToolUseMessage, 'id' | 'toolName' | 'input'>;
|
|
15
|
-
}) {
|
|
16
|
-
// Render docs searches
|
|
17
|
-
if (message.toolName.endsWith('search_docs')) {
|
|
18
|
-
const parsed = z.object({ query: z.string() }).safeParse(message.input);
|
|
19
|
-
if (parsed.success) {
|
|
20
|
-
return (
|
|
21
|
-
<motion.li
|
|
22
|
-
layout="position"
|
|
23
|
-
data-message-role="assistant"
|
|
24
|
-
className={clsx(styles['chat-message'], styles['tool-use'])}
|
|
25
|
-
>
|
|
26
|
-
<p>
|
|
27
|
-
Searched for <em>{parsed.data.query}</em>
|
|
28
|
-
</p>
|
|
29
|
-
</motion.li>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// No other tool renderers yet
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
.hljs-github {
|
|
2
|
-
/* color: light-dark(#24292e, #c9d1d9); */
|
|
3
|
-
/* background: light-dark(#ffffff, #0d1117); */
|
|
4
|
-
|
|
5
|
-
.hljs-doctag,
|
|
6
|
-
.hljs-keyword,
|
|
7
|
-
.hljs-meta .hljs-keyword,
|
|
8
|
-
.hljs-template-tag,
|
|
9
|
-
.hljs-template-variable,
|
|
10
|
-
.hljs-type,
|
|
11
|
-
.hljs-variable.language_ {
|
|
12
|
-
color: light-dark(#d73a49, #ff7b72);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.hljs-title,
|
|
16
|
-
.hljs-title.class_,
|
|
17
|
-
.hljs-title.class_.inherited__,
|
|
18
|
-
.hljs-title.function_ {
|
|
19
|
-
color: light-dark(#6f42c1, #d2a8ff);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.hljs-attr,
|
|
23
|
-
.hljs-attribute,
|
|
24
|
-
.hljs-literal,
|
|
25
|
-
.hljs-meta,
|
|
26
|
-
.hljs-number,
|
|
27
|
-
.hljs-operator,
|
|
28
|
-
.hljs-variable,
|
|
29
|
-
.hljs-selector-attr,
|
|
30
|
-
.hljs-selector-class,
|
|
31
|
-
.hljs-selector-id {
|
|
32
|
-
color: light-dark(#005cc5, #79c0ff);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.hljs-regexp,
|
|
36
|
-
.hljs-string,
|
|
37
|
-
.hljs-meta .hljs-string {
|
|
38
|
-
color: light-dark(#032f62, #a5d6ff);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.hljs-built_in,
|
|
42
|
-
.hljs-symbol {
|
|
43
|
-
color: light-dark(#e36209, #ffa657);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.hljs-comment,
|
|
47
|
-
.hljs-code,
|
|
48
|
-
.hljs-formula {
|
|
49
|
-
color: light-dark(#6a737d, #8b949e);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.hljs-name,
|
|
53
|
-
.hljs-quote,
|
|
54
|
-
.hljs-selector-tag,
|
|
55
|
-
.hljs-selector-pseudo {
|
|
56
|
-
color: light-dark(#22863a, #7ee787);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.hljs-subst {
|
|
60
|
-
color: light-dark(#24292e, #c9d1d9);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.hljs-section {
|
|
64
|
-
color: light-dark(#005cc5, #1f6feb);
|
|
65
|
-
font-weight: bold;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.hljs-bullet {
|
|
69
|
-
color: light-dark(#735c0f, #f2cc60);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.hljs-emphasis {
|
|
73
|
-
color: light-dark(#24292e, #c9d1d9);
|
|
74
|
-
font-style: italic;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.hljs-strong {
|
|
78
|
-
color: light-dark(#24292e, #c9d1d9);
|
|
79
|
-
font-weight: bold;
|
|
80
|
-
}
|
|
81
|
-
}
|