@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableCell.svelte.d.ts","sourceRoot":"","sources":["../../../../src/components/chat/markdown/TableCell.svelte"],"names":[],"mappings":"AAGE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEvC,KAAK,gBAAgB,GAAI;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AA4BJ,QAAA,MAAM,SAAS,sDAAwC,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
@@ -1 +1,8 @@
1
- export { SvelteComponent as default } from 'svelte';
1
+ import type { Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ children?: Snippet;
4
+ };
5
+ declare const TableHead: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type TableHead = ReturnType<typeof TableHead>;
7
+ export default TableHead;
8
+ //# sourceMappingURL=TableHead.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableHead.svelte.d.ts","sourceRoot":"","sources":["../../../../src/components/chat/markdown/TableHead.svelte"],"names":[],"mappings":"AAGE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEvC,KAAK,gBAAgB,GAAI;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAcjD,QAAA,MAAM,SAAS,sDAAwC,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
@@ -1 +1,8 @@
1
- export { SvelteComponent as default } from 'svelte';
1
+ import type { Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ children?: Snippet;
4
+ };
5
+ declare const TableRow: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type TableRow = ReturnType<typeof TableRow>;
7
+ export default TableRow;
8
+ //# sourceMappingURL=TableRow.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableRow.svelte.d.ts","sourceRoot":"","sources":["../../../../src/components/chat/markdown/TableRow.svelte"],"names":[],"mappings":"AAGE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEvC,KAAK,gBAAgB,GAAI;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAcjD,QAAA,MAAM,QAAQ,sDAAwC,CAAC;AACvD,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC5C,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,91 @@
1
+ import hljs from "highlight.js";
2
+ const LANGUAGE_ALIASES = {
3
+ js: "javascript",
4
+ jsx: "javascript",
5
+ mjs: "javascript",
6
+ cjs: "javascript",
7
+ ts: "typescript",
8
+ tsx: "typescript",
9
+ sh: "bash",
10
+ shell: "bash",
11
+ zsh: "bash",
12
+ yml: "yaml",
13
+ md: "markdown",
14
+ py: "python",
15
+ rb: "ruby",
16
+ rs: "rust",
17
+ "c++": "cpp",
18
+ cs: "csharp",
19
+ "c#": "csharp",
20
+ html: "xml",
21
+ svg: "xml",
22
+ };
23
+ const EXTENSION_BY_LANGUAGE = {
24
+ bash: "sh",
25
+ c: "c",
26
+ cpp: "cpp",
27
+ csharp: "cs",
28
+ css: "css",
29
+ diff: "diff",
30
+ go: "go",
31
+ graphql: "graphql",
32
+ java: "java",
33
+ javascript: "js",
34
+ json: "json",
35
+ kotlin: "kt",
36
+ less: "less",
37
+ lua: "lua",
38
+ markdown: "md",
39
+ php: "php",
40
+ plaintext: "txt",
41
+ python: "py",
42
+ ruby: "rb",
43
+ rust: "rs",
44
+ scss: "scss",
45
+ sql: "sql",
46
+ swift: "swift",
47
+ typescript: "ts",
48
+ xml: "xml",
49
+ yaml: "yml",
50
+ };
51
+ function normalizeLanguage(lang) {
52
+ const cleaned = lang?.trim().toLowerCase().split(/\s+/)[0];
53
+ if (!cleaned)
54
+ return undefined;
55
+ return LANGUAGE_ALIASES[cleaned] ?? cleaned;
56
+ }
57
+ function escapeHtml(value) {
58
+ return value
59
+ .replace(/&/g, "&amp;")
60
+ .replace(/</g, "&lt;")
61
+ .replace(/>/g, "&gt;")
62
+ .replace(/"/g, "&quot;")
63
+ .replace(/'/g, "&#39;");
64
+ }
65
+ /**
66
+ * Highlights a fenced code block. Unknown languages fall back to automatic
67
+ * detection so highlighting still works when the fence is missing a language.
68
+ */
69
+ export function highlightCode(code, lang) {
70
+ const language = normalizeLanguage(lang);
71
+ try {
72
+ if (language && hljs.getLanguage(language)) {
73
+ return hljs.highlight(code, { language, ignoreIllegals: true }).value;
74
+ }
75
+ if (code.trim().length > 0) {
76
+ return hljs.highlightAuto(code).value;
77
+ }
78
+ }
79
+ catch {
80
+ // Fall through to escaped plain text on any highlighter failure.
81
+ }
82
+ return escapeHtml(code);
83
+ }
84
+ export function getLanguageLabel(lang) {
85
+ return normalizeLanguage(lang) ?? "text";
86
+ }
87
+ export function getDownloadFilename(lang) {
88
+ const language = normalizeLanguage(lang);
89
+ const extension = (language && EXTENSION_BY_LANGUAGE[language]) || "txt";
90
+ return `code.${extension}`;
91
+ }
@@ -1,5 +1,5 @@
1
- import { UserMessage } from '@ag-ui/core';
2
- import { AudioInputPart, DocumentInputPart, ImageInputPart, VideoInputPart } from '@copilotkit/shared';
1
+ import type { UserMessage } from "@ag-ui/core";
2
+ import type { AudioInputPart, DocumentInputPart, ImageInputPart, VideoInputPart } from "@copilotkit/shared";
3
3
  export type MediaPart = ImageInputPart | AudioInputPart | VideoInputPart | DocumentInputPart;
4
4
  /**
5
5
  * Keeps only the non-text parts of a user message. Mirrors the React package so
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Keeps only the non-text parts of a user message. Mirrors the React package so
3
+ * sent images, audio, video and documents render above the message bubble
4
+ * instead of being dropped.
5
+ */
6
+ export function getMediaParts(content) {
7
+ if (!content || typeof content === "string")
8
+ return [];
9
+ return content.filter((part) => part.type === "image" ||
10
+ part.type === "audio" ||
11
+ part.type === "video" ||
12
+ part.type === "document");
13
+ }
14
+ export function getMediaPartFilename(part) {
15
+ const filename = part.metadata?.filename;
16
+ return typeof filename === "string" ? filename : undefined;
17
+ }
@@ -1,6 +1,8 @@
1
- import { Message, AssistantMessage, UserMessage, ToolCall, ToolMessage } from '@ag-ui/core';
2
- import { ToolCallStatus, Suggestion, CopilotKitCoreErrorCode } from '@copilotkit/core';
3
- import { Attachment, AttachmentModality, AttachmentsConfig, InputContent } from '@copilotkit/shared';
1
+ import type { Message, AssistantMessage, UserMessage, ToolCall, ToolMessage } from "@ag-ui/core";
2
+ import type { ToolCallStatus } from "@copilotkit/core";
3
+ import type { Suggestion } from "@copilotkit/core";
4
+ import type { Attachment, AttachmentModality, AttachmentsConfig, InputContent } from "@copilotkit/shared";
5
+ import type { CopilotKitCoreErrorCode } from "@copilotkit/core";
4
6
  export type { Attachment, AttachmentModality, AttachmentsConfig, InputContent };
5
7
  export type AutoScrollMode = "pin-to-bottom" | "pin-to-send" | "none";
6
8
  export declare function normalizeAutoScroll(value: AutoScrollMode | boolean | undefined): AutoScrollMode;
@@ -0,0 +1,7 @@
1
+ export function normalizeAutoScroll(value) {
2
+ if (value === undefined || value === true)
3
+ return "pin-to-bottom";
4
+ if (value === false)
5
+ return "none";
6
+ return value;
7
+ }
@@ -1,2 +1,2 @@
1
- export { Check as IconCheck, Copy as IconCopy, Download as IconDownload, SquarePen as IconEdit, ChevronLeft as IconChevronLeft, ChevronRight as IconChevronRight, ChevronDown as IconChevronDown, RefreshCw as IconRefreshCw, Volume2 as IconVolume2, ThumbsUp as IconThumbsUp, ThumbsDown as IconThumbsDown, CircleCheck as IconCheckCircle, Circle as IconCircle, MessageCircle as IconMessageCircle, X as IconX, Plus as IconPlus, Mic as IconMic, ArrowUp as IconArrowUp, Square as IconSquare, LoaderCircle as IconLoader2, PanelLeftOpen as IconPanelLeftOpen, } from 'lucide-svelte';
1
+ export { Check as IconCheck, Copy as IconCopy, Download as IconDownload, SquarePen as IconEdit, ChevronLeft as IconChevronLeft, ChevronRight as IconChevronRight, ChevronDown as IconChevronDown, RefreshCw as IconRefreshCw, Volume2 as IconVolume2, ThumbsUp as IconThumbsUp, ThumbsDown as IconThumbsDown, CircleCheck as IconCheckCircle, Circle as IconCircle, MessageCircle as IconMessageCircle, X as IconX, Plus as IconPlus, Mic as IconMic, ArrowUp as IconArrowUp, Square as IconSquare, LoaderCircle as IconLoader2, PanelLeftOpen as IconPanelLeftOpen, } from "lucide-svelte";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ export { Check as IconCheck, Copy as IconCopy, Download as IconDownload, SquarePen as IconEdit, ChevronLeft as IconChevronLeft, ChevronRight as IconChevronRight, ChevronDown as IconChevronDown, RefreshCw as IconRefreshCw, Volume2 as IconVolume2, ThumbsUp as IconThumbsUp, ThumbsDown as IconThumbsDown, CircleCheck as IconCheckCircle, Circle as IconCircle, MessageCircle as IconMessageCircle, X as IconX, Plus as IconPlus, Mic as IconMic, ArrowUp as IconArrowUp, Square as IconSquare, LoaderCircle as IconLoader2, PanelLeftOpen as IconPanelLeftOpen, } from "lucide-svelte";
@@ -1,18 +1,18 @@
1
- export * from './chat/types';
2
- export { default as CopilotChat } from './chat/CopilotChat.svelte';
3
- export { default as CopilotChatView } from './chat/CopilotChatView.svelte';
4
- export { default as CopilotChatInput } from './chat/CopilotChatInput.svelte';
5
- export { default as CopilotChatMessage } from './chat/CopilotChatMessage.svelte';
6
- export { default as CopilotChatMessageView } from './chat/CopilotChatMessageView.svelte';
7
- export { default as CopilotChatAssistantMessage } from './chat/CopilotChatAssistantMessage.svelte';
8
- export { default as CopilotChatUserMessage } from './chat/CopilotChatUserMessage.svelte';
9
- export { default as CopilotChatReasoningMessage } from './chat/CopilotChatReasoningMessage.svelte';
10
- export { default as CopilotChatToolCallsView } from './chat/CopilotChatToolCallsView.svelte';
11
- export { default as CopilotChatSuggestionView } from './chat/CopilotChatSuggestionView.svelte';
12
- export { default as CopilotChatSuggestionPill } from './chat/CopilotChatSuggestionPill.svelte';
13
- export { default as CopilotChatAttachmentQueue } from './chat/CopilotChatAttachmentQueue.svelte';
14
- export { default as CopilotChatToggleButton } from './chat/CopilotChatToggleButton.svelte';
15
- export { default as CopilotSidebar } from './chat/CopilotSidebar.svelte';
16
- export { default as CopilotPopup } from './chat/CopilotPopup.svelte';
17
- export { default as StreamMarkdown } from './chat/StreamMarkdown.svelte';
1
+ export * from "./chat/types";
2
+ export { default as CopilotChat } from "./chat/CopilotChat.svelte";
3
+ export { default as CopilotChatView } from "./chat/CopilotChatView.svelte";
4
+ export { default as CopilotChatInput } from "./chat/CopilotChatInput.svelte";
5
+ export { default as CopilotChatMessage } from "./chat/CopilotChatMessage.svelte";
6
+ export { default as CopilotChatMessageView } from "./chat/CopilotChatMessageView.svelte";
7
+ export { default as CopilotChatAssistantMessage } from "./chat/CopilotChatAssistantMessage.svelte";
8
+ export { default as CopilotChatUserMessage } from "./chat/CopilotChatUserMessage.svelte";
9
+ export { default as CopilotChatReasoningMessage } from "./chat/CopilotChatReasoningMessage.svelte";
10
+ export { default as CopilotChatToolCallsView } from "./chat/CopilotChatToolCallsView.svelte";
11
+ export { default as CopilotChatSuggestionView } from "./chat/CopilotChatSuggestionView.svelte";
12
+ export { default as CopilotChatSuggestionPill } from "./chat/CopilotChatSuggestionPill.svelte";
13
+ export { default as CopilotChatAttachmentQueue } from "./chat/CopilotChatAttachmentQueue.svelte";
14
+ export { default as CopilotChatToggleButton } from "./chat/CopilotChatToggleButton.svelte";
15
+ export { default as CopilotSidebar } from "./chat/CopilotSidebar.svelte";
16
+ export { default as CopilotPopup } from "./chat/CopilotPopup.svelte";
17
+ export { default as StreamMarkdown } from "./chat/StreamMarkdown.svelte";
18
18
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { getContext } from "svelte";
2
+ import { COPILOT_KIT_KEY } from "../providers/context";
3
+ export function connectAgentContext(context) {
4
+ const ctx = getContext(COPILOT_KIT_KEY);
5
+ if (!ctx) {
6
+ throw new Error("connectAgentContext must be used within CopilotKitProvider");
7
+ }
8
+ $effect(() => {
9
+ const core = ctx.copilotkit;
10
+ const description = context.description;
11
+ const raw = context.value;
12
+ const stringValue = raw === undefined
13
+ ? ""
14
+ : typeof raw === "string"
15
+ ? raw
16
+ : JSON.stringify(raw);
17
+ const id = core.addContext({
18
+ description,
19
+ value: stringValue,
20
+ });
21
+ return () => {
22
+ core.removeContext(id);
23
+ };
24
+ });
25
+ }
@@ -1,6 +1,6 @@
1
- import { AbstractAgent } from '@ag-ui/client';
2
- import { Message } from '@ag-ui/core';
3
- import { SvelteMap } from 'svelte/reactivity';
1
+ import type { AbstractAgent } from "@ag-ui/client";
2
+ import type { Message } from "@ag-ui/core";
3
+ import { SvelteMap } from "svelte/reactivity";
4
4
  export declare enum CreateAgentUpdate {
5
5
  OnMessagesChanged = "OnMessagesChanged",
6
6
  OnStateChanged = "OnStateChanged",
@@ -0,0 +1,341 @@
1
+ import { HttpAgent } from "@ag-ui/client";
2
+ import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
3
+ import { ProxiedCopilotRuntimeAgent } from "@copilotkit/core";
4
+ import { CopilotKitCoreRuntimeConnectionStatus } from "@copilotkit/core";
5
+ import { COPILOT_KIT_KEY } from "../providers/context";
6
+ import { getContext } from "svelte";
7
+ import { SvelteMap } from "svelte/reactivity";
8
+ export var CreateAgentUpdate;
9
+ (function (CreateAgentUpdate) {
10
+ CreateAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
11
+ CreateAgentUpdate["OnStateChanged"] = "OnStateChanged";
12
+ CreateAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
13
+ })(CreateAgentUpdate || (CreateAgentUpdate = {}));
14
+ const ALL_UPDATES = [
15
+ CreateAgentUpdate.OnMessagesChanged,
16
+ CreateAgentUpdate.OnStateChanged,
17
+ CreateAgentUpdate.OnRunStatusChanged,
18
+ ];
19
+ export const globalThreadCloneMap = new WeakMap();
20
+ const globalThreadCloneConsumers = new WeakMap();
21
+ const MAX_CLONES_PER_AGENT = 50;
22
+ export function getThreadClone(registryAgent, threadId) {
23
+ if (!registryAgent || !threadId)
24
+ return undefined;
25
+ return globalThreadCloneMap.get(registryAgent)?.get(threadId);
26
+ }
27
+ function cloneForThread(source, threadId) {
28
+ const clone = source.clone();
29
+ if (clone === source) {
30
+ throw new Error(`createAgent: ${source.constructor.name}.clone() returned the same instance. ` +
31
+ "clone() must return a new, independent object.");
32
+ }
33
+ clone.threadId = threadId;
34
+ clone.setMessages([]);
35
+ clone.setState({});
36
+ return clone;
37
+ }
38
+ function applyProviderHeaders(core, target, headers) {
39
+ if (target instanceof HttpAgent) {
40
+ if (typeof core.applyHeadersToAgent === "function") {
41
+ core.applyHeadersToAgent(target);
42
+ }
43
+ else {
44
+ // Structural test doubles and older compatible cores may not expose the
45
+ // merge helper. Preserve existing agent headers in that fallback path.
46
+ target.headers = { ...target.headers, ...headers };
47
+ }
48
+ }
49
+ }
50
+ function getOrCreateThreadClone(core, source, threadId, headers) {
51
+ let byThread = globalThreadCloneMap.get(source);
52
+ if (!byThread) {
53
+ byThread = new SvelteMap();
54
+ globalThreadCloneMap.set(source, byThread);
55
+ }
56
+ const existing = byThread.get(threadId);
57
+ if (existing) {
58
+ existing.threadId = threadId;
59
+ applyProviderHeaders(core, existing, headers);
60
+ return existing;
61
+ }
62
+ const clone = cloneForThread(source, threadId);
63
+ applyProviderHeaders(core, clone, headers);
64
+ if (byThread.size >= MAX_CLONES_PER_AGENT) {
65
+ const consumers = globalThreadCloneConsumers.get(source);
66
+ const evictable = [...byThread.keys()].find((candidate) => !consumers?.get(candidate));
67
+ if (evictable !== undefined)
68
+ byThread.delete(evictable);
69
+ }
70
+ byThread.set(threadId, clone);
71
+ return clone;
72
+ }
73
+ function retainThreadClone(source, threadId) {
74
+ let consumers = globalThreadCloneConsumers.get(source);
75
+ if (!consumers) {
76
+ consumers = new SvelteMap();
77
+ globalThreadCloneConsumers.set(source, consumers);
78
+ }
79
+ consumers.set(threadId, (consumers.get(threadId) ?? 0) + 1);
80
+ }
81
+ function releaseThreadClone(source, threadId) {
82
+ const consumers = globalThreadCloneConsumers.get(source);
83
+ const count = consumers?.get(threadId);
84
+ if (count === undefined)
85
+ return;
86
+ if (count <= 1)
87
+ consumers?.delete(threadId);
88
+ else
89
+ consumers?.set(threadId, count - 1);
90
+ const byThread = globalThreadCloneMap.get(source);
91
+ while (byThread && byThread.size > MAX_CLONES_PER_AGENT) {
92
+ const evictable = [...byThread.keys()].find((candidate) => !consumers?.get(candidate));
93
+ if (evictable === undefined)
94
+ break;
95
+ byThread.delete(evictable);
96
+ }
97
+ }
98
+ export function createAgent(props = {}) {
99
+ const context = getContext(COPILOT_KIT_KEY);
100
+ if (!context) {
101
+ throw new Error("createAgent must be used within CopilotKitProvider");
102
+ }
103
+ const agentId = $derived(props.agentId ?? DEFAULT_AGENT_ID);
104
+ const threadId = $derived(props.threadId);
105
+ const updateFlags = $derived(props.updates ?? ALL_UPDATES);
106
+ const hookThrottleMs = $derived(props.throttleMs);
107
+ let agent = $state(null);
108
+ let agentIdentity = null;
109
+ let agentRevision = $state(0);
110
+ let agentInstanceRevision = $state(0);
111
+ let messages = $state([]);
112
+ let isRunning = $state(false);
113
+ let subscriptionAgent = $state(null);
114
+ const provisionalAgentCache = new SvelteMap();
115
+ let ownedClone = null;
116
+ function releaseOwnedClone() {
117
+ if (!ownedClone)
118
+ return;
119
+ releaseThreadClone(ownedClone.source, ownedClone.threadId);
120
+ ownedClone = null;
121
+ }
122
+ function setResolvedAgent(next) {
123
+ if (agentIdentity !== next)
124
+ agentInstanceRevision += 1;
125
+ agentIdentity = next;
126
+ agent = next;
127
+ }
128
+ const resolveAgent = () => {
129
+ const id = agentId;
130
+ const resolvedThreadId = threadId;
131
+ const cacheKey = resolvedThreadId ? `${id}:${resolvedThreadId}` : id;
132
+ const core = context.copilotkit;
133
+ const runtimeUrl = context.runtimeUrl;
134
+ const status = context.runtimeConnectionStatus;
135
+ const transport = context.runtimeTransport;
136
+ const headers = context.headers;
137
+ const credentials = "credentials" in context ? context.credentials : core.credentials;
138
+ const registered = context.agents ?? {};
139
+ // Reactive registry wins over mutable core fields. getAgent remains the
140
+ // core lookup when the provider has not published the agent yet.
141
+ const coreAgent = core.getAgent(id);
142
+ const existing = registered[id] ?? coreAgent;
143
+ if (existing) {
144
+ provisionalAgentCache.delete(cacheKey);
145
+ provisionalAgentCache.delete(id);
146
+ applyProviderHeaders(core, existing, headers);
147
+ let resolvedAgent;
148
+ if (resolvedThreadId) {
149
+ if (ownedClone &&
150
+ (ownedClone.source !== existing ||
151
+ ownedClone.threadId !== resolvedThreadId)) {
152
+ releaseOwnedClone();
153
+ }
154
+ resolvedAgent = getOrCreateThreadClone(core, existing, resolvedThreadId, headers);
155
+ if (!ownedClone ||
156
+ ownedClone.source !== existing ||
157
+ ownedClone.threadId !== resolvedThreadId) {
158
+ retainThreadClone(existing, resolvedThreadId);
159
+ ownedClone = { source: existing, threadId: resolvedThreadId };
160
+ }
161
+ }
162
+ else {
163
+ releaseOwnedClone();
164
+ resolvedAgent = existing;
165
+ }
166
+ setResolvedAgent(resolvedAgent);
167
+ messages = [...(resolvedAgent.messages ?? [])];
168
+ isRunning = resolvedAgent.isRunning ?? false;
169
+ subscriptionAgent = resolvedAgent;
170
+ return;
171
+ }
172
+ const isRuntimeConfigured = runtimeUrl !== undefined;
173
+ if (isRuntimeConfigured &&
174
+ (status === CopilotKitCoreRuntimeConnectionStatus.Disconnected ||
175
+ status === CopilotKitCoreRuntimeConnectionStatus.Connecting ||
176
+ status === CopilotKitCoreRuntimeConnectionStatus.Error)) {
177
+ releaseOwnedClone();
178
+ let cached = provisionalAgentCache.get(cacheKey);
179
+ if (cached &&
180
+ (cached.runtimeUrl !== runtimeUrl || cached.transport !== transport)) {
181
+ provisionalAgentCache.delete(cacheKey);
182
+ cached = undefined;
183
+ }
184
+ if (cached) {
185
+ cached.agent.credentials = credentials;
186
+ applyProviderHeaders(core, cached.agent, headers);
187
+ if (resolvedThreadId) {
188
+ cached.agent.threadId = resolvedThreadId;
189
+ }
190
+ setResolvedAgent(cached.agent);
191
+ messages = [...(cached.agent.messages ?? [])];
192
+ isRunning = cached.agent.isRunning ?? false;
193
+ subscriptionAgent = cached.agent;
194
+ return;
195
+ }
196
+ const provisional = new ProxiedCopilotRuntimeAgent({
197
+ runtimeUrl: runtimeUrl,
198
+ agentId: id,
199
+ transport,
200
+ runtimeMode: "pending",
201
+ credentials,
202
+ });
203
+ applyProviderHeaders(core, provisional, headers);
204
+ if (resolvedThreadId) {
205
+ provisional.threadId = resolvedThreadId;
206
+ }
207
+ provisionalAgentCache.set(cacheKey, {
208
+ agent: provisional,
209
+ runtimeUrl: runtimeUrl,
210
+ transport,
211
+ });
212
+ setResolvedAgent(provisional);
213
+ messages = [...(provisional.messages ?? [])];
214
+ isRunning = provisional.isRunning ?? false;
215
+ subscriptionAgent = provisional;
216
+ return;
217
+ }
218
+ releaseOwnedClone();
219
+ const knownAgents = Object.keys(registered);
220
+ const runtimePart = isRuntimeConfigured
221
+ ? `runtimeUrl=${runtimeUrl}`
222
+ : "no runtimeUrl";
223
+ throw new Error(`createAgent: Agent '${id}' not found after runtime sync (${runtimePart}). ` +
224
+ (knownAgents.length
225
+ ? `Known agents: [${knownAgents.join(", ")}]`
226
+ : "No agents registered."));
227
+ };
228
+ $effect(() => {
229
+ resolveAgent();
230
+ });
231
+ $effect(() => () => releaseOwnedClone());
232
+ $effect(() => {
233
+ // Track the provider getter so updates rerun this effect. The core owns
234
+ // the merge baseline and preserves each HttpAgent's construction headers.
235
+ const headers = context.headers;
236
+ const core = context.copilotkit;
237
+ applyProviderHeaders(core, subscriptionAgent, headers);
238
+ for (const registered of Object.values(context.agents ?? {})) {
239
+ applyProviderHeaders(core, registered, headers);
240
+ const clones = globalThreadCloneMap.get(registered);
241
+ if (!clones)
242
+ continue;
243
+ for (const clone of clones.values()) {
244
+ applyProviderHeaders(core, clone, headers);
245
+ }
246
+ }
247
+ for (const provisional of provisionalAgentCache.values()) {
248
+ applyProviderHeaders(core, provisional.agent, headers);
249
+ }
250
+ });
251
+ $effect(() => {
252
+ const a = subscriptionAgent;
253
+ const flags = updateFlags;
254
+ const core = context.copilotkit;
255
+ if (!a || flags.length === 0)
256
+ return;
257
+ let active = true;
258
+ let batchScheduled = false;
259
+ const batchedRefresh = () => {
260
+ if (!active)
261
+ return;
262
+ if (!batchScheduled) {
263
+ batchScheduled = true;
264
+ queueMicrotask(() => {
265
+ batchScheduled = false;
266
+ if (active) {
267
+ agentRevision += 1;
268
+ }
269
+ });
270
+ }
271
+ };
272
+ const handlers = {};
273
+ if (flags.includes(CreateAgentUpdate.OnMessagesChanged)) {
274
+ handlers.onMessagesChanged = () => {
275
+ if (active) {
276
+ messages = (a.messages ?? []).map((m) => ({ ...m }));
277
+ isRunning = a.isRunning ?? false;
278
+ agentRevision += 1;
279
+ }
280
+ };
281
+ }
282
+ if (flags.includes(CreateAgentUpdate.OnStateChanged)) {
283
+ handlers.onStateChanged = batchedRefresh;
284
+ }
285
+ if (flags.includes(CreateAgentUpdate.OnRunStatusChanged)) {
286
+ handlers.onRunInitialized = () => {
287
+ if (active) {
288
+ isRunning = true;
289
+ agent = a;
290
+ agentRevision += 1;
291
+ }
292
+ };
293
+ handlers.onRunFinalized = () => {
294
+ if (active) {
295
+ isRunning = false;
296
+ agent = a;
297
+ messages = (a.messages ?? []).map((m) => ({ ...m }));
298
+ agentRevision += 1;
299
+ }
300
+ };
301
+ handlers.onRunFailed = () => {
302
+ if (active) {
303
+ isRunning = false;
304
+ agent = a;
305
+ messages = (a.messages ?? []).map((m) => ({ ...m }));
306
+ agentRevision += 1;
307
+ }
308
+ };
309
+ handlers.onRunErrorEvent = () => {
310
+ if (active) {
311
+ isRunning = false;
312
+ agent = a;
313
+ messages = (a.messages ?? []).map((m) => ({ ...m }));
314
+ agentRevision += 1;
315
+ }
316
+ };
317
+ }
318
+ const subscription = core.subscribeToAgentWithOptions(a, handlers, {
319
+ throttleMs: hookThrottleMs,
320
+ });
321
+ return () => {
322
+ active = false;
323
+ subscription.unsubscribe();
324
+ };
325
+ });
326
+ return {
327
+ get agent() {
328
+ void agentRevision;
329
+ return agent;
330
+ },
331
+ get agentInstanceVersion() {
332
+ return agentInstanceRevision;
333
+ },
334
+ get messages() {
335
+ return messages;
336
+ },
337
+ get isRunning() {
338
+ return isRunning;
339
+ },
340
+ };
341
+ }
@@ -1,4 +1,4 @@
1
- import { Attachment, AttachmentsConfig } from '@copilotkit/shared';
1
+ import type { Attachment, AttachmentsConfig } from "@copilotkit/shared";
2
2
  export type AttachmentsConfigInput = AttachmentsConfig | (() => AttachmentsConfig | undefined);
3
3
  export interface CreateAttachmentsProps {
4
4
  config?: AttachmentsConfigInput;