@extrachill/chat 0.5.1 → 0.7.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +1 -1
  3. package/css/chat.css +184 -1
  4. package/dist/Chat.d.ts +22 -1
  5. package/dist/Chat.d.ts.map +1 -1
  6. package/dist/Chat.js +3 -2
  7. package/dist/client-context.d.ts +31 -0
  8. package/dist/client-context.d.ts.map +1 -0
  9. package/dist/client-context.js +100 -0
  10. package/dist/components/ChatMessages.d.ts +18 -1
  11. package/dist/components/ChatMessages.d.ts.map +1 -1
  12. package/dist/components/ChatMessages.js +5 -1
  13. package/dist/components/CopyTranscriptButton.d.ts +12 -0
  14. package/dist/components/CopyTranscriptButton.d.ts.map +1 -0
  15. package/dist/components/CopyTranscriptButton.js +26 -0
  16. package/dist/components/DiffCard.d.ts +40 -0
  17. package/dist/components/DiffCard.d.ts.map +1 -0
  18. package/dist/components/DiffCard.js +162 -0
  19. package/dist/components/ErrorBoundary.d.ts +1 -1
  20. package/dist/components/index.d.ts +1 -0
  21. package/dist/components/index.d.ts.map +1 -1
  22. package/dist/components/index.js +1 -0
  23. package/dist/diff.d.ts +27 -0
  24. package/dist/diff.d.ts.map +1 -0
  25. package/dist/diff.js +109 -0
  26. package/dist/index.d.ts +6 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +8 -0
  29. package/dist/transcript.d.ts +4 -0
  30. package/dist/transcript.d.ts.map +1 -0
  31. package/dist/transcript.js +32 -0
  32. package/package.json +1 -1
  33. package/src/Chat.tsx +51 -9
  34. package/src/client-context.ts +160 -0
  35. package/src/components/ChatMessages.tsx +26 -0
  36. package/src/components/CopyTranscriptButton.tsx +58 -0
  37. package/src/components/DiffCard.tsx +252 -0
  38. package/src/components/index.ts +1 -0
  39. package/src/diff.ts +159 -0
  40. package/src/index.ts +39 -1
  41. 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
+ }