@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Atai Barkai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,326 @@
|
|
|
1
|
-
|
|
1
|
+
Community-maintained Svelte 5 components and runes for CopilotKit. This package
|
|
2
|
+
is tested with `@copilotkit/core` **1.87.1**, pinned exactly because the Svelte
|
|
3
|
+
bindings use internal thread APIs. Its releases are independent of the core
|
|
4
|
+
packages and it is not part of the CopilotKit monorepo build.
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
The package provides a context provider, rune-based state factories,
|
|
7
|
+
lifecycle-managed tool registrations, and chat components backed by
|
|
8
|
+
[Copilot Runtime](https://docs.copilotkit.ai/backend/copilot-runtime).
|
|
9
|
+
|
|
10
|
+
The package covers chat and agent interaction. Check the compatibility table
|
|
11
|
+
below before replacing a frontend that depends on advanced renderers or
|
|
12
|
+
developer tooling.
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
- Svelte 5
|
|
17
|
+
- Node.js 20 or later
|
|
18
|
+
- A Copilot Runtime endpoint
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @copilotkit/svelte
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Add `zod` when you register typed frontend tools.
|
|
27
|
+
|
|
28
|
+
## Add the provider and styles
|
|
29
|
+
|
|
30
|
+
Place the provider above every component that uses a CopilotKit factory or
|
|
31
|
+
registration. Import the public stylesheet once at the application root.
|
|
32
|
+
|
|
33
|
+
```svelte
|
|
34
|
+
<script lang="ts">
|
|
35
|
+
import "@copilotkit/svelte/styles.css";
|
|
36
|
+
import { CopilotKitProvider } from "@copilotkit/svelte";
|
|
37
|
+
|
|
38
|
+
let { children } = $props();
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<CopilotKitProvider runtimeUrl="/api/copilotkit">
|
|
42
|
+
{@render children()}
|
|
43
|
+
</CopilotKitProvider>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Global CSS resets
|
|
47
|
+
|
|
48
|
+
The stylesheet ships in a low-priority layer and only targets elements inside
|
|
49
|
+
`[data-copilotkit]`, so it does not reset your application's own markup. Avoid
|
|
50
|
+
adding `* { margin: 0; padding: 0 }` or similar resets at the application root:
|
|
51
|
+
they also strip spacing from the chat's internal elements, which makes message
|
|
52
|
+
spacing and markdown blocks collapse. Reset only what you need, for example:
|
|
53
|
+
|
|
54
|
+
```css
|
|
55
|
+
*,
|
|
56
|
+
*::before,
|
|
57
|
+
*::after {
|
|
58
|
+
box-sizing: border-box;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Render chat
|
|
63
|
+
|
|
64
|
+
```svelte
|
|
65
|
+
<script lang="ts">
|
|
66
|
+
import { CopilotChat } from "@copilotkit/svelte";
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<div class="chat-shell">
|
|
70
|
+
<CopilotChat agentId="default" />
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<style>
|
|
74
|
+
.chat-shell {
|
|
75
|
+
height: 700px;
|
|
76
|
+
}
|
|
77
|
+
</style>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The runtime must expose the selected agent ID. If `agentId` is omitted, the
|
|
81
|
+
chat uses the runtime's `default` agent.
|
|
82
|
+
|
|
83
|
+
## Compatibility
|
|
84
|
+
|
|
85
|
+
| Area | Initial Svelte support | Notes |
|
|
86
|
+
| -------------------------------------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
87
|
+
| Runtime connection and AG-UI streaming | Supported | Includes message updates, run state, and agent state invalidation. |
|
|
88
|
+
| Inline chat | Supported | Use `CopilotChat`; lower-level chat and message components are also exported. |
|
|
89
|
+
| Popup and sidebar chat | Supported | `CopilotPopup` and `CopilotSidebar` keep the chat mounted while closed, so generated thread state persists across open/close. Pass an explicit `threadId` to share state across surfaces. |
|
|
90
|
+
| Frontend tools | Supported | Register with `registerFrontendTool`; registrations clean up with their component. |
|
|
91
|
+
| Agent context | Supported | Connect reactive application data with `connectAgentContext`. |
|
|
92
|
+
| Suggestions | Observation only | `createSuggestions` observes suggestions already present in core; Svelte does not yet register suggestion-generation configuration. |
|
|
93
|
+
| Threads | Supported headless API | `createThreads` lists pages, fetches more, and renames/archives/unarchives/deletes threads over the core runtime transport, with reactive `agentId`/`enabled`/`limit`/`includeArchived` inputs and store cleanup on unmount. A prebuilt threads drawer is not included. |
|
|
94
|
+
| Interrupts | Headless | Observe and resolve AG-UI interrupts with `createInterrupt`. |
|
|
95
|
+
| Attachments | Supported | `createAttachments` validates/uploads files (drag-drop, picker, scoped paste) and `CopilotChat` wires it into the composer with `attachments={{ enabled: true }}`. See the attachments example below. |
|
|
96
|
+
| Tool-call rendering | Supported in prebuilt chat | Renderers from `registerRenderToolCall` (including the `"*"` wildcard fallback) mount inside `CopilotChat`; a `toolCall` slot override still wins when provided. Unmatched calls fall back to generic status. |
|
|
97
|
+
| Human approval | Supported with custom UI | `registerHumanInTheLoop` mounts its renderer in the prebuilt chat and matches concurrent calls by tool-call ID. The provider-level `humanInTheLoop` prop is unsupported and throws; use the registration instead. |
|
|
98
|
+
| A2UI and Open Generative UI | Not yet supported | Built-in catalogs, renderers, and sandbox helpers are planned. |
|
|
99
|
+
| CoAgent/LangGraph state renderers | Not yet supported | Use the lower-level agent binding for state today. |
|
|
100
|
+
| Memories and learning APIs | Not yet supported | No Svelte-specific bindings are included in this release. |
|
|
101
|
+
| Modal, threads drawer, audio input | Not yet supported | Build these surfaces from the exported state factories where possible. |
|
|
102
|
+
| Inspector and developer console | Not yet supported | Use Runtime and browser diagnostics while developing. |
|
|
103
|
+
|
|
104
|
+
## Reactive agent state
|
|
105
|
+
|
|
106
|
+
Stateful APIs use `create*` names because they create rune-backed state and
|
|
107
|
+
subscriptions. Keep the returned object intact and read its live getters in
|
|
108
|
+
markup; plain destructuring snapshots a getter and loses reactivity.
|
|
109
|
+
|
|
110
|
+
```svelte
|
|
111
|
+
<script lang="ts">
|
|
112
|
+
import { createAgent, useCopilotKit } from "@copilotkit/svelte";
|
|
113
|
+
import { isRunCompletionAware } from "@copilotkit/core";
|
|
114
|
+
|
|
115
|
+
const agentHandle = createAgent({ agentId: "default" });
|
|
116
|
+
const { copilotkit } = useCopilotKit();
|
|
117
|
+
|
|
118
|
+
async function send(content: string) {
|
|
119
|
+
const agent = agentHandle.agent;
|
|
120
|
+
if (!agent) return;
|
|
121
|
+
|
|
122
|
+
const maybeAware: unknown = agent;
|
|
123
|
+
const activeRunCompletionPromise = isRunCompletionAware(maybeAware)
|
|
124
|
+
? maybeAware.activeRunCompletionPromise
|
|
125
|
+
: undefined;
|
|
126
|
+
if (agent.isRunning && activeRunCompletionPromise) {
|
|
127
|
+
try {
|
|
128
|
+
await activeRunCompletionPromise;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error("The active CopilotKit run failed before this send", error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
agent.addMessage({
|
|
135
|
+
id: crypto.randomUUID(),
|
|
136
|
+
role: "user",
|
|
137
|
+
content,
|
|
138
|
+
});
|
|
139
|
+
await copilotkit.runAgent({ agent });
|
|
140
|
+
}
|
|
141
|
+
</script>
|
|
142
|
+
|
|
143
|
+
{#if agentHandle.isRunning}
|
|
144
|
+
<p>Agent is thinking…</p>
|
|
145
|
+
{/if}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Use `$derived` only when you want a local alias or computed value:
|
|
149
|
+
|
|
150
|
+
```svelte
|
|
151
|
+
<script lang="ts">
|
|
152
|
+
const { messages, isRunning } = $derived(agentHandle);
|
|
153
|
+
</script>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Register a frontend tool
|
|
157
|
+
|
|
158
|
+
Registration APIs use `register*` names. They register during component setup
|
|
159
|
+
and unregister when the component is destroyed.
|
|
160
|
+
|
|
161
|
+
```svelte
|
|
162
|
+
<script lang="ts">
|
|
163
|
+
import { registerFrontendTool } from "@copilotkit/svelte";
|
|
164
|
+
import { z } from "zod";
|
|
165
|
+
|
|
166
|
+
registerFrontendTool({
|
|
167
|
+
name: "showToast",
|
|
168
|
+
description: "Show a notification in the browser",
|
|
169
|
+
parameters: z.object({ message: z.string() }),
|
|
170
|
+
handler: async ({ message }) => {
|
|
171
|
+
alert(message);
|
|
172
|
+
return "Notification shown";
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
</script>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Set `agentId` to scope a registration to one agent. Omit it to make the tool
|
|
179
|
+
available to every agent connected through the provider.
|
|
180
|
+
|
|
181
|
+
## Render tool calls in chat
|
|
182
|
+
|
|
183
|
+
Registered renderers mount inside `CopilotChat`. Return a string for simple
|
|
184
|
+
status output, or a Svelte snippet for rich UI. A `"*"` registration acts as
|
|
185
|
+
the fallback when no named renderer matches.
|
|
186
|
+
|
|
187
|
+
```svelte
|
|
188
|
+
<script lang="ts">
|
|
189
|
+
import { registerRenderToolCall } from "@copilotkit/svelte";
|
|
190
|
+
import { z } from "zod";
|
|
191
|
+
|
|
192
|
+
registerRenderToolCall({
|
|
193
|
+
name: "lookupWeather",
|
|
194
|
+
parameters: z.object({ city: z.string().optional() }),
|
|
195
|
+
render: ({ status, toolCallId, parameters, result }) =>
|
|
196
|
+
`weather:${toolCallId}:${status}:${String(parameters["city"] ?? "")}:${result ?? ""}`,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
registerRenderToolCall({
|
|
200
|
+
name: "*",
|
|
201
|
+
render: ({ name, status }) => `${name}:${status}`,
|
|
202
|
+
});
|
|
203
|
+
</script>
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Scope with `agentId` to render only calls for one agent. For interactive
|
|
207
|
+
approval UI, use `registerHumanInTheLoop` instead: its `render` receives
|
|
208
|
+
`respond` while `status === "executing"` — render a snippet with an approve
|
|
209
|
+
button that calls `respond(result)` to resolve that tool call ID.
|
|
210
|
+
|
|
211
|
+
## Attach files
|
|
212
|
+
|
|
213
|
+
Pass `attachments` to `CopilotChat` to wire `createAttachments` into the
|
|
214
|
+
composer (file picker, drag-drop overlay, scoped paste, upload queue).
|
|
215
|
+
`attachments={true}` enables defaults; pass a config object to customize.
|
|
216
|
+
|
|
217
|
+
```svelte
|
|
218
|
+
<script lang="ts">
|
|
219
|
+
import { CopilotChat } from "@copilotkit/svelte";
|
|
220
|
+
</script>
|
|
221
|
+
|
|
222
|
+
<CopilotChat
|
|
223
|
+
agentId="default"
|
|
224
|
+
attachments={{ enabled: true, accept: "image/*,.pdf", maxSize: 10 * 1024 * 1024 }}
|
|
225
|
+
/>
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Use `createAttachments` directly only when building a custom composer. It
|
|
229
|
+
exposes `fileInputAction`/`containerAction` Svelte actions for DOM refs,
|
|
230
|
+
plus `processFiles`, `handleFileUpload`, drag handlers, and
|
|
231
|
+
`consumeAttachments()`.
|
|
232
|
+
|
|
233
|
+
## Work with threads headlessly
|
|
234
|
+
|
|
235
|
+
`createThreads` exposes the thread store without a prebuilt drawer. Inputs
|
|
236
|
+
are reactive getters, so updates to `agentId`, `enabled`, `limit`, or
|
|
237
|
+
`includeArchived` refetch automatically.
|
|
238
|
+
|
|
239
|
+
```svelte
|
|
240
|
+
<script lang="ts">
|
|
241
|
+
import { createThreads } from "@copilotkit/svelte";
|
|
242
|
+
|
|
243
|
+
const threads = createThreads({ agentId: "default", limit: 20 });
|
|
244
|
+
|
|
245
|
+
function rename(id: string) {
|
|
246
|
+
void threads.renameThread(id, "Trip plan");
|
|
247
|
+
}
|
|
248
|
+
</script>
|
|
249
|
+
|
|
250
|
+
{#if threads.isLoading}
|
|
251
|
+
<p>Loading threads…</p>
|
|
252
|
+
{:else if threads.error}
|
|
253
|
+
<p>{threads.error.message}</p>
|
|
254
|
+
{:else}
|
|
255
|
+
<ul>
|
|
256
|
+
{#each threads.threads as thread (thread.id)}
|
|
257
|
+
<li>
|
|
258
|
+
{thread.name ?? thread.id}
|
|
259
|
+
<button onclick={() => rename(thread.id)}>Rename</button>
|
|
260
|
+
<button onclick={() => void threads.archiveThread(thread.id)}>Archive</button>
|
|
261
|
+
<button onclick={() => void threads.deleteThread(thread.id)}>Delete</button>
|
|
262
|
+
</li>
|
|
263
|
+
{/each}
|
|
264
|
+
</ul>
|
|
265
|
+
{#if threads.hasMoreThreads}
|
|
266
|
+
<button onclick={() => threads.fetchMoreThreads()}>Load more</button>
|
|
267
|
+
{/if}
|
|
268
|
+
{/if}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## API naming
|
|
272
|
+
|
|
273
|
+
| React concept | Svelte 5 API |
|
|
274
|
+
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
275
|
+
| `useAgent` | `createAgent` |
|
|
276
|
+
| `useFrontendTool` | `registerFrontendTool` |
|
|
277
|
+
| `useAgentContext` | `connectAgentContext` |
|
|
278
|
+
| `useRenderToolCall` (`useRenderTool` in V1) | `registerRenderToolCall` |
|
|
279
|
+
| `useHumanInTheLoop` | `registerHumanInTheLoop` |
|
|
280
|
+
| `useInterrupt` | `createInterrupt` |
|
|
281
|
+
| `useThreads` | `createThreads` |
|
|
282
|
+
| `useAttachments` | `createAttachments` |
|
|
283
|
+
| `useSuggestions` | `createSuggestions` (observation only; no suggestion-configuration registration — React's `useConfigureSuggestions` has no Svelte equivalent) |
|
|
284
|
+
| `useCapabilities` | `createCapabilities` |
|
|
285
|
+
| `useKatexStyles` | `loadKatexStyles` |
|
|
286
|
+
| Provider accessor (`useCopilotKit`) | `useCopilotKit` |
|
|
287
|
+
|
|
288
|
+
React V1 names such as `useCopilotAction`, `useCopilotReadable`, and
|
|
289
|
+
`useCopilotChat` are not part of the Svelte API. Prefer the Svelte `create*`,
|
|
290
|
+
`register*`, and `connect*` functions.
|
|
291
|
+
|
|
292
|
+
## Remaining limitations
|
|
293
|
+
|
|
294
|
+
This release does not claim full React parity. Still missing:
|
|
295
|
+
|
|
296
|
+
- Suggestion-generation configuration (Svelte observes suggestions only).
|
|
297
|
+
- Prebuilt thread drawer, modal chat surface, and audio input.
|
|
298
|
+
- Provider-level `humanInTheLoop` prop (throws; use `registerHumanInTheLoop`).
|
|
299
|
+
- A2UI and Open Generative UI renderers/sandbox helpers.
|
|
300
|
+
- CoAgent/LangGraph state renderers.
|
|
301
|
+
- Memories and learning APIs.
|
|
302
|
+
- Inspector and developer console.
|
|
303
|
+
|
|
304
|
+
## Try it
|
|
305
|
+
|
|
306
|
+
The [SvelteKit demo](./examples/demo) renders chat, sidebar, and popup tabs with
|
|
307
|
+
attachments enabled. Copy `examples/demo/.env.example` to `examples/demo/.env.local`, add one of
|
|
308
|
+
`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, or `GOOGLE_API_KEY`, then run:
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
cd community/svelte
|
|
312
|
+
pnpm install
|
|
313
|
+
pnpm build
|
|
314
|
+
cd examples/demo
|
|
315
|
+
pnpm install
|
|
316
|
+
pnpm dev
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Next compatibility milestones
|
|
320
|
+
|
|
321
|
+
1. Suggestion-generation configuration registration.
|
|
322
|
+
2. Prebuilt thread drawer, modal surface, and audio input.
|
|
323
|
+
3. A2UI/Open Generative UI renderers and sandbox helpers.
|
|
324
|
+
4. CoAgent state renderers.
|
|
325
|
+
5. Memories/learning bindings and Inspector tooling.
|
|
326
|
+
6. Public API reference pages and lifecycle examples for every exported factory.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class ChatConfig {
|
|
2
|
+
agentId: string;
|
|
3
|
+
threadId: string | undefined;
|
|
4
|
+
hasExplicitThreadId: boolean;
|
|
5
|
+
labels: Record<string, string>;
|
|
6
|
+
constructor(agentId: string, threadId?: string, hasExplicitThreadId?: boolean);
|
|
7
|
+
}
|
|
8
|
+
export declare function setChatConfig(config: ChatConfig): void;
|
|
9
|
+
export declare function getChatConfig(): ChatConfig | undefined;
|
|
10
|
+
//# sourceMappingURL=chat-config-context.svelte.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class ChatConfig {
|
|
2
|
+
agentId: string;
|
|
3
|
+
threadId: string | undefined;
|
|
4
|
+
hasExplicitThreadId: boolean;
|
|
5
|
+
labels: Record<string, string>;
|
|
6
|
+
constructor(agentId: string, threadId?: string, hasExplicitThreadId?: boolean);
|
|
7
|
+
}
|
|
8
|
+
export declare function setChatConfig(config: ChatConfig): void;
|
|
9
|
+
export declare function getChatConfig(): ChatConfig | undefined;
|
|
10
|
+
//# sourceMappingURL=chat-config-context.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-config-context.svelte.d.ts","sourceRoot":"","sources":["../../../src/components/chat/chat-config-context.svelte.ts"],"names":[],"mappings":"AAGA,qBAAa,UAAU;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAG7B,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EACjB,mBAAmB,CAAC,EAAE,OAAO;CAOhC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAEtD;AAED,wBAAgB,aAAa,IAAI,UAAU,GAAG,SAAS,CAEtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-after-active-run.d.ts","sourceRoot":"","sources":["../../../src/components/chat/dispatch-after-active-run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAKnD,wBAAsB,6BAA6B,CACjD,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAC5B,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Highlights a fenced code block. Unknown languages fall back to automatic
|
|
3
|
+
* detection so highlighting still works when the fence is missing a language.
|
|
4
|
+
*/
|
|
5
|
+
export declare function highlightCode(code: string, lang?: string): string;
|
|
6
|
+
export declare function getLanguageLabel(lang?: string): string;
|
|
7
|
+
export declare function getDownloadFilename(lang?: string): string;
|
|
8
|
+
//# sourceMappingURL=highlight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["../../../../src/components/chat/markdown/highlight.ts"],"names":[],"mappings":"AAoEA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAajE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,mBAAmB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAIzD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UserMessage } from '@ag-ui/core';
|
|
2
|
+
import { AudioInputPart, DocumentInputPart, ImageInputPart, VideoInputPart } from '@copilotkit/shared';
|
|
3
|
+
export type MediaPart = ImageInputPart | AudioInputPart | VideoInputPart | DocumentInputPart;
|
|
4
|
+
/**
|
|
5
|
+
* Keeps only the non-text parts of a user message. Mirrors the React package so
|
|
6
|
+
* sent images, audio, video and documents render above the message bubble
|
|
7
|
+
* instead of being dropped.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getMediaParts(content: UserMessage["content"]): MediaPart[];
|
|
10
|
+
export declare function getMediaPartFilename(part: MediaPart): string | undefined;
|
|
11
|
+
//# sourceMappingURL=media-parts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-parts.d.ts","sourceRoot":"","sources":["../../../src/components/chat/media-parts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,cAAc,EACf,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,SAAS,GACjB,cAAc,GACd,cAAc,GACd,cAAc,GACd,iBAAiB,CAAC;AAEtB;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,GAAG,SAAS,EAAE,CAS1E;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAGxE"}
|