@copilotkit/vue 1.83.0 → 2.0.0-rc.1

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 (64) hide show
  1. package/AGENTS.md +1 -1
  2. package/dist/index.cjs +76 -1
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.mjs +14290 -287
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/styles.css +1 -1
  7. package/dist/v2/components/A2UIMessageRenderer.d.ts.map +1 -1
  8. package/dist/v2/components/a2ui/catalog.d.ts +1 -1
  9. package/dist/v2/components/a2ui/catalog.d.ts.map +1 -1
  10. package/dist/v2/components/chat/BasicMarkdown.vue.d.ts +9 -0
  11. package/dist/v2/components/chat/BasicMarkdown.vue.d.ts.map +1 -0
  12. package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -1
  13. package/dist/v2/components/chat/CopilotChatReasoningMessage.vue.d.ts.map +1 -1
  14. package/dist/v2/components/chat/StreamingMarkdownDefault.vue.d.ts +10 -0
  15. package/dist/v2/components/chat/StreamingMarkdownDefault.vue.d.ts.map +1 -0
  16. package/dist/v2/components/chat/index.d.ts +2 -0
  17. package/dist/v2/components/chat/index.d.ts.map +1 -1
  18. package/dist/v2/hooks/index.d.ts +0 -1
  19. package/dist/v2/hooks/index.d.ts.map +1 -1
  20. package/dist/v2/hooks/use-pin-to-send.d.ts +1 -1
  21. package/dist/v2/index.cjs +1 -1
  22. package/dist/v2/index.mjs +195 -188
  23. package/dist/v2/providers/CopilotKitProvider.types.d.ts +10 -0
  24. package/dist/v2/providers/CopilotKitProvider.types.d.ts.map +1 -1
  25. package/dist/v2/providers/CopilotKitProvider.vue.d.ts.map +1 -1
  26. package/dist/v2/providers/index.d.ts +1 -0
  27. package/dist/v2/providers/index.d.ts.map +1 -1
  28. package/dist/v2/providers/markdown-renderer.d.ts +23 -0
  29. package/dist/v2/providers/markdown-renderer.d.ts.map +1 -0
  30. package/package.json +8 -9
  31. package/src/styles/globals.css +0 -97
  32. package/src/v2/components/A2UIMessageRenderer.ts +3 -2
  33. package/src/v2/components/a2ui/catalog.ts +4 -2
  34. package/src/v2/components/chat/BasicMarkdown.vue +158 -0
  35. package/src/v2/components/chat/CopilotChatAssistantMessage.vue +27 -536
  36. package/src/v2/components/chat/CopilotChatReasoningMessage.vue +7 -2
  37. package/src/v2/components/chat/StreamingMarkdownDefault.vue +57 -0
  38. package/src/v2/components/chat/__tests__/BasicMarkdown.test.ts +69 -0
  39. package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.ts +53 -16
  40. package/src/v2/components/chat/__tests__/CopilotChat.licenseWarning.test.ts +5 -7
  41. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.markdown.test.ts +54 -0
  42. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.ts +0 -41
  43. package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.ts +18 -4
  44. package/src/v2/components/chat/__tests__/markdown-renderer-config.e2e.test.ts +59 -0
  45. package/src/v2/components/chat/index.ts +2 -0
  46. package/src/v2/hooks/__tests__/use-agent.e2e.test.ts +7 -3
  47. package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.ts +7 -3
  48. package/src/v2/hooks/index.ts +0 -1
  49. package/src/v2/hooks/use-pin-to-send.ts +1 -1
  50. package/src/v2/providers/CopilotKitProvider.types.ts +10 -0
  51. package/src/v2/providers/CopilotKitProvider.vue +2 -0
  52. package/src/v2/providers/__tests__/CopilotKitProvider.headersAtSendTime.test.ts +1 -1
  53. package/src/v2/providers/__tests__/markdown-renderer.test.ts +40 -0
  54. package/src/v2/providers/index.ts +1 -0
  55. package/src/v2/providers/markdown-renderer.ts +39 -0
  56. package/vite.config.ts +1 -3
  57. package/dist/use-render-activity-message-B7sDGUl4.cjs +0 -70
  58. package/dist/use-render-activity-message-B7sDGUl4.cjs.map +0 -1
  59. package/dist/use-render-activity-message-mQvByEYF.js +0 -12544
  60. package/dist/use-render-activity-message-mQvByEYF.js.map +0 -1
  61. package/dist/v2/hooks/use-katex-styles.d.ts +0 -22
  62. package/dist/v2/hooks/use-katex-styles.d.ts.map +0 -1
  63. package/src/v2/hooks/__tests__/use-katex-styles.test.ts +0 -69
  64. package/src/v2/hooks/use-katex-styles.ts +0 -44
@@ -1,4 +1,5 @@
1
- import { computed, defineComponent, h, type PropType } from "vue";
1
+ import { computed, defineComponent, h } from "vue";
2
+ import type { PropType } from "vue";
2
3
  import { z } from "zod";
3
4
  import type { VueActivityMessageRenderer } from "../types";
4
5
  import type { A2UITheme } from "../types";
@@ -15,7 +16,7 @@ export type A2UIMessageRendererOptions = {
15
16
  /**
16
17
  * Default loading component shown while an A2UI surface is generating.
17
18
  * Mirrors React's `DefaultA2UILoading` in
18
- * `packages/react-core/src/v2/a2ui/A2UIMessageRenderer.tsx`:
19
+ * `packages/react-core/src/a2ui/A2UIMessageRenderer.tsx`:
19
20
  * an animated dot + "Generating UI..." label + three shimmer bars
20
21
  * (80% / 60% / 40% widths) with staggered `cpk-a2ui-pulse` opacity animation.
21
22
  */
@@ -5,7 +5,8 @@
5
5
  * mirroring the React renderer's catalog/basic/.
6
6
  */
7
7
 
8
- import { h, ref, type CSSProperties, type VNode } from "vue";
8
+ import { h, ref } from "vue";
9
+ import type { CSSProperties, VNode } from "vue";
9
10
  import { Catalog } from "@a2ui/web_core/v0_9";
10
11
  import {
11
12
  TextApi,
@@ -29,7 +30,8 @@ import {
29
30
  BASIC_FUNCTIONS,
30
31
  } from "@a2ui/web_core/v0_9/basic_catalog";
31
32
 
32
- import { createVueComponent, type VueComponentImplementation } from "./adapter";
33
+ import { createVueComponent } from "./adapter";
34
+ import type { VueComponentImplementation } from "./adapter";
33
35
  import {
34
36
  LEAF_MARGIN,
35
37
  STANDARD_BORDER,
@@ -0,0 +1,158 @@
1
+ <script setup lang="ts">
2
+ import { computed, h, type VNode } from "vue";
3
+ import { parseMarkdown, type MarkdownToken } from "@copilotkit/core";
4
+
5
+ const props = withDefaults(
6
+ defineProps<{ content: string; isStreaming?: boolean }>(),
7
+ { isStreaming: false },
8
+ );
9
+
10
+ const tokens = computed(() => parseMarkdown(props.content ?? ""));
11
+
12
+ // Allowlist URL schemes to prevent XSS via javascript:/data:/vbscript: URIs.
13
+ const SAFE_HREF = /^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i;
14
+ const SAFE_IMG_SRC = /^(https?:|data:image\/(?!svg)|\/|\.\/|\.\.\/)/i;
15
+
16
+ function sanitizeHref(href: string | undefined): string | undefined {
17
+ if (!href) return undefined;
18
+ return SAFE_HREF.test(href.trim()) ? href : undefined;
19
+ }
20
+ function sanitizeImgSrc(src: string | undefined): string | undefined {
21
+ if (!src) return undefined;
22
+ return SAFE_IMG_SRC.test(src.trim()) ? src : undefined;
23
+ }
24
+
25
+ function inline(toks: MarkdownToken[] | undefined): (VNode | string)[] {
26
+ if (!toks) return [];
27
+ return toks.map((t) => {
28
+ switch (t.type) {
29
+ case "text":
30
+ return "tokens" in t && (t as any).tokens
31
+ ? h("span", inline((t as any).tokens))
32
+ : (t as any).text;
33
+ case "strong":
34
+ return h("strong", inline((t as any).tokens));
35
+ case "em":
36
+ return h("em", inline((t as any).tokens));
37
+ case "del":
38
+ return h("del", inline((t as any).tokens));
39
+ case "codespan":
40
+ return h(
41
+ "code",
42
+ { class: "cpk:rounded cpk:bg-black/5 cpk:px-1 cpk:py-0.5" },
43
+ (t as any).text,
44
+ );
45
+ case "br":
46
+ return h("br");
47
+ case "link":
48
+ return h(
49
+ "a",
50
+ {
51
+ href: sanitizeHref((t as any).href),
52
+ target: "_blank",
53
+ rel: "noopener noreferrer",
54
+ },
55
+ (t as any).tokens ? inline((t as any).tokens) : (t as any).text,
56
+ );
57
+ case "image":
58
+ return h("img", {
59
+ src: sanitizeImgSrc((t as any).href),
60
+ alt: (t as any).text,
61
+ class: "cpk:max-w-full",
62
+ });
63
+ case "escape":
64
+ return (t as any).text;
65
+ default:
66
+ return "text" in t ? (t as any).text : "";
67
+ }
68
+ });
69
+ }
70
+
71
+ function block(t: MarkdownToken): VNode | null {
72
+ switch (t.type) {
73
+ case "space":
74
+ return null;
75
+ case "heading": {
76
+ const depth = Math.min(Math.max((t as any).depth, 1), 6);
77
+ return h(`h${depth}`, inline((t as any).tokens));
78
+ }
79
+ case "paragraph":
80
+ return h("p", inline((t as any).tokens));
81
+ case "blockquote":
82
+ return h(
83
+ "blockquote",
84
+ (((t as any).tokens as MarkdownToken[] | undefined) ?? [])
85
+ .map(block)
86
+ .filter(Boolean),
87
+ );
88
+ case "code":
89
+ return h("pre", { class: "cpk:overflow-x-auto cpk:rounded-lg cpk:p-3" }, [
90
+ h(
91
+ "code",
92
+ { "data-language": (t as any).lang || undefined },
93
+ (t as any).text,
94
+ ),
95
+ ]);
96
+ case "hr":
97
+ return h("hr");
98
+ case "list": {
99
+ const list = t as any;
100
+ const items = list.items.map((it: any) =>
101
+ h(
102
+ "li",
103
+ ((it.tokens as MarkdownToken[] | undefined) ?? [])
104
+ .map(block)
105
+ .filter(Boolean),
106
+ ),
107
+ );
108
+ return list.ordered
109
+ ? h(
110
+ "ol",
111
+ { start: typeof list.start === "number" ? list.start : undefined },
112
+ items,
113
+ )
114
+ : h("ul", items);
115
+ }
116
+ case "table": {
117
+ const tbl = t as any;
118
+ return h("div", { class: "cpk:overflow-x-auto" }, [
119
+ h("table", [
120
+ h("thead", [
121
+ h(
122
+ "tr",
123
+ tbl.header.map((c: any) => h("th", inline(c.tokens))),
124
+ ),
125
+ ]),
126
+ h(
127
+ "tbody",
128
+ tbl.rows.map((row: any) =>
129
+ h(
130
+ "tr",
131
+ row.map((c: any) => h("td", inline(c.tokens))),
132
+ ),
133
+ ),
134
+ ),
135
+ ]),
136
+ ]);
137
+ }
138
+ case "text":
139
+ return h(
140
+ "p",
141
+ (t as any).tokens ? inline((t as any).tokens) : (t as any).text,
142
+ );
143
+ default:
144
+ return "text" in t ? h("span", (t as any).text) : null;
145
+ }
146
+ }
147
+
148
+ const Rendered = () =>
149
+ h(
150
+ "div",
151
+ { class: "copilot-chat-assistant-markdown" },
152
+ tokens.value.map(block).filter(Boolean),
153
+ );
154
+ </script>
155
+
156
+ <template>
157
+ <Rendered v-if="tokens.length" />
158
+ </template>