@copilotkit/svelte 0.1.0 → 0.1.1-canary.svelte-preview

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 (193) hide show
  1. package/{src → dist}/components/chat/CopilotChat.svelte +26 -1
  2. package/dist/components/chat/CopilotChat.svelte.d.ts +5 -1
  3. package/dist/components/chat/CopilotChat.svelte.d.ts.map +1 -0
  4. package/dist/components/chat/CopilotChatAssistantMessage.svelte.d.ts +80 -1
  5. package/dist/components/chat/CopilotChatAssistantMessage.svelte.d.ts.map +1 -0
  6. package/dist/components/chat/CopilotChatAttachmentQueue.svelte.d.ts +9 -1
  7. package/dist/components/chat/CopilotChatAttachmentQueue.svelte.d.ts.map +1 -0
  8. package/dist/components/chat/CopilotChatInput.svelte.d.ts +20 -1
  9. package/dist/components/chat/CopilotChatInput.svelte.d.ts.map +1 -0
  10. package/dist/components/chat/CopilotChatMessage.svelte.d.ts +10 -1
  11. package/dist/components/chat/CopilotChatMessage.svelte.d.ts.map +1 -0
  12. package/dist/components/chat/CopilotChatMessageView.svelte.d.ts +14 -1
  13. package/dist/components/chat/CopilotChatMessageView.svelte.d.ts.map +1 -0
  14. package/dist/components/chat/CopilotChatReasoningMessage.svelte.d.ts +40 -1
  15. package/dist/components/chat/CopilotChatReasoningMessage.svelte.d.ts.map +1 -0
  16. package/dist/components/chat/CopilotChatSuggestionPill.svelte.d.ts +10 -1
  17. package/dist/components/chat/CopilotChatSuggestionPill.svelte.d.ts.map +1 -0
  18. package/dist/components/chat/CopilotChatSuggestionView.svelte.d.ts +10 -1
  19. package/dist/components/chat/CopilotChatSuggestionView.svelte.d.ts.map +1 -0
  20. package/dist/components/chat/CopilotChatToggleButton.svelte.d.ts +8 -1
  21. package/dist/components/chat/CopilotChatToggleButton.svelte.d.ts.map +1 -0
  22. package/dist/components/chat/CopilotChatToolCallsView.svelte.d.ts +12 -1
  23. package/dist/components/chat/CopilotChatToolCallsView.svelte.d.ts.map +1 -0
  24. package/dist/components/chat/CopilotChatUserMessage.svelte.d.ts +62 -1
  25. package/dist/components/chat/CopilotChatUserMessage.svelte.d.ts.map +1 -0
  26. package/dist/components/chat/CopilotChatView.svelte.d.ts +32 -1
  27. package/dist/components/chat/CopilotChatView.svelte.d.ts.map +1 -0
  28. package/dist/components/chat/CopilotPopup.svelte.d.ts +5 -1
  29. package/dist/components/chat/CopilotPopup.svelte.d.ts.map +1 -0
  30. package/dist/components/chat/CopilotSidebar.svelte.d.ts +5 -1
  31. package/dist/components/chat/CopilotSidebar.svelte.d.ts.map +1 -0
  32. package/dist/components/chat/StreamMarkdown.svelte.d.ts +7 -1
  33. package/dist/components/chat/StreamMarkdown.svelte.d.ts.map +1 -0
  34. package/dist/components/chat/chat-config-context.svelte.js +20 -0
  35. package/dist/components/chat/dispatch-after-active-run.d.ts +1 -1
  36. package/dist/components/chat/dispatch-after-active-run.js +31 -0
  37. package/dist/components/chat/markdown/CodeBlock.svelte.d.ts +8 -1
  38. package/dist/components/chat/markdown/CodeBlock.svelte.d.ts.map +1 -0
  39. package/dist/components/chat/markdown/CodeSpan.svelte.d.ts +9 -1
  40. package/dist/components/chat/markdown/CodeSpan.svelte.d.ts.map +1 -0
  41. package/dist/components/chat/markdown/Table.svelte.d.ts +8 -1
  42. package/dist/components/chat/markdown/Table.svelte.d.ts.map +1 -0
  43. package/dist/components/chat/markdown/TableBody.svelte.d.ts +8 -1
  44. package/dist/components/chat/markdown/TableBody.svelte.d.ts.map +1 -0
  45. package/dist/components/chat/markdown/TableCell.svelte.d.ts +10 -1
  46. package/dist/components/chat/markdown/TableCell.svelte.d.ts.map +1 -0
  47. package/dist/components/chat/markdown/TableHead.svelte.d.ts +8 -1
  48. package/dist/components/chat/markdown/TableHead.svelte.d.ts.map +1 -0
  49. package/dist/components/chat/markdown/TableRow.svelte.d.ts +8 -1
  50. package/dist/components/chat/markdown/TableRow.svelte.d.ts.map +1 -0
  51. package/dist/components/chat/markdown/highlight.js +91 -0
  52. package/dist/components/chat/media-parts.d.ts +2 -2
  53. package/dist/components/chat/media-parts.js +17 -0
  54. package/dist/components/chat/types.d.ts +5 -3
  55. package/dist/components/chat/types.js +7 -0
  56. package/dist/components/icons/index.d.ts +1 -1
  57. package/dist/components/icons/index.js +1 -0
  58. package/dist/components/index.d.ts +17 -17
  59. package/dist/hooks/connect-agent-context.svelte.js +25 -0
  60. package/dist/hooks/create-agent.svelte.d.ts +3 -3
  61. package/dist/hooks/create-agent.svelte.js +341 -0
  62. package/dist/hooks/create-attachments.svelte.d.ts +1 -1
  63. package/dist/hooks/create-attachments.svelte.js +232 -0
  64. package/dist/hooks/create-capabilities.svelte.d.ts +1 -1
  65. package/dist/hooks/create-capabilities.svelte.js +17 -0
  66. package/dist/hooks/create-interrupt.svelte.d.ts +2 -2
  67. package/dist/hooks/create-interrupt.svelte.js +333 -0
  68. package/dist/hooks/create-suggestions.svelte.d.ts +1 -1
  69. package/dist/hooks/create-suggestions.svelte.js +61 -0
  70. package/dist/hooks/create-threads.svelte.js +230 -0
  71. package/dist/hooks/index.d.ts +19 -19
  72. package/dist/hooks/index.js +11 -0
  73. package/dist/hooks/load-katex-styles.svelte.js +11 -0
  74. package/dist/hooks/register-frontend-tool.svelte.d.ts +1 -1
  75. package/dist/hooks/register-frontend-tool.svelte.js +32 -0
  76. package/dist/hooks/register-human-in-the-loop.svelte.d.ts +1 -1
  77. package/dist/hooks/register-human-in-the-loop.svelte.js +84 -0
  78. package/dist/hooks/register-render-tool-call.svelte.d.ts +1 -1
  79. package/dist/hooks/register-render-tool-call.svelte.js +26 -0
  80. package/dist/index.d.ts +5 -5
  81. package/dist/lib/svelte-core.d.ts +4 -3
  82. package/dist/lib/svelte-core.js +145 -0
  83. package/dist/providers/CopilotKitProvider.svelte.d.ts +9 -1
  84. package/dist/providers/CopilotKitProvider.svelte.d.ts.map +1 -0
  85. package/dist/providers/CopilotKitProvider.types.d.ts +4 -4
  86. package/dist/providers/CopilotKitProvider.types.js +1 -0
  87. package/dist/providers/context.d.ts +3 -3
  88. package/dist/providers/context.js +2 -0
  89. package/dist/providers/index.d.ts +5 -5
  90. package/dist/providers/index.js +2 -0
  91. package/dist/providers/useCopilotKit.d.ts +1 -1
  92. package/dist/providers/useCopilotKit.js +9 -0
  93. package/dist/styles.css +1 -2
  94. package/dist/types/a2ui.js +1 -0
  95. package/dist/types/activity-message-renderer.d.ts +3 -3
  96. package/dist/types/activity-message-renderer.js +1 -0
  97. package/dist/types/custom-message-renderer.d.ts +1 -1
  98. package/dist/types/custom-message-renderer.js +1 -0
  99. package/dist/types/frontend-tool.d.ts +2 -2
  100. package/dist/types/frontend-tool.js +1 -0
  101. package/dist/types/human-in-the-loop.d.ts +1 -1
  102. package/dist/types/human-in-the-loop.js +1 -0
  103. package/dist/types/index.d.ts +8 -8
  104. package/dist/types/interrupt.d.ts +1 -1
  105. package/dist/types/interrupt.js +1 -0
  106. package/dist/types/sandbox-function.d.ts +1 -1
  107. package/dist/types/sandbox-function.js +1 -0
  108. package/dist/types/tool-call-renderer.d.ts +2 -2
  109. package/dist/types/tool-call-renderer.js +1 -0
  110. package/package.json +14 -22
  111. package/dist/components/chat/CopilotChat.d.svelte.ts +0 -1
  112. package/dist/components/chat/CopilotChatAssistantMessage.d.svelte.ts +0 -1
  113. package/dist/components/chat/CopilotChatAttachmentQueue.d.svelte.ts +0 -1
  114. package/dist/components/chat/CopilotChatInput.d.svelte.ts +0 -1
  115. package/dist/components/chat/CopilotChatMessage.d.svelte.ts +0 -1
  116. package/dist/components/chat/CopilotChatMessageView.d.svelte.ts +0 -1
  117. package/dist/components/chat/CopilotChatReasoningMessage.d.svelte.ts +0 -1
  118. package/dist/components/chat/CopilotChatSuggestionPill.d.svelte.ts +0 -1
  119. package/dist/components/chat/CopilotChatSuggestionView.d.svelte.ts +0 -1
  120. package/dist/components/chat/CopilotChatToggleButton.d.svelte.ts +0 -1
  121. package/dist/components/chat/CopilotChatToolCallsView.d.svelte.ts +0 -1
  122. package/dist/components/chat/CopilotChatUserMessage.d.svelte.ts +0 -1
  123. package/dist/components/chat/CopilotChatView.d.svelte.ts +0 -1
  124. package/dist/components/chat/CopilotPopup.d.svelte.ts +0 -1
  125. package/dist/components/chat/CopilotSidebar.d.svelte.ts +0 -1
  126. package/dist/components/chat/StreamMarkdown.d.svelte.ts +0 -1
  127. package/dist/components/chat/chat-config-context.d.svelte.ts +0 -10
  128. package/dist/index.cjs +0 -5
  129. package/dist/index.cjs.map +0 -1
  130. package/dist/index.d.cts +0 -6
  131. package/dist/index.d.mts +0 -6
  132. package/dist/index.mjs +0 -3037
  133. package/dist/index.mjs.map +0 -1
  134. package/src/components/chat/chat-config-context.svelte.ts +0 -28
  135. package/src/components/chat/dispatch-after-active-run.ts +0 -40
  136. package/src/components/chat/markdown/highlight.ts +0 -96
  137. package/src/components/chat/media-parts.ts +0 -34
  138. package/src/components/chat/types.ts +0 -176
  139. package/src/components/icons/index.ts +0 -23
  140. package/src/hooks/connect-agent-context.svelte.ts +0 -46
  141. package/src/hooks/create-agent.svelte.ts +0 -420
  142. package/src/hooks/create-attachments.svelte.ts +0 -311
  143. package/src/hooks/create-capabilities.svelte.ts +0 -26
  144. package/src/hooks/create-interrupt.svelte.ts +0 -467
  145. package/src/hooks/create-suggestions.svelte.ts +0 -84
  146. package/src/hooks/create-threads.svelte.ts +0 -337
  147. package/src/hooks/index.ts +0 -45
  148. package/src/hooks/load-katex-styles.svelte.ts +0 -13
  149. package/src/hooks/register-frontend-tool.svelte.ts +0 -45
  150. package/src/hooks/register-human-in-the-loop.svelte.ts +0 -118
  151. package/src/hooks/register-render-tool-call.svelte.ts +0 -75
  152. package/src/lib/svelte-core.ts +0 -230
  153. package/src/providers/CopilotKitProvider.types.ts +0 -55
  154. package/src/providers/context.ts +0 -26
  155. package/src/providers/index.ts +0 -5
  156. package/src/providers/useCopilotKit.ts +0 -11
  157. package/src/types/a2ui.ts +0 -5
  158. package/src/types/activity-message-renderer.ts +0 -21
  159. package/src/types/custom-message-renderer.ts +0 -23
  160. package/src/types/frontend-tool.ts +0 -8
  161. package/src/types/human-in-the-loop.ts +0 -40
  162. package/src/types/interrupt.ts +0 -32
  163. package/src/types/sandbox-function.ts +0 -8
  164. package/src/types/tool-call-renderer.ts +0 -36
  165. /package/{src → dist}/app.d.ts +0 -0
  166. /package/{src → dist}/components/chat/CopilotChatAssistantMessage.svelte +0 -0
  167. /package/{src → dist}/components/chat/CopilotChatAttachmentQueue.svelte +0 -0
  168. /package/{src → dist}/components/chat/CopilotChatInput.svelte +0 -0
  169. /package/{src → dist}/components/chat/CopilotChatMessage.svelte +0 -0
  170. /package/{src → dist}/components/chat/CopilotChatMessageView.svelte +0 -0
  171. /package/{src → dist}/components/chat/CopilotChatReasoningMessage.svelte +0 -0
  172. /package/{src → dist}/components/chat/CopilotChatSuggestionPill.svelte +0 -0
  173. /package/{src → dist}/components/chat/CopilotChatSuggestionView.svelte +0 -0
  174. /package/{src → dist}/components/chat/CopilotChatToggleButton.svelte +0 -0
  175. /package/{src → dist}/components/chat/CopilotChatToolCallsView.svelte +0 -0
  176. /package/{src → dist}/components/chat/CopilotChatUserMessage.svelte +0 -0
  177. /package/{src → dist}/components/chat/CopilotChatView.svelte +0 -0
  178. /package/{src → dist}/components/chat/CopilotPopup.svelte +0 -0
  179. /package/{src → dist}/components/chat/CopilotSidebar.svelte +0 -0
  180. /package/{src → dist}/components/chat/StreamMarkdown.svelte +0 -0
  181. /package/{src → dist}/components/chat/markdown/CodeBlock.svelte +0 -0
  182. /package/{src → dist}/components/chat/markdown/CodeSpan.svelte +0 -0
  183. /package/{src → dist}/components/chat/markdown/Table.svelte +0 -0
  184. /package/{src → dist}/components/chat/markdown/TableBody.svelte +0 -0
  185. /package/{src → dist}/components/chat/markdown/TableCell.svelte +0 -0
  186. /package/{src → dist}/components/chat/markdown/TableHead.svelte +0 -0
  187. /package/{src → dist}/components/chat/markdown/TableRow.svelte +0 -0
  188. /package/{src/components/index.ts → dist/components/index.js} +0 -0
  189. /package/{src/index.ts → dist/index.js} +0 -0
  190. /package/{src → dist}/providers/CopilotKitProvider.svelte +0 -0
  191. /package/{src → dist}/styles/globals.css +0 -0
  192. /package/{src → dist}/styles.d.ts +0 -0
  193. /package/{src/types/index.ts → dist/types/index.js} +0 -0
@@ -1,337 +0,0 @@
1
- import { getContext } from "svelte";
2
- import {
3
- CopilotKitCoreRuntimeConnectionStatus,
4
- ɵcreateThreadStore,
5
- ɵselectHasNextPage,
6
- ɵselectIsFetchingNextPage,
7
- ɵselectIsMutating,
8
- ɵselectThreads,
9
- ɵselectThreadsError,
10
- ɵselectFetchMoreError,
11
- ɵselectThreadsIsLoading,
12
- } from "@copilotkit/core";
13
- import type { ɵThreadRuntimeContext, ɵThreadStore } from "@copilotkit/core";
14
- import { COPILOT_KIT_KEY } from "../providers/context";
15
- import type { CopilotKitContextValue } from "../providers/context";
16
-
17
- export interface Thread {
18
- id: string;
19
- agentId: string;
20
- name: string | null;
21
- archived: boolean;
22
- createdAt: string;
23
- updatedAt: string;
24
- lastRunAt?: string;
25
- }
26
-
27
- export interface CreateThreadsInput {
28
- agentId: string;
29
- includeArchived?: boolean;
30
- limit?: number;
31
- enabled?: boolean;
32
- }
33
-
34
- export interface CreateThreadsResult {
35
- threads: Thread[];
36
- isLoading: boolean;
37
- error: Error | null;
38
- listError: Error | null;
39
- fetchMoreError: Error | null;
40
- hasMoreThreads: boolean;
41
- isFetchingMoreThreads: boolean;
42
- isMutating: boolean;
43
- fetchMoreThreads: () => void;
44
- refetchThreads: () => void;
45
- renameThread: (threadId: string, name: string) => Promise<void>;
46
- archiveThread: (threadId: string) => Promise<void>;
47
- unarchiveThread: (threadId: string) => Promise<void>;
48
- deleteThread: (threadId: string) => Promise<void>;
49
- }
50
-
51
- export function createThreads(input: CreateThreadsInput): CreateThreadsResult {
52
- const context = getContext<CopilotKitContextValue | null>(COPILOT_KIT_KEY);
53
- if (!context) {
54
- throw new Error("createThreads must be used within CopilotKitProvider");
55
- }
56
-
57
- // The core object is kept for operations (register/unregister) and the
58
- // instrumented transport. All reactive runtime state below is read through
59
- // the provider getters (context.runtimeUrl, context.headers, ...), never
60
- // through the non-reactive fields on the core object — mirroring
61
- // react-core's useThreads, which reads useCopilotKit() state.
62
- const core = context.copilotkit;
63
-
64
- const store = ɵcreateThreadStore({
65
- fetch: core.ɵruntimeFetch,
66
- });
67
-
68
- let threads = $state<Thread[]>([]);
69
- let storeIsLoading = $state(false);
70
- let storeError = $state<Error | null>(null);
71
- let fetchMoreError = $state<Error | null>(null);
72
- let hasMoreThreads = $state(false);
73
- let isFetchingMoreThreads = $state(false);
74
- let isMutating = $state(false);
75
- let hasDispatchedContext = $state(false);
76
-
77
- function bindSelector<T>(
78
- selector: (state: ReturnType<ɵThreadStore["getState"]>) => T,
79
- ) {
80
- const val = selector(store.getState());
81
- const subscription = store.select(selector).subscribe((next: T) => {
82
- if (selector === ɵselectThreads) threads = next as unknown as Thread[];
83
- else if (selector === ɵselectThreadsIsLoading)
84
- storeIsLoading = next as unknown as boolean;
85
- else if (selector === ɵselectThreadsError)
86
- storeError = next as unknown as Error | null;
87
- else if (selector === ɵselectFetchMoreError)
88
- fetchMoreError = next as unknown as Error | null;
89
- else if (selector === ɵselectHasNextPage)
90
- hasMoreThreads = next as unknown as boolean;
91
- else if (selector === ɵselectIsFetchingNextPage)
92
- isFetchingMoreThreads = next as unknown as boolean;
93
- else if (selector === ɵselectIsMutating)
94
- isMutating = next as unknown as boolean;
95
- });
96
- return {
97
- initialValue: val,
98
- unsubscribe: () => subscription.unsubscribe(),
99
- };
100
- }
101
-
102
- $effect(() => {
103
- const threadsBinding = bindSelector(ɵselectThreads);
104
- const storeIsLoadingBinding = bindSelector(ɵselectThreadsIsLoading);
105
- const storeErrorBinding = bindSelector(ɵselectThreadsError);
106
- const fetchMoreErrorBinding = bindSelector(ɵselectFetchMoreError);
107
- const hasMoreThreadsBinding = bindSelector(ɵselectHasNextPage);
108
- const isFetchingMoreThreadsBinding = bindSelector(
109
- ɵselectIsFetchingNextPage,
110
- );
111
- const isMutatingBinding = bindSelector(ɵselectIsMutating);
112
-
113
- threads = threadsBinding.initialValue as Thread[];
114
- storeIsLoading = storeIsLoadingBinding.initialValue as boolean;
115
- storeError = storeErrorBinding.initialValue as Error | null;
116
- fetchMoreError = fetchMoreErrorBinding.initialValue as Error | null;
117
- hasMoreThreads = hasMoreThreadsBinding.initialValue as boolean;
118
- isFetchingMoreThreads =
119
- isFetchingMoreThreadsBinding.initialValue as boolean;
120
- isMutating = isMutatingBinding.initialValue as boolean;
121
-
122
- return () => {
123
- threadsBinding.unsubscribe();
124
- storeIsLoadingBinding.unsubscribe();
125
- storeErrorBinding.unsubscribe();
126
- fetchMoreErrorBinding.unsubscribe();
127
- hasMoreThreadsBinding.unsubscribe();
128
- isFetchingMoreThreadsBinding.unsubscribe();
129
- isMutatingBinding.unsubscribe();
130
- };
131
- });
132
-
133
- $effect(() => {
134
- store.start();
135
- return () => {
136
- store.setContext(null);
137
- store.stop();
138
- };
139
- });
140
-
141
- // Reactive input getters (agentId/enabled/includeArchived/limit) and
142
- // provider getters are read inside $derived/$effect so updates rerun them.
143
- const resolvedEnabled = $derived(input.enabled ?? true);
144
-
145
- const threadListEndpointSupported = $derived(
146
- context.threadEndpoints?.list !== false,
147
- );
148
- const threadMutationsSupported = $derived(
149
- context.threadEndpoints?.mutations !== false,
150
- );
151
- const threadEndpointsUnavailable = $derived(
152
- !!context.runtimeUrl &&
153
- context.runtimeConnectionStatus ===
154
- CopilotKitCoreRuntimeConnectionStatus.Connected &&
155
- !threadListEndpointSupported,
156
- );
157
- const threadMutationsError = $derived(
158
- threadMutationsSupported
159
- ? null
160
- : new Error(
161
- "Thread mutations are not available on this CopilotKit runtime",
162
- ),
163
- );
164
- const threadEndpointsError = $derived(
165
- threadEndpointsUnavailable
166
- ? new Error(
167
- "Thread endpoints are not available on this CopilotKit runtime",
168
- )
169
- : null,
170
- );
171
-
172
- $effect(() => {
173
- const enabled = input.enabled ?? true;
174
- const runtimeUrl = context.runtimeUrl;
175
- const runtimeStatus = context.runtimeConnectionStatus;
176
- const headers = context.headers;
177
- const endpoints = context.threadEndpoints;
178
- const intelligence = context.intelligence;
179
- const agentId = input.agentId;
180
- const includeArchived = input.includeArchived;
181
- const limit = input.limit;
182
- const listSupported = endpoints?.list !== false;
183
-
184
- const clearContext = () => {
185
- if (hasDispatchedContext) {
186
- store.setContext(null);
187
- }
188
- hasDispatchedContext = false;
189
- };
190
-
191
- // Disabled: stay inert and tear down any previously-dispatched context
192
- // so an in-flight subscription is closed and no further fetch is issued.
193
- if (!enabled) {
194
- clearContext();
195
- return;
196
- }
197
-
198
- if (!runtimeUrl) {
199
- clearContext();
200
- return;
201
- }
202
-
203
- // Defer setting the context until the runtime reports Connected. Before
204
- // `/info` resolves we don't know `intelligence.wsUrl`, so dispatching
205
- // early would issue a list fetch without it, then a second one once it
206
- // lands. For transient states (Disconnected/Connecting/Error with a URL
207
- // still set) the previously-dispatched context stays in place.
208
- if (runtimeStatus !== CopilotKitCoreRuntimeConnectionStatus.Connected) {
209
- return;
210
- }
211
-
212
- if (!listSupported) {
213
- clearContext();
214
- return;
215
- }
216
-
217
- const threadContext: ɵThreadRuntimeContext = {
218
- runtimeUrl,
219
- headers: { ...headers },
220
- wsUrl: intelligence?.wsUrl,
221
- agentId,
222
- includeArchived,
223
- limit,
224
- };
225
- store.setContext(threadContext);
226
- hasDispatchedContext = true;
227
- });
228
-
229
- $effect(() => {
230
- const enabled = input.enabled ?? true;
231
- const nextAgentId = input.agentId;
232
- // A disabled (e.g. unlicensed) surface must not claim the agentId slot.
233
- // The registry is single-slot/last-writer-wins, so registering an inert
234
- // store would evict — and on unmount tear down — a co-mounted live store
235
- // for the same agent. Staying unregistered while disabled leaves the live
236
- // store's registration intact. Mirrors react-core's use-threads gate.
237
- //
238
- // The cleanup unregisters exactly the id this run registered: on an
239
- // agentId change it releases the previous id before the next run
240
- // registers the new one; on an enabled true→false flip it releases the
241
- // active id and the re-run registers nothing; on unmount it releases the
242
- // active id only (an initially-disabled hook never registers, so its
243
- // unmount unregisters nothing).
244
- if (!enabled) {
245
- return;
246
- }
247
- core.registerThreadStore(nextAgentId, store);
248
- return () => {
249
- if (core.getThreadStore(nextAgentId) === store) {
250
- core.unregisterThreadStore(nextAgentId);
251
- }
252
- };
253
- });
254
-
255
- const runtimeError = $derived(
256
- context.runtimeUrl ? null : new Error("Runtime URL is not configured"),
257
- );
258
-
259
- const preConnectLoading = $derived(
260
- !!context.runtimeUrl &&
261
- resolvedEnabled &&
262
- !threadEndpointsUnavailable &&
263
- !hasDispatchedContext,
264
- );
265
-
266
- const isLoading = $derived(
267
- runtimeError || threadEndpointsError
268
- ? false
269
- : preConnectLoading || storeIsLoading,
270
- );
271
-
272
- const error = $derived(runtimeError ?? threadEndpointsError ?? storeError);
273
-
274
- const listError = $derived(storeError);
275
-
276
- function guardMutation<TArgs extends unknown[]>(
277
- mutation: (...args: TArgs) => Promise<void>,
278
- ): (...args: TArgs) => Promise<void> {
279
- return (...args: TArgs) => {
280
- if (threadMutationsError) {
281
- return Promise.reject(threadMutationsError);
282
- }
283
- return mutation(...args);
284
- };
285
- }
286
-
287
- return {
288
- get threads() {
289
- return threads.map(
290
- ({ id, agentId, name, archived, createdAt, updatedAt, lastRunAt }) => ({
291
- id,
292
- agentId,
293
- name,
294
- archived,
295
- createdAt,
296
- updatedAt,
297
- ...(lastRunAt !== undefined ? { lastRunAt } : {}),
298
- }),
299
- );
300
- },
301
- get isLoading() {
302
- return isLoading;
303
- },
304
- get error() {
305
- return error;
306
- },
307
- get listError() {
308
- return listError;
309
- },
310
- get fetchMoreError() {
311
- return fetchMoreError;
312
- },
313
- get hasMoreThreads() {
314
- return hasMoreThreads;
315
- },
316
- get isFetchingMoreThreads() {
317
- return isFetchingMoreThreads;
318
- },
319
- get isMutating() {
320
- return isMutating;
321
- },
322
- fetchMoreThreads: () => store.fetchNextPage(),
323
- refetchThreads: () => store.refetchThreads(),
324
- renameThread: guardMutation((threadId: string, name: string) =>
325
- store.renameThread(threadId, name),
326
- ),
327
- archiveThread: guardMutation((threadId: string) =>
328
- store.archiveThread(threadId),
329
- ),
330
- unarchiveThread: guardMutation((threadId: string) =>
331
- store.unarchiveThread(threadId),
332
- ),
333
- deleteThread: guardMutation((threadId: string) =>
334
- store.deleteThread(threadId),
335
- ),
336
- };
337
- }
@@ -1,45 +0,0 @@
1
- export {
2
- createAgent,
3
- CreateAgentUpdate,
4
- getThreadClone,
5
- } from "./create-agent.svelte";
6
- export type { CreateAgentProps } from "./create-agent.svelte";
7
- export { connectAgentContext } from "./connect-agent-context.svelte";
8
- export type {
9
- AgentContextInput,
10
- JsonSerializable,
11
- } from "./connect-agent-context.svelte";
12
- export { registerFrontendTool } from "./register-frontend-tool.svelte";
13
- export { registerRenderToolCall } from "./register-render-tool-call.svelte";
14
- export type {
15
- RenderToolProps,
16
- RenderToolInProgressProps,
17
- RenderToolExecutingProps,
18
- RenderToolCompleteProps,
19
- } from "./register-render-tool-call.svelte";
20
- export { registerHumanInTheLoop } from "./register-human-in-the-loop.svelte";
21
- export { createSuggestions } from "./create-suggestions.svelte";
22
- export type {
23
- CreateSuggestionsOptions,
24
- CreateSuggestionsResult,
25
- } from "./create-suggestions.svelte";
26
- export { createInterrupt } from "./create-interrupt.svelte";
27
- export type {
28
- CreateInterruptConfig,
29
- CreateInterruptResult,
30
- } from "./create-interrupt.svelte";
31
- export { createThreads } from "./create-threads.svelte";
32
- export type {
33
- Thread,
34
- CreateThreadsInput,
35
- CreateThreadsResult,
36
- } from "./create-threads.svelte";
37
- export { createAttachments } from "./create-attachments.svelte";
38
- export type {
39
- CreateAttachmentsProps,
40
- CreateAttachmentsReturn,
41
- AttachmentsConfigInput,
42
- } from "./create-attachments.svelte";
43
- export { loadKatexStyles } from "./load-katex-styles.svelte";
44
- export { createCapabilities } from "./create-capabilities.svelte";
45
- export type { CreateCapabilitiesResult } from "./create-capabilities.svelte";
@@ -1,13 +0,0 @@
1
- let injected = false;
2
-
3
- export function loadKatexStyles(): void {
4
- $effect(() => {
5
- if (injected || typeof document === "undefined") return;
6
- injected = true;
7
- void import("katex/dist/katex.min.css").catch(() => {
8
- console.warn(
9
- "[CopilotKit] Failed to load katex styles — math content may render without formatting",
10
- );
11
- });
12
- });
13
- }
@@ -1,45 +0,0 @@
1
- import { getContext } from "svelte";
2
- import { COPILOT_KIT_KEY } from "../providers/context";
3
- import type { CopilotKitContextValue } from "../providers/context";
4
- import type { SvelteFrontendTool } from "../types";
5
- import type { SvelteToolCallRenderer } from "../types";
6
-
7
- export function registerFrontendTool<T extends Record<string, unknown>>(
8
- tool: SvelteFrontendTool<T>,
9
- ) {
10
- const context = getContext<CopilotKitContextValue | null>(COPILOT_KIT_KEY);
11
- if (!context) {
12
- throw new Error(
13
- "registerFrontendTool must be used within CopilotKitProvider",
14
- );
15
- }
16
-
17
- $effect(() => {
18
- const core = context.copilotkit;
19
- const name = tool.name;
20
-
21
- if (core.getTool({ toolName: name, agentId: tool.agentId })) {
22
- console.warn(
23
- `Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`,
24
- );
25
- }
26
- core.addHookFrontendTool(tool);
27
-
28
- const renderer = tool.render
29
- ? ({
30
- name,
31
- args: tool.parameters,
32
- agentId: tool.agentId,
33
- render: tool.render,
34
- } as SvelteToolCallRenderer<unknown>)
35
- : undefined;
36
- if (renderer) core.addHookRenderToolCall(renderer);
37
-
38
- return () => {
39
- core.removeHookFrontendTool(name, tool.agentId, tool);
40
- if (renderer) {
41
- core.removeHookRenderToolCall(name, tool.agentId, renderer);
42
- }
43
- };
44
- });
45
- }
@@ -1,118 +0,0 @@
1
- import { getContext } from "svelte";
2
- import type { FrontendToolHandlerContext } from "@copilotkit/core";
3
- import { COPILOT_KIT_KEY } from "../providers/context";
4
- import type { CopilotKitContextValue } from "../providers/context";
5
- import type {
6
- SvelteFrontendTool,
7
- SvelteHumanInTheLoop,
8
- SvelteToolCallRenderer,
9
- SvelteToolCallRendererRenderProps,
10
- } from "../types";
11
-
12
- export function registerHumanInTheLoop<T extends Record<string, unknown>>(
13
- tool: SvelteHumanInTheLoop<T>,
14
- ) {
15
- const context = getContext<CopilotKitContextValue | null>(COPILOT_KIT_KEY);
16
- if (!context) {
17
- throw new Error(
18
- "registerHumanInTheLoop must be used within CopilotKitProvider",
19
- );
20
- }
21
-
22
- const pendingResponses: Record<
23
- string,
24
- | {
25
- resolve: (result: unknown) => void;
26
- reject: (error: Error) => void;
27
- cleanupAbort?: () => void;
28
- }
29
- | undefined
30
- > = {};
31
-
32
- const respond = async (toolCallId: string, result: unknown) => {
33
- const pending = pendingResponses[toolCallId];
34
- if (!pending) return;
35
- pending.cleanupAbort?.();
36
- delete pendingResponses[toolCallId];
37
- pending.resolve(result);
38
- };
39
-
40
- const handler = async (
41
- _args: T,
42
- { toolCall, signal }: FrontendToolHandlerContext,
43
- ) => {
44
- return new Promise((resolve, reject) => {
45
- if (signal?.aborted) {
46
- reject(new Error("Human-in-the-loop interaction aborted"));
47
- return;
48
- }
49
-
50
- const pending = {
51
- resolve,
52
- reject,
53
- cleanupAbort: undefined as (() => void) | undefined,
54
- };
55
- pendingResponses[toolCall.id] = pending;
56
-
57
- if (signal) {
58
- const onAbort = () => {
59
- delete pendingResponses[toolCall.id];
60
- reject(new Error("Human-in-the-loop interaction aborted"));
61
- };
62
- signal.addEventListener("abort", onAbort, { once: true });
63
- pending.cleanupAbort = () =>
64
- signal.removeEventListener("abort", onAbort);
65
- }
66
- });
67
- };
68
-
69
- $effect(() => {
70
- const core = context.copilotkit;
71
- const { name, agentId, parameters, description, render } = tool;
72
- const RenderComponent: SvelteToolCallRenderer<T>["render"] = (
73
- props: SvelteToolCallRendererRenderProps<T>,
74
- ) => {
75
- const extendedProps = {
76
- ...props,
77
- name,
78
- description: description || "",
79
- respond:
80
- props.status === "executing"
81
- ? (result: unknown) => respond(props.toolCallId, result)
82
- : undefined,
83
- };
84
- return render(
85
- extendedProps as Parameters<SvelteHumanInTheLoop<T>["render"]>[0],
86
- );
87
- };
88
- const frontendTool: SvelteFrontendTool<T> = {
89
- ...tool,
90
- name,
91
- agentId,
92
- parameters,
93
- type: "human-in-the-loop",
94
- handler,
95
- render: RenderComponent,
96
- };
97
- const renderer = {
98
- name,
99
- args: parameters,
100
- agentId,
101
- render: RenderComponent,
102
- } as SvelteToolCallRenderer<unknown>;
103
- core.addHookFrontendTool(frontendTool);
104
- core.addHookRenderToolCall(renderer);
105
- return () => {
106
- for (const pending of Object.values(pendingResponses)) {
107
- if (!pending) continue;
108
- pending.cleanupAbort?.();
109
- pending.reject(new Error("Human-in-the-loop interaction aborted"));
110
- }
111
- for (const toolCallId of Object.keys(pendingResponses)) {
112
- delete pendingResponses[toolCallId];
113
- }
114
- core.removeHookFrontendTool(name, agentId, frontendTool);
115
- core.removeHookRenderToolCall(name, agentId, renderer);
116
- };
117
- });
118
- }
@@ -1,75 +0,0 @@
1
- import { getContext } from "svelte";
2
- import { z } from "zod";
3
- import type { StandardSchemaV1 } from "@copilotkit/shared";
4
- import { COPILOT_KIT_KEY } from "../providers/context";
5
- import type { CopilotKitContextValue } from "../providers/context";
6
- import type {
7
- SvelteToolCallRenderer,
8
- SvelteToolCallRendererRenderProps,
9
- } from "../types";
10
-
11
- export type RenderToolInProgressProps = {
12
- name: string;
13
- toolCallId: string;
14
- parameters: Partial<Record<string, unknown>>;
15
- status: "inProgress";
16
- result: undefined;
17
- };
18
-
19
- export type RenderToolExecutingProps = {
20
- name: string;
21
- toolCallId: string;
22
- parameters: Record<string, unknown>;
23
- status: "executing";
24
- result: undefined;
25
- };
26
-
27
- export type RenderToolCompleteProps = {
28
- name: string;
29
- toolCallId: string;
30
- parameters: Record<string, unknown>;
31
- status: "complete";
32
- result: string;
33
- };
34
-
35
- export type RenderToolProps =
36
- | RenderToolInProgressProps
37
- | RenderToolExecutingProps
38
- | RenderToolCompleteProps;
39
-
40
- export function registerRenderToolCall(config: {
41
- name: string;
42
- parameters?: StandardSchemaV1<unknown, unknown>;
43
- render: (props: RenderToolProps) => unknown;
44
- agentId?: string;
45
- }): void {
46
- const context = getContext<CopilotKitContextValue | null>(COPILOT_KIT_KEY);
47
- if (!context) {
48
- throw new Error(
49
- "registerRenderToolCall must be used within CopilotKitProvider",
50
- );
51
- }
52
-
53
- $effect(() => {
54
- const { name, agentId, parameters, render } = config;
55
- const schema =
56
- name === "*" && !parameters ? z.any() : (parameters ?? z.any());
57
-
58
- const renderer: SvelteToolCallRenderer<unknown> = {
59
- name,
60
- args: schema as StandardSchemaV1<unknown, unknown>,
61
- render: (props: SvelteToolCallRendererRenderProps<unknown>) =>
62
- render({
63
- ...props,
64
- parameters: props.args as Record<string, unknown>,
65
- } as RenderToolProps),
66
- ...(agentId ? { agentId } : {}),
67
- };
68
-
69
- context.copilotkit.addHookRenderToolCall(renderer);
70
-
71
- return () => {
72
- context.copilotkit.removeHookRenderToolCall(name, agentId, renderer);
73
- };
74
- });
75
- }