@copilotkit/svelte 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +325 -2
- package/dist/components/chat/CopilotChat.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChat.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatAssistantMessage.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatAssistantMessage.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatAttachmentQueue.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatAttachmentQueue.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatInput.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatInput.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatMessage.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatMessage.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatMessageView.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatMessageView.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatReasoningMessage.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatReasoningMessage.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatSuggestionPill.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatSuggestionPill.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatSuggestionView.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatSuggestionView.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatToggleButton.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatToggleButton.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatToolCallsView.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatToolCallsView.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatUserMessage.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatUserMessage.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotChatView.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotChatView.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotPopup.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotPopup.svelte.d.ts +1 -0
- package/dist/components/chat/CopilotSidebar.d.svelte.ts +1 -0
- package/dist/components/chat/CopilotSidebar.svelte.d.ts +1 -0
- package/dist/components/chat/StreamMarkdown.d.svelte.ts +1 -0
- package/dist/components/chat/StreamMarkdown.svelte.d.ts +1 -0
- package/dist/components/chat/chat-config-context.d.svelte.ts +10 -0
- package/dist/components/chat/chat-config-context.svelte.d.ts +10 -0
- package/dist/components/chat/chat-config-context.svelte.d.ts.map +1 -0
- package/dist/components/chat/dispatch-after-active-run.d.ts +3 -0
- package/dist/components/chat/dispatch-after-active-run.d.ts.map +1 -0
- package/dist/components/chat/markdown/CodeBlock.svelte.d.ts +1 -0
- package/dist/components/chat/markdown/CodeSpan.svelte.d.ts +1 -0
- package/dist/components/chat/markdown/Table.svelte.d.ts +1 -0
- package/dist/components/chat/markdown/TableBody.svelte.d.ts +1 -0
- package/dist/components/chat/markdown/TableCell.svelte.d.ts +1 -0
- package/dist/components/chat/markdown/TableHead.svelte.d.ts +1 -0
- package/dist/components/chat/markdown/TableRow.svelte.d.ts +1 -0
- package/dist/components/chat/markdown/highlight.d.ts +8 -0
- package/dist/components/chat/markdown/highlight.d.ts.map +1 -0
- package/dist/components/chat/media-parts.d.ts +11 -0
- package/dist/components/chat/media-parts.d.ts.map +1 -0
- package/dist/components/chat/types.d.ts +137 -0
- package/dist/components/chat/types.d.ts.map +1 -0
- package/dist/components/icons/index.d.ts +2 -0
- package/dist/components/icons/index.d.ts.map +1 -0
- package/dist/components/index.d.ts +18 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/hooks/connect-agent-context.svelte.d.ts +9 -0
- package/dist/hooks/connect-agent-context.svelte.d.ts.map +1 -0
- package/dist/hooks/create-agent.svelte.d.ts +23 -0
- package/dist/hooks/create-agent.svelte.d.ts.map +1 -0
- package/dist/hooks/create-attachments.svelte.d.ts +33 -0
- package/dist/hooks/create-attachments.svelte.d.ts.map +1 -0
- package/dist/hooks/create-capabilities.svelte.d.ts +6 -0
- package/dist/hooks/create-capabilities.svelte.d.ts.map +1 -0
- package/dist/hooks/create-interrupt.svelte.d.ts +24 -0
- package/dist/hooks/create-interrupt.svelte.d.ts.map +1 -0
- package/dist/hooks/create-suggestions.svelte.d.ts +12 -0
- package/dist/hooks/create-suggestions.svelte.d.ts.map +1 -0
- package/dist/hooks/create-threads.svelte.d.ts +33 -0
- package/dist/hooks/create-threads.svelte.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +20 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/load-katex-styles.svelte.d.ts +2 -0
- package/dist/hooks/load-katex-styles.svelte.d.ts.map +1 -0
- package/dist/hooks/register-frontend-tool.svelte.d.ts +3 -0
- package/dist/hooks/register-frontend-tool.svelte.d.ts.map +1 -0
- package/dist/hooks/register-human-in-the-loop.svelte.d.ts +3 -0
- package/dist/hooks/register-human-in-the-loop.svelte.d.ts.map +1 -0
- package/dist/hooks/register-render-tool-call.svelte.d.ts +30 -0
- package/dist/hooks/register-render-tool-call.svelte.d.ts.map +1 -0
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +3037 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/svelte-core.d.ts +53 -0
- package/dist/lib/svelte-core.d.ts.map +1 -0
- package/dist/providers/CopilotKitProvider.svelte.d.ts +1 -0
- package/dist/providers/CopilotKitProvider.types.d.ts +47 -0
- package/dist/providers/CopilotKitProvider.types.d.ts.map +1 -0
- package/dist/providers/context.d.ts +19 -0
- package/dist/providers/context.d.ts.map +1 -0
- package/dist/providers/index.d.ts +6 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/useCopilotKit.d.ts +3 -0
- package/dist/providers/useCopilotKit.d.ts.map +1 -0
- package/dist/styles.css +3 -0
- package/dist/types/a2ui.d.ts +5 -0
- package/dist/types/a2ui.d.ts.map +1 -0
- package/dist/types/activity-message-renderer.d.ts +17 -0
- package/dist/types/activity-message-renderer.d.ts.map +1 -0
- package/dist/types/custom-message-renderer.d.ts +18 -0
- package/dist/types/custom-message-renderer.d.ts.map +1 -0
- package/dist/types/frontend-tool.d.ts +6 -0
- package/dist/types/frontend-tool.d.ts.map +1 -0
- package/dist/types/human-in-the-loop.d.ts +31 -0
- package/dist/types/human-in-the-loop.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/interrupt.d.ts +23 -0
- package/dist/types/interrupt.d.ts.map +1 -0
- package/dist/types/sandbox-function.d.ts +8 -0
- package/dist/types/sandbox-function.d.ts.map +1 -0
- package/dist/types/tool-call-renderer.d.ts +29 -0
- package/dist/types/tool-call-renderer.d.ts.map +1 -0
- package/package.json +114 -3
- package/src/app.d.ts +7 -0
- package/src/components/chat/CopilotChat.svelte +222 -0
- package/src/components/chat/CopilotChatAssistantMessage.svelte +295 -0
- package/src/components/chat/CopilotChatAttachmentQueue.svelte +241 -0
- package/src/components/chat/CopilotChatInput.svelte +192 -0
- package/src/components/chat/CopilotChatMessage.svelte +37 -0
- package/src/components/chat/CopilotChatMessageView.svelte +76 -0
- package/src/components/chat/CopilotChatReasoningMessage.svelte +210 -0
- package/src/components/chat/CopilotChatSuggestionPill.svelte +66 -0
- package/src/components/chat/CopilotChatSuggestionView.svelte +36 -0
- package/src/components/chat/CopilotChatToggleButton.svelte +47 -0
- package/src/components/chat/CopilotChatToolCallsView.svelte +187 -0
- package/src/components/chat/CopilotChatUserMessage.svelte +312 -0
- package/src/components/chat/CopilotChatView.svelte +177 -0
- package/src/components/chat/CopilotPopup.svelte +187 -0
- package/src/components/chat/CopilotSidebar.svelte +138 -0
- package/src/components/chat/StreamMarkdown.svelte +30 -0
- package/src/components/chat/chat-config-context.svelte.ts +28 -0
- package/src/components/chat/dispatch-after-active-run.ts +40 -0
- package/src/components/chat/markdown/CodeBlock.svelte +78 -0
- package/src/components/chat/markdown/CodeSpan.svelte +29 -0
- package/src/components/chat/markdown/Table.svelte +15 -0
- package/src/components/chat/markdown/TableBody.svelte +11 -0
- package/src/components/chat/markdown/TableCell.svelte +29 -0
- package/src/components/chat/markdown/TableHead.svelte +11 -0
- package/src/components/chat/markdown/TableRow.svelte +11 -0
- package/src/components/chat/markdown/highlight.ts +96 -0
- package/src/components/chat/media-parts.ts +34 -0
- package/src/components/chat/types.ts +176 -0
- package/src/components/icons/index.ts +23 -0
- package/src/components/index.ts +17 -0
- package/src/hooks/connect-agent-context.svelte.ts +46 -0
- package/src/hooks/create-agent.svelte.ts +420 -0
- package/src/hooks/create-attachments.svelte.ts +311 -0
- package/src/hooks/create-capabilities.svelte.ts +26 -0
- package/src/hooks/create-interrupt.svelte.ts +467 -0
- package/src/hooks/create-suggestions.svelte.ts +84 -0
- package/src/hooks/create-threads.svelte.ts +337 -0
- package/src/hooks/index.ts +45 -0
- package/src/hooks/load-katex-styles.svelte.ts +13 -0
- package/src/hooks/register-frontend-tool.svelte.ts +45 -0
- package/src/hooks/register-human-in-the-loop.svelte.ts +118 -0
- package/src/hooks/register-render-tool-call.svelte.ts +75 -0
- package/src/index.ts +6 -0
- package/src/lib/svelte-core.ts +230 -0
- package/src/providers/CopilotKitProvider.svelte +291 -0
- package/src/providers/CopilotKitProvider.types.ts +55 -0
- package/src/providers/context.ts +26 -0
- package/src/providers/index.ts +5 -0
- package/src/providers/useCopilotKit.ts +11 -0
- package/src/styles/globals.css +691 -0
- package/src/styles.d.ts +1 -0
- package/src/types/a2ui.ts +5 -0
- package/src/types/activity-message-renderer.ts +21 -0
- package/src/types/custom-message-renderer.ts +23 -0
- package/src/types/frontend-tool.ts +8 -0
- package/src/types/human-in-the-loop.ts +40 -0
- package/src/types/index.ts +8 -0
- package/src/types/interrupt.ts +32 -0
- package/src/types/sandbox-function.ts +8 -0
- package/src/types/tool-call-renderer.ts +36 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { formatFileSize, getDocumentIcon, getSourceUrl } from "@copilotkit/shared";
|
|
3
|
+
import type { Attachment } from "@copilotkit/shared";
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
attachments = [] as Attachment[],
|
|
7
|
+
onRemoveAttachment,
|
|
8
|
+
}: {
|
|
9
|
+
attachments?: Attachment[];
|
|
10
|
+
onRemoveAttachment?: (id: string) => void;
|
|
11
|
+
} = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
{#if attachments.length > 0}
|
|
15
|
+
<div data-testid="copilot-attachment-queue" class="copilotkit-attachment-queue">
|
|
16
|
+
{#each attachments as attachment (attachment.id)}
|
|
17
|
+
<div
|
|
18
|
+
data-testid="copilot-chat-attachment-item"
|
|
19
|
+
data-card-type={attachment.type}
|
|
20
|
+
class="copilotkit-attachment-card"
|
|
21
|
+
class:is-media={attachment.type === "image" || attachment.type === "video"}
|
|
22
|
+
>
|
|
23
|
+
{#if attachment.status === "uploading"}
|
|
24
|
+
<div
|
|
25
|
+
data-testid="copilot-chat-attachment-uploading-overlay"
|
|
26
|
+
class="copilotkit-attachment-uploading"
|
|
27
|
+
aria-label="Uploading"
|
|
28
|
+
>
|
|
29
|
+
<div class="copilotkit-attachment-spinner"></div>
|
|
30
|
+
</div>
|
|
31
|
+
{/if}
|
|
32
|
+
{#if attachment.status === "ready"}
|
|
33
|
+
{#if attachment.type === "image"}
|
|
34
|
+
<img
|
|
35
|
+
src={getSourceUrl(attachment.source)}
|
|
36
|
+
alt={attachment.filename || "Image attachment"}
|
|
37
|
+
class="copilotkit-attachment-image"
|
|
38
|
+
data-testid="copilot-chat-attachment-image-thumbnail"
|
|
39
|
+
/>
|
|
40
|
+
{:else if attachment.type === "video"}
|
|
41
|
+
{#if attachment.thumbnail}
|
|
42
|
+
<img
|
|
43
|
+
src={attachment.thumbnail}
|
|
44
|
+
alt={attachment.filename || "Video thumbnail"}
|
|
45
|
+
class="copilotkit-attachment-image"
|
|
46
|
+
data-testid="copilot-chat-attachment-video-thumbnail"
|
|
47
|
+
/>
|
|
48
|
+
{:else}
|
|
49
|
+
<video
|
|
50
|
+
src={getSourceUrl(attachment.source)}
|
|
51
|
+
preload="metadata"
|
|
52
|
+
muted
|
|
53
|
+
class="copilotkit-attachment-image"
|
|
54
|
+
data-testid="copilot-chat-attachment-video-fallback"
|
|
55
|
+
></video>
|
|
56
|
+
{/if}
|
|
57
|
+
{:else if attachment.type === "audio"}
|
|
58
|
+
<div class="copilotkit-attachment-audio">
|
|
59
|
+
<audio
|
|
60
|
+
src={getSourceUrl(attachment.source)}
|
|
61
|
+
controls
|
|
62
|
+
preload="metadata"
|
|
63
|
+
class="copilotkit-attachment-audio-player"
|
|
64
|
+
data-testid="copilot-chat-attachment-audio-player"
|
|
65
|
+
></audio>
|
|
66
|
+
{#if attachment.filename}
|
|
67
|
+
<span class="copilotkit-attachment-name">{attachment.filename}</span>
|
|
68
|
+
{/if}
|
|
69
|
+
</div>
|
|
70
|
+
{:else}
|
|
71
|
+
<div class="copilotkit-attachment-doc">
|
|
72
|
+
<div class="copilotkit-attachment-doc-icon">
|
|
73
|
+
{getDocumentIcon(attachment.source.mimeType ?? "")}
|
|
74
|
+
</div>
|
|
75
|
+
<div class="copilotkit-attachment-doc-meta">
|
|
76
|
+
<span
|
|
77
|
+
class="copilotkit-attachment-name"
|
|
78
|
+
data-testid="copilot-chat-attachment-document-filename"
|
|
79
|
+
>
|
|
80
|
+
{attachment.filename || "Document"}
|
|
81
|
+
</span>
|
|
82
|
+
{#if attachment.size != null}
|
|
83
|
+
<span class="copilotkit-attachment-size">
|
|
84
|
+
{formatFileSize(attachment.size)}
|
|
85
|
+
</span>
|
|
86
|
+
{/if}
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
{/if}
|
|
90
|
+
{:else}
|
|
91
|
+
<div
|
|
92
|
+
class="copilotkit-attachment-placeholder"
|
|
93
|
+
data-testid="copilot-chat-attachment-placeholder"
|
|
94
|
+
></div>
|
|
95
|
+
{/if}
|
|
96
|
+
<button
|
|
97
|
+
type="button"
|
|
98
|
+
class="copilotkit-attachment-remove"
|
|
99
|
+
aria-label="Remove attachment"
|
|
100
|
+
onclick={() => onRemoveAttachment?.(attachment.id)}
|
|
101
|
+
>
|
|
102
|
+
✕
|
|
103
|
+
</button>
|
|
104
|
+
</div>
|
|
105
|
+
{/each}
|
|
106
|
+
</div>
|
|
107
|
+
{/if}
|
|
108
|
+
|
|
109
|
+
<style>
|
|
110
|
+
.copilotkit-attachment-queue {
|
|
111
|
+
display: flex;
|
|
112
|
+
flex-wrap: wrap;
|
|
113
|
+
gap: 8px;
|
|
114
|
+
padding: 8px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.copilotkit-attachment-card {
|
|
118
|
+
position: relative;
|
|
119
|
+
display: inline-flex;
|
|
120
|
+
border-radius: 8px;
|
|
121
|
+
overflow: hidden;
|
|
122
|
+
border: 1px solid #e5e7eb;
|
|
123
|
+
background: #fff;
|
|
124
|
+
padding: 8px 28px 8px 12px;
|
|
125
|
+
max-width: 240px;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.copilotkit-attachment-card.is-media {
|
|
129
|
+
width: 72px;
|
|
130
|
+
height: 72px;
|
|
131
|
+
padding: 0 0 0 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.copilotkit-attachment-image {
|
|
135
|
+
width: 100%;
|
|
136
|
+
height: 100%;
|
|
137
|
+
object-fit: cover;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.copilotkit-attachment-uploading {
|
|
141
|
+
position: absolute;
|
|
142
|
+
inset: 0;
|
|
143
|
+
display: flex;
|
|
144
|
+
align-items: center;
|
|
145
|
+
justify-content: center;
|
|
146
|
+
background: rgba(0, 0, 0, 0.4);
|
|
147
|
+
z-index: 10;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.copilotkit-attachment-spinner {
|
|
151
|
+
width: 20px;
|
|
152
|
+
height: 20px;
|
|
153
|
+
border: 2px solid #fff;
|
|
154
|
+
border-top-color: transparent;
|
|
155
|
+
border-radius: 9999px;
|
|
156
|
+
animation: copilotkit-spin 0.8s linear infinite;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@keyframes copilotkit-spin {
|
|
160
|
+
to {
|
|
161
|
+
transform: rotate(360deg);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.copilotkit-attachment-audio {
|
|
166
|
+
display: flex;
|
|
167
|
+
flex-direction: column;
|
|
168
|
+
gap: 4px;
|
|
169
|
+
width: 100%;
|
|
170
|
+
min-width: 200px;
|
|
171
|
+
max-width: 280px;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.copilotkit-attachment-audio-player {
|
|
175
|
+
width: 100%;
|
|
176
|
+
height: 32px;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.copilotkit-attachment-doc {
|
|
180
|
+
display: flex;
|
|
181
|
+
align-items: center;
|
|
182
|
+
gap: 8px;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.copilotkit-attachment-doc-icon {
|
|
186
|
+
width: 32px;
|
|
187
|
+
height: 32px;
|
|
188
|
+
border-radius: 6px;
|
|
189
|
+
background: #3b82f6;
|
|
190
|
+
color: #fff;
|
|
191
|
+
display: flex;
|
|
192
|
+
align-items: center;
|
|
193
|
+
justify-content: center;
|
|
194
|
+
font-size: 10px;
|
|
195
|
+
font-weight: 600;
|
|
196
|
+
flex-shrink: 0;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.copilotkit-attachment-doc-meta {
|
|
200
|
+
display: flex;
|
|
201
|
+
flex-direction: column;
|
|
202
|
+
min-width: 0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.copilotkit-attachment-name {
|
|
206
|
+
font-size: 12px;
|
|
207
|
+
font-weight: 500;
|
|
208
|
+
word-break: break-all;
|
|
209
|
+
line-height: 1.25;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.copilotkit-attachment-size {
|
|
213
|
+
font-size: 11px;
|
|
214
|
+
color: #6b7280;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.copilotkit-attachment-placeholder {
|
|
218
|
+
width: 100%;
|
|
219
|
+
height: 100%;
|
|
220
|
+
min-height: 40px;
|
|
221
|
+
background: rgba(107, 114, 128, 0.2);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.copilotkit-attachment-remove {
|
|
225
|
+
position: absolute;
|
|
226
|
+
top: 4px;
|
|
227
|
+
right: 4px;
|
|
228
|
+
background: rgba(0, 0, 0, 0.6);
|
|
229
|
+
color: #fff;
|
|
230
|
+
border: none;
|
|
231
|
+
border-radius: 9999px;
|
|
232
|
+
width: 20px;
|
|
233
|
+
height: 20px;
|
|
234
|
+
display: flex;
|
|
235
|
+
align-items: center;
|
|
236
|
+
justify-content: center;
|
|
237
|
+
cursor: pointer;
|
|
238
|
+
font-size: 10px;
|
|
239
|
+
z-index: 20;
|
|
240
|
+
}
|
|
241
|
+
</style>
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { CopilotChatInputMode, ToolsMenuItem } from "./types";
|
|
3
|
+
import type { Attachment } from "@copilotkit/shared";
|
|
4
|
+
import CopilotChatAttachmentQueue from "./CopilotChatAttachmentQueue.svelte";
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
value: initialValue = "",
|
|
8
|
+
isRunning = false,
|
|
9
|
+
onSubmit,
|
|
10
|
+
onStop,
|
|
11
|
+
onInputChange,
|
|
12
|
+
placeholder = "Type a message...",
|
|
13
|
+
attachments = [] as Attachment[],
|
|
14
|
+
canAddFile = false,
|
|
15
|
+
onAddFile,
|
|
16
|
+
onRemoveAttachment,
|
|
17
|
+
}: {
|
|
18
|
+
value?: string;
|
|
19
|
+
isRunning?: boolean;
|
|
20
|
+
inputMode?: CopilotChatInputMode;
|
|
21
|
+
toolsMenu?: (ToolsMenuItem | "-")[];
|
|
22
|
+
onSubmit: (value: string) => void;
|
|
23
|
+
onStop?: () => void;
|
|
24
|
+
onInputChange: (value: string) => void;
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
attachments?: Attachment[];
|
|
27
|
+
canAddFile?: boolean;
|
|
28
|
+
onAddFile?: () => void;
|
|
29
|
+
onRemoveAttachment?: (id: string) => void;
|
|
30
|
+
} = $props();
|
|
31
|
+
|
|
32
|
+
let localValue = $derived(initialValue);
|
|
33
|
+
let hasUploading = $derived(attachments.some((a) => a.status === "uploading"));
|
|
34
|
+
let canSend = $derived(
|
|
35
|
+
isRunning ? true : hasUploading ? false : localValue.trim().length > 0 || attachments.length > 0,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
39
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
40
|
+
if (e.isComposing) return;
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
send();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function send() {
|
|
47
|
+
// Mirror React/Vue: block sends while uploads are in flight. Attachments
|
|
48
|
+
// alone (no text) are a valid send.
|
|
49
|
+
if (hasUploading || isRunning) return;
|
|
50
|
+
const trimmed = localValue.trim();
|
|
51
|
+
if (!trimmed && attachments.length === 0) return;
|
|
52
|
+
onSubmit(trimmed);
|
|
53
|
+
localValue = "";
|
|
54
|
+
onInputChange("");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function handleInput() {
|
|
58
|
+
onInputChange(localValue);
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<div class="copilotkit-input">
|
|
63
|
+
{#if attachments.length > 0}
|
|
64
|
+
<CopilotChatAttachmentQueue {attachments} {onRemoveAttachment} />
|
|
65
|
+
{/if}
|
|
66
|
+
{#if hasUploading}
|
|
67
|
+
<div class="copilotkit-upload-hint" role="status">
|
|
68
|
+
Uploading attachments…
|
|
69
|
+
</div>
|
|
70
|
+
{/if}
|
|
71
|
+
<div class="copilotkit-input-row">
|
|
72
|
+
{#if canAddFile}
|
|
73
|
+
<button
|
|
74
|
+
type="button"
|
|
75
|
+
class="copilotkit-attach-btn"
|
|
76
|
+
aria-label="Add file"
|
|
77
|
+
onclick={onAddFile}
|
|
78
|
+
>
|
|
79
|
+
+
|
|
80
|
+
</button>
|
|
81
|
+
{/if}
|
|
82
|
+
<textarea
|
|
83
|
+
class="copilotkit-textarea"
|
|
84
|
+
value={localValue}
|
|
85
|
+
oninput={(e) => { localValue = (e.target as HTMLTextAreaElement).value; handleInput(); }}
|
|
86
|
+
onkeydown={handleKeydown}
|
|
87
|
+
placeholder={placeholder}
|
|
88
|
+
rows="1"
|
|
89
|
+
disabled={isRunning}
|
|
90
|
+
></textarea>
|
|
91
|
+
<button
|
|
92
|
+
type="button"
|
|
93
|
+
class="copilotkit-send-btn"
|
|
94
|
+
onclick={isRunning && onStop ? onStop : send}
|
|
95
|
+
disabled={!isRunning && !canSend}
|
|
96
|
+
>
|
|
97
|
+
{#if isRunning}
|
|
98
|
+
■
|
|
99
|
+
{:else}
|
|
100
|
+
↑
|
|
101
|
+
{/if}
|
|
102
|
+
</button>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<style>
|
|
107
|
+
.copilotkit-input {
|
|
108
|
+
border-top: 1px solid #e5e7eb;
|
|
109
|
+
padding: 12px 16px;
|
|
110
|
+
background: #fff;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.copilotkit-input-row {
|
|
114
|
+
display: flex;
|
|
115
|
+
gap: 8px;
|
|
116
|
+
align-items: flex-end;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.copilotkit-textarea {
|
|
120
|
+
flex: 1;
|
|
121
|
+
resize: none;
|
|
122
|
+
border: 1px solid #d1d5db;
|
|
123
|
+
border-radius: 8px;
|
|
124
|
+
padding: 10px 12px;
|
|
125
|
+
font-size: 14px;
|
|
126
|
+
line-height: 1.5;
|
|
127
|
+
font-family: inherit;
|
|
128
|
+
outline: none;
|
|
129
|
+
min-height: 40px;
|
|
130
|
+
max-height: 200px;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.copilotkit-textarea:focus {
|
|
134
|
+
border-color: #3b82f6;
|
|
135
|
+
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.copilotkit-textarea:disabled {
|
|
139
|
+
opacity: 0.6;
|
|
140
|
+
cursor: not-allowed;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.copilotkit-send-btn {
|
|
144
|
+
width: 40px;
|
|
145
|
+
height: 40px;
|
|
146
|
+
border-radius: 8px;
|
|
147
|
+
border: none;
|
|
148
|
+
background: #3b82f6;
|
|
149
|
+
color: #fff;
|
|
150
|
+
font-size: 18px;
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
display: flex;
|
|
153
|
+
align-items: center;
|
|
154
|
+
justify-content: center;
|
|
155
|
+
flex-shrink: 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.copilotkit-send-btn:disabled {
|
|
159
|
+
opacity: 0.4;
|
|
160
|
+
cursor: not-allowed;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.copilotkit-send-btn:hover:not(:disabled) {
|
|
164
|
+
background: #2563eb;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.copilotkit-attach-btn {
|
|
168
|
+
width: 40px;
|
|
169
|
+
height: 40px;
|
|
170
|
+
border-radius: 8px;
|
|
171
|
+
border: 1px solid #d1d5db;
|
|
172
|
+
background: #f9fafb;
|
|
173
|
+
color: #374151;
|
|
174
|
+
font-size: 20px;
|
|
175
|
+
line-height: 1;
|
|
176
|
+
cursor: pointer;
|
|
177
|
+
display: flex;
|
|
178
|
+
align-items: center;
|
|
179
|
+
justify-content: center;
|
|
180
|
+
flex-shrink: 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.copilotkit-attach-btn:hover {
|
|
184
|
+
background: #f3f4f6;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.copilotkit-upload-hint {
|
|
188
|
+
font-size: 12px;
|
|
189
|
+
color: #6b7280;
|
|
190
|
+
padding: 0 2px 8px;
|
|
191
|
+
}
|
|
192
|
+
</style>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Message, AssistantMessage, UserMessage, ReasoningMessage } from "@ag-ui/core";
|
|
3
|
+
import CopilotChatAssistantMessage from "./CopilotChatAssistantMessage.svelte";
|
|
4
|
+
import CopilotChatUserMessage from "./CopilotChatUserMessage.svelte";
|
|
5
|
+
import CopilotChatReasoningMessage from "./CopilotChatReasoningMessage.svelte";
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
message,
|
|
9
|
+
messages = [] as Message[],
|
|
10
|
+
isRunning = false,
|
|
11
|
+
}: {
|
|
12
|
+
message: Message;
|
|
13
|
+
messages?: Message[];
|
|
14
|
+
isRunning?: boolean;
|
|
15
|
+
} = $props();
|
|
16
|
+
|
|
17
|
+
function isAssistant(msg: Message): msg is AssistantMessage {
|
|
18
|
+
return msg.role === "assistant";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isUser(msg: Message): msg is UserMessage {
|
|
22
|
+
return msg.role === "user";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isReasoning(msg: Message): msg is ReasoningMessage {
|
|
26
|
+
return msg.role === "reasoning";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
{#if isReasoning(message)}
|
|
32
|
+
<CopilotChatReasoningMessage {message} {messages} {isRunning} />
|
|
33
|
+
{:else if isAssistant(message)}
|
|
34
|
+
<CopilotChatAssistantMessage {message} {messages} {isRunning} />
|
|
35
|
+
{:else if isUser(message)}
|
|
36
|
+
<CopilotChatUserMessage {message} />
|
|
37
|
+
{/if}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick } from "svelte";
|
|
3
|
+
import type { Message } from "@ag-ui/core";
|
|
4
|
+
import type { Snippet } from "svelte";
|
|
5
|
+
import CopilotChatMessage from "./CopilotChatMessage.svelte";
|
|
6
|
+
import { normalizeAutoScroll, type AutoScrollMode } from "./types";
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
messages = [] as Message[],
|
|
10
|
+
isRunning = false,
|
|
11
|
+
autoScroll = true as AutoScrollMode | boolean,
|
|
12
|
+
sentMessageId = null,
|
|
13
|
+
footer,
|
|
14
|
+
}: {
|
|
15
|
+
messages?: Message[];
|
|
16
|
+
isRunning?: boolean;
|
|
17
|
+
autoScroll?: AutoScrollMode | boolean;
|
|
18
|
+
sentMessageId?: string | null;
|
|
19
|
+
footer?: Snippet;
|
|
20
|
+
} = $props();
|
|
21
|
+
|
|
22
|
+
let container: HTMLDivElement | undefined = $state();
|
|
23
|
+
const autoScrollMode = $derived(normalizeAutoScroll(autoScroll));
|
|
24
|
+
let handledSentMessageId: string | null = null;
|
|
25
|
+
|
|
26
|
+
$effect(() => {
|
|
27
|
+
if (!container) return;
|
|
28
|
+
if (autoScrollMode === "pin-to-bottom") {
|
|
29
|
+
void messages;
|
|
30
|
+
void isRunning;
|
|
31
|
+
queueMicrotask(() => {
|
|
32
|
+
if (!container) return;
|
|
33
|
+
container.scrollTop = container.scrollHeight;
|
|
34
|
+
});
|
|
35
|
+
} else if (
|
|
36
|
+
autoScrollMode === "pin-to-send" &&
|
|
37
|
+
sentMessageId &&
|
|
38
|
+
sentMessageId !== handledSentMessageId
|
|
39
|
+
) {
|
|
40
|
+
handledSentMessageId = sentMessageId;
|
|
41
|
+
void tick().then(() => {
|
|
42
|
+
const sentMessage = [...(container?.querySelectorAll<HTMLElement>(
|
|
43
|
+
"[data-message-id]",
|
|
44
|
+
) ?? [])].find((element) => element.dataset.messageId === sentMessageId);
|
|
45
|
+
if (sentMessage && container) {
|
|
46
|
+
const containerTop = container.getBoundingClientRect().top;
|
|
47
|
+
const messageTop = sentMessage.getBoundingClientRect().top;
|
|
48
|
+
container.scrollTop += messageTop - containerTop;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<div bind:this={container} class="copilotkit-message-list">
|
|
56
|
+
<div class="copilotkit-message-list-padding cpk:px-4">
|
|
57
|
+
<div class="copilotkit-message-list-inner cpk:w-full cpk:max-w-3xl cpk:mx-auto">
|
|
58
|
+
{#each messages as msg (msg.id)}
|
|
59
|
+
<CopilotChatMessage message={msg} {messages} {isRunning} />
|
|
60
|
+
{/each}
|
|
61
|
+
{#if footer}
|
|
62
|
+
<div class="copilotkit-message-list-footer cpk:mt-4">
|
|
63
|
+
{@render footer()}
|
|
64
|
+
</div>
|
|
65
|
+
{/if}
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<style>
|
|
71
|
+
.copilotkit-message-list {
|
|
72
|
+
flex: 1;
|
|
73
|
+
overflow-y: auto;
|
|
74
|
+
padding: 8px 0;
|
|
75
|
+
}
|
|
76
|
+
</style>
|