@extrachill/chat 0.5.1 → 0.6.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/CHANGELOG.md +5 -0
- package/README.md +1 -1
- package/css/chat.css +184 -1
- package/dist/Chat.d.ts +22 -1
- package/dist/Chat.d.ts.map +1 -1
- package/dist/Chat.js +3 -2
- package/dist/client-context.d.ts +31 -0
- package/dist/client-context.d.ts.map +1 -0
- package/dist/client-context.js +100 -0
- package/dist/components/ChatMessages.d.ts +18 -1
- package/dist/components/ChatMessages.d.ts.map +1 -1
- package/dist/components/ChatMessages.js +5 -1
- package/dist/components/CopyTranscriptButton.d.ts +12 -0
- package/dist/components/CopyTranscriptButton.d.ts.map +1 -0
- package/dist/components/CopyTranscriptButton.js +26 -0
- package/dist/components/DiffCard.d.ts +40 -0
- package/dist/components/DiffCard.d.ts.map +1 -0
- package/dist/components/DiffCard.js +162 -0
- package/dist/components/ErrorBoundary.d.ts +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/diff.d.ts +27 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +109 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/transcript.d.ts +4 -0
- package/dist/transcript.d.ts.map +1 -0
- package/dist/transcript.js +32 -0
- package/package.json +1 -1
- package/src/Chat.tsx +51 -9
- package/src/client-context.ts +160 -0
- package/src/components/ChatMessages.tsx +26 -0
- package/src/components/CopyTranscriptButton.tsx +58 -0
- package/src/components/DiffCard.tsx +252 -0
- package/src/components/index.ts +1 -0
- package/src/diff.ts +159 -0
- package/src/index.ts +39 -1
- package/src/transcript.ts +41 -0
package/src/index.ts
CHANGED
|
@@ -31,6 +31,33 @@ export { normalizeMessage, normalizeConversation, normalizeSession } from './nor
|
|
|
31
31
|
// Markdown
|
|
32
32
|
export { markdownToHtml } from './markdown.ts';
|
|
33
33
|
|
|
34
|
+
// Transcript
|
|
35
|
+
export { formatChatAsMarkdown, copyChatAsMarkdown } from './transcript.ts';
|
|
36
|
+
|
|
37
|
+
// Diff helpers
|
|
38
|
+
export {
|
|
39
|
+
parseCanonicalDiff,
|
|
40
|
+
parseCanonicalDiffFromJson,
|
|
41
|
+
parseCanonicalDiffFromToolGroup,
|
|
42
|
+
type CanonicalDiffData,
|
|
43
|
+
type CanonicalDiffEditorData,
|
|
44
|
+
type CanonicalDiffItem,
|
|
45
|
+
type CanonicalDiffStatus,
|
|
46
|
+
type CanonicalDiffType,
|
|
47
|
+
} from './diff.ts';
|
|
48
|
+
|
|
49
|
+
// Client context
|
|
50
|
+
export {
|
|
51
|
+
getOrCreateClientContextRegistry,
|
|
52
|
+
registerClientContextProvider,
|
|
53
|
+
getClientContextMetadata,
|
|
54
|
+
useClientContextMetadata,
|
|
55
|
+
type ClientContextProvider,
|
|
56
|
+
type ClientContextProviderSnapshot,
|
|
57
|
+
type ClientContextSnapshot,
|
|
58
|
+
type ClientContextRegistry,
|
|
59
|
+
} from './client-context.ts';
|
|
60
|
+
|
|
34
61
|
// Components
|
|
35
62
|
export {
|
|
36
63
|
ChatMessage as ChatMessageComponent,
|
|
@@ -47,12 +74,23 @@ export {
|
|
|
47
74
|
type ChatInputProps,
|
|
48
75
|
} from './components/ChatInput.tsx';
|
|
49
76
|
|
|
77
|
+
export {
|
|
78
|
+
CopyTranscriptButton,
|
|
79
|
+
type CopyTranscriptButtonProps,
|
|
80
|
+
} from './components/CopyTranscriptButton.tsx';
|
|
81
|
+
|
|
50
82
|
export {
|
|
51
83
|
ToolMessage,
|
|
52
84
|
type ToolMessageProps,
|
|
53
85
|
type ToolGroup,
|
|
54
86
|
} from './components/ToolMessage.tsx';
|
|
55
87
|
|
|
88
|
+
export {
|
|
89
|
+
DiffCard,
|
|
90
|
+
type DiffCardProps,
|
|
91
|
+
type DiffData,
|
|
92
|
+
} from './components/DiffCard.tsx';
|
|
93
|
+
|
|
56
94
|
export {
|
|
57
95
|
TypingIndicator,
|
|
58
96
|
type TypingIndicatorProps,
|
|
@@ -81,4 +119,4 @@ export {
|
|
|
81
119
|
} from './hooks/useChat.ts';
|
|
82
120
|
|
|
83
121
|
// Composed
|
|
84
|
-
export { Chat, type ChatProps } from './Chat.tsx';
|
|
122
|
+
export { Chat, type ChatProps, type ChatSessionUi } from './Chat.tsx';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ChatMessage } from './types/index.ts';
|
|
2
|
+
|
|
3
|
+
export function formatChatAsMarkdown( messages: ChatMessage[] ): string {
|
|
4
|
+
return messages
|
|
5
|
+
.filter( ( message ) => {
|
|
6
|
+
if ( message.role === 'system' || message.role === 'tool_call' ) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return true;
|
|
11
|
+
} )
|
|
12
|
+
.map( ( message ) => {
|
|
13
|
+
const timestamp = message.timestamp
|
|
14
|
+
? new Date( message.timestamp ).toLocaleString()
|
|
15
|
+
: '';
|
|
16
|
+
const timestampStr = timestamp ? ` (${ timestamp })` : '';
|
|
17
|
+
|
|
18
|
+
if ( message.role === 'tool_result' ) {
|
|
19
|
+
const toolName = message.toolResult?.toolName ?? 'Tool';
|
|
20
|
+
const success = message.toolResult?.success;
|
|
21
|
+
const status = success === false ? 'FAILED' : 'SUCCESS';
|
|
22
|
+
return `**Tool Response (${ toolName } - ${ status })${ timestampStr }:**\n${ message.content }`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const role = message.role === 'user' ? 'User' : 'Assistant';
|
|
26
|
+
return `**${ role }${ timestampStr }:**\n${ message.content }`;
|
|
27
|
+
} )
|
|
28
|
+
.join( '\n\n---\n\n' );
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function copyChatAsMarkdown( messages: ChatMessage[] ): Promise< string > {
|
|
32
|
+
const markdown = formatChatAsMarkdown( messages );
|
|
33
|
+
|
|
34
|
+
if ( typeof navigator === 'undefined' || ! navigator.clipboard?.writeText ) {
|
|
35
|
+
throw new Error( 'Clipboard API is not available.' );
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await navigator.clipboard.writeText( markdown );
|
|
39
|
+
|
|
40
|
+
return markdown;
|
|
41
|
+
}
|